1 /*
2 * Copyright (c) 2022 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 "RdbNotifierProxy"
16 #include "rdb_notifier_proxy.h"
17 #include "itypes_util.h"
18 #include "log_print.h"
19 namespace OHOS::DistributedRdb {
20 using NotifierIFCode = RelationalStore::IRdbNotifierInterfaceCode;
21
RdbNotifierProxy(const sptr<IRemoteObject> & object)22 RdbNotifierProxy::RdbNotifierProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<RdbNotifierProxyBroker>(object)
23 {
24 ZLOGI("construct");
25 }
26
~RdbNotifierProxy()27 RdbNotifierProxy::~RdbNotifierProxy() noexcept
28 {
29 ZLOGI("destroy");
30 }
31
OnComplete(uint32_t seqNum,Details && result)32 int32_t RdbNotifierProxy::OnComplete(uint32_t seqNum, Details &&result)
33 {
34 MessageParcel data;
35 if (!data.WriteInterfaceToken(GetDescriptor())) {
36 ZLOGE("write descriptor failed");
37 return RDB_ERROR;
38 }
39 if (!ITypesUtil::Marshal(data, seqNum, result)) {
40 return RDB_ERROR;
41 }
42
43 MessageParcel reply;
44 MessageOption option(MessageOption::TF_ASYNC);
45 if (Remote()->SendRequest(
46 static_cast<uint32_t>(NotifierIFCode::RDB_NOTIFIER_CMD_SYNC_COMPLETE), data, reply, option) != 0) {
47 ZLOGE("send request failed");
48 return RDB_ERROR;
49 }
50 return RDB_OK;
51 }
52
OnChange(const Origin & origin,const PrimaryFields & primaries,ChangeInfo && changeInfo)53 int32_t RdbNotifierProxy::OnChange(const Origin &origin, const PrimaryFields &primaries, ChangeInfo &&changeInfo)
54 {
55 MessageParcel data;
56 if (!data.WriteInterfaceToken(GetDescriptor())) {
57 ZLOGE("write descriptor failed");
58 return RDB_ERROR;
59 }
60 if (!ITypesUtil::Marshal(data, origin, primaries, changeInfo)) {
61 ZLOGE("write store name or devices failed");
62 return RDB_ERROR;
63 }
64
65 MessageParcel reply;
66 MessageOption option;
67 if (Remote()->SendRequest(
68 static_cast<uint32_t>(NotifierIFCode::RDB_NOTIFIER_CMD_DATA_CHANGE), data, reply, option) != 0) {
69 ZLOGE("send request failed");
70 return RDB_ERROR;
71 }
72 return RDB_OK;
73 }
74 } // namespace OHOS::DistributedRdb
75