• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef IINPUT_HOST_STUB_H
16 #define IINPUT_HOST_STUB_H
17 
18 #include <list>
19 #include <map>
20 #include <vector>
21 #include <hdf_log.h>
22 #include <iservmgr_hdi.h>
23 #include "iinput_host_callbck.h"
24 
25 namespace OHOS {
26 namespace Input {
27 enum {
28     CMD_INPUT_SCAN_DEVICE = 0,
29     CMD_INPUT_OPNE_DEVICE,
30     CMD_INPUT_CLOSE_DEVICE,
31     CMD_INPUT_GET_DEVICE,
32     CMD_INPUT_GET_DEVICE_LIST,
33     CMD_INPUT_SET_POWER_STATUS,
34     CMD_INPUT_GET_POWER_STATUS,
35     CMD_INPUT_GET_DEVICE_TYPE,
36     CMD_INPUT_GET_CHIP_INFO,
37     CMD_INPUT_GET_VENDOR_NAME,
38     CMD_INPUT_GET_CHIP_NAME,
39     CMD_INPUT_SET_GESTURE_MODE,
40     CMD_INPUT_RUN_CAPACITANCE_TEST,
41     CMD_INPUT_RUN_EXTRA_COMMAND,
42     CMD_INPUT_REGISTER_DEVICE,
43     CMD_INPUT_UNREGISTER_DEVICE,
44     CMD_INPUT_REGISTER_HOT_PLAUS_DEVICE,
45     CMD_INPUT_UNREGISTER_HOT_PLAUS_DEVICE,
46 };
47 
48 class IInputHost {
49 public:
50 
~IInputHost()51     virtual ~IInputHost() {}
52 
53     /**
54      * @brief Scans all online input devices.
55      *
56      * @param staArr Indicates the pointer to the array storing information about the scanned input devices,
57      * including the device index and device type.
58      * @param arrLen Indicates the length of the array.
59      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
60      * {@link RetStatus} otherwise.
61      * @since 1.0
62      * @version 1.0
63      */
64     virtual int32_t ScanInputDevice(DevDesc *staArr, uint32_t arrLen) = 0;
65 
66     /**
67      * @brief Opens a specified input device file.
68      *
69      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
70      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
71      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
72      * {@link RetStatus} otherwise.
73      * @since 1.0
74      * @version 1.0
75      */
76     virtual int32_t OpenInputDevice(uint32_t devIndex) = 0;
77 
78     /**
79      * @brief Closes a specified input device file.
80      *
81      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
82      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
83      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
84      * {@link RetStatus} otherwise.
85      * @since 1.0
86      * @version 1.0
87      */
88     virtual int32_t CloseInputDevice(uint32_t devIndex) = 0;
89 
90     /**
91      * @brief Gets information about a specified input device.
92      *
93      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
94      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
95      * @param devInfo Indicates the double pointer to information about the specified device.
96      * For details, see {@link DeviceInfo}.
97      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
98      * {@link RetStatus} otherwise.
99      * @since 1.0
100      * @version 1.0
101      */
102     virtual int32_t GetInputDevice(uint32_t devIndex, DeviceInfo **devInfo) = 0;
103 
104     /**
105      * @brief Gets information about all input devices in the device list.
106      *
107      * @param devNum Indicates the pointer to the total number of input devices which have been registered.
108      * @param devList Indicates the double pointer to information about all devices in the device list.
109      * For details, see {@link DeviceInfo}.
110      * @param size Indicates the number of elements in thce <b>devList</b> array.
111      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
112      * {@link RetStatus} otherwise.
113      * @since 1.0
114      * @version 1.0
115      */
116     virtual int32_t GetInputDeviceList(uint32_t *devNum, DeviceInfo **devList, uint32_t size) = 0;
117 
118     /**
119      * @brief Sets the power status.
120      *
121      * This function is called only when the power status of the OS is changed. \n
122      * The input service or the power management module can call this function to set the power status
123      * for the input device when the OS is in the Resume or Suspend status, so that the driver integrated circuit (IC)
124      * of the device can normally enter the specified status.
125      *
126      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
127      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
128      * @param status Indicates the power status to set. The input service will notify the input device of entering the
129      * Resume or Suspend state specified by {@link PowerStatus}.
130      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
131      * {@link RetStatus} otherwise.
132      * @since 1.0
133      * @version 1.0
134      */
135     virtual int32_t SetPowerStatus(uint32_t devIndex, uint32_t status) = 0;
136 
137     /**
138      * @brief Gets the power status.
139      *
140      * The input service or the power management module can get the power status for the input device when the OS
141      * is in the Resume or Suspend status, so that the driver IC of the device can normally enter the specified status.
142      * You can call this function to obtain the power status.
143      *
144      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
145      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
146      * @param status Indicates the pointer to the power status of the device. For details, see {@link PowerStatus}.
147      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
148      * {@link RetStatus} otherwise.
149      * @since 1.0
150      * @version 1.0
151      */
152     virtual int32_t GetPowerStatus(uint32_t devIndex, uint32_t *status) = 0;
153 
154     /**
155      * @brief Gets the type of the input device based on the specified device index.
156      *
157      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
158      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
159      * @param deviceType Indicates the pointer to the device type. For details, see {@link InputDevType}.
160      * @return Returns <b>0</b> if the operation is successful; returns an error code defined
161      * in {@link RetStatus} otherwise.
162      * @since 1.0
163      * @version 1.0
164      */
165     virtual int32_t GetDeviceType(uint32_t devIndex, uint32_t *deviceType) = 0;
166 
167     /**
168      * @brief Gets the chip information of the specified device.
169      *
170      * A product is usually equipped with modules and driver ICs provided by multiple vendors. An input service
171      * can call this function to get the specific information if needed.
172      *
173      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
174      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
175      * @param chipInfo Indicates the pointer to the chip information.
176      * @param length Indicates the length of the chip information. The minimum value of length is 10.
177      * @return Returns <b>0</b> if the operation is successful; returns an error code defined
178      * in {@link RetStatus} otherwise.
179      * @since 1.0
180      * @version 1.0
181      */
182     virtual int32_t GetChipInfo(uint32_t devIndex, char *chipInfo, uint32_t length) = 0;
183 
184     /**
185      * @brief Gets the module vendor name of the specified device.
186      *
187      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
188      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
189      * @param vendorName Indicates the pointer to the module vendor name.
190      * @param length Indicates the length of the module vendor name. The minimum value of length is 10.
191      * @return Returns <b>0</b> if the operation is successful; returns an error code defined
192      * in {@link RetStatus} otherwise.
193      * @since 1.0
194      * @version 1.0
195      */
196     virtual int32_t GetVendorName(uint32_t devIndex, char *vendorName, uint32_t length) = 0;
197 
198     /**
199      * @brief Gets the driver chip name of the specified device.
200      *
201      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
202      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
203      * @param chipName Indicates the pointer to the driver chip name.
204      * @param length Indicates the length of the driver chip name. The minimum value of length is 10.
205      * @return Returns <b>0</b> if the operation is successful; returns an error code defined
206      * in {@link RetStatus} otherwise.
207      * @since 1.0
208      * @version 1.0
209      */
210     virtual int32_t GetChipName(uint32_t devIndex, char *chipName, uint32_t length) = 0;
211 
212     /**
213      * @brief Sets the gesture mode.
214      *
215      * The input service can use this function to enable or disable the gesture mode by setting <b>EnableBit</b>
216      * of the gesture mode.
217      *
218      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
219      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
220      * @param gestureMode Indicates the gesture mode to set.
221      * @return Returns <b>0</b> if the operation is successful; returns an error code defined
222      * in {@link RetStatus} otherwise.
223      * @since 1.0
224      * @version 1.0
225      */
226     virtual int32_t SetGestureMode(uint32_t devIndex, uint32_t gestureMode) = 0;
227 
228     /**
229      * @brief Conducts a capacitance self-test.
230      *
231      * The capacitance self-test items are defined by the component vendor, such as the tests on the raw data,
232      * short circuit, open circuit, interference, and row/column difference.
233      *
234      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
235      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
236      * @param testType Indicates the capacitance test type. For details, see {@link CapacitanceTest}.
237      * @param result Indicates the pointer to the capacitance test result. The value is <b>SUCC</b> for a successful
238      * operation and is an error code for a failed operation.
239      * @param length Indicates the length of the test result. The minimum value of length is 20.
240      * @return Returns <b>0</b> if the operation is successful; returns an error code defined
241      * in {@link RetStatus} otherwise.
242      * @since 1.0
243      * @version 1.0
244      */
245     virtual int32_t RunCapacitanceTest(uint32_t devIndex, uint32_t testType, char *result, uint32_t length) = 0;
246 
247     /**
248      * @brief Executes the extra command.
249      *
250      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
251      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
252      * @param cmd Indicates the pointer to the extra command data packet, including the command codes and parameters.
253      * For details, see {@link InputExtraCmd}.
254      * @return Returns <b>0</b> if the operation is successful; returns an error code defined
255      * in {@link RetStatus} otherwise.
256      * @since 1.0
257      * @version 1.0
258      */
259     virtual int32_t RunExtraCommand(uint32_t devIndex, InputExtraCmd *cmd) = 0;
260 
261     /**
262      * @brief Registers a callback for reporting subscribed data of specified input devices.
263      *
264      * After this callback is successfully registered, the driver can report the input event data to the input service
265      * through this callback.
266      *
267      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
268      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
269      * @param callback Indicates the pointer to the callback to register.
270      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
271      * {@link RetStatus} otherwise.
272      * @since 1.0
273      * @version 1.0
274      */
275     virtual int32_t RegisterReportCallback(uint32_t devIndex, OHOS::sptr<InputReportEventCb> callback) = 0;
276 
277     /**
278      * @brief Unregisters the callback for reporting subscribed data of specified input devices.
279      *
280      * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported.
281      * The value ranges from 0 to 31, and value <b>0</b> represents the first input device.
282      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
283      * {@link RetStatus} otherwise.
284      * @since 1.0
285      * @version 1.0
286      */
287     virtual int32_t UnregisterReportCallback(uint32_t devIndex) = 0;
288 
289     /**
290      * @brief Registers a hot plug callback to the HDIs for input devices.
291      *
292      * All input devices can use this callback to report hot plug events.
293      *
294      * @param callback Indicates the pointer to the callback to register.
295      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
296      * {@link RetStatus} otherwise.
297      * @since 1.0
298      * @version 1.0
299      */
300     virtual int32_t RegisterHotPlugCallback(OHOS::sptr<InputReportHostCb> callback) = 0;
301 
302     /**
303      * @brief Unregisters the hot plug callback of input devices.
304      *
305      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
306      * {@link RetStatus} otherwise.
307      * @since 1.0
308      * @version 1.0
309      */
310     virtual int32_t UnregisterHotPlugCallback(void) = 0;
311 };
312 }  // namespace Input
313 }  // namespace OHOS
314 
315 #endif // IINPUT_HOST_STUB_H
316