1 /* 2 * Copyright (C) 2023 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_MEDIALIBRARY_KVSTORE_H 17 #define OHOS_MEDIALIBRARY_KVSTORE_H 18 19 #include "distributed_kv_data_manager.h" 20 21 namespace OHOS { 22 namespace Media { 23 #define EXPORT __attribute__ ((visibility ("default"))) 24 const std::string KV_STORE_OWNER_DIR = "/storage/cloud/files/.thumbs/Photo"; 25 const std::string KV_STORE_VISITOR_DIR = "/storage/Share/.thumbs/Photo"; 26 27 enum class KvStoreRoleType : int32_t { 28 OWNER, 29 VISITOR, 30 }; 31 32 enum class KvStoreValueType : int32_t { 33 MONTH_ASTC, 34 YEAR_ASTC, 35 }; 36 37 class MediaLibraryKvStore { 38 public: 39 EXPORT MediaLibraryKvStore() = default; 40 EXPORT ~MediaLibraryKvStore() = default; 41 42 // return 0 means init KvStore success, others mean init kvstore fail 43 EXPORT int32_t Init(const KvStoreRoleType &roleType, const KvStoreValueType &valueType, const std::string &baseDir); 44 EXPORT int32_t Insert(const std::string &key, const std::vector<uint8_t> &value); 45 EXPORT int32_t Delete(const std::string &key); 46 EXPORT int32_t Query(const std::string &key, std::vector<uint8_t> &value); 47 EXPORT int32_t BatchQuery(std::vector<std::string> &batchKeys, std::vector<std::vector<uint8_t>> &values); 48 EXPORT bool Close(); 49 private: 50 bool GetKvStoreOption(DistributedKv::Options &options, const KvStoreRoleType &roleType, const std::string &baseDir); 51 52 std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_ = nullptr; 53 DistributedKv::DistributedKvDataManager dataManager_; 54 }; 55 } // namespace Media 56 } // namespace OHOS 57 58 #endif // OHOS_MEDIALIBRARY_KVSTORE_H