Merge lp:~oif-team/geis/geis2-add-device into lp:geis
- geis2-add-device
- Merge into trunk
Proposed by
Stephen M. Webb
Status: | Merged |
---|---|
Merged at revision: | 98 |
Proposed branch: | lp:~oif-team/geis/geis2-add-device |
Merge into: | lp:geis |
Diff against target: |
1099 lines (+802/-161) 12 files modified
ChangeLog (+36/-0) include/geis/geis.h (+230/-160) libutouch-geis/Makefile.am (+1/-0) libutouch-geis/geis_device.c (+273/-0) libutouch-geis/geis_device.h (+104/-0) libutouch-geis/libutouch-geis.ver (+7/-0) testsuite/geis2/Makefile.am (+1/-0) testsuite/geis2/check_device.c (+45/-0) testsuite/geis2/check_geis2_api.c (+2/-0) testsuite/libutouch-geis/Makefile.am (+2/-1) testsuite/libutouch-geis/check_device.c (+99/-0) testsuite/libutouch-geis/check_geis2_internals.c (+2/-0) |
To merge this branch: | bzr merge lp:~oif-team/geis/geis2-add-device |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Henrik Rydberg (community) | Approve | ||
Review via email: mp+44341@code.launchpad.net |
Commit message
Description of the change
Added GEIS v2.0 device module
To post a comment you must log in.
Revision history for this message
Stephen M. Webb (bregma) wrote : | # |
I think you mean the geis.h header.
I had to rearrange a chunk of stuff in include/geis/geis.h to move the GeisEvent declarations before the GeisDevice declarations. It looks like a big diff because the diff machine saw this as moving everything else but the GeisEvent section around. the GeisRegion and GeisSubscriptions chunks are in fact unchanged.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ChangeLog' |
2 | --- ChangeLog 2010-12-20 18:06:36 +0000 |
3 | +++ ChangeLog 2010-12-21 14:03:26 +0000 |
4 | @@ -1,5 +1,41 @@ |
5 | 2010-12-20 Stephen M. Webb <stephen.webb@canonical.com> |
6 | |
7 | + Added GEIS v2.0 input device implementation. |
8 | + |
9 | + * libutouch-geis/geis_device.h (GeisDeviceBag): new type |
10 | + (geis_device_bag_new): new function |
11 | + (geis_device_bag_delete): new function |
12 | + (geis_device_bag_count): new function |
13 | + (geis_device_bag_device): new function |
14 | + (geis_device_bag_insert): new function |
15 | + (geis_device_bag_remove): new function |
16 | + * libutouch-geis/geis_device.c: implemented new functions |
17 | + * testsuite/libutouch-geis/check_device.c: new test suite |
18 | + * testsuite/libutouch-geis/Makefile.am: added new test suite |
19 | + * testsuite/libutouch-geis/check_geis2_internals.c: added new test suite |
20 | + |
21 | +2010-12-20 Stephen M. Webb <stephen.webb@canonical.com> |
22 | + |
23 | + Added GEIS v2.0 input device API |
24 | + |
25 | + * libutouch-geis/geis_device.c: new file |
26 | + * libutouch-geis/geis_device.h: new file |
27 | + * testsuite/geis2/check_device.c: new test suite |
28 | + * include/geis/geis.h (GeisDevice): new type |
29 | + (geis_register_device_callback): new function |
30 | + (geis_device_ref): new function |
31 | + (geis_device_unref): new function |
32 | + (geis_device_name): new function |
33 | + (geis_device_id): new function |
34 | + (geis_device_attr_count): new function |
35 | + (geis_device_attr): new function |
36 | + * libutouch-geis/Makefile.am: added new files |
37 | + * libutouch-geis/libutouch-geis.ver: added new API symbols |
38 | + * testsuite/geis2/Makefile.am: added new test suite |
39 | + * testsuite/geis2/check_geis2_api.c: added new test suite |
40 | + |
41 | +2010-12-20 Stephen M. Webb <stephen.webb@canonical.com> |
42 | + |
43 | Updates to match new GEIS v2.0 spec release of 2010.12.20. |
44 | - added a pointer type to the GEIS attr module |
45 | - added additional required GEIS initialization arguments |
46 | |
47 | === modified file 'include/geis/geis.h' |
48 | --- include/geis/geis.h 2010-12-20 18:06:36 +0000 |
49 | +++ include/geis/geis.h 2010-12-21 14:03:26 +0000 |
50 | @@ -658,166 +658,6 @@ |
51 | /* @} */ |
52 | |
53 | /** |
54 | - * @defgroup geis2_region Gesture Regions (GEIS v2.0) |
55 | - * @{ |
56 | - */ |
57 | - |
58 | -typedef struct _GeisRegion *GeisRegion; |
59 | - |
60 | -/** |
61 | - * @defgroup geis2_region_init_args Gesture Region Initialization Arguments |
62 | - * |
63 | - * Gesture regions are created to describe a particular display/feedback region. |
64 | - * The type of the region can not be changed after creation (just create a new |
65 | - * region for that). The types of regions are platform specific and each type |
66 | - * may require addition arguments. |
67 | - * |
68 | - * The following region initialization argument names are required by the |
69 | - * GEIS v2.0 specification. |
70 | - * |
71 | - * @{ |
72 | - */ |
73 | -#define GEIS_REGION_X11_ROOT "org.libgeis.region.x11.root" |
74 | -#define GEIS_REGION_X11_WINDOWID "org.libgeis.region.x11.windowid" |
75 | - |
76 | -/* @} */ |
77 | - |
78 | -/** |
79 | - * Creates a new GEIS v2.0 region. |
80 | - * |
81 | - * @param[in] geis The GEIS API instance. |
82 | - * @param[in] name A name. Used for diagnostics. |
83 | - * @param[in] init_arg_name The name of the first initialization argument. |
84 | - * |
85 | - * The initialization argument list must be terminated by a NULL. |
86 | - * |
87 | - * @returns a newly created region, or NULL on failure. |
88 | - */ |
89 | -GEIS_API GeisRegion geis_region_new(Geis geis, |
90 | - GeisString name, |
91 | - GeisString init_arg_name, ...); |
92 | - |
93 | -/** |
94 | - * Destroys a GEIS v2.0 region. |
95 | - * |
96 | - * @param[in] region The region. |
97 | - */ |
98 | -GEIS_API GeisStatus geis_region_delete(GeisRegion region); |
99 | - |
100 | -/** |
101 | - * Gets the name of a GEIS v2.0 region. |
102 | - * |
103 | - * @param[in] region The region. |
104 | - * |
105 | - * Returns the @p name value used when creating the region. |
106 | - */ |
107 | -GEIS_API GeisString geis_region_name(GeisRegion region); |
108 | - |
109 | -/* @} */ |
110 | - |
111 | -/** |
112 | - * @defgroup geis2_subscription Gesture Subscription (GEIS v2.0) |
113 | - * @{ |
114 | - */ |
115 | - |
116 | -typedef struct _GeisFilter *GeisFilter; |
117 | -typedef struct _GeisSubscription *GeisSubscription; |
118 | - |
119 | -/** |
120 | - * Flags to refine the behaviour of the gesture subscription. |
121 | - */ |
122 | -typedef enum _GeisSubscriptionFlags |
123 | -{ |
124 | - GEIS_SUBSCRIPTION_NONE = 0x0000, |
125 | - GEIS_SUBSCRIPTION_GRAB = 0x0001, |
126 | - GEIS_SUBSCRIPTION_CONT = 0x0002 |
127 | -} GeisSubscriptionFlags; |
128 | - |
129 | -/** |
130 | - * Creates a new subscription. |
131 | - * |
132 | - * @param[in] geis The GEIS API instance. |
133 | - * @param[in] name A name. |
134 | - * @param[in] flags Some flags. |
135 | - * |
136 | - * @returns a GeisSubscription object or NULL on failure. |
137 | - * |
138 | - * A gesture subscription is required for any gesture events to be delivered |
139 | - * from the GEIS API. |
140 | - */ |
141 | -GEIS_API GeisSubscription geis_subscription_new(Geis geis, |
142 | - GeisString name, |
143 | - GeisSubscriptionFlags flags); |
144 | - |
145 | -/** |
146 | - * Destroys a GEIS v2.0 subscription object. |
147 | - * |
148 | - * @param[in] subscription The subscription. |
149 | - */ |
150 | -GEIS_API GeisStatus geis_subscription_delete(GeisSubscription subscription); |
151 | - |
152 | -/** |
153 | - * Activates a subscription. |
154 | - * |
155 | - * @param[in] subscription The subscription. |
156 | - * |
157 | - * Puts the subscription into the active state. Gesture events will be |
158 | - * delivered for this subscription. |
159 | - */ |
160 | -GEIS_API GeisStatus geis_subscription_activate(GeisSubscription subscription); |
161 | - |
162 | -/** |
163 | - * Deactivates a subscription. |
164 | - * |
165 | - * @param[in] subscription The subscription. |
166 | - * |
167 | - * Puts the subscription into the inactive state. Gesture events will not be |
168 | - * delivered for this subscription. |
169 | - */ |
170 | -GEIS_API GeisStatus geis_subscription_deactivate(GeisSubscription subscription); |
171 | - |
172 | -/** |
173 | - * Gets the name given to a subscription when it was created. |
174 | - * |
175 | - * @param[in] subscription The subscription. |
176 | - */ |
177 | -GEIS_API GeisString geis_subscription_name(GeisSubscription subscription); |
178 | - |
179 | -/** |
180 | - * Gets the ID assigned to a subscription when it was created. |
181 | - * |
182 | - * @param[in] subscription The subscription. |
183 | - */ |
184 | -GEIS_API GeisInteger geis_subscription_id(GeisSubscription subscription); |
185 | - |
186 | -/** |
187 | - * Adds a filter to a subscription. |
188 | - * |
189 | - * @param[in] subscription The subscription. |
190 | - * @param[in] filter The filter to be added to the subscription. |
191 | - * |
192 | - * Thye effect of filters are ANDed together so that, for example, a |
193 | - * subscription that has a filter for 3-finger gestures and drag gestures will |
194 | - * produce events only for 3-finger drag gestures. |
195 | - * |
196 | - * The default is no filters: that is, all possible gesture events will be |
197 | - * reported. |
198 | - */ |
199 | -GEIS_API GeisStatus geis_subscription_add_filter(GeisSubscription subscription, |
200 | - GeisFilter filter); |
201 | - |
202 | -/** |
203 | - * Removes a filter from a subscription. |
204 | - * |
205 | - * @param[in] subscription The subscription. |
206 | - * @param[in] filter The filter to be removed from the subscription. |
207 | - */ |
208 | -GEIS_API GeisStatus geis_subscription_remove_filter(GeisSubscription subscription, |
209 | - GeisFilter filter); |
210 | - |
211 | -/* @} */ |
212 | - |
213 | -/** |
214 | * @defgroup geis2_event_control Event Control (GEIS v2.0) |
215 | * |
216 | * These functions are used to dispatch events generated from the various other |
217 | @@ -978,6 +818,236 @@ |
218 | |
219 | /* @} */ |
220 | |
221 | +/** |
222 | + * @defgroup geis2_device Gesture Input Devices (GEIS v2.0) |
223 | + * @{ |
224 | + */ |
225 | + |
226 | +/** |
227 | + * An opaque pointer type representing a gesture-capable input device. |
228 | + * |
229 | + * GeisDevice objects are created by the GEIS API and are reference counted. |
230 | + */ |
231 | +typedef struct _GeisDevice *GeisDevice; |
232 | + |
233 | +GEIS_API void geis_register_device_callback(Geis geis, |
234 | + GeisEventCallback event_callback, |
235 | + void *context); |
236 | + |
237 | +/** |
238 | + * Adds a reference count to a device. |
239 | + * |
240 | + * @param[in] device The device. |
241 | + * |
242 | + * An application that wishes to guarantee the device object remains valid |
243 | + * should add a reference using this call, and unref when the object is no |
244 | + * longer needed. |
245 | + */ |
246 | +GEIS_API void geis_device_ref(GeisDevice device); |
247 | + |
248 | +/** |
249 | + * Removes a reference count from a device. |
250 | + * |
251 | + * @param[in] device The device. |
252 | + * |
253 | + * This function decrements the number of references to the device and, if the |
254 | + * number of references hits zero, deletes the device. |
255 | + */ |
256 | +GEIS_API void geis_device_unref(GeisDevice device); |
257 | + |
258 | +/** |
259 | + * Gets the name of teh input device. |
260 | + * |
261 | + * @param[in] device The device. |
262 | + */ |
263 | +GEIS_API GeisString geis_device_name(GeisDevice device); |
264 | + |
265 | +/** |
266 | + * Gets the system identifier of the iput device. |
267 | + * |
268 | + * @param[in] device The device. |
269 | + * |
270 | + * The system-defined device identifier is system- and possibly |
271 | + * device-dependent. |
272 | + */ |
273 | +GEIS_API GeisInteger geis_device_id(GeisDevice device); |
274 | + |
275 | +/** |
276 | + * Gets the number of attributes of the device. |
277 | + * |
278 | + * @param[in] device The device. |
279 | + */ |
280 | +GEIS_API GeisSize geis_device_attr_count(GeisDevice device); |
281 | + |
282 | +/** |
283 | + * Gets the indicated attribute of the device. |
284 | + * |
285 | + * @param[in] device The device. |
286 | + */ |
287 | +GEIS_API GeisAttr geis_device_attr(GeisDevice device, GeisSize index); |
288 | + |
289 | +/* @} */ |
290 | + |
291 | +/** |
292 | + * @defgroup geis2_region Gesture Regions (GEIS v2.0) |
293 | + * @{ |
294 | + */ |
295 | + |
296 | +typedef struct _GeisRegion *GeisRegion; |
297 | + |
298 | +/** |
299 | + * @defgroup geis2_region_init_args Gesture Region Initialization Arguments |
300 | + * |
301 | + * Gesture regions are created to describe a particular display/feedback region. |
302 | + * The type of the region can not be changed after creation (just create a new |
303 | + * region for that). The types of regions are platform specific and each type |
304 | + * may require addition arguments. |
305 | + * |
306 | + * The following region initialization argument names are required by the |
307 | + * GEIS v2.0 specification. |
308 | + * |
309 | + * @{ |
310 | + */ |
311 | +#define GEIS_REGION_X11_ROOT "org.libgeis.region.x11.root" |
312 | +#define GEIS_REGION_X11_WINDOWID "org.libgeis.region.x11.windowid" |
313 | + |
314 | +/* @} */ |
315 | + |
316 | +/** |
317 | + * Creates a new GEIS v2.0 region. |
318 | + * |
319 | + * @param[in] geis The GEIS API instance. |
320 | + * @param[in] name A name. Used for diagnostics. |
321 | + * @param[in] init_arg_name The name of the first initialization argument. |
322 | + * |
323 | + * The initialization argument list must be terminated by a NULL. |
324 | + * |
325 | + * @returns a newly created region, or NULL on failure. |
326 | + */ |
327 | +GEIS_API GeisRegion geis_region_new(Geis geis, |
328 | + GeisString name, |
329 | + GeisString init_arg_name, ...); |
330 | + |
331 | +/** |
332 | + * Destroys a GEIS v2.0 region. |
333 | + * |
334 | + * @param[in] region The region. |
335 | + */ |
336 | +GEIS_API GeisStatus geis_region_delete(GeisRegion region); |
337 | + |
338 | +/** |
339 | + * Gets the name of a GEIS v2.0 region. |
340 | + * |
341 | + * @param[in] region The region. |
342 | + * |
343 | + * Returns the @p name value used when creating the region. |
344 | + */ |
345 | +GEIS_API GeisString geis_region_name(GeisRegion region); |
346 | + |
347 | +/* @} */ |
348 | + |
349 | +/** |
350 | + * @defgroup geis2_subscription Gesture Subscription (GEIS v2.0) |
351 | + * @{ |
352 | + */ |
353 | + |
354 | +typedef struct _GeisFilter *GeisFilter; |
355 | +typedef struct _GeisSubscription *GeisSubscription; |
356 | + |
357 | +/** |
358 | + * Flags to refine the behaviour of the gesture subscription. |
359 | + */ |
360 | +typedef enum _GeisSubscriptionFlags |
361 | +{ |
362 | + GEIS_SUBSCRIPTION_NONE = 0x0000, |
363 | + GEIS_SUBSCRIPTION_GRAB = 0x0001, |
364 | + GEIS_SUBSCRIPTION_CONT = 0x0002 |
365 | +} GeisSubscriptionFlags; |
366 | + |
367 | +/** |
368 | + * Creates a new subscription. |
369 | + * |
370 | + * @param[in] geis The GEIS API instance. |
371 | + * @param[in] name A name. |
372 | + * @param[in] flags Some flags. |
373 | + * |
374 | + * @returns a GeisSubscription object or NULL on failure. |
375 | + * |
376 | + * A gesture subscription is required for any gesture events to be delivered |
377 | + * from the GEIS API. |
378 | + */ |
379 | +GEIS_API GeisSubscription geis_subscription_new(Geis geis, |
380 | + GeisString name, |
381 | + GeisSubscriptionFlags flags); |
382 | + |
383 | +/** |
384 | + * Destroys a GEIS v2.0 subscription object. |
385 | + * |
386 | + * @param[in] subscription The subscription. |
387 | + */ |
388 | +GEIS_API GeisStatus geis_subscription_delete(GeisSubscription subscription); |
389 | + |
390 | +/** |
391 | + * Activates a subscription. |
392 | + * |
393 | + * @param[in] subscription The subscription. |
394 | + * |
395 | + * Puts the subscription into the active state. Gesture events will be |
396 | + * delivered for this subscription. |
397 | + */ |
398 | +GEIS_API GeisStatus geis_subscription_activate(GeisSubscription subscription); |
399 | + |
400 | +/** |
401 | + * Deactivates a subscription. |
402 | + * |
403 | + * @param[in] subscription The subscription. |
404 | + * |
405 | + * Puts the subscription into the inactive state. Gesture events will not be |
406 | + * delivered for this subscription. |
407 | + */ |
408 | +GEIS_API GeisStatus geis_subscription_deactivate(GeisSubscription subscription); |
409 | + |
410 | +/** |
411 | + * Gets the name given to a subscription when it was created. |
412 | + * |
413 | + * @param[in] subscription The subscription. |
414 | + */ |
415 | +GEIS_API GeisString geis_subscription_name(GeisSubscription subscription); |
416 | + |
417 | +/** |
418 | + * Gets the ID assigned to a subscription when it was created. |
419 | + * |
420 | + * @param[in] subscription The subscription. |
421 | + */ |
422 | +GEIS_API GeisInteger geis_subscription_id(GeisSubscription subscription); |
423 | + |
424 | +/** |
425 | + * Adds a filter to a subscription. |
426 | + * |
427 | + * @param[in] subscription The subscription. |
428 | + * @param[in] filter The filter to be added to the subscription. |
429 | + * |
430 | + * Thye effect of filters are ANDed together so that, for example, a |
431 | + * subscription that has a filter for 3-finger gestures and drag gestures will |
432 | + * produce events only for 3-finger drag gestures. |
433 | + * |
434 | + * The default is no filters: that is, all possible gesture events will be |
435 | + * reported. |
436 | + */ |
437 | +GEIS_API GeisStatus geis_subscription_add_filter(GeisSubscription subscription, |
438 | + GeisFilter filter); |
439 | + |
440 | +/** |
441 | + * Removes a filter from a subscription. |
442 | + * |
443 | + * @param[in] subscription The subscription. |
444 | + * @param[in] filter The filter to be removed from the subscription. |
445 | + */ |
446 | +GEIS_API GeisStatus geis_subscription_remove_filter(GeisSubscription subscription, |
447 | + GeisFilter filter); |
448 | + |
449 | +/* @} */ |
450 | + |
451 | #ifdef __cplusplus |
452 | } // extern "C" |
453 | #endif |
454 | |
455 | === modified file 'libutouch-geis/Makefile.am' |
456 | --- libutouch-geis/Makefile.am 2010-12-20 18:06:36 +0000 |
457 | +++ libutouch-geis/Makefile.am 2010-12-21 14:03:26 +0000 |
458 | @@ -28,6 +28,7 @@ |
459 | geis_backend_protected.h \ |
460 | geis_backend_multiplexor.h geis_backend_multiplexor.c \ |
461 | geis_backend_test_fixture.h geis_backend_test_fixture.c \ |
462 | + geis_device.h geis_device.c \ |
463 | geis_error.h geis_error.c \ |
464 | geis_event.h geis_event.c \ |
465 | geis_event_queue.h geis_event_queue.c \ |
466 | |
467 | === added file 'libutouch-geis/geis_device.c' |
468 | --- libutouch-geis/geis_device.c 1970-01-01 00:00:00 +0000 |
469 | +++ libutouch-geis/geis_device.c 2010-12-21 14:03:26 +0000 |
470 | @@ -0,0 +1,273 @@ |
471 | +/** |
472 | + * @file libutouch-geis/geis_region.c |
473 | + * @brief implementation of the uTouch GEIS v2.0 API Input Device module |
474 | + * |
475 | + * Copyright 2010 Canonical Ltd. |
476 | + * |
477 | + * This library is free software; you can redistribute it and/or modify it under |
478 | + * the terms of the GNU Lesser General Public License as published by the Free |
479 | + * Software Foundation; either version 3 of the License, or (at your option) any |
480 | + * later version. |
481 | + * |
482 | + * This library is distributed in the hope that it will be useful, but WITHOUT |
483 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
484 | + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
485 | + * details. |
486 | + * |
487 | + * You should have received a copy of the GNU Lesser General Public License |
488 | + * along with this program; if not, write to the Free Software Foundation, Inc., |
489 | + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
490 | + */ |
491 | +#include "geis_config.h" |
492 | +#include "geis_device.h" |
493 | + |
494 | +#include "geis_attr.h" |
495 | +#include "geis_logging.h" |
496 | +#include <stdlib.h> |
497 | +#include <string.h> |
498 | + |
499 | + |
500 | +struct _GeisDevice |
501 | +{ |
502 | + GeisSize ref_count; |
503 | + GeisString name; |
504 | + GeisInteger id; |
505 | + GeisAttrBag attr_bag; |
506 | +}; |
507 | + |
508 | +struct _GeisDeviceBag |
509 | +{ |
510 | + GeisDevice *device_store; |
511 | + GeisSize device_store_size; |
512 | + GeisSize device_count; |
513 | +}; |
514 | + |
515 | +static const int device_bag_growth_constant = 2; |
516 | + |
517 | + |
518 | +GeisDeviceBag |
519 | +geis_device_bag_new() |
520 | +{ |
521 | + GeisDeviceBag bag = calloc(1, sizeof(struct _GeisDeviceBag)); |
522 | + if (!bag) |
523 | + { |
524 | + geis_error("error allocating device bag"); |
525 | + goto final_exit; |
526 | + } |
527 | + |
528 | + bag->device_store = calloc(1, sizeof(struct _GeisDevice)); |
529 | + if (!bag->device_store) |
530 | + { |
531 | + geis_error("error allocating device bag store"); |
532 | + goto unwind_bag; |
533 | + } |
534 | + |
535 | + bag->device_store_size = 1; |
536 | + bag->device_count = 0; |
537 | + goto final_exit; |
538 | + |
539 | +unwind_bag: |
540 | + free(bag); |
541 | + bag = NULL; |
542 | +final_exit: |
543 | + return bag; |
544 | +} |
545 | + |
546 | + |
547 | +void |
548 | +geis_device_bag_delete(GeisDeviceBag bag) |
549 | +{ |
550 | + GeisSize i; |
551 | + for (i = bag->device_count; i > 0; --i) |
552 | + { |
553 | + geis_device_unref(bag->device_store[i-1]); |
554 | + } |
555 | + free(bag->device_store); |
556 | + free(bag); |
557 | +} |
558 | + |
559 | + |
560 | +GeisSize |
561 | +geis_device_bag_count(GeisDeviceBag bag) |
562 | +{ |
563 | + return bag->device_count; |
564 | +} |
565 | + |
566 | + |
567 | +GeisDevice |
568 | +geis_device_bag_device(GeisDeviceBag bag, GeisSize index) |
569 | +{ |
570 | + GeisDevice device = NULL; |
571 | + if (index >= bag->device_count) |
572 | + { |
573 | + geis_warning("device bag index out of range"); |
574 | + } |
575 | + else |
576 | + { |
577 | + device = bag->device_store[index]; |
578 | + } |
579 | + return device; |
580 | +} |
581 | + |
582 | + |
583 | +GeisStatus |
584 | +geis_device_bag_insert(GeisDeviceBag bag, GeisDevice device) |
585 | +{ |
586 | + GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR; |
587 | + if (bag->device_count >= bag->device_store_size) |
588 | + { |
589 | + GeisSize new_store_size = bag->device_store_size * device_bag_growth_constant; |
590 | + GeisDevice *new_store = realloc(bag->device_store, |
591 | + new_store_size * sizeof(struct _GeisDevice)); |
592 | + if (!new_store) |
593 | + { |
594 | + geis_error("failed to reallocate device bag"); |
595 | + goto error_exit; |
596 | + } |
597 | + bag->device_store = new_store; |
598 | + bag->device_store_size = new_store_size; |
599 | + } |
600 | + bag->device_store[bag->device_count++] = device; |
601 | + status = GEIS_STATUS_SUCCESS; |
602 | + |
603 | +error_exit: |
604 | + return status; |
605 | +} |
606 | + |
607 | +GeisStatus |
608 | +geis_device_bag_remove(GeisDeviceBag bag, GeisDevice device) |
609 | +{ |
610 | + GeisSize i; |
611 | + GeisStatus status = GEIS_STATUS_SUCCESS; |
612 | + for (i = 0; i < bag->device_count; ++i) |
613 | + { |
614 | + if (bag->device_store[i] == device) |
615 | + { |
616 | + GeisSize j; |
617 | + geis_device_unref(bag->device_store[i]); |
618 | + --bag->device_count; |
619 | + for (j = i; j < bag->device_count; ++j) |
620 | + { |
621 | + bag->device_store[j] = bag->device_store[j+1]; |
622 | + } |
623 | + break; |
624 | + } |
625 | + } |
626 | + return status; |
627 | +} |
628 | + |
629 | + |
630 | +/* |
631 | + * Creates a new, empty device. |
632 | + */ |
633 | +GeisDevice |
634 | +geis_device_new(GeisString name, GeisInteger id) |
635 | +{ |
636 | + GeisDevice device = calloc(1, sizeof(struct _GeisDevice)); |
637 | + if (!device) |
638 | + { |
639 | + geis_error("error allocating input device"); |
640 | + goto final_exit; |
641 | + } |
642 | + |
643 | + device->attr_bag = geis_attr_bag_new(4); |
644 | + if (!device->attr_bag) |
645 | + { |
646 | + geis_debug("error allocating attr bag"); |
647 | + goto unwind_device; |
648 | + } |
649 | + |
650 | + device->name = strdup(name); |
651 | + if (!device->name) |
652 | + { |
653 | + geis_debug("error allocating device name"); |
654 | + goto unwind_attrs; |
655 | + } |
656 | + |
657 | + device->id = id; |
658 | + geis_device_ref(device); |
659 | + goto final_exit; |
660 | + |
661 | +unwind_attrs: |
662 | + geis_attr_bag_delete(device->attr_bag); |
663 | +unwind_device: |
664 | + free(device); |
665 | + device = NULL; |
666 | +final_exit: |
667 | + return device; |
668 | +} |
669 | + |
670 | + |
671 | +/* |
672 | + * Destroys a device. |
673 | + */ |
674 | +static void |
675 | +_device_delete(GeisDevice device) |
676 | +{ |
677 | + free((char *)device->name); |
678 | + free(device); |
679 | +} |
680 | + |
681 | + |
682 | +/* |
683 | + * Adds a reference count to a device. |
684 | + */ |
685 | +void |
686 | +geis_device_ref(GeisDevice device) |
687 | +{ |
688 | + __sync_add_and_fetch(&device->ref_count, 1); |
689 | +} |
690 | + |
691 | + |
692 | +/* |
693 | + * Removes a reference count from a device. |
694 | + */ |
695 | +void |
696 | +geis_device_unref(GeisDevice device) |
697 | +{ |
698 | + if (0 == __sync_sub_and_fetch(&device->ref_count, 1)) |
699 | + { |
700 | + _device_delete(device); |
701 | + } |
702 | +} |
703 | + |
704 | + |
705 | +/* |
706 | + * Gets the name of teh input device. |
707 | + */ |
708 | +GeisString |
709 | +geis_device_name(GeisDevice device) |
710 | +{ |
711 | + return device->name; |
712 | +} |
713 | + |
714 | + |
715 | +/* |
716 | + * Gets the system identifier of the iput device. |
717 | + */ |
718 | +GeisInteger |
719 | +geis_device_id(GeisDevice device) |
720 | +{ |
721 | + return device->id; |
722 | +} |
723 | + |
724 | + |
725 | +/* |
726 | + * Gets the number of attributes of the device. |
727 | + */ |
728 | +GeisSize |
729 | +geis_device_attr_count(GeisDevice device) |
730 | +{ |
731 | + return geis_attr_bag_count(device->attr_bag); |
732 | +} |
733 | + |
734 | + |
735 | +/* |
736 | + * Gets the indicated attribute of the device. |
737 | + */ |
738 | +GeisAttr |
739 | +geis_device_attr(GeisDevice device, GeisSize index) |
740 | +{ |
741 | + return geis_attr_bag_attr(device->attr_bag, index); |
742 | +} |
743 | + |
744 | |
745 | === added file 'libutouch-geis/geis_device.h' |
746 | --- libutouch-geis/geis_device.h 1970-01-01 00:00:00 +0000 |
747 | +++ libutouch-geis/geis_device.h 2010-12-21 14:03:26 +0000 |
748 | @@ -0,0 +1,104 @@ |
749 | +/** |
750 | + * @file geis_device.h |
751 | + * @brief internal uTouch Geis Input Device module private interface |
752 | + * |
753 | + * Copyright 2010 Canonical Ltd. |
754 | + * |
755 | + * This library is free software; you can redistribute it and/or modify it under |
756 | + * the terms of the GNU Lesser General Public License as published by the Free |
757 | + * Software Foundation; either version 3 of the License, or (at your option) any |
758 | + * later version. |
759 | + * |
760 | + * This library is distributed in the hope that it will be useful, but WITHOUT |
761 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
762 | + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
763 | + * details. |
764 | + * |
765 | + * You should have received a copy of the GNU Lesser General Public License |
766 | + * along with this program; if not, write to the Free Software Foundation, Inc., |
767 | + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
768 | + */ |
769 | +#ifndef GEIS_DEVICE_H_ |
770 | +#define GEIS_DEVICE_H_ |
771 | + |
772 | +#include "geis/geis.h" |
773 | + |
774 | +/** |
775 | + * @defgroup utouch_geis_device_container A Device Container |
776 | + * @{ |
777 | + */ |
778 | + |
779 | +/** |
780 | + * An unsorted container for holding devices. |
781 | + */ |
782 | +typedef struct _GeisDeviceBag *GeisDeviceBag; |
783 | + |
784 | +/** |
785 | + * Creates a new device bag, |
786 | + */ |
787 | +GeisDeviceBag geis_device_bag_new(); |
788 | + |
789 | +/** |
790 | + * Destroys a device bag. |
791 | + * |
792 | + * @param[in] bag The device bag, |
793 | + */ |
794 | +void geis_device_bag_delete(GeisDeviceBag bag); |
795 | + |
796 | +/** |
797 | + * Gets the number of devices in the bag. |
798 | + * |
799 | + * @param[in] bag The device bag, |
800 | + */ |
801 | +GeisSize geis_device_bag_count(GeisDeviceBag bag); |
802 | + |
803 | +/** |
804 | + * Gets an indicated device from a bag. |
805 | + * |
806 | + * @param[in] bag The device bag. |
807 | + * @param[in] index The index. |
808 | + */ |
809 | +GeisDevice geis_device_bag_device(GeisDeviceBag bag, GeisSize index); |
810 | + |
811 | +/** |
812 | + * Inserts a device in teh bag. |
813 | + * |
814 | + * @param[in] bag The device bag. |
815 | + * @param[in] device The device to insert. |
816 | + */ |
817 | +GeisStatus geis_device_bag_insert(GeisDeviceBag bag, GeisDevice device); |
818 | + |
819 | +/** |
820 | + * Remoes a device from the bag. |
821 | + * |
822 | + * @param[in] bag The device bag. |
823 | + * @param[in] device The device to remove. |
824 | + */ |
825 | +GeisStatus geis_device_bag_remove(GeisDeviceBag bag, GeisDevice device); |
826 | + |
827 | +/** @} */ |
828 | + |
829 | +/** |
830 | + * @defgroup utouch_geis_device Internal Device Functions |
831 | + * @{ |
832 | + */ |
833 | + |
834 | +/** |
835 | + * Creates a new device. |
836 | + * |
837 | + * @param[in] name A system-specific device name. |
838 | + * @param[in] id A system-specific device identifier. |
839 | + */ |
840 | +GeisDevice geis_device_new(GeisString name, GeisInteger id); |
841 | + |
842 | +/** |
843 | + * Inserts an attr into a device. |
844 | + * |
845 | + * @param[in] device A device. |
846 | + * @param[in] attr An attr. |
847 | + */ |
848 | +void geis_device_add_attr(GeisDevice device, GeisAttr attr); |
849 | + |
850 | +/* @} */ |
851 | + |
852 | +#endif /* GEIS_DEVICE_H_ */ |
853 | |
854 | === modified file 'libutouch-geis/libutouch-geis.ver' |
855 | --- libutouch-geis/libutouch-geis.ver 2010-12-20 18:06:36 +0000 |
856 | +++ libutouch-geis/libutouch-geis.ver 2010-12-21 14:03:26 +0000 |
857 | @@ -21,6 +21,12 @@ |
858 | geis_attr_value_to_pointer; |
859 | geis_attr_value_to_string; |
860 | geis_delete; |
861 | + geis_device_attr; |
862 | + geis_device_attr_count; |
863 | + geis_device_id; |
864 | + geis_device_name; |
865 | + geis_device_ref; |
866 | + geis_device_unref; |
867 | geis_dispatch_events; |
868 | geis_error_code; |
869 | geis_error_count; |
870 | @@ -31,6 +37,7 @@ |
871 | geis_region_delete; |
872 | geis_region_name; |
873 | geis_region_new; |
874 | + geis_register_device_callback; |
875 | geis_register_event_callback; |
876 | geis_set_configuration; |
877 | geis_subscription_activate; |
878 | |
879 | === modified file 'testsuite/geis2/Makefile.am' |
880 | --- testsuite/geis2/Makefile.am 2010-12-20 18:06:36 +0000 |
881 | +++ testsuite/geis2/Makefile.am 2010-12-21 14:03:26 +0000 |
882 | @@ -16,6 +16,7 @@ |
883 | check_geis2_api_SOURCES = \ |
884 | check_attr.c \ |
885 | check_config.c \ |
886 | + check_device.c \ |
887 | check_error_codes.c \ |
888 | check_event.c \ |
889 | check_geis_new.c \ |
890 | |
891 | === added file 'testsuite/geis2/check_device.c' |
892 | --- testsuite/geis2/check_device.c 1970-01-01 00:00:00 +0000 |
893 | +++ testsuite/geis2/check_device.c 2010-12-21 14:03:26 +0000 |
894 | @@ -0,0 +1,45 @@ |
895 | +/** |
896 | + * Unit tests for GEIS v2.0 Input Device Module. |
897 | + */ |
898 | +#include <check.h> |
899 | + |
900 | +#include <geis/geis.h> |
901 | + |
902 | +/* Compile-time test to ensure types are defined */ |
903 | +START_TEST(geis_device_types) |
904 | +{ |
905 | + GeisEventType type; |
906 | +} |
907 | +END_TEST |
908 | + |
909 | +/* Compile-and-link-time test to verify required functions exist */ |
910 | +START_TEST(geis_device_functions) |
911 | +{ |
912 | + Geis geis; |
913 | + GeisEventCallback callback; |
914 | + GeisDevice device; |
915 | + geis_register_device_callback(geis, callback, NULL); |
916 | + |
917 | + geis_device_ref(device); |
918 | + geis_device_unref(device); |
919 | + GeisString n = geis_device_name(device); |
920 | + GeisInteger i = geis_device_id(device); |
921 | + GeisSize s = geis_device_attr_count(device); |
922 | + GeisAttr a = geis_device_attr(device, 0); |
923 | +} |
924 | +END_TEST |
925 | + |
926 | + |
927 | +/* boilerplate */ |
928 | +Suite * |
929 | +geis2_device_suite_new() |
930 | +{ |
931 | + Suite *s = suite_create("geis2_device"); |
932 | + |
933 | + TCase *device = tcase_create("geis2_device"); |
934 | + tcase_add_test(device, geis_device_types); |
935 | + suite_add_tcase(s, device); |
936 | + |
937 | + return s; |
938 | +} |
939 | + |
940 | |
941 | === modified file 'testsuite/geis2/check_geis2_api.c' |
942 | --- testsuite/geis2/check_geis2_api.c 2010-12-20 18:06:36 +0000 |
943 | +++ testsuite/geis2/check_geis2_api.c 2010-12-21 14:03:26 +0000 |
944 | @@ -7,6 +7,7 @@ |
945 | extern Suite *make_version_macro_suite(); |
946 | extern Suite *geis2_general_types_suite_new(); |
947 | extern Suite *geis2_error_codes_suite_new(); |
948 | +extern Suite *geis2_device_suite_new(); |
949 | extern Suite *geis2_geis_new_suite_new(); |
950 | extern Suite *geis2_config_suite_new(); |
951 | extern Suite *geis2_attr_suite_new(); |
952 | @@ -29,6 +30,7 @@ |
953 | srunner_add_suite(sr, geis2_config_suite_new()); |
954 | srunner_add_suite(sr, geis2_attr_suite_new()); |
955 | srunner_add_suite(sr, geis2_region_suite_new()); |
956 | + srunner_add_suite(sr, geis2_device_suite_new()); |
957 | srunner_add_suite(sr, geis2_subscription_suite_new()); |
958 | srunner_add_suite(sr, geis2_event_suite_new()); |
959 | |
960 | |
961 | === modified file 'testsuite/libutouch-geis/Makefile.am' |
962 | --- testsuite/libutouch-geis/Makefile.am 2010-12-20 18:06:36 +0000 |
963 | +++ testsuite/libutouch-geis/Makefile.am 2010-12-21 14:03:26 +0000 |
964 | @@ -32,10 +32,11 @@ |
965 | |
966 | check_geis2_internals_SOURCES = \ |
967 | check_attr.c \ |
968 | - check_geis_private.c \ |
969 | check_backend_multiplexor.c \ |
970 | + check_device.c \ |
971 | check_error_reporting.c \ |
972 | check_event_queue.c \ |
973 | + check_geis_private.c \ |
974 | check_region.c \ |
975 | check_subscription.c \ |
976 | check_geis2_internals.c |
977 | |
978 | === added file 'testsuite/libutouch-geis/check_device.c' |
979 | --- testsuite/libutouch-geis/check_device.c 1970-01-01 00:00:00 +0000 |
980 | +++ testsuite/libutouch-geis/check_device.c 2010-12-21 14:03:26 +0000 |
981 | @@ -0,0 +1,99 @@ |
982 | +/** |
983 | + * unit tests for the geis device module |
984 | + */ |
985 | +#include <check.h> |
986 | + |
987 | +#include "libutouch-geis/geis_device.h" |
988 | + |
989 | + |
990 | +/* fixtures */ |
991 | +static GeisDeviceBag g_device_bag; |
992 | +static GeisString g_device_name = "device"; |
993 | +static GeisInteger g_device_id = 12; |
994 | + |
995 | +/* fixture setup */ |
996 | +static void |
997 | +construct_bag() |
998 | +{ |
999 | + g_device_bag = geis_device_bag_new(); |
1000 | +} |
1001 | + |
1002 | +/* fixture teardown */ |
1003 | +static void |
1004 | +destroy_bag() |
1005 | +{ |
1006 | + geis_device_bag_delete(g_device_bag); |
1007 | +} |
1008 | + |
1009 | +/* verify bag construction/destruction */ |
1010 | +START_TEST(construct) |
1011 | +{ |
1012 | + GeisDeviceBag bag = geis_device_bag_new(); |
1013 | + fail_unless(bag != NULL, "failed to create device bag"); |
1014 | + geis_device_bag_delete(bag); |
1015 | +} |
1016 | +END_TEST |
1017 | + |
1018 | +/* verify bag insertion */ |
1019 | +START_TEST(insert) |
1020 | +{ |
1021 | + GeisDevice device = geis_device_new(g_device_name, g_device_id); |
1022 | + geis_device_bag_insert(g_device_bag, device); |
1023 | + fail_unless(geis_device_bag_count(g_device_bag) == 1, |
1024 | + "unexpected bag size after insertion"); |
1025 | +} |
1026 | +END_TEST |
1027 | + |
1028 | +/* verify bag removal */ |
1029 | +START_TEST(remove) |
1030 | +{ |
1031 | + GeisDevice device = geis_device_new(g_device_name, g_device_id); |
1032 | + geis_device_bag_insert(g_device_bag, device); |
1033 | + fail_unless(geis_device_bag_count(g_device_bag) == 1, |
1034 | + "unexpected bag size after insertion"); |
1035 | + geis_device_bag_remove(g_device_bag, device); |
1036 | + fail_unless(geis_device_bag_count(g_device_bag) == 0, |
1037 | + "unexpected bag size after removal"); |
1038 | +} |
1039 | +END_TEST |
1040 | + |
1041 | +START_TEST(expand) |
1042 | +{ |
1043 | + int i; |
1044 | + for (i = 0; i < 24; ++i) |
1045 | + { |
1046 | + GeisSize count; |
1047 | + char name[32]; |
1048 | + sprintf(name, "%04d", i); |
1049 | + GeisDevice device = geis_device_new(name, i); |
1050 | + geis_device_bag_insert(g_device_bag, device); |
1051 | + count = geis_device_bag_count(g_device_bag); |
1052 | + fail_unless(count == (i+1), |
1053 | + "unexpected bag size %ld after insertion, expected %d", |
1054 | + count, i+1); |
1055 | + } |
1056 | +} |
1057 | +END_TEST |
1058 | + |
1059 | + |
1060 | + |
1061 | +/* boilerplate */ |
1062 | +Suite * |
1063 | +make_device_suite() |
1064 | +{ |
1065 | + Suite *s = suite_create("utouch-geis2-device"); |
1066 | + |
1067 | + TCase *create = tcase_create("device-bag-creation"); |
1068 | + tcase_add_test(create, construct); |
1069 | + suite_add_tcase(s, create); |
1070 | + |
1071 | + TCase *usage = tcase_create("device-bag-usage"); |
1072 | + tcase_add_checked_fixture(usage, construct_bag, destroy_bag); |
1073 | + tcase_add_test(usage, insert); |
1074 | + tcase_add_test(usage, remove); |
1075 | + tcase_add_test(usage, expand); |
1076 | + suite_add_tcase(s, usage); |
1077 | + |
1078 | + return s; |
1079 | +} |
1080 | + |
1081 | |
1082 | === modified file 'testsuite/libutouch-geis/check_geis2_internals.c' |
1083 | --- testsuite/libutouch-geis/check_geis2_internals.c 2010-12-17 02:56:43 +0000 |
1084 | +++ testsuite/libutouch-geis/check_geis2_internals.c 2010-12-21 14:03:26 +0000 |
1085 | @@ -8,6 +8,7 @@ |
1086 | extern Suite *make_attr_suite(); |
1087 | extern Suite *make_backend_event_posting_suite(); |
1088 | extern Suite *make_backend_multiplexor_suite(); |
1089 | +extern Suite *make_device_suite(); |
1090 | extern Suite *make_error_reporting_suite(); |
1091 | extern Suite *make_event_queue_suite(); |
1092 | extern Suite *make_region_suite(); |
1093 | @@ -27,6 +28,7 @@ |
1094 | srunner_add_suite(sr, make_event_queue_suite()); |
1095 | srunner_add_suite(sr, make_backend_multiplexor_suite()); |
1096 | srunner_add_suite(sr, make_backend_event_posting_suite()); |
1097 | + srunner_add_suite(sr, make_device_suite()); |
1098 | srunner_add_suite(sr, make_region_suite()); |
1099 | srunner_add_suite(sr, make_subscription_suite()); |
1100 |
Are the region defines untouched in this branch? It seems like it from the logs, but there is quite a bit of diff touching the region header.