1 /* 2 * Copyright (c) 2023-2024 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_DISCOVERY_MANAGER_H 17 #define OHOS_DISCOVERY_MANAGER_H 18 19 #include <set> 20 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) 21 #include "deviceprofile_connector.h" 22 #endif 23 #include "discovery_filter.h" 24 #include "idevice_manager_service_listener.h" 25 #include "dm_timer.h" 26 #include "softbus_listener.h" 27 #include "mine_softbus_listener.h" 28 29 namespace OHOS { 30 namespace DistributedHardware { 31 typedef struct DiscoveryContext { 32 std::string pkgName; 33 std::string extra; 34 uint16_t subscribeId; 35 std::string filterOp; 36 std::vector<DeviceFilters> filters; 37 } DiscoveryContext; 38 39 typedef enum { 40 PROXY_TRANSMISION = 0, 41 PROXY_HEARTBEAT = 1, 42 PROXY_HICAR = 2, 43 PROXY_ACS = 3, 44 PROXY_SHARE = 4, 45 PROXY_CASTPLUS = 5, 46 PROXY_DM = 6, 47 PROXY_WEAR = 7, 48 PROXY_WINPC = 8, 49 PROXY_COLLABORATION_FWK = 9, 50 PROXY_DMSDP = 10, 51 CUSTOM_UNKNOWN, 52 } MetaNodeType; 53 54 class DiscoveryManager : public ISoftbusDiscoveringCallback, public std::enable_shared_from_this<DiscoveryManager> { 55 public: 56 DiscoveryManager(std::shared_ptr<SoftbusListener> softbusListener, 57 std::shared_ptr<IDeviceManagerServiceListener> listener); 58 ~DiscoveryManager() override; 59 60 // interfaces from ISoftbusDiscoveringCallback 61 void OnDeviceFound(const std::string &pkgName, const DmDeviceInfo &info, bool isOnline) override; 62 void OnDiscoveringResult(const std::string &pkgName, int32_t subscribeId, int32_t result) override; 63 int32_t StartDiscovering(const std::string &pkgName, const std::map<std::string, std::string> &discoverParam, 64 const std::map<std::string, std::string> &filterOptions); 65 int32_t StopDiscovering(const std::string &pkgName, uint16_t subscribeId); 66 int32_t EnableDiscoveryListener(const std::string &pkgName, const std::map<std::string, std::string> &discoverParam, 67 const std::map<std::string, std::string> &filterOptions); 68 int32_t DisableDiscoveryListener(const std::string &pkgName, const std::map<std::string, std::string> &extraParam); 69 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) 70 static IDeviceProfileConnector* GetCommonDependencyObj(); 71 static bool IsCommonDependencyReady(); 72 static bool CloseCommonDependencyObj(); 73 #endif 74 void ClearDiscoveryCache(const std::string &pkgName); 75 76 private: 77 void StartDiscoveryTimer(const std::string &pkgName); 78 void HandleDiscoveryTimeout(const std::string &pkgName); 79 int32_t StartDiscovering4MetaType(const std::string &pkgName, DmSubscribeInfo &dmSubInfo, 80 const std::map<std::string, std::string> ¶m); 81 int32_t StartDiscoveringNoMetaType(const std::string &pkgName, DmSubscribeInfo &dmSubInfo, 82 const std::map<std::string, std::string> ¶m); 83 int32_t StartDiscovering4MineLibary(const std::string &pkgName, DmSubscribeInfo &dmSubInfo, 84 const std::string &searchJson); 85 int32_t HandleDiscoveryQueue(const std::string &pkgName, uint16_t subscribeId, 86 const std::map<std::string, std::string> &filterOps); 87 int32_t GetDeviceAclParam(const std::string &pkgName, std::string deviceId, bool &isOnline, int32_t &authForm); 88 void ConfigDiscParam(const std::map<std::string, std::string> &discoverParam, DmSubscribeInfo *dmSubInfo); 89 bool CompareCapability(uint32_t capabilityType, const std::string &capabilityStr); 90 void OnDeviceFound(const std::string &pkgName, const uint32_t capabilityType, 91 const DmDeviceInfo &info, const DeviceFilterPara &filterPara); 92 void UpdateInfoFreq(const std::map<std::string, std::string> &discoverParam, DmSubscribeInfo &dmSubInfo); 93 94 private: 95 std::mutex locks_; 96 std::mutex subIdMapLocks_; 97 std::shared_ptr<DmTimer> timer_; 98 std::map<std::string, uint16_t> pkgName2SubIdMap_; 99 std::shared_ptr<SoftbusListener> softbusListener_; 100 std::shared_ptr<MineSoftbusListener> mineSoftbusListener_; 101 std::shared_ptr<IDeviceManagerServiceListener> listener_; 102 std::map<std::string, DiscoveryContext> discoveryContextMap_; 103 104 std::set<std::string> pkgNameSet_; 105 std::map<std::string, std::string> capabilityMap_; 106 std::mutex capabilityMapLocks_; 107 108 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) 109 static bool isSoLoaded_; 110 static IDeviceProfileConnector *dpConnector_; 111 static void *dpConnectorHandle_; 112 #endif 113 }; 114 } // namespace DistributedHardware 115 } // namespace OHOS 116 #endif // OHOS_DISCOVERY_MANAGER_H 117