1 /* 2 * Copyright (c) 2021 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_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_H 16 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_H 17 18 #include <vector> 19 20 #include "serializable/serializable.h" 21 #include "store/store_info.h" 22 23 namespace OHOS::DistributedData { 24 struct API_EXPORT StoreMetaData final : public Serializable { 25 // record meta version for compatible, should update when modify store meta data structure. 26 static constexpr uint32_t CURRENT_VERSION = 0x03000006; 27 // UID -> uid, deviceAccountId -> userId, userId -> user 28 static constexpr uint32_t FIELD_CHANGED_TAG = 0x03000003; 29 static constexpr uint32_t UUID_CHANGED_TAG = 0x03000004; 30 static constexpr const char *KEY_PREFIX = "KvStoreMetaData"; 31 static constexpr const char *ROOT_USER = "0"; 32 uint32_t version = CURRENT_VERSION; 33 bool isAutoSync = false; 34 bool isBackup = false; 35 bool isDirty = false; 36 bool isEncrypt = false; 37 bool isManualClean = false; 38 bool isSearchable = false; 39 bool isNeedCompress = false; 40 bool enableCloud = false; 41 bool cloudAutoSync = false; 42 int32_t dataType = -1; 43 int32_t storeType = -1; 44 int32_t securityLevel = 0; 45 int32_t area = 0; 46 int32_t uid = -1; 47 int32_t instanceId = 0; 48 int32_t haMode = 0; 49 uint32_t tokenId = 0; 50 std::string appId = ""; 51 std::string appType = ""; 52 std::string bundleName = ""; 53 std::string hapName = ""; 54 std::string dataDir = ""; 55 std::string customDir = ""; 56 std::string deviceId = ""; 57 std::string schema = ""; 58 std::string storeId = ""; 59 std::string user = ""; 60 std::string account = ""; 61 int32_t authType = 0; 62 63 enum StoreType { 64 STORE_KV_BEGIN = 0, 65 STORE_KV_END = 9, 66 STORE_RELATIONAL_BEGIN = 10, 67 STORE_RELATIONAL_END = 19, 68 STORE_OBJECT_BEGIN = 20, 69 STORE_OBJECT_END = 29, 70 STORE_BUTT = 255 71 }; 72 73 API_EXPORT StoreMetaData(); 74 API_EXPORT StoreMetaData(const std::string &userId, const std::string &appId, const std::string &storeId); 75 API_EXPORT explicit StoreMetaData(const StoreInfo &storeInfo); 76 API_EXPORT ~StoreMetaData(); 77 API_EXPORT bool operator==(const StoreMetaData &metaData) const; 78 API_EXPORT bool operator!=(const StoreMetaData &metaData) const; 79 API_EXPORT bool Marshal(json &node) const override; 80 API_EXPORT bool Unmarshal(const json &node) override; 81 API_EXPORT std::string GetKey() const; 82 API_EXPORT std::string GetKeyLocal() const; 83 API_EXPORT std::string GetSecretKey() const; 84 API_EXPORT std::string GetStrategyKey() const; 85 API_EXPORT std::string GetBackupSecretKey() const; 86 API_EXPORT std::string GetAutoLaunchKey() const; 87 API_EXPORT std::string GetDebugInfoKey() const; 88 API_EXPORT std::string GetStoreAlias() const; 89 API_EXPORT StoreInfo GetStoreInfo() const; 90 API_EXPORT static std::string GetKey(const std::initializer_list<std::string> &fields); 91 API_EXPORT static std::string GetPrefix(const std::initializer_list<std::string> &fields); 92 }; 93 } // namespace OHOS::DistributedData 94 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_H