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 #define LOG_TAG "ObserverProxy"
17 #include "data_share_obs_proxy.h"
18 
19 #include "itypes_util.h"
20 #include "log_print.h"
21 
22 namespace OHOS {
23 namespace DataShare {
24 static constexpr int REQUEST_CODE = 0;
OnChangeFromRdb(RdbChangeNode & changeNode)25 void RdbObserverProxy::OnChangeFromRdb(RdbChangeNode &changeNode)
26 {
27     MessageParcel parcel;
28     if (!parcel.WriteInterfaceToken(RdbObserverProxy::GetDescriptor())) {
29         return;
30     }
31 
32     if (!ITypesUtil::Marshal(parcel, changeNode)) {
33         ZLOGE("failed to WriteParcelable changeNode ");
34         return;
35     }
36 
37     MessageParcel reply;
38     MessageOption option;
39     int32_t result = Remote()->SendRequest(REQUEST_CODE, parcel, reply, option);
40     if (result != ERR_NONE) {
41         ZLOGE("SendRequest error, result=%{public}d", result);
42         return;
43     }
44     ZLOGI("SendRequest ok, retval is %{public}d", reply.ReadInt32());
45 }
46 
OnChangeFromPublishedData(PublishedDataChangeNode & changeNode)47 void PublishedDataObserverProxy::OnChangeFromPublishedData(PublishedDataChangeNode &changeNode)
48 {
49     MessageParcel parcel;
50     if (!parcel.WriteInterfaceToken(PublishedDataObserverProxy::GetDescriptor())) {
51         return;
52     }
53 
54     if (!ITypesUtil::Marshal(parcel, changeNode)) {
55         ZLOGE("failed to WriteParcelable changeNode ");
56         return;
57     }
58 
59     MessageParcel reply;
60     MessageOption option;
61     int32_t result = Remote()->SendRequest(REQUEST_CODE, parcel, reply, option);
62     if (result != ERR_NONE) {
63         ZLOGE("SendRequest error, result=%{public}d", result);
64         return;
65     }
66     ZLOGI("SendRequest ok, retval is %{public}d", reply.ReadInt32());
67 }
68 } // namespace DataShare
69 } // namespace OHOS