1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "base_client.h" 17 #include "common/media_log.h" 18 #include "utils/utils.h" 19 20 namespace OHOS { 21 namespace Sharing { ~BaseClient()22BaseClient::~BaseClient() 23 { 24 SHARING_LOGD("trace."); 25 } 26 BaseClient()27BaseClient::BaseClient() 28 { 29 SHARING_LOGD("trace."); 30 } 31 RegisterCallback(std::weak_ptr<IClientCallback> callback)32void BaseClient::RegisterCallback(std::weak_ptr<IClientCallback> callback) 33 { 34 SHARING_LOGD("trace."); 35 callback_ = callback; 36 } 37 GetCallback()38std::weak_ptr<IClientCallback> &BaseClient::GetCallback() 39 { 40 MEDIA_LOGD("trace."); 41 return callback_; 42 } 43 SetRecvOption(int32_t flags)44void BaseClient::SetRecvOption(int32_t flags) 45 { 46 SHARING_LOGD("trace."); 47 flags_ = flags; 48 } 49 OnReadable(int32_t fd)50void BaseClientEventListener::OnReadable(int32_t fd) 51 { 52 MEDIA_LOGD("trace thread_id: %{public}llu.", GetThreadId()); 53 auto client = client_.lock(); 54 if (client) { 55 client->OnClientReadable(fd); 56 } 57 } 58 OnWritable(int32_t fd)59void BaseClientEventListener::OnWritable(int32_t fd) 60 { 61 MEDIA_LOGD("trace thread_id: %{public}llu.", GetThreadId()); 62 auto client = client_.lock(); 63 if (client) { 64 auto callback = client->GetCallback().lock(); 65 if (callback) { 66 callback->OnClientWriteable(fd); 67 } 68 } 69 } 70 OnShutdown(int32_t fd)71void BaseClientEventListener::OnShutdown(int32_t fd) 72 { 73 SHARING_LOGD("trace thread_id: %{public}llu.", GetThreadId()); 74 auto client = client_.lock(); 75 if (client) { 76 auto callback = client->GetCallback().lock(); 77 if (callback) { 78 callback->OnClientClose(fd); 79 } 80 } 81 } 82 OnException(int32_t fd)83void BaseClientEventListener::OnException(int32_t fd) 84 { 85 SHARING_LOGD("trace thread_id: %{public}llu.", GetThreadId()); 86 auto client = client_.lock(); 87 if (client) { 88 auto callback = client->GetCallback().lock(); 89 if (callback) { 90 callback->OnClientException(fd); 91 } 92 } 93 } 94 } // namespace Sharing 95 } // namespace OHOS