• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_DEVICE_MANAGER_SOFTBUS_ADAPTER_H
17 #define OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H
18 
19 #include <string>
20 #include <mutex>
21 #include <map>
22 #include <memory>
23 #include <vector>
24 #include <list>
25 #include "softbus_bus_center.h"
26 #include "discovery_service.h"
27 #include "dm_device_info.h"
28 #include "dm_subscribe_info.h"
29 
30 namespace OHOS {
31 namespace DistributedHardware {
32 class PublishServiceCallBack {
33 public:
34     static void OnPublishSuccess(int publishId);
35     static void OnPublishFail(int publishId, PublishFailReason reason);
36 };
37 
38 class SoftbusAdapter {
39 public:
40     static int32_t Init();
41     static int32_t GetTrustDevices(const std::string &pkgName, NodeBasicInfo **info, int32_t *infoNum);
42     static int32_t StartDiscovery(std::string &pkgName, SubscribeInfo *info);
43     static int32_t StopDiscovery(std::string &pkgName, uint16_t subscribeId);
44     static bool IsDeviceOnLine(std::string &deviceId);
45     static int32_t GetConnectionIpAddr(std::string deviceId, std::string &ipAddr);
46     static ConnectionAddr *GetConnectAddr(std::string deviceId);
47 public:
48     static void OnDeviceStateChange(DmDeviceState state, DmDeviceInfo &deviceInfo);
49     static void OnSoftBusDeviceOnline(NodeBasicInfo *info);
50     static void OnSoftbusDeviceOffline(NodeBasicInfo *info);
51     static void OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info);
52     static void OnSoftbusDeviceFound(const DeviceInfo *device);
53     static void OnSoftbusDiscoverFailed(int subscribeId, DiscoveryFailReason failReason);
54     static void OnSoftbusDiscoverySuccess(int subscribeId);
55 private:
56     static bool GetsubscribeIdAdapter(std::string &pkgName, int16_t originId, int32_t &adapterId);
57     static bool GetpkgNameBySubscribeId(int32_t adapterId, std::string &pkgName);
58     static void SaveDiscoverDeviceInfo(const DeviceInfo *deviceInfo);
59     static void RemoveDiscoverDeviceInfo(const std::string deviceId);
60     static void NodeBasicInfoCopyToDmDevice(DmDeviceInfo &dmDeviceInfo, NodeBasicInfo &nodeBasicInfo);
61     static void DeviceInfoCopyToDmDevice(DmDeviceInfo &dmDeviceInfo, const DeviceInfo &deviceInfo);
62     static ConnectionAddr *GetConnectAddrByType(DeviceInfo *deviceInfo, ConnectionAddrType type);
63 private:
64     struct SubscribeInfoAdapter {
65         SubscribeInfo info;
66         uint16_t subscribeIdOrigin;
67         uint16_t subscribeIdPrefix;
68     };
69     static std::map<std::string, std::vector<std::shared_ptr<SubscribeInfoAdapter>>> subscribeInfos_;
70     static std::map<std::string, std::shared_ptr<DeviceInfo>> discoverDeviceInfoMap_;
71     static std::vector<std::shared_ptr<DeviceInfo>> discoverDeviceInfoVector_;
72     static uint16_t subscribeIdPrefix;
73     // static std::mutex lock_;
74     static INodeStateCb softbusNodeStateCb_;
75     static IDiscoveryCallback softbusDiscoverCallback_;
76     static IPublishCallback servicePublishCallback_;
77 };
78 } // namespace DistributedHardware
79 } // namespace OHOS
80 #endif // OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H
81