1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 DEVCIES_MEADIA_LIBRARY_INFO_INTERACTION_H 17 #define DEVCIES_MEADIA_LIBRARY_INFO_INTERACTION_H 18 19 #include "distributed_kv_data_manager.h" 20 #include "nlohmann/json.hpp" 21 22 namespace OHOS { 23 namespace Sharing { 24 25 constexpr char SHARING_INFOS[] = "sharingInfos"; 26 constexpr char VALID_PID[] = "validPid"; 27 constexpr char ENABLE_HARDWARE[] = "enableHardware"; 28 29 class KvOperator final : public DistributedKv::KvStoreSyncCallback, 30 public std::enable_shared_from_this<KvOperator> { 31 public: 32 KvOperator() = default; 33 KvOperator(const KvOperator&) = delete; 34 KvOperator(const KvOperator&&) = delete; 35 virtual ~KvOperator() = default; 36 37 KvOperator& operator=(const KvOperator&) = delete; 38 KvOperator& operator=(const KvOperator&&) = delete; 39 40 void OpenKvStore(); 41 void CloseKvStore(); 42 void SyncKvStore(const std::string &key, const std::string &deviceId); 43 void SyncCompleted(const std::map<std::string, DistributedKv::Status> &results) override; 44 45 bool GetValues(const std::string &key, std::string &val); 46 bool PutValues(const std::string &key, std::string values); 47 48 bool StringToJson(const std::string &str, nlohmann::json &jsonObj); 49 bool JsonToString(const nlohmann::json &jsonObj, std::string &str); 50 bool QueryFromJson(const nlohmann::json &jsonObj, const std::string &key, std::string &val); 51 52 private: 53 std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_; 54 55 DistributedKv::DistributedKvDataManager dataManager_; 56 }; 57 58 } // namespace Media 59 } // namespace OHOS 60 #endif 61