4 static GDBusNodeInfo
*introspection_data
= NULL
;
5 static GMainLoop
*loop
= NULL
;
6 static GHashTable
*properties
= NULL
;
8 static const gchar introspection_xml
[] =
10 " <interface name='com.example.Frob'>"
11 " <method name='Quit'>"
13 " <method name='TestArrayOfStringTypes'>"
14 " <arg direction='in' type='as' name='val_string' />"
15 " <arg direction='in' type='ao' name='val_objpath' />"
16 " <arg direction='in' type='ag' name='val_signature' />"
17 " <arg direction='out' type='as' />"
18 " <arg direction='out' type='ao' />"
19 " <arg direction='out' type='ag' />"
21 " <method name='TestPrimitiveTypes'>"
22 " <arg direction='in' type='y' name='val_byte' />"
23 " <arg direction='in' type='b' name='val_boolean' />"
24 " <arg direction='in' type='n' name='val_int16' />"
25 " <arg direction='in' type='q' name='val_uint16' />"
26 " <arg direction='in' type='i' name='val_int32' />"
27 " <arg direction='in' type='u' name='val_uint32' />"
28 " <arg direction='in' type='x' name='val_int64' />"
29 " <arg direction='in' type='t' name='val_uint64' />"
30 " <arg direction='in' type='d' name='val_double' />"
31 " <arg direction='in' type='s' name='val_string' />"
32 " <arg direction='in' type='o' name='val_objpath' />"
33 " <arg direction='in' type='g' name='val_signature' />"
34 " <arg direction='out' type='y' />"
35 " <arg direction='out' type='b' />"
36 " <arg direction='out' type='n' />"
37 " <arg direction='out' type='q' />"
38 " <arg direction='out' type='i' />"
39 " <arg direction='out' type='u' />"
40 " <arg direction='out' type='x' />"
41 " <arg direction='out' type='t' />"
42 " <arg direction='out' type='d' />"
43 " <arg direction='out' type='s' />"
44 " <arg direction='out' type='o' />"
45 " <arg direction='out' type='g' />"
47 " <method name='EmitSignal'>"
48 " <arg direction='in' type='s' name='str1' />"
49 " <arg direction='in' type='o' name='objpath1' />"
51 " <method name='TestArrayOfPrimitiveTypes'>"
52 " <arg direction='in' type='ay' name='val_byte' />"
53 " <arg direction='in' type='ab' name='val_boolean' />"
54 " <arg direction='in' type='an' name='val_int16' />"
55 " <arg direction='in' type='aq' name='val_uint16' />"
56 " <arg direction='in' type='ai' name='val_int32' />"
57 " <arg direction='in' type='au' name='val_uint32' />"
58 " <arg direction='in' type='ax' name='val_int64' />"
59 " <arg direction='in' type='at' name='val_uint64' />"
60 " <arg direction='in' type='ad' name='val_double' />"
61 " <arg direction='out' type='ay' />"
62 " <arg direction='out' type='ab' />"
63 " <arg direction='out' type='an' />"
64 " <arg direction='out' type='aq' />"
65 " <arg direction='out' type='ai' />"
66 " <arg direction='out' type='au' />"
67 " <arg direction='out' type='ax' />"
68 " <arg direction='out' type='at' />"
69 " <arg direction='out' type='ad' />"
71 " <method name='FrobSetProperty'>"
72 " <arg direction='in' type='s' name='prop_name' />"
73 " <arg direction='in' type='v' name='prop_value' />"
75 " <signal name='TestSignal'>"
76 " <arg type='s' name='str1' />"
77 " <arg type='o' name='objpath1' />"
78 " <arg type='v' name='variant1' />"
80 " <method name='TestComplexArrays'>"
81 " <arg direction='in' type='a(ii)' name='aii' />"
82 " <arg direction='in' type='aa(ii)' name='aaii' />"
83 " <arg direction='in' type='aas' name='aas' />"
84 " <arg direction='in' type='aa{ss}' name='ahashes' />"
85 " <arg direction='in' type='aay' name='aay' />"
86 " <arg direction='in' type='av' name='av' />"
87 " <arg direction='in' type='aav' name='aav' />"
88 " <arg direction='out' type='a(ii)' />"
89 " <arg direction='out' type='aa(ii)' />"
90 " <arg direction='out' type='aas' />"
91 " <arg direction='out' type='aa{ss}' />"
92 " <arg direction='out' type='aay' />"
93 " <arg direction='out' type='av' />"
94 " <arg direction='out' type='aav' />"
96 " <method name='TestVariant'>"
97 " <arg direction='in' type='v' name='v' />"
98 " <arg direction='in' type='b' name='modify' />"
99 " <arg direction='out' type='v' />"
101 " <method name='FrobInvalidateProperty'>"
102 " <arg direction='in' type='s' name='new_value' />"
104 " <method name='HelloWorld'>"
105 " <arg direction='in' type='s' name='hello_message' />"
106 " <arg direction='out' type='s' />"
108 " <method name='PairReturn'>"
109 " <arg direction='out' type='s' />"
110 " <arg direction='out' type='u' />"
112 " <method name='TestStructureTypes'>"
113 " <arg direction='in' type='(ii)' name='s1' />"
114 " <arg direction='in' type='(s(ii)aya{ss})' name='s2' />"
115 " <arg direction='out' type='(ii)' />"
116 " <arg direction='out' type='(s(ii)aya{ss})' />"
118 " <method name='EmitSignal2'>"
120 " <method name='DoubleHelloWorld'>"
121 " <arg direction='in' type='s' name='hello1' />"
122 " <arg direction='in' type='s' name='hello2' />"
123 " <arg direction='out' type='s' />"
124 " <arg direction='out' type='s' />"
126 " <method name='Sleep'>"
127 " <arg direction='in' type='i' name='msec' />"
129 " <method name='TestHashTables'>"
130 " <arg direction='in' type='a{yy}' name='hyy' />"
131 " <arg direction='in' type='a{bb}' name='hbb' />"
132 " <arg direction='in' type='a{nn}' name='hnn' />"
133 " <arg direction='in' type='a{qq}' name='hqq' />"
134 " <arg direction='in' type='a{ii}' name='hii' />"
135 " <arg direction='in' type='a{uu}' name='huu' />"
136 " <arg direction='in' type='a{xx}' name='hxx' />"
137 " <arg direction='in' type='a{tt}' name='htt' />"
138 " <arg direction='in' type='a{dd}' name='hdd' />"
139 " <arg direction='in' type='a{ss}' name='hss' />"
140 " <arg direction='in' type='a{oo}' name='hoo' />"
141 " <arg direction='in' type='a{gg}' name='hgg' />"
142 " <arg direction='out' type='a{yy}' />"
143 " <arg direction='out' type='a{bb}' />"
144 " <arg direction='out' type='a{nn}' />"
145 " <arg direction='out' type='a{qq}' />"
146 " <arg direction='out' type='a{ii}' />"
147 " <arg direction='out' type='a{uu}' />"
148 " <arg direction='out' type='a{xx}' />"
149 " <arg direction='out' type='a{tt}' />"
150 " <arg direction='out' type='a{dd}' />"
151 " <arg direction='out' type='a{ss}' />"
152 " <arg direction='out' type='a{oo}' />"
153 " <arg direction='out' type='a{gg}' />"
155 " <signal name='TestSignal2'>"
156 " <arg type='i' name='int1' />"
158 " <method name='TestComplexHashTables'>"
159 " <arg direction='in' type='a{s(ii)}' name='h_str_to_pair' />"
160 " <arg direction='in' type='a{sv}' name='h_str_to_variant' />"
161 " <arg direction='in' type='a{sav}' name='h_str_to_av' />"
162 " <arg direction='in' type='a{saav}' name='h_str_to_aav' />"
163 " <arg direction='in' type='a{sa(ii)}' name='h_str_to_array_of_pairs' />"
164 " <arg direction='in' type='a{sa{ss}}' name='hash_of_hashes' />"
165 " <arg direction='out' type='a{s(ii)}' />"
166 " <arg direction='out' type='a{sv}' />"
167 " <arg direction='out' type='a{sav}' />"
168 " <arg direction='out' type='a{saav}' />"
169 " <arg direction='out' type='a{sa(ii)}' />"
170 " <arg direction='out' type='a{sa{ss}}' />"
172 " <property type='y' name='y' access='readwrite' />"
173 " <property type='b' name='b' access='readwrite' />"
174 " <property type='n' name='n' access='readwrite' />"
175 " <property type='q' name='q' access='readwrite' />"
176 " <property type='i' name='i' access='readwrite' />"
177 " <property type='u' name='u' access='readwrite' />"
178 " <property type='x' name='x' access='readwrite' />"
179 " <property type='t' name='t' access='readwrite' />"
180 " <property type='d' name='d' access='readwrite' />"
181 " <property type='s' name='s' access='readwrite' />"
182 " <property type='o' name='o' access='readwrite' />"
183 " <property type='ay' name='ay' access='readwrite' />"
184 " <property type='ab' name='ab' access='readwrite' />"
185 " <property type='an' name='an' access='readwrite' />"
186 " <property type='aq' name='aq' access='readwrite' />"
187 " <property type='ai' name='ai' access='readwrite' />"
188 " <property type='au' name='au' access='readwrite' />"
189 " <property type='ax' name='ax' access='readwrite' />"
190 " <property type='at' name='at' access='readwrite' />"
191 " <property type='ad' name='ad' access='readwrite' />"
192 " <property type='as' name='as' access='readwrite' />"
193 " <property type='ao' name='ao' access='readwrite' />"
194 " <property type='s' name='foo' access='readwrite' />"
195 " <property type='s' name='PropertyThatWillBeInvalidated' access='readwrite' />"
200 end_sleep (gpointer data
)
202 GDBusMethodInvocation
*invocation
= data
;
204 g_dbus_method_invocation_return_value (invocation
, NULL
);
205 g_object_unref (invocation
);
207 return G_SOURCE_REMOVE
;
211 handle_method_call (GDBusConnection
*connection
,
213 const gchar
*object_path
,
214 const gchar
*interface_name
,
215 const gchar
*method_name
,
216 GVariant
*parameters
,
217 GDBusMethodInvocation
*invocation
,
220 if (g_strcmp0 (method_name
, "HelloWorld") == 0)
222 const gchar
*greeting
;
224 g_variant_get (parameters
, "(&s)", &greeting
);
225 if (g_strcmp0 (greeting
, "Yo") == 0)
227 g_dbus_method_invocation_return_dbus_error (invocation
,
228 "com.example.TestException",
229 "Yo is not a proper greeting");
234 response
= g_strdup_printf ("You greeted me with '%s'. Thanks!", greeting
);
235 g_dbus_method_invocation_return_value (invocation
,
236 g_variant_new ("(s)", response
));
240 else if (g_strcmp0 (method_name
, "DoubleHelloWorld") == 0)
242 const gchar
*hello1
, *hello2
;
243 gchar
*reply1
, *reply2
;
245 g_variant_get (parameters
, "(&s&s)", &hello1
, &hello2
);
246 reply1
= g_strdup_printf ("You greeted me with '%s'. Thanks!", hello1
);
247 reply2
= g_strdup_printf ("Yo dawg, you uttered '%s'. Thanks!", hello2
);
248 g_dbus_method_invocation_return_value (invocation
,
249 g_variant_new ("(ss)", reply1
, reply2
));
253 else if (g_strcmp0 (method_name
, "PairReturn") == 0)
255 g_dbus_method_invocation_return_value (invocation
,
256 g_variant_new ("(su)", "foo", 42));
258 else if (g_strcmp0 (method_name
, "TestPrimitiveTypes") == 0)
261 gboolean val_boolean
;
269 const gchar
*val_string
;
270 const gchar
*val_objpath
;
271 const gchar
*val_signature
;
274 gchar
*ret_signature
;
276 g_variant_get (parameters
, "(ybnqiuxtd&s&o&g)",
290 ret_string
= g_strconcat (val_string
, val_string
, NULL
);
291 ret_objpath
= g_strconcat (val_objpath
, "/modified", NULL
);
292 ret_signature
= g_strconcat (val_signature
, val_signature
, NULL
);
294 g_dbus_method_invocation_return_value (invocation
,
295 g_variant_new ("(ybnqiuxtdsog)",
304 - val_double
+ 0.123,
310 g_free (ret_objpath
);
311 g_free (ret_signature
);
313 else if (g_strcmp0 (method_name
, "TestArrayOfPrimitiveTypes") == 0)
317 const gint16
*int16s
;
318 const guint16
*uint16s
;
319 const gint32
*int32s
;
320 const guint32
*uint32s
;
321 const gint64
*int64s
;
322 const guint64
*uint64s
;
323 const gdouble
*doubles
;
328 g_variant_builder_init (&ret
, G_VARIANT_TYPE ("(ayabanaqaiauaxatad)"));
330 v
= g_variant_get_child_value (parameters
, 0);
331 bytes
= g_variant_get_fixed_array (v
, &n_elts
, 1);
332 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("ay"));
333 for (j
= 0; j
< 2; j
++)
334 for (i
= 0; i
< n_elts
; i
++)
335 g_variant_builder_add (&ret
, "y", bytes
[i
]);
336 g_variant_builder_close (&ret
);
339 v
= g_variant_get_child_value (parameters
, 1);
340 bytes
= g_variant_get_fixed_array (v
, &n_elts
, 1);
341 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("ab"));
342 for (j
= 0; j
< 2; j
++)
343 for (i
= 0; i
< n_elts
; i
++)
344 g_variant_builder_add (&ret
, "b", (gboolean
)bytes
[i
]);
345 g_variant_builder_close (&ret
);
348 v
= g_variant_get_child_value (parameters
, 2);
349 int16s
= g_variant_get_fixed_array (v
, &n_elts
, 2);
350 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("an"));
351 for (j
= 0; j
< 2; j
++)
352 for (i
= 0; i
< n_elts
; i
++)
353 g_variant_builder_add (&ret
, "n", int16s
[i
]);
354 g_variant_builder_close (&ret
);
357 v
= g_variant_get_child_value (parameters
, 3);
358 uint16s
= g_variant_get_fixed_array (v
, &n_elts
, 2);
359 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("aq"));
360 for (j
= 0; j
< 2; j
++)
361 for (i
= 0; i
< n_elts
; i
++)
362 g_variant_builder_add (&ret
, "q", uint16s
[i
]);
363 g_variant_builder_close (&ret
);
366 v
= g_variant_get_child_value (parameters
, 4);
367 int32s
= g_variant_get_fixed_array (v
, &n_elts
, 4);
368 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("ai"));
369 for (j
= 0; j
< 2; j
++)
370 for (i
= 0; i
< n_elts
; i
++)
371 g_variant_builder_add (&ret
, "i", int32s
[i
]);
372 g_variant_builder_close (&ret
);
375 v
= g_variant_get_child_value (parameters
, 5);
376 uint32s
= g_variant_get_fixed_array (v
, &n_elts
, 4);
377 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("au"));
378 for (j
= 0; j
< 2; j
++)
379 for (i
= 0; i
< n_elts
; i
++)
380 g_variant_builder_add (&ret
, "u", uint32s
[i
]);
381 g_variant_builder_close (&ret
);
384 v
= g_variant_get_child_value (parameters
, 6);
385 int64s
= g_variant_get_fixed_array (v
, &n_elts
, 8);
386 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("ax"));
387 for (j
= 0; j
< 2; j
++)
388 for (i
= 0; i
< n_elts
; i
++)
389 g_variant_builder_add (&ret
, "x", int64s
[i
]);
390 g_variant_builder_close (&ret
);
393 v
= g_variant_get_child_value (parameters
, 7);
394 uint64s
= g_variant_get_fixed_array (v
, &n_elts
, 8);
395 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("at"));
396 for (j
= 0; j
< 2; j
++)
397 for (i
= 0; i
< n_elts
; i
++)
398 g_variant_builder_add (&ret
, "t", uint64s
[i
]);
399 g_variant_builder_close (&ret
);
402 v
= g_variant_get_child_value (parameters
, 8);
403 doubles
= g_variant_get_fixed_array (v
, &n_elts
, sizeof (gdouble
));
404 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("ad"));
405 for (j
= 0; j
< 2; j
++)
406 for (i
= 0; i
< n_elts
; i
++)
407 g_variant_builder_add (&ret
, "d", doubles
[i
]);
408 g_variant_builder_close (&ret
);
411 g_dbus_method_invocation_return_value (invocation
,
412 g_variant_builder_end (&ret
));
414 else if (g_strcmp0 (method_name
, "TestArrayOfStringTypes") == 0)
424 g_variant_builder_init (&ret
, G_VARIANT_TYPE ("(asaoag)"));
425 g_variant_get (parameters
, "(asaoag)", &iter1
, &iter2
, &iter3
);
427 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("as"));
428 for (i
= 0; i
< 2; i
++)
430 iter
= g_variant_iter_copy (iter1
);
431 while (g_variant_iter_loop (iter
, "s", &s
))
432 g_variant_builder_add (&ret
, "s", s
);
433 g_variant_iter_free (iter
);
435 g_variant_builder_close (&ret
);
437 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("ao"));
438 for (i
= 0; i
< 2; i
++)
440 iter
= g_variant_iter_copy (iter1
);
441 while (g_variant_iter_loop (iter
, "o", &s
))
442 g_variant_builder_add (&ret
, "o", s
);
443 g_variant_iter_free (iter
);
445 g_variant_builder_close (&ret
);
447 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("ag"));
448 for (i
= 0; i
< 2; i
++)
450 iter
= g_variant_iter_copy (iter1
);
451 while (g_variant_iter_loop (iter
, "g", &s
))
452 g_variant_builder_add (&ret
, "g", s
);
453 g_variant_iter_free (iter
);
455 g_variant_builder_close (&ret
);
457 g_variant_iter_free (iter1
);
458 g_variant_iter_free (iter2
);
459 g_variant_iter_free (iter3
);
461 g_dbus_method_invocation_return_value (invocation
,
462 g_variant_builder_end (&ret
));
464 else if (g_strcmp0 (method_name
, "TestHashTables") == 0)
480 g_variant_builder_init (&ret
, G_VARIANT_TYPE ("(a{yy}a{bb}a{nn}a{qq}a{ii}a{uu}a{xx}a{tt}a{dd}a{ss}a{oo}a{gg})"));
482 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{yy}"));
483 v
= g_variant_get_child_value (parameters
, 0);
484 g_variant_iter_init (&iter
, v
);
485 while (g_variant_iter_loop (&iter
, "yy", &y1
, &y2
))
486 g_variant_builder_add (&ret
, "{yy}", y1
* 2, (y2
* 3) & 255);
488 g_variant_builder_close (&ret
);
490 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{bb}"));
491 v
= g_variant_get_child_value (parameters
, 1);
492 g_variant_iter_init (&iter
, v
);
493 while (g_variant_iter_loop (&iter
, "bb", &b1
, &b2
))
494 g_variant_builder_add (&ret
, "{bb}", b1
, TRUE
);
496 g_variant_builder_close (&ret
);
498 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{nn}"));
499 v
= g_variant_get_child_value (parameters
, 2);
500 g_variant_iter_init (&iter
, v
);
501 while (g_variant_iter_loop (&iter
, "nn", &n1
, &n2
))
502 g_variant_builder_add (&ret
, "{nn}", n1
* 2, n2
* 3);
504 g_variant_builder_close (&ret
);
506 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{qq}"));
507 v
= g_variant_get_child_value (parameters
, 3);
508 g_variant_iter_init (&iter
, v
);
509 while (g_variant_iter_loop (&iter
, "qq", &q1
, &q2
))
510 g_variant_builder_add (&ret
, "{qq}", q1
* 2, q2
* 3);
512 g_variant_builder_close (&ret
);
514 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{ii}"));
515 v
= g_variant_get_child_value (parameters
, 4);
516 g_variant_iter_init (&iter
, v
);
517 while (g_variant_iter_loop (&iter
, "ii", &i1
, &i2
))
518 g_variant_builder_add (&ret
, "{ii}", i1
* 2, i2
* 3);
520 g_variant_builder_close (&ret
);
522 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{uu}"));
523 v
= g_variant_get_child_value (parameters
, 5);
524 g_variant_iter_init (&iter
, v
);
525 while (g_variant_iter_loop (&iter
, "uu", &u1
, &u2
))
526 g_variant_builder_add (&ret
, "{uu}", u1
* 2, u2
* 3);
528 g_variant_builder_close (&ret
);
530 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{xx}"));
531 v
= g_variant_get_child_value (parameters
, 6);
532 g_variant_iter_init (&iter
, v
);
533 while (g_variant_iter_loop (&iter
, "xx", &x1
, &x2
))
534 g_variant_builder_add (&ret
, "{xx}", x1
+ 2, x2
+ 1);
536 g_variant_builder_close (&ret
);
538 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{tt}"));
539 v
= g_variant_get_child_value (parameters
, 7);
540 g_variant_iter_init (&iter
, v
);
541 while (g_variant_iter_loop (&iter
, "tt", &t1
, &t2
))
542 g_variant_builder_add (&ret
, "{tt}", t1
+ 2, t2
+ 1);
544 g_variant_builder_close (&ret
);
546 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{dd}"));
547 v
= g_variant_get_child_value (parameters
, 8);
548 g_variant_iter_init (&iter
, v
);
549 while (g_variant_iter_loop (&iter
, "dd", &d1
, &d2
))
550 g_variant_builder_add (&ret
, "{dd}", d1
+ 2.5, d2
+ 5.0);
552 g_variant_builder_close (&ret
);
554 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{ss}"));
555 v
= g_variant_get_child_value (parameters
, 9);
556 g_variant_iter_init (&iter
, v
);
557 while (g_variant_iter_loop (&iter
, "ss", &s1
, &s2
))
560 tmp1
= g_strconcat (s1
, "mod", NULL
);
561 tmp2
= g_strconcat (s2
, s2
, NULL
);
562 g_variant_builder_add (&ret
, "{ss}", tmp1
, tmp2
);
567 g_variant_builder_close (&ret
);
569 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{oo}"));
570 v
= g_variant_get_child_value (parameters
, 10);
571 g_variant_iter_init (&iter
, v
);
572 while (g_variant_iter_loop (&iter
, "oo", &s1
, &s2
))
575 tmp1
= g_strconcat (s1
, "/mod", NULL
);
576 tmp2
= g_strconcat (s2
, "/mod2", NULL
);
577 g_variant_builder_add (&ret
, "{oo}", tmp1
, tmp2
);
582 g_variant_builder_close (&ret
);
584 g_variant_builder_open (&ret
, G_VARIANT_TYPE ("a{gg}"));
585 v
= g_variant_get_child_value (parameters
, 11);
586 g_variant_iter_init (&iter
, v
);
587 while (g_variant_iter_loop (&iter
, "gg", &s1
, &s2
))
590 tmp1
= g_strconcat (s1
, "assgit", NULL
);
591 tmp2
= g_strconcat (s2
, s2
, NULL
);
592 g_variant_builder_add (&ret
, "{gg}", tmp1
, tmp2
);
597 g_variant_builder_close (&ret
);
599 g_dbus_method_invocation_return_value (invocation
,
600 g_variant_builder_end (&ret
));
602 else if (g_strcmp0 (method_name
, "TestStructureTypes") == 0)
606 GVariantIter
*iter1
, *iter2
;
608 GVariantBuilder ret1
, ret2
;
613 g_variant_get (parameters
, "((ii)(&s(ii)aya{ss}))",
614 &x
, &y
, &desc
, &x1
, &y1
, &iter1
, &iter2
);
616 desc_ret
= g_strconcat (desc
, "... in bed!", NULL
);
618 g_variant_builder_init (&ret1
, G_VARIANT_TYPE ("ay"));
619 iter
= g_variant_iter_copy (iter1
);
620 while (g_variant_iter_loop (iter1
, "y", &v
))
621 g_variant_builder_add (&ret1
, "y", v
);
622 while (g_variant_iter_loop (iter
, "y", &v
))
623 g_variant_builder_add (&ret1
, "y", v
);
624 g_variant_iter_free (iter
);
625 g_variant_iter_free (iter1
);
627 g_variant_builder_init (&ret2
, G_VARIANT_TYPE ("a{ss}"));
628 while (g_variant_iter_loop (iter1
, "ss", &s1
, &s2
))
631 tmp
= g_strconcat (s2
, " ... in bed!", NULL
);
632 g_variant_builder_add (&ret1
, "{ss}", s1
, tmp
);
635 g_variant_iter_free (iter2
);
637 g_dbus_method_invocation_return_value (invocation
,
638 g_variant_new ("((ii)(&s(ii)aya{ss}))",
639 x
+ 1, y
+ 1, desc_ret
, x1
+ 2, y1
+ 2,
644 else if (g_strcmp0 (method_name
, "TestVariant") == 0)
650 g_variant_get (parameters
, "(vb)", &v
, &modify
);
652 /* FIXME handle more cases */
655 if (g_variant_is_of_type (v
, G_VARIANT_TYPE_BOOLEAN
))
657 ret
= g_variant_new_boolean (FALSE
);
659 else if (g_variant_is_of_type (v
, G_VARIANT_TYPE_TUPLE
))
661 ret
= g_variant_new ("(si)", "other struct", 100);
664 g_assert_not_reached ();
669 g_dbus_method_invocation_return_value (invocation
, ret
);
672 else if (g_strcmp0 (method_name
, "TestComplexArrays") == 0)
675 g_dbus_method_invocation_return_value (invocation
, parameters
);
677 else if (g_strcmp0 (method_name
, "TestComplexHashTables") == 0)
680 g_dbus_method_invocation_return_value (invocation
, parameters
);
682 else if (g_strcmp0 (method_name
, "FrobSetProperty") == 0)
686 g_variant_get (parameters
, "(sv)", &name
, &value
);
687 g_hash_table_replace (properties
, name
, value
);
688 g_dbus_connection_emit_signal (connection
,
690 "/com/example/TestObject",
691 "org.freedesktop.DBus.Properties",
693 g_variant_new_parsed ("('com.example.Frob', [{%s, %v}], @as [])", name
, value
),
695 g_dbus_method_invocation_return_value (invocation
, NULL
);
697 else if (g_strcmp0 (method_name
, "FrobInvalidateProperty") == 0)
700 g_variant_get (parameters
, "(&s)", &value
);
701 g_hash_table_replace (properties
, g_strdup ("PropertyThatWillBeInvalidated"), g_variant_ref_sink (g_variant_new_string (value
)));
703 g_dbus_connection_emit_signal (connection
,
705 "/com/example/TestObject",
706 "org.freedesktop.DBus.Properties",
708 g_variant_new_parsed ("('com.example.Frob', @a{sv} [], ['PropertyThatWillBeInvalidated'])"),
710 g_dbus_method_invocation_return_value (invocation
, NULL
);
712 else if (g_strcmp0 (method_name
, "EmitSignal") == 0)
718 g_variant_get (parameters
, "(&s&o)", &str
, &path
);
719 str_ret
= g_strconcat (str
, " .. in bed!", NULL
);
720 path_ret
= g_strconcat (path
, "/in/bed", NULL
);
721 g_dbus_connection_emit_signal (connection
,
723 "/com/example/TestObject",
726 g_variant_new_parsed ("(%s, %o, <'a variant'>)", str_ret
, path_ret
),
730 g_dbus_method_invocation_return_value (invocation
, NULL
);
732 else if (g_strcmp0 (method_name
, "EmitSignal2") == 0)
734 g_dbus_connection_emit_signal (connection
,
736 "/com/example/TestObject",
739 g_variant_new_parsed ("(42, )"),
741 g_dbus_method_invocation_return_value (invocation
, NULL
);
743 else if (g_strcmp0 (method_name
, "Sleep") == 0)
747 g_variant_get (parameters
, "(i)", &msec
);
749 g_timeout_add ((guint
)msec
, end_sleep
, g_object_ref (invocation
));
751 else if (g_strcmp0 (method_name
, "Quit") == 0)
753 g_dbus_method_invocation_return_value (invocation
, NULL
);
754 g_main_loop_quit (loop
);
759 handle_get_property (GDBusConnection
*connection
,
761 const gchar
*object_path
,
762 const gchar
*interface_name
,
763 const gchar
*property_name
,
769 ret
= g_hash_table_lookup (properties
, property_name
);
772 g_assert (!g_variant_is_floating (ret
));
778 G_DBUS_ERROR
, G_DBUS_ERROR_FAILED
,
779 "no such property: %s", property_name
);
786 handle_set_property (GDBusConnection
*connection
,
788 const gchar
*object_path
,
789 const gchar
*interface_name
,
790 const gchar
*property_name
,
796 G_DBUS_ERROR
, G_DBUS_ERROR_FAILED
,
797 "SetProperty not implemented");
801 static const GDBusInterfaceVTable interface_vtable
=
809 on_bus_acquired (GDBusConnection
*connection
,
815 id
= g_dbus_connection_register_object (connection
,
816 "/com/example/TestObject",
817 introspection_data
->interfaces
[0],
826 on_name_acquired (GDBusConnection
*connection
,
833 on_name_lost (GDBusConnection
*connection
,
841 main (int argc
, char *argv
[])
845 introspection_data
= g_dbus_node_info_new_for_xml (introspection_xml
, NULL
);
846 properties
= g_hash_table_new_full (g_str_hash
, g_str_equal
, g_free
, (GDestroyNotify
)g_variant_unref
);
847 g_hash_table_insert (properties
, g_strdup ("y"), g_variant_ref_sink (g_variant_new_byte (1)));
848 g_hash_table_insert (properties
, g_strdup ("b"), g_variant_ref_sink (g_variant_new_boolean (TRUE
)));
849 g_hash_table_insert (properties
, g_strdup ("n"), g_variant_ref_sink (g_variant_new_int16 (2)));
850 g_hash_table_insert (properties
, g_strdup ("q"), g_variant_ref_sink (g_variant_new_uint16 (3)));
851 g_hash_table_insert (properties
, g_strdup ("i"), g_variant_ref_sink (g_variant_new_int32 (4)));
852 g_hash_table_insert (properties
, g_strdup ("u"), g_variant_ref_sink (g_variant_new_uint32 (5)));
853 g_hash_table_insert (properties
, g_strdup ("x"), g_variant_ref_sink (g_variant_new_int64 (6)));
854 g_hash_table_insert (properties
, g_strdup ("t"), g_variant_ref_sink (g_variant_new_uint64 (7)));
855 g_hash_table_insert (properties
, g_strdup ("d"), g_variant_ref_sink (g_variant_new_double (7.5)));
856 g_hash_table_insert (properties
, g_strdup ("s"), g_variant_ref_sink (g_variant_new_string ("a string")));
857 g_hash_table_insert (properties
, g_strdup ("o"), g_variant_ref_sink (g_variant_new_object_path ("/some/path")));
858 g_hash_table_insert (properties
, g_strdup ("ay"), g_variant_ref_sink (g_variant_new_parsed ("[@y 1, @y 11]")));
859 g_hash_table_insert (properties
, g_strdup ("ab"), g_variant_ref_sink (g_variant_new_parsed ("[true, false]")));
860 g_hash_table_insert (properties
, g_strdup ("an"), g_variant_ref_sink (g_variant_new_parsed ("[@n 2, @n 12]")));
861 g_hash_table_insert (properties
, g_strdup ("aq"), g_variant_ref_sink (g_variant_new_parsed ("[@q 3, @q 13]")));
862 g_hash_table_insert (properties
, g_strdup ("ai"), g_variant_ref_sink (g_variant_new_parsed ("[@i 4, @i 14]")));
863 g_hash_table_insert (properties
, g_strdup ("au"), g_variant_ref_sink (g_variant_new_parsed ("[@u 5, @u 15]")));
864 g_hash_table_insert (properties
, g_strdup ("ax"), g_variant_ref_sink (g_variant_new_parsed ("[@x 6, @x 16]")));
865 g_hash_table_insert (properties
, g_strdup ("at"), g_variant_ref_sink (g_variant_new_parsed ("[@t 7, @t 17]")));
866 g_hash_table_insert (properties
, g_strdup ("ad"), g_variant_ref_sink (g_variant_new_parsed ("[7.5, 17.5]")));
867 g_hash_table_insert (properties
, g_strdup ("as"), g_variant_ref_sink (g_variant_new_parsed ("['a string', 'another string']")));
868 g_hash_table_insert (properties
, g_strdup ("ao"), g_variant_ref_sink (g_variant_new_parsed ("[@o '/some/path', @o '/another/path']")));
869 g_hash_table_insert (properties
, g_strdup ("foo"), g_variant_ref_sink (g_variant_new_string ("a frobbed string")));
870 g_hash_table_insert (properties
, g_strdup ("PropertyThatWillBeInvalidated"), g_variant_ref_sink (g_variant_new_string ("InitialValue")));
872 owner_id
= g_bus_own_name (G_BUS_TYPE_SESSION
,
873 "com.example.TestService",
874 G_BUS_NAME_OWNER_FLAGS_NONE
,
881 loop
= g_main_loop_new (NULL
, FALSE
);
882 g_main_loop_run (loop
);
884 g_bus_unown_name (owner_id
);
886 g_dbus_node_info_unref (introspection_data
);