1 /*
2 * Copyright (c) 2022-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 "simulation_event_listener_proxy.h"
17
18 #include "ipc_types.h"
19 #include "parcel.h"
20
21 #include "dinput_errcode.h"
22 #include "dinput_log.h"
23
24 namespace OHOS {
25 namespace DistributedHardware {
26 namespace DistributedInput {
SimulationEventListenerProxy(const sptr<IRemoteObject> & object)27 SimulationEventListenerProxy::SimulationEventListenerProxy(const sptr<IRemoteObject> &object)
28 : IRemoteProxy<ISimulationEventListener>(object)
29 {
30 }
31
~SimulationEventListenerProxy()32 SimulationEventListenerProxy::~SimulationEventListenerProxy() {}
33
OnSimulationEvent(uint32_t type,uint32_t code,int32_t value)34 int32_t SimulationEventListenerProxy::OnSimulationEvent(uint32_t type, uint32_t code, int32_t value)
35 {
36 int32_t result = ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
37 sptr<IRemoteObject> remote = Remote();
38 if (remote == nullptr) {
39 DHLOGE("SimulationEventListenerProxy get remote failed");
40 return result;
41 }
42
43 MessageParcel data;
44 MessageParcel reply;
45 MessageOption option;
46 if (!data.WriteInterfaceToken(GetDescriptor())) {
47 DHLOGE("SimulationEventListenerProxy write token valid failed");
48 return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
49 }
50 if (!data.WriteUint32(type)) {
51 DHLOGE("SimulationEventListenerProxy write type failed");
52 return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
53 }
54 if (!data.WriteUint32(code)) {
55 DHLOGE("SimulationEventListenerProxy write code failed");
56 return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
57 }
58 if (!data.WriteInt32(value)) {
59 DHLOGE("SimulationEventListenerProxy write value failed");
60 return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
61 }
62 int32_t ret =
63 remote->SendRequest(static_cast<uint32_t>(ISimulationEventListener::Message::RESULT_ON), data, reply, option);
64 if (ret == DH_SUCCESS) {
65 result = reply.ReadInt32();
66 } else {
67 DHLOGE("SimulationEventListenerProxy SendRequest error:%{public}d", ret);
68 }
69 return result;
70 }
71 } // namespace DistributedInput
72 } // namespace DistributedHardware
73 } // namespace OHOS
74