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 #include "input_host_callback_proxy.h"
16 #include <hdf_base.h>
17 #include <message_parcel.h>
18
19 #define HDF_LOG_TAG InputCallbackProxy
20
21 namespace OHOS {
22 namespace Input {
ReportEventPkgCallback(const EventPackage * pkgs,uint32_t count,uint32_t devIndex)23 void InputCallbackProxy::ReportEventPkgCallback(const EventPackage *pkgs, uint32_t count, uint32_t devIndex)
24 {
25 MessageParcel data {};
26 MessageParcel reply {};
27 MessageOption option { MessageOption::TF_ASYNC };
28 HDF_LOGE("%{public}s: count:%{public}d.", __func__, count);
29 if (!pkgs) {
30 HDF_LOGE("%{public}s: pkgs is null failed.", __func__);
31 return;
32 }
33 if (!data.WriteInterfaceToken(InputCallbackProxy::GetDescriptor())) {
34 HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
35 return;
36 }
37 if (!data.WriteUint32(count)) {
38 HDF_LOGE("%{public}s: write error count failed.", __func__);
39 return;
40 }
41 if (!data.WriteUint32(devIndex)) {
42 HDF_LOGE("%{public}s: write error devIndex failed.", __func__);
43 return;
44 }
45 if (!data.WriteUint32((sizeof(EventPackage) * count))) {
46 HDF_LOGE("%{public}s: write error length failed line %{public}d", __func__, __LINE__);
47 return;
48 }
49 if (!data.WriteRawData((void*)(pkgs), (sizeof(EventPackage) * count))) {
50 HDF_LOGE("%{public}s: write error pkgs failed.", __func__);
51 return;
52 }
53 int32_t ret = Remote()->SendRequest(CMD_INPUT_CALLBACK_REMOTE_REPROT_EVENT_PROXY, data, reply, option);
54 if (ret != HDF_SUCCESS) {
55 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
56 return;
57 }
58 }
59
ReportHotPlugEventCallback(const HotPlugEvent * event)60 void InputHotCallbackProxy::ReportHotPlugEventCallback(const HotPlugEvent *event)
61 {
62 MessageParcel data {};
63 MessageParcel reply {};
64 MessageOption option {};
65 if (!data.WriteInterfaceToken(InputHotCallbackProxy::GetDescriptor())) {
66 HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
67 return;
68 }
69 if (!data.WriteUint32(sizeof(HotPlugEvent))) {
70 HDF_LOGE("%{public}s: write error length failed line %{public}d", __func__, __LINE__);
71 return;
72 }
73 if (!data.WriteRawData((void*)event, sizeof(HotPlugEvent))) {
74 HDF_LOGE("%{public}s: write event failed.", __func__);
75 return;
76 }
77 int32_t ret = Remote()->SendRequest(CMD_INPUT_CALLBACK_REMOTE_REPROT_HOT_PLUG_EVENT_PROXY, data, reply, option);
78 if (ret != HDF_SUCCESS) {
79 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
80 return;
81 }
82 }
83 } // namespace Input
84 } // namespace OHOS
85