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_server.h" 17 #include "common/media_log.h" 18 #include "network/session/base_network_session.h" 19 #include "utils/utils.h" 20 namespace OHOS { 21 namespace Sharing { ~BaseServer()22BaseServer::~BaseServer() 23 { 24 SHARING_LOGD("trace."); 25 } 26 BaseServer()27BaseServer::BaseServer() 28 { 29 SHARING_LOGD("trace."); 30 } 31 RegisterCallback(std::weak_ptr<IServerCallback> callback)32void BaseServer::RegisterCallback(std::weak_ptr<IServerCallback> callback) 33 { 34 SHARING_LOGD("trace."); 35 callback_ = callback; 36 } 37 GetCallback()38std::weak_ptr<IServerCallback> &BaseServer::GetCallback() 39 { 40 MEDIA_LOGD("trace."); 41 return callback_; 42 } 43 OnReadable(int32_t fd)44void BaseServerEventListener::OnReadable(int32_t fd) 45 { 46 MEDIA_LOGD("thread_id: %{public}llu.", GetThreadId()); 47 auto server = server_.lock(); 48 if (server) { 49 server->OnServerReadable(fd); 50 } 51 } 52 OnWritable(int32_t fd)53void BaseServerEventListener::OnWritable(int32_t fd) 54 { 55 MEDIA_LOGD("thread_id: %{public}llu.", GetThreadId()); 56 auto server = server_.lock(); 57 if (server) { 58 auto callback = server->GetCallback().lock(); 59 if (callback) { 60 callback->OnServerWriteable(fd); 61 } 62 } 63 } 64 OnShutdown(int32_t fd)65void BaseServerEventListener::OnShutdown(int32_t fd) 66 { 67 SHARING_LOGD("thread_id: %{public}llu.", GetThreadId()); 68 auto server = server_.lock(); 69 if (server) { 70 auto callback = server->GetCallback().lock(); 71 if (callback) { 72 callback->OnServerClose(fd); 73 } 74 } 75 } 76 OnException(int32_t fd)77void BaseServerEventListener::OnException(int32_t fd) 78 { 79 SHARING_LOGD("thread_id: %{public}llu.", GetThreadId()); 80 auto server = server_.lock(); 81 if (server) { 82 auto callback = server->GetCallback().lock(); 83 if (callback) { 84 callback->OnServerException(fd); 85 } 86 } 87 } 88 89 } // namespace Sharing 90 } // namespace OHOS