/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_DM_SOFTBUS_CACHE_H #define OHOS_DM_SOFTBUS_CACHE_H #include #include #include #include "dm_device_info.h" #include "dm_single_instance.h" #include "softbus_bus_center.h" #include "softbus_common.h" namespace OHOS { namespace DistributedHardware { class SoftbusCache { DM_DECLARE_SINGLE_INSTANCE(SoftbusCache); public: void SaveDeviceInfo(DmDeviceInfo deviceInfo); void DeleteDeviceInfo(const DmDeviceInfo &nodeInfo); void ChangeDeviceInfo(const DmDeviceInfo deviceInfo); void SaveDeviceSecurityLevel(const char *networkId); void DeleteDeviceSecurityLevel(const char *networkId); int32_t GetDeviceInfoFromCache(std::vector &deviceInfoList); int32_t GetUdidFromCache(const char *networkId, std::string &udid); int32_t GetUuidFromCache(const char *networkId, std::string &uuid); int32_t GetSecurityDeviceLevel(const char *networkId, int32_t &securityLevel); void UpdateDeviceInfoCache(); void SaveLocalDeviceInfo(); void DeleteLocalDeviceInfo(); int32_t GetLocalDeviceInfo(DmDeviceInfo &nodeInfo); int32_t GetDevInfoByNetworkId(const std::string &networkId, DmDeviceInfo &nodeInfo); void UpDataLocalDevInfo(); int32_t GetNetworkIdFromCache(const std::string &udid, std::string &networkId); private: int32_t GetUdidByNetworkId(const char *networkId, std::string &udid); int32_t GetUuidByNetworkId(const char *networkId, std::string &uuid); int32_t ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeInfo, DmDeviceInfo &devInfo); int32_t GetDevInfoFromBus(const std::string &networkId, DmDeviceInfo &devInfo); int32_t GetDevLevelFromBus(const char *networkId, int32_t &securityLevel); private: std::mutex deviceInfosMutex_; std::mutex deviceSecurityLevelMutex_; std::unordered_map> deviceInfo_; std::unordered_map deviceSecurityLevel_; }; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_PERMISSION_STANDARD_PERMISSION_MANAGER_H