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 ChangeDeviceInfo(const DmDeviceInfo deviceInfo); 36 void SaveDeviceSecurityLevel(const char *networkId); 37 void DeleteDeviceSecurityLevel(const char *networkId); 38 int32_t GetDeviceInfoFromCache(std::vector<DmDeviceInfo> &deviceInfoList); 39 int32_t GetUdidFromCache(const char *networkId, std::string &udid); 40 int32_t GetUuidFromCache(const char *networkId, std::string &uuid); 41 int32_t GetSecurityDeviceLevel(const char *networkId, int32_t &securityLevel); 42 void UpdateDeviceInfoCache(); 43 void SaveLocalDeviceInfo(); 44 void DeleteLocalDeviceInfo(); 45 int32_t GetLocalDeviceInfo(DmDeviceInfo &nodeInfo); 46 int32_t GetDevInfoByNetworkId(const std::string &networkId, DmDeviceInfo &nodeInfo); 47 void UpDataLocalDevInfo(); 48 int32_t GetNetworkIdFromCache(const std::string &udid, std::string &networkId); 49 50 private: 51 int32_t GetUdidByNetworkId(const char *networkId, std::string &udid); 52 int32_t GetUuidByNetworkId(const char *networkId, std::string &uuid); 53 int32_t ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeInfo, DmDeviceInfo &devInfo); 54 int32_t GetDevInfoFromBus(const std::string &networkId, DmDeviceInfo &devInfo); 55 int32_t GetDevLevelFromBus(const char *networkId, int32_t &securityLevel); 56 57 private: 58 std::mutex deviceInfosMutex_; 59 std::mutex deviceSecurityLevelMutex_; 60 std::unordered_map<std::string, std::pair<std::string, DmDeviceInfo>> deviceInfo_; 61 std::unordered_map<std::string, int32_t> deviceSecurityLevel_; 62 }; 63 } // namespace DistributedHardware 64 } // namespace OHOS 65 #endif // OHOS_DM_PERMISSION_STANDARD_PERMISSION_MANAGER_H 66