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 struct API_EXPORT AppInfo final : public Serializable { 24 std::string bundleName = ""; 25 std::string appId = ""; 26 uint64_t version = 0; 27 int32_t instanceId = 0; 28 bool cloudSwitch = false; 29 30 bool Marshal(json &node) const override; 31 bool Unmarshal(const json &node) override; 32 }; 33 int32_t user = 0; 34 std::string id = ""; 35 uint64_t totalSpace = 0; 36 uint64_t remainSpace = 0; 37 bool enableCloud = false; 38 std::map<std::string, AppInfo> apps; 39 40 std::string GetKey() const; 41 std::map<std::string, std::string> GetSchemaKey() const; 42 std::string GetSchemaKey(const std::string &bundleName, int32_t instanceId = 0) const; 43 std::string GetSchemaPrefix(const std::string &bundleName) const; 44 static std::string GetSchemaKey(int32_t user, const std::string &bundleName, int32_t instanceId = 0); 45 static std::string GetSchemaKey(const StoreMetaData &meta); 46 bool IsValid() const; 47 bool Exist(const std::string &bundleName, int32_t instanceId = 0); 48 bool IsOn(const std::string &bundleName, int32_t instanceId = 0); 49 bool IsAllSwitchOff() const; 50 static std::string GetPrefix(const std::initializer_list<std::string> &field); 51 52 bool Marshal(json &node) const override; 53 bool Unmarshal(const json &node) override; 54 55 private: 56 static constexpr const char *INFO_PREFIX = "CLOUD_INFO"; 57 static constexpr const char *SCHEMA_PREFIX = "CLOUD_SCHEMA"; 58 59 static std::string GetKey(const std::string &prefix, const std::initializer_list<std::string> &fields); 60 }; 61 } 62 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_INFO_H 63