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 <string>
20 #include <tuple>
21 #include <vector>
22 #include <map>
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     std::string accountId;
67     std::string bundleName;
68     std::string storeId;
69     bool operator<(const QueryKey &queryKey) const
70     {
71         if (accountId < queryKey.accountId) {
72             return true;
73         } else if (accountId == queryKey.accountId) {
74             if (bundleName < queryKey.bundleName) {
75                 return true;
76             } else if (bundleName == queryKey.bundleName) {
77                 return storeId < queryKey.storeId;
78             }
79         }
80         return false;
81     }
82 };
83 
84 struct CloudSyncInfo {
85     int64_t startTime = 0;
86     int64_t finishTime = 0;
87     int32_t code = -1;
88 };
89 
90 using StatisticInfos = std::vector<StatisticInfo>;
91 using Participants = std::vector<Participant>;
92 using Results = std::tuple<int32_t, std::string, std::vector<std::pair<int32_t, std::string>>>;
93 using QueryResults = std::tuple<int32_t, std::string, Participants>;
94 using QueryLastResults = std::map<std::string, CloudSyncInfo>;
95 
96 constexpr const char *DATA_CHANGE_EVENT_ID = "cloud_data_change";
97 
98 /**
99  * Enumerates the error code of sharing invitation.
100  */
101 enum SharingCode : int32_t {
102     /**
103      * @brief means sharing success.
104      */
105     SUCCESS = 0,
106 
107     /**
108      * @brief means the user has been invited.
109      */
110     REPEATED_REQUEST,
111 
112     /**
113      * @brief means the participant is not inviter.
114      */
115     NOT_INVITER,
116 
117     /**
118      * @brief means the participant is not inviter or invitee.
119      */
120     NOT_INVITER_OR_INVITEE,
121 
122     /**
123      * @brief means the number of sharing times today of current user has reached maximum.
124      */
125     OVER_QUOTA,
126 
127     /**
128      * @brief means the number of participants reaches the maximum.
129      */
130     TOO_MANY_PARTICIPANTS,
131 
132     /**
133      * @brief means invalid arguments.
134      */
135     INVALID_ARGS,
136 
137     /**
138      * @brief means the network is unavailable.
139      */
140     NETWORK_ERROR,
141 
142     /**
143      * @brief means cloud is disabled.
144      */
145     CLOUD_DISABLED,
146 
147     /**
148      * @brief means invoke cloud space failed.
149      */
150     SERVER_ERROR,
151 
152     /**
153      * @brief means an unknown error has occurred.
154      */
155     INNER_ERROR,
156 
157     /**
158      * @brief means the invitation has expired or does not exist.
159      */
160     INVALID_INVITATION,
161 
162     /**
163      * @brief means the data transfer is rate-limited.
164      */
165     RATE_LIMIT,
166 
167     /**
168      * @brief means error codes that exceed this enumerated value are custom error codes.
169      */
170     CUSTOM_ERROR = 1000,
171 };
172 
173 enum Strategy : uint32_t {
174     STRATEGY_HEAD,
175     STRATEGY_NETWORK = STRATEGY_HEAD,
176     STRATEGY_BUTT
177 };
178 
179 enum NetWorkStrategy : uint32_t {
180     WIFI = 0x01,
181     CELLULAR = 0x02,
182     NETWORK_STRATEGY_BUTT
183 };
184 } // namespace OHOS::CloudData
185 #endif // OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_H