1 /* 2 * Copyright (c) 2021-2022 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 "dms_notifier.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 bool Init(const sptr<DmsNotifier>& listener); 44 void Stop(); 45 bool GetLocalDeviceId(std::string& deviceId); 46 void DeviceOnlineNotify(const std::shared_ptr<DmsDeviceInfo> devInfo); 47 void DeviceOfflineNotify(const std::string& deviceId); 48 void OnDeviceInfoChanged(const std::string& deviceId); 49 50 /** 51 * get device info by device id 52 * 53 * @param deviceId, string 54 * @return shared_ptr<DmsDeviceInfo> 55 */ 56 std::shared_ptr<DmsDeviceInfo> GetDeviceInfoById(const std::string& deviceId); 57 58 /** 59 * get uuid by networkId 60 * 61 * @param networkId 62 */ 63 std::string GetUuidByNetworkId(const std::string& networkId); 64 65 /** 66 * get networkId by uuid 67 * 68 * @param uuid 69 */ 70 std::string GetNetworkIdByUuid(const std::string& uuid); 71 72 /** 73 * GetDeviceIdSet get all of the device Id in same network 74 * 75 * @param deviceIdSet Returns the device set. 76 */ 77 void GetDeviceIdSet(std::set<std::string>& deviceIdSet); 78 79 private: 80 bool InitNetworkIdManager(std::shared_ptr<DnetworkAdapter> dnetworkAdapter); 81 bool ConnectSoftbus(); 82 void ClearAllDevices(); 83 bool WaitForDnetworkReady(); 84 bool GetLocalDeviceFromDnet(std::string& deviceId); 85 void RegisterUuidNetworkIdMap(const std::string& networkId); 86 void UnregisterUuidNetworkIdMap(const std::string& networkId); 87 sptr<DmsNotifier> listener_; 88 std::mutex deviceLock_; 89 std::shared_ptr<DistributedDeviceNodeListener> deviceNodeListener_; 90 std::map<std::string, std::shared_ptr<DmsDeviceInfo>> remoteDevices_; 91 std::string deviceId_; 92 std::map<std::string, std::string> uuidNetworkIdMap_; 93 std::mutex uuidNetworkIdLock_; 94 std::shared_ptr<AppExecFwk::EventHandler> initHandler_; 95 std::shared_ptr<AppExecFwk::EventHandler> networkIdMgrHandler_; 96 }; 97 } // namespace DistributedSchedule 98 } // namespace OHOS 99 #endif // OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H 100