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 #include "simulation_event_listener_stub.h"
17 
18 #include "string_ex.h"
19 
20 #include "constants_dinput.h"
21 #include "dinput_errcode.h"
22 #include "dinput_log.h"
23 
24 namespace OHOS {
25 namespace DistributedHardware {
26 namespace DistributedInput {
SimulationEventListenerStub()27 SimulationEventListenerStub::SimulationEventListenerStub() {}
28 
~SimulationEventListenerStub()29 SimulationEventListenerStub::~SimulationEventListenerStub() {}
30 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t SimulationEventListenerStub::OnRemoteRequest(
32     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
33 {
34     if (data.ReadInterfaceToken() != GetDescriptor()) {
35         DHLOGE("SimulationEventListenerStub read token valid failed");
36         return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL;
37     }
38     ISimulationEventListener::Message msgCode = static_cast<ISimulationEventListener::Message>(code);
39     switch (msgCode) {
40         case ISimulationEventListener::Message::RESULT_ON: {
41             uint32_t eventType = data.ReadUint32();
42             uint32_t eventCode = data.ReadUint32();
43             int32_t eventValue = data.ReadInt32();
44             int32_t ret = OnSimulationEvent(eventType, eventCode, eventValue);
45             if (!reply.WriteInt32(ret)) {
46                 DHLOGE("SimulationEventListenerStub write ret failed");
47                 return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
48             }
49             break;
50         }
51         default:
52             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
53     }
54     return DH_SUCCESS;
55 }
56 } // namespace DistributedInput
57 } // namespace DistributedHardware
58 } // namespace OHOS
59