• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #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 {
535     if (addWhiteListCallback == nullptr) {
536         DHLOGE("DistributedInputSourceProxy addWhiteListCallback is null.");
537         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
538     }
539     MessageParcel data;
540     if (!data.WriteInterfaceToken(GetDescriptor())) {
541         DHLOGE("DistributedInputSourceProxy write token valid failed");
542         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
543     }
544     if (!data.WriteRemoteObject(addWhiteListCallback->AsObject())) {
545         DHLOGE("DistributedInputSourceProxy write callback failed");
546         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
547     }
548     MessageParcel reply;
549     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WHITELIST_FAIL;
550     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT),
551         data, reply);
552     if (ret) {
553         result = reply.ReadInt32();
554     }
555     return result;
556 }
557 
RegisterDelWhiteListCallback(sptr<IDelWhiteListInfosCallback> delWhiteListCallback)558 int32_t DistributedInputSourceProxy::RegisterDelWhiteListCallback(sptr<IDelWhiteListInfosCallback> delWhiteListCallback)
559 {
560     if (delWhiteListCallback == nullptr) {
561         DHLOGE("DistributedInputSourceProxy delWhiteListCallback is null.");
562         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
563     }
564     MessageParcel data;
565     if (!data.WriteInterfaceToken(GetDescriptor())) {
566         DHLOGE("DistributedInputSourceProxy write token valid failed");
567         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
568     }
569     if (!data.WriteRemoteObject(delWhiteListCallback->AsObject())) {
570         DHLOGE("DistributedInputSourceProxy write callback failed");
571         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
572     }
573     MessageParcel reply;
574     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_WHITELIST_FAIL;
575     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT),
576         data, reply);
577     if (ret) {
578         result = reply.ReadInt32();
579     }
580     return result;
581 }
582 
RegisterInputNodeListener(sptr<InputNodeListener> listener)583 int32_t DistributedInputSourceProxy::RegisterInputNodeListener(sptr<InputNodeListener> listener)
584 {
585     MessageParcel data;
586     if (!data.WriteInterfaceToken(GetDescriptor())) {
587         DHLOGE("DistributedInputSourceProxy write token valid failed");
588         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
589     }
590     if (!data.WriteRemoteObject(listener->AsObject())) {
591         DHLOGE("DistributedInputSourceProxy write callback failed");
592         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
593     }
594 
595     MessageParcel reply;
596     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_NODE_LISTENER_FAIL;
597     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_NODE_LISTENER),
598         data, reply);
599     if (ret) {
600         result = reply.ReadInt32();
601     }
602     return result;
603 }
604 
UnregisterInputNodeListener(sptr<InputNodeListener> listener)605 int32_t DistributedInputSourceProxy::UnregisterInputNodeListener(sptr<InputNodeListener> listener)
606 {
607     MessageParcel data;
608     if (!data.WriteInterfaceToken(GetDescriptor())) {
609         DHLOGE("DistributedInputSourceProxy write token valid failed");
610         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
611     }
612 
613     if (!data.WriteRemoteObject(listener->AsObject())) {
614         DHLOGE("DistributedInputSourceProxy write callback failed");
615         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
616     }
617 
618     MessageParcel reply;
619     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_NODE_LISTENER_FAIL;
620     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::UNREGISTER_NODE_LISTENER),
621         data, reply);
622     if (ret) {
623         result = reply.ReadInt32();
624     }
625     return result;
626 }
627 
SyncNodeInfoRemoteInput(const std::string & userDevId,const std::string & dhid,const std::string & nodeDesc)628 int32_t DistributedInputSourceProxy::SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhid,
629     const std::string &nodeDesc)
630 {
631     MessageParcel data;
632     if (!data.WriteInterfaceToken(GetDescriptor())) {
633         DHLOGE("DistributedInputSourceProxy write token valid failed");
634         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
635     }
636     if (!data.WriteString(userDevId)) {
637         DHLOGE("write SyncNodeInfoRemoteInput userDevId to parcel failed");
638         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
639     }
640     if (!data.WriteString(dhid)) {
641         DHLOGE("write SyncNodeInfoRemoteInput dhid to parcel failed");
642         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
643     }
644     if (!data.WriteString(nodeDesc)) {
645         DHLOGE("write SyncNodeInfoRemoteInput nodeDesc to parcel failed");
646         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
647     }
648     MessageParcel reply;
649     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_SYNC_NODE_FAIL;
650     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::SYNC_NODE_INFO_REMOTE_INPUT),
651         data, reply);
652     if (ret) {
653         result = reply.ReadInt32();
654     }
655     DHLOGI("SyncNodeInfoRemoteInput end, result=%d", result);
656     return result;
657 }
658 
RegisterSimulationEventListener(sptr<ISimulationEventListener> listener)659 int32_t DistributedInputSourceProxy::RegisterSimulationEventListener(sptr<ISimulationEventListener> listener)
660 {
661     MessageParcel data;
662     if (!data.WriteInterfaceToken(GetDescriptor())) {
663         DHLOGE("RegisterSimulationEventListener write token valid failed");
664         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
665     }
666 
667     if (!data.WriteRemoteObject(listener->AsObject())) {
668         DHLOGE("RegisterSimulationEventListener write callback failed");
669         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
670     }
671 
672     MessageParcel reply;
673     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_REGISTER_SIMULATION_LISTENER_FAIL;
674     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_SIMULATION_EVENT_LISTENER),
675         data, reply);
676     if (ret) {
677         result = reply.ReadInt32();
678     }
679     return result;
680 }
681 
UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener)682 int32_t DistributedInputSourceProxy::UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener)
683 {
684     MessageParcel data;
685     if (!data.WriteInterfaceToken(GetDescriptor())) {
686         DHLOGE("UnregisterSimulationEventListener write token valid failed");
687         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
688     }
689 
690     if (!data.WriteRemoteObject(listener->AsObject())) {
691         DHLOGE("UnregisterSimulationEventListener write callback failed");
692         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
693     }
694 
695     MessageParcel reply;
696     int32_t result = ERR_DH_INPUT_SOURCE_PROXY_UNREGISTER_SIMULATION_LISTENER_FAIL;
697     bool ret = SendRequest(static_cast<uint32_t>(IDInputSourceInterfaceCode::UNREGISTER_SIMULATION_EVENT_LISTENER),
698         data, reply);
699     if (ret) {
700         result = reply.ReadInt32();
701     }
702     return result;
703 }
704 
SendRequest(const uint32_t code,MessageParcel & data,MessageParcel & reply)705 bool DistributedInputSourceProxy::SendRequest(const uint32_t code, MessageParcel &data, MessageParcel &reply)
706 {
707     sptr<IRemoteObject> remote = Remote();
708     if (remote == nullptr) {
709         DHLOGE("DistributedInputSourceProxy SendRequest remote is null.");
710         return false;
711     }
712     MessageOption option(MessageOption::TF_SYNC);
713     int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
714     if (result != DH_SUCCESS) {
715         DHLOGE("DistributedInputSourceProxy SendRequest error, result:%d.", result);
716         return false;
717     }
718     return true;
719 }
720 } // namespace DistributedInput
721 } // namespace DistributedHardware
722 } // namespace OHOS
723