• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 OHOS_DM_NOTIFY_H
17 #define OHOS_DM_NOTIFY_H
18 
19 #include <chrono>
20 #include <condition_variable>
21 #include <map>
22 #include <memory>
23 #include <mutex>
24 #include <set>
25 
26 #include "device_manager_callback.h"
27 #include "dm_single_instance.h"
28 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
29 #include "ffrt.h"
30 #endif
31 
32 namespace OHOS {
33 namespace DistributedHardware {
34 class DeviceManagerNotify {
35     DM_DECLARE_SINGLE_INSTANCE(DeviceManagerNotify);
36 
37 public:
38     void RegisterDeathRecipientCallback(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback);
39     void UnRegisterDeathRecipientCallback(const std::string &pkgName);
40     void RegisterDeviceStateCallback(const std::string &pkgName, std::shared_ptr<DeviceStateCallback> callback);
41     void UnRegisterDeviceStateCallback(const std::string &pkgName);
42     void UnRegisterDeviceStatusCallback(const std::string &pkgName);
43     void RegisterDeviceStatusCallback(const std::string &pkgName, std::shared_ptr<DeviceStatusCallback> callback);
44     void RegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId,
45                                    std::shared_ptr<DiscoveryCallback> callback);
46     void UnRegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId);
47     void RegisterPublishCallback(const std::string &pkgName, int32_t publishId,
48         std::shared_ptr<PublishCallback> callback);
49     void UnRegisterPublishCallback(const std::string &pkgName, int32_t publishId);
50     void RegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId,
51                                       std::shared_ptr<AuthenticateCallback> callback);
52     void UnRegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId);
53     void UnRegisterPackageCallback(const std::string &pkgName);
54     void RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr<DeviceManagerUiCallback> callback);
55     void UnRegisterDeviceManagerFaCallback(const std::string &pkgName);
56     void RegisterCredentialCallback(const std::string &pkgName, std::shared_ptr<CredentialCallback> callback);
57     void UnRegisterCredentialCallback(const std::string &pkgName);
58     void RegisterBindCallback(const std::string &pkgName, const PeerTargetId &targetId,
59         std::shared_ptr<BindTargetCallback> callback);
60     void RegisterUnbindCallback(const std::string &pkgName, const PeerTargetId &targetId,
61         std::shared_ptr<UnbindTargetCallback> callback);
62     void OnBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, int32_t status,
63         std::string content);
64     void OnUnbindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, std::string content);
65     void RegisterPinHolderCallback(const std::string &pkgName, std::shared_ptr<PinHolderCallback> callback);
66     void RegDevTrustChangeCallback(const std::string &pkgName, std::shared_ptr<DevTrustChangeCallback> callback);
67     void RegisterDeviceScreenStatusCallback(const std::string &pkgName,
68         std::shared_ptr<DeviceScreenStatusCallback> callback);
69     void UnRegisterDeviceScreenStatusCallback(const std::string &pkgName);
70     void RegisterCredentialAuthStatusCallback(const std::string &pkgName,
71         std::shared_ptr<CredentialAuthStatusCallback> callback);
72     void UnRegisterCredentialAuthStatusCallback(const std::string &pkgName);
73     void RegisterSinkBindCallback(const std::string &pkgName, std::shared_ptr<BindTargetCallback> callback);
74     void UnRegisterSinkBindCallback(const std::string &pkgName);
75 
76     int32_t RegisterGetDeviceProfileInfoListCallback(const std::string &pkgName,
77         std::shared_ptr<GetDeviceProfileInfoListCallback> callback);
78     void OnGetDeviceProfileInfoListResult(const std::string &pkgName,
79         const std::vector<DmDeviceProfileInfo> &deviceProfileInfos, int32_t code);
80     int32_t RegisterGetDeviceIconInfoCallback(const std::string &pkgName, const std::string &uk,
81         std::shared_ptr<GetDeviceIconInfoCallback> callback);
82     void OnGetDeviceIconInfoResult(const std::string &pkgName, const DmDeviceIconInfo &deviceIconInfo, int32_t code);
83     int32_t RegisterSetLocalDeviceNameCallback(const std::string &pkgName,
84         std::shared_ptr<SetLocalDeviceNameCallback> callback);
85     void OnSetLocalDeviceNameResult(const std::string &pkgName, int32_t code);
86     int32_t RegisterSetRemoteDeviceNameCallback(const std::string &pkgName, const std::string &deviceId,
87         std::shared_ptr<SetRemoteDeviceNameCallback> callback);
88     void OnSetRemoteDeviceNameResult(const std::string &pkgName, const std::string &deviceId, int32_t code);
89     void UnRegisterPinHolderCallback(const std::string &pkgName);
90 
91 public:
92     static void DeviceInfoOnline(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk);
93     static void DeviceInfoOffline(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk);
94     static void DeviceInfoChanged(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk);
95     static void DeviceInfoReady(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk);
96     static void DeviceBasicInfoOnline(const DmDeviceBasicInfo &deviceBasicInfo,
97         std::shared_ptr<DeviceStatusCallback> tempCbk);
98     static void DeviceBasicInfoOffline(const DmDeviceBasicInfo &deviceBasicInfo,
99         std::shared_ptr<DeviceStatusCallback> tempCbk);
100     static void DeviceBasicInfoChanged(const DmDeviceBasicInfo &deviceBasicInfo,
101         std::shared_ptr<DeviceStatusCallback> tempCbk);
102     static void DeviceBasicInfoReady(const DmDeviceBasicInfo &deviceBasicInfo,
103         std::shared_ptr<DeviceStatusCallback> tempCbk);
104     static void DeviceTrustChange(const std::string &udid, const std::string &uuid, DmAuthForm authForm,
105         std::shared_ptr<DevTrustChangeCallback> tempCbk);
106 public:
107     void OnRemoteDied();
108     void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
109     void OnDeviceOnline(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
110     void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
111     void OnDeviceOffline(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
112     void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
113     void OnDeviceChanged(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
114     void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
115     void OnDeviceReady(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
116     void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo);
117     void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceBasicInfo &deviceBasicInfo);
118     void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason);
119     void OnDiscoverySuccess(const std::string &pkgName, uint16_t subscribeId);
120     void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult);
121     void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token,
122                       int32_t status, int32_t reason);
123     void OnUiCall(std::string &pkgName, std::string &paramJson);
124     void OnCredentialResult(const std::string &pkgName, int32_t &action, const std::string &credentialResult);
125     void OnPinHolderCreate(const std::string &deviceId, const std::string &pkgName, DmPinType pinType,
126         const std::string &payload);
127     void OnPinHolderDestroy(const std::string &pkgName, DmPinType pinType, const std::string &payload);
128     void OnCreateResult(const std::string &pkgName, int32_t result);
129     void OnDestroyResult(const std::string &pkgName, int32_t result);
130     void OnPinHolderEvent(const std::string &pkgName, DmPinHolderEvent event, int32_t result,
131                           const std::string &content);
132     std::map<std::string, std::shared_ptr<DmInitCallback>> GetDmInitCallback();
133     void OnDeviceTrustChange(const std::string &pkgName, const std::string &udid, const std::string &uuid,
134         int32_t authForm);
135     void OnDeviceScreenStatus(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
136     void OnCredentialAuthStatus(const std::string &pkgName, const std::string &deviceList,
137                                 uint16_t deviceTypeId, int32_t errcode);
138     void OnSinkBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, int32_t status,
139         std::string content);
140     std::shared_ptr<DiscoveryCallback> GetDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId);
141     void GetCallBack(std::map<DmCommonNotifyEvent, std::set<std::string>> &callbackMap);
142 
143 private:
144 #if !defined(__LITEOS_M__)
145     std::mutex lock_;
146 #endif
147     std::map<std::string, std::shared_ptr<DeviceStateCallback>> deviceStateCallback_;
148     std::map<std::string, std::shared_ptr<DeviceStatusCallback>> deviceStatusCallback_;
149     std::map<std::string, std::map<uint16_t, std::shared_ptr<DiscoveryCallback>>> deviceDiscoveryCallbacks_;
150     std::map<std::string, std::map<int32_t, std::shared_ptr<PublishCallback>>> devicePublishCallbacks_;
151     std::map<std::string, std::map<std::string, std::shared_ptr<AuthenticateCallback>>> authenticateCallback_;
152     std::map<std::string, std::shared_ptr<DmInitCallback>> dmInitCallback_;
153     std::map<std::string, std::shared_ptr<DeviceManagerUiCallback>> dmUiCallback_;
154     std::map<std::string, std::shared_ptr<CredentialCallback>> credentialCallback_;
155     std::map<std::string, std::map<PeerTargetId, std::shared_ptr<BindTargetCallback>>> bindCallback_;
156     std::map<std::string, std::map<PeerTargetId, std::shared_ptr<UnbindTargetCallback>>> unbindCallback_;
157     std::map<std::string, std::shared_ptr<PinHolderCallback>> pinHolderCallback_;
158     std::map<std::string, std::shared_ptr<DevTrustChangeCallback>> devTrustChangeCallback_;
159     std::map<std::string, std::shared_ptr<DeviceScreenStatusCallback>> deviceScreenStatusCallback_;
160     std::map<std::string, std::shared_ptr<CredentialAuthStatusCallback>> credentialAuthStatusCallback_;
161     std::map<std::string, std::shared_ptr<BindTargetCallback>> sinkBindTargetCallback_;
162     std::mutex bindLock_;
163     std::map<std::string, std::shared_ptr<GetDeviceProfileInfoListCallback>> getDeviceProfileInfoCallback_;
164     std::map<std::string,
165         std::map<std::string, std::set<std::shared_ptr<GetDeviceIconInfoCallback>>>> getDeviceIconInfoCallback_;
166     std::map<std::string, std::shared_ptr<SetLocalDeviceNameCallback>> setLocalDeviceNameCallback_;
167     std::map<std::string,
168         std::map<std::string, std::shared_ptr<SetRemoteDeviceNameCallback>>> setRemoteDeviceNameCallback_;
169 };
170 } // namespace DistributedHardware
171 } // namespace OHOS
172 #endif // OHOS_DM_NOTIFY_H
173