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 #ifndef OHOS_SHARING_WFD_SOURCE_IMPL_H 17 #define OHOS_SHARING_WFD_SOURCE_IMPL_H 18 19 #include "impl/scene/wfd/wfd_msg.h" 20 #include "interaction/interprocess/inter_ipc_client.h" 21 #include "interaction/interprocess/ipc_msg_adapter.h" 22 #include "nocopyable.h" 23 #include "wfd_source.h" 24 25 namespace OHOS { 26 namespace Sharing { 27 class WfdSourceImpl : public WfdSource, 28 public MsgAdapterListener, 29 public std::enable_shared_from_this<WfdSourceImpl>, 30 public NoCopyable { 31 public: 32 WfdSourceImpl(); 33 ~WfdSourceImpl(); 34 SetIpcAdapter(const std::weak_ptr<IpcMsgAdapter> & adapter)35 void SetIpcAdapter(const std::weak_ptr<IpcMsgAdapter> &adapter) 36 { 37 SHARING_LOGD("trace."); 38 ipcAdapter_ = adapter; 39 auto ipcAdapter = ipcAdapter_.lock(); 40 if (ipcAdapter) { 41 ipcAdapter->SetListener(shared_from_this()); 42 } 43 } 44 SetIpcClient(const std::shared_ptr<InterIpcClient> & client)45 void SetIpcClient(const std::shared_ptr<InterIpcClient> &client) 46 { 47 SHARING_LOGD("trace."); 48 client_ = client; 49 } 50 51 public: 52 void OnRemoteDied() override; 53 void OnRequest(std::shared_ptr<BaseMsg> msg, std::shared_ptr<BaseMsg> &reply) override; 54 55 int32_t StopDiscover() override; 56 int32_t StartDiscover() override; 57 int32_t RemoveDevice(std::string deviceId) override; 58 int32_t AddDevice(uint64_t screenId, WfdCastDeviceInfo &deviceInfo) override; 59 int32_t SetListener(const std::shared_ptr<IWfdEventListener> &listener) override; 60 61 private: 62 std::mutex mutex_; 63 64 std::atomic_bool deviceAdded_ = false; 65 66 std::weak_ptr<IpcMsgAdapter> ipcAdapter_; 67 std::weak_ptr<IWfdEventListener> listener_; 68 std::shared_ptr<InterIpcClient> client_ = nullptr; 69 }; 70 71 } // namespace Sharing 72 } // namespace OHOS 73 #endif 74