Merge lp:~oif-team/geis/geis2-add-gesture-class into lp:geis
- geis2-add-gesture-class
- Merge into trunk
Proposed by
Stephen M. Webb
Status: | Merged |
---|---|
Merged at revision: | 101 |
Proposed branch: | lp:~oif-team/geis/geis2-add-gesture-class |
Merge into: | lp:geis |
Diff against target: |
1427 lines (+1030/-31) 21 files modified
ChangeLog (+70/-0) include/geis/geis.h (+102/-9) libutouch-geis/Makefile.am (+1/-0) libutouch-geis/backend/test_fixture/geis_backend_test_fixture.c (+33/-1) libutouch-geis/backend/test_fixture/geis_backend_test_fixture.h (+3/-1) libutouch-geis/geis.c (+119/-4) libutouch-geis/geis_class.c (+327/-0) libutouch-geis/geis_class.h (+108/-0) libutouch-geis/geis_filter.c (+4/-1) libutouch-geis/geis_private.h (+15/-0) libutouch-geis/libutouch-geis.ver (+7/-0) testsuite/geis2/Makefile.am (+1/-0) testsuite/geis2/check_class.c (+98/-0) testsuite/geis2/check_event.c (+3/-2) testsuite/geis2/check_filter.c (+1/-1) testsuite/geis2/check_geis2_api.c (+3/-1) testsuite/geis2/check_geis_new.c (+1/-1) testsuite/geis2/check_subscription.c (+32/-10) testsuite/libutouch-geis/Makefile.am (+1/-0) testsuite/libutouch-geis/check_class.c (+99/-0) testsuite/libutouch-geis/check_geis2_internals.c (+2/-0) |
To merge this branch: | bzr merge lp:~oif-team/geis/geis2-add-gesture-class |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chase Douglas (community) | Approve | ||
Review via email: mp+46141@code.launchpad.net |
Commit message
Description of the change
Adds the GEIS v2.0 gesture class module.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ChangeLog' |
2 | --- ChangeLog 2011-01-06 00:56:16 +0000 |
3 | +++ ChangeLog 2011-01-13 16:20:11 +0000 |
4 | @@ -1,3 +1,73 @@ |
5 | +2011-01-06 Stephen M. Webb <stephen.webb@canonical.com> |
6 | + |
7 | + Added Geis v2.0 gesture class implementation (part 2, utouch internals) |
8 | + |
9 | + * testsuite/libutouch-geis/check_class.c: new test suite |
10 | + * include/geis/geis.h: fixed GEIS_FILTER_CLASS |
11 | + * libutouch-geis/backend/test_fixture/geis_backend_test_fixture.c |
12 | + (_create_test_classes): new function |
13 | + * libutouch-geis/backend/test_fixture/geis_backend_test_fixture.h |
14 | + (geis_backend_new_test_fixture): added track_classes parameter |
15 | + * libutouch-geis/geis.c (struct _Geis): added new fields |
16 | + (_class_event_handler): implemented event handling |
17 | + (geis_new_empty): initialized new fields |
18 | + (_set_valist): handled GEIS_INIT_TRACK_GESTURE_CLASSES |
19 | + (geis_get_class_attr_type): new function |
20 | + * libutouch-geis/geis_class.h (GeisGestureClassBag): new data structure |
21 | + (geis_gesture_class_bag_new): new function |
22 | + (geis_gesture_class_bag_delete): new function |
23 | + (geis_gesture_class_bag_count): new function |
24 | + (geis_gesture_class_bag_gesture_class): new function |
25 | + (geis_gesture_class_bag_insert): new function |
26 | + (geis_gesture_class_bag_remove): new function |
27 | + * libutouch-geis/geis_class.c: implemented above new functions |
28 | + * libutouch-geis/geis_filter.c (_facility_is_valid): fixed facility name |
29 | + * libutouch-geis/geis_private.h (geis_get_class_attr_type): new function |
30 | + * testsuite/geis2/check_filter.c: fixed facility name |
31 | + * testsuite/geis2/check_subscription.c: added check for class subscription |
32 | + * testsuite/libutouch-geis/Makefile.am: added new test suite file |
33 | + * testsuite/libutouch-geis/check_geis2_internals.c: called new test suite |
34 | + |
35 | +2011-01-06 Stephen M. Webb <stephen.webb@canonical.com> |
36 | + |
37 | + Added Geis v2.0 gesture class implementation (part 1, basic API) |
38 | + |
39 | + * libutouch-geis/geis_class.c: new file |
40 | + * libutouch-geis/geis_class.h: new file |
41 | + * libutouch-geis/Makefile.am: added new source files |
42 | + * libutouch-geis/geis.c (struct _Geis): added new class callback fields |
43 | + (_class_event_handler): new function |
44 | + (_input_event_handler): added case for gesture class events |
45 | + (geis_register_class_callback): implemented function |
46 | + * include/geis/geis.h (geis_gesture_class_ref): adjusted return type |
47 | + (geis_gesture_class_unref): same |
48 | + |
49 | +2011-01-06 Stephen M. Webb <stephen.webb@canonical.com> |
50 | + |
51 | + Added GEIS v2.0 gesture class API |
52 | + |
53 | + * testsuite/geis2/check_class.c: new test suite |
54 | + * include/geis/geis.h (GEIS_INIT_TRACK_GESTURE_CLASSES): new init ath |
55 | + (GEIS_EVENT_CLASS_AVAILABLE): new event type |
56 | + (GEIS_EVENT_CLASS_CHANGED): new event type |
57 | + (GEIS_EVENT_CLASS_UNAVAILABLE): new event type |
58 | + (GeisGestureClass): new opaque type |
59 | + (GEIS_CLASS_ATTRIBUTE_NAME): new attribute name |
60 | + (GEIS_CLASS_ATTRIBUTE_ID): new attribute name |
61 | + (GEIS_EVENT_ATTRIBUTE_CLASS): new attribute name |
62 | + (geis_register_class_callback): new function |
63 | + (geis_gesture_class_ref): new function |
64 | + (geis_gesture_class_unref): new function |
65 | + (geis_gesture_class_name): new function |
66 | + (geis_gesture_class_id): new function |
67 | + (geis_gesture_class_attr_count): new function |
68 | + (geis_gesture_class_attr): new function |
69 | + * libutouch-geis/libutouch-geis.ver: added new exported symbols |
70 | + * testsuite/geis2/Makefile.am: build new test suite |
71 | + * testsuite/geis2/check_event.c: changed event type names |
72 | + * testsuite/geis2/check_geis2_api.c: used new test suite |
73 | + * testsuite/geis2/check_geis_new.c: changed init constant names |
74 | + |
75 | 2011-01-05 Stephen M. Webb <stephen.webb@canonical.com> |
76 | |
77 | Minor tweaks. |
78 | |
79 | === modified file 'include/geis/geis.h' |
80 | --- include/geis/geis.h 2011-01-06 00:56:16 +0000 |
81 | +++ include/geis/geis.h 2011-01-13 16:20:11 +0000 |
82 | @@ -1,7 +1,8 @@ |
83 | /** |
84 | - * geis.h |
85 | + * @file geis/geis.h |
86 | + * This is the public interface for the GEIS gesture API. |
87 | * |
88 | - * Copyright 2010 Canonical Ltd. |
89 | + * Copyright 2010, 2011 Canonical Ltd. |
90 | * |
91 | * This library is free software; you can redistribute it and/or modify it under |
92 | * the terms of the GNU Lesser General Public License as published by the Free |
93 | @@ -223,11 +224,11 @@ |
94 | #define GEIS_INIT_TRACK_DEVICES "org.libgeis.init.track-devices" |
95 | |
96 | /** |
97 | - * Tells GEIS to send gesture type events. |
98 | + * Tells GEIS to send gesture class events. |
99 | * |
100 | * This initialization argument takes no parameters. |
101 | */ |
102 | -#define GEIS_INIT_TRACK_GESTURE_TYPES "org.libgeis.init.track-gesture-types" |
103 | +#define GEIS_INIT_TRACK_GESTURE_CLASSES "org.libgeis.init.track-gesture-classes" |
104 | |
105 | /* @} */ |
106 | |
107 | @@ -677,8 +678,9 @@ |
108 | { |
109 | GEIS_EVENT_DEVICE_AVAILABLE = 1000, |
110 | GEIS_EVENT_DEVICE_UNAVAILABLE = 1010, |
111 | - GEIS_EVENT_GESTURE_TYPE_AVAILABLE = 2000, |
112 | - GEIS_EVENT_GESTURE_TYPE_UNAVAILABLE = 2010, |
113 | + GEIS_EVENT_CLASS_AVAILABLE = 2000, |
114 | + GEIS_EVENT_CLASS_CHANGED = 2005, |
115 | + GEIS_EVENT_CLASS_UNAVAILABLE = 2010, |
116 | GEIS_EVENT_GESTURE_BEGIN = 3000, |
117 | GEIS_EVENT_GESTURE_UPDATE = 3010, |
118 | GEIS_EVENT_GESTURE_END = 3020, |
119 | @@ -890,6 +892,97 @@ |
120 | /* @} */ |
121 | |
122 | /** |
123 | + * @defgroup geis2_class Gesture Classes (GEIS v2.0) |
124 | + * @{ |
125 | + */ |
126 | + |
127 | +/** |
128 | + * An opaque pointer type representing a gesture-capable input device. |
129 | + * |
130 | + * GeisDevice objects are created by the GEIS API and are reference counted. An |
131 | + * application needs to increment and decrement the reference count of a gesture |
132 | + * class object to control its persistence. |
133 | + */ |
134 | +typedef struct _GeisGestureClass *GeisGestureClass; |
135 | + |
136 | +#define GEIS_CLASS_ATTRIBUTE_NAME "class name" |
137 | +#define GEIS_CLASS_ATTRIBUTE_ID "class id" |
138 | + |
139 | +#define GEIS_EVENT_ATTRIBUTE_CLASS "gesture class" |
140 | + |
141 | +/** |
142 | + * Registers a callback to receive gesture class change notifications. |
143 | + * |
144 | + * @param[in] geis The API instance. |
145 | + * @param[in] event_callback The callback function. |
146 | + * @param[in] context Contextual data to be passed through to the |
147 | + * callback. |
148 | + * |
149 | + * This function is used to register a function to be executed when a change to |
150 | + * the available gesture class definitions has occurred. If no function is |
151 | + * registered, the default action is to deliver gesture class events through the |
152 | + * main event mechanism. |
153 | + * |
154 | + * Passing a value of GEIS_DEFAULT_EVENT_CALLBACK as the @p event-callback will |
155 | + * reset the callback function to the default action. |
156 | + * |
157 | + * The @p event_callback function will be executed in the same thread context as |
158 | + * geis_dispatch_events(). |
159 | + */ |
160 | +GEIS_API void geis_register_class_callback(Geis geis, |
161 | + GeisEventCallback event_callback, |
162 | + void *context); |
163 | + |
164 | +/** |
165 | + * Increments the reference count of a gesture class object. |
166 | + * |
167 | + * @param[in] gesture_class The gesture class object. |
168 | + */ |
169 | +GEIS_API void geis_gesture_class_ref(GeisGestureClass gesture_class); |
170 | + |
171 | +/** |
172 | + * Decrements the reference count of a gesture class object. |
173 | + * |
174 | + * @param[in] gesture_class The gesture class object. |
175 | + * |
176 | + * The reference count of teh object is decremented and, if it reaches zero, the |
177 | + * object is destroyed. |
178 | + */ |
179 | +GEIS_API void geis_gesture_class_unref(GeisGestureClass gesture_class); |
180 | + |
181 | +/** |
182 | + * Gets the name of the gesture class. |
183 | + * |
184 | + * @param[in] gesture_class The gesture class object. |
185 | + */ |
186 | +GEIS_API GeisString geis_gesture_class_name(GeisGestureClass gesture_class); |
187 | + |
188 | +/** |
189 | + * Gets the numeric identifier of the gesture class. |
190 | + * |
191 | + * @param[in] gesture_class The gesture class object. |
192 | + */ |
193 | +GEIS_API GeisInteger geis_gesture_class_id(GeisGestureClass gesture_class); |
194 | + |
195 | +/** |
196 | + * Gets the number of attributes of the gesture class. |
197 | + * |
198 | + * @param[in] gesture_class The gesture class object. |
199 | + */ |
200 | +GEIS_API GeisSize geis_gesture_class_attr_count(GeisGestureClass gesture_class); |
201 | + |
202 | +/** |
203 | + * Gets the indicated attribute of teh gesture class. |
204 | + * |
205 | + * @param[in] gesture_class The gesture class object. |
206 | + * @param[in] index The index of the attribute to retrieve. |
207 | + */ |
208 | +GEIS_API GeisAttr geis_gesture_class_attr(GeisGestureClass gesture_class, |
209 | + int index); |
210 | + |
211 | +/* @} */ |
212 | + |
213 | +/** |
214 | * @defgroup geis2_region Gesture Regions (GEIS v2.0) |
215 | * @{ |
216 | */ |
217 | @@ -956,9 +1049,9 @@ |
218 | |
219 | typedef enum _GeisFilterFacility |
220 | { |
221 | - GEIS_FILTER_DEVICE = 1000, |
222 | - GEIS_FILTER_GESTURE_TYPE = 2000, |
223 | - GEIS_FILTER_REGION = 3000 |
224 | + GEIS_FILTER_DEVICE = 1000, |
225 | + GEIS_FILTER_CLASS = 2000, |
226 | + GEIS_FILTER_REGION = 3000 |
227 | } GeisFilterFacility; |
228 | |
229 | typedef enum _GeisFilterOperation |
230 | |
231 | === modified file 'libutouch-geis/Makefile.am' |
232 | --- libutouch-geis/Makefile.am 2011-01-05 18:23:20 +0000 |
233 | +++ libutouch-geis/Makefile.am 2011-01-13 16:20:11 +0000 |
234 | @@ -31,6 +31,7 @@ |
235 | geis_backend.h geis_backend.c \ |
236 | geis_backend_protected.h \ |
237 | geis_backend_multiplexor.h geis_backend_multiplexor.c \ |
238 | + geis_class.h geis_class.c \ |
239 | geis_device.h geis_device.c \ |
240 | geis_error.h geis_error.c \ |
241 | geis_event.h geis_event.c \ |
242 | |
243 | === modified file 'libutouch-geis/backend/test_fixture/geis_backend_test_fixture.c' |
244 | --- libutouch-geis/backend/test_fixture/geis_backend_test_fixture.c 2011-01-06 00:47:03 +0000 |
245 | +++ libutouch-geis/backend/test_fixture/geis_backend_test_fixture.c 2011-01-13 16:20:11 +0000 |
246 | @@ -22,6 +22,7 @@ |
247 | #include "geis_backend_protected.h" |
248 | |
249 | #include "geis_attr.h" |
250 | +#include "geis_class.h" |
251 | #include "geis_device.h" |
252 | #include "geis_event.h" |
253 | #include "geis_filter.h" |
254 | @@ -69,6 +70,18 @@ |
255 | geis_filter_term_operation(term), |
256 | geis_attr_value_to_string(geis_filter_term_attr(term))); |
257 | } |
258 | + for (j = 0; |
259 | + j < geis_filter_term_by_facility_count(filter, GEIS_FILTER_CLASS); |
260 | + ++j) |
261 | + { |
262 | + GeisFilterTerm term = geis_filter_term_by_facility(filter, |
263 | + GEIS_FILTER_CLASS, |
264 | + j); |
265 | + geis_debug(" CLASS \"%s\" (%d) \"%s\"", |
266 | + geis_attr_name(geis_filter_term_attr(term)), |
267 | + geis_filter_term_operation(term), |
268 | + geis_attr_value_to_string(geis_filter_term_attr(term))); |
269 | + } |
270 | } |
271 | geis_debug("ends"); |
272 | return status; |
273 | @@ -102,8 +115,22 @@ |
274 | } |
275 | |
276 | |
277 | +static void _create_test_classes(GeisBackendTestFixture tf) |
278 | +{ |
279 | + GeisGestureClass gesture_class = geis_gesture_class_new("poke", 0); |
280 | + GeisEvent event = geis_event_new(GEIS_EVENT_CLASS_AVAILABLE); |
281 | + GeisAttr attr = geis_attr_new(GEIS_EVENT_ATTRIBUTE_CLASS, |
282 | + GEIS_ATTR_TYPE_POINTER, |
283 | + gesture_class); |
284 | + geis_event_add_attr(event, attr); |
285 | + geis_post_event(tf->tf_geis, event); |
286 | +} |
287 | + |
288 | + |
289 | GeisBackend |
290 | -geis_backend_new_test_fixture(Geis geis, GeisBoolean track_devices) |
291 | +geis_backend_new_test_fixture(Geis geis, |
292 | + GeisBoolean track_devices, |
293 | + GeisBoolean track_classes) |
294 | { |
295 | GeisBackendTestFixture tf = calloc(1, sizeof(struct _GeisBackendTestFixture)); |
296 | if (!tf) |
297 | @@ -120,6 +147,11 @@ |
298 | _create_test_devices(tf); |
299 | } |
300 | |
301 | + if (track_classes) |
302 | + { |
303 | + _create_test_classes(tf); |
304 | + } |
305 | + |
306 | geis_debug("%s back end created", geis_backend_name(&tf->tf_base)); |
307 | |
308 | nomem: |
309 | |
310 | === modified file 'libutouch-geis/backend/test_fixture/geis_backend_test_fixture.h' |
311 | --- libutouch-geis/backend/test_fixture/geis_backend_test_fixture.h 2011-01-05 22:00:54 +0000 |
312 | +++ libutouch-geis/backend/test_fixture/geis_backend_test_fixture.h 2011-01-13 16:20:11 +0000 |
313 | @@ -28,10 +28,12 @@ |
314 | * |
315 | * @param[in] geis The API instance the back end will run in. |
316 | * @param[in] track_devices Indicates devices should be tracked. |
317 | + * @param[in] track_classes Indicates classes should be tracked. |
318 | * |
319 | * The Test Fixture back end is used in unit tests. |
320 | */ |
321 | GeisBackend geis_backend_new_test_fixture(Geis geis, |
322 | - GeisBoolean track_devices); |
323 | + GeisBoolean track_devices, |
324 | + GeisBoolean track_classes); |
325 | |
326 | #endif /* GEIS_BACKEND_TEST_FIXTURE_H_ */ |
327 | |
328 | === modified file 'libutouch-geis/geis.c' |
329 | --- libutouch-geis/geis.c 2011-01-05 22:00:54 +0000 |
330 | +++ libutouch-geis/geis.c 2011-01-13 16:20:11 +0000 |
331 | @@ -24,15 +24,16 @@ |
332 | #include <errno.h> |
333 | #include "geis_attr.h" |
334 | #include "geis_backend.h" |
335 | -#include "test_fixture/geis_backend_test_fixture.h" |
336 | +#include "geis_class.h" |
337 | +#include "geis_device.h" |
338 | #include "geis_backend_multiplexor.h" |
339 | #include "geis_error.h" |
340 | #include "geis_event.h" |
341 | #include "geis_event_queue.h" |
342 | -#include "geis_device.h" |
343 | #include "geis_logging.h" |
344 | #include <stdarg.h> |
345 | #include <string.h> |
346 | +#include "test_fixture/geis_backend_test_fixture.h" |
347 | #include <unistd.h> |
348 | |
349 | |
350 | @@ -48,6 +49,11 @@ |
351 | GeisEventCallback output_event_callback; |
352 | void *output_event_callback_context; |
353 | GeisDeviceBag devices; |
354 | + GeisEventCallback device_event_callback; |
355 | + void *device_event_callback_context; |
356 | + GeisGestureClassBag gesture_classes; |
357 | + GeisEventCallback class_event_callback; |
358 | + void *class_event_callback_context; |
359 | }; |
360 | |
361 | |
362 | @@ -91,6 +97,55 @@ |
363 | geis_device_bag_remove(geis->devices, device); |
364 | } |
365 | |
366 | + if (geis->device_event_callback != GEIS_DEFAULT_EVENT_CALLBACK) |
367 | + { |
368 | + geis->device_event_callback(geis, event, geis->device_event_callback_context); |
369 | + handled = GEIS_TRUE; |
370 | + } |
371 | + |
372 | +final_exit: |
373 | + return handled; |
374 | +} |
375 | + |
376 | + |
377 | +/* |
378 | + * Handles class events coming in from the back end. |
379 | + */ |
380 | +static GeisBoolean |
381 | +_class_event_handler(Geis geis, GeisEvent event) |
382 | +{ |
383 | + GeisBoolean handled = GEIS_FALSE; |
384 | + |
385 | + GeisAttr attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_CLASS); |
386 | + if (!attr) |
387 | + { |
388 | + geis_warning("invalid class event received from back end."); |
389 | + handled = GEIS_TRUE; |
390 | + goto final_exit; |
391 | + } |
392 | + |
393 | + GeisGestureClass gesture_class = geis_attr_value_to_pointer(attr); |
394 | + |
395 | + GeisEventType event_type = geis_event_type(event); |
396 | + if (event_type == GEIS_EVENT_CLASS_AVAILABLE) |
397 | + { |
398 | + geis_gesture_class_bag_insert(geis->gesture_classes, gesture_class); |
399 | + } |
400 | + else if (event_type == GEIS_EVENT_CLASS_CHANGED) |
401 | + { |
402 | + /** @todo implement GEIS_EVENT_CLASS_CHANGED */ |
403 | + } |
404 | + else if (event_type == GEIS_EVENT_CLASS_UNAVAILABLE) |
405 | + { |
406 | + geis_gesture_class_bag_remove(geis->gesture_classes, gesture_class); |
407 | + } |
408 | + |
409 | + if (geis->class_event_callback != GEIS_DEFAULT_EVENT_CALLBACK) |
410 | + { |
411 | + geis->class_event_callback(geis, event, geis->class_event_callback_context); |
412 | + handled = GEIS_TRUE; |
413 | + } |
414 | + |
415 | final_exit: |
416 | return handled; |
417 | } |
418 | @@ -129,6 +184,12 @@ |
419 | handled = _device_event_handler(geis, event); |
420 | break; |
421 | |
422 | + case GEIS_EVENT_CLASS_AVAILABLE: |
423 | + case GEIS_EVENT_CLASS_CHANGED: |
424 | + case GEIS_EVENT_CLASS_UNAVAILABLE: |
425 | + handled = _class_event_handler(geis, event); |
426 | + break; |
427 | + |
428 | default: |
429 | break; |
430 | } |
431 | @@ -205,15 +266,27 @@ |
432 | geis->output_event_callback = _default_output_event_callback; |
433 | |
434 | geis->devices = geis_device_bag_new(); |
435 | - if (!geis->output_event_queue) |
436 | + if (!geis->devices) |
437 | { |
438 | geis_error_push(NULL, GEIS_STATUS_UNKNOWN_ERROR); |
439 | geis_error("creation of geis device bag failed"); |
440 | goto unwind_output_queue; |
441 | } |
442 | + geis->device_event_callback = _default_output_event_callback; |
443 | + |
444 | + geis->gesture_classes = geis_gesture_class_bag_new(); |
445 | + if (!geis->gesture_classes) |
446 | + { |
447 | + geis_error_push(NULL, GEIS_STATUS_UNKNOWN_ERROR); |
448 | + geis_error("creation of geis gesture class bag failed"); |
449 | + goto unwind_device_bag; |
450 | + } |
451 | + geis->class_event_callback = _default_output_event_callback; |
452 | |
453 | goto final_exit; |
454 | |
455 | +unwind_device_bag: |
456 | + geis_device_bag_delete(geis->devices); |
457 | unwind_output_queue: |
458 | geis_event_queue_delete(geis->output_event_queue); |
459 | unwind_input_signal_pipe: |
460 | @@ -249,6 +322,7 @@ |
461 | GeisBoolean status = GEIS_TRUE; |
462 | BackendType back_end_type = BACK_END_TYPE_NONE; |
463 | GeisBoolean track_devices = GEIS_FALSE; |
464 | + GeisBoolean track_classes = GEIS_FALSE; |
465 | |
466 | while (init_arg_name) |
467 | { |
468 | @@ -260,6 +334,10 @@ |
469 | { |
470 | track_devices = GEIS_TRUE; |
471 | } |
472 | + else if (0 == strcmp(init_arg_name, GEIS_INIT_TRACK_GESTURE_CLASSES)) |
473 | + { |
474 | + track_classes = GEIS_TRUE; |
475 | + } |
476 | else if (0 == strcmp(init_arg_name, GEIS_INIT_UTOUCH_MOCK_ENGINE)) |
477 | { |
478 | if (back_end_type != BACK_END_TYPE_NONE) |
479 | @@ -274,7 +352,9 @@ |
480 | |
481 | if (back_end_type ==BACK_END_TYPE_MOCK_ENGINE) |
482 | { |
483 | - geis->backend = geis_backend_new_test_fixture(geis, track_devices); |
484 | + geis->backend = geis_backend_new_test_fixture(geis, |
485 | + track_devices, |
486 | + track_classes); |
487 | } |
488 | else |
489 | { |
490 | @@ -387,6 +467,19 @@ |
491 | |
492 | |
493 | /* |
494 | + * Registers a callback to receive gesture class change notifications. |
495 | + */ |
496 | +void |
497 | +geis_register_class_callback(Geis geis, |
498 | + GeisEventCallback event_callback, |
499 | + void *context) |
500 | +{ |
501 | + geis->class_event_callback = event_callback; |
502 | + geis->class_event_callback_context = context; |
503 | +} |
504 | + |
505 | + |
506 | +/* |
507 | * Registers an application-supplied event callback. |
508 | */ |
509 | void |
510 | @@ -531,3 +624,25 @@ |
511 | return GEIS_ATTR_TYPE_UNKNOWN; |
512 | } |
513 | |
514 | + |
515 | +GeisAttrType |
516 | +geis_get_class_attr_type(Geis geis, GeisString attr_name) |
517 | +{ |
518 | + GeisSize i = 0; |
519 | + for (; i < geis_gesture_class_bag_count(geis->gesture_classes); ++i) |
520 | + { |
521 | + GeisGestureClass gesture_class = geis_gesture_class_bag_gesture_class(geis->gesture_classes, i); |
522 | + GeisSize j = 0; |
523 | + for (; j < geis_gesture_class_attr_count(gesture_class); ++j) |
524 | + { |
525 | + GeisAttr attr = geis_gesture_class_attr(gesture_class, j); |
526 | + if (0 == strcmp(geis_attr_name(attr), attr_name)) |
527 | + { |
528 | + return geis_attr_type(attr); |
529 | + } |
530 | + } |
531 | + } |
532 | + return GEIS_ATTR_TYPE_UNKNOWN; |
533 | +} |
534 | + |
535 | + |
536 | |
537 | === added file 'libutouch-geis/geis_class.c' |
538 | --- libutouch-geis/geis_class.c 1970-01-01 00:00:00 +0000 |
539 | +++ libutouch-geis/geis_class.c 2011-01-13 16:20:11 +0000 |
540 | @@ -0,0 +1,327 @@ |
541 | +/** |
542 | + * @file libutouch-geis/geis_class.c |
543 | + * @brief implementation of the uTouch GEIS v2.0 API Gesture Class module |
544 | + * |
545 | + * Copyright 2011 Canonical Ltd. |
546 | + * |
547 | + * This library is free software; you can redistribute it and/or modify it under |
548 | + * the terms of the GNU Lesser General Public License as published by the Free |
549 | + * Software Foundation; either version 3 of the License, or (at your option) any |
550 | + * later version. |
551 | + * |
552 | + * This library is distributed in the hope that it will be useful, but WITHOUT |
553 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
554 | + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
555 | + * details. |
556 | + * |
557 | + * You should have received a copy of the GNU Lesser General Public License |
558 | + * along with this program; if not, write to the Free Software Foundation, Inc., |
559 | + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
560 | + */ |
561 | +#include "geis_config.h" |
562 | +#include "geis_class.h" |
563 | + |
564 | +#include "geis_attr.h" |
565 | +#include "geis_logging.h" |
566 | +#include <stdlib.h> |
567 | + |
568 | + |
569 | +struct _GeisGestureClass |
570 | +{ |
571 | + GeisSize ref_count; |
572 | + GeisAttrBag attrs; |
573 | +}; |
574 | + |
575 | +struct _GeisGestureClassBag |
576 | +{ |
577 | + GeisGestureClass *store; |
578 | + GeisSize store_size; |
579 | + GeisSize count; |
580 | +}; |
581 | + |
582 | +static const int gesture_class_bag_growth_constant = 2; |
583 | + |
584 | + |
585 | +/* |
586 | + * Creates a new class bag, |
587 | + */ |
588 | +GeisGestureClassBag |
589 | +geis_gesture_class_bag_new() |
590 | +{ |
591 | + GeisGestureClassBag bag = calloc(1, sizeof(struct _GeisGestureClassBag)); |
592 | + if (!bag) |
593 | + { |
594 | + geis_error("error allocating gesture class bag"); |
595 | + goto final_exit; |
596 | + } |
597 | + |
598 | + bag->store = calloc(1, sizeof(struct _GeisGestureClass)); |
599 | + if (!bag->store) |
600 | + { |
601 | + geis_error("error allocating gesture class bag store"); |
602 | + goto unwind_bag; |
603 | + } |
604 | + |
605 | + bag->store_size = 1; |
606 | + bag->count = 0; |
607 | + goto final_exit; |
608 | + |
609 | +unwind_bag: |
610 | + free(bag); |
611 | + bag = NULL; |
612 | +final_exit: |
613 | + return bag; |
614 | +} |
615 | + |
616 | + |
617 | +/* |
618 | + * Destroys a gesture class bag. |
619 | + */ |
620 | +void |
621 | +geis_gesture_class_bag_delete(GeisGestureClassBag bag) |
622 | +{ |
623 | + GeisSize i; |
624 | + for (i = bag->count; i > 0; --i) |
625 | + { |
626 | + geis_gesture_class_unref(bag->store[i-1]); |
627 | + } |
628 | + free(bag->store); |
629 | + free(bag); |
630 | +} |
631 | + |
632 | + |
633 | +/* |
634 | + * Gets the number of gesture classs in the bag. |
635 | + */ |
636 | +GeisSize |
637 | +geis_gesture_class_bag_count(GeisGestureClassBag bag) |
638 | +{ |
639 | + return bag->count; |
640 | +} |
641 | + |
642 | + |
643 | +/* |
644 | + * Gets an indicated gesture class from a bag. |
645 | + */ |
646 | +GeisGestureClass |
647 | +geis_gesture_class_bag_gesture_class(GeisGestureClassBag bag, |
648 | + GeisSize index) |
649 | +{ |
650 | + GeisGestureClass gesture_class = NULL; |
651 | + if (index >= bag->count) |
652 | + { |
653 | + geis_warning("class bag index out of range"); |
654 | + } |
655 | + else |
656 | + { |
657 | + gesture_class = bag->store[index]; |
658 | + } |
659 | + return gesture_class; |
660 | +} |
661 | + |
662 | + |
663 | +/* |
664 | + * Inserts a gesture class in teh bag. |
665 | + */ |
666 | +GeisStatus |
667 | +geis_gesture_class_bag_insert(GeisGestureClassBag bag, |
668 | + GeisGestureClass gesture_class) |
669 | +{ |
670 | + GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR; |
671 | + if (bag->count >= bag->store_size) |
672 | + { |
673 | + GeisSize new_store_size = bag->store_size * gesture_class_bag_growth_constant; |
674 | + GeisGestureClass *new_store = realloc(bag->store, |
675 | + new_store_size * sizeof(struct _GeisGestureClass)); |
676 | + if (!new_store) |
677 | + { |
678 | + geis_error("failed to reallocate class bag"); |
679 | + goto error_exit; |
680 | + } |
681 | + bag->store = new_store; |
682 | + bag->store_size = new_store_size; |
683 | + } |
684 | + bag->store[bag->count++] = gesture_class; |
685 | + status = GEIS_STATUS_SUCCESS; |
686 | + |
687 | +error_exit: |
688 | + return status; |
689 | +} |
690 | + |
691 | + |
692 | +/* |
693 | + * Remoes a gesture class from the bag. |
694 | + */ |
695 | +GeisStatus |
696 | +geis_gesture_class_bag_remove(GeisGestureClassBag bag, |
697 | + GeisGestureClass gesture_class) |
698 | +{ |
699 | + GeisSize i; |
700 | + GeisStatus status = GEIS_STATUS_SUCCESS; |
701 | + for (i = 0; i < bag->count; ++i) |
702 | + { |
703 | + if (bag->store[i] == gesture_class) |
704 | + { |
705 | + GeisSize j; |
706 | + geis_gesture_class_unref(bag->store[i]); |
707 | + --bag->count; |
708 | + for (j = i; j < bag->count; ++j) |
709 | + { |
710 | + bag->store[j] = bag->store[j+1]; |
711 | + } |
712 | + break; |
713 | + } |
714 | + } |
715 | + return status; |
716 | +} |
717 | + |
718 | + |
719 | +/* |
720 | + * Creates a new, empty gesture_class. |
721 | + */ |
722 | +GeisGestureClass |
723 | +geis_gesture_class_new(GeisString name, GeisInteger id) |
724 | +{ |
725 | + GeisAttr attr; |
726 | + |
727 | + GeisGestureClass gesture_class = calloc(1, sizeof(struct _GeisGestureClass)); |
728 | + if (!gesture_class) |
729 | + { |
730 | + geis_error("error allocating gesture class"); |
731 | + goto final_exit; |
732 | + } |
733 | + |
734 | + gesture_class->attrs = geis_attr_bag_new(3); |
735 | + if (!gesture_class->attrs) |
736 | + { |
737 | + geis_debug("error allocating attr bag"); |
738 | + goto unwind_gesture_class; |
739 | + } |
740 | + |
741 | + attr = geis_attr_new(GEIS_CLASS_ATTRIBUTE_NAME, GEIS_ATTR_TYPE_STRING, (void *)name); |
742 | + if (!attr) |
743 | + { |
744 | + geis_debug("error creating gesture class name attr"); |
745 | + goto unwind_attrs; |
746 | + } |
747 | + geis_attr_bag_insert(gesture_class->attrs, attr); |
748 | + |
749 | + attr = geis_attr_new(GEIS_CLASS_ATTRIBUTE_ID, GEIS_ATTR_TYPE_INTEGER, &id); |
750 | + if (!attr) |
751 | + { |
752 | + geis_debug("error creating gesture class id attr"); |
753 | + goto unwind_attrs; |
754 | + } |
755 | + geis_attr_bag_insert(gesture_class->attrs, attr); |
756 | + |
757 | + geis_gesture_class_ref(gesture_class); |
758 | + goto final_exit; |
759 | + |
760 | +unwind_attrs: |
761 | + geis_attr_bag_delete(gesture_class->attrs); |
762 | +unwind_gesture_class: |
763 | + free(gesture_class); |
764 | + gesture_class = NULL; |
765 | +final_exit: |
766 | + return gesture_class; |
767 | +} |
768 | + |
769 | + |
770 | +/* |
771 | + * Destroys a gesture class. |
772 | + */ |
773 | +static void |
774 | +_gesture_class_delete(GeisGestureClass gesture_class) |
775 | +{ |
776 | + geis_attr_bag_delete(gesture_class->attrs); |
777 | + free(gesture_class); |
778 | +} |
779 | + |
780 | + |
781 | +/* |
782 | + * Increments the reference count of a gesture class object. |
783 | + */ |
784 | +void |
785 | +geis_gesture_class_ref(GeisGestureClass gesture_class) |
786 | +{ |
787 | + __sync_add_and_fetch(&gesture_class->ref_count, 1); |
788 | +} |
789 | + |
790 | + |
791 | +/* |
792 | + * Decrements the reference count of a gesture class object. |
793 | + */ |
794 | +void |
795 | +geis_gesture_class_unref(GeisGestureClass gesture_class) |
796 | +{ |
797 | + if (0 == __sync_sub_and_fetch(&gesture_class->ref_count, 1)) |
798 | + { |
799 | + _gesture_class_delete(gesture_class); |
800 | + } |
801 | +} |
802 | + |
803 | + |
804 | +/* |
805 | + * Gets the name of the gesture class. |
806 | + */ |
807 | +GeisString |
808 | +geis_gesture_class_name(GeisGestureClass gesture_class) |
809 | +{ |
810 | + GeisString name = NULL; |
811 | + GeisAttr attr = geis_attr_bag_find(gesture_class->attrs, |
812 | + GEIS_CLASS_ATTRIBUTE_NAME); |
813 | + if (attr) |
814 | + { |
815 | + name = geis_attr_value_to_string(attr); |
816 | + } |
817 | + return name; |
818 | +} |
819 | + |
820 | + |
821 | +/** |
822 | + * Gets the numeric identifier of the gesture class. |
823 | + */ |
824 | +GeisInteger |
825 | +geis_gesture_class_id(GeisGestureClass gesture_class) |
826 | +{ |
827 | + GeisInteger id = -1; |
828 | + GeisAttr attr = geis_attr_bag_find(gesture_class->attrs, |
829 | + GEIS_CLASS_ATTRIBUTE_ID); |
830 | + if (attr) |
831 | + { |
832 | + id = geis_attr_value_to_integer(attr); |
833 | + } |
834 | + return id; |
835 | +} |
836 | + |
837 | + |
838 | +/* |
839 | + * Gets the number of attributes of the gesture class. |
840 | + */ |
841 | +GeisSize |
842 | +geis_gesture_class_attr_count(GeisGestureClass gesture_class) |
843 | +{ |
844 | + return geis_attr_bag_count(gesture_class->attrs); |
845 | +} |
846 | + |
847 | + |
848 | +/* |
849 | + * Gets the indicated attribute of teh gesture class. |
850 | + */ |
851 | +GeisAttr |
852 | +geis_gesture_class_attr(GeisGestureClass gesture_class, |
853 | + int index) |
854 | +{ |
855 | + return geis_attr_bag_attr(gesture_class->attrs, index); |
856 | +} |
857 | + |
858 | + |
859 | +/* |
860 | + * Inserts an attr into a gesture class. |
861 | + */ |
862 | +GeisStatus |
863 | +geis_gesture_class_add_attr(GeisGestureClass gesture_class, GeisAttr attr) |
864 | +{ |
865 | + return geis_attr_bag_insert(gesture_class->attrs, attr); |
866 | +} |
867 | + |
868 | |
869 | === added file 'libutouch-geis/geis_class.h' |
870 | --- libutouch-geis/geis_class.h 1970-01-01 00:00:00 +0000 |
871 | +++ libutouch-geis/geis_class.h 2011-01-13 16:20:11 +0000 |
872 | @@ -0,0 +1,108 @@ |
873 | +/** |
874 | + * @file geis_class.h |
875 | + * @brief internal uTouch Geis Gesture Class module private interface |
876 | + * |
877 | + * Copyright 2010 Canonical Ltd. |
878 | + * |
879 | + * This library is free software; you can redistribute it and/or modify it under |
880 | + * the terms of the GNU Lesser General Public License as published by the Free |
881 | + * Software Foundation; either version 3 of the License, or (at your option) any |
882 | + * later version. |
883 | + * |
884 | + * This library is distributed in the hope that it will be useful, but WITHOUT |
885 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
886 | + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
887 | + * details. |
888 | + * |
889 | + * You should have received a copy of the GNU Lesser General Public License |
890 | + * along with this program; if not, write to the Free Software Foundation, Inc., |
891 | + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
892 | + */ |
893 | +#ifndef GEIS_CLASS_H_ |
894 | +#define GEIS_CLASS_H_ |
895 | + |
896 | +#include "geis/geis.h" |
897 | + |
898 | +/** |
899 | + * @defgroup utouch_geis_gesture_class_container A Gesture Class Container |
900 | + * @{ |
901 | + */ |
902 | + |
903 | +/** |
904 | + * An unsorted container for holding classs. |
905 | + */ |
906 | +typedef struct _GeisGestureClassBag *GeisGestureClassBag; |
907 | + |
908 | +/** |
909 | + * Creates a new class bag, |
910 | + */ |
911 | +GeisGestureClassBag geis_gesture_class_bag_new(); |
912 | + |
913 | +/** |
914 | + * Destroys a gesture class bag. |
915 | + * |
916 | + * @param[in] bag The gesture class bag, |
917 | + */ |
918 | +void geis_gesture_class_bag_delete(GeisGestureClassBag bag); |
919 | + |
920 | +/** |
921 | + * Gets the number of gesture classs in the bag. |
922 | + * |
923 | + * @param[in] bag The gesture class bag, |
924 | + */ |
925 | +GeisSize geis_gesture_class_bag_count(GeisGestureClassBag bag); |
926 | + |
927 | +/** |
928 | + * Gets an indicated gesture class from a bag. |
929 | + * |
930 | + * @param[in] bag The gesture class bag. |
931 | + * @param[in] index The index. |
932 | + */ |
933 | +GeisGestureClass geis_gesture_class_bag_gesture_class(GeisGestureClassBag bag, |
934 | + GeisSize index); |
935 | + |
936 | +/** |
937 | + * Inserts a gesture class in teh bag. |
938 | + * |
939 | + * @param[in] bag The gesture class bag. |
940 | + * @param[in] gesture_class The gesture class to insert. |
941 | + */ |
942 | +GeisStatus geis_gesture_class_bag_insert(GeisGestureClassBag bag, |
943 | + GeisGestureClass gesture_class); |
944 | + |
945 | +/** |
946 | + * Remoes a gesture class from the bag. |
947 | + * |
948 | + * @param[in] bag The gesture class bag. |
949 | + * @param[in] gesture_class The gesture class to remove. |
950 | + */ |
951 | +GeisStatus geis_gesture_class_bag_remove(GeisGestureClassBag bag, |
952 | + GeisGestureClass gesture_class); |
953 | + |
954 | +/** @} */ |
955 | + |
956 | +/** |
957 | + * @defgroup utouch_geis_gesture_class Internal Gesture Class Functions |
958 | + * @{ |
959 | + */ |
960 | + |
961 | +/** |
962 | + * Creates a new gesture class. |
963 | + * |
964 | + * @param[in] name A system-specific gesture class name. |
965 | + * @param[in] id A system-specific gesture class identifier. |
966 | + */ |
967 | +GeisGestureClass geis_gesture_class_new(GeisString name, GeisInteger id); |
968 | + |
969 | +/** |
970 | + * Inserts an attr into a gesture class. |
971 | + * |
972 | + * @param[in] gesture_class A gesture class. |
973 | + * @param[in] attr An attr. |
974 | + */ |
975 | +GeisStatus geis_gesture_class_add_attr(GeisGestureClass gesture_class, |
976 | + GeisAttr attr); |
977 | + |
978 | +/** @} */ |
979 | + |
980 | +#endif /* GEIS_CLASS_H_ */ |
981 | |
982 | === modified file 'libutouch-geis/geis_filter.c' |
983 | --- libutouch-geis/geis_filter.c 2011-01-06 00:47:03 +0000 |
984 | +++ libutouch-geis/geis_filter.c 2011-01-13 16:20:11 +0000 |
985 | @@ -262,7 +262,7 @@ |
986 | _facility_is_valid(GeisFilterFacility facility) |
987 | { |
988 | return facility == GEIS_FILTER_DEVICE |
989 | - || facility == GEIS_FILTER_GESTURE_TYPE |
990 | + || facility == GEIS_FILTER_CLASS |
991 | || facility == GEIS_FILTER_REGION; |
992 | } |
993 | |
994 | @@ -297,6 +297,9 @@ |
995 | case GEIS_FILTER_DEVICE: |
996 | type = geis_get_device_attr_type(geis, attr_name); |
997 | break; |
998 | + case GEIS_FILTER_CLASS: |
999 | + type = geis_get_class_attr_type(geis, attr_name); |
1000 | + break; |
1001 | default: |
1002 | break; |
1003 | } |
1004 | |
1005 | === modified file 'libutouch-geis/geis_private.h' |
1006 | --- libutouch-geis/geis_private.h 2011-01-05 16:59:42 +0000 |
1007 | +++ libutouch-geis/geis_private.h 2011-01-13 16:20:11 +0000 |
1008 | @@ -105,4 +105,19 @@ |
1009 | */ |
1010 | GeisAttrType geis_get_device_attr_type(Geis geis, GeisString attr_name); |
1011 | |
1012 | +/** |
1013 | + * Gets the type of a named class attr. |
1014 | + * |
1015 | + * @param[in] geis The API instance. |
1016 | + * @param[in] attr_name The name of the class attr. |
1017 | + * |
1018 | + * Gets the type of a class attr by name, assuming the attr is known. |
1019 | + * |
1020 | + * There is a basic assumption that all class attrs of the same name are of the |
1021 | + * same type. |
1022 | + * |
1023 | + * @returns the type of the attr, GEIS_ATTR_TYPE_UNKNOWN if the attr is unknown. |
1024 | + */ |
1025 | +GeisAttrType geis_get_class_attr_type(Geis geis, GeisString attr_name); |
1026 | + |
1027 | #endif /* GEIS_PRIVATE_H_ */ |
1028 | |
1029 | === modified file 'libutouch-geis/libutouch-geis.ver' |
1030 | --- libutouch-geis/libutouch-geis.ver 2011-01-05 21:54:10 +0000 |
1031 | +++ libutouch-geis/libutouch-geis.ver 2011-01-13 16:20:11 +0000 |
1032 | @@ -40,12 +40,19 @@ |
1033 | geis_filter_delete; |
1034 | geis_filter_name; |
1035 | geis_filter_new; |
1036 | + geis_gesture_class_attr; |
1037 | + geis_gesture_class_attr_count; |
1038 | + geis_gesture_class_id; |
1039 | + geis_gesture_class_name; |
1040 | + geis_gesture_class_ref; |
1041 | + geis_gesture_class_unref; |
1042 | geis_get_configuration; |
1043 | geis_new; |
1044 | geis_next_event; |
1045 | geis_region_delete; |
1046 | geis_region_name; |
1047 | geis_region_new; |
1048 | + geis_register_class_callback; |
1049 | geis_register_device_callback; |
1050 | geis_register_event_callback; |
1051 | geis_set_configuration; |
1052 | |
1053 | === modified file 'testsuite/geis2/Makefile.am' |
1054 | --- testsuite/geis2/Makefile.am 2010-12-31 00:30:21 +0000 |
1055 | +++ testsuite/geis2/Makefile.am 2011-01-13 16:20:11 +0000 |
1056 | @@ -15,6 +15,7 @@ |
1057 | |
1058 | check_geis2_api_SOURCES = \ |
1059 | check_attr.c \ |
1060 | + check_class.c \ |
1061 | check_config.c \ |
1062 | check_device.c \ |
1063 | check_error_codes.c \ |
1064 | |
1065 | === added file 'testsuite/geis2/check_class.c' |
1066 | --- testsuite/geis2/check_class.c 1970-01-01 00:00:00 +0000 |
1067 | +++ testsuite/geis2/check_class.c 2011-01-13 16:20:11 +0000 |
1068 | @@ -0,0 +1,98 @@ |
1069 | +/** |
1070 | + * Unit tests for GEIS v2.0 Input Gesture Class Module. |
1071 | + */ |
1072 | +#include <check.h> |
1073 | + |
1074 | +#include <geis/geis.h> |
1075 | + |
1076 | +/* fixtures */ |
1077 | +static Geis g_geis; |
1078 | + |
1079 | +/* fixture setup */ |
1080 | +static void |
1081 | +construct_geis() |
1082 | +{ |
1083 | + g_geis = geis_new(GEIS_INIT_UTOUCH_MOCK_ENGINE, |
1084 | + GEIS_INIT_TRACK_GESTURE_CLASSES, |
1085 | + NULL); |
1086 | +} |
1087 | + |
1088 | +/* fixture teardown */ |
1089 | +static void |
1090 | +destroy_geis() |
1091 | +{ |
1092 | + geis_delete(g_geis); |
1093 | +} |
1094 | + |
1095 | + |
1096 | +/* Compile-time test to ensure types are defined */ |
1097 | +START_TEST(geis_gesture_class_types) |
1098 | +{ |
1099 | + GeisGestureClass gesture_class; |
1100 | +} |
1101 | +END_TEST |
1102 | + |
1103 | +/* Compile-time test to ensure constants are defined */ |
1104 | +START_TEST(geis_gesture_class_constants) |
1105 | +{ |
1106 | + GeisString attr_name; |
1107 | + attr_name = GEIS_CLASS_ATTRIBUTE_NAME; |
1108 | + attr_name = GEIS_CLASS_ATTRIBUTE_ID; |
1109 | + attr_name = GEIS_EVENT_ATTRIBUTE_CLASS; |
1110 | +} |
1111 | +END_TEST |
1112 | + |
1113 | +/* Compile-and-link-time test to verify required functions exist */ |
1114 | +START_TEST(geis_gesture_class_functions) |
1115 | +{ |
1116 | + Geis geis; |
1117 | + GeisEventCallback callback; |
1118 | + GeisGestureClass gesture_class; |
1119 | + geis_register_class_callback(geis, callback, NULL); |
1120 | + |
1121 | + geis_gesture_class_ref(gesture_class); |
1122 | + geis_gesture_class_unref(gesture_class); |
1123 | + GeisString n = geis_gesture_class_name(gesture_class); |
1124 | + GeisInteger i = geis_gesture_class_id(gesture_class); |
1125 | + GeisSize s = geis_gesture_class_attr_count(gesture_class); |
1126 | + GeisAttr a = geis_gesture_class_attr(gesture_class, 0); |
1127 | +} |
1128 | +END_TEST |
1129 | + |
1130 | +START_TEST(receive_events) |
1131 | +{ |
1132 | + GeisStatus status; |
1133 | + GeisEvent event_out; |
1134 | + |
1135 | + status = geis_dispatch_events(g_geis); |
1136 | + fail_unless(status == GEIS_STATUS_SUCCESS, |
1137 | + "unexpected status from geis_dispatch_events"); |
1138 | + status = geis_next_event(g_geis, &event_out); |
1139 | + fail_unless(status == GEIS_STATUS_SUCCESS, |
1140 | + "unexpected status from geis_dispatch_events"); |
1141 | + fail_unless(geis_event_type(event_out) == GEIS_EVENT_CLASS_AVAILABLE, |
1142 | + "unexpected event type received"); |
1143 | + |
1144 | +} |
1145 | +END_TEST |
1146 | + |
1147 | + |
1148 | +/* boilerplate */ |
1149 | +Suite * |
1150 | +geis2_gesture_class_suite_new() |
1151 | +{ |
1152 | + Suite *s = suite_create("geis2_gesture_class"); |
1153 | + |
1154 | + TCase *gesture_class = tcase_create("gesture-class-api"); |
1155 | + tcase_add_test(gesture_class, geis_gesture_class_types); |
1156 | + tcase_add_test(gesture_class, geis_gesture_class_constants); |
1157 | + suite_add_tcase(s, gesture_class); |
1158 | + |
1159 | + TCase *usage = tcase_create("gesture-class-usage"); |
1160 | + tcase_add_checked_fixture(usage, construct_geis, destroy_geis); |
1161 | + tcase_add_test(usage, receive_events); |
1162 | + suite_add_tcase(s, usage); |
1163 | + |
1164 | + return s; |
1165 | +} |
1166 | + |
1167 | |
1168 | === modified file 'testsuite/geis2/check_event.c' |
1169 | --- testsuite/geis2/check_event.c 2010-12-20 18:06:36 +0000 |
1170 | +++ testsuite/geis2/check_event.c 2011-01-13 16:20:11 +0000 |
1171 | @@ -11,8 +11,9 @@ |
1172 | GeisEventType type; |
1173 | type = GEIS_EVENT_DEVICE_AVAILABLE; |
1174 | type = GEIS_EVENT_DEVICE_UNAVAILABLE; |
1175 | - type = GEIS_EVENT_GESTURE_TYPE_AVAILABLE; |
1176 | - type = GEIS_EVENT_GESTURE_TYPE_UNAVAILABLE; |
1177 | + type = GEIS_EVENT_CLASS_AVAILABLE; |
1178 | + type = GEIS_EVENT_CLASS_CHANGED; |
1179 | + type = GEIS_EVENT_CLASS_UNAVAILABLE; |
1180 | type = GEIS_EVENT_GESTURE_BEGIN; |
1181 | type = GEIS_EVENT_GESTURE_UPDATE; |
1182 | type = GEIS_EVENT_GESTURE_END; |
1183 | |
1184 | === modified file 'testsuite/geis2/check_filter.c' |
1185 | --- testsuite/geis2/check_filter.c 2010-12-31 00:30:21 +0000 |
1186 | +++ testsuite/geis2/check_filter.c 2011-01-13 16:20:11 +0000 |
1187 | @@ -18,7 +18,7 @@ |
1188 | Geis geis; |
1189 | GeisFilter filter = geis_filter_new(geis, "filter"); |
1190 | GeisString name = geis_filter_name(filter); |
1191 | - GeisStatus status = geis_filter_add_term(filter, GEIS_FILTER_GESTURE_TYPE, |
1192 | + GeisStatus status = geis_filter_add_term(filter, GEIS_FILTER_CLASS, |
1193 | GEIS_GESTURE_ATTRIBUTE_TOUCHES, GEIS_FILTER_OP_GT, 1, |
1194 | NULL); |
1195 | geis_filter_delete(filter); |
1196 | |
1197 | === modified file 'testsuite/geis2/check_geis2_api.c' |
1198 | --- testsuite/geis2/check_geis2_api.c 2010-12-31 00:30:21 +0000 |
1199 | +++ testsuite/geis2/check_geis2_api.c 2011-01-13 16:20:11 +0000 |
1200 | @@ -8,6 +8,7 @@ |
1201 | extern Suite *geis2_general_types_suite_new(); |
1202 | extern Suite *geis2_error_codes_suite_new(); |
1203 | extern Suite *geis2_device_suite_new(); |
1204 | +extern Suite *geis2_gesture_class_suite_new(); |
1205 | extern Suite *geis2_geis_new_suite_new(); |
1206 | extern Suite *geis2_config_suite_new(); |
1207 | extern Suite *geis2_attr_suite_new(); |
1208 | @@ -30,8 +31,9 @@ |
1209 | srunner_add_suite(sr, geis2_geis_new_suite_new()); |
1210 | srunner_add_suite(sr, geis2_config_suite_new()); |
1211 | srunner_add_suite(sr, geis2_attr_suite_new()); |
1212 | + srunner_add_suite(sr, geis2_device_suite_new()); |
1213 | + srunner_add_suite(sr, geis2_gesture_class_suite_new()); |
1214 | srunner_add_suite(sr, geis2_region_suite_new()); |
1215 | - srunner_add_suite(sr, geis2_device_suite_new()); |
1216 | srunner_add_suite(sr, geis2_filter_suite_new()); |
1217 | srunner_add_suite(sr, geis2_subscription_suite_new()); |
1218 | srunner_add_suite(sr, geis2_event_suite_new()); |
1219 | |
1220 | === modified file 'testsuite/geis2/check_geis_new.c' |
1221 | --- testsuite/geis2/check_geis_new.c 2010-12-20 18:06:36 +0000 |
1222 | +++ testsuite/geis2/check_geis_new.c 2011-01-13 16:20:11 +0000 |
1223 | @@ -11,7 +11,7 @@ |
1224 | GeisString init_arg; |
1225 | init_arg = GEIS_INIT_SERVICE_PROVIDER; |
1226 | init_arg = GEIS_INIT_TRACK_DEVICES; |
1227 | - init_arg = GEIS_INIT_TRACK_GESTURE_TYPES; |
1228 | + init_arg = GEIS_INIT_TRACK_GESTURE_CLASSES; |
1229 | } |
1230 | END_TEST |
1231 | |
1232 | |
1233 | === modified file 'testsuite/geis2/check_subscription.c' |
1234 | --- testsuite/geis2/check_subscription.c 2011-01-06 00:56:16 +0000 |
1235 | +++ testsuite/geis2/check_subscription.c 2011-01-13 16:20:11 +0000 |
1236 | @@ -14,7 +14,10 @@ |
1237 | static void |
1238 | construct_geis() |
1239 | { |
1240 | - g_geis = geis_new(GEIS_INIT_UTOUCH_MOCK_ENGINE, GEIS_INIT_TRACK_DEVICES, NULL); |
1241 | + g_geis = geis_new(GEIS_INIT_UTOUCH_MOCK_ENGINE, |
1242 | + GEIS_INIT_TRACK_DEVICES, |
1243 | + GEIS_INIT_TRACK_GESTURE_CLASSES, |
1244 | + NULL); |
1245 | } |
1246 | |
1247 | /* fixture teardown */ |
1248 | @@ -96,15 +99,34 @@ |
1249 | |
1250 | fs = geis_subscription_add_filter(sub, filter); |
1251 | fail_if(fs != GEIS_STATUS_SUCCESS, "can not subscribe filter"); |
1252 | - |
1253 | - if (status == GEIS_STATUS_CONTINUE) |
1254 | - { |
1255 | - status = geis_next_event(g_geis, &event); |
1256 | - } |
1257 | - else |
1258 | - { |
1259 | - break; |
1260 | - } |
1261 | + } |
1262 | + else if (geis_event_type(event) == GEIS_EVENT_CLASS_AVAILABLE) |
1263 | + { |
1264 | + GeisAttr attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_CLASS); |
1265 | + fail_if (!attr, "attr not found in class event"); |
1266 | + |
1267 | + GeisGestureClass device = geis_attr_value_to_pointer(attr); |
1268 | + fail_if (!device, "geis class not found in class event"); |
1269 | + |
1270 | + GeisFilter filter = geis_filter_new(g_geis, "class filter"); |
1271 | + fail_if(!filter, "can not create filter"); |
1272 | + |
1273 | + GeisStatus fs = geis_filter_add_term(filter, GEIS_FILTER_CLASS, |
1274 | + GEIS_CLASS_ATTRIBUTE_NAME, GEIS_FILTER_OP_NE, geis_gesture_class_name(device), |
1275 | + NULL); |
1276 | + fail_if(fs != GEIS_STATUS_SUCCESS, "can not add class to filter"); |
1277 | + |
1278 | + fs = geis_subscription_add_filter(sub, filter); |
1279 | + fail_if(fs != GEIS_STATUS_SUCCESS, "can not subscribe filter"); |
1280 | + } |
1281 | + |
1282 | + if (status == GEIS_STATUS_CONTINUE) |
1283 | + { |
1284 | + status = geis_next_event(g_geis, &event); |
1285 | + } |
1286 | + else |
1287 | + { |
1288 | + break; |
1289 | } |
1290 | } |
1291 | |
1292 | |
1293 | === modified file 'testsuite/libutouch-geis/Makefile.am' |
1294 | --- testsuite/libutouch-geis/Makefile.am 2010-12-31 21:36:34 +0000 |
1295 | +++ testsuite/libutouch-geis/Makefile.am 2011-01-13 16:20:11 +0000 |
1296 | @@ -33,6 +33,7 @@ |
1297 | check_geis2_internals_SOURCES = \ |
1298 | check_attr.c \ |
1299 | check_backend_multiplexor.c \ |
1300 | + check_class.c \ |
1301 | check_device.c \ |
1302 | check_error_reporting.c \ |
1303 | check_event_queue.c \ |
1304 | |
1305 | === added file 'testsuite/libutouch-geis/check_class.c' |
1306 | --- testsuite/libutouch-geis/check_class.c 1970-01-01 00:00:00 +0000 |
1307 | +++ testsuite/libutouch-geis/check_class.c 2011-01-13 16:20:11 +0000 |
1308 | @@ -0,0 +1,99 @@ |
1309 | +/** |
1310 | + * unit tests for the geis gesture class module |
1311 | + */ |
1312 | +#include <check.h> |
1313 | + |
1314 | +#include "libutouch-geis/geis_class.h" |
1315 | + |
1316 | + |
1317 | +/* fixtures */ |
1318 | +static GeisGestureClassBag g_gesture_class_bag; |
1319 | +static GeisString g_gesture_class_name = "gesture_class"; |
1320 | +static GeisInteger g_gesture_class_id = 12; |
1321 | + |
1322 | +/* fixture setup */ |
1323 | +static void |
1324 | +construct_bag() |
1325 | +{ |
1326 | + g_gesture_class_bag = geis_gesture_class_bag_new(); |
1327 | +} |
1328 | + |
1329 | +/* fixture teardown */ |
1330 | +static void |
1331 | +destroy_bag() |
1332 | +{ |
1333 | + geis_gesture_class_bag_delete(g_gesture_class_bag); |
1334 | +} |
1335 | + |
1336 | +/* verify bag construction/destruction */ |
1337 | +START_TEST(construct) |
1338 | +{ |
1339 | + GeisGestureClassBag bag = geis_gesture_class_bag_new(); |
1340 | + fail_unless(bag != NULL, "failed to create gesture class bag"); |
1341 | + geis_gesture_class_bag_delete(bag); |
1342 | +} |
1343 | +END_TEST |
1344 | + |
1345 | +/* verify bag insertion */ |
1346 | +START_TEST(insert) |
1347 | +{ |
1348 | + GeisGestureClass gesture_class = geis_gesture_class_new(g_gesture_class_name, g_gesture_class_id); |
1349 | + geis_gesture_class_bag_insert(g_gesture_class_bag, gesture_class); |
1350 | + fail_unless(geis_gesture_class_bag_count(g_gesture_class_bag) == 1, |
1351 | + "unexpected bag size after insertion"); |
1352 | +} |
1353 | +END_TEST |
1354 | + |
1355 | +/* verify bag removal */ |
1356 | +START_TEST(remove) |
1357 | +{ |
1358 | + GeisGestureClass gesture_class = geis_gesture_class_new(g_gesture_class_name, g_gesture_class_id); |
1359 | + geis_gesture_class_bag_insert(g_gesture_class_bag, gesture_class); |
1360 | + fail_unless(geis_gesture_class_bag_count(g_gesture_class_bag) == 1, |
1361 | + "unexpected bag size after insertion"); |
1362 | + geis_gesture_class_bag_remove(g_gesture_class_bag, gesture_class); |
1363 | + fail_unless(geis_gesture_class_bag_count(g_gesture_class_bag) == 0, |
1364 | + "unexpected bag size after removal"); |
1365 | +} |
1366 | +END_TEST |
1367 | + |
1368 | +START_TEST(expand) |
1369 | +{ |
1370 | + int i; |
1371 | + for (i = 0; i < 24; ++i) |
1372 | + { |
1373 | + GeisSize count; |
1374 | + char name[32]; |
1375 | + sprintf(name, "%04d", i); |
1376 | + GeisGestureClass gesture_class = geis_gesture_class_new(name, i); |
1377 | + geis_gesture_class_bag_insert(g_gesture_class_bag, gesture_class); |
1378 | + count = geis_gesture_class_bag_count(g_gesture_class_bag); |
1379 | + fail_unless(count == (i+1), |
1380 | + "unexpected bag size %ld after insertion, expected %d", |
1381 | + count, i+1); |
1382 | + } |
1383 | +} |
1384 | +END_TEST |
1385 | + |
1386 | + |
1387 | + |
1388 | +/* boilerplate */ |
1389 | +Suite * |
1390 | +make_gesture_class_suite() |
1391 | +{ |
1392 | + Suite *s = suite_create("utouch-geis2-gesture_class"); |
1393 | + |
1394 | + TCase *create = tcase_create("gesture-class-bag-creation"); |
1395 | + tcase_add_test(create, construct); |
1396 | + suite_add_tcase(s, create); |
1397 | + |
1398 | + TCase *usage = tcase_create("gesture-class-bag-usage"); |
1399 | + tcase_add_checked_fixture(usage, construct_bag, destroy_bag); |
1400 | + tcase_add_test(usage, insert); |
1401 | + tcase_add_test(usage, remove); |
1402 | + tcase_add_test(usage, expand); |
1403 | + suite_add_tcase(s, usage); |
1404 | + |
1405 | + return s; |
1406 | +} |
1407 | + |
1408 | |
1409 | === modified file 'testsuite/libutouch-geis/check_geis2_internals.c' |
1410 | --- testsuite/libutouch-geis/check_geis2_internals.c 2010-12-31 21:36:34 +0000 |
1411 | +++ testsuite/libutouch-geis/check_geis2_internals.c 2011-01-13 16:20:11 +0000 |
1412 | @@ -12,6 +12,7 @@ |
1413 | extern Suite *make_error_reporting_suite(); |
1414 | extern Suite *make_event_queue_suite(); |
1415 | extern Suite *make_filter_suite(); |
1416 | +extern Suite *make_gesture_class_suite(); |
1417 | extern Suite *make_region_suite(); |
1418 | extern Suite *make_subscription_suite(); |
1419 | |
1420 | @@ -30,6 +31,7 @@ |
1421 | srunner_add_suite(sr, make_backend_multiplexor_suite()); |
1422 | srunner_add_suite(sr, make_backend_event_posting_suite()); |
1423 | srunner_add_suite(sr, make_device_suite()); |
1424 | + srunner_add_suite(sr, make_gesture_class_suite()); |
1425 | srunner_add_suite(sr, make_region_suite()); |
1426 | srunner_add_suite(sr, make_filter_suite()); |
1427 | srunner_add_suite(sr, make_subscription_suite()); |
Overall looks fine.