1 /*
2 * Copyright (c) 2021 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 <hdf_device_desc.h>
17 #include <hdf_device_object.h>
18 #include <hdf_log.h>
19 #include "sample_hdi.h"
20
21 #define HDF_LOG_TAG sample_driver
22
SampleServiceDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)23 static int32_t SampleServiceDispatch(
24 struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
25 {
26 return SampleServiceOnRemoteRequest(client, cmdId, data, reply);
27 }
28
HdfSampleDriverRelease(struct HdfDeviceObject * deviceObject)29 static void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject)
30 {
31 (void)deviceObject;
32 return;
33 }
34
HdfSampleDriverBind(struct HdfDeviceObject * deviceObject)35 static int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject)
36 {
37 HDF_LOGE("HdfSampleDriverBind enter!");
38 static struct IDeviceIoService testService = {
39 .Open = nullptr,
40 .Dispatch = SampleServiceDispatch,
41 .Release = nullptr,
42 };
43 int ret = HdfDeviceObjectSetInterfaceDesc(deviceObject, "hdf.test.sampele_service");
44 if (ret != HDF_SUCCESS) {
45 HDF_LOGE("failed to set interface desc");
46 return ret;
47 }
48 deviceObject->service = &testService;
49 return HDF_SUCCESS;
50 }
51
HdfSampleDriverInit(struct HdfDeviceObject * deviceObject)52 static int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject)
53 {
54 HDF_LOGE("HdfSampleDriverInit enter, new hdi impl");
55 if (HdfDeviceObjectSetServInfo(deviceObject, "sample_driver_service") != HDF_SUCCESS) {
56 HDF_LOGE("failed to set service info");
57 }
58 return HDF_SUCCESS;
59 }
60
61 static struct HdfDriverEntry g_sampleDriverEntry = {
62 .moduleVersion = 1,
63 .moduleName = "sample_driver",
64 .Bind = HdfSampleDriverBind,
65 .Init = HdfSampleDriverInit,
66 .Release = HdfSampleDriverRelease,
67 };
68
69 extern "C" {
70 HDF_INIT(g_sampleDriverEntry);
71 }