• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "hdf_device_desc.h"
32 #include "hdf_log.h"
33 #include "sample_service.h"
34 
35 #define HDF_LOG_TAG sample_driver
36 
SampleServiceGetData(void)37 static const char *SampleServiceGetData(void)
38 {
39     return "sample";
40 }
41 
SampleServiceSetData(const char * data)42 static int32_t SampleServiceSetData(const char *data)
43 {
44     if (data == NULL) {
45         return HDF_ERR_INVALID_PARAM;
46     }
47     HDF_LOGD("%s:%s", __func__, data);
48     return HDF_SUCCESS;
49 }
50 
HdfSampleDriverRelease(struct HdfDeviceObject * deviceObject)51 static void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject)
52 {
53     (void)deviceObject;
54     return;
55 }
56 
HdfSampleDriverBind(struct HdfDeviceObject * deviceObject)57 static int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject)
58 {
59     HDF_LOGD("%s::enter, deviceObject=%p", __func__, deviceObject);
60     if (deviceObject == NULL) {
61         return HDF_FAILURE;
62     }
63     static struct SampleService sampleService = {
64         .getData = SampleServiceGetData,
65         .setData = SampleServiceSetData,
66     };
67     deviceObject->service = &sampleService.service;
68     return HDF_SUCCESS;
69 }
70 
HdfSampleDriverInit(struct HdfDeviceObject * deviceObject)71 static int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject)
72 {
73     HDF_LOGD("%s::enter, deviceObject=%p", __func__, deviceObject);
74     if (deviceObject == NULL) {
75         HDF_LOGE("%s::ptr is null!", __func__);
76         return HDF_FAILURE;
77     }
78     HDF_LOGD("%s:Init success", __func__);
79     return HDF_SUCCESS;
80 }
81 
82 struct HdfDriverEntry g_sampleDriverEntry = {
83     .moduleVersion = 1,
84     .moduleName = "sample_driver",
85     .Bind = HdfSampleDriverBind,
86     .Init = HdfSampleDriverInit,
87     .Release = HdfSampleDriverRelease,
88 };
89 
90 HDF_INIT(g_sampleDriverEntry);
91