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_DOMAIN_MANAGER_H 17 #define OHOS_SHARING_DOMAIN_MANAGER_H 18 19 #include <mutex> 20 #include "dm_kit.h" 21 #include "domain_def.h" 22 #include "ipc_msg.h" 23 #include "nocopyable.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace Sharing { 28 29 class DomainManagerListener { 30 public: 31 using Ptr = std::shared_ptr<DomainManagerListener>; 32 virtual ~DomainManagerListener() = default; 33 34 virtual int32_t OnDomainMsg(std::shared_ptr<BaseDomainMsg> msg) = 0; 35 }; 36 37 class DomainManager : public DelayedSingleton<DomainManager>, 38 public std::enable_shared_from_this<DomainManager>, 39 public ITransmitMgrListener { 40 DECLARE_DELAYED_SINGLETON(DomainManager); 41 42 public: 43 // impl ITransmitMgrListener 44 int32_t DelPeer(std::string remoteId) override; 45 int32_t AddPeer(std::shared_ptr<ITransmitMgr> mgr, std::shared_ptr<IDomainPeer> caller) override; 46 void OnDomainRequest(std::string remoteId, std::shared_ptr<BaseDomainMsg> BaseMsg) override; 47 48 void SetListener(DomainManagerListener::Ptr listener); 49 virtual int32_t AddServiceManager(std::shared_ptr<ITransmitMgr> mgr); 50 int32_t SendDomainRequest(std::string remoteId, std::shared_ptr<BaseDomainMsg> BaseMsg); 51 52 private: 53 std::shared_ptr<ITransmitMgr> FindMgrByRemoteId(std::string remoteId); 54 55 private: 56 std::mutex mutex_; 57 std::map<std::string, DomainType> peerTypeMap_; 58 std::map<DomainType, std::shared_ptr<ITransmitMgr>> transmitMgrs_; 59 std::vector<OHOS::DistributedHardware::DmDeviceInfo> trustedDeviceInfos_; 60 std::weak_ptr<DomainManagerListener> listener_; 61 OHOS::DistributedHardware::DmDeviceInfo localDeviceInfo_; 62 }; 63 64 } // namespace Sharing 65 } // namespace OHOS 66 67 #endif