179a732c7Sopenharmony_ci/*
279a732c7Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License.
579a732c7Sopenharmony_ci * You may obtain a copy of the License at
679a732c7Sopenharmony_ci *
779a732c7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
879a732c7Sopenharmony_ci *
979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and
1379a732c7Sopenharmony_ci * limitations under the License.
1479a732c7Sopenharmony_ci */
1579a732c7Sopenharmony_ci
1679a732c7Sopenharmony_ci#ifndef OHOS_DM_SOFTBUS_CACHE_H
1779a732c7Sopenharmony_ci#define OHOS_DM_SOFTBUS_CACHE_H
1879a732c7Sopenharmony_ci
1979a732c7Sopenharmony_ci#include <cstdint>
2079a732c7Sopenharmony_ci#include <string>
2179a732c7Sopenharmony_ci#include <mutex>
2279a732c7Sopenharmony_ci#include "dm_device_info.h"
2379a732c7Sopenharmony_ci#include "dm_single_instance.h"
2479a732c7Sopenharmony_ci#include "softbus_bus_center.h"
2579a732c7Sopenharmony_ci#include "softbus_common.h"
2679a732c7Sopenharmony_ci
2779a732c7Sopenharmony_cinamespace OHOS {
2879a732c7Sopenharmony_cinamespace DistributedHardware {
2979a732c7Sopenharmony_ciclass SoftbusCache {
3079a732c7Sopenharmony_ci    DM_DECLARE_SINGLE_INSTANCE(SoftbusCache);
3179a732c7Sopenharmony_ci
3279a732c7Sopenharmony_cipublic:
3379a732c7Sopenharmony_ci    void SaveDeviceInfo(DmDeviceInfo deviceInfo);
3479a732c7Sopenharmony_ci    void DeleteDeviceInfo(const DmDeviceInfo &nodeInfo);
3579a732c7Sopenharmony_ci    void ChangeDeviceInfo(const DmDeviceInfo deviceInfo);
3679a732c7Sopenharmony_ci    void SaveDeviceSecurityLevel(const char *networkId);
3779a732c7Sopenharmony_ci    void DeleteDeviceSecurityLevel(const char *networkId);
3879a732c7Sopenharmony_ci    int32_t GetDeviceInfoFromCache(std::vector<DmDeviceInfo> &deviceInfoList);
3979a732c7Sopenharmony_ci    int32_t GetUdidFromCache(const char *networkId, std::string &udid);
4079a732c7Sopenharmony_ci    int32_t GetUuidFromCache(const char *networkId, std::string &uuid);
4179a732c7Sopenharmony_ci    int32_t GetSecurityDeviceLevel(const char *networkId, int32_t &securityLevel);
4279a732c7Sopenharmony_ci    void UpdateDeviceInfoCache();
4379a732c7Sopenharmony_ci    void SaveLocalDeviceInfo();
4479a732c7Sopenharmony_ci    void DeleteLocalDeviceInfo();
4579a732c7Sopenharmony_ci    int32_t GetLocalDeviceInfo(DmDeviceInfo &nodeInfo);
4679a732c7Sopenharmony_ci    int32_t GetDevInfoByNetworkId(const std::string &networkId, DmDeviceInfo &nodeInfo);
4779a732c7Sopenharmony_ci    void UpDataLocalDevInfo();
4879a732c7Sopenharmony_ci    int32_t GetUdidByUdidHash(const std::string &udidHash, std::string &udid);
4979a732c7Sopenharmony_ci    int32_t GetUuidByUdid(const std::string &udid, std::string &uuid);
5079a732c7Sopenharmony_ci    int32_t GetNetworkIdFromCache(const std::string &udid, std::string &networkId);
5179a732c7Sopenharmony_ci    bool CheckIsOnline(const std::string &udidHash);
5279a732c7Sopenharmony_ciprivate:
5379a732c7Sopenharmony_ci    int32_t GetUdidByNetworkId(const char *networkId, std::string &udid);
5479a732c7Sopenharmony_ci    int32_t GetUuidByNetworkId(const char *networkId, std::string &uuid);
5579a732c7Sopenharmony_ci    int32_t ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeInfo, DmDeviceInfo &devInfo);
5679a732c7Sopenharmony_ci    int32_t GetDevInfoFromBus(const std::string &networkId, DmDeviceInfo &devInfo);
5779a732c7Sopenharmony_ci    int32_t GetDevLevelFromBus(const char *networkId, int32_t &securityLevel);
5879a732c7Sopenharmony_ci
5979a732c7Sopenharmony_ciprivate:
6079a732c7Sopenharmony_ci    std::mutex deviceInfosMutex_;
6179a732c7Sopenharmony_ci    std::mutex deviceSecurityLevelMutex_;
6279a732c7Sopenharmony_ci    std::unordered_map<std::string, std::pair<std::string, DmDeviceInfo>> deviceInfo_;
6379a732c7Sopenharmony_ci    std::unordered_map<std::string, int32_t> deviceSecurityLevel_;
6479a732c7Sopenharmony_ci};
6579a732c7Sopenharmony_ci} // namespace DistributedHardware
6679a732c7Sopenharmony_ci} // namespace OHOS
6779a732c7Sopenharmony_ci#endif // OHOS_DM_PERMISSION_STANDARD_PERMISSION_MANAGER_H
68