Merge lp:geis/2.x into lp:geis

Proposed by Stephen M. Webb
Status: Merged
Merged at revision: 91
Proposed branch: lp:geis/2.x
Merge into: lp:geis
Diff against target: 936 lines (+726/-15)
15 files modified
ChangeLog (+35/-0)
include/geis/geis.h (+89/-7)
libutouch-geis/Makefile.am (+5/-4)
libutouch-geis/geis.c (+22/-1)
libutouch-geis/geis_error.c (+2/-2)
libutouch-geis/geis_private.h (+8/-0)
libutouch-geis/geis_subscription.c (+306/-0)
libutouch-geis/geis_subscription.h (+76/-0)
libutouch-geis/libutouch-geis.ver (+7/-1)
testsuite/geis2/Makefile.am (+1/-0)
testsuite/geis2/check_geis2_api.c (+2/-0)
testsuite/geis2/check_subscription.c (+67/-0)
testsuite/libutouch-geis/Makefile.am (+1/-0)
testsuite/libutouch-geis/check_geis2_internals.c (+2/-0)
testsuite/libutouch-geis/check_subscription.c (+103/-0)
To merge this branch: bzr merge lp:geis/2.x
Reviewer Review Type Date Requested Status
Mohamed IKBEL Boulabiar (community) Approve
Henrik Rydberg (community) Approve
Chase Douglas (community) Approve
Review via email: mp+42152@code.launchpad.net

Description of the change

Added GEIS v2.0 subscription module (construction and accessors only).

Fixed a typo in the Doxygen comments in geis.h.

To post a comment you must log in.
Revision history for this message
Chase Douglas (chasedouglas) wrote :

Commit 105 highlights that GeisSize is implemented as an unsigned long. This size varies between architectures on Linux. Although I would have liked a static size, I think this is ok. However, we need to be very careful. We are going to be sending data between clients and a grail service. When we encode data we cannot use GeisSize. We will need to use set bit-width elements. A 32-bit client could be running on a 64-bit machine where grail is 64-bit.

I have questions about the subscription and filter usage, I'll track down Stephen to have a conversation about it. I may just need some more information.

commits 105 and 107 seem fine to me as is.

Revision history for this message
Chase Douglas (chasedouglas) wrote :

After reviewing the spec some more, I think the subscription and filter functions are fine.

We're getting closer to specifying the form of the filters, and I feel this is the greatest challenge of geis. We have to take into account gesture types and numbers of fingers, including the ability to specify ranges of changes of numbers of fingers for gesture continuation. However, that discussion will come after this merge proposal.

review: Approve
Revision history for this message
Henrik Rydberg (rydberg) wrote :

+ geis_error("creation of subscroption bag failed");

I cannot help to think it is quite a bit of code, but it does serve its purpose.

review: Approve
Revision history for this message
Mohamed IKBEL Boulabiar (boulabiar) wrote :

The patch looks nice.

(I'm just thinking gotos can be avoided but that's not important in our case here)

review: Approve
lp:geis/2.x updated
108. By Stephen M. Webb

Improved internal data encapsulation.

109. By Stephen M. Webb

Fixed a sig11 in a test case

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2010-11-26 18:22:53 +0000
3+++ ChangeLog 2010-11-29 17:52:57 +0000
4@@ -1,3 +1,38 @@
5+2010-11-29 Stephen M. Webb <stephen.webb@canonical.com>
6+
7+ Fixed a typo in the Doxygen comments in geis.h.
8+
9+ * include/geis/geis.h: fixed typo in documentation
10+
11+2010-11-28 Stephen M. Webb <stephen.webb@canonical.com>
12+
13+ Added Geis Subscription creation and accessors.
14+
15+ * libutouch-geis/geis_subscription.c: new file
16+ * libutouch-geis/geis_subscription.h: new file
17+ * testsuite/geis2/check_subscription.c: new API test suite
18+ * testsuite/libutouch-geis/check_subscription.c: new internals test suite
19+ * include/geis/geis.h (GeisFilter): new type
20+ (GeisSubscription): new type
21+ (GeisSubscriptionFlags): new type
22+ (geis_subscription_new): new function
23+ (geis_subscription_delete): new function
24+ (geis_subscription_name): new function
25+ (geis_subscription_id): new function
26+ (geis_subscription_add_filter): new function
27+ (geis_subscription_remove_filter): new function
28+ * libutouch-geis/Makefile.am: added new files
29+ * libutouch-geis/geis_private.h (geis_subscription_bag): new function
30+ (struct _Geis): added subscription_bag field
31+ * libutouch-geis/geis.c (geis_subscription_bag): implemented it
32+ (geis_new_empty): created an empty subscription bag
33+ * libutouch-geis/libutouch-geis.ver: added new geis_subscription_* symbols
34+ * testsuite/geis2/Makefile.am: added new test suite source
35+ * testsuite/geis2/check_geis2_api.c: added new test suite
36+ * testsuite/libutouch-geis/Makefile.am: added new test suite source
37+ * testsuite/libutouch-geis/check_geis2_internals.c: added new test suite
38+
39+
40 2010-11-26 Stephen M. Webb <stephen.webb@canonical.com>
41
42 Added Geis Attr functions.
43
44=== modified file 'include/geis/geis.h'
45--- include/geis/geis.h 2010-11-26 18:22:53 +0000
46+++ include/geis/geis.h 2010-11-29 17:52:57 +0000
47@@ -344,9 +344,9 @@
48 * depends on the
49 * @p configuration_value_name.
50 *
51- * @retval GEIS_STATUS_BAD_ARGUMENT an invalid argument value was passed
52- * @retval GEIS_STATUS_NO_SUPPORTED the configuration value is not supported
53- * @retval GEIS_STATUS_SUCCESS normal successful completion
54+ * @retval GEIS_STATUS_BAD_ARGUMENT an invalid argument value was passed
55+ * @retval GEIS_STATUS_NOT_SUPPORTED the configuration value is not supported
56+ * @retval GEIS_STATUS_SUCCESS normal successful completion
57 */
58 GEIS_API GeisStatus geis_get_configuration(Geis geis,
59 GeisString configuration_item_name,
60@@ -363,9 +363,9 @@
61 * this buffer depends on the
62 * @p configuration_value_name.
63 *
64- * @retval GEIS_STATUS_BAD_ARGUMENT an invalid argument value was passed
65- * @retval GEIS_STATUS_NO_SUPPORTED the configuration value is not supported
66- * @retval GEIS_STATUS_SUCCESS normal successful completion
67+ * @retval GEIS_STATUS_BAD_ARGUMENT an invalid argument value was passed
68+ * @retval GEIS_STATUS_NOT_SUPPORTED the configuration value is not supported
69+ * @retval GEIS_STATUS_SUCCESS normal successful completion
70 */
71 GEIS_API GeisStatus geis_set_configuration(Geis geis,
72 GeisString configuration_item_name,
73@@ -494,7 +494,7 @@
74 /* @} */
75
76 /**
77- * @defgroup geis_subscription Gesture Subscription
78+ * @defgroup geis1_subscription Gesture Subscription (GEIS v1.0)
79 * @{
80 */
81 typedef unsigned int GeisGestureType;
82@@ -580,6 +580,88 @@
83
84 /* @} */
85
86+/**
87+ * @defgroup geis2_subscription Gesture Subscription (GEIS v2.0)
88+ * @{
89+ */
90+
91+typedef struct _GeisFilter *GeisFilter;
92+typedef struct _GeisSubscription *GeisSubscription;
93+
94+/**
95+ * Flags to refine the behaviour of the gesture subscription.
96+ */
97+typedef enum _GeisSubscriptionFlags
98+{
99+ GEIS_SUBSCRIPTION_NONE = 0x0000,
100+ GEIS_SUBSCRIPTION_GRAB = 0x0001,
101+ GEIS_SUBSCRIPTION_CONT = 0x0002
102+} GeisSubscriptionFlags;
103+
104+/**
105+ * Creates a new subscription.
106+ *
107+ * @param[in] geis The GEIS API instance.
108+ * @param[in] name A name.
109+ * @param[in] flags Some flags.
110+ *
111+ * @returns a GeisSubscription object or NULL on failure.
112+ *
113+ * A gesture subscription is required for any gesture events to be delivered
114+ * from the GEIS API.
115+ */
116+GEIS_API GeisSubscription geis_subscription_new(Geis geis,
117+ GeisString name,
118+ GeisSubscriptionFlags flags);
119+
120+/**
121+ * Destroys a GEIS v2.0 subscription object.
122+ *
123+ * @param[in] subscription The subscription.
124+ */
125+GEIS_API GeisStatus geis_subscription_delete(GeisSubscription subscription);
126+
127+/**
128+ * Gets the name given to a subscription when it was created.
129+ *
130+ * @param[in] subscription The subscription.
131+ */
132+GEIS_API GeisString geis_subscription_name(GeisSubscription subscription);
133+
134+/**
135+ * Gets the ID assigned to a subscription when it was created.
136+ *
137+ * @param[in] subscription The subscription.
138+ */
139+GEIS_API GeisInteger geis_subscription_id(GeisSubscription subscription);
140+
141+/**
142+ * Adds a filter to a subscription.
143+ *
144+ * @param[in] subscription The subscription.
145+ * @param[in] filter The filter to be added to the subscription.
146+ *
147+ * Thye effect of filters are ANDed together so that, for example, a
148+ * subscription that has a filter for 3-finger gestures and drag gestures will
149+ * produce events only for 3-finger drag gestures.
150+ *
151+ * The default is no filters: that is, all possible gesture events will be
152+ * reported.
153+ */
154+GEIS_API GeisStatus geis_subscription_add_filter(GeisSubscription subscription,
155+ GeisFilter filter);
156+
157+/**
158+ * Removes a filter from a subscription.
159+ *
160+ * @param[in] subscription The subscription.
161+ * @param[in] filter The filter to be removed from the subscription.
162+ */
163+GEIS_API GeisStatus geis_subscription_remove_filter(GeisSubscription subscription,
164+ GeisFilter filter);
165+
166+/* @} */
167+
168 #ifdef __cplusplus
169 } // extern "C"
170 #endif
171
172=== modified file 'libutouch-geis/Makefile.am'
173--- libutouch-geis/Makefile.am 2010-11-26 18:22:53 +0000
174+++ libutouch-geis/Makefile.am 2010-11-29 17:52:57 +0000
175@@ -23,10 +23,11 @@
176 lib_LTLIBRARIES = libutouch-geis.la
177
178 libutouch_geis_la_SOURCES = \
179- geis_attr.h geis_attr.c \
180- geis_error.h geis_error.c \
181- geis_logging.h geis_logging.c \
182- geis_private.h geis.c
183+ geis_attr.h geis_attr.c \
184+ geis_error.h geis_error.c \
185+ geis_logging.h geis_logging.c \
186+ geis_subscription.h geis_subscription.c \
187+ geis_private.h geis.c
188
189 libutouch_geis_la_CPPFLAGS = \
190 -Wall -Wextra \
191
192=== modified file 'libutouch-geis/geis.c'
193--- libutouch-geis/geis.c 2010-11-25 03:14:17 +0000
194+++ libutouch-geis/geis.c 2010-11-29 17:52:57 +0000
195@@ -40,7 +40,20 @@
196 {
197 geis_error_push(NULL, GEIS_STATUS_UNKNOWN_ERROR);
198 geis_error("calloc failed");
199- }
200+ goto error_exit;
201+ }
202+
203+ geis->subscription_bag = geis_subscription_bag_new(1);
204+ if (!geis->subscription_bag)
205+ {
206+ geis_error_push(NULL, GEIS_STATUS_UNKNOWN_ERROR);
207+ geis_error("creation of subscroption bag failed");
208+ free(geis);
209+ geis = NULL;
210+ goto error_exit;
211+ }
212+
213+error_exit:
214 return geis;
215 }
216
217@@ -132,3 +145,11 @@
218 return GEIS_STATUS_UNKNOWN_ERROR;
219 }
220
221+
222+GeisSubBag
223+geis_subscription_bag(Geis geis)
224+{
225+ return geis->subscription_bag;
226+}
227+
228+
229
230=== modified file 'libutouch-geis/geis_error.c'
231--- libutouch-geis/geis_error.c 2010-11-23 23:33:37 +0000
232+++ libutouch-geis/geis_error.c 2010-11-29 17:52:57 +0000
233@@ -49,7 +49,7 @@
234 error_stack->store = realloc(error_stack->store, error_stack->store_size);
235 if (!error_stack->store)
236 {
237- geis_error("error_stack realloc failed for size %d",
238+ geis_error("error_stack realloc failed for size %lu",
239 error_stack->store_size);
240 return;
241 }
242@@ -128,7 +128,7 @@
243
244
245 GeisString
246-geis_error_message(Geis geis, GeisSize index)
247+geis_error_message(Geis geis, GeisSize index __attribute__((unused)))
248 {
249 GeisString message = "";
250 if (geis)
251
252=== modified file 'libutouch-geis/geis_private.h'
253--- libutouch-geis/geis_private.h 2010-11-23 23:33:37 +0000
254+++ libutouch-geis/geis_private.h 2010-11-29 17:52:57 +0000
255@@ -24,13 +24,21 @@
256 #include <geis/geis.h>
257
258 #include "geis_error.h"
259+#include "geis_subscription.h"
260
261
262 struct _Geis
263 {
264 GeisBoolean is_test_fixture;
265 GeisErrorStack error_stack;
266+ GeisSubBag subscription_bag;
267 };
268
269
270+/**
271+ * Gets the subscription container from the geis object.
272+ */
273+GeisSubBag geis_subscription_bag(Geis geis);
274+
275+
276 #endif /* GEIS_PRIVATE_H_ */
277
278=== added file 'libutouch-geis/geis_subscription.c'
279--- libutouch-geis/geis_subscription.c 1970-01-01 00:00:00 +0000
280+++ libutouch-geis/geis_subscription.c 2010-11-29 17:52:57 +0000
281@@ -0,0 +1,306 @@
282+/**
283+ * @file libutouch-geis/geis_subscription.c
284+ * @brief implementation of the uTouch GEIS v2.0 API subscription module
285+ *
286+ * Copyright 2010 Canonical Ltd.
287+ *
288+ * This library is free software; you can redistribute it and/or modify it under
289+ * the terms of the GNU Lesser General Public License as published by the Free
290+ * Software Foundation; either version 3 of the License, or (at your option) any
291+ * later version.
292+ *
293+ * This library is distributed in the hope that it will be useful, but WITHOUT
294+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
295+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
296+ * details.
297+ *
298+ * You should have received a copy of the GNU Lesser General Public License
299+ * along with this program; if not, write to the Free Software Foundation, Inc.,
300+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
301+ */
302+#include "geis_config.h"
303+#include "geis_subscription.h"
304+
305+#include "geis/geis.h"
306+#include "geis_private.h"
307+#include "geis_logging.h"
308+#include <math.h>
309+#include <stdlib.h>
310+#include <string.h>
311+
312+
313+struct _GeisSubscription
314+{
315+ Geis sub_geis;
316+ GeisInteger sub_id;
317+ GeisString sub_name;
318+ GeisSubscriptionFlags sub_flags;
319+};
320+
321+struct _GeisSubBag
322+{
323+ GeisSubscription *sub_store;
324+ GeisSize sub_store_size;
325+};
326+
327+static const float sub_bag_growth_constant = 1.5f;
328+
329+
330+/**
331+ * Creates a new subsciption container.
332+ */
333+GeisSubBag
334+geis_subscription_bag_new(GeisSize size_hint)
335+{
336+ GeisSubBag bag = calloc(1, sizeof(struct _GeisSubBag));
337+ if (!bag)
338+ {
339+ geis_error("failed to allocate subscription container");
340+ goto error_exit;
341+ }
342+
343+ bag->sub_store_size = size_hint > 2 ? size_hint : 2;
344+ bag->sub_store = calloc(bag->sub_store_size, sizeof(GeisSubscription));
345+ if (!bag->sub_store)
346+ {
347+ geis_error("failed to allocate subscription container store");
348+ free(bag);
349+ bag = NULL;
350+ }
351+
352+error_exit:
353+ return bag;
354+}
355+
356+
357+/**
358+ * Destroys a subsciption container and free any associated resources.
359+ *
360+ * Any contained subsciptions that are still valid are also destroyed.
361+ */
362+void
363+geis_subscription_bag_delete(GeisSubBag bag)
364+{
365+ GeisSize i;
366+ for (i = 0; i < bag->sub_store_size; ++i)
367+ {
368+ if (bag->sub_store[i])
369+ geis_subscription_delete(bag->sub_store[i]);
370+ }
371+ free(bag);
372+}
373+
374+
375+/**
376+ * Gets the number of (valid) subsciptions in the subsciption container.
377+ */
378+GeisSize
379+geis_subscription_bag_count(GeisSubBag bag)
380+{
381+ GeisSize count = 0;
382+ GeisSize i;
383+ for (i = 0; i < bag->sub_store_size; ++i)
384+ {
385+ if (bag->sub_store[i])
386+ ++count;
387+ }
388+ return count;
389+}
390+
391+
392+/**
393+ * Inserts a subscription in the subscription container.
394+ */
395+GeisSize
396+geis_subscription_bag_insert(GeisSubBag bag,
397+ GeisSubscription sub)
398+{
399+ GeisSize index = -1;
400+ for (index = 0; index < bag->sub_store_size; ++index)
401+ {
402+ if (!bag->sub_store[index])
403+ {
404+ bag->sub_store[index] = sub;
405+ geis_debug("subscription \"%s\" inserted at index %lu",
406+ sub->sub_name, index);
407+ goto final_exit;
408+ }
409+ }
410+
411+ GeisSize new_store_size = ceilf(bag->sub_store_size
412+ * sub_bag_growth_constant);
413+ GeisSubscription *new_store = realloc(bag->sub_store, new_store_size);
414+ if (!new_store)
415+ {
416+ geis_error("failed to reallocate sub bag");
417+ goto final_exit;
418+ }
419+ index = bag->sub_store_size;
420+ bag->sub_store = new_store;
421+ bag->sub_store_size = new_store_size;
422+ bag->sub_store[index] = sub;
423+ geis_debug("subscription \"%s\" inserted at index %lu",
424+ sub->sub_name, index);
425+
426+final_exit:
427+ return index;
428+}
429+
430+
431+void
432+geis_subscription_bag_remove(GeisSubBag bag,
433+ GeisSubscription sub)
434+{
435+ bag->sub_store[sub->sub_id] = NULL;
436+ geis_debug("subscription \"%s\" removed", sub->sub_name);
437+}
438+
439+
440+/**
441+ * Finds a subsciption by ID.
442+ */
443+GeisSubscription
444+geis_subscription_bag_find(GeisSubBag bag, GeisInteger sub_id)
445+{
446+ GeisSubscription sub = NULL;
447+ GeisSize i;
448+ for (i = 0; i < bag->sub_store_size; ++i)
449+ {
450+ if (bag->sub_store[i] && bag->sub_store[i]->sub_id == sub_id)
451+ {
452+ sub = bag->sub_store[i];
453+ break;
454+ }
455+ }
456+ return sub;
457+}
458+
459+
460+/**
461+ * Creates a new subsciption on an API instance.
462+ */
463+GeisSubscription
464+geis_subscription_new(Geis geis,
465+ GeisString sub_name,
466+ GeisSubscriptionFlags sub_flags)
467+{
468+ GeisSubscription sub = calloc(1, sizeof(struct _GeisSubscription));
469+ if (!sub)
470+ {
471+ geis_error_push(geis, GEIS_STATUS_UNKNOWN_ERROR);
472+ geis_error("calloc failed");
473+ goto error_exit;
474+ }
475+ else
476+ {
477+ if (sub_name)
478+ {
479+ sub->sub_name = strdup(sub_name);
480+ }
481+ else
482+ {
483+ sub->sub_name = strdup("");
484+ }
485+ sub->sub_geis = geis;
486+ sub->sub_id = geis_subscription_bag_insert(geis_subscription_bag(geis), sub);
487+ sub->sub_flags = sub_flags;
488+ geis_debug("creating subscription \"%s\" id %d", sub->sub_name, sub->sub_id);
489+ }
490+
491+error_exit:
492+ return sub;
493+}
494+
495+
496+/**
497+ * Frees all resources allocated for the subscription and destroys the
498+ * subscription. Use of the subscription oject after this call will result in
499+ * undefined behaviour.
500+ */
501+GeisStatus
502+geis_subscription_delete(GeisSubscription sub)
503+{
504+ GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
505+ if (!sub)
506+ {
507+ status = GEIS_STATUS_BAD_ARGUMENT;
508+ goto error_exit;
509+ }
510+
511+ geis_debug("destroying subscription \"%s\" id %d", sub->sub_name, sub->sub_id);
512+
513+ geis_subscription_bag_remove(geis_subscription_bag(sub->sub_geis), sub);
514+
515+ free((char *)sub->sub_name);
516+ free(sub);
517+ status = GEIS_STATUS_SUCCESS;
518+
519+error_exit:
520+ return status;
521+}
522+
523+
524+/**
525+ * Retrieves the name used on creation of the subscrition.
526+ */
527+GeisString
528+geis_subscription_name(GeisSubscription subscription)
529+{
530+ return subscription->sub_name;
531+}
532+
533+
534+/**
535+ * Retrieves the identifier assigned to the subscrition on creation.
536+ * The identifier is only unique for a given API instance and identifiers may be
537+ * reused after the subscription they identify has been deleted.
538+ */
539+GeisInteger
540+geis_subscription_id(GeisSubscription subscription)
541+{
542+ return subscription->sub_id;
543+}
544+
545+
546+/**
547+ * Adds a filter to a subscription.
548+ *
549+ * @todo implement this function after the filter module is implemented
550+ */
551+GeisStatus
552+geis_subscription_add_filter(GeisSubscription sub,
553+ GeisFilter filter __attribute__((unused)))
554+{
555+ GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
556+ if (!sub)
557+ {
558+ status = GEIS_STATUS_BAD_ARGUMENT;
559+ goto error_exit;
560+ }
561+
562+error_exit:
563+ return status;
564+}
565+
566+
567+/**
568+ * Removes a filter from a subscription.
569+ *
570+ * @todo implement this function after the filter module is implemented
571+ */
572+GeisStatus
573+geis_subscription_remove_filter(GeisSubscription sub,
574+ GeisFilter filter __attribute__((unused)))
575+{
576+ GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
577+ if (!sub)
578+ {
579+ status = GEIS_STATUS_BAD_ARGUMENT;
580+ goto error_exit;
581+ }
582+
583+error_exit:
584+ return status;
585+}
586+
587+
588
589=== added file 'libutouch-geis/geis_subscription.h'
590--- libutouch-geis/geis_subscription.h 1970-01-01 00:00:00 +0000
591+++ libutouch-geis/geis_subscription.h 2010-11-29 17:52:57 +0000
592@@ -0,0 +1,76 @@
593+/**
594+ * @file geis_subscription.h
595+ * @brief internal uTouch Geis subscription modul private interface
596+ *
597+ * Copyright 2010 Canonical Ltd.
598+ *
599+ * This library is free software; you can redistribute it and/or modify it under
600+ * the terms of the GNU Lesser General Public License as published by the Free
601+ * Software Foundation; either version 3 of the License, or (at your option) any
602+ * later version.
603+ *
604+ * This library is distributed in the hope that it will be useful, but WITHOUT
605+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
606+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
607+ * details.
608+ *
609+ * You should have received a copy of the GNU Lesser General Public License
610+ * along with this program; if not, write to the Free Software Foundation, Inc.,
611+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
612+ */
613+#ifndef GEIS_SUBSCRIPTION_H_
614+#define GEIS_SUBSCRIPTION_H_
615+
616+#include <geis/geis.h>
617+
618+
619+/**
620+ * A container for subscriptions.
621+ */
622+typedef struct _GeisSubBag *GeisSubBag;
623+
624+
625+/**
626+ * Creates a new Geis Subscription container.
627+ *
628+ * @param[in] hint A hint as to how many subscriptions to initially allocate in
629+ * the new container.
630+ */
631+GeisSubBag geis_subscription_bag_new(GeisSize size_hint);
632+
633+/**
634+ * Destroys a Geis Subscription container.
635+ *
636+ * @param[in] bag The bag.
637+ */
638+void geis_subscription_bag_delete(GeisSubBag bag);
639+
640+/**
641+ * Tells how any entires in a Geis Subscription container.
642+ *
643+ * @param[in] bag The bag.
644+ */
645+GeisSize geis_subscription_bag_count(GeisSubBag bag);
646+
647+/**
648+ * Creates a new subscription object in a subscription container.
649+ *
650+ * @param[in] bag The bag.
651+ *
652+ * @returns the index of the newly inserted subscription
653+ */
654+GeisSize geis_subscription_bag_insert(GeisSubBag bag,
655+ GeisSubscription sub);
656+
657+void geis_subscription_bag_removed(GeisSubBag bag,
658+ GeisSubscription sub);
659+
660+/**
661+ * Looks for an subscription in an subscription container.
662+ *
663+ * @param[in] bag The bag.
664+ */
665+GeisSubscription geis_subscription_bag_find(GeisSubBag bag, GeisInteger sub_id);
666+
667+
668+#endif /* GEIS_SUBSCRIPTION_H_ */
669
670=== modified file 'libutouch-geis/libutouch-geis.ver'
671--- libutouch-geis/libutouch-geis.ver 2010-11-26 18:22:53 +0000
672+++ libutouch-geis/libutouch-geis.ver 2010-11-29 17:52:57 +0000
673@@ -20,12 +20,18 @@
674 geis_attr_value_to_integer;
675 geis_attr_value_to_string;
676 geis_delete;
677+ geis_error_code;
678 geis_error_count;
679- geis_error_code;
680 geis_error_message;
681 geis_get_configuration;
682 geis_new;
683 geis_set_configuration;
684+ geis_subscription_add_filter;
685+ geis_subscription_delete;
686+ geis_subscription_id;
687+ geis_subscription_name;
688+ geis_subscription_new;
689+ geis_subscription_remove_filter;
690
691 local:
692 *;
693
694=== modified file 'testsuite/geis2/Makefile.am'
695--- testsuite/geis2/Makefile.am 2010-11-25 03:14:17 +0000
696+++ testsuite/geis2/Makefile.am 2010-11-29 17:52:57 +0000
697@@ -18,6 +18,7 @@
698 check_error_codes.c \
699 check_geis_new.c \
700 check_general_types.c \
701+ check_subscription.c \
702 check_version_macro.c \
703 check_geis2_api.c
704
705
706=== modified file 'testsuite/geis2/check_geis2_api.c'
707--- testsuite/geis2/check_geis2_api.c 2010-11-25 03:14:17 +0000
708+++ testsuite/geis2/check_geis2_api.c 2010-11-29 17:52:57 +0000
709@@ -9,6 +9,7 @@
710 extern Suite *geis2_error_codes_suite_new();
711 extern Suite *geis2_geis_new_suite_new();
712 extern Suite *geis2_config_suite_new();
713+extern Suite *geis2_subscription_suite_new();
714
715 int
716 main(int argc, char* argv[])
717@@ -23,6 +24,7 @@
718 srunner_add_suite(sr, geis2_error_codes_suite_new());
719 srunner_add_suite(sr, geis2_geis_new_suite_new());
720 srunner_add_suite(sr, geis2_config_suite_new());
721+ srunner_add_suite(sr, geis2_subscription_suite_new());
722
723 srunner_set_log(sr, "geis2_api.log");
724 srunner_run_all(sr, CK_NORMAL);
725
726=== added file 'testsuite/geis2/check_subscription.c'
727--- testsuite/geis2/check_subscription.c 1970-01-01 00:00:00 +0000
728+++ testsuite/geis2/check_subscription.c 2010-11-29 17:52:57 +0000
729@@ -0,0 +1,67 @@
730+/**
731+ * Unit tests for GEIS v2.0 subsciption module
732+ */
733+#include <check.h>
734+
735+#include <geis/geis.h>
736+#include <string.h>
737+
738+
739+/* fixtures */
740+static Geis g_geis;
741+
742+/* fixture setup */
743+static void
744+construct_geis()
745+{
746+ g_geis = geis_new("geis-test-fixture", NULL);
747+}
748+
749+/* fixture teardown */
750+static void
751+destroy_geis()
752+{
753+ geis_delete(g_geis);
754+}
755+
756+
757+/* compile-time test to ensure required types are defined */
758+START_TEST(subscription_constants)
759+{
760+ GeisSubscriptionFlags f = GEIS_SUBSCRIPTION_NONE
761+ | GEIS_SUBSCRIPTION_GRAB
762+ | GEIS_SUBSCRIPTION_CONT;
763+}
764+END_TEST
765+
766+START_TEST(construction)
767+{
768+ GeisSubscription sub = geis_subscription_new(g_geis,
769+ "name",
770+ GEIS_SUBSCRIPTION_NONE);
771+ fail_unless(sub != NULL,
772+ "failed to create subscription");
773+ fail_unless(0 == strcmp(geis_subscription_name(sub), "name"),
774+ "unexpected subscription name returned");
775+ geis_subscription_delete(sub);
776+}
777+END_TEST
778+
779+/* boilerplate */
780+Suite *
781+geis2_subscription_suite_new()
782+{
783+ Suite *s = suite_create("geis2_subscriptions");
784+
785+ TCase *create = tcase_create("subscription-constants");
786+ tcase_add_test(create, subscription_constants);
787+ suite_add_tcase(s, create);
788+
789+ TCase *usage = tcase_create("subscription-usage");
790+ tcase_add_checked_fixture(usage, construct_geis, destroy_geis);
791+ tcase_add_test(usage, construction);
792+ suite_add_tcase(s, usage);
793+
794+ return s;
795+}
796+
797
798=== modified file 'testsuite/libutouch-geis/Makefile.am'
799--- testsuite/libutouch-geis/Makefile.am 2010-11-26 18:22:53 +0000
800+++ testsuite/libutouch-geis/Makefile.am 2010-11-29 17:52:57 +0000
801@@ -33,6 +33,7 @@
802 check_geis2_internals_SOURCES = \
803 check_attr.c \
804 check_error_reporting.c \
805+ check_subscription.c \
806 check_geis2_internals.c
807
808 check_geis2_internals_CFLAGS = \
809
810=== modified file 'testsuite/libutouch-geis/check_geis2_internals.c'
811--- testsuite/libutouch-geis/check_geis2_internals.c 2010-11-26 18:22:53 +0000
812+++ testsuite/libutouch-geis/check_geis2_internals.c 2010-11-29 17:52:57 +0000
813@@ -5,6 +5,7 @@
814
815 extern Suite *make_error_reporting_suite();
816 extern Suite *make_attr_suite();
817+extern Suite *make_subscription_suite();
818
819
820 int
821@@ -17,6 +18,7 @@
822 SRunner *sr = srunner_create(s);
823 srunner_add_suite(sr, make_error_reporting_suite());
824 srunner_add_suite(sr, make_attr_suite());
825+ srunner_add_suite(sr, make_subscription_suite());
826
827 srunner_set_log(sr, "geis2_internals.log");
828 srunner_run_all(sr, CK_NORMAL);
829
830=== added file 'testsuite/libutouch-geis/check_subscription.c'
831--- testsuite/libutouch-geis/check_subscription.c 1970-01-01 00:00:00 +0000
832+++ testsuite/libutouch-geis/check_subscription.c 2010-11-29 17:52:57 +0000
833@@ -0,0 +1,103 @@
834+/**
835+ * internal unit tests for the uTouch GEIS v2.0 subscription module
836+ */
837+#include <check.h>
838+
839+#include "geis/geis.h"
840+#include "libutouch-geis/geis_subscription.h"
841+
842+
843+/* fixtures */
844+static Geis g_geis;
845+static GeisSubBag g_sub_bag;
846+static const GeisString test_sub_string = "zot!";
847+
848+/* fixture setup */
849+static void
850+construct_bag()
851+{
852+ g_geis = geis_new("geis-test-fixture", NULL);
853+ g_sub_bag = geis_subscription_bag_new(1);
854+}
855+
856+/* fixture teardown */
857+static void
858+destroy_bag()
859+{
860+ geis_subscription_bag_delete(g_sub_bag);
861+ geis_delete(g_geis);
862+}
863+
864+
865+/* verify bag construction/destruction */
866+START_TEST(construction)
867+{
868+ GeisSubBag bag = geis_subscription_bag_new(1);
869+ fail_unless(bag != NULL,
870+ "failed to create subscription bag");
871+ fail_unless(geis_subscription_bag_count(bag) == 0,
872+ "unexpected size");
873+ geis_subscription_bag_delete(bag);
874+}
875+END_TEST
876+
877+
878+/* verify bag insertion */
879+START_TEST(insertion)
880+{
881+ GeisSubscription sub = geis_subscription_new(g_geis,
882+ "test-sub",
883+ GEIS_SUBSCRIPTION_NONE);
884+ geis_subscription_bag_insert(g_sub_bag, sub);
885+ fail_unless(geis_subscription_bag_count(g_sub_bag) == 1,
886+ "unexpected bag size after insertion");
887+}
888+END_TEST
889+
890+
891+/* verify bag find operation (positive results) */
892+START_TEST(find_success)
893+{
894+ GeisSubscription sub2;
895+ GeisSubscription sub1 = geis_subscription_new(g_geis,
896+ "test-sub",
897+ GEIS_SUBSCRIPTION_NONE);
898+ GeisSize id = geis_subscription_bag_insert(g_sub_bag, sub1);
899+ sub2 = geis_subscription_bag_find(g_sub_bag, id);
900+ fail_if(sub2 == NULL, "expected instance not found");
901+ fail_unless(0 == strcmp(geis_subscription_name(sub1),
902+ geis_subscription_name(sub2)),
903+ "unexpected subscription name returned");
904+}
905+END_TEST
906+
907+
908+/* verify bag find operation (negative results) */
909+START_TEST(find_fail)
910+{
911+ GeisSubscription sub = geis_subscription_bag_find(g_sub_bag, 999);
912+ fail_unless(sub == NULL, "unexpected instance found");
913+}
914+END_TEST
915+
916+
917+/* boilerplate */
918+Suite *
919+make_subscription_suite()
920+{
921+ Suite *s = suite_create("utouch-geis2-subscriptions");
922+
923+ TCase *create = tcase_create("sub-bag-creation");
924+ tcase_add_test(create, construction);
925+ suite_add_tcase(s, create);
926+
927+ TCase *usage = tcase_create("sub-bag-usage");
928+ tcase_add_checked_fixture(usage, construct_bag, destroy_bag);
929+ tcase_add_test(usage, insertion);
930+ tcase_add_test(usage, find_success);
931+ tcase_add_test(usage, find_fail);
932+ suite_add_tcase(s, usage);
933+
934+ return s;
935+}
936+

Subscribers

People subscribed via source and target branches

to all changes: