1 /* 2 * Copyright (c) 2022 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 UnRegisterDeviceStatusCallback(const std::string &pkgName); 41 void RegisterDeviceStatusCallback(const std::string &pkgName, std::shared_ptr<DeviceStatusCallback> callback); 42 void RegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId, 43 std::shared_ptr<DiscoveryCallback> callback); 44 void UnRegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId); 45 void RegisterPublishCallback(const std::string &pkgName, int32_t publishId, 46 std::shared_ptr<PublishCallback> callback); 47 void UnRegisterPublishCallback(const std::string &pkgName, int32_t publishId); 48 void RegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId, 49 std::shared_ptr<AuthenticateCallback> callback); 50 void UnRegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId); 51 void UnRegisterPackageCallback(const std::string &pkgName); 52 void RegisterVerifyAuthenticationCallback(const std::string &pkgName, const std::string &authPara, 53 std::shared_ptr<VerifyAuthCallback> callback); 54 void UnRegisterVerifyAuthenticationCallback(const std::string &pkgName); 55 void RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr<DeviceManagerUiCallback> callback); 56 void UnRegisterDeviceManagerFaCallback(const std::string &pkgName); 57 void RegisterCredentialCallback(const std::string &pkgName, std::shared_ptr<CredentialCallback> callback); 58 void UnRegisterCredentialCallback(const std::string &pkgName); 59 60 public: 61 void OnRemoteDied(); 62 void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 63 void OnDeviceOnline(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo); 64 void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 65 void OnDeviceOffline(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo); 66 void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 67 void OnDeviceChanged(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo); 68 void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 69 void OnDeviceReady(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo); 70 void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo); 71 void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceBasicInfo &deviceBasicInfo); 72 void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason); 73 void OnDiscoverySuccess(const std::string &pkgName, uint16_t subscribeId); 74 void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult); 75 void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token, 76 uint32_t status, uint32_t reason); 77 void OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId, int32_t resultCode, int32_t flag); 78 void OnUiCall(std::string &pkgName, std::string ¶mJson); 79 void OnCredentialResult(const std::string &pkgName, int32_t &action, const std::string &credentialResult); 80 81 private: 82 #if !defined(__LITEOS_M__) 83 std::mutex lock_; 84 #endif 85 std::map<std::string, std::shared_ptr<DeviceStateCallback>> deviceStateCallback_; 86 std::map<std::string, std::shared_ptr<DeviceStatusCallback>> deviceStatusCallback_; 87 std::map<std::string, std::map<uint16_t, std::shared_ptr<DiscoveryCallback>>> deviceDiscoveryCallbacks_; 88 std::map<std::string, std::map<int32_t, std::shared_ptr<PublishCallback>>> devicePublishCallbacks_; 89 std::map<std::string, std::map<std::string, std::shared_ptr<AuthenticateCallback>>> authenticateCallback_; 90 std::map<std::string, std::shared_ptr<VerifyAuthCallback>> verifyAuthCallback_; 91 std::map<std::string, std::shared_ptr<DmInitCallback>> dmInitCallback_; 92 std::map<std::string, std::shared_ptr<DeviceManagerUiCallback>> dmUiCallback_; 93 std::map<std::string, std::shared_ptr<CredentialCallback>> credentialCallback_; 94 }; 95 } // namespace DistributedHardware 96 } // namespace OHOS 97 #endif // OHOS_DM_NOTIFY_H 98