• 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 #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         ZLOGI("SendRequest ok, retval is %{public}d", reply.ReadInt32());
42     } else {
43         ZLOGE("SendRequest error, result=%{public}d", result);
44         return;
45     }
46 }
47 
OnChangeFromPublishedData(PublishedDataChangeNode & changeNode)48 void PublishedDataObserverProxy::OnChangeFromPublishedData(PublishedDataChangeNode &changeNode)
49 {
50     MessageParcel parcel;
51     if (!parcel.WriteInterfaceToken(PublishedDataObserverProxy::GetDescriptor())) {
52         return;
53     }
54 
55     if (!ITypesUtil::Marshal(parcel, changeNode)) {
56         ZLOGE("failed to WriteParcelable changeNode ");
57         return;
58     }
59 
60     MessageParcel reply;
61     MessageOption option;
62     int32_t result = Remote()->SendRequest(REQUEST_CODE, parcel, reply, option);
63     if (result == ERR_NONE) {
64         ZLOGI("SendRequest ok, retval is %{public}d", reply.ReadInt32());
65     } else {
66         ZLOGE("SendRequest error, result=%{public}d", result);
67         return;
68     }
69 }
70 } // namespace DataShare
71 } // namespace OHOS