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_CLOUD_CLOUD_SERVICE_H 17 #define OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_SERVICE_H 18 #include <errors.h> 19 20 #include <cstdint> 21 #include <map> 22 #include <string> 23 #include <vector> 24 25 #include "cloud_types.h" 26 #include "common_types.h" 27 #include "rdb_types.h" 28 #include "values_bucket.h" 29 namespace OHOS { 30 namespace CloudData { 31 class CloudService { 32 public: 33 enum TransId : int32_t { 34 TRANS_HEAD, 35 TRANS_CONFIG_HEAD = TRANS_HEAD, 36 TRANS_ENABLE_CLOUD = TRANS_CONFIG_HEAD, 37 TRANS_DISABLE_CLOUD, 38 TRANS_CHANGE_APP_SWITCH, 39 TRANS_CLEAN, 40 TRANS_NOTIFY_DATA_CHANGE, 41 TRANS_NOTIFY_DATA_CHANGE_EXT, 42 TRANS_QUERY_STATISTICS, 43 TRANS_QUERY_LAST_SYNC_INFO, 44 TRANS_SET_GLOBAL_CLOUD_STRATEGY, 45 TRANS_CONFIG_BUTT, 46 TRANS_SHARE_HEAD = TRANS_CONFIG_BUTT, 47 TRANS_ALLOC_RESOURCE_AND_SHARE = TRANS_SHARE_HEAD, 48 TRANS_SHARE, 49 TRANS_UNSHARE, 50 TRANS_EXIT, 51 TRANS_CHANGE_PRIVILEGE, 52 TRANS_QUERY, 53 TRANS_QUERY_BY_INVITATION, 54 TRANS_CONFIRM_INVITATION, 55 TRANS_CHANGE_CONFIRMATION, 56 TRANS_SHARE_BUTT, 57 TRANS_CLIENT_HEAD = TRANS_SHARE_BUTT, 58 TRANS_SET_CLOUD_STRATEGY = TRANS_CLIENT_HEAD, 59 TRANS_CLIENT_BUTT, 60 TRANS_BUTT = TRANS_CLIENT_BUTT, 61 }; 62 enum Action : int32_t { 63 CLEAR_CLOUD_INFO, 64 CLEAR_CLOUD_DATA_AND_INFO, 65 CLEAR_CLOUD_BUTT 66 }; 67 68 enum Switch : int32_t { 69 SWITCH_ON, 70 SWITCH_OFF 71 }; 72 73 enum CloudSyncModule { 74 CLOUD_SYNC_MODULE_ID = 10, 75 }; 76 static const ErrCode CLOUD_ERR_OFFSET = ErrCodeOffset(SUBSYS_DISTRIBUTEDDATAMNG, CLOUD_SYNC_MODULE_ID); 77 enum Status : int32_t { 78 SUCCESS = 0, 79 ERROR = CLOUD_ERR_OFFSET + 1, 80 INVALID_ARGUMENT, 81 SERVER_UNAVAILABLE, 82 FEATURE_UNAVAILABLE, 83 NOT_SUPPORT, 84 CLOUD_DISABLE, 85 CLOUD_DISABLE_SWITCH, 86 IPC_ERROR, 87 IPC_PARCEL_ERROR, 88 PERMISSION_DENIED, 89 CLOUD_CONFIG_PERMISSION_DENIED, 90 NETWORK_ERROR, 91 CLOUD_INFO_INVALID, 92 SCHEMA_INVALID, 93 STRATEGY_BLOCKING, 94 }; 95 96 static const int INVALID_USER_ID = -1; 97 98 virtual ~CloudService() = default; 99 virtual int32_t EnableCloud(const std::string &id, const std::map<std::string, int32_t> &switches) = 0; 100 virtual int32_t DisableCloud(const std::string &id) = 0; 101 virtual int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) = 0; 102 virtual int32_t Clean(const std::string &id, const std::map<std::string, int32_t> &actions) = 0; 103 virtual int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) = 0; 104 virtual int32_t NotifyDataChange(const std::string &eventId, const std::string &extraData, int32_t userId) = 0; 105 virtual std::pair<int32_t, std::map<std::string, StatisticInfos>> QueryStatistics( 106 const std::string &id, const std::string &bundleName, const std::string &storeId) = 0; 107 virtual int32_t SetGlobalCloudStrategy(Strategy strategy, const std::vector<CommonType::Value> &values) = 0; 108 109 virtual std::pair<int32_t, std::vector<NativeRdb::ValuesBucket>> AllocResourceAndShare(const std::string &storeId, 110 const DistributedRdb::PredicatesMemo &predicates, const std::vector<std::string> &columns, 111 const Participants &participants) = 0; 112 virtual int32_t Share(const std::string &sharingRes, const Participants &participants, Results &results) = 0; 113 virtual int32_t Unshare(const std::string &sharingRes, const Participants &participants, Results &results) = 0; 114 virtual int32_t Exit(const std::string &sharingRes, std::pair<int32_t, std::string> &result) = 0; 115 virtual int32_t ChangePrivilege( 116 const std::string &sharingRes, const Participants &participants, Results &results) = 0; 117 virtual int32_t Query(const std::string &sharingRes, QueryResults &results) = 0; 118 virtual int32_t QueryByInvitation(const std::string &invitation, QueryResults &results) = 0; 119 virtual int32_t ConfirmInvitation(const std::string &invitation, int32_t confirmation, 120 std::tuple<int32_t, std::string, std::string> &result) = 0; 121 virtual int32_t ChangeConfirmation( 122 const std::string &sharingRes, int32_t confirmation, std::pair<int32_t, std::string> &result) = 0; 123 124 virtual int32_t SetCloudStrategy(Strategy strategy, const std::vector<CommonType::Value> &values) = 0; 125 virtual std::pair<int32_t, QueryLastResults> QueryLastSyncInfo( 126 const std::string &id, const std::string &bundleName, const std::string &storeId) = 0; 127 128 inline static constexpr const char *SERVICE_NAME = "cloud"; 129 }; 130 } // namespace CloudData 131 } // namespace OHOS 132 #endif // OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_SERVICE_H