/* * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H #define OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H #include #include "adapter/dnetwork_adapter.h" #include "deviceManager/dms_device_info.h" #include "distributed_device_node_listener.h" #include "event_handler.h" #include "iremote_object.h" #include "single_instance.h" namespace OHOS { namespace DistributedSchedule { class DnetServiceDeathRecipient : public IRemoteObject::DeathRecipient { public: DnetServiceDeathRecipient() = default; ~DnetServiceDeathRecipient() override = default; void OnRemoteDied(const wptr& remote) override; }; class DtbschedmgrDeviceInfoStorage { DECLARE_SINGLE_INSTANCE(DtbschedmgrDeviceInfoStorage); public: bool Init(); void Stop(); bool GetLocalDeviceId(std::string& networkId); void DeviceOnlineNotify(const std::shared_ptr devInfo); void DeviceOfflineNotify(const std::string& networkId); void OnDeviceInfoChanged(const std::string& networkId); /** * get device info by device id * * @param networkId, string * @return shared_ptr */ std::shared_ptr GetDeviceInfoById(const std::string& networkId); /** * get uuid by networkId * * @param networkId */ std::string GetUuidByNetworkId(const std::string& networkId); /** * get networkId by uuid * * @param uuid */ std::string GetNetworkIdByUuid(const std::string& uuid); /** * GetDeviceIdSet get all of the device Id in same network * * @param networkIdSet Returns the device set. */ void GetDeviceIdSet(std::set& deviceIdSet); /** * UpdateDeviceInfoStorage update device Info cache * * @param dmDeviceInfoList */ void UpdateDeviceInfoStorage(const std::vector& dmDeviceInfoList); private: bool InitNetworkIdManager(std::shared_ptr dnetworkAdapter); bool ConnectSoftbus(); void ClearAllDevices(); bool WaitForDnetworkReady(); bool GetLocalDeviceFromDnet(std::string& networkId); void RegisterUuidNetworkIdMap(const std::string& networkId); void UnregisterUuidNetworkIdMap(const std::string& networkId); std::mutex deviceLock_; std::shared_ptr deviceNodeListener_; std::map> remoteDevices_; std::string deviceId_; std::map uuidNetworkIdMap_; std::mutex uuidNetworkIdLock_; std::shared_ptr initHandler_; std::shared_ptr networkIdMgrHandler_; }; } // namespace DistributedSchedule } // namespace OHOS #endif // OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H