1 /* 2 * Copyright (c) 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_DM_SOFTBUS_CACHE_H 17 #define OHOS_DM_SOFTBUS_CACHE_H 18 19 #include <cstdint> 20 #include <string> 21 #include <mutex> 22 #include "dm_device_info.h" 23 #include "dm_single_instance.h" 24 #include "softbus_bus_center.h" 25 #include "softbus_common.h" 26 27 namespace OHOS { 28 namespace DistributedHardware { 29 class SoftbusCache { 30 DM_DECLARE_SINGLE_INSTANCE(SoftbusCache); 31 32 public: 33 void SaveDeviceInfo(DmDeviceInfo deviceInfo); 34 void DeleteDeviceInfo(const DmDeviceInfo &nodeInfo); 35 void DeleteDeviceInfo(); 36 void ChangeDeviceInfo(const DmDeviceInfo deviceInfo); 37 void SaveDeviceSecurityLevel(const char *networkId); 38 void DeleteDeviceSecurityLevel(const char *networkId); 39 int32_t GetDeviceInfoFromCache(std::vector<DmDeviceInfo> &deviceInfoList); 40 int32_t GetUdidFromCache(const char *networkId, std::string &udid); 41 int32_t GetUuidFromCache(const char *networkId, std::string &uuid); 42 int32_t GetSecurityDeviceLevel(const char *networkId, int32_t &securityLevel); 43 void UpdateDeviceInfoCache(); 44 void SaveLocalDeviceInfo(); 45 void DeleteLocalDeviceInfo(); 46 int32_t GetLocalDeviceInfo(DmDeviceInfo &nodeInfo); 47 int32_t GetDevInfoByNetworkId(const std::string &networkId, DmDeviceInfo &nodeInfo); 48 void UpDataLocalDevInfo(); 49 int32_t GetUdidByUdidHash(const std::string &udidHash, std::string &udid); 50 int32_t GetUuidByUdid(const std::string &udid, std::string &uuid); 51 int32_t GetNetworkIdFromCache(const std::string &udid, std::string &networkId); 52 int32_t GetDeviceNameFromCache(const std::string &udid, std::string &deviceName); 53 bool CheckIsOnline(const std::string &udidHash); 54 bool CheckIsOnlineByPeerUdid(const std::string &peerUdid); 55 private: 56 int32_t GetUdidByNetworkId(const char *networkId, std::string &udid); 57 int32_t GetUuidByNetworkId(const char *networkId, std::string &uuid); 58 int32_t ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeInfo, DmDeviceInfo &devInfo); 59 int32_t GetDevInfoFromBus(const std::string &networkId, DmDeviceInfo &devInfo); 60 int32_t GetDevLevelFromBus(const char *networkId, int32_t &securityLevel); 61 62 private: 63 std::mutex deviceInfosMutex_; 64 std::mutex deviceSecurityLevelMutex_; 65 std::unordered_map<std::string, std::pair<std::string, DmDeviceInfo>> deviceInfo_; 66 std::unordered_map<std::string, int32_t> deviceSecurityLevel_; 67 }; 68 } // namespace DistributedHardware 69 } // namespace OHOS 70 #endif // OHOS_DM_PERMISSION_STANDARD_PERMISSION_MANAGER_H 71