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