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 
16 #define LOG_TAG "IObjectCallbackProxy"
17 #include "object_callback_proxy.h"
18 
19 #include "ipc_skeleton.h"
20 #include "itypes_util.h"
21 #include "log_print.h"
22 
23 namespace OHOS {
24 namespace DistributedObject {
ObjectSaveCallbackProxy(const sptr<IRemoteObject> & impl)25 ObjectSaveCallbackProxy::ObjectSaveCallbackProxy(const sptr<IRemoteObject> &impl)
26     : IRemoteProxy<ObjectSaveCallbackProxyBroker>(impl)
27 {
28 }
29 
ObjectRevokeSaveCallbackProxy(const sptr<IRemoteObject> & impl)30 ObjectRevokeSaveCallbackProxy::ObjectRevokeSaveCallbackProxy(const sptr<IRemoteObject> &impl)
31     : IRemoteProxy<ObjectRevokeSaveCallbackProxyBroker>(impl)
32 {
33 }
34 
ObjectRetrieveCallbackProxy(const sptr<IRemoteObject> & impl)35 ObjectRetrieveCallbackProxy::ObjectRetrieveCallbackProxy(const sptr<IRemoteObject> &impl)
36     : IRemoteProxy<ObjectRetrieveCallbackProxyBroker>(impl)
37 {
38 }
39 
ObjectChangeCallbackProxy(const sptr<IRemoteObject> & impl)40 ObjectChangeCallbackProxy::ObjectChangeCallbackProxy(const sptr<IRemoteObject> &impl)
41     : IRemoteProxy<ObjectChangeCallbackProxyBroker>(impl)
42 {
43 }
44 
Completed(const std::map<std::string,int32_t> & results)45 void ObjectSaveCallbackProxy::Completed(const std::map<std::string, int32_t> &results)
46 {
47     MessageParcel data;
48     MessageParcel reply;
49     if (!data.WriteInterfaceToken(GetDescriptor())) {
50         ZLOGE("write descriptor failed");
51         return;
52     }
53     if (!ITypesUtil::Marshal(data, results)) {
54         ZLOGE("Marshalling failed");
55         return;
56     }
57     MessageOption mo { MessageOption::TF_SYNC };
58     int error = Remote()->SendRequest(COMPLETED, data, reply, mo);
59     if (error != 0) {
60         ZLOGW("SendRequest failed, error %d", error);
61     }
62 }
63 
Completed(int32_t status)64 void ObjectRevokeSaveCallbackProxy::Completed(int32_t status)
65 {
66     MessageParcel data;
67     MessageParcel reply;
68     if (!data.WriteInterfaceToken(GetDescriptor())) {
69         ZLOGE("write descriptor failed");
70         return;
71     }
72     if (!ITypesUtil::Marshal(data, status)) {
73         ZLOGE("write descriptor failed");
74         return;
75     }
76     MessageOption mo { MessageOption::TF_SYNC };
77     int error = Remote()->SendRequest(COMPLETED, data, reply, mo);
78     if (error != 0) {
79         ZLOGW("SendRequest failed, error %d", error);
80     }
81 }
82 
Completed(const std::map<std::string,std::vector<uint8_t>> & results,bool allReady)83 void ObjectRetrieveCallbackProxy::Completed(const std::map<std::string, std::vector<uint8_t>> &results, bool allReady)
84 {
85     MessageParcel data;
86     MessageParcel reply;
87     if (!data.WriteInterfaceToken(GetDescriptor())) {
88         ZLOGE("write descriptor failed");
89         return;
90     }
91     if (!ITypesUtil::Marshal(data, results, allReady)) {
92         ZLOGE("write descriptor failed");
93         return;
94     }
95     MessageOption mo { MessageOption::TF_SYNC };
96     int error = Remote()->SendRequest(COMPLETED, data, reply, mo);
97     if (error != 0) {
98         ZLOGW("SendRequest failed, error %d", error);
99     }
100 }
101 
Completed(const std::map<std::string,std::vector<uint8_t>> & results,bool allReady)102 void ObjectChangeCallbackProxy::Completed(const std::map<std::string, std::vector<uint8_t>> &results, bool allReady)
103 {
104     MessageParcel data;
105     MessageParcel reply;
106     if (!data.WriteInterfaceToken(GetDescriptor())) {
107         ZLOGE("write descriptor failed");
108         return;
109     }
110     if (!ITypesUtil::Marshal(data, results, allReady)) {
111         ZLOGE("write descriptor failed");
112         return;
113     }
114     MessageOption mo { MessageOption::TF_SYNC };
115     int error = Remote()->SendRequest(COMPLETED, data, reply, mo);
116     if (error != 0) {
117         ZLOGW("SendRequest failed, error %d", error);
118     }
119 }
120 }  // namespace DistributedObject
121 }  // namespace OHOS