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 <map> 20 #include <string> 21 #include <vector> 22 #include "cloud_types.h" 23 #include "rdb_types.h" 24 #include "values_bucket.h" 25 namespace OHOS { 26 namespace CloudData { 27 class CloudService { 28 public: 29 enum TransId : int32_t { 30 TRANS_HEAD, 31 TRANS_ENABLE_CLOUD = TRANS_HEAD, 32 TRANS_DISABLE_CLOUD, 33 TRANS_CHANGE_APP_SWITCH, 34 TRANS_CLEAN, 35 TRANS_NOTIFY_DATA_CHANGE, 36 TRANS_NOTIFY_DATA_CHANGE_EXT, 37 TRANS_ALLOC_RESOURCE_AND_SHARE, 38 TRANS_SHARE, 39 TRANS_UNSHARE, 40 TRANS_EXIT, 41 TRANS_CHANGE_PRIVILEGE, 42 TRANS_QUERY, 43 TRANS_QUERY_BY_INVITATION, 44 TRANS_CONFIRM_INVITATION, 45 TRANS_CHANGE_CONFIRMATION, 46 TRANS_BUTT, 47 }; 48 enum Action : int32_t { 49 CLEAR_CLOUD_INFO, 50 CLEAR_CLOUD_DATA_AND_INFO, 51 CLEAR_CLOUD_BUTT 52 }; 53 54 enum Switch : int32_t { 55 SWITCH_ON, 56 SWITCH_OFF 57 }; 58 59 enum Status : int32_t { 60 SUCCESS = 0, 61 ERROR, 62 INVALID_ARGUMENT, 63 SERVER_UNAVAILABLE, 64 FEATURE_UNAVAILABLE, 65 NOT_SUPPORT, 66 CLOUD_DISABLE, 67 CLOUD_DISABLE_SWITCH, 68 IPC_ERROR, 69 IPC_PARCEL_ERROR, 70 PERMISSION_DENIED, 71 CLOUD_CONFIG_PERMISSION_DENIED 72 }; 73 74 static const int INVALID_USER_ID = -1; 75 76 virtual ~CloudService() = default; 77 virtual int32_t EnableCloud(const std::string &id, const std::map<std::string, int32_t> &switches) = 0; 78 virtual int32_t DisableCloud(const std::string &id) = 0; 79 virtual int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) = 0; 80 virtual int32_t Clean(const std::string &id, const std::map<std::string, int32_t> &actions) = 0; 81 virtual int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) = 0; 82 virtual int32_t NotifyDataChange(const std::string &eventId, const std::string &extraData, int32_t userId) = 0; 83 84 virtual std::pair<int32_t, std::vector<NativeRdb::ValuesBucket>> AllocResourceAndShare(const std::string &storeId, 85 const DistributedRdb::PredicatesMemo &predicates, const std::vector<std::string> &columns, 86 const Participants &participants) = 0; 87 virtual int32_t Share(const std::string &sharingRes, const Participants &participants, Results &results) = 0; 88 virtual int32_t Unshare(const std::string &sharingRes, const Participants &participants, Results &results) = 0; 89 virtual int32_t Exit(const std::string &sharingRes, std::pair<int32_t, std::string> &result) = 0; 90 virtual int32_t ChangePrivilege( 91 const std::string &sharingRes, const Participants &participants, Results &results) = 0; 92 virtual int32_t Query(const std::string &sharingRes, QueryResults &results) = 0; 93 virtual int32_t QueryByInvitation(const std::string &invitation, QueryResults &results) = 0; 94 virtual int32_t ConfirmInvitation(const std::string &invitation, int32_t confirmation, 95 std::tuple<int32_t, std::string, std::string> &result) = 0; 96 virtual int32_t ChangeConfirmation(const std::string &sharingRes, 97 int32_t confirmation, std::pair<int32_t, std::string> &result) = 0; 98 99 inline static constexpr const char *SERVICE_NAME = "cloud"; 100 }; 101 } // namespace CloudData 102 } // namespace OHOS 103 #endif // OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_SERVICE_H 104