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 <hdf_log.h>
16 #include <hdf_base.h>
17 #include <hdf_device_desc.h>
18 #include <osal_mem.h>
19 #include "input_server_stub.h"
20
21 #define HDF_LOG_TAG InputServer
22
23 using namespace OHOS::Input;
24 struct HdfInputService {
25 struct IDeviceIoService ioservice;
26 void *instance;
27 };
28
InputServiceDispatch(struct HdfDeviceIoClient * client,int32_t cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)29 static int32_t InputServiceDispatch(struct HdfDeviceIoClient *client, int32_t cmdId,
30 struct HdfSBuf *data, struct HdfSBuf *reply)
31 {
32 HDF_LOGE("%{public}s: line%{public}d!", __func__, __LINE__);
33 struct HdfInputService *hdfInputService = CONTAINER_OF(
34 client->device->service, struct HdfInputService, ioservice);
35 return InputServiceOnRemoteRequest(hdfInputService->instance, cmdId, *data, *reply);
36 }
37
HdfInputDriverInit(struct HdfDeviceObject * deviceObject)38 static int32_t HdfInputDriverInit(struct HdfDeviceObject *deviceObject)
39 {
40 HDF_LOGE("HdfInputDriverInit enter, new hdi impl");
41 return HDF_SUCCESS;
42 }
43
HdfInputDriverBind(struct HdfDeviceObject * deviceObject)44 static int32_t HdfInputDriverBind(struct HdfDeviceObject *deviceObject)
45 {
46 HDF_LOGI("HdfInputDriverBind enter! line: %{public}d", __LINE__);
47 struct HdfInputService *hdfInputService = (struct HdfInputService *)OsalMemAlloc(
48 sizeof(struct HdfInputService));
49 if (hdfInputService == nullptr) {
50 HDF_LOGI("HdfInputDriverBind OsalMemAlloc hdfInputService failed!");
51 return HDF_FAILURE;
52 }
53 hdfInputService->ioservice.Dispatch = InputServiceDispatch;
54 hdfInputService->ioservice.Open = NULL;
55 hdfInputService->ioservice.Release = NULL;
56 hdfInputService->instance = InputStubInstance();
57 deviceObject->service = &hdfInputService->ioservice;
58 HDF_LOGI("HdfInputDriverBind end!");
59 return HDF_SUCCESS;
60 }
61
HdfInputDriverRelease(struct HdfDeviceObject * deviceObject)62 static void HdfInputDriverRelease(struct HdfDeviceObject *deviceObject)
63 {
64 HDF_LOGI("HdfInputDriverRelease enter!");
65 struct HdfInputService *hdfInputService = CONTAINER_OF(deviceObject->service, struct HdfInputService, ioservice);
66 InputStubRelease(hdfInputService->instance);
67 OsalMemFree(hdfInputService);
68 }
69
70 struct HdfDriverEntry g_inputDriverEntry = {
71 .moduleVersion = 1,
72 .moduleName = "input_service",
73 .Bind = HdfInputDriverBind,
74 .Init = HdfInputDriverInit,
75 .Release = HdfInputDriverRelease,
76 };
77 #ifndef __cplusplus
78 extern "C" {
79 #endif
80 HDF_INIT(g_inputDriverEntry);
81 #ifndef __cplusplus
82 }
83 #endif
84