• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr<DeviceManagerUiCallback> callback);
53     void UnRegisterDeviceManagerFaCallback(const std::string &pkgName);
54     void RegisterCredentialCallback(const std::string &pkgName, std::shared_ptr<CredentialCallback> callback);
55     void UnRegisterCredentialCallback(const std::string &pkgName);
56     void RegisterBindCallback(const std::string &pkgName, const PeerTargetId &targetId,
57         std::shared_ptr<BindTargetCallback> callback);
58     void RegisterUnbindCallback(const std::string &pkgName, const PeerTargetId &targetId,
59         std::shared_ptr<UnbindTargetCallback> callback);
60     void OnBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, int32_t status,
61         std::string content);
62     void OnUnbindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, std::string content);
63     void RegisterPinHolderCallback(const std::string &pkgName, std::shared_ptr<PinHolderCallback> callback);
64 
65 public:
66     void OnRemoteDied();
67     void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
68     void OnDeviceOnline(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
69     void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
70     void OnDeviceOffline(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
71     void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
72     void OnDeviceChanged(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
73     void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
74     void OnDeviceReady(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
75     void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo);
76     void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceBasicInfo &deviceBasicInfo);
77     void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason);
78     void OnDiscoverySuccess(const std::string &pkgName, uint16_t subscribeId);
79     void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult);
80     void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token,
81                       int32_t status, int32_t reason);
82     void OnUiCall(std::string &pkgName, std::string &paramJson);
83     void OnCredentialResult(const std::string &pkgName, int32_t &action, const std::string &credentialResult);
84     void OnPinHolderCreate(const std::string &deviceId, const std::string &pkgName, DmPinType pinType,
85         const std::string &payload);
86     void OnPinHolderDestroy(const std::string &pkgName, DmPinType pinType, const std::string &payload);
87     void OnCreateResult(const std::string &pkgName, int32_t result);
88     void OnDestroyResult(const std::string &pkgName, int32_t result);
89     std::map<std::string, std::shared_ptr<DmInitCallback>> GetDmInitCallback();
90 
91 private:
92 #if !defined(__LITEOS_M__)
93     std::mutex lock_;
94 #endif
95     std::map<std::string, std::shared_ptr<DeviceStateCallback>> deviceStateCallback_;
96     std::map<std::string, std::shared_ptr<DeviceStatusCallback>> deviceStatusCallback_;
97     std::map<std::string, std::map<uint16_t, std::shared_ptr<DiscoveryCallback>>> deviceDiscoveryCallbacks_;
98     std::map<std::string, std::map<int32_t, std::shared_ptr<PublishCallback>>> devicePublishCallbacks_;
99     std::map<std::string, std::map<std::string, std::shared_ptr<AuthenticateCallback>>> authenticateCallback_;
100     std::map<std::string, std::shared_ptr<DmInitCallback>> dmInitCallback_;
101     std::map<std::string, std::shared_ptr<DeviceManagerUiCallback>> dmUiCallback_;
102     std::map<std::string, std::shared_ptr<CredentialCallback>> credentialCallback_;
103     std::map<std::string, std::map<PeerTargetId, std::shared_ptr<BindTargetCallback>>> bindCallback_;
104     std::map<std::string, std::map<PeerTargetId, std::shared_ptr<UnbindTargetCallback>>> unbindCallback_;
105     std::map<std::string, std::shared_ptr<PinHolderCallback>> pinHolderCallback_;
106 };
107 } // namespace DistributedHardware
108 } // namespace OHOS
109 #endif // OHOS_DM_NOTIFY_H
110