3 # GDBus - GLib D-Bus Library
5 # Copyright (C) 2008-2011 Red Hat, Inc.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General
18 # Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 # Author: David Zeuthen <davidz@redhat.com>
26 from . import dbustypes
28 # ----------------------------------------------------------------------------------------------------
31 def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, docbook_gen, h, c):
32 self.docbook_gen = docbook_gen
33 self.generate_objmanager = generate_objmanager
37 self.namespace = namespace
38 if len(namespace) > 0:
39 if utils.is_ugly_case(namespace):
40 self.namespace = namespace.replace('_', '')
41 self.ns_upper = namespace.upper() + '_'
42 self.ns_lower = namespace.lower() + '_'
44 self.ns_upper = utils.camel_case_to_uscore(namespace).upper() + '_'
45 self.ns_lower = utils.camel_case_to_uscore(namespace).lower() + '_'
49 self.interface_prefix = interface_prefix
50 self.header_guard = self.h.name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
52 # ----------------------------------------------------------------------------------------------------
54 def generate_intro(self):
56 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
58 ' * The license of this code is the same as for the source it was derived from.\n'
62 self.c.write('#ifdef HAVE_CONFIG_H\n'
63 '# include "config.h"\n'
68 '#include <string.h>\n'
71 self.c.write('#ifdef G_OS_UNIX\n'
72 '# include <gio/gunixfdlist.h>\n'
76 self.c.write('typedef struct\n'
78 ' GDBusArgInfo parent_struct;\n'
79 ' gboolean use_gvariant;\n'
80 '} _ExtendedGDBusArgInfo;\n'
83 self.c.write('typedef struct\n'
85 ' GDBusMethodInfo parent_struct;\n'
86 ' const gchar *signal_name;\n'
87 ' gboolean pass_fdlist;\n'
88 '} _ExtendedGDBusMethodInfo;\n'
91 self.c.write('typedef struct\n'
93 ' GDBusSignalInfo parent_struct;\n'
94 ' const gchar *signal_name;\n'
95 '} _ExtendedGDBusSignalInfo;\n'
98 self.c.write('typedef struct\n'
100 ' GDBusPropertyInfo parent_struct;\n'
101 ' const gchar *hyphen_name;\n'
102 ' gboolean use_gvariant;\n'
103 '} _ExtendedGDBusPropertyInfo;\n'
106 self.c.write('typedef struct\n'
108 ' GDBusInterfaceInfo parent_struct;\n'
109 ' const gchar *hyphen_name;\n'
110 '} _ExtendedGDBusInterfaceInfo;\n'
113 self.c.write('typedef struct\n'
115 ' const _ExtendedGDBusPropertyInfo *info;\n'
117 ' GValue orig_value; /* the value before the change */\n'
118 '} ChangedProperty;\n'
121 '_changed_property_free (ChangedProperty *data)\n'
123 ' g_value_unset (&data->orig_value);\n'
128 self.c.write('static gboolean\n'
129 '_g_strv_equal0 (gchar **a, gchar **b)\n'
131 ' gboolean ret = FALSE;\n'
133 ' if (a == NULL && b == NULL)\n'
138 ' if (a == NULL || b == NULL)\n'
140 ' if (g_strv_length (a) != g_strv_length (b))\n'
142 ' for (n = 0; a[n] != NULL; n++)\n'
143 ' if (g_strcmp0 (a[n], b[n]) != 0)\n'
151 self.c.write('static gboolean\n'
152 '_g_variant_equal0 (GVariant *a, GVariant *b)\n'
154 ' gboolean ret = FALSE;\n'
155 ' if (a == NULL && b == NULL)\n'
160 ' if (a == NULL || b == NULL)\n'
162 ' ret = g_variant_equal (a, b);\n'
168 # simplified - only supports the types we use
169 self.c.write('G_GNUC_UNUSED static gboolean\n'
170 '_g_value_equal (const GValue *a, const GValue *b)\n'
172 ' gboolean ret = FALSE;\n'
173 ' g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b));\n'
174 ' switch (G_VALUE_TYPE (a))\n'
176 ' case G_TYPE_BOOLEAN:\n'
177 ' ret = (g_value_get_boolean (a) == g_value_get_boolean (b));\n'
179 ' case G_TYPE_UCHAR:\n'
180 ' ret = (g_value_get_uchar (a) == g_value_get_uchar (b));\n'
182 ' case G_TYPE_INT:\n'
183 ' ret = (g_value_get_int (a) == g_value_get_int (b));\n'
185 ' case G_TYPE_UINT:\n'
186 ' ret = (g_value_get_uint (a) == g_value_get_uint (b));\n'
188 ' case G_TYPE_INT64:\n'
189 ' ret = (g_value_get_int64 (a) == g_value_get_int64 (b));\n'
191 ' case G_TYPE_UINT64:\n'
192 ' ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n'
194 ' case G_TYPE_DOUBLE:\n'
196 ' /* Avoid -Wfloat-equal warnings by doing a direct bit compare */\n'
197 ' gdouble da = g_value_get_double (a);\n'
198 ' gdouble db = g_value_get_double (b);\n'
199 ' ret = memcmp (&da, &db, sizeof (gdouble)) == 0;\n'
202 ' case G_TYPE_STRING:\n'
203 ' ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n'
205 ' case G_TYPE_VARIANT:\n'
206 ' ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b));\n'
209 ' if (G_VALUE_TYPE (a) == G_TYPE_STRV)\n'
210 ' ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b));\n'
212 ' g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a)));\n'
220 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
222 ' * The license of this code is the same as for the source it was derived from.\n'
227 '\n'%(config.VERSION, self.header_guard, self.header_guard))
228 self.h.write('#include <gio/gio.h>\n'
233 # ----------------------------------------------------------------------------------------------------
235 def declare_types(self):
236 for i in self.ifaces:
238 self.h.write('/* ------------------------------------------------------------------------ */\n')
239 self.h.write('/* Declarations for %s */\n'%i.name)
242 # First the GInterface
243 self.h.write('#define %sTYPE_%s (%s_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
244 self.h.write('#define %s%s(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_%s, %s))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
245 self.h.write('#define %sIS_%s(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_%s))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
246 self.h.write('#define %s%s_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), %sTYPE_%s, %sIface))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
248 self.h.write('struct _%s;\n'%(i.camel_name))
249 self.h.write('typedef struct _%s %s;\n'%(i.camel_name, i.camel_name))
250 self.h.write('typedef struct _%sIface %sIface;\n'%(i.camel_name, i.camel_name))
252 self.h.write('struct _%sIface\n'%(i.camel_name))
254 self.h.write(' GTypeInterface parent_iface;\n')
256 function_pointers = {}
259 if len(i.methods) > 0:
263 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
265 key = (m.since, '_method_%s'%m.name_lower)
266 value = ' gboolean (*handle_%s) (\n'%(m.name_lower)
267 value += ' %s *object,\n'%(i.camel_name)
268 value += ' GDBusMethodInvocation *invocation'%()
270 value += ',\n GUnixFDList *fd_list'
272 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
274 function_pointers[key] = value
277 if len(i.signals) > 0:
280 key = (s.since, '_signal_%s'%s.name_lower)
281 value = ' void (*%s) (\n'%(s.name_lower)
282 value += ' %s *object'%(i.camel_name)
284 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
286 function_pointers[key] = value
288 # vfuncs for properties
289 if len(i.properties) > 0:
291 for p in i.properties:
292 key = (p.since, '_prop_get_%s'%p.name_lower)
293 value = ' %s (*get_%s) (%s *object);\n\n'%(p.arg.ctype_in, p.name_lower, i.camel_name)
294 function_pointers[key] = value
296 # Sort according to @since tag, then name.. this ensures
297 # that the function pointers don't change order assuming
298 # judicious use of @since
300 # Also use a proper version comparison function so e.g.
301 # 10.0 comes after 2.0.
303 # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
305 for key in sorted(function_pointers.keys(), key=utils.version_cmp_key):
306 self.h.write('%s'%function_pointers[key])
310 self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
312 self.h.write('GDBusInterfaceInfo *%s_interface_info (void);\n'%(i.name_lower))
313 self.h.write('guint %s_override_properties (GObjectClass *klass, guint property_id_begin);\n'%(i.name_lower))
316 # Then method call completion functions
317 if len(i.methods) > 0:
319 self.h.write('/* D-Bus method call completion functions: */\n')
322 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
325 self.h.write('G_GNUC_DEPRECATED ')
326 self.h.write('void %s_complete_%s (\n'
328 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
330 self.h.write(',\n GUnixFDList *fd_list')
332 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
337 # Then signal emission functions
338 if len(i.signals) > 0:
340 self.h.write('/* D-Bus signal emissions functions: */\n')
343 self.h.write('G_GNUC_DEPRECATED ')
344 self.h.write('void %s_emit_%s (\n'
345 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
347 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
352 # Then method call declarations
353 if len(i.methods) > 0:
355 self.h.write('/* D-Bus method calls: */\n')
358 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
362 self.h.write('G_GNUC_DEPRECATED ')
363 self.h.write('void %s_call_%s (\n'
364 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
366 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
368 self.h.write(',\n GUnixFDList *fd_list')
370 ' GCancellable *cancellable,\n'
371 ' GAsyncReadyCallback callback,\n'
372 ' gpointer user_data);\n')
376 self.h.write('G_GNUC_DEPRECATED ')
377 self.h.write('gboolean %s_call_%s_finish (\n'
378 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
380 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
382 self.h.write(',\n GUnixFDList **out_fd_list')
384 ' GAsyncResult *res,\n'
385 ' GError **error);\n')
389 self.h.write('G_GNUC_DEPRECATED ')
390 self.h.write('gboolean %s_call_%s_sync (\n'
391 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
393 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
395 self.h.write(',\n GUnixFDList *fd_list')
397 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
399 self.h.write(',\n GUnixFDList **out_fd_list')
401 ' GCancellable *cancellable,\n'
402 ' GError **error);\n')
406 # Then the property accessor declarations
407 if len(i.properties) > 0:
409 self.h.write('/* D-Bus property accessors: */\n')
410 for p in i.properties:
413 self.h.write('G_GNUC_DEPRECATED ')
414 self.h.write('%s%s_get_%s (%s *object);\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
415 if p.arg.free_func != None:
417 self.h.write('G_GNUC_DEPRECATED ')
418 self.h.write('%s%s_dup_%s (%s *object);\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name))
421 self.h.write('G_GNUC_DEPRECATED ')
422 self.h.write('void %s_set_%s (%s *object, %svalue);\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
427 self.h.write('/* ---- */\n')
429 self.h.write('#define %sTYPE_%s_PROXY (%s_proxy_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
430 self.h.write('#define %s%s_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_%s_PROXY, %sProxy))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
431 self.h.write('#define %s%s_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_%s_PROXY, %sProxyClass))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
432 self.h.write('#define %s%s_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_%s_PROXY, %sProxyClass))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
433 self.h.write('#define %sIS_%s_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_%s_PROXY))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
434 self.h.write('#define %sIS_%s_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_%s_PROXY))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
436 self.h.write('typedef struct _%sProxy %sProxy;\n'%(i.camel_name, i.camel_name))
437 self.h.write('typedef struct _%sProxyClass %sProxyClass;\n'%(i.camel_name, i.camel_name))
438 self.h.write('typedef struct _%sProxyPrivate %sProxyPrivate;\n'%(i.camel_name, i.camel_name))
440 self.h.write('struct _%sProxy\n'%(i.camel_name))
442 self.h.write(' /*< private >*/\n')
443 self.h.write(' GDBusProxy parent_instance;\n')
444 self.h.write(' %sProxyPrivate *priv;\n'%(i.camel_name))
447 self.h.write('struct _%sProxyClass\n'%(i.camel_name))
449 self.h.write(' GDBusProxyClass parent_class;\n')
452 self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
454 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
455 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sProxy, g_object_unref)\n' % (i.camel_name))
456 self.h.write('#endif\n')
460 self.h.write('G_GNUC_DEPRECATED ')
461 self.h.write('void %s_proxy_new (\n'
462 ' GDBusConnection *connection,\n'
463 ' GDBusProxyFlags flags,\n'
464 ' const gchar *name,\n'
465 ' const gchar *object_path,\n'
466 ' GCancellable *cancellable,\n'
467 ' GAsyncReadyCallback callback,\n'
468 ' gpointer user_data);\n'
471 self.h.write('G_GNUC_DEPRECATED ')
472 self.h.write('%s *%s_proxy_new_finish (\n'
473 ' GAsyncResult *res,\n'
474 ' GError **error);\n'
475 %(i.camel_name, i.name_lower))
477 self.h.write('G_GNUC_DEPRECATED ')
478 self.h.write('%s *%s_proxy_new_sync (\n'
479 ' GDBusConnection *connection,\n'
480 ' GDBusProxyFlags flags,\n'
481 ' const gchar *name,\n'
482 ' const gchar *object_path,\n'
483 ' GCancellable *cancellable,\n'
484 ' GError **error);\n'
485 %(i.camel_name, i.name_lower))
488 self.h.write('G_GNUC_DEPRECATED ')
489 self.h.write('void %s_proxy_new_for_bus (\n'
490 ' GBusType bus_type,\n'
491 ' GDBusProxyFlags flags,\n'
492 ' const gchar *name,\n'
493 ' const gchar *object_path,\n'
494 ' GCancellable *cancellable,\n'
495 ' GAsyncReadyCallback callback,\n'
496 ' gpointer user_data);\n'
499 self.h.write('G_GNUC_DEPRECATED ')
500 self.h.write('%s *%s_proxy_new_for_bus_finish (\n'
501 ' GAsyncResult *res,\n'
502 ' GError **error);\n'
503 %(i.camel_name, i.name_lower))
505 self.h.write('G_GNUC_DEPRECATED ')
506 self.h.write('%s *%s_proxy_new_for_bus_sync (\n'
507 ' GBusType bus_type,\n'
508 ' GDBusProxyFlags flags,\n'
509 ' const gchar *name,\n'
510 ' const gchar *object_path,\n'
511 ' GCancellable *cancellable,\n'
512 ' GError **error);\n'
513 %(i.camel_name, i.name_lower))
518 self.h.write('/* ---- */\n')
520 self.h.write('#define %sTYPE_%s_SKELETON (%s_skeleton_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
521 self.h.write('#define %s%s_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_%s_SKELETON, %sSkeleton))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
522 self.h.write('#define %s%s_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_%s_SKELETON, %sSkeletonClass))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
523 self.h.write('#define %s%s_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_%s_SKELETON, %sSkeletonClass))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
524 self.h.write('#define %sIS_%s_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_%s_SKELETON))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
525 self.h.write('#define %sIS_%s_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_%s_SKELETON))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
527 self.h.write('typedef struct _%sSkeleton %sSkeleton;\n'%(i.camel_name, i.camel_name))
528 self.h.write('typedef struct _%sSkeletonClass %sSkeletonClass;\n'%(i.camel_name, i.camel_name))
529 self.h.write('typedef struct _%sSkeletonPrivate %sSkeletonPrivate;\n'%(i.camel_name, i.camel_name))
531 self.h.write('struct _%sSkeleton\n'%(i.camel_name))
533 self.h.write(' /*< private >*/\n')
534 self.h.write(' GDBusInterfaceSkeleton parent_instance;\n')
535 self.h.write(' %sSkeletonPrivate *priv;\n'%(i.camel_name))
538 self.h.write('struct _%sSkeletonClass\n'%(i.camel_name))
540 self.h.write(' GDBusInterfaceSkeletonClass parent_class;\n')
543 self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
545 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
546 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sSkeleton, g_object_unref)\n' % (i.camel_name))
547 self.h.write('#endif\n')
550 self.h.write('G_GNUC_DEPRECATED ')
551 self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
555 # Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
556 if self.generate_objmanager:
558 self.h.write('/* ---- */\n')
560 self.h.write('#define %sTYPE_OBJECT (%sobject_get_type ())\n'%(self.ns_upper, self.ns_lower))
561 self.h.write('#define %sOBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
562 self.h.write('#define %sIS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT))\n'%(self.ns_upper, self.ns_upper))
563 self.h.write('#define %sOBJECT_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
565 self.h.write('struct _%sObject;\n'%(self.namespace))
566 self.h.write('typedef struct _%sObject %sObject;\n'%(self.namespace, self.namespace))
567 self.h.write('typedef struct _%sObjectIface %sObjectIface;\n'%(self.namespace, self.namespace))
569 self.h.write('struct _%sObjectIface\n'%(self.namespace))
571 ' GTypeInterface parent_iface;\n'
574 self.h.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
577 for i in self.ifaces:
579 self.h.write('G_GNUC_DEPRECATED ')
580 self.h.write ('%s *%sobject_get_%s (%sObject *object);\n'
581 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
582 for i in self.ifaces:
584 self.h.write('G_GNUC_DEPRECATED ')
585 self.h.write ('%s *%sobject_peek_%s (%sObject *object);\n'
586 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
588 self.h.write('#define %sTYPE_OBJECT_PROXY (%sobject_proxy_get_type ())\n'%(self.ns_upper, self.ns_lower))
589 self.h.write('#define %sOBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT_PROXY, %sObjectProxy))\n'%(self.ns_upper, self.ns_upper, self.namespace))
590 self.h.write('#define %sOBJECT_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_OBJECT_PROXY, %sObjectProxyClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
591 self.h.write('#define %sOBJECT_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_OBJECT_PROXY, %sObjectProxyClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
592 self.h.write('#define %sIS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
593 self.h.write('#define %sIS_OBJECT_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
595 self.h.write('typedef struct _%sObjectProxy %sObjectProxy;\n'%(self.namespace, self.namespace))
596 self.h.write('typedef struct _%sObjectProxyClass %sObjectProxyClass;\n'%(self.namespace, self.namespace))
597 self.h.write('typedef struct _%sObjectProxyPrivate %sObjectProxyPrivate;\n'%(self.namespace, self.namespace))
599 self.h.write('struct _%sObjectProxy\n'%(self.namespace))
601 self.h.write(' /*< private >*/\n')
602 self.h.write(' GDBusObjectProxy parent_instance;\n')
603 self.h.write(' %sObjectProxyPrivate *priv;\n'%(self.namespace))
606 self.h.write('struct _%sObjectProxyClass\n'%(self.namespace))
608 self.h.write(' GDBusObjectProxyClass parent_class;\n')
611 self.h.write('GType %sobject_proxy_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
613 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
614 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectProxy, g_object_unref)\n' % (self.namespace))
615 self.h.write('#endif\n')
617 self.h.write('%sObjectProxy *%sobject_proxy_new (GDBusConnection *connection, const gchar *object_path);\n'%(self.namespace, self.ns_lower))
619 self.h.write('#define %sTYPE_OBJECT_SKELETON (%sobject_skeleton_get_type ())\n'%(self.ns_upper, self.ns_lower))
620 self.h.write('#define %sOBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT_SKELETON, %sObjectSkeleton))\n'%(self.ns_upper, self.ns_upper, self.namespace))
621 self.h.write('#define %sOBJECT_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_OBJECT_SKELETON, %sObjectSkeletonClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
622 self.h.write('#define %sOBJECT_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_OBJECT_SKELETON, %sObjectSkeletonClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
623 self.h.write('#define %sIS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
624 self.h.write('#define %sIS_OBJECT_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
626 self.h.write('typedef struct _%sObjectSkeleton %sObjectSkeleton;\n'%(self.namespace, self.namespace))
627 self.h.write('typedef struct _%sObjectSkeletonClass %sObjectSkeletonClass;\n'%(self.namespace, self.namespace))
628 self.h.write('typedef struct _%sObjectSkeletonPrivate %sObjectSkeletonPrivate;\n'%(self.namespace, self.namespace))
630 self.h.write('struct _%sObjectSkeleton\n'%(self.namespace))
632 self.h.write(' /*< private >*/\n')
633 self.h.write(' GDBusObjectSkeleton parent_instance;\n')
634 self.h.write(' %sObjectSkeletonPrivate *priv;\n'%(self.namespace))
637 self.h.write('struct _%sObjectSkeletonClass\n'%(self.namespace))
639 self.h.write(' GDBusObjectSkeletonClass parent_class;\n')
642 self.h.write('GType %sobject_skeleton_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
644 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
645 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectSkeleton, g_object_unref)\n' % (self.namespace))
646 self.h.write('#endif\n')
648 self.h.write('%sObjectSkeleton *%sobject_skeleton_new (const gchar *object_path);\n'
649 %(self.namespace, self.ns_lower))
650 for i in self.ifaces:
652 self.h.write('G_GNUC_DEPRECATED ')
653 self.h.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_);\n'
654 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
657 self.h.write('/* ---- */\n')
659 self.h.write('#define %sTYPE_OBJECT_MANAGER_CLIENT (%sobject_manager_client_get_type ())\n'%(self.ns_upper, self.ns_lower))
660 self.h.write('#define %sOBJECT_MANAGER_CLIENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT_MANAGER_CLIENT, %sObjectManagerClient))\n'%(self.ns_upper, self.ns_upper, self.namespace))
661 self.h.write('#define %sOBJECT_MANAGER_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_OBJECT_MANAGER_CLIENT, %sObjectManagerClientClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
662 self.h.write('#define %sOBJECT_MANAGER_CLIENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_OBJECT_MANAGER_CLIENT, %sObjectManagerClientClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
663 self.h.write('#define %sIS_OBJECT_MANAGER_CLIENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_MANAGER_CLIENT))\n'%(self.ns_upper, self.ns_upper))
664 self.h.write('#define %sIS_OBJECT_MANAGER_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_OBJECT_MANAGER_CLIENT))\n'%(self.ns_upper, self.ns_upper))
666 self.h.write('typedef struct _%sObjectManagerClient %sObjectManagerClient;\n'%(self.namespace, self.namespace))
667 self.h.write('typedef struct _%sObjectManagerClientClass %sObjectManagerClientClass;\n'%(self.namespace, self.namespace))
668 self.h.write('typedef struct _%sObjectManagerClientPrivate %sObjectManagerClientPrivate;\n'%(self.namespace, self.namespace))
670 self.h.write('struct _%sObjectManagerClient\n'%(self.namespace))
672 self.h.write(' /*< private >*/\n')
673 self.h.write(' GDBusObjectManagerClient parent_instance;\n')
674 self.h.write(' %sObjectManagerClientPrivate *priv;\n'%(self.namespace))
677 self.h.write('struct _%sObjectManagerClientClass\n'%(self.namespace))
679 self.h.write(' GDBusObjectManagerClientClass parent_class;\n')
682 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
683 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectManagerClient, g_object_unref)\n' % (self.namespace))
684 self.h.write('#endif\n')
686 self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
688 self.h.write('GType %sobject_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data);\n'%(self.ns_lower))
690 self.h.write('void %sobject_manager_client_new (\n'
691 ' GDBusConnection *connection,\n'
692 ' GDBusObjectManagerClientFlags flags,\n'
693 ' const gchar *name,\n'
694 ' const gchar *object_path,\n'
695 ' GCancellable *cancellable,\n'
696 ' GAsyncReadyCallback callback,\n'
697 ' gpointer user_data);\n'
699 self.h.write('GDBusObjectManager *%sobject_manager_client_new_finish (\n'
700 ' GAsyncResult *res,\n'
701 ' GError **error);\n'
703 self.h.write('GDBusObjectManager *%sobject_manager_client_new_sync (\n'
704 ' GDBusConnection *connection,\n'
705 ' GDBusObjectManagerClientFlags flags,\n'
706 ' const gchar *name,\n'
707 ' const gchar *object_path,\n'
708 ' GCancellable *cancellable,\n'
709 ' GError **error);\n'
712 self.h.write('void %sobject_manager_client_new_for_bus (\n'
713 ' GBusType bus_type,\n'
714 ' GDBusObjectManagerClientFlags flags,\n'
715 ' const gchar *name,\n'
716 ' const gchar *object_path,\n'
717 ' GCancellable *cancellable,\n'
718 ' GAsyncReadyCallback callback,\n'
719 ' gpointer user_data);\n'
721 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_finish (\n'
722 ' GAsyncResult *res,\n'
723 ' GError **error);\n'
725 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_sync (\n'
726 ' GBusType bus_type,\n'
727 ' GDBusObjectManagerClientFlags flags,\n'
728 ' const gchar *name,\n'
729 ' const gchar *object_path,\n'
730 ' GCancellable *cancellable,\n'
731 ' GError **error);\n'
735 # ----------------------------------------------------------------------------------------------------
737 def generate_outro(self):
741 '#endif /* __%s__ */\n'%(self.header_guard))
743 # ----------------------------------------------------------------------------------------------------
745 def generate_annotations(self, prefix, annotations):
746 if annotations == None:
750 for a in annotations:
751 #self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
753 # skip internal annotations
754 if a.key.startswith('org.gtk.GDBus'):
757 self.c.write('static const GDBusAnnotationInfo %s_%d =\n'
761 ' (gchar *) "%s",\n'%(prefix, n, a.key, a.value))
762 if len(a.annotations) == 0:
763 self.c.write(' NULL\n')
765 self.c.write(' (GDBusAnnotationInfo **) &%s_%d_pointers\n'%(prefix, n))
771 self.c.write('static const GDBusAnnotationInfo * const %s_pointers[] =\n'
774 for a in annotations:
775 if a.key.startswith('org.gtk.GDBus'):
777 self.c.write(' &%s_%d,\n'%(prefix, m))
779 self.c.write(' NULL\n'
784 def generate_args(self, prefix, args):
786 num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
788 self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
793 ' (gchar *) "%s",\n'%(prefix, a.name, a.name, a.signature))
795 self.c.write(' NULL\n')
797 self.c.write(' (GDBusAnnotationInfo **) &%s_arg_%s_annotation_info_pointers\n'%(prefix, a.name))
798 self.c.write(' },\n')
799 if not utils.lookup_annotation(a.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
800 self.c.write(' FALSE\n')
802 self.c.write(' TRUE\n')
807 self.c.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
810 self.c.write(' &%s_%s,\n'%(prefix, a.name))
811 self.c.write(' NULL\n'
815 def generate_introspection_for_interface(self, i):
816 self.c.write('/* ---- Introspection data for %s ---- */\n'
819 if len(i.methods) > 0:
822 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
824 self.generate_args('_%s_method_info_%s_IN_ARG'%(i.name_lower, m.name_lower), m.in_args)
825 self.generate_args('_%s_method_info_%s_OUT_ARG'%(i.name_lower, m.name_lower), m.out_args)
827 num_anno = self.generate_annotations('_%s_method_%s_annotation_info'%(i.name_lower, m.name_lower), m.annotations)
829 self.c.write('static const _ExtendedGDBusMethodInfo _%s_method_info_%s =\n'
833 ' (gchar *) "%s",\n'%(i.name_lower, m.name_lower, m.name))
834 if len(m.in_args) == 0:
835 self.c.write(' NULL,\n')
837 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_IN_ARG_pointers,\n'%(i.name_lower, m.name_lower))
838 if len(m.out_args) == 0:
839 self.c.write(' NULL,\n')
841 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_OUT_ARG_pointers,\n'%(i.name_lower, m.name_lower))
843 self.c.write(' NULL\n')
845 self.c.write(' (GDBusAnnotationInfo **) &_%s_method_%s_annotation_info_pointers\n'%(i.name_lower, m.name_lower))
849 %(m.name_hyphen, 'TRUE' if unix_fd else 'FALSE'))
853 self.c.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] =\n'
854 '{\n'%(i.name_lower))
856 self.c.write(' &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
857 self.c.write(' NULL\n'
863 if len(i.signals) > 0:
865 self.generate_args('_%s_signal_info_%s_ARG'%(i.name_lower, s.name_lower), s.args)
867 num_anno = self.generate_annotations('_%s_signal_%s_annotation_info'%(i.name_lower, s.name_lower), s.annotations)
868 self.c.write('static const _ExtendedGDBusSignalInfo _%s_signal_info_%s =\n'
872 ' (gchar *) "%s",\n'%(i.name_lower, s.name_lower, s.name))
874 self.c.write(' NULL,\n')
876 self.c.write(' (GDBusArgInfo **) &_%s_signal_info_%s_ARG_pointers,\n'%(i.name_lower, s.name_lower))
878 self.c.write(' NULL\n')
880 self.c.write(' (GDBusAnnotationInfo **) &_%s_signal_%s_annotation_info_pointers\n'%(i.name_lower, s.name_lower))
887 self.c.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
888 '{\n'%(i.name_lower))
890 self.c.write(' &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
891 self.c.write(' NULL\n'
897 if len(i.properties) > 0:
898 for p in i.properties:
899 if p.readable and p.writable:
900 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
902 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE'
904 access = 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
906 access = 'G_DBUS_PROPERTY_INFO_FLAGS_NONE'
907 num_anno = self.generate_annotations('_%s_property_%s_annotation_info'%(i.name_lower, p.name_lower), p.annotations)
908 self.c.write('static const _ExtendedGDBusPropertyInfo _%s_property_info_%s =\n'
914 ' %s,\n'%(i.name_lower, p.name_lower, p.name, p.arg.signature, access))
916 self.c.write(' NULL\n')
918 self.c.write(' (GDBusAnnotationInfo **) &_%s_property_%s_annotation_info_pointers\n'%(i.name_lower, p.name_lower))
922 if not utils.lookup_annotation(p.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
923 self.c.write(' FALSE\n')
925 self.c.write(' TRUE\n')
929 self.c.write('static const _ExtendedGDBusPropertyInfo * const _%s_property_info_pointers[] =\n'
930 '{\n'%(i.name_lower))
931 for p in i.properties:
932 self.c.write(' &_%s_property_info_%s,\n'%(i.name_lower, p.name_lower))
933 self.c.write(' NULL\n'
937 num_anno = self.generate_annotations('_%s_annotation_info'%(i.name_lower), i.annotations)
938 self.c.write('static const _ExtendedGDBusInterfaceInfo _%s_interface_info =\n'
942 ' (gchar *) "%s",\n'%(i.name_lower, i.name))
943 if len(i.methods) == 0:
944 self.c.write(' NULL,\n')
946 self.c.write(' (GDBusMethodInfo **) &_%s_method_info_pointers,\n'%(i.name_lower))
947 if len(i.signals) == 0:
948 self.c.write(' NULL,\n')
950 self.c.write(' (GDBusSignalInfo **) &_%s_signal_info_pointers,\n'%(i.name_lower))
951 if len(i.properties) == 0:
952 self.c.write(' NULL,\n')
954 self.c.write(' (GDBusPropertyInfo **) &_%s_property_info_pointers,\n'%(i.name_lower))
956 self.c.write(' NULL\n')
958 self.c.write(' (GDBusAnnotationInfo **) &_%s_annotation_info_pointers\n'%(i.name_lower))
965 self.c.write(self.docbook_gen.expand(
967 ' * %s_interface_info:\n'
969 ' * Gets a machine-readable description of the #%s D-Bus interface.\n'
971 ' * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free.\n'
972 %(i.name_lower, i.name), False))
973 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
974 self.c.write('GDBusInterfaceInfo *\n'
975 '%s_interface_info (void)\n'
977 ' return (GDBusInterfaceInfo *) &_%s_interface_info.parent_struct;\n'
979 '\n'%(i.name_lower, i.name_lower))
981 self.c.write(self.docbook_gen.expand(
983 ' * %s_override_properties:\n'
984 ' * @klass: The class structure for a #GObject<!-- -->-derived class.\n'
985 ' * @property_id_begin: The property id to assign to the first overridden property.\n'
987 ' * Overrides all #GObject properties in the #%s interface for a concrete class.\n'
988 ' * The properties are overridden in the order they are defined.\n'
990 ' * Returns: The last property id.\n'
991 %(i.name_lower, i.camel_name), False))
992 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
993 self.c.write('guint\n'
994 '%s_override_properties (GObjectClass *klass, guint property_id_begin)\n'
995 '{\n'%(i.name_lower))
996 for p in i.properties:
997 self.c.write (' g_object_class_override_property (klass, property_id_begin++, "%s");\n'%(p.name_hyphen))
998 self.c.write(' return property_id_begin - 1;\n'
1003 # ----------------------------------------------------------------------------------------------------
1005 def generate_interface(self, i):
1008 self.c.write(self.docbook_gen.expand(
1012 ' * Abstract interface type for the D-Bus interface #%s.\n'
1013 %(i.camel_name, i.name), False))
1014 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1017 self.c.write(self.docbook_gen.expand(
1020 ' * @parent_iface: The parent interface.\n'
1021 %(i.camel_name), False))
1024 if len(i.methods) > 0:
1026 key = (m.since, '_method_%s'%m.name_lower)
1027 value = '@handle_%s: '%(m.name_lower)
1028 value += 'Handler for the #%s::handle-%s signal.'%(i.camel_name, m.name_hyphen)
1029 doc_bits[key] = value
1030 if len(i.signals) > 0:
1032 key = (s.since, '_signal_%s'%s.name_lower)
1033 value = '@%s: '%(s.name_lower)
1034 value += 'Handler for the #%s::%s signal.'%(i.camel_name, s.name_hyphen)
1035 doc_bits[key] = value
1036 if len(i.properties) > 0:
1037 for p in i.properties:
1038 key = (p.since, '_prop_get_%s'%p.name_lower)
1039 value = '@get_%s: '%(p.name_lower)
1040 value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
1041 doc_bits[key] = value
1042 for key in sorted(doc_bits.keys(), key=utils.version_cmp_key):
1043 self.c.write(' * %s\n'%doc_bits[key])
1045 self.c.write(self.docbook_gen.expand(
1047 ' * Virtual table for the D-Bus interface #%s.\n'
1049 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1052 self.c.write('typedef %sIface %sInterface;\n'%(i.camel_name, i.camel_name))
1053 self.c.write('G_DEFINE_INTERFACE (%s, %s, G_TYPE_OBJECT);\n'%(i.camel_name, i.name_lower))
1056 self.c.write('static void\n'
1057 '%s_default_init (%sIface *iface)\n'
1058 '{\n'%(i.name_lower, i.camel_name));
1060 if len(i.methods) > 0:
1061 self.c.write(' /* GObject signals for incoming D-Bus method calls: */\n')
1064 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1066 self.c.write(self.docbook_gen.expand(
1068 ' * %s::handle-%s:\n'
1069 ' * @object: A #%s.\n'
1070 ' * @invocation: A #GDBusMethodInvocation.\n'
1071 %(i.camel_name, m.name_hyphen, i.camel_name), False))
1073 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1075 self.c.write (' * @arg_%s: Argument passed by remote caller.\n'%(a.name))
1076 self.c.write(self.docbook_gen.expand(
1078 ' * Signal emitted when a remote caller is invoking the %s.%s() D-Bus method.\n'
1080 ' * If a signal handler returns %%TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call %s_complete_%s() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %%G_DBUS_ERROR_UNKNOWN_METHOD error is returned.\n'
1082 ' * Returns: %%TRUE if the invocation was handled, %%FALSE to let other signal handlers run.\n'
1083 %(i.name, m.name, i.name_lower, m.name_lower), False))
1084 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 2)
1089 self.c.write(' g_signal_new ("handle-%s",\n'
1090 ' G_TYPE_FROM_INTERFACE (iface),\n'
1091 ' G_SIGNAL_RUN_LAST,\n'
1092 ' G_STRUCT_OFFSET (%sIface, handle_%s),\n'
1093 ' g_signal_accumulator_true_handled,\n'
1094 ' NULL,\n' # accu_data
1095 ' g_cclosure_marshal_generic,\n'
1096 ' G_TYPE_BOOLEAN,\n'
1098 ' G_TYPE_DBUS_METHOD_INVOCATION'
1099 %(m.name_hyphen, i.camel_name, m.name_lower, len(m.in_args) + extra_args))
1101 self.c.write(', G_TYPE_UNIX_FD_LIST')
1103 self.c.write (', %s'%(a.gtype))
1104 self.c.write(');\n')
1107 if len(i.signals) > 0:
1108 self.c.write(' /* GObject signals for received D-Bus signals: */\n')
1110 self.c.write(self.docbook_gen.expand(
1113 ' * @object: A #%s.\n'
1114 %(i.camel_name, s.name_hyphen, i.camel_name), False))
1116 self.c.write (' * @arg_%s: Argument.\n'%(a.name))
1117 self.c.write(self.docbook_gen.expand(
1119 ' * On the client-side, this signal is emitted whenever the D-Bus signal #%s::%s is received.\n'
1121 ' * On the service-side, this signal can be used with e.g. g_signal_emit_by_name() to make the object emit the D-Bus signal.\n'
1122 %(i.name, s.name), False))
1123 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 2)
1124 self.c.write(' g_signal_new ("%s",\n'
1125 ' G_TYPE_FROM_INTERFACE (iface),\n'
1126 ' G_SIGNAL_RUN_LAST,\n'
1127 ' G_STRUCT_OFFSET (%sIface, %s),\n'
1128 ' NULL,\n' # accumulator
1129 ' NULL,\n' # accu_data
1130 ' g_cclosure_marshal_generic,\n'
1133 %(s.name_hyphen, i.camel_name, s.name_lower, len(s.args)))
1135 self.c.write (', %s'%(a.gtype))
1136 self.c.write(');\n')
1139 if len(i.properties) > 0:
1140 self.c.write(' /* GObject properties for D-Bus properties: */\n')
1141 for p in i.properties:
1142 if p.readable and p.writable:
1143 hint = 'Since the D-Bus property for this #GObject property is both readable and writable, it is meaningful to both read from it and write to it on both the service- and client-side.'
1145 hint = 'Since the D-Bus property for this #GObject property is readable but not writable, it is meaningful to read from it on both the client- and service-side. It is only meaningful, however, to write to it on the service-side.'
1147 hint = 'Since the D-Bus property for this #GObject property is writable but not readable, it is meaningful to write to it on both the client- and service-side. It is only meaningful, however, to read from it on the service-side.'
1149 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1150 self.c.write(self.docbook_gen.expand(
1154 ' * Represents the D-Bus property #%s:%s.\n'
1157 %(i.camel_name, p.name_hyphen, i.name, p.name, hint), False))
1158 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 2)
1159 self.c.write(' g_object_interface_install_property (iface,\n')
1160 if p.arg.gtype == 'G_TYPE_VARIANT':
1161 s = 'g_param_spec_variant ("%s", "%s", "%s", G_VARIANT_TYPE ("%s"), NULL'%(p.name_hyphen, p.name, p.name, p.arg.signature)
1162 elif p.arg.signature == 'b':
1163 s = 'g_param_spec_boolean ("%s", "%s", "%s", FALSE'%(p.name_hyphen, p.name, p.name)
1164 elif p.arg.signature == 'y':
1165 s = 'g_param_spec_uchar ("%s", "%s", "%s", 0, 255, 0'%(p.name_hyphen, p.name, p.name)
1166 elif p.arg.signature == 'n':
1167 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT16, G_MAXINT16, 0'%(p.name_hyphen, p.name, p.name)
1168 elif p.arg.signature == 'q':
1169 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT16, 0'%(p.name_hyphen, p.name, p.name)
1170 elif p.arg.signature == 'i':
1171 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT32, G_MAXINT32, 0'%(p.name_hyphen, p.name, p.name)
1172 elif p.arg.signature == 'u':
1173 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT32, 0'%(p.name_hyphen, p.name, p.name)
1174 elif p.arg.signature == 'x':
1175 s = 'g_param_spec_int64 ("%s", "%s", "%s", G_MININT64, G_MAXINT64, 0'%(p.name_hyphen, p.name, p.name)
1176 elif p.arg.signature == 't':
1177 s = 'g_param_spec_uint64 ("%s", "%s", "%s", 0, G_MAXUINT64, 0'%(p.name_hyphen, p.name, p.name)
1178 elif p.arg.signature == 'd':
1179 s = 'g_param_spec_double ("%s", "%s", "%s", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0'%(p.name_hyphen, p.name, p.name)
1180 elif p.arg.signature == 's':
1181 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1182 elif p.arg.signature == 'o':
1183 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1184 elif p.arg.signature == 'g':
1185 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1186 elif p.arg.signature == 'ay':
1187 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1188 elif p.arg.signature == 'as':
1189 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1190 elif p.arg.signature == 'ao':
1191 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1192 elif p.arg.signature == 'aay':
1193 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1195 raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
1196 self.c.write(' %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
1202 # ----------------------------------------------------------------------------------------------------
1204 def generate_property_accessors(self, i):
1205 for p in i.properties:
1207 if p.readable and p.writable:
1208 hint = 'Since this D-Bus property is both readable and writable, it is meaningful to use this function on both the client- and service-side.'
1210 hint = 'Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.'
1212 hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
1214 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1215 self.c.write(self.docbook_gen.expand(
1217 ' * %s_get_%s: (skip)\n'
1218 ' * @object: A #%s.\n'
1220 ' * Gets the value of the #%s:%s D-Bus property.\n'
1224 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1225 if p.arg.free_func != None:
1226 self.c.write(' * <warning>The returned value is only valid until the property changes so on the client-side it is only safe to use this function on the thread where @object was constructed. Use %s_dup_%s() if on another thread.</warning>\n'
1228 ' * Returns: (transfer none): The property value or %%NULL if the property is not set. Do not free the returned value, it belongs to @object.\n'
1229 %(i.name_lower, p.name_lower))
1231 self.c.write(' * Returns: The property value.\n')
1232 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1234 '%s_get_%s (%s *object)\n'
1235 '{\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
1236 self.c.write(' return %s%s_GET_IFACE (object)->get_%s (object);\n'%(i.ns_upper, i.name_upper, p.name_lower))
1239 if p.arg.free_func != None:
1241 self.c.write(self.docbook_gen.expand(
1243 ' * %s_dup_%s: (skip)\n'
1244 ' * @object: A #%s.\n'
1246 ' * Gets a copy of the #%s:%s D-Bus property.\n'
1250 ' * Returns: (transfer full): The property value or %%NULL if the property is not set. The returned value should be freed with %s().\n'
1251 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint, p.arg.free_func), False))
1252 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1254 '%s_dup_%s (%s *object)\n'
1256 ' %svalue;\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in_dup))
1257 self.c.write(' g_object_get (G_OBJECT (object), "%s", &value, NULL);\n'%(p.name_hyphen))
1258 self.c.write(' return value;\n')
1263 if p.readable and p.writable:
1264 hint = 'Since this D-Bus property is both readable and writable, it is meaningful to use this function on both the client- and service-side.'
1266 hint = 'Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.'
1268 hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
1270 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1271 self.c.write(self.docbook_gen.expand(
1273 ' * %s_set_%s: (skip)\n'
1274 ' * @object: A #%s.\n'
1275 ' * @value: The value to set.\n'
1277 ' * Sets the #%s:%s D-Bus property to @value.\n'
1280 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1281 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1282 self.c.write('void\n'
1283 '%s_set_%s (%s *object, %svalue)\n'
1284 '{\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
1285 self.c.write(' g_object_set (G_OBJECT (object), "%s", value, NULL);\n'%(p.name_hyphen))
1289 # ---------------------------------------------------------------------------------------------------
1291 def generate_signal_emitters(self, i):
1293 self.c.write(self.docbook_gen.expand(
1296 ' * @object: A #%s.\n'
1297 %(i.name_lower, s.name_lower, i.camel_name), False))
1299 self.c.write(' * @arg_%s: Argument to pass with the signal.\n'%(a.name))
1300 self.c.write(self.docbook_gen.expand(
1302 ' * Emits the #%s::%s D-Bus signal.\n'
1303 %(i.name, s.name), False))
1304 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 0)
1305 self.c.write('void\n'
1307 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
1309 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1312 ' g_signal_emit_by_name (object, "%s"'%(s.name_hyphen))
1314 self.c.write(', arg_%s'%a.name)
1315 self.c.write(');\n')
1319 # ---------------------------------------------------------------------------------------------------
1321 def generate_method_calls(self, i):
1324 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1327 self.c.write('/**\n'
1329 ' * @proxy: A #%sProxy.\n'
1330 %(i.name_lower, m.name_lower, i.camel_name))
1332 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1334 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1335 self.c.write(self.docbook_gen.expand(
1336 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1337 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %%NULL.\n'
1338 ' * @user_data: User data to pass to @callback.\n'
1340 ' * Asynchronously invokes the %s.%s() D-Bus method on @proxy.\n'
1341 ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
1342 ' * You can then call %s_call_%s_finish() to get the result of the operation.\n'
1344 ' * See %s_call_%s_sync() for the synchronous, blocking version of this method.\n'
1345 %(i.name, m.name, i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1346 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1347 self.c.write('void\n'
1349 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1351 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1353 self.c.write(',\n GUnixFDList *fd_list')
1355 ' GCancellable *cancellable,\n'
1356 ' GAsyncReadyCallback callback,\n'
1357 ' gpointer user_data)\n'
1360 self.c.write(' g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy),\n')
1362 self.c.write(' g_dbus_proxy_call (G_DBUS_PROXY (proxy),\n')
1363 self.c.write(' "%s",\n'
1364 ' g_variant_new ("('%(m.name))
1366 self.c.write('%s'%(a.format_in))
1369 self.c.write(',\n arg_%s'%(a.name))
1371 ' G_DBUS_CALL_FLAGS_NONE,\n'
1374 self.c.write(' fd_list,\n')
1375 self.c.write(' cancellable,\n'
1381 self.c.write('/**\n'
1382 ' * %s_call_%s_finish:\n'
1383 ' * @proxy: A #%sProxy.\n'
1384 %(i.name_lower, m.name_lower, i.camel_name))
1385 for a in m.out_args:
1386 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1388 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1389 self.c.write(self.docbook_gen.expand(
1390 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_call_%s().\n'
1391 ' * @error: Return location for error or %%NULL.\n'
1393 ' * Finishes an operation started with %s_call_%s().\n'
1395 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1396 %(i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1397 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1398 self.c.write('gboolean\n'
1399 '%s_call_%s_finish (\n'
1400 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1401 for a in m.out_args:
1402 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1404 self.c.write(',\n GUnixFDList **out_fd_list')
1406 ' GAsyncResult *res,\n'
1407 ' GError **error)\n'
1409 ' GVariant *_ret;\n')
1411 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error);\n')
1413 self.c.write(' _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);\n')
1414 self.c.write(' if (_ret == NULL)\n'
1416 self.c.write(' g_variant_get (_ret,\n'
1418 for a in m.out_args:
1419 self.c.write('%s'%(a.format_out))
1421 for a in m.out_args:
1422 self.c.write(',\n out_%s'%(a.name))
1424 ' g_variant_unref (_ret);\n')
1425 self.c.write('_out:\n'
1426 ' return _ret != NULL;\n'
1432 self.c.write('/**\n'
1433 ' * %s_call_%s_sync:\n'
1434 ' * @proxy: A #%sProxy.\n'
1435 %(i.name_lower, m.name_lower, i.camel_name))
1437 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1439 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1440 for a in m.out_args:
1441 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1443 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1444 self.c.write(self.docbook_gen.expand(
1445 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1446 ' * @error: Return location for error or %%NULL.\n'
1448 ' * Synchronously invokes the %s.%s() D-Bus method on @proxy. The calling thread is blocked until a reply is received.\n'
1450 ' * See %s_call_%s() for the asynchronous version of this method.\n'
1452 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1453 %(i.name, m.name, i.name_lower, m.name_lower), False))
1454 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1455 self.c.write('gboolean\n'
1456 '%s_call_%s_sync (\n'
1457 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1459 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1461 self.c.write(',\n GUnixFDList *fd_list')
1462 for a in m.out_args:
1463 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1465 self.c.write(',\n GUnixFDList **out_fd_list')
1467 ' GCancellable *cancellable,\n'
1468 ' GError **error)\n'
1470 ' GVariant *_ret;\n')
1472 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy),\n')
1474 self.c.write(' _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),\n')
1475 self.c.write(' "%s",\n'
1476 ' g_variant_new ("('%(m.name))
1478 self.c.write('%s'%(a.format_in))
1481 self.c.write(',\n arg_%s'%(a.name))
1483 ' G_DBUS_CALL_FLAGS_NONE,\n'
1486 self.c.write(' fd_list,\n'
1488 self.c.write(' cancellable,\n'
1490 ' if (_ret == NULL)\n'
1492 self.c.write(' g_variant_get (_ret,\n'
1494 for a in m.out_args:
1495 self.c.write('%s'%(a.format_out))
1497 for a in m.out_args:
1498 self.c.write(',\n out_%s'%(a.name))
1500 ' g_variant_unref (_ret);\n')
1501 self.c.write('_out:\n'
1502 ' return _ret != NULL;\n'
1506 # ---------------------------------------------------------------------------------------------------
1508 def generate_method_completers(self, i):
1511 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1513 self.c.write('/**\n'
1514 ' * %s_complete_%s:\n'
1515 ' * @object: A #%s.\n'
1516 ' * @invocation: (transfer full): A #GDBusMethodInvocation.\n'
1517 %(i.name_lower, m.name_lower, i.camel_name))
1519 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1520 for a in m.out_args:
1521 self.c.write(' * @%s: Parameter to return.\n'%(a.name))
1522 self.c.write(self.docbook_gen.expand(
1524 ' * Helper function used in service implementations to finish handling invocations of the %s.%s() D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar.\n'
1526 ' * This method will free @invocation, you cannot use it afterwards.\n'
1527 %(i.name, m.name), False))
1528 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1529 self.c.write('void\n'
1530 '%s_complete_%s (\n'
1532 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
1534 self.c.write(',\n GUnixFDList *fd_list')
1535 for a in m.out_args:
1536 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1541 self.c.write(' g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,\n'
1542 ' g_variant_new ("(')
1544 self.c.write(' g_dbus_method_invocation_return_value (invocation,\n'
1545 ' g_variant_new ("(')
1546 for a in m.out_args:
1547 self.c.write('%s'%(a.format_in))
1549 for a in m.out_args:
1550 self.c.write(',\n %s'%(a.name))
1552 self.c.write('),\n fd_list);\n')
1554 self.c.write('));\n')
1558 # ---------------------------------------------------------------------------------------------------
1560 def generate_proxy(self, i):
1562 self.c.write('/* ------------------------------------------------------------------------ */\n'
1565 self.c.write(self.docbook_gen.expand(
1569 ' * The #%sProxy structure contains only private data and should only be accessed using the provided API.\n'
1570 %(i.camel_name, i.camel_name), False))
1571 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1574 self.c.write(self.docbook_gen.expand(
1576 ' * %sProxyClass:\n'
1577 ' * @parent_class: The parent class.\n'
1579 ' * Class structure for #%sProxy.\n'
1580 %(i.camel_name, i.camel_name), False))
1581 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1584 self.c.write('struct _%sProxyPrivate\n'
1590 self.c.write('static void %s_proxy_iface_init (%sIface *iface);\n'
1591 '\n'%(i.name_lower, i.camel_name))
1592 self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
1593 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1594 self.c.write(' G_ADD_PRIVATE (%sProxy)\n'%(i.camel_name))
1595 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1596 self.c.write('#else\n')
1597 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1598 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1599 self.c.write('#endif\n')
1602 self.c.write('static void\n'
1603 '%s_proxy_finalize (GObject *object)\n'
1604 '{\n'%(i.name_lower))
1605 self.c.write(' %sProxy *proxy = %s%s_PROXY (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
1606 self.c.write(' g_datalist_clear (&proxy->priv->qdata);\n')
1607 self.c.write(' G_OBJECT_CLASS (%s_proxy_parent_class)->finalize (object);\n'
1609 '\n'%(i.name_lower))
1611 # property accessors
1613 # Note that we are guaranteed that prop_id starts at 1 and is
1614 # laid out in the same order as introspection data pointers
1616 self.c.write('static void\n'
1617 '%s_proxy_get_property (GObject *object,\n'
1620 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
1621 '{\n'%(i.name_lower))
1622 if len(i.properties) > 0:
1623 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1624 ' GVariant *variant;\n'
1625 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1626 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1627 ' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
1628 ' if (info->use_gvariant)\n'
1630 ' g_value_set_variant (value, variant);\n'
1634 # could be that we don't have the value in cache - in that case, we do
1635 # nothing and the user gets the default value for the GType
1636 ' if (variant != NULL)\n'
1637 ' g_dbus_gvariant_to_gvalue (variant, value);\n'
1639 ' if (variant != NULL)\n'
1640 ' g_variant_unref (variant);\n'
1641 %(len(i.properties), i.name_lower))
1644 if len(i.properties) > 0:
1645 self.c.write('static void\n'
1646 '%s_proxy_set_property_cb (GDBusProxy *proxy,\n'
1647 ' GAsyncResult *res,\n'
1648 ' gpointer user_data)\n'
1649 '{\n'%(i.name_lower))
1650 self.c.write(' const _ExtendedGDBusPropertyInfo *info = user_data;\n'
1652 ' GVariant *_ret;\n'
1654 ' _ret = g_dbus_proxy_call_finish (proxy, res, &error);\n'
1657 ' g_warning ("Error setting property \'%%s\' on interface %s: %%s (%%s, %%d)",\n'
1658 ' info->parent_struct.name, \n'
1659 ' error->message, g_quark_to_string (error->domain), error->code);\n'
1660 ' g_error_free (error);\n'
1664 ' g_variant_unref (_ret);\n'
1669 self.c.write('static void\n'
1670 '%s_proxy_set_property (GObject *object,\n'
1672 ' const GValue *value,\n'
1673 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
1674 '{\n'%(i.name_lower))
1675 if len(i.properties) > 0:
1676 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1677 ' GVariant *variant;\n'
1678 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1679 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1680 ' variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
1681 ' g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
1682 ' "org.freedesktop.DBus.Properties.Set",\n'
1683 ' g_variant_new ("(ssv)", "%s", info->parent_struct.name, variant),\n'
1684 ' G_DBUS_CALL_FLAGS_NONE,\n'
1686 ' NULL, (GAsyncReadyCallback) %s_proxy_set_property_cb, (GDBusPropertyInfo *) &info->parent_struct);\n'
1687 ' g_variant_unref (variant);\n'
1688 %(len(i.properties), i.name_lower, i.name, i.name_lower))
1693 self.c.write('static void\n'
1694 '%s_proxy_g_signal (GDBusProxy *proxy,\n'
1695 ' const gchar *sender_name G_GNUC_UNUSED,\n'
1696 ' const gchar *signal_name,\n'
1697 ' GVariant *parameters)\n'
1698 '{\n'%(i.name_lower))
1699 self.c.write(' _ExtendedGDBusSignalInfo *info;\n'
1700 ' GVariantIter iter;\n'
1701 ' GVariant *child;\n'
1702 ' GValue *paramv;\n'
1703 ' guint num_params;\n'
1705 ' guint signal_id;\n');
1706 # Note: info could be NULL if we are talking to a newer version of the interface
1707 self.c.write(' info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, signal_name);\n'
1708 ' if (info == NULL)\n'
1711 self.c.write (' num_params = g_variant_n_children (parameters);\n'
1712 ' paramv = g_new0 (GValue, num_params + 1);\n'
1713 ' g_value_init (¶mv[0], %sTYPE_%s);\n'
1714 ' g_value_set_object (¶mv[0], proxy);\n'
1715 %(i.ns_upper, i.name_upper))
1716 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
1718 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
1720 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1];\n'
1721 ' if (arg_info->use_gvariant)\n'
1723 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
1724 ' g_value_set_variant (¶mv[n], child);\n'
1728 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
1729 ' g_variant_unref (child);\n'
1732 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
1733 %(i.ns_upper, i.name_upper))
1734 self.c.write(' g_signal_emitv (paramv, signal_id, 0, NULL);\n')
1735 self.c.write(' for (n = 0; n < num_params + 1; n++)\n'
1736 ' g_value_unset (¶mv[n]);\n'
1737 ' g_free (paramv);\n')
1742 self.c.write('static void\n'
1743 '%s_proxy_g_properties_changed (GDBusProxy *_proxy,\n'
1744 ' GVariant *changed_properties,\n'
1745 ' const gchar *const *invalidated_properties)\n'
1746 '{\n'%(i.name_lower))
1747 # Note: info could be NULL if we are talking to a newer version of the interface
1748 self.c.write(' %sProxy *proxy = %s%s_PROXY (_proxy);\n'
1750 ' const gchar *key;\n'
1751 ' GVariantIter *iter;\n'
1752 ' _ExtendedGDBusPropertyInfo *info;\n'
1753 ' g_variant_get (changed_properties, "a{sv}", &iter);\n'
1754 ' while (g_variant_iter_next (iter, "{&sv}", &key, NULL))\n'
1756 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, key);\n'
1757 ' g_datalist_remove_data (&proxy->priv->qdata, key);\n'
1758 ' if (info != NULL)\n'
1759 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1761 ' g_variant_iter_free (iter);\n'
1762 ' for (n = 0; invalidated_properties[n] != NULL; n++)\n'
1764 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, invalidated_properties[n]);\n'
1765 ' g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]);\n'
1766 ' if (info != NULL)\n'
1767 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1771 %(i.camel_name, i.ns_upper, i.name_upper,
1772 i.name_lower, i.name_lower))
1775 for p in i.properties:
1777 if p.arg.free_func != None:
1779 self.c.write('static %s\n'
1780 '%s_proxy_get_%s (%s *object)\n'
1782 ' %sProxy *proxy = %s%s_PROXY (object);\n'
1783 ' GVariant *variant;\n'
1784 ' %svalue = %s;\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name,
1785 i.camel_name, i.ns_upper, i.name_upper,
1786 p.arg.ctype_in, nul_value))
1787 # For some property types, we have to free the returned
1788 # value (or part of it, e.g. the container) because of how
1789 # GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
1792 free_container = False;
1793 if p.arg.gvariant_get == 'g_variant_get_strv' or p.arg.gvariant_get == 'g_variant_get_objpathv' or p.arg.gvariant_get == 'g_variant_get_bytestring_array':
1794 free_container = True;
1795 # If already using an old value for strv, objpathv, bytestring_array (see below),
1796 # then just return that... that way the result from multiple consecutive calls
1797 # to the getter are valid as long as they're freed
1800 self.c.write(' value = g_datalist_get_data (&proxy->priv->qdata, \"%s\");\n'
1801 ' if (value != NULL)\n'
1804 self.c.write(' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \"%s\");\n'%(p.name))
1805 if p.arg.gtype == 'G_TYPE_VARIANT':
1806 self.c.write(' value = variant;\n')
1807 self.c.write(' if (variant != NULL)\n')
1808 self.c.write(' g_variant_unref (variant);\n')
1810 self.c.write(' if (variant != NULL)\n'
1813 if p.arg.gvariant_get == 'g_variant_get_string' or p.arg.gvariant_get == 'g_variant_get_strv' or p.arg.gvariant_get == 'g_variant_get_objv' or p.arg.gvariant_get == 'g_variant_get_bytestring_array':
1814 extra_len = ', NULL'
1815 self.c.write(' value = %s (variant%s);\n'%(p.arg.gvariant_get, extra_len))
1817 self.c.write(' g_datalist_set_data_full (&proxy->priv->qdata, \"%s\", (gpointer) value, g_free);\n'
1819 self.c.write(' g_variant_unref (variant);\n')
1820 self.c.write(' }\n')
1821 self.c.write(' return value;\n')
1826 self.c.write('static void\n'
1827 '%s_proxy_init (%sProxy *proxy)\n'
1829 '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
1830 ' proxy->priv = %s_proxy_get_instance_private (proxy);\n'
1832 ' proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %sTYPE_%s_PROXY, %sProxyPrivate);\n'
1834 ' g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
1837 %(i.name_lower, i.camel_name,
1839 i.ns_upper, i.name_upper, i.camel_name,
1841 self.c.write('static void\n'
1842 '%s_proxy_class_init (%sProxyClass *klass)\n'
1844 ' GObjectClass *gobject_class;\n'
1845 ' GDBusProxyClass *proxy_class;\n'
1847 ' gobject_class = G_OBJECT_CLASS (klass);\n'
1848 ' gobject_class->finalize = %s_proxy_finalize;\n'
1849 ' gobject_class->get_property = %s_proxy_get_property;\n'
1850 ' gobject_class->set_property = %s_proxy_set_property;\n'
1852 ' proxy_class = G_DBUS_PROXY_CLASS (klass);\n'
1853 ' proxy_class->g_signal = %s_proxy_g_signal;\n'
1854 ' proxy_class->g_properties_changed = %s_proxy_g_properties_changed;\n'
1855 '\n'%(i.name_lower, i.camel_name,
1856 i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
1857 if len(i.properties) > 0:
1858 self.c.write(' %s_override_properties (gobject_class, 1);\n\n'%(i.name_lower))
1859 self.c.write('#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
1860 ' g_type_class_add_private (klass, sizeof (%sProxyPrivate));\n'
1861 '#endif\n'%(i.camel_name))
1865 self.c.write('static void\n'
1866 '%s_proxy_iface_init (%sIface *iface)\n'
1867 '{\n'%(i.name_lower, i.camel_name))
1868 for p in i.properties:
1869 self.c.write(' iface->get_%s = %s_proxy_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
1874 self.c.write(self.docbook_gen.expand(
1876 ' * %s_proxy_new:\n'
1877 ' * @connection: A #GDBusConnection.\n'
1878 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1879 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1880 ' * @object_path: An object path.\n'
1881 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1882 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1883 ' * @user_data: User data to pass to @callback.\n'
1885 ' * Asynchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new() for more details.\n'
1887 ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
1888 ' * You can then call %s_proxy_new_finish() to get the result of the operation.\n'
1890 ' * See %s_proxy_new_sync() for the synchronous, blocking version of this constructor.\n'
1891 %(i.name_lower, i.name, i.name_lower, i.name_lower), False))
1892 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1893 self.c.write('void\n'
1895 ' GDBusConnection *connection,\n'
1896 ' GDBusProxyFlags flags,\n'
1897 ' const gchar *name,\n'
1898 ' const gchar *object_path,\n'
1899 ' GCancellable *cancellable,\n'
1900 ' GAsyncReadyCallback callback,\n'
1901 ' gpointer user_data)\n'
1903 ' g_async_initable_new_async (%sTYPE_%s_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "%s", NULL);\n'
1906 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1907 self.c.write('/**\n'
1908 ' * %s_proxy_new_finish:\n'
1909 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new().\n'
1910 ' * @error: Return location for error or %%NULL\n'
1912 ' * Finishes an operation started with %s_proxy_new().\n'
1914 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1915 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1916 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1917 self.c.write('%s *\n'
1918 '%s_proxy_new_finish (\n'
1919 ' GAsyncResult *res,\n'
1920 ' GError **error)\n'
1923 ' GObject *source_object;\n'
1924 ' source_object = g_async_result_get_source_object (res);\n'
1925 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1926 ' g_object_unref (source_object);\n'
1927 ' if (ret != NULL)\n'
1928 ' return %s%s (ret);\n'
1933 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1934 self.c.write(self.docbook_gen.expand(
1936 ' * %s_proxy_new_sync:\n'
1937 ' * @connection: A #GDBusConnection.\n'
1938 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1939 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1940 ' * @object_path: An object path.\n'
1941 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1942 ' * @error: Return location for error or %%NULL\n'
1944 ' * Synchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new_sync() for more details.\n'
1946 ' * The calling thread is blocked until a reply is received.\n'
1948 ' * See %s_proxy_new() for the asynchronous version of this constructor.\n'
1950 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1951 %(i.name_lower, i.name, i.name_lower, i.camel_name), False))
1952 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1953 self.c.write('%s *\n'
1954 '%s_proxy_new_sync (\n'
1955 ' GDBusConnection *connection,\n'
1956 ' GDBusProxyFlags flags,\n'
1957 ' const gchar *name,\n'
1958 ' const gchar *object_path,\n'
1959 ' GCancellable *cancellable,\n'
1960 ' GError **error)\n'
1962 ' GInitable *ret;\n'
1963 ' ret = g_initable_new (%sTYPE_%s_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "%s", NULL);\n'
1964 ' if (ret != NULL)\n'
1965 ' return %s%s (ret);\n'
1970 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
1972 self.c.write(self.docbook_gen.expand(
1974 ' * %s_proxy_new_for_bus:\n'
1975 ' * @bus_type: A #GBusType.\n'
1976 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1977 ' * @name: A bus name (well-known or unique).\n'
1978 ' * @object_path: An object path.\n'
1979 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1980 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1981 ' * @user_data: User data to pass to @callback.\n'
1983 ' * Like %s_proxy_new() but takes a #GBusType instead of a #GDBusConnection.\n'
1985 ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
1986 ' * You can then call %s_proxy_new_for_bus_finish() to get the result of the operation.\n'
1988 ' * See %s_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
1989 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower), False))
1990 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1991 self.c.write('void\n'
1992 '%s_proxy_new_for_bus (\n'
1993 ' GBusType bus_type,\n'
1994 ' GDBusProxyFlags flags,\n'
1995 ' const gchar *name,\n'
1996 ' const gchar *object_path,\n'
1997 ' GCancellable *cancellable,\n'
1998 ' GAsyncReadyCallback callback,\n'
1999 ' gpointer user_data)\n'
2001 ' g_async_initable_new_async (%sTYPE_%s_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "%s", NULL);\n'
2004 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
2005 self.c.write('/**\n'
2006 ' * %s_proxy_new_for_bus_finish:\n'
2007 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new_for_bus().\n'
2008 ' * @error: Return location for error or %%NULL\n'
2010 ' * Finishes an operation started with %s_proxy_new_for_bus().\n'
2012 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2013 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
2014 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2015 self.c.write('%s *\n'
2016 '%s_proxy_new_for_bus_finish (\n'
2017 ' GAsyncResult *res,\n'
2018 ' GError **error)\n'
2021 ' GObject *source_object;\n'
2022 ' source_object = g_async_result_get_source_object (res);\n'
2023 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
2024 ' g_object_unref (source_object);\n'
2025 ' if (ret != NULL)\n'
2026 ' return %s%s (ret);\n'
2031 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
2032 self.c.write(self.docbook_gen.expand(
2034 ' * %s_proxy_new_for_bus_sync:\n'
2035 ' * @bus_type: A #GBusType.\n'
2036 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
2037 ' * @name: A bus name (well-known or unique).\n'
2038 ' * @object_path: An object path.\n'
2039 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
2040 ' * @error: Return location for error or %%NULL\n'
2042 ' * Like %s_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
2044 ' * The calling thread is blocked until a reply is received.\n'
2046 ' * See %s_proxy_new_for_bus() for the asynchronous version of this constructor.\n'
2048 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2049 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name), False))
2050 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2051 self.c.write('%s *\n'
2052 '%s_proxy_new_for_bus_sync (\n'
2053 ' GBusType bus_type,\n'
2054 ' GDBusProxyFlags flags,\n'
2055 ' const gchar *name,\n'
2056 ' const gchar *object_path,\n'
2057 ' GCancellable *cancellable,\n'
2058 ' GError **error)\n'
2060 ' GInitable *ret;\n'
2061 ' ret = g_initable_new (%sTYPE_%s_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "%s", NULL);\n'
2062 ' if (ret != NULL)\n'
2063 ' return %s%s (ret);\n'
2068 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
2071 # ---------------------------------------------------------------------------------------------------
2073 def generate_skeleton(self, i):
2075 self.c.write('/* ------------------------------------------------------------------------ */\n'
2078 self.c.write(self.docbook_gen.expand(
2082 ' * The #%sSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2083 %(i.camel_name, i.camel_name), False))
2084 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2087 self.c.write(self.docbook_gen.expand(
2089 ' * %sSkeletonClass:\n'
2090 ' * @parent_class: The parent class.\n'
2092 ' * Class structure for #%sSkeleton.\n'
2093 %(i.camel_name, i.camel_name), False))
2094 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2097 self.c.write('struct _%sSkeletonPrivate\n'
2099 ' GValue *properties;\n'
2100 ' GList *changed_properties;\n'
2101 ' GSource *changed_properties_idle_source;\n'
2102 ' GMainContext *context;\n'
2107 self.c.write('static void\n'
2108 '_%s_skeleton_handle_method_call (\n'
2109 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2110 ' const gchar *sender G_GNUC_UNUSED,\n'
2111 ' const gchar *object_path G_GNUC_UNUSED,\n'
2112 ' const gchar *interface_name,\n'
2113 ' const gchar *method_name,\n'
2114 ' GVariant *parameters,\n'
2115 ' GDBusMethodInvocation *invocation,\n'
2116 ' gpointer user_data)\n'
2118 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2119 ' _ExtendedGDBusMethodInfo *info;\n'
2120 ' GVariantIter iter;\n'
2121 ' GVariant *child;\n'
2122 ' GValue *paramv;\n'
2123 ' guint num_params;\n'
2124 ' guint num_extra;\n'
2126 ' guint signal_id;\n'
2127 ' GValue return_value = G_VALUE_INIT;\n'
2128 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2129 self.c.write(' info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n'
2130 ' g_assert (info != NULL);\n'
2132 self.c.write (' num_params = g_variant_n_children (parameters);\n'
2133 ' num_extra = info->pass_fdlist ? 3 : 2;'
2134 ' paramv = g_new0 (GValue, num_params + num_extra);\n'
2136 ' g_value_init (¶mv[n], %sTYPE_%s);\n'
2137 ' g_value_set_object (¶mv[n++], skeleton);\n'
2138 ' g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION);\n'
2139 ' g_value_set_object (¶mv[n++], invocation);\n'
2140 ' if (info->pass_fdlist)\n'
2142 '#ifdef G_OS_UNIX\n'
2143 ' g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST);\n'
2144 ' g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)));\n'
2146 ' g_assert_not_reached ();\n'
2149 %(i.ns_upper, i.name_upper))
2150 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
2151 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
2153 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra];\n'
2154 ' if (arg_info->use_gvariant)\n'
2156 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
2157 ' g_value_set_variant (¶mv[n], child);\n'
2161 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
2162 ' g_variant_unref (child);\n'
2165 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
2166 %(i.ns_upper, i.name_upper))
2167 self.c.write(' g_value_init (&return_value, G_TYPE_BOOLEAN);\n'
2168 ' g_signal_emitv (paramv, signal_id, 0, &return_value);\n'
2169 ' if (!g_value_get_boolean (&return_value))\n'
2170 ' g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Method %s is not implemented on interface %s", method_name, interface_name);\n'
2171 ' g_value_unset (&return_value);\n'
2173 self.c.write(' for (n = 0; n < num_params + num_extra; n++)\n'
2174 ' g_value_unset (¶mv[n]);\n'
2175 ' g_free (paramv);\n')
2179 self.c.write('static GVariant *\n'
2180 '_%s_skeleton_handle_get_property (\n'
2181 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2182 ' const gchar *sender G_GNUC_UNUSED,\n'
2183 ' const gchar *object_path G_GNUC_UNUSED,\n'
2184 ' const gchar *interface_name G_GNUC_UNUSED,\n'
2185 ' const gchar *property_name,\n'
2186 ' GError **error,\n'
2187 ' gpointer user_data)\n'
2189 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2190 ' GValue value = G_VALUE_INIT;\n'
2191 ' GParamSpec *pspec;\n'
2192 ' _ExtendedGDBusPropertyInfo *info;\n'
2194 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2195 self.c.write(' ret = NULL;\n'
2196 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2197 ' g_assert (info != NULL);\n'
2198 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2199 ' if (pspec == NULL)\n'
2201 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2205 ' g_value_init (&value, pspec->value_type);\n'
2206 ' g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2207 ' ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
2208 ' g_value_unset (&value);\n'
2215 self.c.write('static gboolean\n'
2216 '_%s_skeleton_handle_set_property (\n'
2217 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2218 ' const gchar *sender G_GNUC_UNUSED,\n'
2219 ' const gchar *object_path G_GNUC_UNUSED,\n'
2220 ' const gchar *interface_name G_GNUC_UNUSED,\n'
2221 ' const gchar *property_name,\n'
2222 ' GVariant *variant,\n'
2223 ' GError **error,\n'
2224 ' gpointer user_data)\n'
2226 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2227 ' GValue value = G_VALUE_INIT;\n'
2228 ' GParamSpec *pspec;\n'
2229 ' _ExtendedGDBusPropertyInfo *info;\n'
2231 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2232 self.c.write(' ret = FALSE;\n'
2233 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2234 ' g_assert (info != NULL);\n'
2235 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2236 ' if (pspec == NULL)\n'
2238 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2242 ' if (info->use_gvariant)\n'
2243 ' g_value_set_variant (&value, variant);\n'
2245 ' g_dbus_gvariant_to_gvalue (variant, &value);\n'
2246 ' g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2247 ' g_value_unset (&value);\n'
2256 self.c.write('static const GDBusInterfaceVTable _%s_skeleton_vtable =\n'
2258 ' _%s_skeleton_handle_method_call,\n'
2259 ' _%s_skeleton_handle_get_property,\n'
2260 ' _%s_skeleton_handle_set_property,\n'
2263 '\n'%(i.name_lower, i.name_lower, i.name_lower, i.name_lower))
2265 self.c.write('static GDBusInterfaceInfo *\n'
2266 '%s_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2268 ' return %s_interface_info ();\n'
2269 %(i.name_lower, i.name_lower))
2273 self.c.write('static GDBusInterfaceVTable *\n'
2274 '%s_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2276 ' return (GDBusInterfaceVTable *) &_%s_skeleton_vtable;\n'
2277 %(i.name_lower, i.name_lower))
2281 self.c.write('static GVariant *\n'
2282 '%s_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton)\n'
2284 ' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2285 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2287 ' GVariantBuilder builder;\n'
2289 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2290 ' if (_%s_interface_info.parent_struct.properties == NULL)\n'
2292 ' for (n = 0; _%s_interface_info.parent_struct.properties[n] != NULL; n++)\n'
2294 ' GDBusPropertyInfo *info = _%s_interface_info.parent_struct.properties[n];\n'
2295 ' if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)\n'
2297 ' GVariant *value;\n'
2298 ' value = _%s_skeleton_handle_get_property (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)), NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", info->name, NULL, skeleton);\n'
2299 ' if (value != NULL)\n'
2301 ' g_variant_take_ref (value);\n'
2302 ' g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
2303 ' g_variant_unref (value);\n'
2308 ' return g_variant_builder_end (&builder);\n'
2311 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name))
2313 if len(i.properties) > 0:
2314 self.c.write('static gboolean _%s_emit_changed (gpointer user_data);\n'
2318 self.c.write('static void\n'
2319 '%s_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton)\n'
2322 if len(i.properties) > 0:
2323 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2324 ' gboolean emit_changed = FALSE;\n'
2326 ' g_mutex_lock (&skeleton->priv->lock);\n'
2327 ' if (skeleton->priv->changed_properties_idle_source != NULL)\n'
2329 ' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
2330 ' skeleton->priv->changed_properties_idle_source = NULL;\n'
2331 ' emit_changed = TRUE;\n'
2333 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2335 ' if (emit_changed)\n'
2336 ' _%s_emit_changed (skeleton);\n'
2337 %(i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2342 self.c.write('static void\n'
2343 '_%s_on_signal_%s (\n'
2344 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
2346 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
2349 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n\n'
2350 ' GList *connections, *l;\n'
2351 ' GVariant *signal_variant;\n'
2352 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2353 %(i.camel_name, i.ns_upper, i.name_upper))
2355 ' signal_variant = g_variant_ref_sink (g_variant_new ("(')
2357 self.c.write('%s'%(a.format_in))
2360 self.c.write(',\n arg_%s'%(a.name))
2361 self.c.write('));\n')
2363 self.c.write(' for (l = connections; l != NULL; l = l->next)\n'
2365 ' GDBusConnection *connection = l->data;\n'
2366 ' g_dbus_connection_emit_signal (connection,\n'
2367 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", "%s",\n'
2368 ' signal_variant, NULL);\n'
2371 self.c.write(' g_variant_unref (signal_variant);\n')
2372 self.c.write(' g_list_free_full (connections, g_object_unref);\n')
2376 self.c.write('static void %s_skeleton_iface_init (%sIface *iface);\n'
2377 %(i.name_lower, i.camel_name))
2379 self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
2380 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2381 self.c.write(' G_ADD_PRIVATE (%sSkeleton)\n'%(i.camel_name))
2382 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2383 self.c.write('#else\n')
2384 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2385 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2386 self.c.write('#endif\n')
2389 self.c.write('static void\n'
2390 '%s_skeleton_finalize (GObject *object)\n'
2391 '{\n'%(i.name_lower))
2392 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2393 if len(i.properties) > 0:
2394 self.c.write(' guint n;\n'
2395 ' for (n = 0; n < %d; n++)\n'
2396 ' g_value_unset (&skeleton->priv->properties[n]);\n'%(len(i.properties)))
2397 self.c.write(' g_free (skeleton->priv->properties);\n')
2398 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2399 self.c.write(' if (skeleton->priv->changed_properties_idle_source != NULL)\n')
2400 self.c.write(' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
2401 self.c.write(' g_main_context_unref (skeleton->priv->context);\n')
2402 self.c.write(' g_mutex_clear (&skeleton->priv->lock);\n')
2403 self.c.write(' G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
2405 '\n'%(i.name_lower))
2407 # property accessors (TODO: generate PropertiesChanged signals in setter)
2408 if len(i.properties) > 0:
2409 self.c.write('static void\n'
2410 '%s_skeleton_get_property (GObject *object,\n'
2413 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
2414 '{\n'%(i.name_lower))
2415 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2416 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2417 ' g_mutex_lock (&skeleton->priv->lock);\n'
2418 ' g_value_copy (&skeleton->priv->properties[prop_id - 1], value);\n'
2419 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2420 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
2424 # if property is already scheduled then re-use entry.. though it could be
2427 # foo_set_prop_bar (object, "");
2428 # foo_set_prop_bar (object, "blah");
2430 # say, every update... In this case, where nothing happens, we obviously
2431 # don't want a PropertiesChanged() event. We can easily check for this
2432 # by comparing against the _original value_ recorded before the first
2433 # change event. If the latest value is not different from the original
2434 # one, we can simply ignore the ChangedProperty
2436 self.c.write('static gboolean\n'
2437 '_%s_emit_changed (gpointer user_data)\n'
2439 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2440 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2441 self.c.write(' GList *l;\n'
2442 ' GVariantBuilder builder;\n'
2443 ' GVariantBuilder invalidated_builder;\n'
2444 ' guint num_changes;\n'
2446 ' g_mutex_lock (&skeleton->priv->lock);\n'
2447 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2448 ' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
2449 ' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
2451 ' ChangedProperty *cp = l->data;\n'
2452 ' GVariant *variant;\n'
2453 ' const GValue *cur_value;\n'
2455 ' cur_value = &skeleton->priv->properties[cp->prop_id - 1];\n'
2456 ' if (!_g_value_equal (cur_value, &cp->orig_value))\n'
2458 ' variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature));\n'
2459 ' g_variant_builder_add (&builder, "{sv}", cp->info->parent_struct.name, variant);\n'
2460 ' g_variant_unref (variant);\n'
2464 ' if (num_changes > 0)\n'
2466 ' GList *connections, *ll;\n'
2467 ' GVariant *signal_variant;'
2469 ' signal_variant = g_variant_ref_sink (g_variant_new ("(sa{sv}as)", "%s",\n'
2470 ' &builder, &invalidated_builder));\n'
2471 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2472 ' for (ll = connections; ll != NULL; ll = ll->next)\n'
2474 ' GDBusConnection *connection = ll->data;\n'
2476 ' g_dbus_connection_emit_signal (connection,\n'
2477 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2478 ' "org.freedesktop.DBus.Properties",\n'
2479 ' "PropertiesChanged",\n'
2480 ' signal_variant,\n'
2483 ' g_variant_unref (signal_variant);\n'
2484 ' g_list_free_full (connections, g_object_unref);\n'
2488 ' g_variant_builder_clear (&builder);\n'
2489 ' g_variant_builder_clear (&invalidated_builder);\n'
2492 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2493 self.c.write(' skeleton->priv->changed_properties = NULL;\n')
2494 self.c.write(' skeleton->priv->changed_properties_idle_source = NULL;\n')
2495 self.c.write(' g_mutex_unlock (&skeleton->priv->lock);\n')
2496 self.c.write(' return FALSE;\n'
2499 # holding lock while being called
2500 self.c.write('static void\n'
2501 '_%s_schedule_emit_changed (%sSkeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value)\n'
2503 ' ChangedProperty *cp;\n'
2506 ' for (l = skeleton->priv->changed_properties; l != NULL; l = l->next)\n'
2508 ' ChangedProperty *i_cp = l->data;\n'
2509 ' if (i_cp->info == info)\n'
2515 %(i.name_lower, i.camel_name))
2516 self.c.write(' if (cp == NULL)\n'
2518 ' cp = g_new0 (ChangedProperty, 1);\n'
2519 ' cp->prop_id = prop_id;\n'
2520 ' cp->info = info;\n'
2521 ' skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp);\n'
2522 ' g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value));\n'
2523 ' g_value_copy (orig_value, &cp->orig_value);\n'
2529 # Postpone setting up the refresh source until the ::notify signal is emitted as
2530 # this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
2531 # This is useful when updating several properties from another thread than
2532 # where the idle will be emitted from
2533 self.c.write('static void\n'
2534 '%s_skeleton_notify (GObject *object,\n'
2535 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
2537 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2538 ' g_mutex_lock (&skeleton->priv->lock);\n'
2539 ' if (skeleton->priv->changed_properties != NULL &&\n'
2540 ' skeleton->priv->changed_properties_idle_source == NULL)\n'
2542 ' skeleton->priv->changed_properties_idle_source = g_idle_source_new ();\n'
2543 ' g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);\n'
2544 ' g_source_set_callback (skeleton->priv->changed_properties_idle_source, _%s_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);\n'
2545 ' g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _%s_emit_changed");\n'
2546 ' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
2547 ' g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
2549 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2552 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower, i.name_lower))
2554 self.c.write('static void\n'
2555 '%s_skeleton_set_property (GObject *object,\n'
2557 ' const GValue *value,\n'
2558 ' GParamSpec *pspec)\n'
2559 '{\n'%(i.name_lower))
2560 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2561 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2562 ' g_mutex_lock (&skeleton->priv->lock);\n'
2563 ' g_object_freeze_notify (object);\n'
2564 ' if (!_g_value_equal (value, &skeleton->priv->properties[prop_id - 1]))\n'
2566 ' if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
2567 ' _%s_schedule_emit_changed (skeleton, _%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties[prop_id - 1]);\n'
2568 ' g_value_copy (value, &skeleton->priv->properties[prop_id - 1]);\n'
2569 ' g_object_notify_by_pspec (object, pspec);\n'
2571 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2572 ' g_object_thaw_notify (object);\n'
2573 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
2577 self.c.write('static void\n'
2578 '%s_skeleton_init (%sSkeleton *skeleton)\n'
2580 '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
2581 ' skeleton->priv = %s_skeleton_get_instance_private (skeleton);\n'
2583 ' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
2585 %(i.name_lower, i.camel_name,
2587 i.ns_upper, i.name_upper, i.camel_name))
2588 self.c.write(' g_mutex_init (&skeleton->priv->lock);\n')
2589 self.c.write(' skeleton->priv->context = g_main_context_ref_thread_default ();\n')
2590 if len(i.properties) > 0:
2591 self.c.write(' skeleton->priv->properties = g_new0 (GValue, %d);\n'%(len(i.properties)))
2593 for p in i.properties:
2594 self.c.write(' g_value_init (&skeleton->priv->properties[%d], %s);\n'%(n, p.arg.gtype))
2601 for p in i.properties:
2602 self.c.write('static %s\n'
2603 '%s_skeleton_get_%s (%s *object)\n'
2605 %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
2606 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2607 self.c.write(' %svalue;\n'
2608 ' g_mutex_lock (&skeleton->priv->lock);\n'
2609 ' value = %s (&(skeleton->priv->properties[%d]));\n'
2610 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2611 %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
2612 self.c.write(' return value;\n')
2617 self.c.write('static void\n'
2618 '%s_skeleton_class_init (%sSkeletonClass *klass)\n'
2620 ' GObjectClass *gobject_class;\n'
2621 ' GDBusInterfaceSkeletonClass *skeleton_class;\n'
2623 ' gobject_class = G_OBJECT_CLASS (klass);\n'
2624 ' gobject_class->finalize = %s_skeleton_finalize;\n'
2625 %(i.name_lower, i.camel_name, i.name_lower))
2626 if len(i.properties) > 0:
2627 self.c.write(' gobject_class->get_property = %s_skeleton_get_property;\n'
2628 ' gobject_class->set_property = %s_skeleton_set_property;\n'
2629 ' gobject_class->notify = %s_skeleton_notify;\n'
2630 '\n'%(i.name_lower, i.name_lower, i.name_lower))
2632 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
2634 ' skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);\n');
2635 self.c.write(' skeleton_class->get_info = %s_skeleton_dbus_interface_get_info;\n'%(i.name_lower))
2636 self.c.write(' skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
2637 self.c.write(' skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
2638 self.c.write(' skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
2641 '#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
2642 ' g_type_class_add_private (klass, sizeof (%sSkeletonPrivate));\n'
2643 '#endif\n'%(i.camel_name))
2648 self.c.write('static void\n'
2649 '%s_skeleton_iface_init (%sIface *iface)\n'
2651 %(i.name_lower, i.camel_name))
2653 self.c.write(' iface->%s = _%s_on_signal_%s;\n'
2654 %(s.name_lower, i.name_lower, s.name_lower))
2655 for p in i.properties:
2656 self.c.write(' iface->get_%s = %s_skeleton_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
2661 self.c.write(self.docbook_gen.expand(
2663 ' * %s_skeleton_new:\n'
2665 ' * Creates a skeleton object for the D-Bus interface #%s.\n'
2667 ' * Returns: (transfer full) (type %sSkeleton): The skeleton object.\n'
2668 %(i.name_lower, i.name, i.camel_name), False))
2669 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2670 self.c.write('%s *\n'
2671 '%s_skeleton_new (void)\n'
2673 ' return %s%s (g_object_new (%sTYPE_%s_SKELETON, NULL));\n'
2675 '\n'%(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
2677 # ---------------------------------------------------------------------------------------------------
2679 def generate_object(self):
2680 self.c.write('/* ------------------------------------------------------------------------\n'
2681 ' * Code for Object, ObjectProxy and ObjectSkeleton\n'
2682 ' * ------------------------------------------------------------------------\n'
2686 self.c.write(self.docbook_gen.expand(
2688 ' * SECTION:%sObject\n'
2689 ' * @title: %sObject\n'
2690 ' * @short_description: Specialized GDBusObject types\n'
2692 ' * This section contains the #%sObject, #%sObjectProxy, and #%sObjectSkeleton types which make it easier to work with objects implementing generated types for D-Bus interfaces.\n'
2694 %(self.namespace, self.namespace, self.namespace, self.namespace, self.namespace), False))
2697 self.c.write(self.docbook_gen.expand(
2701 ' * The #%sObject type is a specialized container of interfaces.\n'
2703 %(self.namespace, self.namespace), False))
2706 self.c.write(self.docbook_gen.expand(
2708 ' * %sObjectIface:\n'
2709 ' * @parent_iface: The parent interface.\n'
2711 ' * Virtual table for the #%sObject interface.\n'
2713 %(self.namespace, self.namespace), False))
2716 self.c.write('typedef %sObjectIface %sObjectInterface;\n'%(self.namespace, self.namespace))
2717 self.c.write('G_DEFINE_INTERFACE_WITH_CODE (%sObject, %sobject, G_TYPE_OBJECT, g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_DBUS_OBJECT));\n'%(self.namespace, self.ns_lower))
2719 self.c.write('static void\n'
2720 '%sobject_default_init (%sObjectIface *iface)\n'
2722 %(self.ns_lower, self.namespace));
2723 for i in self.ifaces:
2724 self.c.write(self.docbook_gen.expand(
2728 ' * The #%s instance corresponding to the D-Bus interface #%s, if any.\n'
2730 ' * Connect to the #GObject::notify signal to get informed of property changes.\n'
2731 %(self.namespace, i.name_hyphen, i.camel_name, i.name), False))
2732 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 2)
2733 self.c.write(' g_object_interface_install_property (iface, g_param_spec_object ("%s", "%s", "%s", %sTYPE_%s, G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS));\n'
2735 %(i.name_hyphen, i.name_hyphen, i.name_hyphen, self.ns_upper, i.name_upper))
2739 for i in self.ifaces:
2740 self.c.write(self.docbook_gen.expand(
2742 ' * %sobject_get_%s:\n'
2743 ' * @object: A #%sObject.\n'
2745 ' * Gets the #%s instance for the D-Bus interface #%s on @object, if any.\n'
2747 ' * Returns: (transfer full): A #%s that must be freed with g_object_unref() or %%NULL if @object does not implement the interface.\n'
2748 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.name, i.camel_name), False))
2749 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2750 self.c.write ('%s *%sobject_get_%s (%sObject *object)\n'
2751 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2753 ' GDBusInterface *ret;\n'
2754 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2755 ' if (ret == NULL)\n'
2757 ' return %s%s (ret);\n'
2760 %(i.name, self.ns_upper, i.name_upper))
2762 for i in self.ifaces:
2763 self.c.write(self.docbook_gen.expand(
2765 ' * %sobject_peek_%s: (skip)\n'
2766 ' * @object: A #%sObject.\n'
2768 ' * Like %sobject_get_%s() but doesn\'t increase the reference count on the returned object.\n'
2770 ' * <warning>It is not safe to use the returned object if you are on another thread than the one where the #GDBusObjectManagerClient or #GDBusObjectManagerServer for @object is running.</warning>\n'
2772 ' * Returns: (transfer none): A #%s or %%NULL if @object does not implement the interface. Do not free the returned object, it is owned by @object.\n'
2773 %(self.ns_lower, i.name_upper.lower(), self.namespace, self.ns_lower, i.name_upper.lower(), i.camel_name), False))
2774 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2775 self.c.write ('%s *%sobject_peek_%s (%sObject *object)\n'
2776 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2778 ' GDBusInterface *ret;\n'
2779 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2780 ' if (ret == NULL)\n'
2782 ' g_object_unref (ret);\n'
2783 ' return %s%s (ret);\n'
2786 %(i.name, self.ns_upper, i.name_upper))
2788 # shared by ObjectProxy and ObjectSkeleton classes
2789 self.c.write('static void\n'
2790 '%sobject_notify (GDBusObject *object, GDBusInterface *interface)\n'
2792 ' _ExtendedGDBusInterfaceInfo *info = (_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface);\n'
2793 ' /* info can be NULL if the other end is using a D-Bus interface we don\'t know\n'
2794 ' * anything about, for example old generated code in this process talking to\n'
2795 ' * newer generated code in the other process. */\n'
2796 ' if (info != NULL)\n'
2797 ' g_object_notify (G_OBJECT (object), info->hyphen_name);\n'
2802 self.c.write(self.docbook_gen.expand(
2804 ' * %sObjectProxy:\n'
2806 ' * The #%sObjectProxy structure contains only private data and should only be accessed using the provided API.\n'
2807 %(self.namespace, self.namespace), False))
2808 self.c.write(' */\n')
2810 self.c.write(self.docbook_gen.expand(
2812 ' * %sObjectProxyClass:\n'
2813 ' * @parent_class: The parent class.\n'
2815 ' * Class structure for #%sObjectProxy.\n'
2816 %(self.namespace, self.namespace), False))
2817 self.c.write(' */\n')
2820 self.c.write('static void\n'
2821 '%sobject_proxy__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2825 %(self.ns_lower, self.ns_lower, self.namespace))
2826 self.c.write('static void\n'
2827 '%sobject_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2829 ' iface->interface_added = %sobject_notify;\n'
2830 ' iface->interface_removed = %sobject_notify;\n'
2833 %(self.ns_lower, self.ns_lower, self.ns_lower))
2835 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectProxy, %sobject_proxy, G_TYPE_DBUS_OBJECT_PROXY,\n'
2836 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_proxy__%sobject_iface_init)\n'
2837 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_proxy__g_dbus_object_iface_init));\n'
2839 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2841 self.c.write('static void\n'
2842 '%sobject_proxy_init (%sObjectProxy *object G_GNUC_UNUSED)\n'
2845 '\n'%(self.ns_lower, self.namespace))
2846 self.c.write('static void\n'
2847 '%sobject_proxy_set_property (GObject *gobject,\n'
2849 ' const GValue *value G_GNUC_UNUSED,\n'
2850 ' GParamSpec *pspec)\n'
2852 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2856 self.c.write('static void\n'
2857 '%sobject_proxy_get_property (GObject *gobject,\n'
2860 ' GParamSpec *pspec)\n'
2862 ' %sObjectProxy *object = %sOBJECT_PROXY (gobject);\n'
2863 ' GDBusInterface *interface;\n'
2865 ' switch (prop_id)\n'
2867 %(self.ns_lower, self.namespace, self.ns_upper))
2869 for i in self.ifaces:
2870 self.c.write(' case %d:\n'
2871 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2872 ' g_value_take_object (value, interface);\n'
2877 self.c.write(' default:\n'
2878 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2883 self.c.write('static void\n'
2884 '%sobject_proxy_class_init (%sObjectProxyClass *klass)\n'
2886 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2888 ' gobject_class->set_property = %sobject_proxy_set_property;\n'
2889 ' gobject_class->get_property = %sobject_proxy_get_property;\n'
2891 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2893 for i in self.ifaces:
2894 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2896 %(n, i.name_hyphen))
2901 self.c.write(self.docbook_gen.expand(
2903 ' * %sobject_proxy_new:\n'
2904 ' * @connection: A #GDBusConnection.\n'
2905 ' * @object_path: An object path.\n'
2907 ' * Creates a new proxy object.\n'
2909 ' * Returns: (transfer full): The proxy object.\n'
2911 %(self.ns_lower), False))
2912 self.c.write('%sObjectProxy *\n'
2913 '%sobject_proxy_new (GDBusConnection *connection,\n'
2914 ' const gchar *object_path)\n'
2916 ' g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);\n'
2917 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2918 ' return %sOBJECT_PROXY (g_object_new (%sTYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL));\n'
2920 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2922 self.c.write(self.docbook_gen.expand(
2924 ' * %sObjectSkeleton:\n'
2926 ' * The #%sObjectSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2927 %(self.namespace, self.namespace), False))
2928 self.c.write(' */\n')
2930 self.c.write(self.docbook_gen.expand(
2932 ' * %sObjectSkeletonClass:\n'
2933 ' * @parent_class: The parent class.\n'
2935 ' * Class structure for #%sObjectSkeleton.\n'
2936 %(self.namespace, self.namespace), False))
2937 self.c.write(' */\n')
2940 self.c.write('static void\n'
2941 '%sobject_skeleton__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2945 %(self.ns_lower, self.ns_lower, self.namespace))
2947 self.c.write('static void\n'
2948 '%sobject_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2950 ' iface->interface_added = %sobject_notify;\n'
2951 ' iface->interface_removed = %sobject_notify;\n'
2954 %(self.ns_lower, self.ns_lower, self.ns_lower))
2955 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectSkeleton, %sobject_skeleton, G_TYPE_DBUS_OBJECT_SKELETON,\n'
2956 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_skeleton__%sobject_iface_init)\n'
2957 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_skeleton__g_dbus_object_iface_init));\n'
2959 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2961 self.c.write('static void\n'
2962 '%sobject_skeleton_init (%sObjectSkeleton *object G_GNUC_UNUSED)\n'
2965 '\n'%(self.ns_lower, self.namespace))
2966 self.c.write('static void\n'
2967 '%sobject_skeleton_set_property (GObject *gobject,\n'
2969 ' const GValue *value,\n'
2970 ' GParamSpec *pspec)\n'
2972 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2973 ' GDBusInterfaceSkeleton *interface;\n'
2975 ' switch (prop_id)\n'
2977 %(self.ns_lower, self.namespace, self.ns_upper))
2979 for i in self.ifaces:
2980 self.c.write(' case %d:\n'
2981 ' interface = g_value_get_object (value);\n'
2982 ' if (interface != NULL)\n'
2984 ' g_warn_if_fail (%sIS_%s (interface));\n'
2985 ' g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface);\n'
2989 ' g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "%s");\n'
2993 %(n, self.ns_upper, i.name_upper, i.name))
2995 self.c.write(' default:\n'
2996 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
3001 self.c.write('static void\n'
3002 '%sobject_skeleton_get_property (GObject *gobject,\n'
3005 ' GParamSpec *pspec)\n'
3007 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
3008 ' GDBusInterface *interface;\n'
3010 ' switch (prop_id)\n'
3012 %(self.ns_lower, self.namespace, self.ns_upper))
3014 for i in self.ifaces:
3015 self.c.write(' case %d:\n'
3016 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
3017 ' g_value_take_object (value, interface);\n'
3022 self.c.write(' default:\n'
3023 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
3028 self.c.write('static void\n'
3029 '%sobject_skeleton_class_init (%sObjectSkeletonClass *klass)\n'
3031 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
3033 ' gobject_class->set_property = %sobject_skeleton_set_property;\n'
3034 ' gobject_class->get_property = %sobject_skeleton_get_property;\n'
3036 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
3038 for i in self.ifaces:
3039 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
3041 %(n, i.name_hyphen))
3045 self.c.write(self.docbook_gen.expand(
3047 ' * %sobject_skeleton_new:\n'
3048 ' * @object_path: An object path.\n'
3050 ' * Creates a new skeleton object.\n'
3052 ' * Returns: (transfer full): The skeleton object.\n'
3054 %(self.ns_lower), False))
3055 self.c.write('%sObjectSkeleton *\n'
3056 '%sobject_skeleton_new (const gchar *object_path)\n'
3058 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
3059 ' return %sOBJECT_SKELETON (g_object_new (%sTYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL));\n'
3061 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
3062 for i in self.ifaces:
3063 self.c.write(self.docbook_gen.expand(
3065 ' * %sobject_skeleton_set_%s:\n'
3066 ' * @object: A #%sObjectSkeleton.\n'
3067 ' * @interface_: (allow-none): A #%s or %%NULL to clear the interface.\n'
3069 ' * Sets the #%s instance for the D-Bus interface #%s on @object.\n'
3070 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.camel_name, i.name), False))
3071 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
3072 self.c.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_)\n'
3073 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
3075 ' g_object_set (G_OBJECT (object), "%s", interface_, NULL);\n'
3082 def generate_object_manager_client(self):
3083 self.c.write('/* ------------------------------------------------------------------------\n'
3084 ' * Code for ObjectManager client\n'
3085 ' * ------------------------------------------------------------------------\n'
3089 self.c.write(self.docbook_gen.expand(
3091 ' * SECTION:%sObjectManagerClient\n'
3092 ' * @title: %sObjectManagerClient\n'
3093 ' * @short_description: Generated GDBusObjectManagerClient type\n'
3095 ' * This section contains a #GDBusObjectManagerClient that uses %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc.\n'
3097 %(self.namespace, self.namespace, self.ns_lower), False))
3100 self.c.write(self.docbook_gen.expand(
3102 ' * %sObjectManagerClient:\n'
3104 ' * The #%sObjectManagerClient structure contains only private data and should only be accessed using the provided API.\n'
3105 %(self.namespace, self.namespace), False))
3106 self.c.write(' */\n')
3109 self.c.write(self.docbook_gen.expand(
3111 ' * %sObjectManagerClientClass:\n'
3112 ' * @parent_class: The parent class.\n'
3114 ' * Class structure for #%sObjectManagerClient.\n'
3115 %(self.namespace, self.namespace), False))
3116 self.c.write(' */\n')
3120 self.c.write('G_DEFINE_TYPE (%sObjectManagerClient, %sobject_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT);\n'
3122 %(self.namespace, self.ns_lower))
3125 self.c.write('static void\n'
3126 '%sobject_manager_client_init (%sObjectManagerClient *manager G_GNUC_UNUSED)\n'
3129 '\n'%(self.ns_lower, self.namespace))
3130 self.c.write('static void\n'
3131 '%sobject_manager_client_class_init (%sObjectManagerClientClass *klass G_GNUC_UNUSED)\n'
3134 '\n'%(self.ns_lower, self.namespace))
3136 self.c.write(self.docbook_gen.expand(
3138 ' * %sobject_manager_client_get_proxy_type:\n'
3139 ' * @manager: A #GDBusObjectManagerClient.\n'
3140 ' * @object_path: The object path of the remote object (unused).\n'
3141 ' * @interface_name: (allow-none): Interface name of the remote object or %%NULL to get the object proxy #GType.\n'
3142 ' * @user_data: User data (unused).\n'
3144 ' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types.\n'
3146 ' * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %%NULL, otherwise the #GType for #%sObjectProxy.\n'
3147 %(self.ns_lower, self.namespace), False))
3148 self.c.write(' */\n')
3149 self.c.write('GType\n'
3150 '%sobject_manager_client_get_proxy_type (GDBusObjectManagerClient *manager G_GNUC_UNUSED, const gchar *object_path G_GNUC_UNUSED, const gchar *interface_name, gpointer user_data G_GNUC_UNUSED)\n'
3153 self.c.write(' static gsize once_init_value = 0;\n'
3154 ' static GHashTable *lookup_hash;\n'
3157 ' if (interface_name == NULL)\n'
3158 ' return %sTYPE_OBJECT_PROXY;\n'
3159 ' if (g_once_init_enter (&once_init_value))\n'
3161 ' lookup_hash = g_hash_table_new (g_str_hash, g_str_equal);\n'
3163 for i in self.ifaces:
3164 self.c.write(' g_hash_table_insert (lookup_hash, (gpointer) "%s", GSIZE_TO_POINTER (%sTYPE_%s_PROXY));\n'
3165 %(i.name, i.ns_upper, i.name_upper))
3166 self.c.write(' g_once_init_leave (&once_init_value, 1);\n'
3168 self.c.write(' ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name));\n'
3169 ' if (ret == (GType) 0)\n'
3170 ' ret = G_TYPE_DBUS_PROXY;\n')
3171 self.c.write(' return ret;\n'
3176 self.c.write(self.docbook_gen.expand(
3178 ' * %sobject_manager_client_new:\n'
3179 ' * @connection: A #GDBusConnection.\n'
3180 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3181 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3182 ' * @object_path: An object path.\n'
3183 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3184 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3185 ' * @user_data: User data to pass to @callback.\n'
3187 ' * Asynchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details.\n'
3189 ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
3190 ' * You can then call %sobject_manager_client_new_finish() to get the result of the operation.\n'
3192 ' * See %sobject_manager_client_new_sync() for the synchronous, blocking version of this constructor.\n'
3193 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3194 self.c.write(' */\n')
3195 self.c.write('void\n'
3196 '%sobject_manager_client_new (\n'
3197 ' GDBusConnection *connection,\n'
3198 ' GDBusObjectManagerClientFlags flags,\n'
3199 ' const gchar *name,\n'
3200 ' const gchar *object_path,\n'
3201 ' GCancellable *cancellable,\n'
3202 ' GAsyncReadyCallback callback,\n'
3203 ' gpointer user_data)\n'
3205 ' g_async_initable_new_async (%sTYPE_OBJECT_MANAGER_CLIENT, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "flags", flags, "name", name, "connection", connection, "object-path", object_path, "get-proxy-type-func", %sobject_manager_client_get_proxy_type, NULL);\n'
3208 %(self.ns_lower, self.ns_upper, self.ns_lower))
3209 self.c.write('/**\n'
3210 ' * %sobject_manager_client_new_finish:\n'
3211 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new().\n'
3212 ' * @error: Return location for error or %%NULL\n'
3214 ' * Finishes an operation started with %sobject_manager_client_new().\n'
3216 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3217 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3218 self.c.write(' */\n')
3219 self.c.write('GDBusObjectManager *\n'
3220 '%sobject_manager_client_new_finish (\n'
3221 ' GAsyncResult *res,\n'
3222 ' GError **error)\n'
3225 ' GObject *source_object;\n'
3226 ' source_object = g_async_result_get_source_object (res);\n'
3227 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3228 ' g_object_unref (source_object);\n'
3229 ' if (ret != NULL)\n'
3230 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3236 self.c.write(self.docbook_gen.expand(
3238 ' * %sobject_manager_client_new_sync:\n'
3239 ' * @connection: A #GDBusConnection.\n'
3240 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3241 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3242 ' * @object_path: An object path.\n'
3243 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3244 ' * @error: Return location for error or %%NULL\n'
3246 ' * Synchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new_sync() for more details.\n'
3248 ' * The calling thread is blocked until a reply is received.\n'
3250 ' * See %sobject_manager_client_new() for the asynchronous version of this constructor.\n'
3252 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3253 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3254 self.c.write(' */\n')
3255 self.c.write('GDBusObjectManager *\n'
3256 '%sobject_manager_client_new_sync (\n'
3257 ' GDBusConnection *connection,\n'
3258 ' GDBusObjectManagerClientFlags flags,\n'
3259 ' const gchar *name,\n'
3260 ' const gchar *object_path,\n'
3261 ' GCancellable *cancellable,\n'
3262 ' GError **error)\n'
3264 ' GInitable *ret;\n'
3265 ' ret = g_initable_new (%sTYPE_OBJECT_MANAGER_CLIENT, cancellable, error, "flags", flags, "name", name, "connection", connection, "object-path", object_path, "get-proxy-type-func", %sobject_manager_client_get_proxy_type, NULL);\n'
3266 ' if (ret != NULL)\n'
3267 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3272 %(self.ns_lower, self.ns_upper, self.ns_lower))
3274 self.c.write(self.docbook_gen.expand(
3276 ' * %sobject_manager_client_new_for_bus:\n'
3277 ' * @bus_type: A #GBusType.\n'
3278 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3279 ' * @name: A bus name (well-known or unique).\n'
3280 ' * @object_path: An object path.\n'
3281 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3282 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3283 ' * @user_data: User data to pass to @callback.\n'
3285 ' * Like %sobject_manager_client_new() but takes a #GBusType instead of a #GDBusConnection.\n'
3287 ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
3288 ' * You can then call %sobject_manager_client_new_for_bus_finish() to get the result of the operation.\n'
3290 ' * See %sobject_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
3291 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3292 self.c.write(' */\n')
3293 self.c.write('void\n'
3294 '%sobject_manager_client_new_for_bus (\n'
3295 ' GBusType bus_type,\n'
3296 ' GDBusObjectManagerClientFlags flags,\n'
3297 ' const gchar *name,\n'
3298 ' const gchar *object_path,\n'
3299 ' GCancellable *cancellable,\n'
3300 ' GAsyncReadyCallback callback,\n'
3301 ' gpointer user_data)\n'
3303 ' g_async_initable_new_async (%sTYPE_OBJECT_MANAGER_CLIENT, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "flags", flags, "name", name, "bus-type", bus_type, "object-path", object_path, "get-proxy-type-func", %sobject_manager_client_get_proxy_type, NULL);\n'
3306 %(self.ns_lower, self.ns_upper, self.ns_lower))
3307 self.c.write('/**\n'
3308 ' * %sobject_manager_client_new_for_bus_finish:\n'
3309 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new_for_bus().\n'
3310 ' * @error: Return location for error or %%NULL\n'
3312 ' * Finishes an operation started with %sobject_manager_client_new_for_bus().\n'
3314 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3315 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3316 self.c.write(' */\n')
3317 self.c.write('GDBusObjectManager *\n'
3318 '%sobject_manager_client_new_for_bus_finish (\n'
3319 ' GAsyncResult *res,\n'
3320 ' GError **error)\n'
3323 ' GObject *source_object;\n'
3324 ' source_object = g_async_result_get_source_object (res);\n'
3325 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3326 ' g_object_unref (source_object);\n'
3327 ' if (ret != NULL)\n'
3328 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3334 self.c.write(self.docbook_gen.expand(
3336 ' * %sobject_manager_client_new_for_bus_sync:\n'
3337 ' * @bus_type: A #GBusType.\n'
3338 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3339 ' * @name: A bus name (well-known or unique).\n'
3340 ' * @object_path: An object path.\n'
3341 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3342 ' * @error: Return location for error or %%NULL\n'
3344 ' * Like %sobject_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
3346 ' * The calling thread is blocked until a reply is received.\n'
3348 ' * See %sobject_manager_client_new_for_bus() for the asynchronous version of this constructor.\n'
3350 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3351 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3352 self.c.write(' */\n')
3353 self.c.write('GDBusObjectManager *\n'
3354 '%sobject_manager_client_new_for_bus_sync (\n'
3355 ' GBusType bus_type,\n'
3356 ' GDBusObjectManagerClientFlags flags,\n'
3357 ' const gchar *name,\n'
3358 ' const gchar *object_path,\n'
3359 ' GCancellable *cancellable,\n'
3360 ' GError **error)\n'
3362 ' GInitable *ret;\n'
3363 ' ret = g_initable_new (%sTYPE_OBJECT_MANAGER_CLIENT, cancellable, error, "flags", flags, "name", name, "bus-type", bus_type, "object-path", object_path, "get-proxy-type-func", %sobject_manager_client_get_proxy_type, NULL);\n'
3364 ' if (ret != NULL)\n'
3365 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3370 %(self.ns_lower, self.ns_upper, self.ns_lower))
3373 # ---------------------------------------------------------------------------------------------------
3375 def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
3376 if len(obj.since) > 0:
3379 %(indent, '', indent, '', obj.since))
3381 if isinstance(obj, dbustypes.Interface):
3382 thing = 'The D-Bus interface'
3383 elif isinstance(obj, dbustypes.Method):
3384 thing = 'The D-Bus method'
3385 elif isinstance(obj, dbustypes.Signal):
3386 thing = 'The D-Bus signal'
3387 elif isinstance(obj, dbustypes.Property):
3388 thing = 'The D-Bus property'
3390 raise RuntimeError('Cannot handle object ', obj)
3391 f.write(self.docbook_gen.expand(
3393 '%*s * Deprecated: %s has been deprecated.\n'
3394 %(indent, '', indent, '', thing), False))
3395 f.write('%*s */\n'%(indent, ''))
3397 # ---------------------------------------------------------------------------------------------------
3399 def generate_interface_intro(self, i):
3400 self.c.write('/* ------------------------------------------------------------------------\n'
3401 ' * Code for interface %s\n'
3402 ' * ------------------------------------------------------------------------\n'
3406 self.c.write(self.docbook_gen.expand(
3410 ' * @short_description: Generated C code for the %s D-Bus interface\n'
3412 ' * This section contains code for working with the #%s D-Bus interface in C.\n'
3414 %(i.camel_name, i.camel_name, i.name, i.name), False))
3418 self.generate_intro()
3419 self.declare_types()
3420 for i in self.ifaces:
3421 self.generate_interface_intro(i)
3422 self.generate_introspection_for_interface(i)
3423 self.generate_interface(i)
3424 self.generate_property_accessors(i)
3425 self.generate_signal_emitters(i)
3426 self.generate_method_calls(i)
3427 self.generate_method_completers(i)
3428 self.generate_proxy(i)
3429 self.generate_skeleton(i)
3430 if self.generate_objmanager:
3431 self.generate_object()
3432 self.generate_object_manager_client()
3434 self.generate_outro()