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_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_INFO_H 17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_INFO_H 18 #include "metadata/store_meta_data.h" 19 #include "serializable/serializable.h" 20 namespace OHOS::DistributedData { 21 class API_EXPORT CloudInfo final : public Serializable { 22 public: 23 static constexpr int32_t DEFAULT_BATCH_NUMBER = 30; 24 static constexpr int32_t DEFAULT_BATCH_SIZE = 1024 * 512 * 3; // 1.5M 25 struct API_EXPORT AppInfo final : public Serializable { 26 std::string bundleName = ""; 27 std::string appId = ""; 28 uint64_t version = 0; 29 int32_t instanceId = 0; 30 bool cloudSwitch = false; 31 32 bool Marshal(json &node) const override; 33 bool Unmarshal(const json &node) override; 34 }; 35 int32_t user = 0; 36 std::string id = ""; 37 uint64_t totalSpace = 0; 38 uint64_t remainSpace = 0; 39 int32_t maxNumber = 0; 40 int32_t maxSize = 0; 41 bool enableCloud = false; 42 std::map<std::string, AppInfo> apps; 43 44 std::string GetKey() const; 45 std::map<std::string, std::string> GetSchemaKey() const; 46 std::string GetSchemaKey(const std::string &bundleName, int32_t instanceId = 0) const; 47 std::string GetSchemaPrefix(const std::string &bundleName) const; 48 static std::string GetSchemaKey(int32_t user, const std::string &bundleName, int32_t instanceId = 0); 49 static std::string GetSchemaKey(const StoreMetaData &meta); 50 bool IsValid() const; 51 bool Exist(const std::string &bundleName, int32_t instanceId = 0) const; 52 bool IsOn(const std::string &bundleName, int32_t instanceId = 0) const; 53 bool IsAllSwitchOff() const; 54 static std::string GetPrefix(const std::initializer_list<std::string> &field); 55 56 bool Marshal(json &node) const override; 57 bool Unmarshal(const json &node) override; 58 59 private: 60 static constexpr const char *INFO_PREFIX = "CLOUD_INFO"; 61 static constexpr const char *SCHEMA_PREFIX = "CLOUD_SCHEMA"; 62 63 static std::string GetKey(const std::string &prefix, const std::initializer_list<std::string> &fields); 64 }; 65 } 66 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_INFO_H 67