• 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 #include "cloud_service_proxy.h"
17 #include "itypes_util.h"
18 #include "logger.h"
19 
20 namespace OHOS::CloudData {
21 using namespace OHOS::Rdb;
22 
23 #define IPC_SEND(code, reply, ...)                                          \
24 ({                                                                          \
25     int32_t __status = SUCCESS;                                             \
26     do {                                                                    \
27         MessageParcel request;                                              \
28         if (!request.WriteInterfaceToken(GetDescriptor())) {                \
29             __status = IPC_PARCEL_ERROR;                                    \
30             break;                                                          \
31         }                                                                   \
32         if (!ITypesUtil::Marshal(request, ##__VA_ARGS__)) {                 \
33             __status = IPC_PARCEL_ERROR;                                    \
34             break;                                                          \
35         }                                                                   \
36         MessageOption option;                                               \
37         auto result = remote_->SendRequest((code), request, reply, option); \
38         if (result != 0) {                                                  \
39             __status = IPC_ERROR;                                           \
40             break;                                                          \
41         }                                                                   \
42                                                                             \
43         ITypesUtil::Unmarshal(reply, __status);                             \
44     } while (0);                                                            \
45     __status;                                                               \
46 })
47 
CloudServiceProxy(const sptr<IRemoteObject> & object)48 CloudServiceProxy::CloudServiceProxy(const sptr<IRemoteObject> &object)
49     : IRemoteProxy<ICloudService>(object)
50 {
51     remote_ = Remote();
52 }
53 
EnableCloud(const std::string & id,const std::map<std::string,int32_t> & switches)54 int32_t CloudServiceProxy::EnableCloud(const std::string &id, const std::map<std::string, int32_t> &switches)
55 {
56     MessageParcel reply;
57     int32_t status = IPC_SEND(TRANS_ENABLE_CLOUD, reply, id, switches);
58     if (status != SUCCESS) {
59         LOG_ERROR("status:0x%{public}x id:%{public}.6s size:%{public}zu", status, id.c_str(), switches.size());
60     }
61     return static_cast<Status>(status);
62 }
63 
DisableCloud(const std::string & id)64 int32_t CloudServiceProxy::DisableCloud(const std::string &id)
65 {
66     MessageParcel reply;
67     int32_t status = IPC_SEND(TRANS_DISABLE_CLOUD, reply, id);
68     if (status != SUCCESS) {
69         LOG_ERROR("status:0x%{public}x id:%{public}.6s", status, id.c_str());
70     }
71     return static_cast<Status>(status);
72 }
73 
ChangeAppSwitch(const std::string & id,const std::string & bundleName,int32_t appSwitch)74 int32_t CloudServiceProxy::ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch)
75 {
76     MessageParcel reply;
77     int32_t status = IPC_SEND(TRANS_CHANGE_APP_SWITCH, reply, id, bundleName, appSwitch);
78     if (status != SUCCESS) {
79         LOG_ERROR("status:0x%{public}x id:%{public}.6s bundleName:%{public}s switch:%{public}d",
80             status, id.c_str(), bundleName.c_str(), appSwitch);
81     }
82     return static_cast<Status>(status);
83 }
84 
Clean(const std::string & id,const std::map<std::string,int32_t> & actions)85 int32_t CloudServiceProxy::Clean(const std::string &id, const std::map<std::string, int32_t> &actions)
86 {
87     MessageParcel reply;
88     int32_t status = IPC_SEND(TRANS_CLEAN, reply, id, actions);
89     if (status != SUCCESS) {
90         LOG_ERROR("status:0x%{public}x id:%{public}.6s size:%{public}zu", status, id.c_str(), actions.size());
91     }
92     return static_cast<Status>(status);
93 }
94 
NotifyDataChange(const std::string & id,const std::string & bundleName)95 int32_t CloudServiceProxy::NotifyDataChange(const std::string &id, const std::string &bundleName)
96 {
97     MessageParcel reply;
98     int32_t status = IPC_SEND(TRANS_NOTIFY_DATA_CHANGE, reply, id, bundleName);
99     if (status != SUCCESS) {
100         LOG_ERROR("status:0x%{public}x id:%{public}.6s bundleName:%{public}s", status, id.c_str(), bundleName.c_str());
101     }
102     return static_cast<Status>(status);
103 }
104 } // namespace OHOS::CloudData