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_TYPES_H 17 #define OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_H 18 19 #include <map> 20 #include <string> 21 #include <tuple> 22 #include <vector> 23 24 namespace OHOS::CloudData { 25 enum Role : int32_t { 26 ROLE_NIL = -1, 27 ROLE_INVITER, 28 ROLE_INVITEE, 29 ROLE_BUTT 30 }; 31 32 enum Confirmation : int32_t { 33 CFM_NIL = -1, 34 CFM_UNKNOWN, 35 CFM_ACCEPTED, 36 CFM_REJECTED, 37 CFM_SUSPENDED, 38 CFM_UNAVAILABLE, 39 CFM_BUTT 40 }; 41 42 struct Privilege { 43 bool writable = false; 44 bool readable = false; 45 bool creatable = false; 46 bool deletable = false; 47 bool shareable = false; 48 }; 49 50 struct Participant { 51 std::string identity; 52 int32_t role = Role::ROLE_NIL; 53 int32_t state = Confirmation::CFM_NIL; 54 Privilege privilege; 55 std::string attachInfo; 56 }; 57 58 struct StatisticInfo { 59 std::string table; 60 int32_t inserted = 0; 61 int32_t updated = 0; 62 int32_t normal = 0; 63 }; 64 65 struct QueryKey { 66 int32_t user; 67 std::string accountId; 68 std::string bundleName; 69 std::string storeId; 70 bool operator<(const QueryKey &queryKey) const 71 { 72 return std::tie(accountId, user, bundleName, storeId) < 73 std::tie(queryKey.accountId, queryKey.user, queryKey.bundleName, queryKey.storeId); 74 } 75 }; 76 77 enum SyncStatus : int32_t { 78 RUNNING, 79 FINISHED 80 }; 81 82 struct CloudSyncInfo { 83 int64_t startTime = 0; 84 int64_t finishTime = 0; 85 int32_t code = -1; 86 int32_t syncStatus = SyncStatus::RUNNING; 87 }; 88 89 using StatisticInfos = std::vector<StatisticInfo>; 90 using Participants = std::vector<Participant>; 91 using Results = std::tuple<int32_t, std::string, std::vector<std::pair<int32_t, std::string>>>; 92 using QueryResults = std::tuple<int32_t, std::string, Participants>; 93 using QueryLastResults = std::map<std::string, CloudSyncInfo>; 94 95 constexpr const char *DATA_CHANGE_EVENT_ID = "cloud_data_change"; 96 97 /** 98 * Enumerates the error code of sharing invitation. 99 */ 100 enum SharingCode : int32_t { 101 /** 102 * @brief means sharing success. 103 */ 104 SUCCESS = 0, 105 106 /** 107 * @brief means the user has been invited. 108 */ 109 REPEATED_REQUEST, 110 111 /** 112 * @brief means the participant is not inviter. 113 */ 114 NOT_INVITER, 115 116 /** 117 * @brief means the participant is not inviter or invitee. 118 */ 119 NOT_INVITER_OR_INVITEE, 120 121 /** 122 * @brief means the number of sharing times today of current user has reached maximum. 123 */ 124 OVER_QUOTA, 125 126 /** 127 * @brief means the number of participants reaches the maximum. 128 */ 129 TOO_MANY_PARTICIPANTS, 130 131 /** 132 * @brief means invalid arguments. 133 */ 134 INVALID_ARGS, 135 136 /** 137 * @brief means the network is unavailable. 138 */ 139 NETWORK_ERROR, 140 141 /** 142 * @brief means cloud is disabled. 143 */ 144 CLOUD_DISABLED, 145 146 /** 147 * @brief means invoke cloud space failed. 148 */ 149 SERVER_ERROR, 150 151 /** 152 * @brief means an unknown error has occurred. 153 */ 154 INNER_ERROR, 155 156 /** 157 * @brief means the invitation has expired or does not exist. 158 */ 159 INVALID_INVITATION, 160 161 /** 162 * @brief means the data transfer is rate-limited. 163 */ 164 RATE_LIMIT, 165 166 /** 167 * @brief means error codes that exceed this enumerated value are custom error codes. 168 */ 169 CUSTOM_ERROR = 1000, 170 }; 171 172 enum Strategy : uint32_t { 173 STRATEGY_HEAD, 174 STRATEGY_NETWORK = STRATEGY_HEAD, 175 STRATEGY_BUTT 176 }; 177 178 enum NetWorkStrategy : uint32_t { 179 WIFI = 0x01, 180 CELLULAR = 0x02, 181 NETWORK_STRATEGY_BUTT 182 }; 183 } // namespace OHOS::CloudData 184 #endif // OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_H