Merge lp:~ted/libindicate/variable-variants into lp:libindicate/0.6

Proposed by Ted Gould
Status: Merged
Merged at revision: not available
Proposed branch: lp:~ted/libindicate/variable-variants
Merge into: lp:libindicate/0.6
Diff against target: 568 lines (+274/-57)
10 files modified
libindicate/indicate-interface.xml (+2/-2)
libindicate/indicator.c (+75/-29)
libindicate/indicator.h (+5/-2)
libindicate/listener.c (+5/-11)
libindicate/listener.h (+2/-2)
libindicate/server.c (+21/-10)
libindicate/server.h (+1/-1)
tests/Makefile.am (+32/-0)
tests/test-properties-client.c (+36/-0)
tests/test-properties-server.c (+95/-0)
To merge this branch: bzr merge lp:~ted/libindicate/variable-variants
Reviewer Review Type Date Requested Status
David Barth Approve
Review via email: mp+18367@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

Making the dbus protocol use variants.

Revision history for this message
David Barth (dbarth) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libindicate/indicate-interface.xml'
2--- libindicate/indicate-interface.xml 2009-09-08 21:56:49 +0000
3+++ libindicate/indicate-interface.xml 2010-02-01 06:36:18 +0000
4@@ -45,12 +45,12 @@
5 <method name="GetIndicatorProperty">
6 <arg type="u" name="id" direction="in" />
7 <arg type="s" name="property" direction="in" />
8- <arg type="s" name="value" direction="out" />
9+ <arg type="v" name="value" direction="out" />
10 </method>
11 <method name="GetIndicatorPropertyGroup">
12 <arg type="u" name="id" direction="in" />
13 <arg type="as" name="properties" direction="in" />
14- <arg type="as" name="values" direction="out" />
15+ <arg type="a{sv}" name="values" direction="out" />
16 </method>
17 <method name="GetIndicatorProperties">
18 <arg type="u" name="id" direction="in" />
19
20=== modified file 'libindicate/indicator.c'
21--- libindicate/indicator.c 2009-09-14 14:48:43 +0000
22+++ libindicate/indicator.c 2010-02-01 06:36:18 +0000
23@@ -60,8 +60,8 @@
24 G_DEFINE_TYPE (IndicateIndicator, indicate_indicator, G_TYPE_OBJECT);
25
26 static void indicate_indicator_finalize (GObject * object);
27-static void set_property (IndicateIndicator * indicator, const gchar * key, const gchar * data);
28-static const gchar * get_property (IndicateIndicator * indicator, const gchar * key);
29+static void set_property (IndicateIndicator * indicator, const gchar * key, const GValue * data);
30+static const GValue * get_property (IndicateIndicator * indicator, const gchar * key);
31 static GPtrArray * list_properties (IndicateIndicator * indicator);
32
33
34@@ -166,6 +166,18 @@
35 return;
36 }
37
38+/* A small little function to both clear the insides of a
39+ value as well as the memory it itself uses. */
40+static void
41+_g_value_free (gpointer data)
42+{
43+ if (data == NULL) return;
44+ GValue * value = (GValue*)data;
45+ g_value_unset(value);
46+ g_free(data);
47+ return;
48+}
49+
50 static void
51 indicate_indicator_init (IndicateIndicator * indicator)
52 {
53@@ -175,7 +187,7 @@
54 priv->is_visible = FALSE;
55 priv->is_displayed = FALSE;
56
57- priv->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
58+ priv->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, _g_value_free);
59
60 priv->server = indicate_server_ref_default();
61 priv->id = indicate_server_get_next_id(priv->server);
62@@ -398,7 +410,11 @@
63 return;
64 }
65
66- return class->set_property(indicator, key, data);
67+ GValue strval = {0};
68+ g_value_init(&strval, G_TYPE_STRING);
69+ g_value_set_static_string(&strval, data);
70+
71+ return class->set_property(indicator, key, &strval);
72 }
73
74 /**
75@@ -436,12 +452,16 @@
76 void
77 indicate_indicator_set_property_int (IndicateIndicator * indicator, const gchar * key, gint value)
78 {
79- gchar * valuestr = g_strdup_printf("%d", value);
80- if (valuestr != NULL) {
81- indicate_indicator_set_property(indicator, key, valuestr);
82+ IndicateIndicatorClass * class = INDICATE_INDICATOR_GET_CLASS(indicator);
83+ if (class->set_property == NULL) {
84+ return;
85 }
86- g_free(valuestr);
87- return;
88+
89+ GValue intval = {0};
90+ g_value_init(&intval, G_TYPE_INT);
91+ g_value_set_int(&intval, value);
92+
93+ return class->set_property(indicator, key, &intval);
94 }
95
96 /**
97@@ -457,12 +477,27 @@
98 void
99 indicate_indicator_set_property_bool (IndicateIndicator * indicator, const gchar * key, gboolean value)
100 {
101- if (value) {
102- indicate_indicator_set_property(indicator, key, INDICATE_INDICATOR_VALUE_TRUE);
103- } else {
104- indicate_indicator_set_property(indicator, key, INDICATE_INDICATOR_VALUE_FALSE);
105- }
106- return;
107+ IndicateIndicatorClass * class = INDICATE_INDICATOR_GET_CLASS(indicator);
108+ if (class->set_property == NULL) {
109+ return;
110+ }
111+
112+ GValue boolval = {0};
113+ g_value_init(&boolval, G_TYPE_BOOLEAN);
114+ g_value_set_boolean(&boolval, value);
115+
116+ return class->set_property(indicator, key, &boolval);
117+}
118+
119+void
120+indicate_indicator_set_property_value (IndicateIndicator * indicator, const gchar * key, GValue * value)
121+{
122+ IndicateIndicatorClass * class = INDICATE_INDICATOR_GET_CLASS(indicator);
123+ if (class->set_property == NULL) {
124+ return;
125+ }
126+
127+ return class->set_property(indicator, key, value);
128 }
129
130 /**
131@@ -483,6 +518,18 @@
132 return NULL;
133 }
134
135+ const GValue * val = class->get_property(indicator, key);
136+ return g_value_get_string(val);
137+}
138+
139+const GValue *
140+indicate_indicator_get_property_value (IndicateIndicator * indicator, const gchar * key)
141+{
142+ IndicateIndicatorClass * class = INDICATE_INDICATOR_GET_CLASS(indicator);
143+ if (class->get_property == NULL) {
144+ return NULL;
145+ }
146+
147 return class->get_property(indicator, key);
148 }
149
150@@ -508,36 +555,35 @@
151 }
152
153 static void
154-set_property (IndicateIndicator * indicator, const gchar * key, const gchar * data)
155+set_property (IndicateIndicator * indicator, const gchar * key, const GValue * data)
156 {
157 g_return_if_fail(INDICATE_IS_INDICATOR(indicator));
158
159 IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator);
160
161- gchar * current = g_hash_table_lookup(priv->properties, key);
162- if (current == NULL || g_strcmp0(current, data)) {
163- /* If the value has changed or there is no value */
164- gchar * newkey = g_strdup(key);
165- /* g_debug("What is newkey? %s", newkey); */
166- g_hash_table_insert(priv->properties, newkey, g_strdup(data));
167- if (indicate_indicator_is_visible(indicator)) {
168- /* g_debug("Indicator property modified: %s %s", key, data); */
169- g_signal_emit(indicator, signals[MODIFIED], 0, key, TRUE);
170- }
171+ gchar * newkey = g_strdup(key);
172+ GValue * newval = g_new0(GValue, 1);
173+ g_value_init(newval, G_VALUE_TYPE(data));
174+ g_value_copy(data, newval);
175+
176+ g_hash_table_replace(priv->properties, newkey, newval);
177+
178+ if (indicate_indicator_is_visible(indicator)) {
179+ /* g_debug("Indicator property modified: %s", key); */
180+ g_signal_emit(indicator, signals[MODIFIED], 0, key, TRUE);
181 }
182
183 return;
184 }
185
186-static const gchar *
187+static const GValue *
188 get_property (IndicateIndicator * indicator, const gchar * key)
189 {
190 g_return_val_if_fail(INDICATE_IS_INDICATOR(indicator), NULL);
191
192 IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator);
193
194- // TODO: Think about whether we should be strdup'ing this. Seems like overkill, but might not be.
195- return (const gchar *)g_hash_table_lookup(priv->properties, key);
196+ return (const GValue *)g_hash_table_lookup(priv->properties, key);
197 }
198
199 static GPtrArray *
200
201=== modified file 'libindicate/indicator.h'
202--- libindicate/indicator.h 2009-09-14 14:48:43 +0000
203+++ libindicate/indicator.h 2010-02-01 06:36:18 +0000
204@@ -113,8 +113,8 @@
205 void (*displayed) (IndicateIndicator * indicator, gboolean displayed);
206
207 /* Subclassable functions */
208- void (*set_property) (IndicateIndicator * indicator, const gchar * key, const gchar * data);
209- const gchar * (*get_property) (IndicateIndicator * indicator, const gchar * key);
210+ void (*set_property) (IndicateIndicator * indicator, const gchar * key, const GValue * data);
211+ const GValue * (*get_property) (IndicateIndicator * indicator, const gchar * key);
212 GPtrArray * (*list_properties) (IndicateIndicator * indicator);
213
214 /* Reserver for future use */
215@@ -149,8 +149,11 @@
216 void indicate_indicator_set_property_time (IndicateIndicator * indicator, const gchar * key, GTimeVal * time);
217 void indicate_indicator_set_property_int (IndicateIndicator * indicator, const gchar * key, gint value);
218 void indicate_indicator_set_property_bool (IndicateIndicator * indicator, const gchar * key, gboolean value);
219+void indicate_indicator_set_property_value (IndicateIndicator * indicator, const gchar * key, GValue * value);
220
221 const gchar * indicate_indicator_get_property (IndicateIndicator * indicator, const gchar * key);
222+const GValue * indicate_indicator_get_property_value (IndicateIndicator * indicator, const gchar * key);
223+
224 GPtrArray * indicate_indicator_list_properties (IndicateIndicator * indicator);
225
226 /* Controling whether it's displayed */
227
228=== modified file 'libindicate/listener.c'
229--- libindicate/listener.c 2009-11-04 17:51:08 +0000
230+++ libindicate/listener.c 2010-02-01 06:36:18 +0000
231@@ -730,7 +730,7 @@
232 it nice to work with properties and the listener.
233 */
234 static void
235-get_property_cb (DBusGProxy *proxy, char * OUT_value, GError *error, gpointer userdata)
236+get_property_cb (DBusGProxy *proxy, GValue OUT_value, GError *error, gpointer userdata)
237 {
238 get_property_t * get_property_data = (get_property_t *)userdata;
239
240@@ -744,14 +744,14 @@
241 case PROPERTY_TYPE_STRING: {
242 /* Just pass the string along. */
243 indicate_listener_get_property_cb cb = (indicate_listener_get_property_cb)get_property_data->cb;
244- cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, OUT_value, get_property_data->data);
245+ cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, g_value_get_string(&OUT_value), get_property_data->data);
246 break;
247 }
248 case PROPERTY_TYPE_TIME: {
249 /* Convert it to a time val */
250 indicate_listener_get_property_time_cb cb = (indicate_listener_get_property_time_cb)get_property_data->cb;
251 GTimeVal time;
252- if (g_time_val_from_iso8601(OUT_value, &time)) {
253+ if (g_time_val_from_iso8601(g_value_get_string(&OUT_value), &time)) {
254 cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, &time, get_property_data->data);
255 }
256 break;
257@@ -759,20 +759,14 @@
258 case PROPERTY_TYPE_INT: {
259 /* Take the string and convert it to an integer */
260 indicate_listener_get_property_int_cb cb = (indicate_listener_get_property_int_cb)get_property_data->cb;
261- if (OUT_value == NULL) break;
262- gint intval = atoi(OUT_value);
263- cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, intval, get_property_data->data);
264+ cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, g_value_get_int(&OUT_value), get_property_data->data);
265 break;
266 }
267 case PROPERTY_TYPE_BOOL: {
268 /* Check to see if it's 'true', if not assume that
269 it's false */
270 indicate_listener_get_property_bool_cb cb = (indicate_listener_get_property_bool_cb)get_property_data->cb;
271- if (g_strcmp0(OUT_value, INDICATE_INDICATOR_VALUE_TRUE) == 0) {
272- cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, TRUE, get_property_data->data);
273- } else {
274- cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, FALSE, get_property_data->data);
275- }
276+ cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, g_value_get_boolean(&OUT_value), get_property_data->data);
277 break;
278 }
279 }
280
281=== modified file 'libindicate/listener.h'
282--- libindicate/listener.h 2009-09-14 15:01:18 +0000
283+++ libindicate/listener.h 2010-02-01 06:36:18 +0000
284@@ -110,8 +110,8 @@
285
286 GType indicate_listener_get_type (void) G_GNUC_CONST;
287
288-typedef void (*indicate_listener_get_property_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data);
289-typedef void (*indicate_listener_get_property_time_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GTimeVal * propertydata, gpointer data);
290+typedef void (*indicate_listener_get_property_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const gchar * propertydata, gpointer data);
291+typedef void (*indicate_listener_get_property_time_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const GTimeVal * propertydata, gpointer data);
292 typedef void (*indicate_listener_get_property_int_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gint propertydata, gpointer data);
293 typedef void (*indicate_listener_get_property_bool_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gboolean propertydata, gpointer data);
294 typedef void (*indicate_listener_get_server_property_cb) (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data);
295
296=== modified file 'libindicate/server.c'
297--- libindicate/server.c 2009-09-17 15:00:42 +0000
298+++ libindicate/server.c 2010-02-01 06:36:18 +0000
299@@ -129,7 +129,7 @@
300 static gboolean get_indicator_count (IndicateServer * server, guint * count, GError **error);
301 static gboolean get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** error);
302 static IndicateIndicator * get_indicator (IndicateServer * server, guint id, GError **error);
303-static gboolean get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error);
304+static gboolean get_indicator_property (IndicateServer * server, guint id, gchar * property, GValue * value, GError **error);
305 static gboolean get_indicator_property_group (IndicateServer * server, guint id, GPtrArray * properties, gchar *** value, GError **error);
306 static gboolean get_indicator_properties (IndicateServer * server, guint id, gchar *** properties, GError **error);
307 static gboolean show_indicator_to_user (IndicateServer * server, guint id, GError ** error);
308@@ -155,7 +155,7 @@
309 /* DBus API */
310 gboolean _indicate_server_get_indicator_count (IndicateServer * server, guint * count, GError **error);
311 gboolean _indicate_server_get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** error);
312-gboolean _indicate_server_get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error);
313+gboolean _indicate_server_get_indicator_property (IndicateServer * server, guint id, gchar * property, GValue * value, GError **error);
314 gboolean _indicate_server_get_indicator_property_group (IndicateServer * server, guint id, GPtrArray * properties, gchar *** value, GError **error);
315 gboolean _indicate_server_get_indicator_properties (IndicateServer * server, guint id, gchar *** properties, GError **error);
316 gboolean _indicate_server_show_indicator_to_user (IndicateServer * server, guint id, GError ** error);
317@@ -1187,14 +1187,20 @@
318 }
319
320 static gboolean
321-get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error)
322+get_indicator_property (IndicateServer * server, guint id, gchar * property, GValue * value, GError **error)
323 {
324 IndicateIndicator * indicator = get_indicator(server, id, error);
325 if (indicator == NULL) {
326 return FALSE;
327 }
328
329- *value = g_strdup(indicate_indicator_get_property(indicator, property));
330+ const GValue * ind_property = indicate_indicator_get_property_value(indicator, property);
331+ if (ind_property == NULL) {
332+ return FALSE;
333+ }
334+
335+ g_value_init(value, G_VALUE_TYPE(ind_property));
336+ g_value_copy(ind_property, value);
337 return TRUE;
338 }
339
340@@ -1209,12 +1215,17 @@
341 GPtrArray * array = g_ptr_array_new();
342 int i;
343 for (i = 0; i < properties->len; i++) {
344- const gchar * val = indicate_indicator_get_property(indicator, g_ptr_array_index(properties, i));
345- if (val != NULL) {
346- g_ptr_array_add(array, g_strdup(val));
347- } else {
348- g_ptr_array_add(array, g_strdup(""));
349+ const GValue * ind_property = indicate_indicator_get_property_value(indicator, g_ptr_array_index(properties, i));
350+
351+ if (ind_property == NULL) {
352+ continue;
353 }
354+
355+ GValue * value = g_new0(GValue, 1);
356+ g_value_init(value, G_VALUE_TYPE(ind_property));
357+ g_value_copy(ind_property, value);
358+
359+ g_ptr_array_add(array, value);
360 }
361 g_ptr_array_add(array, NULL);
362 *value = (gchar **)g_ptr_array_free(array, FALSE);
363@@ -1339,7 +1350,7 @@
364 }
365
366 gboolean
367-_indicate_server_get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error)
368+_indicate_server_get_indicator_property (IndicateServer * server, guint id, gchar * property, GValue * value, GError **error)
369 {
370 IndicateServerClass * class = INDICATE_SERVER_GET_CLASS(server);
371
372
373=== modified file 'libindicate/server.h'
374--- libindicate/server.h 2009-09-08 21:57:25 +0000
375+++ libindicate/server.h 2010-02-01 06:36:18 +0000
376@@ -150,7 +150,7 @@
377 /* Virtual Functions */
378 gboolean (*get_indicator_count) (IndicateServer * server, guint * count, GError **error);
379 gboolean (*get_indicator_list) (IndicateServer * server, GArray ** indicators, GError ** error);
380- gboolean (*get_indicator_property) (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error);
381+ gboolean (*get_indicator_property) (IndicateServer * server, guint id, gchar * property, GValue * value, GError **error);
382 gboolean (*get_indicator_property_group) (IndicateServer * server, guint id, GPtrArray * properties, gchar *** value, GError **error);
383 gboolean (*get_indicator_properties) (IndicateServer * server, guint id, gchar *** properties, GError **error);
384 gboolean (*show_indicator_to_user) (IndicateServer * server, guint id, GError ** error);
385
386=== modified file 'tests/Makefile.am'
387--- tests/Makefile.am 2009-12-10 15:13:43 +0000
388+++ tests/Makefile.am 2010-02-01 06:36:18 +0000
389@@ -37,6 +37,38 @@
390 $(LIBINDICATE_LIBS)
391
392 ##########################
393+# test properties
394+##########################
395+
396+TESTS += test-properties
397+check_PROGRAMS += test-properties-client test-properties-server
398+
399+test-properties: test-properties-client test-properties-server Makefile.am
400+ @echo "#!/bin/sh" > $@
401+ @echo "$(DBUS_RUNNER) --task ./test-properties-client --task-name Client --task ./test-properties-server --task-name Server" >> $@
402+ @chmod +x $@
403+
404+test_properties_client_SOURCES = \
405+ test-properties-client.c
406+
407+test_properties_client_CFLAGS = \
408+ $(LIBINDICATE_CFLAGS) -I$(srcdir)/..
409+
410+test_properties_client_LDADD = \
411+ ../libindicate/libindicate.la \
412+ $(LIBINDICATE_LIBS)
413+
414+test_properties_server_SOURCES = \
415+ test-properties-server.c
416+
417+test_properties_server_CFLAGS = \
418+ $(LIBINDICATE_CFLAGS) -I$(srcdir)/..
419+
420+test_properties_server_LDADD = \
421+ ../libindicate/libindicate.la \
422+ $(LIBINDICATE_LIBS)
423+
424+##########################
425 # test interests
426 ##########################
427
428
429=== added file 'tests/test-properties-client.c'
430--- tests/test-properties-client.c 1970-01-01 00:00:00 +0000
431+++ tests/test-properties-client.c 2010-02-01 06:36:18 +0000
432@@ -0,0 +1,36 @@
433+
434+#include <glib.h>
435+#include "libindicate/indicator.h"
436+
437+static gboolean passed = TRUE;
438+static GMainLoop * mainloop = NULL;
439+
440+static gboolean
441+done_timeout_cb (gpointer data)
442+{
443+ g_debug("All done.");
444+ g_main_loop_quit(mainloop);
445+ return FALSE;
446+}
447+
448+int
449+main (int argc, char * argv)
450+{
451+ g_type_init();
452+
453+ IndicateIndicator * indicator = indicate_indicator_new();
454+
455+ indicate_indicator_set_property(indicator, "string-value", "my-value");
456+ indicate_indicator_set_property_int(indicator, "int-value", 42);
457+ indicate_indicator_set_property_bool(indicator, "bool-value", TRUE);
458+ indicate_indicator_set_property_bool(indicator, "no-bool-value", FALSE);
459+
460+ indicate_indicator_show(indicator);
461+
462+ g_timeout_add_seconds(2, done_timeout_cb, indicator);
463+
464+ mainloop = g_main_loop_new(NULL, FALSE);
465+ g_main_loop_run(mainloop);
466+
467+ return !passed;
468+}
469
470=== added file 'tests/test-properties-server.c'
471--- tests/test-properties-server.c 1970-01-01 00:00:00 +0000
472+++ tests/test-properties-server.c 2010-02-01 06:36:18 +0000
473@@ -0,0 +1,95 @@
474+
475+#include <glib.h>
476+#include "libindicate/listener.h"
477+
478+static gboolean passed = TRUE;
479+static GMainLoop * mainloop = NULL;
480+static gint tests = 0;
481+
482+static void
483+string_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const gchar * propertydata, gpointer data)
484+{
485+ g_debug("Got string property '%s' value '%s'", property, propertydata);
486+ if (g_strcmp0(propertydata, (gchar *)data)) {
487+ passed = FALSE;
488+ g_debug("\tExpecting '%s'", (gchar *)data);
489+ }
490+ tests--;
491+ if (tests == 0) {
492+ g_main_loop_quit(mainloop);
493+ }
494+ return;
495+}
496+
497+static void
498+int_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gint propertydata, gpointer data)
499+{
500+ g_debug("Got int property '%s' value '%d'", property, propertydata);
501+ if (propertydata != GPOINTER_TO_INT(data)) {
502+ passed = FALSE;
503+ g_debug("\tExpecting '%d'", GPOINTER_TO_INT(data));
504+ }
505+ tests--;
506+ if (tests == 0) {
507+ g_main_loop_quit(mainloop);
508+ }
509+ return;
510+}
511+
512+static void
513+bool_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gboolean propertydata, gpointer data)
514+{
515+ g_debug("Got bool property '%s' value '%d'", property, propertydata);
516+ if (propertydata != GPOINTER_TO_INT(data)) {
517+ passed = FALSE;
518+ g_debug("\tExpecting '%d'", GPOINTER_TO_INT(data));
519+ }
520+ tests--;
521+ if (tests == 0) {
522+ g_main_loop_quit(mainloop);
523+ }
524+ return;
525+}
526+
527+static void
528+indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gpointer data)
529+{
530+ g_debug("Indicator Added: %s %d", INDICATE_LISTENER_SERVER_DBUS_NAME(server), indicate_listener_indicator_get_id(indicator));
531+
532+ indicate_listener_get_property(listener, server, indicator, "string-value", string_cb, "my-value");
533+ tests++;
534+ indicate_listener_get_property_int(listener, server, indicator, "int-value", int_cb, GINT_TO_POINTER(42));
535+ tests++;
536+ indicate_listener_get_property_bool(listener, server, indicator, "bool-value", bool_cb, GINT_TO_POINTER(TRUE));
537+ tests++;
538+ indicate_listener_get_property_bool(listener, server, indicator, "no-bool-value", bool_cb, GINT_TO_POINTER(FALSE));
539+ tests++;
540+
541+ return;
542+}
543+
544+static gboolean
545+failed_cb (gpointer data)
546+{
547+ g_debug("Failed to get a server in 5 seconds.");
548+ passed = FALSE;
549+ g_main_loop_quit(mainloop);
550+ return FALSE;
551+}
552+
553+int
554+main (int argc, char * argv)
555+{
556+ g_type_init();
557+
558+ IndicateListener * listener = indicate_listener_ref_default();
559+
560+ g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), NULL);
561+
562+ g_timeout_add_seconds(5, failed_cb, NULL);
563+
564+ mainloop = g_main_loop_new(NULL, FALSE);
565+ g_main_loop_run(mainloop);
566+
567+ return !passed;
568+}

Subscribers

People subscribed via source and target branches

to all changes: