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