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_DNETWORK_ADAPTER_H 17#define OHOS_DISTRIBUTED_DNETWORK_ADAPTER_H 18 19#include <iosfwd> 20#include <memory> 21#include <mutex> 22#include <set> 23#include <string> 24 25#include "device_manager.h" 26#include "event_handler.h" 27#include "nocopyable.h" 28 29namespace OHOS { 30namespace DistributedSchedule { 31enum DeviceInfoType { 32 UNKNOWN_INFO = 0, 33 BASIC_INFO = 1, 34 NETWORK_INFO = 2, 35 TRUST_INFO = 3, 36}; 37 38enum NodeDeviceInfoKey { 39 NODE_KEY_UDID = 0, 40 NODE_KEY_UUID = 1, 41}; 42 43class DeviceListener { 44public: 45 DeviceListener() = default; 46 virtual ~DeviceListener() = default; 47 48 virtual void OnDeviceOnline(const DistributedHardware::DmDeviceInfo& deviceInfo) = 0; 49 virtual void OnDeviceOffline(const DistributedHardware::DmDeviceInfo& deviceInfo) = 0; 50 virtual void OnDeviceInfoChanged(const DistributedHardware::DmDeviceInfo& deviceInfo) = 0; 51}; 52 53class DnetworkAdapter { 54public: 55 DnetworkAdapter() = default; 56 ~DnetworkAdapter() = default; 57 58 void Init(); 59 bool AddDeviceChangeListener(const std::shared_ptr<DeviceListener>& listener); 60 void RemoveDeviceChangeListener(const std::shared_ptr<DeviceListener>& listener); 61 std::string GetUdidByNetworkId(const std::string& networkId); 62 std::string GetUuidByNetworkId(const std::string& networkId); 63 bool GetLocalBasicInfo(DistributedHardware::DmDeviceInfo& dmDeviceInfo); 64 65 static std::shared_ptr<DnetworkAdapter> GetInstance(); 66 bool UpdateDeviceInfoStorage(); 67 68private: 69 DISALLOW_COPY_AND_MOVE(DnetworkAdapter); 70 71 static std::shared_ptr<AppExecFwk::EventHandler> dnetworkHandler_; 72 static std::mutex listenerSetMutex_; 73 static std::set<std::shared_ptr<DeviceListener>> listenerSet_; 74 75 std::shared_ptr<DistributedHardware::DeviceStateCallback> stateCallback_; 76 std::shared_ptr<DistributedHardware::DevTrustChangeCallback> devTrustChangeCallback_; 77 std::shared_ptr<DistributedHardware::DmInitCallback> initCallback_; 78class DeviceInitCallBack : public DistributedHardware::DmInitCallback { 79 void OnRemoteDied() override; 80}; 81 82class DmsDeviceStateCallback : public DistributedHardware::DeviceStateCallback { 83 void OnDeviceOnline(const DistributedHardware::DmDeviceInfo& deviceInfo) override; 84 void OnDeviceOffline(const DistributedHardware::DmDeviceInfo& deviceInfo) override; 85 void OnDeviceChanged(const DistributedHardware::DmDeviceInfo& deviceInfo) override; 86 void OnDeviceReady(const DistributedHardware::DmDeviceInfo& deviceInfo) override; 87}; 88 89class DmsDevTrustChangeCallback : public DistributedHardware::DevTrustChangeCallback { 90 void OnDeviceTrustChange(const std::string &udid, const std::string &uuid, 91 const DistributedHardware::DmAuthForm authform) override; 92}; 93}; 94} // namespace DistributedSchedule 95} // namespace OHOS 96#endif // OHOS_DISTRIBUTED_DNETWORK_ADAPTER_H