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