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