1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
/*****************************************************************************
*
* evemu - Kernel device emulation
*
* Copyright (C) 2010-2012 Canonical Ltd.
*
* This library is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
****************************************************************************/
#ifndef EVEMU_H
#define EVEMU_H
#include <stdio.h>
#include <errno.h>
#include <linux/input.h>
#ifdef __cplusplus
extern "C" {
#endif
#define EVEMU_VERSION 0x00010000
/**
* evemu_new() - allocate a new evemu device
* @name: wanted input device name (or NULL to leave empty)
*
* This function allocates a new evemu device structure and
* initializes all fields to zero. If name is non-null and the length
* is sane, it is copied to the device name.
*
* Returns NULL in case of memory failure.
*/
struct evemu_device *evemu_new(const char *name);
/**
* evemu_delete() - free and allocated evemu device
* @dev: the device to free
*
* The device pointer is invalidated by this call.
*/
void evemu_delete(struct evemu_device *dev);
/**
* evemu_get_version() - get library version
* @dev: the device in use
*
* Returns the library version used to create this evemu instance. The
* version may differ from the value of EVEMU_VERSION in this header
* file.
*/
unsigned int evemu_get_version(const struct evemu_device *dev);
/**
* evemu_get_name() - get device name
* @dev: the device in use
*
* Returns the name of the device. The pointer is owned by the evemu
* instance and has evemu scope.
*/
const char *evemu_get_name(const struct evemu_device *dev);
/**
* evemu_set_name() - set device name
* @dev: the device in use
*
* Sets the name of the device. If name is non-null and the length is
* sane, it is copied to the device name.
*/
void evemu_set_name(struct evemu_device *dev, const char *name);
/**
* evemu_get_id_bustype() - get kernel device bustype
* @dev: the device in use
*
* Returns the kernel bus type used by the device.
*/
unsigned int evemu_get_id_bustype(const struct evemu_device *dev);
/**
* evemu_set_id_bustype() - set kernel bustype
*
* @dev: the device in use
* @bustype: the bustype value to set.
*/
void evemu_set_id_bustype(struct evemu_device *dev, unsigned int bustype);
/**
* evemu_get_id_vendor() - get kernel device vendor id
* @dev: the device in use
*
* Returns the kernel vendor id used by the device.
*/
unsigned int evemu_get_id_vendor(const struct evemu_device *dev);
/**
* evemu_set_id_vendor() - set kernel device vendor id
*
* @dev: the device in use
* @vendor: the vendor id value to set.
*/
void evemu_set_id_vendor(struct evemu_device *dev, unsigned int vendor);
/**
* evemu_get_id_product() - get kernel device product id
* @dev: the device in use
*
* Returns the kernel product id used by the device.
*/
unsigned int evemu_get_id_product(const struct evemu_device *dev);
/**
* evemu_set_id_product() - set kernel device product id
*
* @dev: the device in use
* @product: the product id value to set.
*/
void evemu_set_id_product(struct evemu_device *dev, unsigned int product);
/**
* evemu_get_id_version() - get kernel device id version
* @dev: the device in use
*
* Returns the kernel device id used by the device.
*/
unsigned int evemu_get_id_version(const struct evemu_device *dev);
/**
* evemu_set_id_version() - set kernel device id version
*
* @dev: the device in use
* @version: the version value to set.
*/
void evemu_set_id_version(struct evemu_device *dev, unsigned int version);
/**
* evemu_get_abs_minimum() - get kernel minimum value of event type
* @dev: the device in use
* @code: the event type code to query
*
* Returns the range minimum of the specified event type.
*/
int evemu_get_abs_minimum(const struct evemu_device *dev, int code);
/**
* evemu_set_abs_minimum() - set kernel minimum value of event type
*
* @dev: the device in use
* @code: the event type code to set
* @min: the minimum value to set
*/
void evemu_set_abs_minimum(struct evemu_device *dev, int code, int min);
/**
* evemu_get_abs_maximum() - get kernel maximum value of event type
* @dev: the device in use
* @code: the event type code to query
*
* Returns the range maximum of the specified event type.
*/
int evemu_get_abs_maximum(const struct evemu_device *dev, int code);
/**
* evemu_set_abs_maximum() - set kernel maximum value of event type
*
* @dev: the device in use
* @code: the event type code to set
* @max: the maximum value to set
*/
void evemu_set_abs_maximum(struct evemu_device *dev, int code, int max);
/**
* evemu_get_abs_maximum() - get kernel filter fuzz of event type
* @dev: the device in use
* @code: the event type code to query
*
* Returns the filter fuzz of the specified event type.
*/
int evemu_get_abs_fuzz(const struct evemu_device *dev, int code);
/**
* evemu_set_abs_fuzz() - set kernel filter fuzz of event type
*
* @dev: the device in use
* @code: the event type code to set
* @fuzz: the fuzz value to set
*/
void evemu_set_abs_fuzz(struct evemu_device *dev, int code, int fuzz);
/**
* evemu_get_abs_maximum() - get kernel flat value of event type
* @dev: the device in use
* @code: the event type code to query
*
* Returns the flat value of the specified event type. Only used for
* joysticks.
*/
int evemu_get_abs_flat(const struct evemu_device *dev, int code);
/**
* evemu_set_abs_flat() - set kernel filter flat of event type
*
* @dev: the device in use
* @code: the event type code to set
* @flat: the flat value to set
*/
void evemu_set_abs_flat(struct evemu_device *dev, int code, int flat);
/**
* evemu_get_abs_resolution() - get kernel resolution of event type
* @dev: the device in use
* @code: the event type code to query
*
* Returns the resolution of the specified event type. Resolution is
* specified in units per millimeter (units/mm), or units per radian
* where appropriate.
*/
int evemu_get_abs_resolution(const struct evemu_device *dev, int code);
/**
* evemu_set_abs_resolution() - set kernel resolution of event type
* @dev: the device in use
* @code: the event type code to set
* @res: the resolution value to set.
*
* Resolution is specified in units per millimeter (units/mm), or units per
* radian where appropriate.
*/
void evemu_set_abs_resolution(struct evemu_device *dev, int code, int res);
/**
* evemu_has_prop() - check if device has a certain property
* @dev: the device in use
* @code: the property type code to query
*
* Returns true if the device has the given property.
*/
int evemu_has_prop(const struct evemu_device *dev, int code);
/**
* evemu_has_event() - check if device has a certain event type
* @dev: the device in use
* @code: the event type code to query
*
* Returns true if the event type is supported by the device.
*/
int evemu_has_event(const struct evemu_device *dev, int type, int code);
/**
* evemu_extract() - configure evemu instance directly from the kernel device
* @dev: the device in use
* @fd: file descriptor of the kernel device to query
*
* Returns zero if successful, negative error otherwise.
*/
int evemu_extract(struct evemu_device *dev, int fd);
/**
* evemu_write() - write evemu configuration to a file
* @dev: the device in use
* @fp: file pointer to write the evemu configuration to
*
* Returns zero if successful, negative error otherwise.
*/
int evemu_write(const struct evemu_device *dev, FILE *fp);
/**
* evemu_read() - read evemu configuration from a file
* @dev: the device in use
* @fp: file pointer to read the evemu configuration from
*
* Returns a positive number if successful, zero or negative error
* otherwise.
*/
int evemu_read(struct evemu_device *dev, FILE *fp);
/**
* evemu_write_event() - write kernel event to file
* @fp: file pointer to write the event to
* @ev: pointer to the kernel event to write
*
* Writes the kernel event to the file.
*
* Returns a positive number if successful, zero or negative error
* otherwise.
*/
int evemu_write_event(FILE *fp, const struct input_event *ev);
/**
* evemu_create_event() - Create a single event
* @ev: pointer to the kernel event to be filled
* @type: the event type to set
* @code: the event code to set
* @value: the event value to set
*/
int evemu_create_event(struct input_event *ev, int type, int code, int value);
/**
* evemu_read_event() - read kernel event from file
* @fp: file pointer to read the event from
* @ev: pointer to the kernel event to be filled
*
* Reads a kernel event from the file.
*
* Returns a positive number if successful, zero or negative error
* otherwise.
*/
int evemu_read_event(FILE *fp, struct input_event *ev);
/**
* evemu_read_event_realtime() - read kernel events in realtime
* @fp: file pointer to read the event from
* @ev: pointer to the kernel event to be filled
* @evtime: pointer to a timeval struct
*
* The evtime struct should be cleared (zeroed) before the first call
* to this function. This function reads a kernel event from the file,
* and performs the microsleep necessary to deliver the event with the
* same timings as originally received.
*
* Returns a positive number if successful, zero or negative error
* otherwise.
*/
int evemu_read_event_realtime(FILE *fp, struct input_event *ev,
struct timeval *evtime);
/**
* evemu_record() - read events directly from a kernel device
* @fp: file pointer to write the events to
* @fd: file descriptor of kernel device to read from
* @ms: maximum time to wait for an event to appear before reading (ms)
*
* Contiuously reads events from the kernel device and writes them to
* the file. The function terminates after ms milliseconds of
* inactivity.
*
* Returns zero if successful, negative error otherwise.
*/
int evemu_record(FILE *fp, int fd, int ms);
/**
* evemu_play_one() - play one event to kernel device
* @fd: file descriptor of kernel device to write to
* @ev: pointer to the kernel event to be played
*/
int evemu_play_one(int fd, const struct input_event *ev);
/**
* evemu_play() - replay events from file to kernel device in realtime
* @fp: file pointer to read the events from
* @fd: file descriptor of kernel device to write to
*
* Contiuously reads events from the file and writes them to the
* kernel device, in realtime. The function terminates when end of
* file has been reached.
*
* Returns zero if successful, negative error otherwise.
*/
int evemu_play(FILE *fp, int fd);
/**
* evemu_create() - create a kernel device from the evemu configuration
* @dev: the device in use
* @fd: file descriptor of the special kernel uinput device
*
* Creates a new device with all the properties of the evemu device.
*
* Returns zero if successful, negative error otherwise.
*/
int evemu_create(const struct evemu_device *dev, int fd);
/**
* evemu_destroy() - destroy all created kernel devices
* @fd: file descriptor of the special kernel uinput device
*
* Destroys all devices created using this file descriptor.
*/
void evemu_destroy(int fd);
#ifdef __cplusplus
}
#endif
#endif
|