• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device 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_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
17 #define OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
18 
19 #include <set>
20 
21 #include "adapter/dnetwork_adapter.h"
22 #include "deviceManager/dms_device_info.h"
23 #include "distributed_device_node_listener.h"
24 #include "event_handler.h"
25 #include "iremote_object.h"
26 #include "single_instance.h"
27 
28 namespace OHOS {
29 namespace DistributedSchedule {
30 class DnetServiceDeathRecipient : public IRemoteObject::DeathRecipient {
31 public:
32     DnetServiceDeathRecipient() = default;
33     ~DnetServiceDeathRecipient() override = default;
34     void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
35 };
36 
37 class DtbschedmgrDeviceInfoStorage {
38     DECLARE_SINGLE_INSTANCE(DtbschedmgrDeviceInfoStorage);
39 
40 public:
41     bool Init();
42     void Stop();
43     bool GetLocalDeviceId(std::string& networkId);
44     void DeviceOnlineNotify(const std::shared_ptr<DmsDeviceInfo> devInfo);
45     void DeviceOfflineNotify(const std::string& networkId);
46     void OnDeviceInfoChanged(const std::string& networkId);
47 
48     /**
49      * get device info by device id
50      *
51      * @param networkId, string
52      * @return shared_ptr<DmsDeviceInfo>
53      */
54     std::shared_ptr<DmsDeviceInfo> GetDeviceInfoById(const std::string& networkId);
55 
56     /**
57      * get uuid by networkId
58      *
59      * @param networkId
60      */
61     std::string GetUuidByNetworkId(const std::string& networkId);
62 
63     /**
64      * get networkId by uuid
65      *
66      * @param uuid
67      */
68     std::string GetNetworkIdByUuid(const std::string& uuid);
69 
70     /**
71      * GetDeviceIdSet get all of the device Id in same network
72      *
73      * @param networkIdSet Returns the device set.
74      */
75     void GetDeviceIdSet(std::set<std::string>& deviceIdSet);
76 
77     /**
78      * UpdateDeviceInfoStorage update device Info cache
79      *
80      * @param dmDeviceInfoList
81      */
82     void UpdateDeviceInfoStorage(const std::vector<DistributedHardware::DmDeviceInfo>& dmDeviceInfoList);
83 
84 private:
85     bool InitNetworkIdManager(std::shared_ptr<DnetworkAdapter> dnetworkAdapter);
86     bool ConnectSoftbus();
87     void ClearAllDevices();
88     bool WaitForDnetworkReady();
89     bool GetLocalDeviceFromDnet(std::string& networkId);
90     void RegisterUuidNetworkIdMap(const std::string& networkId);
91     void UnregisterUuidNetworkIdMap(const std::string& networkId);
92     std::mutex deviceLock_;
93     std::shared_ptr<DistributedDeviceNodeListener> deviceNodeListener_;
94     std::map<std::string, std::shared_ptr<DmsDeviceInfo>> remoteDevices_;
95     std::string deviceId_;
96     std::map<std::string, std::string> uuidNetworkIdMap_;
97     std::mutex uuidNetworkIdLock_;
98     std::shared_ptr<AppExecFwk::EventHandler> initHandler_;
99     std::shared_ptr<AppExecFwk::EventHandler> networkIdMgrHandler_;
100 };
101 } // namespace DistributedSchedule
102 } // namespace OHOS
103 #endif // OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
104