• 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_stub.h"
17 
18 #include "constants_dinput.h"
19 #include "dinput_errcode.h"
20 #include "dinput_ipc_interface_code.h"
21 #include "dinput_log.h"
22 
23 namespace OHOS {
24 namespace DistributedHardware {
25 namespace DistributedInput {
DistributedInputSourceStub()26 DistributedInputSourceStub::DistributedInputSourceStub()
27 {}
28 
~DistributedInputSourceStub()29 DistributedInputSourceStub::~DistributedInputSourceStub()
30 {}
31 
HandleInitDistributedHardware(MessageParcel & reply)32 int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel &reply)
33 {
34     std::unique_lock<std::mutex> lock(operatorMutex_);
35     if (sourceManagerInitFlag_.load()) {
36         DHLOGE("DistributedInputSourceStub already init.");
37         return DH_SUCCESS;
38     }
39     int32_t ret = Init();
40     if (!reply.WriteInt32(ret)) {
41         DHLOGE("DistributedInputSourceStub Init write ret failed");
42         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
43     }
44     sourceManagerInitFlag_.store(true);
45     return DH_SUCCESS;
46 }
47 
HandleReleaseDistributedHardware(MessageParcel & reply)48 int32_t DistributedInputSourceStub::HandleReleaseDistributedHardware(MessageParcel &reply)
49 {
50     std::unique_lock<std::mutex> lock(operatorMutex_);
51     if (!sourceManagerInitFlag_.load()) {
52         DHLOGE("DistributedInputSourceStub already Release.");
53         return DH_SUCCESS;
54     }
55     int32_t ret = Release();
56     if (!reply.WriteInt32(ret)) {
57         DHLOGE("DistributedInputSourceStub release write ret failed");
58         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
59     }
60     sourceManagerInitFlag_.store(false);
61     return DH_SUCCESS;
62 }
63 
HandleRegisterDistributedHardware(MessageParcel & data,MessageParcel & reply)64 int32_t DistributedInputSourceStub::HandleRegisterDistributedHardware(MessageParcel &data, MessageParcel &reply)
65 {
66     std::string devId = data.ReadString();
67     std::string dhId = data.ReadString();
68     std::string params = data.ReadString();
69     sptr<IRegisterDInputCallback> callback = iface_cast<IRegisterDInputCallback>(data.ReadRemoteObject());
70     if (callback == nullptr) {
71         DHLOGE("HandleRegisterDistributedHardware failed, callback is nullptr.");
72         return ERR_DH_INPUT_POINTER_NULL;
73     }
74     int32_t ret = RegisterDistributedHardware(devId, dhId, params, callback);
75     if (!reply.WriteInt32(ret)) {
76         DHLOGE("HandleRegisterDistributedHardware write ret failed");
77         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
78     }
79     return DH_SUCCESS;
80 }
81 
HandleUnregisterDistributedHardware(MessageParcel & data,MessageParcel & reply)82 int32_t DistributedInputSourceStub::HandleUnregisterDistributedHardware(MessageParcel &data, MessageParcel &reply)
83 {
84     std::string devId = data.ReadString();
85     std::string dhId = data.ReadString();
86     sptr<IUnregisterDInputCallback> callback = iface_cast<IUnregisterDInputCallback>(data.ReadRemoteObject());
87     if (callback == nullptr) {
88         DHLOGE("HandleUnregisterDistributedHardware failed, callback is nullptr.");
89         return ERR_DH_INPUT_POINTER_NULL;
90     }
91     int32_t ret = UnregisterDistributedHardware(devId, dhId, callback);
92     if (!reply.WriteInt32(ret)) {
93         DHLOGE("HandleUnregisterDistributedHardware write ret failed");
94         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
95     }
96     return DH_SUCCESS;
97 }
98 
HandlePrepareRemoteInput(MessageParcel & data,MessageParcel & reply)99 int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data, MessageParcel &reply)
100 {
101     std::string deviceId = data.ReadString();
102     sptr<IPrepareDInputCallback> callback = iface_cast<IPrepareDInputCallback>(data.ReadRemoteObject());
103     if (callback == nullptr) {
104         DHLOGE("HandlePrepareRemoteInput failed, callback is nullptr.");
105         return ERR_DH_INPUT_POINTER_NULL;
106     }
107     int32_t ret = PrepareRemoteInput(deviceId, callback);
108     if (!reply.WriteInt32(ret)) {
109         DHLOGE("HandlePrepareRemoteInput write ret failed");
110         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
111     }
112     return DH_SUCCESS;
113 }
114 
HandleUnprepareRemoteInput(MessageParcel & data,MessageParcel & reply)115 int32_t DistributedInputSourceStub::HandleUnprepareRemoteInput(MessageParcel &data, MessageParcel &reply)
116 {
117     std::string deviceId = data.ReadString();
118     sptr<IUnprepareDInputCallback> callback = iface_cast<IUnprepareDInputCallback>(data.ReadRemoteObject());
119     if (callback == nullptr) {
120         DHLOGE("HandleUnprepareRemoteInput failed, callback is nullptr.");
121         return ERR_DH_INPUT_POINTER_NULL;
122     }
123     int32_t ret = UnprepareRemoteInput(deviceId, callback);
124     if (!reply.WriteInt32(ret)) {
125         DHLOGE("HandleUnprepareRemoteInput write ret failed");
126         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
127     }
128     return DH_SUCCESS;
129 }
130 
HandleStartRemoteInput(MessageParcel & data,MessageParcel & reply)131 int32_t DistributedInputSourceStub::HandleStartRemoteInput(MessageParcel &data, MessageParcel &reply)
132 {
133     std::string deviceId = data.ReadString();
134     uint32_t inputTypes = data.ReadUint32();
135     sptr<IStartDInputCallback> callback = iface_cast<IStartDInputCallback>(data.ReadRemoteObject());
136     if (callback == nullptr) {
137         DHLOGE("HandleStartRemoteInput failed, callback is nullptr.");
138         return ERR_DH_INPUT_POINTER_NULL;
139     }
140     int32_t ret = StartRemoteInput(deviceId, inputTypes, callback);
141     if (!reply.WriteInt32(ret)) {
142         DHLOGE("HandleStartRemoteInput write ret failed");
143         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
144     }
145     return DH_SUCCESS;
146 }
147 
HandleStopRemoteInput(MessageParcel & data,MessageParcel & reply)148 int32_t DistributedInputSourceStub::HandleStopRemoteInput(MessageParcel &data, MessageParcel &reply)
149 {
150     std::string deviceId = data.ReadString();
151     uint32_t inputTypes = data.ReadUint32();
152     sptr<IStopDInputCallback> callback = iface_cast<IStopDInputCallback>(data.ReadRemoteObject());
153     if (callback == nullptr) {
154         DHLOGE("HandleStopRemoteInput failed, callback is nullptr.");
155         return ERR_DH_INPUT_POINTER_NULL;
156     }
157     int32_t ret = StopRemoteInput(deviceId, inputTypes, callback);
158     if (!reply.WriteInt32(ret)) {
159         DHLOGE("HandleStopRemoteInput write ret failed");
160         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
161     }
162     return DH_SUCCESS;
163 }
164 
HandleStartRelayTypeRemoteInput(MessageParcel & data,MessageParcel & reply)165 int32_t DistributedInputSourceStub::HandleStartRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply)
166 {
167     std::string srcId = data.ReadString();
168     std::string sinkId = data.ReadString();
169     uint32_t inputTypes = data.ReadUint32();
170     sptr<IStartDInputCallback> callback = iface_cast<IStartDInputCallback>(data.ReadRemoteObject());
171     if (callback == nullptr) {
172         DHLOGE("HandleStartRelayTypeRemoteInput failed, callback is nullptr.");
173         return ERR_DH_INPUT_POINTER_NULL;
174     }
175     int32_t ret = StartRemoteInput(srcId, sinkId, inputTypes, callback);
176     if (!reply.WriteInt32(ret)) {
177         DHLOGE("HandleStartRelayTypeRemoteInput write ret failed");
178         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
179     }
180     return DH_SUCCESS;
181 }
182 
HandleStopRelayTypeRemoteInput(MessageParcel & data,MessageParcel & reply)183 int32_t DistributedInputSourceStub::HandleStopRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply)
184 {
185     std::string srcId = data.ReadString();
186     std::string sinkId = data.ReadString();
187     uint32_t inputTypes = data.ReadUint32();
188     sptr<IStopDInputCallback> callback = iface_cast<IStopDInputCallback>(data.ReadRemoteObject());
189     if (callback == nullptr) {
190         DHLOGE("HandleStopRelayTypeRemoteInput failed, callback is nullptr.");
191         return ERR_DH_INPUT_POINTER_NULL;
192     }
193     int32_t ret = StopRemoteInput(srcId, sinkId, inputTypes, callback);
194     if (!reply.WriteInt32(ret)) {
195         DHLOGE("HandleStopRelayTypeRemoteInput write ret failed");
196         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
197     }
198     return DH_SUCCESS;
199 }
200 
HandlePrepareRelayRemoteInput(MessageParcel & data,MessageParcel & reply)201 int32_t DistributedInputSourceStub::HandlePrepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply)
202 {
203     std::string srcId = data.ReadString();
204     std::string sinkId = data.ReadString();
205     sptr<IPrepareDInputCallback> callback = iface_cast<IPrepareDInputCallback>(data.ReadRemoteObject());
206     if (callback == nullptr) {
207         DHLOGE("HandlePrepareRelayRemoteInput failed, callback is nullptr.");
208         return ERR_DH_INPUT_POINTER_NULL;
209     }
210     int32_t ret = PrepareRemoteInput(srcId, sinkId, callback);
211     if (!reply.WriteInt32(ret)) {
212         DHLOGE("HandlePrepareRelayRemoteInput write ret failed");
213         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
214     }
215     return DH_SUCCESS;
216 }
217 
HandleUnprepareRelayRemoteInput(MessageParcel & data,MessageParcel & reply)218 int32_t DistributedInputSourceStub::HandleUnprepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply)
219 {
220     std::string srcId = data.ReadString();
221     std::string sinkId = data.ReadString();
222     sptr<IUnprepareDInputCallback> callback = iface_cast<IUnprepareDInputCallback>(data.ReadRemoteObject());
223     if (callback == nullptr) {
224         DHLOGE("HandleUnprepareRelayRemoteInput failed, callback is nullptr.");
225         return ERR_DH_INPUT_POINTER_NULL;
226     }
227     int32_t ret = UnprepareRemoteInput(srcId, sinkId, callback);
228     if (!reply.WriteInt32(ret)) {
229         DHLOGE("HandleUnprepareRelayRemoteInput write ret failed");
230         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
231     }
232     return DH_SUCCESS;
233 }
234 
HandleStartDhidRemoteInput(MessageParcel & data,MessageParcel & reply)235 int32_t DistributedInputSourceStub::HandleStartDhidRemoteInput(MessageParcel &data, MessageParcel &reply)
236 {
237     std::string sinkId = data.ReadString();
238 
239     std::vector<std::string> tempVector;
240     uint32_t vecSize = data.ReadUint32();
241     if (vecSize > IPC_VECTOR_MAX_SIZE) {
242         DHLOGE("HandleStartDhidRemoteInput vecSize too large");
243         return ERR_DH_INPUT_IPC_READ_VALID_FAIL;
244     }
245 
246     for (uint32_t i = 0; i < vecSize; i++) {
247         std::string dhid = data.ReadString();
248         if (dhid.empty()) {
249             DHLOGE("HandleStartDhidRemoteInput dhid is empty");
250             continue;
251         }
252         tempVector.push_back(dhid);
253     }
254 
255     sptr<IStartStopDInputsCallback> callback = iface_cast<IStartStopDInputsCallback>(data.ReadRemoteObject());
256     if (callback == nullptr) {
257         DHLOGE("HandleStartDhidRemoteInput failed, callback is nullptr.");
258         return ERR_DH_INPUT_POINTER_NULL;
259     }
260     int32_t ret = StartRemoteInput(sinkId, tempVector, callback);
261     if (!reply.WriteInt32(ret)) {
262         DHLOGE("HandleStartDhidRemoteInput write ret failed");
263         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
264     }
265     return DH_SUCCESS;
266 }
267 
HandleStopDhidRemoteInput(MessageParcel & data,MessageParcel & reply)268 int32_t DistributedInputSourceStub::HandleStopDhidRemoteInput(MessageParcel &data, MessageParcel &reply)
269 {
270     std::string sinkId = data.ReadString();
271 
272     std::vector<std::string> tempVector;
273     uint32_t vecSize = data.ReadUint32();
274     if (vecSize > IPC_VECTOR_MAX_SIZE) {
275         DHLOGE("HandleStopDhidRemoteInput vecSize too large");
276         return ERR_DH_INPUT_IPC_READ_VALID_FAIL;
277     }
278 
279     for (uint32_t i = 0; i < vecSize; i++) {
280         std::string dhid = data.ReadString();
281         if (dhid.empty()) {
282             DHLOGE("HandleStopDhidRemoteInput dhid is empty");
283             continue;
284         }
285         tempVector.push_back(dhid);
286     }
287 
288     sptr<IStartStopDInputsCallback> callback = iface_cast<IStartStopDInputsCallback>(data.ReadRemoteObject());
289     if (callback == nullptr) {
290         DHLOGE("HandleStopDhidRemoteInput failed, callback is nullptr.");
291         return ERR_DH_INPUT_POINTER_NULL;
292     }
293     int32_t ret = StopRemoteInput(sinkId, tempVector, callback);
294     if (!reply.WriteInt32(ret)) {
295         DHLOGE("HandleStopDhidRemoteInput write ret failed");
296         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
297     }
298     return DH_SUCCESS;
299 }
300 
HandleStartRelayDhidRemoteInput(MessageParcel & data,MessageParcel & reply)301 int32_t DistributedInputSourceStub::HandleStartRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply)
302 {
303     std::string srcId = data.ReadString();
304     std::string sinkId = data.ReadString();
305 
306     std::vector<std::string> tempVector;
307     uint32_t vecSize = data.ReadUint32();
308     if (vecSize > IPC_VECTOR_MAX_SIZE) {
309         DHLOGE("HandleStartRelayDhidRemoteInput vecSize too large");
310         return ERR_DH_INPUT_IPC_READ_VALID_FAIL;
311     }
312 
313     for (uint32_t i = 0; i < vecSize; i++) {
314         std::string dhid = data.ReadString();
315         if (dhid.empty()) {
316             DHLOGE("HandleStartRelayDhidRemoteInput dhid is empty");
317             continue;
318         }
319         tempVector.push_back(dhid);
320     }
321 
322     sptr<IStartStopDInputsCallback> callback = iface_cast<IStartStopDInputsCallback>(data.ReadRemoteObject());
323     if (callback == nullptr) {
324         DHLOGE("HandleStartRelayDhidRemoteInput failed, callback is nullptr.");
325         return ERR_DH_INPUT_POINTER_NULL;
326     }
327     int32_t ret = StartRemoteInput(srcId, sinkId, tempVector, callback);
328     if (!reply.WriteInt32(ret)) {
329         DHLOGE("HandleStartRelayDhidRemoteInput write ret failed");
330         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
331     }
332     return DH_SUCCESS;
333 }
334 
HandleStopRelayDhidRemoteInput(MessageParcel & data,MessageParcel & reply)335 int32_t DistributedInputSourceStub::HandleStopRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply)
336 {
337     std::string srcId = data.ReadString();
338     std::string sinkId = data.ReadString();
339 
340     std::vector<std::string> tempVector;
341     uint32_t vecSize = data.ReadUint32();
342     if (vecSize > IPC_VECTOR_MAX_SIZE) {
343         DHLOGE("HandleStopRelayDhidRemoteInput vecSize too large");
344         return ERR_DH_INPUT_IPC_READ_VALID_FAIL;
345     }
346 
347     for (uint32_t i = 0; i < vecSize; i++) {
348         std::string dhid = data.ReadString();
349         if (dhid.empty()) {
350             DHLOGE("HandleStopRelayDhidRemoteInput dhid is empty");
351             continue;
352         }
353         tempVector.push_back(dhid);
354     }
355 
356     sptr<IStartStopDInputsCallback> callback = iface_cast<IStartStopDInputsCallback>(data.ReadRemoteObject());
357     if (callback == nullptr) {
358         DHLOGE("HandleStopRelayDhidRemoteInput failed, callback is nullptr.");
359         return ERR_DH_INPUT_POINTER_NULL;
360     }
361     int32_t ret = StopRemoteInput(srcId, sinkId, tempVector, callback);
362     if (!reply.WriteInt32(ret)) {
363         DHLOGE("HandleStopRelayDhidRemoteInput write ret failed");
364         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
365     }
366     return DH_SUCCESS;
367 }
368 
HandleSyncNodeInfoRemoteInput(MessageParcel & data,MessageParcel & reply)369 int32_t DistributedInputSourceStub::HandleSyncNodeInfoRemoteInput(MessageParcel &data, MessageParcel &reply)
370 {
371     std::string userDevId = data.ReadString();
372     std::string dhid = data.ReadString();
373     std::string nodeDesc = data.ReadString();
374 
375     int32_t ret = SyncNodeInfoRemoteInput(userDevId, dhid, nodeDesc);
376     if (!reply.WriteInt32(ret)) {
377         DHLOGE("HandleSyncNodeInfoRemoteInput write ret failed");
378         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
379     }
380     return DH_SUCCESS;
381 }
382 
HandleRegisterAddWhiteListCallback(MessageParcel & data,MessageParcel & reply)383 int32_t DistributedInputSourceStub::HandleRegisterAddWhiteListCallback(MessageParcel &data, MessageParcel &reply)
384 {
385     sptr<IAddWhiteListInfosCallback> callback = iface_cast<IAddWhiteListInfosCallback>(data.ReadRemoteObject());
386     if (callback == nullptr) {
387         DHLOGE("HandleRegisterAddWhiteListCallback failed, callback is nullptr.");
388         return ERR_DH_INPUT_POINTER_NULL;
389     }
390     int32_t ret = RegisterAddWhiteListCallback(callback);
391     if (!reply.WriteInt32(ret)) {
392         DHLOGE("HandleRegisterAddWhiteListCallback write ret failed");
393         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
394     }
395     return DH_SUCCESS;
396 }
397 
HandleRegisterDelWhiteListCallback(MessageParcel & data,MessageParcel & reply)398 int32_t DistributedInputSourceStub::HandleRegisterDelWhiteListCallback(MessageParcel &data, MessageParcel &reply)
399 {
400     sptr<IDelWhiteListInfosCallback> callback = iface_cast<IDelWhiteListInfosCallback>(data.ReadRemoteObject());
401     if (callback == nullptr) {
402         DHLOGE("HandleRegisterDelWhiteListCallback failed, callback is nullptr.");
403         return ERR_DH_INPUT_POINTER_NULL;
404     }
405     int32_t ret = RegisterDelWhiteListCallback(callback);
406     if (!reply.WriteInt32(ret)) {
407         DHLOGE("HandleRegisterDelWhiteListCallback write ret failed");
408         return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
409     }
410     return DH_SUCCESS;
411 }
412 
HandleRegisterInputNodeListener(MessageParcel & data,MessageParcel & reply)413 int32_t DistributedInputSourceStub::HandleRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply)
414 {
415     sptr<InputNodeListener> callback = iface_cast<InputNodeListener>(data.ReadRemoteObject());
416     if (callback == nullptr) {
417         DHLOGE("HandleRegisterInputNodeListener failed, callback is nullptr.");
418         return ERR_DH_INPUT_POINTER_NULL;
419     }
420     int32_t ret = RegisterInputNodeListener(callback);
421     if (!reply.WriteInt32(ret)) {
422         DHLOGE("HandleRegisterInputNodeListener write ret failed");
423         return ERR_DH_INPUT_SOURCE_STUB_REGISTER_NODE_LISTENER_FAIL;
424     }
425 
426     return DH_SUCCESS;
427 }
428 
HandleUnRegisterInputNodeListener(MessageParcel & data,MessageParcel & reply)429 int32_t DistributedInputSourceStub::HandleUnRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply)
430 {
431     sptr<InputNodeListener> callback = iface_cast<InputNodeListener>(data.ReadRemoteObject());
432     if (callback == nullptr) {
433         DHLOGE("HandleUnRegisterInputNodeListener failed, callback is nullptr.");
434         return ERR_DH_INPUT_POINTER_NULL;
435     }
436     int32_t ret = RegisterInputNodeListener(callback);
437     if (!reply.WriteInt32(ret)) {
438         DHLOGE("HandleUnRegisterInputNodeListener write ret failed");
439         return ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_NODE_LISTENER_FAIL;
440     }
441 
442     return DH_SUCCESS;
443 }
444 
HandleRegisterSimulationEventListener(MessageParcel & data,MessageParcel & reply)445 int32_t DistributedInputSourceStub::HandleRegisterSimulationEventListener(MessageParcel &data, MessageParcel &reply)
446 {
447     sptr<ISimulationEventListener> callback = iface_cast<ISimulationEventListener>(data.ReadRemoteObject());
448     if (callback == nullptr) {
449         DHLOGE("HandleRegisterSimulationEventListener failed, callback is nullptr.");
450         return ERR_DH_INPUT_POINTER_NULL;
451     }
452     int32_t ret = RegisterSimulationEventListener(callback);
453     if (!reply.WriteInt32(ret)) {
454         DHLOGE("HandleRegisterSimulationEventListener write ret failed, ret = %d", ret);
455         return ERR_DH_INPUT_SOURCE_STUB_REGISTER_SIMULATION_EVENT_LISTENER_FAIL;
456     }
457 
458     return DH_SUCCESS;
459 }
460 
HandleUnregisterSimulationEventListener(MessageParcel & data,MessageParcel & reply)461 int32_t DistributedInputSourceStub::HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply)
462 {
463     sptr<ISimulationEventListener> callback = iface_cast<ISimulationEventListener>(data.ReadRemoteObject());
464     if (callback == nullptr) {
465         DHLOGE("HandleUnregisterSimulationEventListener failed, callback is nullptr.");
466         return ERR_DH_INPUT_POINTER_NULL;
467     }
468     int32_t ret = UnregisterSimulationEventListener(callback);
469     if (!reply.WriteInt32(ret)) {
470         DHLOGE("HandleUnregisterSimulationEventListener write ret failed, ret = %d", ret);
471         return ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_SIMULATION_EVENT_LISTENER_FAIL;
472     }
473 
474     return DH_SUCCESS;
475 }
476 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)477 int32_t DistributedInputSourceStub::OnRemoteRequest(
478     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
479 {
480     if (data.ReadInterfaceToken() != GetDescriptor()) {
481         DHLOGE("DistributedInputSourceStub read token valid failed");
482         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
483     }
484     switch (code) {
485         case static_cast<uint32_t>(IDInputSourceInterfaceCode::INIT): {
486             return HandleInitDistributedHardware(reply);
487         }
488         case static_cast<uint32_t>(IDInputSourceInterfaceCode::RELEASE): {
489             return HandleReleaseDistributedHardware(reply);
490         }
491         case static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_REMOTE_INPUT): {
492             return HandleRegisterDistributedHardware(data, reply);
493         }
494         case static_cast<uint32_t>(IDInputSourceInterfaceCode::UNREGISTER_REMOTE_INPUT): {
495             return HandleUnregisterDistributedHardware(data, reply);
496         }
497         case static_cast<uint32_t>(IDInputSourceInterfaceCode::PREPARE_REMOTE_INPUT): {
498             return HandlePrepareRemoteInput(data, reply);
499         }
500         case static_cast<uint32_t>(IDInputSourceInterfaceCode::UNPREPARE_REMOTE_INPUT): {
501             return HandleUnprepareRemoteInput(data, reply);
502         }
503         case static_cast<uint32_t>(IDInputSourceInterfaceCode::START_REMOTE_INPUT): {
504             return HandleStartRemoteInput(data, reply);
505         }
506         case static_cast<uint32_t>(IDInputSourceInterfaceCode::STOP_REMOTE_INPUT): {
507             return HandleStopRemoteInput(data, reply);
508         }
509         case static_cast<uint32_t>(IDInputSourceInterfaceCode::START_RELAY_TYPE_REMOTE_INPUT): {
510             return HandleStartRelayTypeRemoteInput(data, reply);
511         }
512         case static_cast<uint32_t>(IDInputSourceInterfaceCode::STOP_RELAY_TYPE_REMOTE_INPUT): {
513             return HandleStopRelayTypeRemoteInput(data, reply);
514         }
515         case static_cast<uint32_t>(IDInputSourceInterfaceCode::PREPARE_RELAY_REMOTE_INPUT): {
516             return HandlePrepareRelayRemoteInput(data, reply);
517         }
518         case static_cast<uint32_t>(IDInputSourceInterfaceCode::UNPREPARE_RELAY_REMOTE_INPUT): {
519             return HandleUnprepareRelayRemoteInput(data, reply);
520         }
521         case static_cast<uint32_t>(IDInputSourceInterfaceCode::START_DHID_REMOTE_INPUT): {
522             return HandleStartDhidRemoteInput(data, reply);
523         }
524         case static_cast<uint32_t>(IDInputSourceInterfaceCode::STOP_DHID_REMOTE_INPUT): {
525             return HandleStopDhidRemoteInput(data, reply);
526         }
527         case static_cast<uint32_t>(IDInputSourceInterfaceCode::START_RELAY_DHID_REMOTE_INPUT): {
528             return HandleStartRelayDhidRemoteInput(data, reply);
529         }
530         case static_cast<uint32_t>(IDInputSourceInterfaceCode::STOP_RELAY_DHID_REMOTE_INPUT): {
531             return HandleStopRelayDhidRemoteInput(data, reply);
532         }
533         case static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT): {
534             return HandleRegisterAddWhiteListCallback(data, reply);
535         }
536         case static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT): {
537             return HandleRegisterDelWhiteListCallback(data, reply);
538         }
539         case static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_NODE_LISTENER): {
540             return HandleRegisterInputNodeListener(data, reply);
541         }
542         case static_cast<uint32_t>(IDInputSourceInterfaceCode::UNREGISTER_NODE_LISTENER): {
543             return HandleUnRegisterInputNodeListener(data, reply);
544         }
545         case static_cast<uint32_t>(IDInputSourceInterfaceCode::REGISTER_SIMULATION_EVENT_LISTENER): {
546             return HandleRegisterSimulationEventListener(data, reply);
547         }
548         case static_cast<uint32_t>(IDInputSourceInterfaceCode::UNREGISTER_SIMULATION_EVENT_LISTENER): {
549             return HandleUnregisterSimulationEventListener(data, reply);
550         }
551         case static_cast<uint32_t>(IDInputSourceInterfaceCode::SYNC_NODE_INFO_REMOTE_INPUT): {
552             return HandleSyncNodeInfoRemoteInput(data, reply);
553         }
554         default:
555             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
556     }
557 }
558 } // namespace DistributedInput
559 } // namespace DistributedHardware
560 } // namespace OHOS
561