1 /*
2 * Copyright (c) 2025 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 #define LOG_TAG "CloudNotifierProxy"
16
17 #include "cloud_notifier_proxy.h"
18
19 #include "cloud_service.h"
20 #include "itypes_util.h"
21 #include "log_print.h"
22 #include "utils/anonymous.h"
23
24 namespace OHOS::CloudData {
25 using namespace DistributedRdb;
26 using NotifierCode = RelationalStore::ICloudNotifierInterfaceCode;
27
CloudNotifierProxy(const sptr<IRemoteObject> & object)28 CloudNotifierProxy::CloudNotifierProxy(const sptr<IRemoteObject> &object)
29 : IRemoteProxy<CloudNotifierProxyBroker>(object)
30 {}
31
~CloudNotifierProxy()32 CloudNotifierProxy::~CloudNotifierProxy() noexcept {}
33
OnComplete(uint32_t seqNum,DistributedRdb::Details && result)34 int32_t CloudNotifierProxy::OnComplete(uint32_t seqNum, DistributedRdb::Details &&result)
35 {
36 MessageParcel data;
37 if (!data.WriteInterfaceToken(GetDescriptor())) {
38 ZLOGE("write descriptor failed");
39 return CloudService::IPC_PARCEL_ERROR;
40 }
41 if (!ITypesUtil::Marshal(data, seqNum, result)) {
42 return CloudService::IPC_PARCEL_ERROR;
43 }
44
45 MessageParcel reply;
46 MessageOption option(MessageOption::TF_ASYNC);
47 auto remote = Remote();
48 if (remote == nullptr) {
49 ZLOGE("get remote failed, seqNum:%{public}u", seqNum);
50 return CloudService::IPC_ERROR;
51 }
52 auto status = remote->SendRequest(static_cast<uint32_t>(NotifierCode::CLOUD_NOTIFIER_CMD_SYNC_COMPLETE),
53 data, reply, option);
54 if (status != CloudService::SUCCESS) {
55 ZLOGE("seqNum:%{public}u, send request failed, status:%{public}d", seqNum, status);
56 }
57 return status;
58 }
59 } // namespace OHOS::CloudData
60