• 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_SERVICE_IMPL_H
17 #define OHOS_DM_SERVICE_IMPL_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "dm_ability_manager.h"
23 #include "dm_auth_manager.h"
24 #include "dm_common_event_manager.h"
25 #include "dm_credential_manager.h"
26 #include "dm_device_info.h"
27 #include "dm_device_state_manager.h"
28 #include "dm_discovery_manager.h"
29 #include "dm_publish_manager.h"
30 #include "idevice_manager_service_impl.h"
31 #include "single_instance.h"
32 #include "softbus_connector.h"
33 
34 namespace OHOS {
35 namespace DistributedHardware {
36 class DeviceManagerServiceImpl : public IDeviceManagerServiceImpl {
37 public:
38     DeviceManagerServiceImpl();
39     virtual ~DeviceManagerServiceImpl();
40 
41     int32_t Initialize(const std::shared_ptr<IDeviceManagerServiceListener> &listener);
42 
43     void Release();
44 
45     int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
46                                  const std::string &extra);
47 
48     int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId);
49 
50     int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo);
51 
52     int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId);
53 
54     int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId,
55                                const std::string &extra);
56 
57     int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId);
58 
59     int32_t VerifyAuthentication(const std::string &authParam);
60 
61     int32_t GetFaParam(std::string &pkgName, DmAuthParam &authParam);
62 
63     int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string &params);
64 
65     int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra);
66 
67     int32_t UnRegisterDevStateCallback(const std::string &pkgName, const std::string &extra);
68 
69     void HandleDeviceOnline(const DmDeviceInfo &info);
70 
71     void HandleDeviceOffline(const DmDeviceInfo &info);
72 
73     int OnSessionOpened(int sessionId, int result);
74 
75     void OnSessionClosed(int sessionId);
76 
77     void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen);
78 
79     int32_t RequestCredential(const std::string &reqJsonStr, std::string &returnJsonStr);
80 
81     int32_t ImportCredential(const std::string &pkgName, const std::string &credentialInfo);
82 
83     int32_t DeleteCredential(const std::string &pkgName, const std::string &deleteInfo);
84 
85     int32_t RegisterCredentialCallback(const std::string &pkgName);
86 
87     int32_t UnRegisterCredentialCallback(const std::string &pkgName);
88 
89     int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event);
90 
91     void LoadHardwareFwkService();
92 
93     int32_t GetEncryptedUuidByNetworkId(const std::string &pkgName, const std::string &networkId,
94     std::string &uuid);
95 
96     int32_t GenerateEncryptedUuid(const std::string &pkgName, const std::string &uuid,
97     const std::string &appId, std::string &encryptedUuid);
98 private:
99     int32_t PraseNotifyEventJson(const std::string &event, nlohmann::json &jsonObject);
100 private:
101     std::shared_ptr<DmAuthManager> authMgr_;
102     std::shared_ptr<DmDeviceStateManager> deviceStateMgr_;
103     std::shared_ptr<DmDiscoveryManager> discoveryMgr_;
104     std::shared_ptr<DmPublishManager> publishMgr_;
105     std::shared_ptr<SoftbusConnector> softbusConnector_;
106     std::shared_ptr<DmAbilityManager> abilityMgr_;
107     std::shared_ptr<HiChainConnector> hiChainConnector_;
108     std::shared_ptr<DmCredentialManager> credentialMgr_;
109     std::shared_ptr<DmCommonEventManager> commonEventManager_;
110 };
111 
112 using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void);
113 } // namespace DistributedHardware
114 } // namespace OHOS
115 #endif // OHOS_DM_SERVICE_IMPL_H
116