summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/mtdev-plumbing.h105
-rw-r--r--include/mtdev.h99
2 files changed, 120 insertions, 84 deletions
diff --git a/include/mtdev-plumbing.h b/include/mtdev-plumbing.h
new file mode 100644
index 0000000..b610873
--- /dev/null
+++ b/include/mtdev-plumbing.h
@@ -0,0 +1,105 @@
1/*****************************************************************************
2 *
3 * mtdev - MT device event converter (MIT license)
4 *
5 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
6 * Copyright (C) 2010 Canonical Ltd.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 ****************************************************************************/
28
29#ifndef _MTDEV_PLUMBING_H
30#define _MTDEV_PLUMBING_H
31
32#include <mtdev.h>
33
34/**
35 * mtdev_init - initialize mtdev converter
36 * @dev: the mtdev to initialize
37 *
38 * Sets up the internal data structures.
39 *
40 * Returns zero on success, negative error number otherwise.
41 */
42int mtdev_init(struct mtdev *dev);
43
44/**
45 * mtdev_configure - configure the mtdev converter
46 * @dev: the mtdev to configure
47 * @fd: file descriptor of the kernel device
48 *
49 * Reads the device properties to set up the protocol capabilities.
50 * If preferred, this can be done by hand, omitting this call.
51 *
52 * Returns zero on success, negative error number otherwise.
53 */
54int mtdev_configure(struct mtdev *dev, int fd);
55
56/**
57 * mtdev_fetch_event - fetch an event from the kernel device
58 * @dev: the mtdev in use
59 * @fd: file descriptor of the kernel device
60 * @ev: the kernel input event to fill
61 *
62 * Fetch a kernel event from the kernel device. The read operation
63 * behaves as dictated by the file descriptor; if O_NONBLOCK is not
64 * set, the read will block until an event is available.
65 *
66 * On success, returns the number of events read (0 or 1). Otherwise,
67 * a standard negative error number is returned.
68 */
69int mtdev_fetch_event(struct mtdev *dev, int fd, struct input_event *ev);
70
71/**
72 * mtdev_put_event - put an event into the converter
73 * @dev: the mtdev in use
74 * @ev: the kernel input event to put
75 *
76 * Put a kernel event into the mtdev converter. The event should
77 * come straight from the device.
78 *
79 * This call does not block; if the buffer becomes full, older events
80 * are dropped. The buffer is guaranteed to handle several complete MT
81 * packets.
82 */
83void mtdev_put_event(struct mtdev *dev, const struct input_event *ev);
84
85/**
86 * mtdev_empty - check if there are events to get
87 * @dev: the mtdev in use
88 *
89 * Returns true if the processed event queue is empty, false otherwise.
90 */
91int mtdev_empty(struct mtdev *dev);
92
93/**
94 * mtdev_get_event - get processed events from mtdev
95 * @dev: the mtdev in use
96 * @ev: the input event to fill
97 *
98 * Get a processed event from mtdev. The events appear as if they came
99 * from a type B device emitting MT slot events.
100 *
101 * The queue must be non-empty before calling this function.
102 */
103void mtdev_get_event(struct mtdev *dev, struct input_event* ev);
104
105#endif
diff --git a/include/mtdev.h b/include/mtdev.h
index 98e022a..b759803 100644
--- a/include/mtdev.h
+++ b/include/mtdev.h
@@ -109,28 +109,6 @@ struct mtdev {
109}; 109};
110 110
111/** 111/**
112 * mtdev_init - initialize mtdev converter
113 * @dev: the mtdev to initialize
114 *
115 * Sets up the internal data structures.
116 *
117 * Returns zero on success, negative error number otherwise.
118 */
119int mtdev_init(struct mtdev *dev);
120
121/**
122 * mtdev_configure - configure the mtdev converter
123 * @dev: the mtdev to configure
124 * @fd: file descriptor of the kernel device
125 *
126 * Reads the device properties to set up the protocol capabilities.
127 * If preferred, this can be done by hand, omitting this call.
128 *
129 * Returns zero on success, negative error number otherwise.
130 */
131int mtdev_configure(struct mtdev *dev, int fd);
132
133/**
134 * mtdev_open - open an mtdev converter 112 * mtdev_open - open an mtdev converter
135 * @dev: the mtdev to open 113 * @dev: the mtdev to open
136 * @fd: file descriptor of the kernel device 114 * @fd: file descriptor of the kernel device
@@ -140,8 +118,8 @@ int mtdev_configure(struct mtdev *dev, int fd);
140 * 118 *
141 * Returns zero on success, negative error number otherwise. 119 * Returns zero on success, negative error number otherwise.
142 * 120 *
143 * This call combines mtdev_init() and mtdev_configure(), which 121 * This call combines the plumbing functions mtdev_init() and
144 * may be used separately instead. 122 * mtdev_configure().
145 */ 123 */
146int mtdev_open(struct mtdev *dev, int fd); 124int mtdev_open(struct mtdev *dev, int fd);
147 125
@@ -157,73 +135,26 @@ int mtdev_open(struct mtdev *dev, int fd);
157int mtdev_idle(struct mtdev *dev, int fd, int ms); 135int mtdev_idle(struct mtdev *dev, int fd, int ms);
158 136
159/** 137/**
160 * mtdev_fetch - fetch an event from the kernel device 138 * mtdev_get - get processed events from mtdev
161 * @dev: the mtdev in use
162 * @fd: file descriptor of the kernel device
163 * @ev: the kernel input event to fill
164 *
165 * Fetch a kernel event from the kernel device. The read operation
166 * behaves as dictated by the file descriptor; if O_NONBLOCK is not
167 * set, the read will block until an event is available.
168 *
169 * On success, returns the number of events read. Otherwise, a standard
170 * negative error number is returned.
171 */
172int mtdev_fetch(struct mtdev *dev, int fd, struct input_event *ev);
173
174/**
175 * mtdev_put - put an event into the converter
176 * @dev: the mtdev in use
177 * @ev: the kernel input event to put
178 *
179 * Put a kernel event into the mtdev converter. The event should
180 * come straight from the device.
181 *
182 * This call does not block; if the buffer becomes full, older events
183 * are dropped. The buffer is guaranteed to handle several complete MT
184 * packets.
185 */
186void mtdev_put(struct mtdev *dev, const struct input_event *ev);
187
188/**
189 * mtdev_pull - pull events from the kernel device
190 * @dev: the mtdev in use 139 * @dev: the mtdev in use
191 * @fd: file descriptor of the kernel device 140 * @fd: file descriptor of the kernel device
192 * @max_events: max number of events to read (zero for all) 141 * @ev: array of input events to fill
193 * 142 * @ev_max: maximum number of events to read
194 * Read a maxmimum of max_events events from the device, and put them
195 * in the converter. If max_events is zero, all available events will
196 * be read. The read operation behaves as dictated by the file
197 * descriptor; if O_NONBLOCK is not set, the read will block until
198 * max_events events are available or the buffer is full.
199 * 143 *
200 * On success, returns the number of events read. Otherwise, a standard 144 * Get a processed event from mtdev. The events appear as if they came
201 * negative error number is returned. 145 * from a type B device emitting MT slot events.
202 *
203 * This call combines mtdev_fetch() with mtdev_put(), which
204 * may be used separately instead.
205 */
206int mtdev_pull(struct mtdev *dev, int fd, int max_events);
207
208/**
209 * mtdev_empty - check if there are events to get
210 * @dev: the mtdev in use
211 * 146 *
212 * Returns true if the event queue is empty, false otherwise. 147 * The read operations involved behave as dictated by the file
213 */ 148 * descriptor; if O_NONBLOCK is not set, mtdev_get() will block until
214int mtdev_empty(struct mtdev *dev); 149 * the specified number of processed events are available.
215
216/**
217 * mtdev_get - get canonical events from mtdev
218 * @dev: the mtdev in use
219 * @ev: the input event to fill
220 * 150 *
221 * Get a canonical event from mtdev. The events appear as if they came 151 * On success, returns the number of events read. Otherwise,
222 * from a type B device emitting MT slot events. 152 * a standard negative error number is returned.
223 * 153 *
224 * The queue must be non-empty before calling this function. 154 * This call combines the plumbing functions mtdev_fetch_event(),
155 * mtdev_put_event() and mtdev_get_event().
225 */ 156 */
226void mtdev_get(struct mtdev *dev, struct input_event* ev); 157int mtdev_get(struct mtdev *dev, int fd, struct input_event* ev, int ev_max);
227 158
228/** 159/**
229 * mtdev_close - close the mtdev converter 160 * mtdev_close - close the mtdev converter