1 /* 2 * Copyright (c) 2021 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 #ifndef DFS_DEVICE_MANAGER_AGENT_H 16 #define DFS_DEVICE_MANAGER_AGENT_H 17 18 #include <atomic> 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <set> 23 #include <unordered_map> 24 #include <vector> 25 26 #include "device_manager.h" 27 #include "dfsu_singleton.h" 28 29 namespace OHOS { 30 namespace Storage { 31 namespace DistributedFile { 32 class DeviceManagerAgent : public DistributedHardware::DmInitCallback, 33 public DistributedHardware::DeviceStateCallback, 34 public std::enable_shared_from_this<DeviceManagerAgent>, 35 public Utils::DfsuSingleton<DeviceManagerAgent> { 36 DECLARE_SINGLETON(DeviceManagerAgent); 37 38 public: 39 void OnDeviceOnline(const DistributedHardware::DmDeviceInfo &deviceInfo) override; 40 void OnDeviceOffline(const DistributedHardware::DmDeviceInfo &deviceInfo) override; OnDeviceChanged(const DistributedHardware::DmDeviceInfo & deviceInfo)41 void OnDeviceChanged(const DistributedHardware::DmDeviceInfo &deviceInfo) override {} OnDeviceReady(const DistributedHardware::DmDeviceInfo & deviceInfo)42 void OnDeviceReady(const DistributedHardware::DmDeviceInfo &deviceInfo) override {} 43 void OfflineAllDevice(); 44 void OnRemoteDied() override; getOnlineDevs()45 std::set<std::string> getOnlineDevs() const 46 { 47 return alreadyOnlineDev_; 48 } 49 std::vector<std::string> GetRemoteDevicesInfo(); 50 51 private: 52 void StartInstance() override; 53 void StopInstance() override; 54 55 void RegisterToExternalDm(); 56 void UnregisterFromExternalDm(); 57 58 std::mutex devsRecordMutex_; 59 std::set<std::string> alreadyOnlineDev_; 60 }; 61 } // namespace DistributedFile 62 } // namespace Storage 63 } // namespace OHOS 64 #endif // DFS_DEVICE_MANAGER_AGENT_H