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