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