• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 #include "distributed_input_source_proxy.h"
17 
18 #include "dinput_errcode.h"
19 #include "dinput_ipc_interface_code.h"
20 #include "dinput_log.h"
21 
22 namespace OHOS {
23 namespace DistributedHardware {
24 namespace DistributedInput {
DistributedInputSourceProxy(const sptr<IRemoteObject> & object)25 DistributedInputSourceProxy::DistributedInputSourceProxy(const sptr<IRemoteObject> &object)
26     : IRemoteProxy<IDistributedSourceInput>(object)
27 {}
28 
~DistributedInputSourceProxy()29 DistributedInputSourceProxy::~DistributedInputSourceProxy()
30 {}
31 
Init()32 int32_t DistributedInputSourceProxy::Init()
33 {
34     MessageParcel data;
35     MessageParcel reply;
36     if (!data.WriteInterfaceToken(GetDescriptor())) {
37         DHLOGE("DistributedInputSourceProxy write token valid failed");
38         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
39     }
40     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_INIT_FAIL;
41     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::INIT), data, reply);
42     if (ret) {
43         result = reply.ReadInt32();
44     }
45     return result;
46 }
47 
Release()48 int32_t DistributedInputSourceProxy::Release()
49 {
50     MessageParcel data;
51     MessageParcel reply;
52     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_RELEASE_FAIL;
53     if (!data.WriteInterfaceToken(GetDescriptor())) {
54         DHLOGE("DistributedInputSourceProxy write token valid failed");
55         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
56     }
57     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::RELEASE), data, reply);
58     if (ret) {
59         result = reply.ReadInt32();
60     }
61     return result;
62 }
63 
RegisterDistributedHardware(const std::string & devId,const std::string & dhId,const std::string & parameters,sptr<IRegisterDInputCallback> callback)64 int32_t DistributedInputSourceProxy::RegisterDistributedHardware(const std::string &devId, const std::string &dhId,
65     const std::string &parameters, sptr<IRegisterDInputCallback> callback)
66 {
67     MessageParcel data;
68     if (!data.WriteInterfaceToken(GetDescriptor())) {
69         DHLOGE("DistributedInputSourceProxy write token valid failed");
70         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
71     }
72     if (!data.WriteString(devId)) {
73         DHLOGE("DistributedInputSourceProxy write devId failed");
74         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
75     }
76     if (!data.WriteString(dhId)) {
77         DHLOGE("DistributedInputSourceProxy write dhId failed");
78         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
79     }
80     if (!data.WriteString(parameters)) {
81         DHLOGE("DistributedInputSourceProxy write parameters failed");
82         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
83     }
84     if (!data.WriteRemoteObject(callback->AsObject())) {
85         DHLOGE("DistributedInputSourceProxy write callback failed");
86         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
87     }
88     MessageParcel reply;
89     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_FAIL;
90     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_REMOTE_INPUT), data, reply);
91     if (ret) {
92         result = reply.ReadInt32();
93     }
94     return result;
95 }
96 
UnregisterDistributedHardware(const std::string & devId,const std::string & dhId,sptr<IUnregisterDInputCallback> callback)97 int32_t DistributedInputSourceProxy::UnregisterDistributedHardware(const std::string &devId, const std::string &dhId,
98     sptr<IUnregisterDInputCallback> callback)
99 {
100     MessageParcel data;
101     if (!data.WriteInterfaceToken(GetDescriptor())) {
102         DHLOGE("DistributedInputSourceProxy write token valid failed");
103         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
104     }
105     if (!data.WriteString(devId)) {
106         DHLOGE("DistributedInputSourceProxy write devId failed");
107         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
108     }
109     if (!data.WriteString(dhId)) {
110         DHLOGE("DistributedInputSourceProxy write dhId failed");
111         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
112     }
113     if (!data.WriteRemoteObject(callback->AsObject())) {
114         DHLOGE("DistributedInputSourceProxy write callback failed");
115         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
116     }
117     MessageParcel reply;
118     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_FAIL;
119     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::UNREGISTER_REMOTE_INPUT), data, reply);
120     if (ret) {
121         result = reply.ReadInt32();
122     }
123     return result;
124 }
125 
PrepareRemoteInput(const std::string & deviceId,sptr<IPrepareDInputCallback> callback)126 int32_t DistributedInputSourceProxy::PrepareRemoteInput(
127     const std::string &deviceId, sptr<IPrepareDInputCallback> callback)
128 {
129     MessageParcel data;
130     if (!data.WriteInterfaceToken(GetDescriptor())) {
131         DHLOGE("DistributedInputSourceProxy write token valid failed");
132         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
133     }
134     if (!data.WriteString(deviceId)) {
135         DHLOGE("DistributedInputSourceProxy write deviceId failed");
136         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
137     }
138     if (!data.WriteRemoteObject(callback->AsObject())) {
139         DHLOGE("DistributedInputSourceProxy write callback failed");
140         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
141     }
142 
143     MessageParcel reply;
144     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL;
145     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::PREPARE_REMOTE_INPUT), data, reply);
146     if (ret) {
147         result = reply.ReadInt32();
148     }
149     DHLOGI("PrepareRemoteInput end, result:%d", result);
150     return result;
151 }
152 
UnprepareRemoteInput(const std::string & deviceId,sptr<IUnprepareDInputCallback> callback)153 int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &deviceId,
154     sptr<IUnprepareDInputCallback> callback)
155 {
156     MessageParcel data;
157     if (!data.WriteInterfaceToken(GetDescriptor())) {
158         DHLOGE("DistributedInputSourceProxy write token valid failed");
159         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
160     }
161     if (!data.WriteString(deviceId)) {
162         DHLOGE("DistributedInputSourceProxy write deviceId failed");
163         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
164     }
165     if (!data.WriteRemoteObject(callback->AsObject())) {
166         DHLOGE("DistributedInputSourceProxy write callback failed");
167         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
168     }
169     MessageParcel reply;
170     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL;
171     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::UNPREPARE_REMOTE_INPUT), data, reply);
172     if (ret) {
173         result = reply.ReadInt32();
174     }
175     DHLOGE("UnprepareRemoteInput end, result=%d", result);
176     return result;
177 }
178 
StartRemoteInput(const std::string & deviceId,const uint32_t & inputTypes,sptr<IStartDInputCallback> callback)179 int32_t DistributedInputSourceProxy::StartRemoteInput(
180     const std::string &deviceId, const uint32_t &inputTypes, sptr<IStartDInputCallback> callback)
181 {
182     DHLOGI("source proxy StartRemoteInput start");
183     MessageParcel data;
184     if (!data.WriteInterfaceToken(GetDescriptor())) {
185         DHLOGE("DistributedInputSourceProxy write token valid failed");
186         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
187     }
188     if (!data.WriteString(deviceId)) {
189         DHLOGE("DistributedInputSourceProxy write deviceId failed");
190         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
191     }
192     if (!data.WriteUint32(inputTypes)) {
193         DHLOGE("DistributedInputSourceProxy write inputTypes failed");
194         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
195     }
196     if (!data.WriteRemoteObject(callback->AsObject())) {
197         DHLOGE("DistributedInputSourceProxy write callback failed");
198         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
199     }
200     MessageParcel reply;
201     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL;
202     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::START_REMOTE_INPUT), data, reply);
203     if (ret) {
204         result = reply.ReadInt32();
205     }
206     DHLOGI("source proxy StartRemoteInput end, result:%d.", result);
207     return result;
208 }
209 
StopRemoteInput(const std::string & deviceId,const uint32_t & inputTypes,sptr<IStopDInputCallback> callback)210 int32_t DistributedInputSourceProxy::StopRemoteInput(
211     const std::string &deviceId, const uint32_t &inputTypes, sptr<IStopDInputCallback> callback)
212 {
213     MessageParcel data;
214     if (!data.WriteInterfaceToken(GetDescriptor())) {
215         DHLOGE("DistributedInputSourceProxy write token valid failed");
216         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
217     }
218     if (!data.WriteString(deviceId)) {
219         DHLOGE("DistributedInputSourceProxy write deviceId failed");
220         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
221     }
222     if (!data.WriteUint32(inputTypes)) {
223         DHLOGE("DistributedInputSourceProxy write inputTypes failed");
224         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
225     }
226     if (!data.WriteRemoteObject(callback->AsObject())) {
227         DHLOGE("DistributedInputSourceProxy write callback failed");
228         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
229     }
230     MessageParcel reply;
231     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL;
232     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::STOP_REMOTE_INPUT), data, reply);
233     if (ret) {
234         result = reply.ReadInt32();
235     }
236     return result;
237 }
238 
StartRemoteInput(const std::string & srcId,const std::string & sinkId,const uint32_t & inputTypes,sptr<IStartDInputCallback> callback)239 int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
240     const uint32_t &inputTypes, sptr<IStartDInputCallback> callback)
241 {
242     DHLOGI("source proxy StartRemoteInput start");
243     MessageParcel data;
244     if (!data.WriteInterfaceToken(GetDescriptor())) {
245         DHLOGE("DistributedInputSourceProxy write token valid failed");
246         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
247     }
248     if (!data.WriteString(srcId)) {
249         DHLOGE("DistributedInputSourceProxy write srcId failed");
250         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
251     }
252     if (!data.WriteString(sinkId)) {
253         DHLOGE("DistributedInputSourceProxy write sinkId failed");
254         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
255     }
256     if (!data.WriteUint32(inputTypes)) {
257         DHLOGE("DistributedInputSourceProxy write inputTypes failed");
258         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
259     }
260     if (!data.WriteRemoteObject(callback->AsObject())) {
261         DHLOGE("DistributedInputSourceProxy write callback failed");
262         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
263     }
264     MessageParcel reply;
265     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL;
266     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::START_RELAY_TYPE_REMOTE_INPUT), data,
267         reply);
268     if (ret) {
269         result = reply.ReadInt32();
270     }
271     DHLOGI("source proxy StartRemoteInput end, result:%d.", result);
272     return result;
273 }
274 
StopRemoteInput(const std::string & srcId,const std::string & sinkId,const uint32_t & inputTypes,sptr<IStopDInputCallback> callback)275 int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &srcId, const std::string &sinkId,
276     const uint32_t &inputTypes, sptr<IStopDInputCallback> callback)
277 {
278     MessageParcel data;
279     if (!data.WriteInterfaceToken(GetDescriptor())) {
280         DHLOGE("DistributedInputSourceProxy write token valid failed");
281         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
282     }
283     if (!data.WriteString(srcId)) {
284         DHLOGE("DistributedInputSourceProxy write srcId failed");
285         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
286     }
287     if (!data.WriteString(sinkId)) {
288         DHLOGE("DistributedInputSourceProxy write sinkId failed");
289         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
290     }
291     if (!data.WriteUint32(inputTypes)) {
292         DHLOGE("DistributedInputSourceProxy write inputTypes failed");
293         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
294     }
295     if (!data.WriteRemoteObject(callback->AsObject())) {
296         DHLOGE("DistributedInputSourceProxy write callback failed");
297         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
298     }
299     MessageParcel reply;
300     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL;
301     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::STOP_RELAY_TYPE_REMOTE_INPUT),
302         data, reply);
303     if (ret) {
304         result = reply.ReadInt32();
305     }
306     return result;
307 }
308 
PrepareRemoteInput(const std::string & srcId,const std::string & sinkId,sptr<IPrepareDInputCallback> callback)309 int32_t DistributedInputSourceProxy::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
310     sptr<IPrepareDInputCallback> callback)
311 {
312     MessageParcel data;
313     if (!data.WriteInterfaceToken(GetDescriptor())) {
314         DHLOGE("DistributedInputSourceProxy write token valid failed");
315         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
316     }
317     if (!data.WriteString(srcId)) {
318         DHLOGE("Write PrepareRemoteInput relay srcid to parcel failed");
319         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
320     }
321     if (!data.WriteString(sinkId)) {
322         DHLOGE("Write PrepareRemoteInput relay sinkid to parcel failed");
323         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
324     }
325     if (!data.WriteRemoteObject(callback->AsObject())) {
326         DHLOGE("Write PrepareRemoteInput relay callback to parcel failed");
327         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
328     }
329 
330     MessageParcel reply;
331     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_PREPARE_FAIL;
332     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::PREPARE_RELAY_REMOTE_INPUT), data, reply);
333     if (ret) {
334         result = reply.ReadInt32();
335     }
336     DHLOGI("PrepareRemoteInput relay result:%d", result);
337     return result;
338 }
339 
UnprepareRemoteInput(const std::string & srcId,const std::string & sinkId,sptr<IUnprepareDInputCallback> callback)340 int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
341     sptr<IUnprepareDInputCallback> callback)
342 {
343     MessageParcel data;
344     if (!data.WriteInterfaceToken(GetDescriptor())) {
345         DHLOGE("DistributedInputSourceProxy write token valid failed");
346         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
347     }
348     if (!data.WriteString(srcId)) {
349         DHLOGE("Write UnprepareRemoteInput relay srcid to parcel failed");
350         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
351     }
352     if (!data.WriteString(sinkId)) {
353         DHLOGE("Write UnprepareRemoteInput relay sinkid to parcel failed");
354         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
355     }
356     if (!data.WriteRemoteObject(callback->AsObject())) {
357         DHLOGE("Write UnprepareRemoteInput relay callback to parcel failed");
358         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
359     }
360     MessageParcel reply;
361     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNPREPARE_FAIL;
362     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::UNPREPARE_RELAY_REMOTE_INPUT),
363         data, reply);
364     if (ret) {
365         result = reply.ReadInt32();
366     }
367     DHLOGI("UnprepareRemoteInput relay result:%d", result);
368     return result;
369 }
370 
StartRemoteInput(const std::string & sinkId,const std::vector<std::string> & dhIds,sptr<IStartStopDInputsCallback> callback)371 int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
372     sptr<IStartStopDInputsCallback> callback)
373 {
374     MessageParcel data;
375     if (!data.WriteInterfaceToken(GetDescriptor())) {
376         DHLOGE("DistributedInputSourceProxy write token valid failed");
377         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
378     }
379     if (!data.WriteString(sinkId)) {
380         DHLOGE("Write StartRemoteInput dhid sinkId to parcel failed");
381         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
382     }
383 
384     if (!data.WriteUint32(dhIds.size())) {
385         DHLOGE("Write StartRemoteInput dhid size to parcel failed");
386         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
387     }
388     for (auto it = dhIds.begin(); it != dhIds.end(); ++it) {
389         if (!data.WriteString(*it)) {
390             DHLOGE("Write StartRemoteInput dhid dhid to parcel failed");
391             return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
392         }
393     }
394 
395     if (!data.WriteRemoteObject(callback->AsObject())) {
396         DHLOGE("Write StartRemoteInput dhid callback to parcel failed");
397         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
398     }
399     MessageParcel reply;
400     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL;
401     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::START_DHID_REMOTE_INPUT), data, reply);
402     if (ret) {
403         result = reply.ReadInt32();
404     }
405     DHLOGI("Source proxy StartRemoteInput dhid end, result:%d.", result);
406     return result;
407 }
408 
StopRemoteInput(const std::string & sinkId,const std::vector<std::string> & dhIds,sptr<IStartStopDInputsCallback> callback)409 int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
410     sptr<IStartStopDInputsCallback> callback)
411 {
412     MessageParcel data;
413     if (!data.WriteInterfaceToken(GetDescriptor())) {
414         DHLOGE("DistributedInputSourceProxy write token valid failed");
415         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
416     }
417     if (!data.WriteString(sinkId)) {
418         DHLOGE("Write StopRemoteInput dhid sinkId to parcel failed");
419         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
420     }
421 
422     if (!data.WriteUint32(dhIds.size())) {
423         DHLOGE("Write StopRemoteInput dhid size to parcel failed");
424         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
425     }
426     for (auto it = dhIds.begin(); it != dhIds.end(); ++it) {
427         if (!data.WriteString(*it)) {
428             DHLOGE("Write StopRemoteInput dhid dhid to parcel failed");
429             return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
430         }
431     }
432 
433     if (!data.WriteRemoteObject(callback->AsObject())) {
434         DHLOGE("Write StopRemoteInput dhid callback to parcel failed");
435         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
436     }
437     MessageParcel reply;
438     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL;
439     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::STOP_DHID_REMOTE_INPUT), data, reply);
440     if (ret) {
441         result = reply.ReadInt32();
442     }
443     DHLOGI("Source proxy StopRemoteInput dhid end, result:%d.", result);
444     return result;
445 }
446 
StartRemoteInput(const std::string & srcId,const std::string & sinkId,const std::vector<std::string> & dhIds,sptr<IStartStopDInputsCallback> callback)447 int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
448     const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
449 {
450     MessageParcel data;
451     if (!data.WriteInterfaceToken(GetDescriptor())) {
452         DHLOGE("DistributedInputSourceProxy relay dhid write token valid failed");
453         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
454     }
455     if (!data.WriteString(srcId)) {
456         DHLOGE("Write StartRemoteInput relay dhid srcId to parcel failed");
457         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
458     }
459     if (!data.WriteString(sinkId)) {
460         DHLOGE("Write StartRemoteInput relay dhid sinkId to parcel failed");
461         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
462     }
463 
464     if (!data.WriteUint32(dhIds.size())) {
465         DHLOGE("Write StartRemoteInput relay dhid size to parcel failed");
466         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
467     }
468     for (auto it = dhIds.begin(); it != dhIds.end(); ++it) {
469         if (!data.WriteString(*it)) {
470             DHLOGE("Write StartRemoteInput relay dhid dhid to parcel failed");
471             return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
472         }
473     }
474 
475     if (!data.WriteRemoteObject(callback->AsObject())) {
476         DHLOGE("Write StartRemoteInput relay dhid callback to parcel failed");
477         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
478     }
479     MessageParcel reply;
480     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_START_FAIL;
481     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::START_RELAY_DHID_REMOTE_INPUT),
482         data, reply);
483     if (ret) {
484         result = reply.ReadInt32();
485     }
486     DHLOGI("Source proxy StartRemoteInput relay dhid end, result:%d.", result);
487     return result;
488 }
489 
StopRemoteInput(const std::string & srcId,const std::string & sinkId,const std::vector<std::string> & dhIds,sptr<IStartStopDInputsCallback> callback)490 int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &srcId, const std::string &sinkId,
491     const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
492 {
493     MessageParcel data;
494     if (!data.WriteInterfaceToken(GetDescriptor())) {
495         DHLOGE("DistributedInputSourceProxy write token valid failed");
496         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
497     }
498     if (!data.WriteString(srcId)) {
499         DHLOGE("Write StopRemoteInput relay dhid srcId to parcel failed");
500         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
501     }
502     if (!data.WriteString(sinkId)) {
503         DHLOGE("Write StopRemoteInput relay dhid sinkId to parcel failed");
504         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
505     }
506 
507     if (!data.WriteUint32(dhIds.size())) {
508         DHLOGE("Write StopRemoteInput relay dhid size to parcel failed");
509         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
510     }
511     for (auto it = dhIds.begin(); it != dhIds.end(); ++it) {
512         if (!data.WriteString(*it)) {
513             DHLOGE("Write StopRemoteInput relay dhid dhid to parcel failed");
514             return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
515         }
516     }
517 
518     if (!data.WriteRemoteObject(callback->AsObject())) {
519         DHLOGE("Write StopRemoteInput relay dhid callback to parcel failed");
520         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
521     }
522     MessageParcel reply;
523     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_STOP_FAIL;
524     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::STOP_RELAY_DHID_REMOTE_INPUT),
525         data, reply);
526     if (ret) {
527         result = reply.ReadInt32();
528     }
529     DHLOGI("Source proxy StopRemoteInput relay dhid end, result:%d.", result);
530     return result;
531 }
532 
RegisterAddWhiteListCallback(sptr<IAddWhiteListInfosCallback> addWhiteListCallback)533 int32_t DistributedInputSourceProxy::RegisterAddWhiteListCallback(sptr<IAddWhiteListInfosCallback> addWhiteListCallback)
534     __attribute__((no_sanitize("cfi")))
535 {
536     if (addWhiteListCallback == nullptr) {
537         DHLOGE("DistributedInputSourceProxy addWhiteListCallback is null.");
538         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
539     }
540     MessageParcel data;
541     if (!data.WriteInterfaceToken(GetDescriptor())) {
542         DHLOGE("DistributedInputSourceProxy write token valid failed");
543         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
544     }
545     if (!data.WriteRemoteObject(addWhiteListCallback->AsObject())) {
546         DHLOGE("DistributedInputSourceProxy write callback failed");
547         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
548     }
549     MessageParcel reply;
550     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WHITELIST_FAIL;
551     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT),
552         data, reply);
553     if (ret) {
554         result = reply.ReadInt32();
555     }
556     return result;
557 }
558 
RegisterDelWhiteListCallback(sptr<IDelWhiteListInfosCallback> delWhiteListCallback)559 int32_t DistributedInputSourceProxy::RegisterDelWhiteListCallback(sptr<IDelWhiteListInfosCallback> delWhiteListCallback)
560 {
561     if (delWhiteListCallback == nullptr) {
562         DHLOGE("DistributedInputSourceProxy delWhiteListCallback is null.");
563         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
564     }
565     MessageParcel data;
566     if (!data.WriteInterfaceToken(GetDescriptor())) {
567         DHLOGE("DistributedInputSourceProxy write token valid failed");
568         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
569     }
570     if (!data.WriteRemoteObject(delWhiteListCallback->AsObject())) {
571         DHLOGE("DistributedInputSourceProxy write callback failed");
572         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
573     }
574     MessageParcel reply;
575     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WHITELIST_FAIL;
576     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT),
577         data, reply);
578     if (ret) {
579         result = reply.ReadInt32();
580     }
581     return result;
582 }
583 
RegisterSimulationEventListener(sptr<ISimulationEventListener> listener)584 int32_t DistributedInputSourceProxy::RegisterSimulationEventListener(sptr<ISimulationEventListener> listener)
585 {
586     MessageParcel data;
587     if (!data.WriteInterfaceToken(GetDescriptor())) {
588         DHLOGE("RegisterSimulationEventListener write token valid failed");
589         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
590     }
591 
592     if (!data.WriteRemoteObject(listener->AsObject())) {
593         DHLOGE("RegisterSimulationEventListener write callback failed");
594         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
595     }
596 
597     MessageParcel reply;
598     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_SIMULATION_LISTENER_FAIL;
599     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_SIMULATION_EVENT_LISTENER),
600         data, reply);
601     if (ret) {
602         result = reply.ReadInt32();
603     }
604     return result;
605 }
606 
UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener)607 int32_t DistributedInputSourceProxy::UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener)
608 {
609     MessageParcel data;
610     if (!data.WriteInterfaceToken(GetDescriptor())) {
611         DHLOGE("UnregisterSimulationEventListener write token valid failed");
612         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
613     }
614 
615     if (!data.WriteRemoteObject(listener->AsObject())) {
616         DHLOGE("UnregisterSimulationEventListener write callback failed");
617         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
618     }
619 
620     MessageParcel reply;
621     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_SIMULATION_LISTENER_FAIL;
622     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::UNREGISTER_SIMULATION_EVENT_LISTENER),
623         data, reply);
624     if (ret) {
625         result = reply.ReadInt32();
626     }
627     return result;
628 }
629 
RegisterSessionStateCb(sptr<ISessionStateCallback> callback)630 int32_t DistributedInputSourceProxy::RegisterSessionStateCb(sptr<ISessionStateCallback> callback)
631 {
632     MessageParcel data;
633     if (!data.WriteInterfaceToken(GetDescriptor())) {
634         DHLOGE("RegisterSessionStateCb write token valid failed");
635         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
636     }
637 
638     if (!data.WriteRemoteObject(callback->AsObject())) {
639         DHLOGE("RegisterSessionStateCb write callback failed");
640         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
641     }
642 
643     MessageParcel reply;
644     int32_t result = ERR_DH_INPUT_SRC_STUB_REGISTER_SESSION_STATE_FAIL;
645     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_SESSION_STATE_CB),
646         data, reply);
647     if (ret) {
648         result = reply.ReadInt32();
649     }
650     return result;
651 }
652 
UnregisterSessionStateCb()653 int32_t DistributedInputSourceProxy::UnregisterSessionStateCb()
654 {
655     MessageParcel data;
656     if (!data.WriteInterfaceToken(GetDescriptor())) {
657         DHLOGE("UnregisterSessionStateCb write token valid failed");
658         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
659     }
660 
661     MessageParcel reply;
662     int32_t result = ERR_DH_INPUT_SRC_STUB_UNREGISTER_SESSION_STATE_FAIL;
663     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::UNREGISTER_SESSION_STATE_CB),
664         data, reply);
665     if (ret) {
666         result = reply.ReadInt32();
667     }
668     return result;
669 }
670 
SendRequest(const uint32_t code,MessageParcel & data,MessageParcel & reply)671 bool DistributedInputSourceProxy::SendRequest(const uint32_t code, MessageParcel &data, MessageParcel &reply)
672 {
673     sptr<IRemoteObject> remote = Remote();
674     if (remote == nullptr) {
675         DHLOGE("DistributedInputSourceProxy SendRequest remote is null.");
676         return false;
677     }
678     MessageOption option(MessageOption::TF_SYNC);
679     int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
680     if (result != DH_SUCCESS) {
681         DHLOGE("DistributedInputSourceProxy SendRequest error, result:%d.", result);
682         return false;
683     }
684     return true;
685 }
686 } // namespace DistributedInput
687 } // namespace DistributedHardware
688 } // namespace OHOS
689