1 /* 2 * Copyright (c) 2022 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 #ifndef OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_DEV_MANAGER_H 16 #define OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_DEV_MANAGER_H 17 #include <string> 18 #include "concurrent_map.h" 19 #include "types.h" 20 #include "lru_bucket.h" 21 namespace OHOS::DistributedKv { 22 class DevManager { 23 public: 24 static constexpr size_t MAX_ID_LEN = 64; 25 struct DetailInfo { 26 std::string uuid; 27 std::string networkId; 28 std::string deviceName; 29 std::string deviceType; 30 }; 31 static DevManager &GetInstance(); 32 std::string ToUUID(const std::string &networkId); 33 std::string ToNetworkId(const std::string &uuid); 34 const DetailInfo &GetLocalDevice(); 35 std::vector<DetailInfo> GetRemoteDevices(); 36 std::string GetUnEncryptedUuid(); 37 private: 38 friend class DmDeathCallback; 39 DevManager(const std::string &pkgName); 40 ~DevManager() = default; 41 void RegisterDevCallback(); 42 void UpdateBucket(); 43 DetailInfo GetDevInfoFromBucket(const std::string &id); 44 45 int32_t Init(); 46 std::function<void()> Retry(); 47 const std::string PKG_NAME; 48 const DetailInfo invalidDetail_ {}; 49 DetailInfo localInfo_ {}; 50 DetailInfo UnEncryptedLocalInfo_ {}; 51 mutable std::mutex mutex_ {}; 52 mutable LRUBucket<std::string, DetailInfo> deviceInfos_ {64}; 53 }; 54 } // namespace OHOS::DistributedKv 55 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_DEV_MANAGER_H 56