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