1 /* 2 * Copyright (C) 2025-2025 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 INTEROPERABLE_DEVICE_OBSERVER_H 17 #define INTEROPERABLE_DEVICE_OBSERVER_H 18 19 #include <list> 20 #include <string> 21 #include <unordered_set> 22 #include <shared_mutex> 23 #include "singleton.h" 24 #include "ffrt.h" 25 #include "i_interoperable_device_state_callback.h" 26 #include "device_manager.h" 27 28 namespace OHOS { 29 namespace Telephony { 30 constexpr const char* PACKAGE_NAME = "ohos.telephony.callmanager"; 31 32 class DeviceInitCallback : public DistributedHardware::DmInitCallback { 33 public: 34 DeviceInitCallback() = default; 35 virtual ~DeviceInitCallback() = default; OnRemoteDied()36 void OnRemoteDied() override {} 37 }; 38 39 class DmStateCallback : public DistributedHardware::DeviceStateCallback { 40 public: 41 void OnDeviceOnline(const DistributedHardware::DmDeviceInfo &deviceInfo) override; 42 void OnDeviceOffline(const DistributedHardware::DmDeviceInfo &deviceInfo) override; OnDeviceChanged(const DistributedHardware::DmDeviceInfo & deviceInfo)43 void OnDeviceChanged(const DistributedHardware::DmDeviceInfo &deviceInfo) override {} OnDeviceReady(const DistributedHardware::DmDeviceInfo & deviceInfo)44 void OnDeviceReady(const DistributedHardware::DmDeviceInfo &deviceInfo) override {} 45 }; 46 47 class InteroperableDeviceObserver { 48 DECLARE_DELAYED_SINGLETON(InteroperableDeviceObserver) 49 50 public: 51 void Init(); 52 void RegisterDevStatusCallback(const std::shared_ptr<IInteroperableDeviceStateCallback> &callback); 53 void UnRegisterDevStatusCallback(const std::shared_ptr<IInteroperableDeviceStateCallback> &callback); 54 void OnDeviceOnline(const std::string &networkId, const std::string &devName, uint16_t devType); 55 void OnDeviceOffline(const std::string &networkId, const std::string &devName, uint16_t devType); 56 57 private: 58 ffrt::mutex mutex_{}; 59 std::list<std::shared_ptr<IInteroperableDeviceStateCallback>> callbacks_{}; 60 }; 61 } 62 } 63 #endif // INTEROPERABLE_DEVICE_OBSERVER_H