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_KV_ADAPTER_MANAGER_H 17 #define OHOS_DM_KV_ADAPTER_MANAGER_H 18 19 #include <atomic> 20 #include <map> 21 #include <memory> 22 #include <string> 23 24 #include "dm_single_instance.h" 25 26 #include "kv_adapter.h" 27 28 namespace OHOS { 29 namespace DistributedHardware { 30 31 class KVAdapterManager { 32 DM_DECLARE_SINGLE_INSTANCE_BASE(KVAdapterManager); 33 public: 34 DM_EXPORT int32_t Init(); 35 DM_EXPORT void UnInit(); 36 DM_EXPORT void ReInit(); 37 int32_t PutByAnoyDeviceId(const std::string &key, const DmKVValue &value); 38 DM_EXPORT int32_t Get(const std::string &key, DmKVValue &value); 39 DM_EXPORT int32_t DeleteAgedEntry(); 40 DM_EXPORT int32_t AppUnintall(const std::string &appId); 41 DM_EXPORT int32_t GetFreezeData(const std::string &key, std::string &value); 42 DM_EXPORT int32_t PutFreezeData(const std::string &key, std::string &value); 43 DM_EXPORT int32_t DeleteFreezeData(const std::string &key); 44 DM_EXPORT int32_t GetAllOstypeData(std::vector<std::string> &values); 45 DM_EXPORT int32_t PutOstypeData(const std::string &key, const std::string &value); 46 DM_EXPORT int32_t DeleteOstypeData(const std::string &key); 47 DM_EXPORT int32_t GetLocalUserIdData(const std::string &key, std::string &value); 48 DM_EXPORT int32_t PutLocalUserIdData(const std::string &key, const std::string &value); 49 DM_EXPORT int32_t GetOsTypeCount(int32_t &count); 50 51 private: 52 KVAdapterManager() = default; 53 ~KVAdapterManager() = default; 54 inline bool IsTimeOut(int64_t sourceTime, int64_t targetTime, int64_t timeOut); 55 56 private: 57 std::shared_ptr<DistributedKv::KvStoreDeathRecipient> deathRecipient_ = nullptr; 58 std::shared_ptr<KVAdapter> kvAdapter_ = nullptr; 59 std::mutex idCacheMapMtx_; 60 std::map<std::string, DmKVValue> idCacheMap_; 61 }; 62 } // namespace DistributedHardware 63 } // namespace OHOS 64 #endif // OHOS_DM_KV_ADAPTER_MANAGER_H 65