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, generate_autocleanup, docbook_gen, h, c):
32 self.docbook_gen = docbook_gen
33 self.generate_objmanager = generate_objmanager
34 self.generate_autocleanup = generate_autocleanup
38 self.namespace = namespace
39 if len(namespace) > 0:
40 if utils.is_ugly_case(namespace):
41 self.namespace = namespace.replace('_', '')
42 self.ns_upper = namespace.upper() + '_'
43 self.ns_lower = namespace.lower() + '_'
45 self.ns_upper = utils.camel_case_to_uscore(namespace).upper() + '_'
46 self.ns_lower = utils.camel_case_to_uscore(namespace).lower() + '_'
50 self.interface_prefix = interface_prefix
51 self.header_guard = self.h.name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
53 # ----------------------------------------------------------------------------------------------------
55 def generate_intro(self):
57 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
59 ' * The license of this code is the same as for the source it was derived from.\n'
63 self.c.write('#ifdef HAVE_CONFIG_H\n'
64 '# include "config.h"\n'
69 '#include <string.h>\n'
72 self.c.write('#ifdef G_OS_UNIX\n'
73 '# include <gio/gunixfdlist.h>\n'
77 self.c.write('typedef struct\n'
79 ' GDBusArgInfo parent_struct;\n'
80 ' gboolean use_gvariant;\n'
81 '} _ExtendedGDBusArgInfo;\n'
84 self.c.write('typedef struct\n'
86 ' GDBusMethodInfo parent_struct;\n'
87 ' const gchar *signal_name;\n'
88 ' gboolean pass_fdlist;\n'
89 '} _ExtendedGDBusMethodInfo;\n'
92 self.c.write('typedef struct\n'
94 ' GDBusSignalInfo parent_struct;\n'
95 ' const gchar *signal_name;\n'
96 '} _ExtendedGDBusSignalInfo;\n'
99 self.c.write('typedef struct\n'
101 ' GDBusPropertyInfo parent_struct;\n'
102 ' const gchar *hyphen_name;\n'
103 ' gboolean use_gvariant;\n'
104 '} _ExtendedGDBusPropertyInfo;\n'
107 self.c.write('typedef struct\n'
109 ' GDBusInterfaceInfo parent_struct;\n'
110 ' const gchar *hyphen_name;\n'
111 '} _ExtendedGDBusInterfaceInfo;\n'
114 self.c.write('typedef struct\n'
116 ' const _ExtendedGDBusPropertyInfo *info;\n'
118 ' GValue orig_value; /* the value before the change */\n'
119 '} ChangedProperty;\n'
122 '_changed_property_free (ChangedProperty *data)\n'
124 ' g_value_unset (&data->orig_value);\n'
129 self.c.write('static gboolean\n'
130 '_g_strv_equal0 (gchar **a, gchar **b)\n'
132 ' gboolean ret = FALSE;\n'
134 ' if (a == NULL && b == NULL)\n'
139 ' if (a == NULL || b == NULL)\n'
141 ' if (g_strv_length (a) != g_strv_length (b))\n'
143 ' for (n = 0; a[n] != NULL; n++)\n'
144 ' if (g_strcmp0 (a[n], b[n]) != 0)\n'
152 self.c.write('static gboolean\n'
153 '_g_variant_equal0 (GVariant *a, GVariant *b)\n'
155 ' gboolean ret = FALSE;\n'
156 ' if (a == NULL && b == NULL)\n'
161 ' if (a == NULL || b == NULL)\n'
163 ' ret = g_variant_equal (a, b);\n'
169 # simplified - only supports the types we use
170 self.c.write('G_GNUC_UNUSED static gboolean\n'
171 '_g_value_equal (const GValue *a, const GValue *b)\n'
173 ' gboolean ret = FALSE;\n'
174 ' g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b));\n'
175 ' switch (G_VALUE_TYPE (a))\n'
177 ' case G_TYPE_BOOLEAN:\n'
178 ' ret = (g_value_get_boolean (a) == g_value_get_boolean (b));\n'
180 ' case G_TYPE_UCHAR:\n'
181 ' ret = (g_value_get_uchar (a) == g_value_get_uchar (b));\n'
183 ' case G_TYPE_INT:\n'
184 ' ret = (g_value_get_int (a) == g_value_get_int (b));\n'
186 ' case G_TYPE_UINT:\n'
187 ' ret = (g_value_get_uint (a) == g_value_get_uint (b));\n'
189 ' case G_TYPE_INT64:\n'
190 ' ret = (g_value_get_int64 (a) == g_value_get_int64 (b));\n'
192 ' case G_TYPE_UINT64:\n'
193 ' ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n'
195 ' case G_TYPE_DOUBLE:\n'
197 ' /* Avoid -Wfloat-equal warnings by doing a direct bit compare */\n'
198 ' gdouble da = g_value_get_double (a);\n'
199 ' gdouble db = g_value_get_double (b);\n'
200 ' ret = memcmp (&da, &db, sizeof (gdouble)) == 0;\n'
203 ' case G_TYPE_STRING:\n'
204 ' ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n'
206 ' case G_TYPE_VARIANT:\n'
207 ' ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b));\n'
210 ' if (G_VALUE_TYPE (a) == G_TYPE_STRV)\n'
211 ' ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b));\n'
213 ' g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a)));\n'
221 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
223 ' * The license of this code is the same as for the source it was derived from.\n'
228 '\n'%(config.VERSION, self.header_guard, self.header_guard))
229 self.h.write('#include <gio/gio.h>\n'
234 # ----------------------------------------------------------------------------------------------------
236 def declare_types(self):
237 for i in self.ifaces:
239 self.h.write('/* ------------------------------------------------------------------------ */\n')
240 self.h.write('/* Declarations for %s */\n'%i.name)
243 # First the GInterface
244 self.h.write('#define %sTYPE_%s (%s_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
245 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))
246 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))
247 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))
249 self.h.write('struct _%s;\n'%(i.camel_name))
250 self.h.write('typedef struct _%s %s;\n'%(i.camel_name, i.camel_name))
251 self.h.write('typedef struct _%sIface %sIface;\n'%(i.camel_name, i.camel_name))
253 self.h.write('struct _%sIface\n'%(i.camel_name))
255 self.h.write(' GTypeInterface parent_iface;\n')
257 function_pointers = {}
260 if len(i.methods) > 0:
264 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
266 key = (m.since, '_method_%s'%m.name_lower)
267 value = ' gboolean (*handle_%s) (\n'%(m.name_lower)
268 value += ' %s *object,\n'%(i.camel_name)
269 value += ' GDBusMethodInvocation *invocation'%()
271 value += ',\n GUnixFDList *fd_list'
273 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
275 function_pointers[key] = value
278 if len(i.signals) > 0:
281 key = (s.since, '_signal_%s'%s.name_lower)
282 value = ' void (*%s) (\n'%(s.name_lower)
283 value += ' %s *object'%(i.camel_name)
285 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
287 function_pointers[key] = value
289 # vfuncs for properties
290 if len(i.properties) > 0:
292 for p in i.properties:
293 key = (p.since, '_prop_get_%s'%p.name_lower)
294 value = ' %s (*get_%s) (%s *object);\n\n'%(p.arg.ctype_in, p.name_lower, i.camel_name)
295 function_pointers[key] = value
297 # Sort according to @since tag, then name.. this ensures
298 # that the function pointers don't change order assuming
299 # judicious use of @since
301 # Also use a proper version comparison function so e.g.
302 # 10.0 comes after 2.0.
304 # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
306 for key in sorted(function_pointers.keys(), key=utils.version_cmp_key):
307 self.h.write('%s'%function_pointers[key])
311 if self.generate_autocleanup == 'all':
312 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
313 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%s, g_object_unref)\n' % (i.camel_name))
314 self.h.write('#endif\n')
316 self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
318 self.h.write('GDBusInterfaceInfo *%s_interface_info (void);\n'%(i.name_lower))
319 self.h.write('guint %s_override_properties (GObjectClass *klass, guint property_id_begin);\n'%(i.name_lower))
322 # Then method call completion functions
323 if len(i.methods) > 0:
325 self.h.write('/* D-Bus method call completion functions: */\n')
328 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
331 self.h.write('G_GNUC_DEPRECATED ')
332 self.h.write('void %s_complete_%s (\n'
334 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
336 self.h.write(',\n GUnixFDList *fd_list')
338 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
343 # Then signal emission functions
344 if len(i.signals) > 0:
346 self.h.write('/* D-Bus signal emissions functions: */\n')
349 self.h.write('G_GNUC_DEPRECATED ')
350 self.h.write('void %s_emit_%s (\n'
351 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
353 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
358 # Then method call declarations
359 if len(i.methods) > 0:
361 self.h.write('/* D-Bus method calls: */\n')
364 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
368 self.h.write('G_GNUC_DEPRECATED ')
369 self.h.write('void %s_call_%s (\n'
370 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
372 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
374 self.h.write(',\n GUnixFDList *fd_list')
376 ' GCancellable *cancellable,\n'
377 ' GAsyncReadyCallback callback,\n'
378 ' gpointer user_data);\n')
382 self.h.write('G_GNUC_DEPRECATED ')
383 self.h.write('gboolean %s_call_%s_finish (\n'
384 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
386 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
388 self.h.write(',\n GUnixFDList **out_fd_list')
390 ' GAsyncResult *res,\n'
391 ' GError **error);\n')
395 self.h.write('G_GNUC_DEPRECATED ')
396 self.h.write('gboolean %s_call_%s_sync (\n'
397 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
399 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
401 self.h.write(',\n GUnixFDList *fd_list')
403 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
405 self.h.write(',\n GUnixFDList **out_fd_list')
407 ' GCancellable *cancellable,\n'
408 ' GError **error);\n')
412 # Then the property accessor declarations
413 if len(i.properties) > 0:
415 self.h.write('/* D-Bus property accessors: */\n')
416 for p in i.properties:
419 self.h.write('G_GNUC_DEPRECATED ')
420 self.h.write('%s%s_get_%s (%s *object);\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
421 if p.arg.free_func != None:
423 self.h.write('G_GNUC_DEPRECATED ')
424 self.h.write('%s%s_dup_%s (%s *object);\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name))
427 self.h.write('G_GNUC_DEPRECATED ')
428 self.h.write('void %s_set_%s (%s *object, %svalue);\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
433 self.h.write('/* ---- */\n')
435 self.h.write('#define %sTYPE_%s_PROXY (%s_proxy_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
436 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))
437 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))
438 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))
439 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))
440 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))
442 self.h.write('typedef struct _%sProxy %sProxy;\n'%(i.camel_name, i.camel_name))
443 self.h.write('typedef struct _%sProxyClass %sProxyClass;\n'%(i.camel_name, i.camel_name))
444 self.h.write('typedef struct _%sProxyPrivate %sProxyPrivate;\n'%(i.camel_name, i.camel_name))
446 self.h.write('struct _%sProxy\n'%(i.camel_name))
448 self.h.write(' /*< private >*/\n')
449 self.h.write(' GDBusProxy parent_instance;\n')
450 self.h.write(' %sProxyPrivate *priv;\n'%(i.camel_name))
453 self.h.write('struct _%sProxyClass\n'%(i.camel_name))
455 self.h.write(' GDBusProxyClass parent_class;\n')
458 self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
460 if self.generate_autocleanup in ('objects', 'all'):
461 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
462 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sProxy, g_object_unref)\n' % (i.camel_name))
463 self.h.write('#endif\n')
466 self.h.write('G_GNUC_DEPRECATED ')
467 self.h.write('void %s_proxy_new (\n'
468 ' GDBusConnection *connection,\n'
469 ' GDBusProxyFlags flags,\n'
470 ' const gchar *name,\n'
471 ' const gchar *object_path,\n'
472 ' GCancellable *cancellable,\n'
473 ' GAsyncReadyCallback callback,\n'
474 ' gpointer user_data);\n'
477 self.h.write('G_GNUC_DEPRECATED ')
478 self.h.write('%s *%s_proxy_new_finish (\n'
479 ' GAsyncResult *res,\n'
480 ' GError **error);\n'
481 %(i.camel_name, i.name_lower))
483 self.h.write('G_GNUC_DEPRECATED ')
484 self.h.write('%s *%s_proxy_new_sync (\n'
485 ' GDBusConnection *connection,\n'
486 ' GDBusProxyFlags flags,\n'
487 ' const gchar *name,\n'
488 ' const gchar *object_path,\n'
489 ' GCancellable *cancellable,\n'
490 ' GError **error);\n'
491 %(i.camel_name, i.name_lower))
494 self.h.write('G_GNUC_DEPRECATED ')
495 self.h.write('void %s_proxy_new_for_bus (\n'
496 ' GBusType bus_type,\n'
497 ' GDBusProxyFlags flags,\n'
498 ' const gchar *name,\n'
499 ' const gchar *object_path,\n'
500 ' GCancellable *cancellable,\n'
501 ' GAsyncReadyCallback callback,\n'
502 ' gpointer user_data);\n'
505 self.h.write('G_GNUC_DEPRECATED ')
506 self.h.write('%s *%s_proxy_new_for_bus_finish (\n'
507 ' GAsyncResult *res,\n'
508 ' GError **error);\n'
509 %(i.camel_name, i.name_lower))
511 self.h.write('G_GNUC_DEPRECATED ')
512 self.h.write('%s *%s_proxy_new_for_bus_sync (\n'
513 ' GBusType bus_type,\n'
514 ' GDBusProxyFlags flags,\n'
515 ' const gchar *name,\n'
516 ' const gchar *object_path,\n'
517 ' GCancellable *cancellable,\n'
518 ' GError **error);\n'
519 %(i.camel_name, i.name_lower))
524 self.h.write('/* ---- */\n')
526 self.h.write('#define %sTYPE_%s_SKELETON (%s_skeleton_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
527 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))
528 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))
529 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))
530 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))
531 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))
533 self.h.write('typedef struct _%sSkeleton %sSkeleton;\n'%(i.camel_name, i.camel_name))
534 self.h.write('typedef struct _%sSkeletonClass %sSkeletonClass;\n'%(i.camel_name, i.camel_name))
535 self.h.write('typedef struct _%sSkeletonPrivate %sSkeletonPrivate;\n'%(i.camel_name, i.camel_name))
537 self.h.write('struct _%sSkeleton\n'%(i.camel_name))
539 self.h.write(' /*< private >*/\n')
540 self.h.write(' GDBusInterfaceSkeleton parent_instance;\n')
541 self.h.write(' %sSkeletonPrivate *priv;\n'%(i.camel_name))
544 self.h.write('struct _%sSkeletonClass\n'%(i.camel_name))
546 self.h.write(' GDBusInterfaceSkeletonClass parent_class;\n')
549 self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
551 if self.generate_autocleanup in ('objects', 'all'):
552 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
553 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sSkeleton, g_object_unref)\n' % (i.camel_name))
554 self.h.write('#endif\n')
557 self.h.write('G_GNUC_DEPRECATED ')
558 self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
562 # Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
563 if self.generate_objmanager:
565 self.h.write('/* ---- */\n')
567 self.h.write('#define %sTYPE_OBJECT (%sobject_get_type ())\n'%(self.ns_upper, self.ns_lower))
568 self.h.write('#define %sOBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
569 self.h.write('#define %sIS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT))\n'%(self.ns_upper, self.ns_upper))
570 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))
572 self.h.write('struct _%sObject;\n'%(self.namespace))
573 self.h.write('typedef struct _%sObject %sObject;\n'%(self.namespace, self.namespace))
574 self.h.write('typedef struct _%sObjectIface %sObjectIface;\n'%(self.namespace, self.namespace))
576 self.h.write('struct _%sObjectIface\n'%(self.namespace))
578 ' GTypeInterface parent_iface;\n'
581 self.h.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
584 for i in self.ifaces:
586 self.h.write('G_GNUC_DEPRECATED ')
587 self.h.write ('%s *%sobject_get_%s (%sObject *object);\n'
588 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
589 for i in self.ifaces:
591 self.h.write('G_GNUC_DEPRECATED ')
592 self.h.write ('%s *%sobject_peek_%s (%sObject *object);\n'
593 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
595 self.h.write('#define %sTYPE_OBJECT_PROXY (%sobject_proxy_get_type ())\n'%(self.ns_upper, self.ns_lower))
596 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))
597 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))
598 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))
599 self.h.write('#define %sIS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
600 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))
602 self.h.write('typedef struct _%sObjectProxy %sObjectProxy;\n'%(self.namespace, self.namespace))
603 self.h.write('typedef struct _%sObjectProxyClass %sObjectProxyClass;\n'%(self.namespace, self.namespace))
604 self.h.write('typedef struct _%sObjectProxyPrivate %sObjectProxyPrivate;\n'%(self.namespace, self.namespace))
606 self.h.write('struct _%sObjectProxy\n'%(self.namespace))
608 self.h.write(' /*< private >*/\n')
609 self.h.write(' GDBusObjectProxy parent_instance;\n')
610 self.h.write(' %sObjectProxyPrivate *priv;\n'%(self.namespace))
613 self.h.write('struct _%sObjectProxyClass\n'%(self.namespace))
615 self.h.write(' GDBusObjectProxyClass parent_class;\n')
618 self.h.write('GType %sobject_proxy_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
620 if self.generate_autocleanup in ('objects', 'all'):
621 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
622 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectProxy, g_object_unref)\n' % (self.namespace))
623 self.h.write('#endif\n')
625 self.h.write('%sObjectProxy *%sobject_proxy_new (GDBusConnection *connection, const gchar *object_path);\n'%(self.namespace, self.ns_lower))
627 self.h.write('#define %sTYPE_OBJECT_SKELETON (%sobject_skeleton_get_type ())\n'%(self.ns_upper, self.ns_lower))
628 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))
629 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))
630 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))
631 self.h.write('#define %sIS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
632 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))
634 self.h.write('typedef struct _%sObjectSkeleton %sObjectSkeleton;\n'%(self.namespace, self.namespace))
635 self.h.write('typedef struct _%sObjectSkeletonClass %sObjectSkeletonClass;\n'%(self.namespace, self.namespace))
636 self.h.write('typedef struct _%sObjectSkeletonPrivate %sObjectSkeletonPrivate;\n'%(self.namespace, self.namespace))
638 self.h.write('struct _%sObjectSkeleton\n'%(self.namespace))
640 self.h.write(' /*< private >*/\n')
641 self.h.write(' GDBusObjectSkeleton parent_instance;\n')
642 self.h.write(' %sObjectSkeletonPrivate *priv;\n'%(self.namespace))
645 self.h.write('struct _%sObjectSkeletonClass\n'%(self.namespace))
647 self.h.write(' GDBusObjectSkeletonClass parent_class;\n')
650 self.h.write('GType %sobject_skeleton_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
652 if self.generate_autocleanup in ('objects', 'all'):
653 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
654 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectSkeleton, g_object_unref)\n' % (self.namespace))
655 self.h.write('#endif\n')
657 self.h.write('%sObjectSkeleton *%sobject_skeleton_new (const gchar *object_path);\n'
658 %(self.namespace, self.ns_lower))
659 for i in self.ifaces:
661 self.h.write('G_GNUC_DEPRECATED ')
662 self.h.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_);\n'
663 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
666 self.h.write('/* ---- */\n')
668 self.h.write('#define %sTYPE_OBJECT_MANAGER_CLIENT (%sobject_manager_client_get_type ())\n'%(self.ns_upper, self.ns_lower))
669 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))
670 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))
671 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))
672 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))
673 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))
675 self.h.write('typedef struct _%sObjectManagerClient %sObjectManagerClient;\n'%(self.namespace, self.namespace))
676 self.h.write('typedef struct _%sObjectManagerClientClass %sObjectManagerClientClass;\n'%(self.namespace, self.namespace))
677 self.h.write('typedef struct _%sObjectManagerClientPrivate %sObjectManagerClientPrivate;\n'%(self.namespace, self.namespace))
679 self.h.write('struct _%sObjectManagerClient\n'%(self.namespace))
681 self.h.write(' /*< private >*/\n')
682 self.h.write(' GDBusObjectManagerClient parent_instance;\n')
683 self.h.write(' %sObjectManagerClientPrivate *priv;\n'%(self.namespace))
686 self.h.write('struct _%sObjectManagerClientClass\n'%(self.namespace))
688 self.h.write(' GDBusObjectManagerClientClass parent_class;\n')
691 if self.generate_autocleanup in ('objects', 'all'):
692 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
693 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectManagerClient, g_object_unref)\n' % (self.namespace))
694 self.h.write('#endif\n')
696 self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
698 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))
700 self.h.write('void %sobject_manager_client_new (\n'
701 ' GDBusConnection *connection,\n'
702 ' GDBusObjectManagerClientFlags flags,\n'
703 ' const gchar *name,\n'
704 ' const gchar *object_path,\n'
705 ' GCancellable *cancellable,\n'
706 ' GAsyncReadyCallback callback,\n'
707 ' gpointer user_data);\n'
709 self.h.write('GDBusObjectManager *%sobject_manager_client_new_finish (\n'
710 ' GAsyncResult *res,\n'
711 ' GError **error);\n'
713 self.h.write('GDBusObjectManager *%sobject_manager_client_new_sync (\n'
714 ' GDBusConnection *connection,\n'
715 ' GDBusObjectManagerClientFlags flags,\n'
716 ' const gchar *name,\n'
717 ' const gchar *object_path,\n'
718 ' GCancellable *cancellable,\n'
719 ' GError **error);\n'
722 self.h.write('void %sobject_manager_client_new_for_bus (\n'
723 ' GBusType bus_type,\n'
724 ' GDBusObjectManagerClientFlags flags,\n'
725 ' const gchar *name,\n'
726 ' const gchar *object_path,\n'
727 ' GCancellable *cancellable,\n'
728 ' GAsyncReadyCallback callback,\n'
729 ' gpointer user_data);\n'
731 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_finish (\n'
732 ' GAsyncResult *res,\n'
733 ' GError **error);\n'
735 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_sync (\n'
736 ' GBusType bus_type,\n'
737 ' GDBusObjectManagerClientFlags flags,\n'
738 ' const gchar *name,\n'
739 ' const gchar *object_path,\n'
740 ' GCancellable *cancellable,\n'
741 ' GError **error);\n'
745 # ----------------------------------------------------------------------------------------------------
747 def generate_outro(self):
751 '#endif /* __%s__ */\n'%(self.header_guard))
753 # ----------------------------------------------------------------------------------------------------
755 def generate_annotations(self, prefix, annotations):
756 if annotations == None:
760 for a in annotations:
761 #self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
763 # skip internal annotations
764 if a.key.startswith('org.gtk.GDBus'):
767 self.c.write('static const GDBusAnnotationInfo %s_%d =\n'
771 ' (gchar *) "%s",\n'%(prefix, n, a.key, a.value))
772 if len(a.annotations) == 0:
773 self.c.write(' NULL\n')
775 self.c.write(' (GDBusAnnotationInfo **) &%s_%d_pointers\n'%(prefix, n))
781 self.c.write('static const GDBusAnnotationInfo * const %s_pointers[] =\n'
784 for a in annotations:
785 if a.key.startswith('org.gtk.GDBus'):
787 self.c.write(' &%s_%d,\n'%(prefix, m))
789 self.c.write(' NULL\n'
794 def generate_args(self, prefix, args):
796 num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
798 self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
803 ' (gchar *) "%s",\n'%(prefix, a.name, a.name, a.signature))
805 self.c.write(' NULL\n')
807 self.c.write(' (GDBusAnnotationInfo **) &%s_arg_%s_annotation_info_pointers\n'%(prefix, a.name))
808 self.c.write(' },\n')
809 if not utils.lookup_annotation(a.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
810 self.c.write(' FALSE\n')
812 self.c.write(' TRUE\n')
817 self.c.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
820 self.c.write(' &%s_%s,\n'%(prefix, a.name))
821 self.c.write(' NULL\n'
825 def generate_introspection_for_interface(self, i):
826 self.c.write('/* ---- Introspection data for %s ---- */\n'
829 if len(i.methods) > 0:
832 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
834 self.generate_args('_%s_method_info_%s_IN_ARG'%(i.name_lower, m.name_lower), m.in_args)
835 self.generate_args('_%s_method_info_%s_OUT_ARG'%(i.name_lower, m.name_lower), m.out_args)
837 num_anno = self.generate_annotations('_%s_method_%s_annotation_info'%(i.name_lower, m.name_lower), m.annotations)
839 self.c.write('static const _ExtendedGDBusMethodInfo _%s_method_info_%s =\n'
843 ' (gchar *) "%s",\n'%(i.name_lower, m.name_lower, m.name))
844 if len(m.in_args) == 0:
845 self.c.write(' NULL,\n')
847 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_IN_ARG_pointers,\n'%(i.name_lower, m.name_lower))
848 if len(m.out_args) == 0:
849 self.c.write(' NULL,\n')
851 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_OUT_ARG_pointers,\n'%(i.name_lower, m.name_lower))
853 self.c.write(' NULL\n')
855 self.c.write(' (GDBusAnnotationInfo **) &_%s_method_%s_annotation_info_pointers\n'%(i.name_lower, m.name_lower))
859 %(m.name_hyphen, 'TRUE' if unix_fd else 'FALSE'))
863 self.c.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] =\n'
864 '{\n'%(i.name_lower))
866 self.c.write(' &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
867 self.c.write(' NULL\n'
873 if len(i.signals) > 0:
875 self.generate_args('_%s_signal_info_%s_ARG'%(i.name_lower, s.name_lower), s.args)
877 num_anno = self.generate_annotations('_%s_signal_%s_annotation_info'%(i.name_lower, s.name_lower), s.annotations)
878 self.c.write('static const _ExtendedGDBusSignalInfo _%s_signal_info_%s =\n'
882 ' (gchar *) "%s",\n'%(i.name_lower, s.name_lower, s.name))
884 self.c.write(' NULL,\n')
886 self.c.write(' (GDBusArgInfo **) &_%s_signal_info_%s_ARG_pointers,\n'%(i.name_lower, s.name_lower))
888 self.c.write(' NULL\n')
890 self.c.write(' (GDBusAnnotationInfo **) &_%s_signal_%s_annotation_info_pointers\n'%(i.name_lower, s.name_lower))
897 self.c.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
898 '{\n'%(i.name_lower))
900 self.c.write(' &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
901 self.c.write(' NULL\n'
907 if len(i.properties) > 0:
908 for p in i.properties:
909 if p.readable and p.writable:
910 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
912 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE'
914 access = 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
916 access = 'G_DBUS_PROPERTY_INFO_FLAGS_NONE'
917 num_anno = self.generate_annotations('_%s_property_%s_annotation_info'%(i.name_lower, p.name_lower), p.annotations)
918 self.c.write('static const _ExtendedGDBusPropertyInfo _%s_property_info_%s =\n'
924 ' %s,\n'%(i.name_lower, p.name_lower, p.name, p.arg.signature, access))
926 self.c.write(' NULL\n')
928 self.c.write(' (GDBusAnnotationInfo **) &_%s_property_%s_annotation_info_pointers\n'%(i.name_lower, p.name_lower))
932 if not utils.lookup_annotation(p.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
933 self.c.write(' FALSE\n')
935 self.c.write(' TRUE\n')
939 self.c.write('static const _ExtendedGDBusPropertyInfo * const _%s_property_info_pointers[] =\n'
940 '{\n'%(i.name_lower))
941 for p in i.properties:
942 self.c.write(' &_%s_property_info_%s,\n'%(i.name_lower, p.name_lower))
943 self.c.write(' NULL\n'
947 num_anno = self.generate_annotations('_%s_annotation_info'%(i.name_lower), i.annotations)
948 self.c.write('static const _ExtendedGDBusInterfaceInfo _%s_interface_info =\n'
952 ' (gchar *) "%s",\n'%(i.name_lower, i.name))
953 if len(i.methods) == 0:
954 self.c.write(' NULL,\n')
956 self.c.write(' (GDBusMethodInfo **) &_%s_method_info_pointers,\n'%(i.name_lower))
957 if len(i.signals) == 0:
958 self.c.write(' NULL,\n')
960 self.c.write(' (GDBusSignalInfo **) &_%s_signal_info_pointers,\n'%(i.name_lower))
961 if len(i.properties) == 0:
962 self.c.write(' NULL,\n')
964 self.c.write(' (GDBusPropertyInfo **) &_%s_property_info_pointers,\n'%(i.name_lower))
966 self.c.write(' NULL\n')
968 self.c.write(' (GDBusAnnotationInfo **) &_%s_annotation_info_pointers\n'%(i.name_lower))
975 self.c.write(self.docbook_gen.expand(
977 ' * %s_interface_info:\n'
979 ' * Gets a machine-readable description of the #%s D-Bus interface.\n'
981 ' * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free.\n'
982 %(i.name_lower, i.name), False))
983 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
984 self.c.write('GDBusInterfaceInfo *\n'
985 '%s_interface_info (void)\n'
987 ' return (GDBusInterfaceInfo *) &_%s_interface_info.parent_struct;\n'
989 '\n'%(i.name_lower, i.name_lower))
991 self.c.write(self.docbook_gen.expand(
993 ' * %s_override_properties:\n'
994 ' * @klass: The class structure for a #GObject<!-- -->-derived class.\n'
995 ' * @property_id_begin: The property id to assign to the first overridden property.\n'
997 ' * Overrides all #GObject properties in the #%s interface for a concrete class.\n'
998 ' * The properties are overridden in the order they are defined.\n'
1000 ' * Returns: The last property id.\n'
1001 %(i.name_lower, i.camel_name), False))
1002 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1003 self.c.write('guint\n'
1004 '%s_override_properties (GObjectClass *klass, guint property_id_begin)\n'
1005 '{\n'%(i.name_lower))
1006 for p in i.properties:
1007 self.c.write (' g_object_class_override_property (klass, property_id_begin++, "%s");\n'%(p.name_hyphen))
1008 self.c.write(' return property_id_begin - 1;\n'
1013 # ----------------------------------------------------------------------------------------------------
1015 def generate_interface(self, i):
1018 self.c.write(self.docbook_gen.expand(
1022 ' * Abstract interface type for the D-Bus interface #%s.\n'
1023 %(i.camel_name, i.name), False))
1024 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1027 self.c.write(self.docbook_gen.expand(
1030 ' * @parent_iface: The parent interface.\n'
1031 %(i.camel_name), False))
1034 if len(i.methods) > 0:
1036 key = (m.since, '_method_%s'%m.name_lower)
1037 value = '@handle_%s: '%(m.name_lower)
1038 value += 'Handler for the #%s::handle-%s signal.'%(i.camel_name, m.name_hyphen)
1039 doc_bits[key] = value
1040 if len(i.signals) > 0:
1042 key = (s.since, '_signal_%s'%s.name_lower)
1043 value = '@%s: '%(s.name_lower)
1044 value += 'Handler for the #%s::%s signal.'%(i.camel_name, s.name_hyphen)
1045 doc_bits[key] = value
1046 if len(i.properties) > 0:
1047 for p in i.properties:
1048 key = (p.since, '_prop_get_%s'%p.name_lower)
1049 value = '@get_%s: '%(p.name_lower)
1050 value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
1051 doc_bits[key] = value
1052 for key in sorted(doc_bits.keys(), key=utils.version_cmp_key):
1053 self.c.write(' * %s\n'%doc_bits[key])
1055 self.c.write(self.docbook_gen.expand(
1057 ' * Virtual table for the D-Bus interface #%s.\n'
1059 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1062 self.c.write('typedef %sIface %sInterface;\n'%(i.camel_name, i.camel_name))
1063 self.c.write('G_DEFINE_INTERFACE (%s, %s, G_TYPE_OBJECT);\n'%(i.camel_name, i.name_lower))
1066 self.c.write('static void\n'
1067 '%s_default_init (%sIface *iface)\n'
1068 '{\n'%(i.name_lower, i.camel_name));
1070 if len(i.methods) > 0:
1071 self.c.write(' /* GObject signals for incoming D-Bus method calls: */\n')
1074 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1076 self.c.write(self.docbook_gen.expand(
1078 ' * %s::handle-%s:\n'
1079 ' * @object: A #%s.\n'
1080 ' * @invocation: A #GDBusMethodInvocation.\n'
1081 %(i.camel_name, m.name_hyphen, i.camel_name), False))
1083 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1085 self.c.write (' * @arg_%s: Argument passed by remote caller.\n'%(a.name))
1086 self.c.write(self.docbook_gen.expand(
1088 ' * Signal emitted when a remote caller is invoking the %s.%s() D-Bus method.\n'
1090 ' * 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'
1092 ' * Returns: %%TRUE if the invocation was handled, %%FALSE to let other signal handlers run.\n'
1093 %(i.name, m.name, i.name_lower, m.name_lower), False))
1094 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 2)
1099 self.c.write(' g_signal_new ("handle-%s",\n'
1100 ' G_TYPE_FROM_INTERFACE (iface),\n'
1101 ' G_SIGNAL_RUN_LAST,\n'
1102 ' G_STRUCT_OFFSET (%sIface, handle_%s),\n'
1103 ' g_signal_accumulator_true_handled,\n'
1104 ' NULL,\n' # accu_data
1105 ' g_cclosure_marshal_generic,\n'
1106 ' G_TYPE_BOOLEAN,\n'
1108 ' G_TYPE_DBUS_METHOD_INVOCATION'
1109 %(m.name_hyphen, i.camel_name, m.name_lower, len(m.in_args) + extra_args))
1111 self.c.write(', G_TYPE_UNIX_FD_LIST')
1113 self.c.write (', %s'%(a.gtype))
1114 self.c.write(');\n')
1117 if len(i.signals) > 0:
1118 self.c.write(' /* GObject signals for received D-Bus signals: */\n')
1120 self.c.write(self.docbook_gen.expand(
1123 ' * @object: A #%s.\n'
1124 %(i.camel_name, s.name_hyphen, i.camel_name), False))
1126 self.c.write (' * @arg_%s: Argument.\n'%(a.name))
1127 self.c.write(self.docbook_gen.expand(
1129 ' * On the client-side, this signal is emitted whenever the D-Bus signal #%s::%s is received.\n'
1131 ' * 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'
1132 %(i.name, s.name), False))
1133 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 2)
1134 self.c.write(' g_signal_new ("%s",\n'
1135 ' G_TYPE_FROM_INTERFACE (iface),\n'
1136 ' G_SIGNAL_RUN_LAST,\n'
1137 ' G_STRUCT_OFFSET (%sIface, %s),\n'
1138 ' NULL,\n' # accumulator
1139 ' NULL,\n' # accu_data
1140 ' g_cclosure_marshal_generic,\n'
1143 %(s.name_hyphen, i.camel_name, s.name_lower, len(s.args)))
1145 self.c.write (', %s'%(a.gtype))
1146 self.c.write(');\n')
1149 if len(i.properties) > 0:
1150 self.c.write(' /* GObject properties for D-Bus properties: */\n')
1151 for p in i.properties:
1152 if p.readable and p.writable:
1153 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.'
1155 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.'
1157 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.'
1159 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1160 self.c.write(self.docbook_gen.expand(
1164 ' * Represents the D-Bus property #%s:%s.\n'
1167 %(i.camel_name, p.name_hyphen, i.name, p.name, hint), False))
1168 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 2)
1169 self.c.write(' g_object_interface_install_property (iface,\n')
1170 if p.arg.gtype == 'G_TYPE_VARIANT':
1171 s = 'g_param_spec_variant ("%s", "%s", "%s", G_VARIANT_TYPE ("%s"), NULL'%(p.name_hyphen, p.name, p.name, p.arg.signature)
1172 elif p.arg.signature == 'b':
1173 s = 'g_param_spec_boolean ("%s", "%s", "%s", FALSE'%(p.name_hyphen, p.name, p.name)
1174 elif p.arg.signature == 'y':
1175 s = 'g_param_spec_uchar ("%s", "%s", "%s", 0, 255, 0'%(p.name_hyphen, p.name, p.name)
1176 elif p.arg.signature == 'n':
1177 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT16, G_MAXINT16, 0'%(p.name_hyphen, p.name, p.name)
1178 elif p.arg.signature == 'q':
1179 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT16, 0'%(p.name_hyphen, p.name, p.name)
1180 elif p.arg.signature == 'i':
1181 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT32, G_MAXINT32, 0'%(p.name_hyphen, p.name, p.name)
1182 elif p.arg.signature == 'u':
1183 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT32, 0'%(p.name_hyphen, p.name, p.name)
1184 elif p.arg.signature == 'x':
1185 s = 'g_param_spec_int64 ("%s", "%s", "%s", G_MININT64, G_MAXINT64, 0'%(p.name_hyphen, p.name, p.name)
1186 elif p.arg.signature == 't':
1187 s = 'g_param_spec_uint64 ("%s", "%s", "%s", 0, G_MAXUINT64, 0'%(p.name_hyphen, p.name, p.name)
1188 elif p.arg.signature == 'd':
1189 s = 'g_param_spec_double ("%s", "%s", "%s", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0'%(p.name_hyphen, p.name, p.name)
1190 elif p.arg.signature == 's':
1191 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1192 elif p.arg.signature == 'o':
1193 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1194 elif p.arg.signature == 'g':
1195 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1196 elif p.arg.signature == 'ay':
1197 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1198 elif p.arg.signature == 'as':
1199 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1200 elif p.arg.signature == 'ao':
1201 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1202 elif p.arg.signature == 'aay':
1203 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1205 raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
1206 self.c.write(' %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
1212 # ----------------------------------------------------------------------------------------------------
1214 def generate_property_accessors(self, i):
1215 for p in i.properties:
1217 if p.readable and p.writable:
1218 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.'
1220 hint = 'Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.'
1222 hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
1224 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1225 self.c.write(self.docbook_gen.expand(
1227 ' * %s_get_%s: (skip)\n'
1228 ' * @object: A #%s.\n'
1230 ' * Gets the value of the #%s:%s D-Bus property.\n'
1234 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1235 if p.arg.free_func != None:
1236 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'
1238 ' * 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'
1239 %(i.name_lower, p.name_lower))
1241 self.c.write(' * Returns: The property value.\n')
1242 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1244 '%s_get_%s (%s *object)\n'
1245 '{\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
1246 self.c.write(' return %s%s_GET_IFACE (object)->get_%s (object);\n'%(i.ns_upper, i.name_upper, p.name_lower))
1249 if p.arg.free_func != None:
1251 self.c.write(self.docbook_gen.expand(
1253 ' * %s_dup_%s: (skip)\n'
1254 ' * @object: A #%s.\n'
1256 ' * Gets a copy of the #%s:%s D-Bus property.\n'
1260 ' * Returns: (transfer full): The property value or %%NULL if the property is not set. The returned value should be freed with %s().\n'
1261 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint, p.arg.free_func), False))
1262 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1264 '%s_dup_%s (%s *object)\n'
1266 ' %svalue;\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in_dup))
1267 self.c.write(' g_object_get (G_OBJECT (object), "%s", &value, NULL);\n'%(p.name_hyphen))
1268 self.c.write(' return value;\n')
1273 if p.readable and p.writable:
1274 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.'
1276 hint = 'Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.'
1278 hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
1280 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1281 self.c.write(self.docbook_gen.expand(
1283 ' * %s_set_%s: (skip)\n'
1284 ' * @object: A #%s.\n'
1285 ' * @value: The value to set.\n'
1287 ' * Sets the #%s:%s D-Bus property to @value.\n'
1290 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1291 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1292 self.c.write('void\n'
1293 '%s_set_%s (%s *object, %svalue)\n'
1294 '{\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
1295 self.c.write(' g_object_set (G_OBJECT (object), "%s", value, NULL);\n'%(p.name_hyphen))
1299 # ---------------------------------------------------------------------------------------------------
1301 def generate_signal_emitters(self, i):
1303 self.c.write(self.docbook_gen.expand(
1306 ' * @object: A #%s.\n'
1307 %(i.name_lower, s.name_lower, i.camel_name), False))
1309 self.c.write(' * @arg_%s: Argument to pass with the signal.\n'%(a.name))
1310 self.c.write(self.docbook_gen.expand(
1312 ' * Emits the #%s::%s D-Bus signal.\n'
1313 %(i.name, s.name), False))
1314 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 0)
1315 self.c.write('void\n'
1317 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
1319 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1322 ' g_signal_emit_by_name (object, "%s"'%(s.name_hyphen))
1324 self.c.write(', arg_%s'%a.name)
1325 self.c.write(');\n')
1329 # ---------------------------------------------------------------------------------------------------
1331 def generate_method_calls(self, i):
1334 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1337 self.c.write('/**\n'
1339 ' * @proxy: A #%sProxy.\n'
1340 %(i.name_lower, m.name_lower, i.camel_name))
1342 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1344 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1345 self.c.write(self.docbook_gen.expand(
1346 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1347 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %%NULL.\n'
1348 ' * @user_data: User data to pass to @callback.\n'
1350 ' * Asynchronously invokes the %s.%s() D-Bus method on @proxy.\n'
1351 ' * 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'
1352 ' * You can then call %s_call_%s_finish() to get the result of the operation.\n'
1354 ' * See %s_call_%s_sync() for the synchronous, blocking version of this method.\n'
1355 %(i.name, m.name, i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1356 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1357 self.c.write('void\n'
1359 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1361 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1363 self.c.write(',\n GUnixFDList *fd_list')
1365 ' GCancellable *cancellable,\n'
1366 ' GAsyncReadyCallback callback,\n'
1367 ' gpointer user_data)\n'
1370 self.c.write(' g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy),\n')
1372 self.c.write(' g_dbus_proxy_call (G_DBUS_PROXY (proxy),\n')
1373 self.c.write(' "%s",\n'
1374 ' g_variant_new ("('%(m.name))
1376 self.c.write('%s'%(a.format_in))
1379 self.c.write(',\n arg_%s'%(a.name))
1381 ' G_DBUS_CALL_FLAGS_NONE,\n'
1384 self.c.write(' fd_list,\n')
1385 self.c.write(' cancellable,\n'
1391 self.c.write('/**\n'
1392 ' * %s_call_%s_finish:\n'
1393 ' * @proxy: A #%sProxy.\n'
1394 %(i.name_lower, m.name_lower, i.camel_name))
1395 for a in m.out_args:
1396 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1398 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1399 self.c.write(self.docbook_gen.expand(
1400 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_call_%s().\n'
1401 ' * @error: Return location for error or %%NULL.\n'
1403 ' * Finishes an operation started with %s_call_%s().\n'
1405 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1406 %(i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1407 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1408 self.c.write('gboolean\n'
1409 '%s_call_%s_finish (\n'
1410 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1411 for a in m.out_args:
1412 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1414 self.c.write(',\n GUnixFDList **out_fd_list')
1416 ' GAsyncResult *res,\n'
1417 ' GError **error)\n'
1419 ' GVariant *_ret;\n')
1421 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error);\n')
1423 self.c.write(' _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);\n')
1424 self.c.write(' if (_ret == NULL)\n'
1426 self.c.write(' g_variant_get (_ret,\n'
1428 for a in m.out_args:
1429 self.c.write('%s'%(a.format_out))
1431 for a in m.out_args:
1432 self.c.write(',\n out_%s'%(a.name))
1434 ' g_variant_unref (_ret);\n')
1435 self.c.write('_out:\n'
1436 ' return _ret != NULL;\n'
1442 self.c.write('/**\n'
1443 ' * %s_call_%s_sync:\n'
1444 ' * @proxy: A #%sProxy.\n'
1445 %(i.name_lower, m.name_lower, i.camel_name))
1447 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1449 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1450 for a in m.out_args:
1451 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1453 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1454 self.c.write(self.docbook_gen.expand(
1455 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1456 ' * @error: Return location for error or %%NULL.\n'
1458 ' * Synchronously invokes the %s.%s() D-Bus method on @proxy. The calling thread is blocked until a reply is received.\n'
1460 ' * See %s_call_%s() for the asynchronous version of this method.\n'
1462 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1463 %(i.name, m.name, i.name_lower, m.name_lower), False))
1464 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1465 self.c.write('gboolean\n'
1466 '%s_call_%s_sync (\n'
1467 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1469 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1471 self.c.write(',\n GUnixFDList *fd_list')
1472 for a in m.out_args:
1473 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1475 self.c.write(',\n GUnixFDList **out_fd_list')
1477 ' GCancellable *cancellable,\n'
1478 ' GError **error)\n'
1480 ' GVariant *_ret;\n')
1482 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy),\n')
1484 self.c.write(' _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),\n')
1485 self.c.write(' "%s",\n'
1486 ' g_variant_new ("('%(m.name))
1488 self.c.write('%s'%(a.format_in))
1491 self.c.write(',\n arg_%s'%(a.name))
1493 ' G_DBUS_CALL_FLAGS_NONE,\n'
1496 self.c.write(' fd_list,\n'
1498 self.c.write(' cancellable,\n'
1500 ' if (_ret == NULL)\n'
1502 self.c.write(' g_variant_get (_ret,\n'
1504 for a in m.out_args:
1505 self.c.write('%s'%(a.format_out))
1507 for a in m.out_args:
1508 self.c.write(',\n out_%s'%(a.name))
1510 ' g_variant_unref (_ret);\n')
1511 self.c.write('_out:\n'
1512 ' return _ret != NULL;\n'
1516 # ---------------------------------------------------------------------------------------------------
1518 def generate_method_completers(self, i):
1521 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1523 self.c.write('/**\n'
1524 ' * %s_complete_%s:\n'
1525 ' * @object: A #%s.\n'
1526 ' * @invocation: (transfer full): A #GDBusMethodInvocation.\n'
1527 %(i.name_lower, m.name_lower, i.camel_name))
1529 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1530 for a in m.out_args:
1531 self.c.write(' * @%s: Parameter to return.\n'%(a.name))
1532 self.c.write(self.docbook_gen.expand(
1534 ' * 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'
1536 ' * This method will free @invocation, you cannot use it afterwards.\n'
1537 %(i.name, m.name), False))
1538 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1539 self.c.write('void\n'
1540 '%s_complete_%s (\n'
1542 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
1544 self.c.write(',\n GUnixFDList *fd_list')
1545 for a in m.out_args:
1546 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1551 self.c.write(' g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,\n'
1552 ' g_variant_new ("(')
1554 self.c.write(' g_dbus_method_invocation_return_value (invocation,\n'
1555 ' g_variant_new ("(')
1556 for a in m.out_args:
1557 self.c.write('%s'%(a.format_in))
1559 for a in m.out_args:
1560 self.c.write(',\n %s'%(a.name))
1562 self.c.write('),\n fd_list);\n')
1564 self.c.write('));\n')
1568 # ---------------------------------------------------------------------------------------------------
1570 def generate_proxy(self, i):
1572 self.c.write('/* ------------------------------------------------------------------------ */\n'
1575 self.c.write(self.docbook_gen.expand(
1579 ' * The #%sProxy structure contains only private data and should only be accessed using the provided API.\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(self.docbook_gen.expand(
1586 ' * %sProxyClass:\n'
1587 ' * @parent_class: The parent class.\n'
1589 ' * Class structure for #%sProxy.\n'
1590 %(i.camel_name, i.camel_name), False))
1591 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1594 self.c.write('struct _%sProxyPrivate\n'
1600 self.c.write('static void %s_proxy_iface_init (%sIface *iface);\n'
1601 '\n'%(i.name_lower, i.camel_name))
1602 self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
1603 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1604 self.c.write(' G_ADD_PRIVATE (%sProxy)\n'%(i.camel_name))
1605 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1606 self.c.write('#else\n')
1607 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1608 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1609 self.c.write('#endif\n')
1612 self.c.write('static void\n'
1613 '%s_proxy_finalize (GObject *object)\n'
1614 '{\n'%(i.name_lower))
1615 self.c.write(' %sProxy *proxy = %s%s_PROXY (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
1616 self.c.write(' g_datalist_clear (&proxy->priv->qdata);\n')
1617 self.c.write(' G_OBJECT_CLASS (%s_proxy_parent_class)->finalize (object);\n'
1619 '\n'%(i.name_lower))
1621 # property accessors
1623 # Note that we are guaranteed that prop_id starts at 1 and is
1624 # laid out in the same order as introspection data pointers
1626 self.c.write('static void\n'
1627 '%s_proxy_get_property (GObject *object,\n'
1630 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
1631 '{\n'%(i.name_lower))
1632 if len(i.properties) > 0:
1633 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1634 ' GVariant *variant;\n'
1635 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1636 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1637 ' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
1638 ' if (info->use_gvariant)\n'
1640 ' g_value_set_variant (value, variant);\n'
1644 # could be that we don't have the value in cache - in that case, we do
1645 # nothing and the user gets the default value for the GType
1646 ' if (variant != NULL)\n'
1647 ' g_dbus_gvariant_to_gvalue (variant, value);\n'
1649 ' if (variant != NULL)\n'
1650 ' g_variant_unref (variant);\n'
1651 %(len(i.properties), i.name_lower))
1654 if len(i.properties) > 0:
1655 self.c.write('static void\n'
1656 '%s_proxy_set_property_cb (GDBusProxy *proxy,\n'
1657 ' GAsyncResult *res,\n'
1658 ' gpointer user_data)\n'
1659 '{\n'%(i.name_lower))
1660 self.c.write(' const _ExtendedGDBusPropertyInfo *info = user_data;\n'
1662 ' GVariant *_ret;\n'
1664 ' _ret = g_dbus_proxy_call_finish (proxy, res, &error);\n'
1667 ' g_warning ("Error setting property \'%%s\' on interface %s: %%s (%%s, %%d)",\n'
1668 ' info->parent_struct.name, \n'
1669 ' error->message, g_quark_to_string (error->domain), error->code);\n'
1670 ' g_error_free (error);\n'
1674 ' g_variant_unref (_ret);\n'
1679 self.c.write('static void\n'
1680 '%s_proxy_set_property (GObject *object,\n'
1682 ' const GValue *value,\n'
1683 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
1684 '{\n'%(i.name_lower))
1685 if len(i.properties) > 0:
1686 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1687 ' GVariant *variant;\n'
1688 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1689 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1690 ' variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
1691 ' g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
1692 ' "org.freedesktop.DBus.Properties.Set",\n'
1693 ' g_variant_new ("(ssv)", "%s", info->parent_struct.name, variant),\n'
1694 ' G_DBUS_CALL_FLAGS_NONE,\n'
1696 ' NULL, (GAsyncReadyCallback) %s_proxy_set_property_cb, (GDBusPropertyInfo *) &info->parent_struct);\n'
1697 ' g_variant_unref (variant);\n'
1698 %(len(i.properties), i.name_lower, i.name, i.name_lower))
1703 self.c.write('static void\n'
1704 '%s_proxy_g_signal (GDBusProxy *proxy,\n'
1705 ' const gchar *sender_name G_GNUC_UNUSED,\n'
1706 ' const gchar *signal_name,\n'
1707 ' GVariant *parameters)\n'
1708 '{\n'%(i.name_lower))
1709 self.c.write(' _ExtendedGDBusSignalInfo *info;\n'
1710 ' GVariantIter iter;\n'
1711 ' GVariant *child;\n'
1712 ' GValue *paramv;\n'
1713 ' guint num_params;\n'
1715 ' guint signal_id;\n');
1716 # Note: info could be NULL if we are talking to a newer version of the interface
1717 self.c.write(' info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, signal_name);\n'
1718 ' if (info == NULL)\n'
1721 self.c.write (' num_params = g_variant_n_children (parameters);\n'
1722 ' paramv = g_new0 (GValue, num_params + 1);\n'
1723 ' g_value_init (¶mv[0], %sTYPE_%s);\n'
1724 ' g_value_set_object (¶mv[0], proxy);\n'
1725 %(i.ns_upper, i.name_upper))
1726 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
1728 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
1730 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1];\n'
1731 ' if (arg_info->use_gvariant)\n'
1733 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
1734 ' g_value_set_variant (¶mv[n], child);\n'
1738 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
1739 ' g_variant_unref (child);\n'
1742 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
1743 %(i.ns_upper, i.name_upper))
1744 self.c.write(' g_signal_emitv (paramv, signal_id, 0, NULL);\n')
1745 self.c.write(' for (n = 0; n < num_params + 1; n++)\n'
1746 ' g_value_unset (¶mv[n]);\n'
1747 ' g_free (paramv);\n')
1752 self.c.write('static void\n'
1753 '%s_proxy_g_properties_changed (GDBusProxy *_proxy,\n'
1754 ' GVariant *changed_properties,\n'
1755 ' const gchar *const *invalidated_properties)\n'
1756 '{\n'%(i.name_lower))
1757 # Note: info could be NULL if we are talking to a newer version of the interface
1758 self.c.write(' %sProxy *proxy = %s%s_PROXY (_proxy);\n'
1760 ' const gchar *key;\n'
1761 ' GVariantIter *iter;\n'
1762 ' _ExtendedGDBusPropertyInfo *info;\n'
1763 ' g_variant_get (changed_properties, "a{sv}", &iter);\n'
1764 ' while (g_variant_iter_next (iter, "{&sv}", &key, NULL))\n'
1766 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, key);\n'
1767 ' g_datalist_remove_data (&proxy->priv->qdata, key);\n'
1768 ' if (info != NULL)\n'
1769 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1771 ' g_variant_iter_free (iter);\n'
1772 ' for (n = 0; invalidated_properties[n] != NULL; n++)\n'
1774 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, invalidated_properties[n]);\n'
1775 ' g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]);\n'
1776 ' if (info != NULL)\n'
1777 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1781 %(i.camel_name, i.ns_upper, i.name_upper,
1782 i.name_lower, i.name_lower))
1785 for p in i.properties:
1787 if p.arg.free_func != None:
1789 self.c.write('static %s\n'
1790 '%s_proxy_get_%s (%s *object)\n'
1792 ' %sProxy *proxy = %s%s_PROXY (object);\n'
1793 ' GVariant *variant;\n'
1794 ' %svalue = %s;\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name,
1795 i.camel_name, i.ns_upper, i.name_upper,
1796 p.arg.ctype_in, nul_value))
1797 # For some property types, we have to free the returned
1798 # value (or part of it, e.g. the container) because of how
1799 # GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
1802 free_container = False;
1803 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':
1804 free_container = True;
1805 # If already using an old value for strv, objpathv, bytestring_array (see below),
1806 # then just return that... that way the result from multiple consecutive calls
1807 # to the getter are valid as long as they're freed
1810 self.c.write(' value = g_datalist_get_data (&proxy->priv->qdata, \"%s\");\n'
1811 ' if (value != NULL)\n'
1814 self.c.write(' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \"%s\");\n'%(p.name))
1815 if p.arg.gtype == 'G_TYPE_VARIANT':
1816 self.c.write(' value = variant;\n')
1817 self.c.write(' if (variant != NULL)\n')
1818 self.c.write(' g_variant_unref (variant);\n')
1820 self.c.write(' if (variant != NULL)\n'
1823 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':
1824 extra_len = ', NULL'
1825 self.c.write(' value = %s (variant%s);\n'%(p.arg.gvariant_get, extra_len))
1827 self.c.write(' g_datalist_set_data_full (&proxy->priv->qdata, \"%s\", (gpointer) value, g_free);\n'
1829 self.c.write(' g_variant_unref (variant);\n')
1830 self.c.write(' }\n')
1831 self.c.write(' return value;\n')
1836 self.c.write('static void\n'
1837 '%s_proxy_init (%sProxy *proxy)\n'
1839 '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
1840 ' proxy->priv = %s_proxy_get_instance_private (proxy);\n'
1842 ' proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %sTYPE_%s_PROXY, %sProxyPrivate);\n'
1844 ' g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
1847 %(i.name_lower, i.camel_name,
1849 i.ns_upper, i.name_upper, i.camel_name,
1851 self.c.write('static void\n'
1852 '%s_proxy_class_init (%sProxyClass *klass)\n'
1854 ' GObjectClass *gobject_class;\n'
1855 ' GDBusProxyClass *proxy_class;\n'
1857 ' gobject_class = G_OBJECT_CLASS (klass);\n'
1858 ' gobject_class->finalize = %s_proxy_finalize;\n'
1859 ' gobject_class->get_property = %s_proxy_get_property;\n'
1860 ' gobject_class->set_property = %s_proxy_set_property;\n'
1862 ' proxy_class = G_DBUS_PROXY_CLASS (klass);\n'
1863 ' proxy_class->g_signal = %s_proxy_g_signal;\n'
1864 ' proxy_class->g_properties_changed = %s_proxy_g_properties_changed;\n'
1865 '\n'%(i.name_lower, i.camel_name,
1866 i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
1867 if len(i.properties) > 0:
1868 self.c.write(' %s_override_properties (gobject_class, 1);\n\n'%(i.name_lower))
1869 self.c.write('#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
1870 ' g_type_class_add_private (klass, sizeof (%sProxyPrivate));\n'
1871 '#endif\n'%(i.camel_name))
1875 self.c.write('static void\n'
1876 '%s_proxy_iface_init (%sIface *iface)\n'
1877 '{\n'%(i.name_lower, i.camel_name))
1878 for p in i.properties:
1879 self.c.write(' iface->get_%s = %s_proxy_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
1884 self.c.write(self.docbook_gen.expand(
1886 ' * %s_proxy_new:\n'
1887 ' * @connection: A #GDBusConnection.\n'
1888 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1889 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1890 ' * @object_path: An object path.\n'
1891 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1892 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1893 ' * @user_data: User data to pass to @callback.\n'
1895 ' * Asynchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new() for more details.\n'
1897 ' * 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'
1898 ' * You can then call %s_proxy_new_finish() to get the result of the operation.\n'
1900 ' * See %s_proxy_new_sync() for the synchronous, blocking version of this constructor.\n'
1901 %(i.name_lower, i.name, i.name_lower, i.name_lower), False))
1902 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1903 self.c.write('void\n'
1905 ' GDBusConnection *connection,\n'
1906 ' GDBusProxyFlags flags,\n'
1907 ' const gchar *name,\n'
1908 ' const gchar *object_path,\n'
1909 ' GCancellable *cancellable,\n'
1910 ' GAsyncReadyCallback callback,\n'
1911 ' gpointer user_data)\n'
1913 ' 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'
1916 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1917 self.c.write('/**\n'
1918 ' * %s_proxy_new_finish:\n'
1919 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new().\n'
1920 ' * @error: Return location for error or %%NULL\n'
1922 ' * Finishes an operation started with %s_proxy_new().\n'
1924 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1925 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1926 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1927 self.c.write('%s *\n'
1928 '%s_proxy_new_finish (\n'
1929 ' GAsyncResult *res,\n'
1930 ' GError **error)\n'
1933 ' GObject *source_object;\n'
1934 ' source_object = g_async_result_get_source_object (res);\n'
1935 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1936 ' g_object_unref (source_object);\n'
1937 ' if (ret != NULL)\n'
1938 ' return %s%s (ret);\n'
1943 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1944 self.c.write(self.docbook_gen.expand(
1946 ' * %s_proxy_new_sync:\n'
1947 ' * @connection: A #GDBusConnection.\n'
1948 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1949 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1950 ' * @object_path: An object path.\n'
1951 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1952 ' * @error: Return location for error or %%NULL\n'
1954 ' * Synchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new_sync() for more details.\n'
1956 ' * The calling thread is blocked until a reply is received.\n'
1958 ' * See %s_proxy_new() for the asynchronous version of this constructor.\n'
1960 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1961 %(i.name_lower, i.name, i.name_lower, i.camel_name), False))
1962 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1963 self.c.write('%s *\n'
1964 '%s_proxy_new_sync (\n'
1965 ' GDBusConnection *connection,\n'
1966 ' GDBusProxyFlags flags,\n'
1967 ' const gchar *name,\n'
1968 ' const gchar *object_path,\n'
1969 ' GCancellable *cancellable,\n'
1970 ' GError **error)\n'
1972 ' GInitable *ret;\n'
1973 ' 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'
1974 ' if (ret != NULL)\n'
1975 ' return %s%s (ret);\n'
1980 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
1982 self.c.write(self.docbook_gen.expand(
1984 ' * %s_proxy_new_for_bus:\n'
1985 ' * @bus_type: A #GBusType.\n'
1986 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1987 ' * @name: A bus name (well-known or unique).\n'
1988 ' * @object_path: An object path.\n'
1989 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1990 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1991 ' * @user_data: User data to pass to @callback.\n'
1993 ' * Like %s_proxy_new() but takes a #GBusType instead of a #GDBusConnection.\n'
1995 ' * 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'
1996 ' * You can then call %s_proxy_new_for_bus_finish() to get the result of the operation.\n'
1998 ' * See %s_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
1999 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower), False))
2000 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2001 self.c.write('void\n'
2002 '%s_proxy_new_for_bus (\n'
2003 ' GBusType bus_type,\n'
2004 ' GDBusProxyFlags flags,\n'
2005 ' const gchar *name,\n'
2006 ' const gchar *object_path,\n'
2007 ' GCancellable *cancellable,\n'
2008 ' GAsyncReadyCallback callback,\n'
2009 ' gpointer user_data)\n'
2011 ' 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'
2014 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
2015 self.c.write('/**\n'
2016 ' * %s_proxy_new_for_bus_finish:\n'
2017 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new_for_bus().\n'
2018 ' * @error: Return location for error or %%NULL\n'
2020 ' * Finishes an operation started with %s_proxy_new_for_bus().\n'
2022 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2023 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
2024 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2025 self.c.write('%s *\n'
2026 '%s_proxy_new_for_bus_finish (\n'
2027 ' GAsyncResult *res,\n'
2028 ' GError **error)\n'
2031 ' GObject *source_object;\n'
2032 ' source_object = g_async_result_get_source_object (res);\n'
2033 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
2034 ' g_object_unref (source_object);\n'
2035 ' if (ret != NULL)\n'
2036 ' return %s%s (ret);\n'
2041 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
2042 self.c.write(self.docbook_gen.expand(
2044 ' * %s_proxy_new_for_bus_sync:\n'
2045 ' * @bus_type: A #GBusType.\n'
2046 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
2047 ' * @name: A bus name (well-known or unique).\n'
2048 ' * @object_path: An object path.\n'
2049 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
2050 ' * @error: Return location for error or %%NULL\n'
2052 ' * Like %s_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
2054 ' * The calling thread is blocked until a reply is received.\n'
2056 ' * See %s_proxy_new_for_bus() for the asynchronous version of this constructor.\n'
2058 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2059 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name), False))
2060 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2061 self.c.write('%s *\n'
2062 '%s_proxy_new_for_bus_sync (\n'
2063 ' GBusType bus_type,\n'
2064 ' GDBusProxyFlags flags,\n'
2065 ' const gchar *name,\n'
2066 ' const gchar *object_path,\n'
2067 ' GCancellable *cancellable,\n'
2068 ' GError **error)\n'
2070 ' GInitable *ret;\n'
2071 ' 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'
2072 ' if (ret != NULL)\n'
2073 ' return %s%s (ret);\n'
2078 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
2081 # ---------------------------------------------------------------------------------------------------
2083 def generate_skeleton(self, i):
2085 self.c.write('/* ------------------------------------------------------------------------ */\n'
2088 self.c.write(self.docbook_gen.expand(
2092 ' * The #%sSkeleton structure contains only private data and should only be accessed using the provided API.\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(self.docbook_gen.expand(
2099 ' * %sSkeletonClass:\n'
2100 ' * @parent_class: The parent class.\n'
2102 ' * Class structure for #%sSkeleton.\n'
2103 %(i.camel_name, i.camel_name), False))
2104 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2107 self.c.write('struct _%sSkeletonPrivate\n'
2109 ' GValue *properties;\n'
2110 ' GList *changed_properties;\n'
2111 ' GSource *changed_properties_idle_source;\n'
2112 ' GMainContext *context;\n'
2117 self.c.write('static void\n'
2118 '_%s_skeleton_handle_method_call (\n'
2119 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2120 ' const gchar *sender G_GNUC_UNUSED,\n'
2121 ' const gchar *object_path G_GNUC_UNUSED,\n'
2122 ' const gchar *interface_name,\n'
2123 ' const gchar *method_name,\n'
2124 ' GVariant *parameters,\n'
2125 ' GDBusMethodInvocation *invocation,\n'
2126 ' gpointer user_data)\n'
2128 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2129 ' _ExtendedGDBusMethodInfo *info;\n'
2130 ' GVariantIter iter;\n'
2131 ' GVariant *child;\n'
2132 ' GValue *paramv;\n'
2133 ' guint num_params;\n'
2134 ' guint num_extra;\n'
2136 ' guint signal_id;\n'
2137 ' GValue return_value = G_VALUE_INIT;\n'
2138 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2139 self.c.write(' info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n'
2140 ' g_assert (info != NULL);\n'
2142 self.c.write (' num_params = g_variant_n_children (parameters);\n'
2143 ' num_extra = info->pass_fdlist ? 3 : 2;'
2144 ' paramv = g_new0 (GValue, num_params + num_extra);\n'
2146 ' g_value_init (¶mv[n], %sTYPE_%s);\n'
2147 ' g_value_set_object (¶mv[n++], skeleton);\n'
2148 ' g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION);\n'
2149 ' g_value_set_object (¶mv[n++], invocation);\n'
2150 ' if (info->pass_fdlist)\n'
2152 '#ifdef G_OS_UNIX\n'
2153 ' g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST);\n'
2154 ' g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)));\n'
2156 ' g_assert_not_reached ();\n'
2159 %(i.ns_upper, i.name_upper))
2160 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
2161 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
2163 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra];\n'
2164 ' if (arg_info->use_gvariant)\n'
2166 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
2167 ' g_value_set_variant (¶mv[n], child);\n'
2171 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
2172 ' g_variant_unref (child);\n'
2175 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
2176 %(i.ns_upper, i.name_upper))
2177 self.c.write(' g_value_init (&return_value, G_TYPE_BOOLEAN);\n'
2178 ' g_signal_emitv (paramv, signal_id, 0, &return_value);\n'
2179 ' if (!g_value_get_boolean (&return_value))\n'
2180 ' 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'
2181 ' g_value_unset (&return_value);\n'
2183 self.c.write(' for (n = 0; n < num_params + num_extra; n++)\n'
2184 ' g_value_unset (¶mv[n]);\n'
2185 ' g_free (paramv);\n')
2189 self.c.write('static GVariant *\n'
2190 '_%s_skeleton_handle_get_property (\n'
2191 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2192 ' const gchar *sender G_GNUC_UNUSED,\n'
2193 ' const gchar *object_path G_GNUC_UNUSED,\n'
2194 ' const gchar *interface_name G_GNUC_UNUSED,\n'
2195 ' const gchar *property_name,\n'
2196 ' GError **error,\n'
2197 ' gpointer user_data)\n'
2199 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2200 ' GValue value = G_VALUE_INIT;\n'
2201 ' GParamSpec *pspec;\n'
2202 ' _ExtendedGDBusPropertyInfo *info;\n'
2204 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2205 self.c.write(' ret = NULL;\n'
2206 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2207 ' g_assert (info != NULL);\n'
2208 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2209 ' if (pspec == NULL)\n'
2211 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2215 ' g_value_init (&value, pspec->value_type);\n'
2216 ' g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2217 ' ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
2218 ' g_value_unset (&value);\n'
2225 self.c.write('static gboolean\n'
2226 '_%s_skeleton_handle_set_property (\n'
2227 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2228 ' const gchar *sender G_GNUC_UNUSED,\n'
2229 ' const gchar *object_path G_GNUC_UNUSED,\n'
2230 ' const gchar *interface_name G_GNUC_UNUSED,\n'
2231 ' const gchar *property_name,\n'
2232 ' GVariant *variant,\n'
2233 ' GError **error,\n'
2234 ' gpointer user_data)\n'
2236 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2237 ' GValue value = G_VALUE_INIT;\n'
2238 ' GParamSpec *pspec;\n'
2239 ' _ExtendedGDBusPropertyInfo *info;\n'
2241 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2242 self.c.write(' ret = FALSE;\n'
2243 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2244 ' g_assert (info != NULL);\n'
2245 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2246 ' if (pspec == NULL)\n'
2248 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2252 ' if (info->use_gvariant)\n'
2253 ' g_value_set_variant (&value, variant);\n'
2255 ' g_dbus_gvariant_to_gvalue (variant, &value);\n'
2256 ' g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2257 ' g_value_unset (&value);\n'
2266 self.c.write('static const GDBusInterfaceVTable _%s_skeleton_vtable =\n'
2268 ' _%s_skeleton_handle_method_call,\n'
2269 ' _%s_skeleton_handle_get_property,\n'
2270 ' _%s_skeleton_handle_set_property,\n'
2273 '\n'%(i.name_lower, i.name_lower, i.name_lower, i.name_lower))
2275 self.c.write('static GDBusInterfaceInfo *\n'
2276 '%s_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2278 ' return %s_interface_info ();\n'
2279 %(i.name_lower, i.name_lower))
2283 self.c.write('static GDBusInterfaceVTable *\n'
2284 '%s_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2286 ' return (GDBusInterfaceVTable *) &_%s_skeleton_vtable;\n'
2287 %(i.name_lower, i.name_lower))
2291 self.c.write('static GVariant *\n'
2292 '%s_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton)\n'
2294 ' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2295 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2297 ' GVariantBuilder builder;\n'
2299 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2300 ' if (_%s_interface_info.parent_struct.properties == NULL)\n'
2302 ' for (n = 0; _%s_interface_info.parent_struct.properties[n] != NULL; n++)\n'
2304 ' GDBusPropertyInfo *info = _%s_interface_info.parent_struct.properties[n];\n'
2305 ' if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)\n'
2307 ' GVariant *value;\n'
2308 ' 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'
2309 ' if (value != NULL)\n'
2311 ' g_variant_take_ref (value);\n'
2312 ' g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
2313 ' g_variant_unref (value);\n'
2318 ' return g_variant_builder_end (&builder);\n'
2321 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name))
2323 if len(i.properties) > 0:
2324 self.c.write('static gboolean _%s_emit_changed (gpointer user_data);\n'
2328 self.c.write('static void\n'
2329 '%s_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton)\n'
2332 if len(i.properties) > 0:
2333 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2334 ' gboolean emit_changed = FALSE;\n'
2336 ' g_mutex_lock (&skeleton->priv->lock);\n'
2337 ' if (skeleton->priv->changed_properties_idle_source != NULL)\n'
2339 ' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
2340 ' skeleton->priv->changed_properties_idle_source = NULL;\n'
2341 ' emit_changed = TRUE;\n'
2343 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2345 ' if (emit_changed)\n'
2346 ' _%s_emit_changed (skeleton);\n'
2347 %(i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2352 self.c.write('static void\n'
2353 '_%s_on_signal_%s (\n'
2354 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
2356 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
2359 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n\n'
2360 ' GList *connections, *l;\n'
2361 ' GVariant *signal_variant;\n'
2362 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2363 %(i.camel_name, i.ns_upper, i.name_upper))
2365 ' signal_variant = g_variant_ref_sink (g_variant_new ("(')
2367 self.c.write('%s'%(a.format_in))
2370 self.c.write(',\n arg_%s'%(a.name))
2371 self.c.write('));\n')
2373 self.c.write(' for (l = connections; l != NULL; l = l->next)\n'
2375 ' GDBusConnection *connection = l->data;\n'
2376 ' g_dbus_connection_emit_signal (connection,\n'
2377 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", "%s",\n'
2378 ' signal_variant, NULL);\n'
2381 self.c.write(' g_variant_unref (signal_variant);\n')
2382 self.c.write(' g_list_free_full (connections, g_object_unref);\n')
2386 self.c.write('static void %s_skeleton_iface_init (%sIface *iface);\n'
2387 %(i.name_lower, i.camel_name))
2389 self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
2390 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2391 self.c.write(' G_ADD_PRIVATE (%sSkeleton)\n'%(i.camel_name))
2392 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2393 self.c.write('#else\n')
2394 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2395 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2396 self.c.write('#endif\n')
2399 self.c.write('static void\n'
2400 '%s_skeleton_finalize (GObject *object)\n'
2401 '{\n'%(i.name_lower))
2402 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2403 if len(i.properties) > 0:
2404 self.c.write(' guint n;\n'
2405 ' for (n = 0; n < %d; n++)\n'
2406 ' g_value_unset (&skeleton->priv->properties[n]);\n'%(len(i.properties)))
2407 self.c.write(' g_free (skeleton->priv->properties);\n')
2408 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2409 self.c.write(' if (skeleton->priv->changed_properties_idle_source != NULL)\n')
2410 self.c.write(' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
2411 self.c.write(' g_main_context_unref (skeleton->priv->context);\n')
2412 self.c.write(' g_mutex_clear (&skeleton->priv->lock);\n')
2413 self.c.write(' G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
2415 '\n'%(i.name_lower))
2417 # property accessors (TODO: generate PropertiesChanged signals in setter)
2418 if len(i.properties) > 0:
2419 self.c.write('static void\n'
2420 '%s_skeleton_get_property (GObject *object,\n'
2423 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
2424 '{\n'%(i.name_lower))
2425 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2426 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2427 ' g_mutex_lock (&skeleton->priv->lock);\n'
2428 ' g_value_copy (&skeleton->priv->properties[prop_id - 1], value);\n'
2429 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2430 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
2434 # if property is already scheduled then re-use entry.. though it could be
2437 # foo_set_prop_bar (object, "");
2438 # foo_set_prop_bar (object, "blah");
2440 # say, every update... In this case, where nothing happens, we obviously
2441 # don't want a PropertiesChanged() event. We can easily check for this
2442 # by comparing against the _original value_ recorded before the first
2443 # change event. If the latest value is not different from the original
2444 # one, we can simply ignore the ChangedProperty
2446 self.c.write('static gboolean\n'
2447 '_%s_emit_changed (gpointer user_data)\n'
2449 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2450 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2451 self.c.write(' GList *l;\n'
2452 ' GVariantBuilder builder;\n'
2453 ' GVariantBuilder invalidated_builder;\n'
2454 ' guint num_changes;\n'
2456 ' g_mutex_lock (&skeleton->priv->lock);\n'
2457 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2458 ' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
2459 ' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
2461 ' ChangedProperty *cp = l->data;\n'
2462 ' GVariant *variant;\n'
2463 ' const GValue *cur_value;\n'
2465 ' cur_value = &skeleton->priv->properties[cp->prop_id - 1];\n'
2466 ' if (!_g_value_equal (cur_value, &cp->orig_value))\n'
2468 ' variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature));\n'
2469 ' g_variant_builder_add (&builder, "{sv}", cp->info->parent_struct.name, variant);\n'
2470 ' g_variant_unref (variant);\n'
2474 ' if (num_changes > 0)\n'
2476 ' GList *connections, *ll;\n'
2477 ' GVariant *signal_variant;'
2479 ' signal_variant = g_variant_ref_sink (g_variant_new ("(sa{sv}as)", "%s",\n'
2480 ' &builder, &invalidated_builder));\n'
2481 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2482 ' for (ll = connections; ll != NULL; ll = ll->next)\n'
2484 ' GDBusConnection *connection = ll->data;\n'
2486 ' g_dbus_connection_emit_signal (connection,\n'
2487 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2488 ' "org.freedesktop.DBus.Properties",\n'
2489 ' "PropertiesChanged",\n'
2490 ' signal_variant,\n'
2493 ' g_variant_unref (signal_variant);\n'
2494 ' g_list_free_full (connections, g_object_unref);\n'
2498 ' g_variant_builder_clear (&builder);\n'
2499 ' g_variant_builder_clear (&invalidated_builder);\n'
2502 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2503 self.c.write(' skeleton->priv->changed_properties = NULL;\n')
2504 self.c.write(' skeleton->priv->changed_properties_idle_source = NULL;\n')
2505 self.c.write(' g_mutex_unlock (&skeleton->priv->lock);\n')
2506 self.c.write(' return FALSE;\n'
2509 # holding lock while being called
2510 self.c.write('static void\n'
2511 '_%s_schedule_emit_changed (%sSkeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value)\n'
2513 ' ChangedProperty *cp;\n'
2516 ' for (l = skeleton->priv->changed_properties; l != NULL; l = l->next)\n'
2518 ' ChangedProperty *i_cp = l->data;\n'
2519 ' if (i_cp->info == info)\n'
2525 %(i.name_lower, i.camel_name))
2526 self.c.write(' if (cp == NULL)\n'
2528 ' cp = g_new0 (ChangedProperty, 1);\n'
2529 ' cp->prop_id = prop_id;\n'
2530 ' cp->info = info;\n'
2531 ' skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp);\n'
2532 ' g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value));\n'
2533 ' g_value_copy (orig_value, &cp->orig_value);\n'
2539 # Postpone setting up the refresh source until the ::notify signal is emitted as
2540 # this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
2541 # This is useful when updating several properties from another thread than
2542 # where the idle will be emitted from
2543 self.c.write('static void\n'
2544 '%s_skeleton_notify (GObject *object,\n'
2545 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
2547 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2548 ' g_mutex_lock (&skeleton->priv->lock);\n'
2549 ' if (skeleton->priv->changed_properties != NULL &&\n'
2550 ' skeleton->priv->changed_properties_idle_source == NULL)\n'
2552 ' skeleton->priv->changed_properties_idle_source = g_idle_source_new ();\n'
2553 ' g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);\n'
2554 ' g_source_set_callback (skeleton->priv->changed_properties_idle_source, _%s_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);\n'
2555 ' g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _%s_emit_changed");\n'
2556 ' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
2557 ' g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
2559 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2562 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower, i.name_lower))
2564 self.c.write('static void\n'
2565 '%s_skeleton_set_property (GObject *object,\n'
2567 ' const GValue *value,\n'
2568 ' GParamSpec *pspec)\n'
2569 '{\n'%(i.name_lower))
2570 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2571 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2572 ' g_mutex_lock (&skeleton->priv->lock);\n'
2573 ' g_object_freeze_notify (object);\n'
2574 ' if (!_g_value_equal (value, &skeleton->priv->properties[prop_id - 1]))\n'
2576 ' if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
2577 ' _%s_schedule_emit_changed (skeleton, _%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties[prop_id - 1]);\n'
2578 ' g_value_copy (value, &skeleton->priv->properties[prop_id - 1]);\n'
2579 ' g_object_notify_by_pspec (object, pspec);\n'
2581 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2582 ' g_object_thaw_notify (object);\n'
2583 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
2587 self.c.write('static void\n'
2588 '%s_skeleton_init (%sSkeleton *skeleton)\n'
2590 '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
2591 ' skeleton->priv = %s_skeleton_get_instance_private (skeleton);\n'
2593 ' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
2595 %(i.name_lower, i.camel_name,
2597 i.ns_upper, i.name_upper, i.camel_name))
2598 self.c.write(' g_mutex_init (&skeleton->priv->lock);\n')
2599 self.c.write(' skeleton->priv->context = g_main_context_ref_thread_default ();\n')
2600 if len(i.properties) > 0:
2601 self.c.write(' skeleton->priv->properties = g_new0 (GValue, %d);\n'%(len(i.properties)))
2603 for p in i.properties:
2604 self.c.write(' g_value_init (&skeleton->priv->properties[%d], %s);\n'%(n, p.arg.gtype))
2611 for p in i.properties:
2612 self.c.write('static %s\n'
2613 '%s_skeleton_get_%s (%s *object)\n'
2615 %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
2616 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2617 self.c.write(' %svalue;\n'
2618 ' g_mutex_lock (&skeleton->priv->lock);\n'
2619 ' value = %s (&(skeleton->priv->properties[%d]));\n'
2620 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2621 %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
2622 self.c.write(' return value;\n')
2627 self.c.write('static void\n'
2628 '%s_skeleton_class_init (%sSkeletonClass *klass)\n'
2630 ' GObjectClass *gobject_class;\n'
2631 ' GDBusInterfaceSkeletonClass *skeleton_class;\n'
2633 ' gobject_class = G_OBJECT_CLASS (klass);\n'
2634 ' gobject_class->finalize = %s_skeleton_finalize;\n'
2635 %(i.name_lower, i.camel_name, i.name_lower))
2636 if len(i.properties) > 0:
2637 self.c.write(' gobject_class->get_property = %s_skeleton_get_property;\n'
2638 ' gobject_class->set_property = %s_skeleton_set_property;\n'
2639 ' gobject_class->notify = %s_skeleton_notify;\n'
2640 '\n'%(i.name_lower, i.name_lower, i.name_lower))
2642 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
2644 ' skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);\n');
2645 self.c.write(' skeleton_class->get_info = %s_skeleton_dbus_interface_get_info;\n'%(i.name_lower))
2646 self.c.write(' skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
2647 self.c.write(' skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
2648 self.c.write(' skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
2651 '#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
2652 ' g_type_class_add_private (klass, sizeof (%sSkeletonPrivate));\n'
2653 '#endif\n'%(i.camel_name))
2658 self.c.write('static void\n'
2659 '%s_skeleton_iface_init (%sIface *iface)\n'
2661 %(i.name_lower, i.camel_name))
2663 self.c.write(' iface->%s = _%s_on_signal_%s;\n'
2664 %(s.name_lower, i.name_lower, s.name_lower))
2665 for p in i.properties:
2666 self.c.write(' iface->get_%s = %s_skeleton_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
2671 self.c.write(self.docbook_gen.expand(
2673 ' * %s_skeleton_new:\n'
2675 ' * Creates a skeleton object for the D-Bus interface #%s.\n'
2677 ' * Returns: (transfer full) (type %sSkeleton): The skeleton object.\n'
2678 %(i.name_lower, i.name, i.camel_name), False))
2679 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2680 self.c.write('%s *\n'
2681 '%s_skeleton_new (void)\n'
2683 ' return %s%s (g_object_new (%sTYPE_%s_SKELETON, NULL));\n'
2685 '\n'%(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
2687 # ---------------------------------------------------------------------------------------------------
2689 def generate_object(self):
2690 self.c.write('/* ------------------------------------------------------------------------\n'
2691 ' * Code for Object, ObjectProxy and ObjectSkeleton\n'
2692 ' * ------------------------------------------------------------------------\n'
2696 self.c.write(self.docbook_gen.expand(
2698 ' * SECTION:%sObject\n'
2699 ' * @title: %sObject\n'
2700 ' * @short_description: Specialized GDBusObject types\n'
2702 ' * 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'
2704 %(self.namespace, self.namespace, self.namespace, self.namespace, self.namespace), False))
2707 self.c.write(self.docbook_gen.expand(
2711 ' * The #%sObject type is a specialized container of interfaces.\n'
2713 %(self.namespace, self.namespace), False))
2716 self.c.write(self.docbook_gen.expand(
2718 ' * %sObjectIface:\n'
2719 ' * @parent_iface: The parent interface.\n'
2721 ' * Virtual table for the #%sObject interface.\n'
2723 %(self.namespace, self.namespace), False))
2726 self.c.write('typedef %sObjectIface %sObjectInterface;\n'%(self.namespace, self.namespace))
2727 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))
2729 self.c.write('static void\n'
2730 '%sobject_default_init (%sObjectIface *iface)\n'
2732 %(self.ns_lower, self.namespace));
2733 for i in self.ifaces:
2734 self.c.write(self.docbook_gen.expand(
2738 ' * The #%s instance corresponding to the D-Bus interface #%s, if any.\n'
2740 ' * Connect to the #GObject::notify signal to get informed of property changes.\n'
2741 %(self.namespace, i.name_hyphen, i.camel_name, i.name), False))
2742 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 2)
2743 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'
2745 %(i.name_hyphen, i.name_hyphen, i.name_hyphen, self.ns_upper, i.name_upper))
2749 for i in self.ifaces:
2750 self.c.write(self.docbook_gen.expand(
2752 ' * %sobject_get_%s:\n'
2753 ' * @object: A #%sObject.\n'
2755 ' * Gets the #%s instance for the D-Bus interface #%s on @object, if any.\n'
2757 ' * Returns: (transfer full): A #%s that must be freed with g_object_unref() or %%NULL if @object does not implement the interface.\n'
2758 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.name, i.camel_name), False))
2759 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2760 self.c.write ('%s *%sobject_get_%s (%sObject *object)\n'
2761 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2763 ' GDBusInterface *ret;\n'
2764 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2765 ' if (ret == NULL)\n'
2767 ' return %s%s (ret);\n'
2770 %(i.name, self.ns_upper, i.name_upper))
2772 for i in self.ifaces:
2773 self.c.write(self.docbook_gen.expand(
2775 ' * %sobject_peek_%s: (skip)\n'
2776 ' * @object: A #%sObject.\n'
2778 ' * Like %sobject_get_%s() but doesn\'t increase the reference count on the returned object.\n'
2780 ' * <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'
2782 ' * 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'
2783 %(self.ns_lower, i.name_upper.lower(), self.namespace, self.ns_lower, i.name_upper.lower(), i.camel_name), False))
2784 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2785 self.c.write ('%s *%sobject_peek_%s (%sObject *object)\n'
2786 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2788 ' GDBusInterface *ret;\n'
2789 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2790 ' if (ret == NULL)\n'
2792 ' g_object_unref (ret);\n'
2793 ' return %s%s (ret);\n'
2796 %(i.name, self.ns_upper, i.name_upper))
2798 # shared by ObjectProxy and ObjectSkeleton classes
2799 self.c.write('static void\n'
2800 '%sobject_notify (GDBusObject *object, GDBusInterface *interface)\n'
2802 ' _ExtendedGDBusInterfaceInfo *info = (_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface);\n'
2803 ' /* info can be NULL if the other end is using a D-Bus interface we don\'t know\n'
2804 ' * anything about, for example old generated code in this process talking to\n'
2805 ' * newer generated code in the other process. */\n'
2806 ' if (info != NULL)\n'
2807 ' g_object_notify (G_OBJECT (object), info->hyphen_name);\n'
2812 self.c.write(self.docbook_gen.expand(
2814 ' * %sObjectProxy:\n'
2816 ' * The #%sObjectProxy structure contains only private data and should only be accessed using the provided API.\n'
2817 %(self.namespace, self.namespace), False))
2818 self.c.write(' */\n')
2820 self.c.write(self.docbook_gen.expand(
2822 ' * %sObjectProxyClass:\n'
2823 ' * @parent_class: The parent class.\n'
2825 ' * Class structure for #%sObjectProxy.\n'
2826 %(self.namespace, self.namespace), False))
2827 self.c.write(' */\n')
2830 self.c.write('static void\n'
2831 '%sobject_proxy__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2835 %(self.ns_lower, self.ns_lower, self.namespace))
2836 self.c.write('static void\n'
2837 '%sobject_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2839 ' iface->interface_added = %sobject_notify;\n'
2840 ' iface->interface_removed = %sobject_notify;\n'
2843 %(self.ns_lower, self.ns_lower, self.ns_lower))
2845 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectProxy, %sobject_proxy, G_TYPE_DBUS_OBJECT_PROXY,\n'
2846 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_proxy__%sobject_iface_init)\n'
2847 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_proxy__g_dbus_object_iface_init));\n'
2849 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2851 self.c.write('static void\n'
2852 '%sobject_proxy_init (%sObjectProxy *object G_GNUC_UNUSED)\n'
2855 '\n'%(self.ns_lower, self.namespace))
2856 self.c.write('static void\n'
2857 '%sobject_proxy_set_property (GObject *gobject,\n'
2859 ' const GValue *value G_GNUC_UNUSED,\n'
2860 ' GParamSpec *pspec)\n'
2862 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2866 self.c.write('static void\n'
2867 '%sobject_proxy_get_property (GObject *gobject,\n'
2870 ' GParamSpec *pspec)\n'
2872 ' %sObjectProxy *object = %sOBJECT_PROXY (gobject);\n'
2873 ' GDBusInterface *interface;\n'
2875 ' switch (prop_id)\n'
2877 %(self.ns_lower, self.namespace, self.ns_upper))
2879 for i in self.ifaces:
2880 self.c.write(' case %d:\n'
2881 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2882 ' g_value_take_object (value, interface);\n'
2887 self.c.write(' default:\n'
2888 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2893 self.c.write('static void\n'
2894 '%sobject_proxy_class_init (%sObjectProxyClass *klass)\n'
2896 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2898 ' gobject_class->set_property = %sobject_proxy_set_property;\n'
2899 ' gobject_class->get_property = %sobject_proxy_get_property;\n'
2901 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2903 for i in self.ifaces:
2904 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2906 %(n, i.name_hyphen))
2911 self.c.write(self.docbook_gen.expand(
2913 ' * %sobject_proxy_new:\n'
2914 ' * @connection: A #GDBusConnection.\n'
2915 ' * @object_path: An object path.\n'
2917 ' * Creates a new proxy object.\n'
2919 ' * Returns: (transfer full): The proxy object.\n'
2921 %(self.ns_lower), False))
2922 self.c.write('%sObjectProxy *\n'
2923 '%sobject_proxy_new (GDBusConnection *connection,\n'
2924 ' const gchar *object_path)\n'
2926 ' g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);\n'
2927 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2928 ' return %sOBJECT_PROXY (g_object_new (%sTYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL));\n'
2930 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2932 self.c.write(self.docbook_gen.expand(
2934 ' * %sObjectSkeleton:\n'
2936 ' * The #%sObjectSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2937 %(self.namespace, self.namespace), False))
2938 self.c.write(' */\n')
2940 self.c.write(self.docbook_gen.expand(
2942 ' * %sObjectSkeletonClass:\n'
2943 ' * @parent_class: The parent class.\n'
2945 ' * Class structure for #%sObjectSkeleton.\n'
2946 %(self.namespace, self.namespace), False))
2947 self.c.write(' */\n')
2950 self.c.write('static void\n'
2951 '%sobject_skeleton__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2955 %(self.ns_lower, self.ns_lower, self.namespace))
2957 self.c.write('static void\n'
2958 '%sobject_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2960 ' iface->interface_added = %sobject_notify;\n'
2961 ' iface->interface_removed = %sobject_notify;\n'
2964 %(self.ns_lower, self.ns_lower, self.ns_lower))
2965 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectSkeleton, %sobject_skeleton, G_TYPE_DBUS_OBJECT_SKELETON,\n'
2966 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_skeleton__%sobject_iface_init)\n'
2967 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_skeleton__g_dbus_object_iface_init));\n'
2969 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2971 self.c.write('static void\n'
2972 '%sobject_skeleton_init (%sObjectSkeleton *object G_GNUC_UNUSED)\n'
2975 '\n'%(self.ns_lower, self.namespace))
2976 self.c.write('static void\n'
2977 '%sobject_skeleton_set_property (GObject *gobject,\n'
2979 ' const GValue *value,\n'
2980 ' GParamSpec *pspec)\n'
2982 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2983 ' GDBusInterfaceSkeleton *interface;\n'
2985 ' switch (prop_id)\n'
2987 %(self.ns_lower, self.namespace, self.ns_upper))
2989 for i in self.ifaces:
2990 self.c.write(' case %d:\n'
2991 ' interface = g_value_get_object (value);\n'
2992 ' if (interface != NULL)\n'
2994 ' g_warn_if_fail (%sIS_%s (interface));\n'
2995 ' g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface);\n'
2999 ' g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "%s");\n'
3003 %(n, self.ns_upper, i.name_upper, i.name))
3005 self.c.write(' default:\n'
3006 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
3011 self.c.write('static void\n'
3012 '%sobject_skeleton_get_property (GObject *gobject,\n'
3015 ' GParamSpec *pspec)\n'
3017 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
3018 ' GDBusInterface *interface;\n'
3020 ' switch (prop_id)\n'
3022 %(self.ns_lower, self.namespace, self.ns_upper))
3024 for i in self.ifaces:
3025 self.c.write(' case %d:\n'
3026 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
3027 ' g_value_take_object (value, interface);\n'
3032 self.c.write(' default:\n'
3033 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
3038 self.c.write('static void\n'
3039 '%sobject_skeleton_class_init (%sObjectSkeletonClass *klass)\n'
3041 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
3043 ' gobject_class->set_property = %sobject_skeleton_set_property;\n'
3044 ' gobject_class->get_property = %sobject_skeleton_get_property;\n'
3046 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
3048 for i in self.ifaces:
3049 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
3051 %(n, i.name_hyphen))
3055 self.c.write(self.docbook_gen.expand(
3057 ' * %sobject_skeleton_new:\n'
3058 ' * @object_path: An object path.\n'
3060 ' * Creates a new skeleton object.\n'
3062 ' * Returns: (transfer full): The skeleton object.\n'
3064 %(self.ns_lower), False))
3065 self.c.write('%sObjectSkeleton *\n'
3066 '%sobject_skeleton_new (const gchar *object_path)\n'
3068 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
3069 ' return %sOBJECT_SKELETON (g_object_new (%sTYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL));\n'
3071 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
3072 for i in self.ifaces:
3073 self.c.write(self.docbook_gen.expand(
3075 ' * %sobject_skeleton_set_%s:\n'
3076 ' * @object: A #%sObjectSkeleton.\n'
3077 ' * @interface_: (allow-none): A #%s or %%NULL to clear the interface.\n'
3079 ' * Sets the #%s instance for the D-Bus interface #%s on @object.\n'
3080 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.camel_name, i.name), False))
3081 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
3082 self.c.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_)\n'
3083 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
3085 ' g_object_set (G_OBJECT (object), "%s", interface_, NULL);\n'
3092 def generate_object_manager_client(self):
3093 self.c.write('/* ------------------------------------------------------------------------\n'
3094 ' * Code for ObjectManager client\n'
3095 ' * ------------------------------------------------------------------------\n'
3099 self.c.write(self.docbook_gen.expand(
3101 ' * SECTION:%sObjectManagerClient\n'
3102 ' * @title: %sObjectManagerClient\n'
3103 ' * @short_description: Generated GDBusObjectManagerClient type\n'
3105 ' * This section contains a #GDBusObjectManagerClient that uses %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc.\n'
3107 %(self.namespace, self.namespace, self.ns_lower), False))
3110 self.c.write(self.docbook_gen.expand(
3112 ' * %sObjectManagerClient:\n'
3114 ' * The #%sObjectManagerClient structure contains only private data and should only be accessed using the provided API.\n'
3115 %(self.namespace, self.namespace), False))
3116 self.c.write(' */\n')
3119 self.c.write(self.docbook_gen.expand(
3121 ' * %sObjectManagerClientClass:\n'
3122 ' * @parent_class: The parent class.\n'
3124 ' * Class structure for #%sObjectManagerClient.\n'
3125 %(self.namespace, self.namespace), False))
3126 self.c.write(' */\n')
3130 self.c.write('G_DEFINE_TYPE (%sObjectManagerClient, %sobject_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT);\n'
3132 %(self.namespace, self.ns_lower))
3135 self.c.write('static void\n'
3136 '%sobject_manager_client_init (%sObjectManagerClient *manager G_GNUC_UNUSED)\n'
3139 '\n'%(self.ns_lower, self.namespace))
3140 self.c.write('static void\n'
3141 '%sobject_manager_client_class_init (%sObjectManagerClientClass *klass G_GNUC_UNUSED)\n'
3144 '\n'%(self.ns_lower, self.namespace))
3146 self.c.write(self.docbook_gen.expand(
3148 ' * %sobject_manager_client_get_proxy_type:\n'
3149 ' * @manager: A #GDBusObjectManagerClient.\n'
3150 ' * @object_path: The object path of the remote object (unused).\n'
3151 ' * @interface_name: (allow-none): Interface name of the remote object or %%NULL to get the object proxy #GType.\n'
3152 ' * @user_data: User data (unused).\n'
3154 ' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types.\n'
3156 ' * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %%NULL, otherwise the #GType for #%sObjectProxy.\n'
3157 %(self.ns_lower, self.namespace), False))
3158 self.c.write(' */\n')
3159 self.c.write('GType\n'
3160 '%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'
3163 self.c.write(' static gsize once_init_value = 0;\n'
3164 ' static GHashTable *lookup_hash;\n'
3167 ' if (interface_name == NULL)\n'
3168 ' return %sTYPE_OBJECT_PROXY;\n'
3169 ' if (g_once_init_enter (&once_init_value))\n'
3171 ' lookup_hash = g_hash_table_new (g_str_hash, g_str_equal);\n'
3173 for i in self.ifaces:
3174 self.c.write(' g_hash_table_insert (lookup_hash, (gpointer) "%s", GSIZE_TO_POINTER (%sTYPE_%s_PROXY));\n'
3175 %(i.name, i.ns_upper, i.name_upper))
3176 self.c.write(' g_once_init_leave (&once_init_value, 1);\n'
3178 self.c.write(' ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name));\n'
3179 ' if (ret == (GType) 0)\n'
3180 ' ret = G_TYPE_DBUS_PROXY;\n')
3181 self.c.write(' return ret;\n'
3186 self.c.write(self.docbook_gen.expand(
3188 ' * %sobject_manager_client_new:\n'
3189 ' * @connection: A #GDBusConnection.\n'
3190 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3191 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3192 ' * @object_path: An object path.\n'
3193 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3194 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3195 ' * @user_data: User data to pass to @callback.\n'
3197 ' * Asynchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details.\n'
3199 ' * 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'
3200 ' * You can then call %sobject_manager_client_new_finish() to get the result of the operation.\n'
3202 ' * See %sobject_manager_client_new_sync() for the synchronous, blocking version of this constructor.\n'
3203 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3204 self.c.write(' */\n')
3205 self.c.write('void\n'
3206 '%sobject_manager_client_new (\n'
3207 ' GDBusConnection *connection,\n'
3208 ' GDBusObjectManagerClientFlags flags,\n'
3209 ' const gchar *name,\n'
3210 ' const gchar *object_path,\n'
3211 ' GCancellable *cancellable,\n'
3212 ' GAsyncReadyCallback callback,\n'
3213 ' gpointer user_data)\n'
3215 ' 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'
3218 %(self.ns_lower, self.ns_upper, self.ns_lower))
3219 self.c.write('/**\n'
3220 ' * %sobject_manager_client_new_finish:\n'
3221 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new().\n'
3222 ' * @error: Return location for error or %%NULL\n'
3224 ' * Finishes an operation started with %sobject_manager_client_new().\n'
3226 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3227 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3228 self.c.write(' */\n')
3229 self.c.write('GDBusObjectManager *\n'
3230 '%sobject_manager_client_new_finish (\n'
3231 ' GAsyncResult *res,\n'
3232 ' GError **error)\n'
3235 ' GObject *source_object;\n'
3236 ' source_object = g_async_result_get_source_object (res);\n'
3237 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3238 ' g_object_unref (source_object);\n'
3239 ' if (ret != NULL)\n'
3240 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3246 self.c.write(self.docbook_gen.expand(
3248 ' * %sobject_manager_client_new_sync:\n'
3249 ' * @connection: A #GDBusConnection.\n'
3250 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3251 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3252 ' * @object_path: An object path.\n'
3253 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3254 ' * @error: Return location for error or %%NULL\n'
3256 ' * 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'
3258 ' * The calling thread is blocked until a reply is received.\n'
3260 ' * See %sobject_manager_client_new() for the asynchronous version of this constructor.\n'
3262 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3263 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3264 self.c.write(' */\n')
3265 self.c.write('GDBusObjectManager *\n'
3266 '%sobject_manager_client_new_sync (\n'
3267 ' GDBusConnection *connection,\n'
3268 ' GDBusObjectManagerClientFlags flags,\n'
3269 ' const gchar *name,\n'
3270 ' const gchar *object_path,\n'
3271 ' GCancellable *cancellable,\n'
3272 ' GError **error)\n'
3274 ' GInitable *ret;\n'
3275 ' 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'
3276 ' if (ret != NULL)\n'
3277 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3282 %(self.ns_lower, self.ns_upper, self.ns_lower))
3284 self.c.write(self.docbook_gen.expand(
3286 ' * %sobject_manager_client_new_for_bus:\n'
3287 ' * @bus_type: A #GBusType.\n'
3288 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3289 ' * @name: A bus name (well-known or unique).\n'
3290 ' * @object_path: An object path.\n'
3291 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3292 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3293 ' * @user_data: User data to pass to @callback.\n'
3295 ' * Like %sobject_manager_client_new() but takes a #GBusType instead of a #GDBusConnection.\n'
3297 ' * 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'
3298 ' * You can then call %sobject_manager_client_new_for_bus_finish() to get the result of the operation.\n'
3300 ' * See %sobject_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
3301 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3302 self.c.write(' */\n')
3303 self.c.write('void\n'
3304 '%sobject_manager_client_new_for_bus (\n'
3305 ' GBusType bus_type,\n'
3306 ' GDBusObjectManagerClientFlags flags,\n'
3307 ' const gchar *name,\n'
3308 ' const gchar *object_path,\n'
3309 ' GCancellable *cancellable,\n'
3310 ' GAsyncReadyCallback callback,\n'
3311 ' gpointer user_data)\n'
3313 ' 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'
3316 %(self.ns_lower, self.ns_upper, self.ns_lower))
3317 self.c.write('/**\n'
3318 ' * %sobject_manager_client_new_for_bus_finish:\n'
3319 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new_for_bus().\n'
3320 ' * @error: Return location for error or %%NULL\n'
3322 ' * Finishes an operation started with %sobject_manager_client_new_for_bus().\n'
3324 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3325 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3326 self.c.write(' */\n')
3327 self.c.write('GDBusObjectManager *\n'
3328 '%sobject_manager_client_new_for_bus_finish (\n'
3329 ' GAsyncResult *res,\n'
3330 ' GError **error)\n'
3333 ' GObject *source_object;\n'
3334 ' source_object = g_async_result_get_source_object (res);\n'
3335 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3336 ' g_object_unref (source_object);\n'
3337 ' if (ret != NULL)\n'
3338 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3344 self.c.write(self.docbook_gen.expand(
3346 ' * %sobject_manager_client_new_for_bus_sync:\n'
3347 ' * @bus_type: A #GBusType.\n'
3348 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3349 ' * @name: A bus name (well-known or unique).\n'
3350 ' * @object_path: An object path.\n'
3351 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3352 ' * @error: Return location for error or %%NULL\n'
3354 ' * Like %sobject_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
3356 ' * The calling thread is blocked until a reply is received.\n'
3358 ' * See %sobject_manager_client_new_for_bus() for the asynchronous version of this constructor.\n'
3360 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3361 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3362 self.c.write(' */\n')
3363 self.c.write('GDBusObjectManager *\n'
3364 '%sobject_manager_client_new_for_bus_sync (\n'
3365 ' GBusType bus_type,\n'
3366 ' GDBusObjectManagerClientFlags flags,\n'
3367 ' const gchar *name,\n'
3368 ' const gchar *object_path,\n'
3369 ' GCancellable *cancellable,\n'
3370 ' GError **error)\n'
3372 ' GInitable *ret;\n'
3373 ' 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'
3374 ' if (ret != NULL)\n'
3375 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3380 %(self.ns_lower, self.ns_upper, self.ns_lower))
3383 # ---------------------------------------------------------------------------------------------------
3385 def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
3386 if len(obj.since) > 0:
3389 %(indent, '', indent, '', obj.since))
3391 if isinstance(obj, dbustypes.Interface):
3392 thing = 'The D-Bus interface'
3393 elif isinstance(obj, dbustypes.Method):
3394 thing = 'The D-Bus method'
3395 elif isinstance(obj, dbustypes.Signal):
3396 thing = 'The D-Bus signal'
3397 elif isinstance(obj, dbustypes.Property):
3398 thing = 'The D-Bus property'
3400 raise RuntimeError('Cannot handle object ', obj)
3401 f.write(self.docbook_gen.expand(
3403 '%*s * Deprecated: %s has been deprecated.\n'
3404 %(indent, '', indent, '', thing), False))
3405 f.write('%*s */\n'%(indent, ''))
3407 # ---------------------------------------------------------------------------------------------------
3409 def generate_interface_intro(self, i):
3410 self.c.write('/* ------------------------------------------------------------------------\n'
3411 ' * Code for interface %s\n'
3412 ' * ------------------------------------------------------------------------\n'
3416 self.c.write(self.docbook_gen.expand(
3420 ' * @short_description: Generated C code for the %s D-Bus interface\n'
3422 ' * This section contains code for working with the #%s D-Bus interface in C.\n'
3424 %(i.camel_name, i.camel_name, i.name, i.name), False))
3428 self.generate_intro()
3429 self.declare_types()
3430 for i in self.ifaces:
3431 self.generate_interface_intro(i)
3432 self.generate_introspection_for_interface(i)
3433 self.generate_interface(i)
3434 self.generate_property_accessors(i)
3435 self.generate_signal_emitters(i)
3436 self.generate_method_calls(i)
3437 self.generate_method_completers(i)
3438 self.generate_proxy(i)
3439 self.generate_skeleton(i)
3440 if self.generate_objmanager:
3441 self.generate_object()
3442 self.generate_object_manager_client()
3444 self.generate_outro()