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 16 #ifndef OHOS_DM_NOTIFY_H 17 #define OHOS_DM_NOTIFY_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 #include <vector> 24 25 #include "device_manager_callback.h" 26 #include "dm_device_info.h" 27 #include "dm_subscribe_info.h" 28 #include "single_instance.h" 29 30 namespace OHOS { 31 namespace DistributedHardware { 32 class DeviceManagerNotify { 33 DECLARE_SINGLE_INSTANCE(DeviceManagerNotify); 34 35 public: 36 void RegisterDeathRecipientCallback(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback); 37 void UnRegisterDeathRecipientCallback(const std::string &pkgName); 38 void RegisterDeviceStateCallback(const std::string &pkgName, std::shared_ptr<DeviceStateCallback> callback); 39 void UnRegisterDeviceStateCallback(const std::string &pkgName); 40 void RegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId, 41 std::shared_ptr<DiscoveryCallback> callback); 42 void UnRegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId); 43 void RegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId, 44 std::shared_ptr<AuthenticateCallback> callback); 45 void UnRegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId); 46 void UnRegisterPackageCallback(const std::string &pkgName); 47 void RegisterVerifyAuthenticationCallback(const std::string &pkgName, const std::string &authPara, 48 std::shared_ptr<VerifyAuthCallback> callback); 49 void UnRegisterVerifyAuthenticationCallback(const std::string &pkgName); 50 void RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr<DeviceManagerUiCallback> callback); 51 void UnRegisterDeviceManagerFaCallback(const std::string &pkgName); 52 53 public: 54 void OnRemoteDied(); 55 void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 56 void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 57 void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 58 void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 59 void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo); 60 void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason); 61 void OnDiscoverySuccess(const std::string &pkgName, uint16_t subscribeId); 62 void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token, 63 uint32_t status, uint32_t reason); 64 void OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId, int32_t resultCode, int32_t flag); 65 void OnUiCall(std::string &pkgName, std::string ¶mJson); 66 67 private: 68 #if !defined(__LITEOS_M__) 69 std::mutex lock_; 70 #endif 71 std::map<std::string, std::shared_ptr<DeviceStateCallback>> deviceStateCallback_; 72 std::map<std::string, std::map<uint16_t, std::shared_ptr<DiscoveryCallback>>> deviceDiscoveryCallbacks_; 73 std::map<std::string, std::map<std::string, std::shared_ptr<AuthenticateCallback>>> authenticateCallback_; 74 std::map<std::string, std::shared_ptr<VerifyAuthCallback>> verifyAuthCallback_; 75 std::map<std::string, std::shared_ptr<DmInitCallback>> dmInitCallback_; 76 std::map<std::string, std::shared_ptr<DeviceManagerUiCallback>> dmUiCallback_; 77 }; 78 } // namespace DistributedHardware 79 } // namespace OHOS 80 #endif // OHOS_DM_NOTIFY_H 81