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 38 private: 39 friend class DmDeathCallback; 40 DevManager(const std::string &pkgName); 41 ~DevManager() = default; 42 void RegisterDevCallback(); 43 void UpdateBucket(); 44 DetailInfo GetDevInfoFromBucket(const std::string &id); 45 46 int32_t Init(); 47 std::function<void()> Retry(); 48 const std::string PKG_NAME; 49 const DetailInfo invalidDetail_ {}; 50 DetailInfo localInfo_ {}; 51 DetailInfo UnEncryptedLocalInfo_ {}; 52 mutable std::mutex mutex_ {}; 53 mutable LRUBucket<std::string, DetailInfo> deviceInfos_ {64}; 54 }; 55 } // namespace OHOS::DistributedKv 56 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_DEV_MANAGER_H 57