• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SERVICE_LISTENER_H
17 #define OHOS_DM_SERVICE_LISTENER_H
18 
19 #include <map>
20 #include <string>
21 #include <mutex>
22 
23 #include "dm_device_info.h"
24 #include "idevice_manager_service_listener.h"
25 #if !defined(__LITEOS_M__)
26 #include "ipc_notify_dmfa_result_req.h"
27 #include "ipc_server_listener.h"
28 #endif
29 
30 namespace OHOS {
31 namespace DistributedHardware {
32 class DeviceManagerServiceListener : public IDeviceManagerServiceListener {
33 public:
DeviceManagerServiceListener()34     DeviceManagerServiceListener() {};
~DeviceManagerServiceListener()35     virtual ~DeviceManagerServiceListener() {};
36 
37     void OnDeviceStateChange(const std::string &pkgName, const DmDeviceState &state, const DmDeviceInfo &info);
38 
39     void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &info);
40 
41     void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, DmDeviceBasicInfo &info);
42 
43     void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason);
44 
45     void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId);
46 
47     void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult);
48 
49     void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token, int32_t status,
50                       int32_t reason);
51 
52     void OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId, int32_t resultCode,
53                             const std::string &flag);
54 
55     void OnUiCall(std::string &pkgName, std::string &paramJson);
56 
57     void OnCredentialResult(const std::string &pkgName, int32_t action, const std::string &resultInfo);
58 
59     void DeleteDeviceIdFromMap(const std::string &deviceId);
60     void RegisterDmListener(const std::string &pkgName, const std::string &appId);
61     void UnRegisterDmListener(const std::string &pkgName);
62     std::string GetAppId(const std::string &pkgName);
63     std::string CalcDeviceId(const std::string &udidHash, const std::string &appId);
64     void SetUdidHashMap(const std::string &udidHash, const std::string &deviceId);
65     std::string GetDeviceId(const std::string &udidHash);
66     std::string GetUdidHash(const std::string &deviceId);
67 
68 private:
69     void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName,
70         const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo);
71 private:
72 #if !defined(__LITEOS_M__)
73     IpcServerListener ipcServerListener_;
74     static std::mutex dmListenerMapLock_;
75     static std::map<std::string, std::string> dmListenerMap_;
76     static std::mutex udidHashMapLock_;
77     static std::map<std::string, std::string> udidHashMap_;
78 #endif
79 };
80 } // namespace DistributedHardware
81 } // namespace OHOS
82 #endif // OHOS_DM_SERVICE_LISTENER_H