• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
ObjectProgressCallbackProxy(const sptr<IRemoteObject> & impl)45 ObjectProgressCallbackProxy::ObjectProgressCallbackProxy(const sptr<IRemoteObject> &impl)
46     : IRemoteProxy<ObjectProgressCallbackProxyBroker>(impl)
47 {
48 }
49 
Completed(const std::map<std::string,int32_t> & results)50 void ObjectSaveCallbackProxy::Completed(const std::map<std::string, int32_t> &results)
51 {
52     MessageParcel data;
53     MessageParcel reply;
54     if (!data.WriteInterfaceToken(GetDescriptor())) {
55         ZLOGE("write descriptor failed");
56         return;
57     }
58     if (!ITypesUtil::Marshal(data, results)) {
59         ZLOGE("Marshalling failed");
60         return;
61     }
62     MessageOption mo { MessageOption::TF_SYNC };
63     int error = Remote()->SendRequest(COMPLETED, data, reply, mo);
64     if (error != 0) {
65         ZLOGW("SendRequest failed, error %{public}d", error);
66     }
67 }
68 
Completed(int32_t status)69 void ObjectRevokeSaveCallbackProxy::Completed(int32_t status)
70 {
71     MessageParcel data;
72     MessageParcel reply;
73     if (!data.WriteInterfaceToken(GetDescriptor())) {
74         ZLOGE("write descriptor failed");
75         return;
76     }
77     if (!ITypesUtil::Marshal(data, status)) {
78         ZLOGE("Marshalling failed, status:%{public}d", status);
79         return;
80     }
81     MessageOption mo { MessageOption::TF_SYNC };
82     int error = Remote()->SendRequest(COMPLETED, data, reply, mo);
83     if (error != 0) {
84         ZLOGW("SendRequest failed, error %{public}d", error);
85     }
86 }
87 
Completed(const std::map<std::string,std::vector<uint8_t>> & results,bool allReady)88 void ObjectRetrieveCallbackProxy::Completed(const std::map<std::string, std::vector<uint8_t>> &results, bool allReady)
89 {
90     MessageParcel data;
91     MessageParcel reply;
92     if (!data.WriteInterfaceToken(GetDescriptor())) {
93         ZLOGE("write descriptor failed");
94         return;
95     }
96     if (!ITypesUtil::Marshal(data, results, allReady)) {
97         ZLOGE("Marshalling failed, allReady:%{public}d", allReady);
98         return;
99     }
100     MessageOption mo { MessageOption::TF_SYNC };
101     int error = Remote()->SendRequest(COMPLETED, data, reply, mo);
102     if (error != 0) {
103         ZLOGW("SendRequest failed, error %{public}d", error);
104     }
105 }
106 
Completed(const std::map<std::string,std::vector<uint8_t>> & results,bool allReady)107 void ObjectChangeCallbackProxy::Completed(const std::map<std::string, std::vector<uint8_t>> &results, bool allReady)
108 {
109     MessageParcel data;
110     MessageParcel reply;
111     if (!data.WriteInterfaceToken(GetDescriptor())) {
112         ZLOGE("write descriptor failed");
113         return;
114     }
115     if (!ITypesUtil::Marshal(data, results, allReady)) {
116         ZLOGE("Marshalling failed, allReady:%{public}d", allReady);
117         return;
118     }
119     MessageOption mo { MessageOption::TF_SYNC };
120     int error = Remote()->SendRequest(COMPLETED, data, reply, mo);
121     if (error != 0) {
122         ZLOGW("SendRequest failed, error %{public}d", error);
123     }
124 }
125 
Completed(int32_t progress)126 void ObjectProgressCallbackProxy::Completed(int32_t progress)
127 {
128     MessageParcel data;
129     MessageParcel reply;
130     if (!data.WriteInterfaceToken(GetDescriptor())) {
131         ZLOGE("write descriptor failed");
132         return;
133     }
134     if (!ITypesUtil::Marshal(data, progress)) {
135         ZLOGE("Marshal failed");
136         return;
137     }
138     MessageOption mo { MessageOption::TF_ASYNC };
139     int error = Remote()->SendRequest(COMPLETED, data, reply, mo);
140     if (error != 0) {
141         ZLOGW("SendRequest failed, error %{public}d", error);
142     }
143 }
144 }  // namespace DistributedObject
145 }  // namespace OHOS