• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef INPUT_COMMON_H
17 #define INPUT_COMMON_H
18 
19 #include <pthread.h>
20 #include <poll.h>
21 #include "hdf_dlist.h"
22 #include "hdf_log.h"
23 #include "input_type.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define SERVICE_NAME_LEN 24
30 #define MAX_POLLFD_NUM 10
31 #define SCAN_DEV 0
32 
33 #define GET_MANAGER_CHECK_RETURN(manager) do { \
34     manager = GetDevManager(); \
35     if ((manager) == NULL) { \
36         HDF_LOGE("%s: get device manager failed", __func__); \
37         return INPUT_FAILURE; \
38     } \
39 } while (0)
40 
41 #define INPUT_CHECK_RETURN(ret) do { \
42     if ((ret) != INPUT_SUCCESS) { \
43         HDF_LOGE("%s: failed, line:%d", __func__, __LINE__); \
44         return ret; \
45     } \
46 } while (0)
47 
48 /**
49  * @brief Describes the information nodes of input devices.
50  */
51 typedef struct {
52     InputDeviceInfo payload;                 /* Device information payload */
53     struct HdfIoService *service;            /* Service of the device */
54     struct HdfDevEventlistener *listener;    /* Event listener of the device */
55     InputEventCb *eventCb;                   /* evtCallback {@link InputEventCb} for reporting data */
56     struct DListHead node;                   /* Head node of a linked list */
57 } DeviceInfoNode;
58 
59 typedef struct {
60     struct HdfIoService *service;            /* Service of the device */
61     struct HdfDevEventlistener *listener;    /* Event listener of the device */
62     InputHostCb *hostCb;                     /* Callback {@link InputHostCb} for reporting data */
63 } InputHostDev;
64 
65 /**
66  * @brief Describes the input device manager.
67  */
68 typedef struct {
69     struct DListHead devList;    /* Head node of the linked device list */
70     uint32_t attachedDevNum;     /* Total number of current devices */
71     int32_t evtCallbackNum;      /* The num of registered event callback */
72     pthread_mutex_t mutex;       /* Mutex object to synchronize */
73     InputHostDev hostDev;
74 } InputDevManager;
75 
76 /**
77  * @brief Defines the information of capacitance test.
78  */
79 typedef struct {
80     uint32_t testType;                        /* Capacitance test type */
81     char testResult[SELF_TEST_RESULT_LEN];    /* Capacitance test result */
82 } CapacitanceTestInfo;
83 
84 enum InputIoctlCmd {
85     INPUT_IOCTL_GET_EVENT_DATA,
86     INPUT_IOCTL_SET_POWER_STATUS,
87     INPUT_IOCTL_GET_POWER_STATUS,
88     INPUT_IOCTL_GET_DEVICE_TYPE,
89     INPUT_IOCTL_GET_CHIP_INFO,
90     INPUT_IOCTL_GET_VENDOR_NAME,
91     INPUT_IOCTL_GET_CHIP_NAME,
92     INPUT_IOCTL_SET_GESTURE_MODE,
93     INPUT_IOCTL_RUN_CAPACITANCE_TEST,
94     INPUT_IOCTL_RUN_EXTRA_CMD,
95 };
96 
97 enum InputIOsvcCmdId {
98     GET_DEV_TYPE,
99     SET_PWR_STATUS,
100     GET_PWR_STATUS,
101     GET_CHIP_INFO,
102     GET_VENDOR_NAME,
103     GET_CHIP_NAME,
104     GET_DEV_ATTR,
105     GET_DEV_ABILITY,
106     SET_GESTURE_MODE,
107     RUN_CAPAC_TEST,
108     RUN_EXTRA_CMD,
109 };
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 #endif
115