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,
32 generate_autocleanup, docbook_gen, h, c, header_name):
33 self.docbook_gen = docbook_gen
34 self.generate_objmanager = generate_objmanager
35 self.generate_autocleanup = generate_autocleanup
39 self.header_name = header_name
40 self.namespace = namespace
41 if len(namespace) > 0:
42 if utils.is_ugly_case(namespace):
43 self.namespace = namespace.replace('_', '')
44 self.ns_upper = namespace.upper() + '_'
45 self.ns_lower = namespace.lower() + '_'
47 self.ns_upper = utils.camel_case_to_uscore(namespace).upper() + '_'
48 self.ns_lower = utils.camel_case_to_uscore(namespace).lower() + '_'
52 self.interface_prefix = interface_prefix
53 self.header_guard = header_name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
55 # ----------------------------------------------------------------------------------------------------
57 def generate_intro(self):
59 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
61 ' * The license of this code is the same as for the source it was derived from.\n'
65 self.c.write('#ifdef HAVE_CONFIG_H\n'
66 '# include "config.h"\n'
71 '#include <string.h>\n'
74 self.c.write('#ifdef G_OS_UNIX\n'
75 '# include <gio/gunixfdlist.h>\n'
79 self.c.write('typedef struct\n'
81 ' GDBusArgInfo parent_struct;\n'
82 ' gboolean use_gvariant;\n'
83 '} _ExtendedGDBusArgInfo;\n'
86 self.c.write('typedef struct\n'
88 ' GDBusMethodInfo parent_struct;\n'
89 ' const gchar *signal_name;\n'
90 ' gboolean pass_fdlist;\n'
91 '} _ExtendedGDBusMethodInfo;\n'
94 self.c.write('typedef struct\n'
96 ' GDBusSignalInfo parent_struct;\n'
97 ' const gchar *signal_name;\n'
98 '} _ExtendedGDBusSignalInfo;\n'
101 self.c.write('typedef struct\n'
103 ' GDBusPropertyInfo parent_struct;\n'
104 ' const gchar *hyphen_name;\n'
105 ' gboolean use_gvariant;\n'
106 '} _ExtendedGDBusPropertyInfo;\n'
109 self.c.write('typedef struct\n'
111 ' GDBusInterfaceInfo parent_struct;\n'
112 ' const gchar *hyphen_name;\n'
113 '} _ExtendedGDBusInterfaceInfo;\n'
116 self.c.write('typedef struct\n'
118 ' const _ExtendedGDBusPropertyInfo *info;\n'
120 ' GValue orig_value; /* the value before the change */\n'
121 '} ChangedProperty;\n'
124 '_changed_property_free (ChangedProperty *data)\n'
126 ' g_value_unset (&data->orig_value);\n'
131 self.c.write('static gboolean\n'
132 '_g_strv_equal0 (gchar **a, gchar **b)\n'
134 ' gboolean ret = FALSE;\n'
136 ' if (a == NULL && b == NULL)\n'
141 ' if (a == NULL || b == NULL)\n'
143 ' if (g_strv_length (a) != g_strv_length (b))\n'
145 ' for (n = 0; a[n] != NULL; n++)\n'
146 ' if (g_strcmp0 (a[n], b[n]) != 0)\n'
154 self.c.write('static gboolean\n'
155 '_g_variant_equal0 (GVariant *a, GVariant *b)\n'
157 ' gboolean ret = FALSE;\n'
158 ' if (a == NULL && b == NULL)\n'
163 ' if (a == NULL || b == NULL)\n'
165 ' ret = g_variant_equal (a, b);\n'
171 # simplified - only supports the types we use
172 self.c.write('G_GNUC_UNUSED static gboolean\n'
173 '_g_value_equal (const GValue *a, const GValue *b)\n'
175 ' gboolean ret = FALSE;\n'
176 ' g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b));\n'
177 ' switch (G_VALUE_TYPE (a))\n'
179 ' case G_TYPE_BOOLEAN:\n'
180 ' ret = (g_value_get_boolean (a) == g_value_get_boolean (b));\n'
182 ' case G_TYPE_UCHAR:\n'
183 ' ret = (g_value_get_uchar (a) == g_value_get_uchar (b));\n'
185 ' case G_TYPE_INT:\n'
186 ' ret = (g_value_get_int (a) == g_value_get_int (b));\n'
188 ' case G_TYPE_UINT:\n'
189 ' ret = (g_value_get_uint (a) == g_value_get_uint (b));\n'
191 ' case G_TYPE_INT64:\n'
192 ' ret = (g_value_get_int64 (a) == g_value_get_int64 (b));\n'
194 ' case G_TYPE_UINT64:\n'
195 ' ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n'
197 ' case G_TYPE_DOUBLE:\n'
199 ' /* Avoid -Wfloat-equal warnings by doing a direct bit compare */\n'
200 ' gdouble da = g_value_get_double (a);\n'
201 ' gdouble db = g_value_get_double (b);\n'
202 ' ret = memcmp (&da, &db, sizeof (gdouble)) == 0;\n'
205 ' case G_TYPE_STRING:\n'
206 ' ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n'
208 ' case G_TYPE_VARIANT:\n'
209 ' ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b));\n'
212 ' if (G_VALUE_TYPE (a) == G_TYPE_STRV)\n'
213 ' ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b));\n'
215 ' g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a)));\n'
223 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
225 ' * The license of this code is the same as for the source it was derived from.\n'
230 '\n'%(config.VERSION, self.header_guard, self.header_guard))
231 self.h.write('#include <gio/gio.h>\n'
236 # ----------------------------------------------------------------------------------------------------
238 def declare_types(self):
239 for i in self.ifaces:
241 self.h.write('/* ------------------------------------------------------------------------ */\n')
242 self.h.write('/* Declarations for %s */\n'%i.name)
245 # First the GInterface
246 self.h.write('#define %sTYPE_%s (%s_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
247 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))
248 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))
249 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))
251 self.h.write('struct _%s;\n'%(i.camel_name))
252 self.h.write('typedef struct _%s %s;\n'%(i.camel_name, i.camel_name))
253 self.h.write('typedef struct _%sIface %sIface;\n'%(i.camel_name, i.camel_name))
255 self.h.write('struct _%sIface\n'%(i.camel_name))
257 self.h.write(' GTypeInterface parent_iface;\n')
259 function_pointers = {}
262 if len(i.methods) > 0:
266 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
268 key = (m.since, '_method_%s'%m.name_lower)
269 value = ' gboolean (*handle_%s) (\n'%(m.name_lower)
270 value += ' %s *object,\n'%(i.camel_name)
271 value += ' GDBusMethodInvocation *invocation'%()
273 value += ',\n GUnixFDList *fd_list'
275 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
277 function_pointers[key] = value
280 if len(i.signals) > 0:
283 key = (s.since, '_signal_%s'%s.name_lower)
284 value = ' void (*%s) (\n'%(s.name_lower)
285 value += ' %s *object'%(i.camel_name)
287 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
289 function_pointers[key] = value
291 # vfuncs for properties
292 if len(i.properties) > 0:
294 for p in i.properties:
295 key = (p.since, '_prop_get_%s'%p.name_lower)
296 value = ' %s (*get_%s) (%s *object);\n\n'%(p.arg.ctype_in, p.name_lower, i.camel_name)
297 function_pointers[key] = value
299 # Sort according to @since tag, then name.. this ensures
300 # that the function pointers don't change order assuming
301 # judicious use of @since
303 # Also use a proper version comparison function so e.g.
304 # 10.0 comes after 2.0.
306 # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
308 for key in sorted(function_pointers.keys(), key=utils.version_cmp_key):
309 self.h.write('%s'%function_pointers[key])
313 if self.generate_autocleanup == 'all':
314 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
315 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%s, g_object_unref)\n' % (i.camel_name))
316 self.h.write('#endif\n')
318 self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
320 self.h.write('GDBusInterfaceInfo *%s_interface_info (void);\n'%(i.name_lower))
321 self.h.write('guint %s_override_properties (GObjectClass *klass, guint property_id_begin);\n'%(i.name_lower))
324 # Then method call completion functions
325 if len(i.methods) > 0:
327 self.h.write('/* D-Bus method call completion functions: */\n')
330 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
333 self.h.write('G_GNUC_DEPRECATED ')
334 self.h.write('void %s_complete_%s (\n'
336 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
338 self.h.write(',\n GUnixFDList *fd_list')
340 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
345 # Then signal emission functions
346 if len(i.signals) > 0:
348 self.h.write('/* D-Bus signal emissions functions: */\n')
351 self.h.write('G_GNUC_DEPRECATED ')
352 self.h.write('void %s_emit_%s (\n'
353 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
355 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
360 # Then method call declarations
361 if len(i.methods) > 0:
363 self.h.write('/* D-Bus method calls: */\n')
366 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
370 self.h.write('G_GNUC_DEPRECATED ')
371 self.h.write('void %s_call_%s (\n'
372 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
374 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
376 self.h.write(',\n GUnixFDList *fd_list')
378 ' GCancellable *cancellable,\n'
379 ' GAsyncReadyCallback callback,\n'
380 ' gpointer user_data);\n')
384 self.h.write('G_GNUC_DEPRECATED ')
385 self.h.write('gboolean %s_call_%s_finish (\n'
386 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
388 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
390 self.h.write(',\n GUnixFDList **out_fd_list')
392 ' GAsyncResult *res,\n'
393 ' GError **error);\n')
397 self.h.write('G_GNUC_DEPRECATED ')
398 self.h.write('gboolean %s_call_%s_sync (\n'
399 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
401 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
403 self.h.write(',\n GUnixFDList *fd_list')
405 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
407 self.h.write(',\n GUnixFDList **out_fd_list')
409 ' GCancellable *cancellable,\n'
410 ' GError **error);\n')
414 # Then the property accessor declarations
415 if len(i.properties) > 0:
417 self.h.write('/* D-Bus property accessors: */\n')
418 for p in i.properties:
421 self.h.write('G_GNUC_DEPRECATED ')
422 self.h.write('%s%s_get_%s (%s *object);\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
423 if p.arg.free_func != None:
425 self.h.write('G_GNUC_DEPRECATED ')
426 self.h.write('%s%s_dup_%s (%s *object);\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name))
429 self.h.write('G_GNUC_DEPRECATED ')
430 self.h.write('void %s_set_%s (%s *object, %svalue);\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
435 self.h.write('/* ---- */\n')
437 self.h.write('#define %sTYPE_%s_PROXY (%s_proxy_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
438 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))
439 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))
440 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))
441 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))
442 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))
444 self.h.write('typedef struct _%sProxy %sProxy;\n'%(i.camel_name, i.camel_name))
445 self.h.write('typedef struct _%sProxyClass %sProxyClass;\n'%(i.camel_name, i.camel_name))
446 self.h.write('typedef struct _%sProxyPrivate %sProxyPrivate;\n'%(i.camel_name, i.camel_name))
448 self.h.write('struct _%sProxy\n'%(i.camel_name))
450 self.h.write(' /*< private >*/\n')
451 self.h.write(' GDBusProxy parent_instance;\n')
452 self.h.write(' %sProxyPrivate *priv;\n'%(i.camel_name))
455 self.h.write('struct _%sProxyClass\n'%(i.camel_name))
457 self.h.write(' GDBusProxyClass parent_class;\n')
460 self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
462 if self.generate_autocleanup in ('objects', 'all'):
463 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
464 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sProxy, g_object_unref)\n' % (i.camel_name))
465 self.h.write('#endif\n')
468 self.h.write('G_GNUC_DEPRECATED ')
469 self.h.write('void %s_proxy_new (\n'
470 ' GDBusConnection *connection,\n'
471 ' GDBusProxyFlags flags,\n'
472 ' const gchar *name,\n'
473 ' const gchar *object_path,\n'
474 ' GCancellable *cancellable,\n'
475 ' GAsyncReadyCallback callback,\n'
476 ' gpointer user_data);\n'
479 self.h.write('G_GNUC_DEPRECATED ')
480 self.h.write('%s *%s_proxy_new_finish (\n'
481 ' GAsyncResult *res,\n'
482 ' GError **error);\n'
483 %(i.camel_name, i.name_lower))
485 self.h.write('G_GNUC_DEPRECATED ')
486 self.h.write('%s *%s_proxy_new_sync (\n'
487 ' GDBusConnection *connection,\n'
488 ' GDBusProxyFlags flags,\n'
489 ' const gchar *name,\n'
490 ' const gchar *object_path,\n'
491 ' GCancellable *cancellable,\n'
492 ' GError **error);\n'
493 %(i.camel_name, i.name_lower))
496 self.h.write('G_GNUC_DEPRECATED ')
497 self.h.write('void %s_proxy_new_for_bus (\n'
498 ' GBusType bus_type,\n'
499 ' GDBusProxyFlags flags,\n'
500 ' const gchar *name,\n'
501 ' const gchar *object_path,\n'
502 ' GCancellable *cancellable,\n'
503 ' GAsyncReadyCallback callback,\n'
504 ' gpointer user_data);\n'
507 self.h.write('G_GNUC_DEPRECATED ')
508 self.h.write('%s *%s_proxy_new_for_bus_finish (\n'
509 ' GAsyncResult *res,\n'
510 ' GError **error);\n'
511 %(i.camel_name, i.name_lower))
513 self.h.write('G_GNUC_DEPRECATED ')
514 self.h.write('%s *%s_proxy_new_for_bus_sync (\n'
515 ' GBusType bus_type,\n'
516 ' GDBusProxyFlags flags,\n'
517 ' const gchar *name,\n'
518 ' const gchar *object_path,\n'
519 ' GCancellable *cancellable,\n'
520 ' GError **error);\n'
521 %(i.camel_name, i.name_lower))
526 self.h.write('/* ---- */\n')
528 self.h.write('#define %sTYPE_%s_SKELETON (%s_skeleton_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
529 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))
530 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))
531 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))
532 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))
533 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))
535 self.h.write('typedef struct _%sSkeleton %sSkeleton;\n'%(i.camel_name, i.camel_name))
536 self.h.write('typedef struct _%sSkeletonClass %sSkeletonClass;\n'%(i.camel_name, i.camel_name))
537 self.h.write('typedef struct _%sSkeletonPrivate %sSkeletonPrivate;\n'%(i.camel_name, i.camel_name))
539 self.h.write('struct _%sSkeleton\n'%(i.camel_name))
541 self.h.write(' /*< private >*/\n')
542 self.h.write(' GDBusInterfaceSkeleton parent_instance;\n')
543 self.h.write(' %sSkeletonPrivate *priv;\n'%(i.camel_name))
546 self.h.write('struct _%sSkeletonClass\n'%(i.camel_name))
548 self.h.write(' GDBusInterfaceSkeletonClass parent_class;\n')
551 self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
553 if self.generate_autocleanup in ('objects', 'all'):
554 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
555 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sSkeleton, g_object_unref)\n' % (i.camel_name))
556 self.h.write('#endif\n')
559 self.h.write('G_GNUC_DEPRECATED ')
560 self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
564 # Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
565 if self.generate_objmanager:
567 self.h.write('/* ---- */\n')
569 self.h.write('#define %sTYPE_OBJECT (%sobject_get_type ())\n'%(self.ns_upper, self.ns_lower))
570 self.h.write('#define %sOBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
571 self.h.write('#define %sIS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT))\n'%(self.ns_upper, self.ns_upper))
572 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))
574 self.h.write('struct _%sObject;\n'%(self.namespace))
575 self.h.write('typedef struct _%sObject %sObject;\n'%(self.namespace, self.namespace))
576 self.h.write('typedef struct _%sObjectIface %sObjectIface;\n'%(self.namespace, self.namespace))
578 self.h.write('struct _%sObjectIface\n'%(self.namespace))
580 ' GTypeInterface parent_iface;\n'
583 self.h.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
586 for i in self.ifaces:
588 self.h.write('G_GNUC_DEPRECATED ')
589 self.h.write ('%s *%sobject_get_%s (%sObject *object);\n'
590 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
591 for i in self.ifaces:
593 self.h.write('G_GNUC_DEPRECATED ')
594 self.h.write ('%s *%sobject_peek_%s (%sObject *object);\n'
595 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
597 self.h.write('#define %sTYPE_OBJECT_PROXY (%sobject_proxy_get_type ())\n'%(self.ns_upper, self.ns_lower))
598 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))
599 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))
600 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))
601 self.h.write('#define %sIS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
602 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))
604 self.h.write('typedef struct _%sObjectProxy %sObjectProxy;\n'%(self.namespace, self.namespace))
605 self.h.write('typedef struct _%sObjectProxyClass %sObjectProxyClass;\n'%(self.namespace, self.namespace))
606 self.h.write('typedef struct _%sObjectProxyPrivate %sObjectProxyPrivate;\n'%(self.namespace, self.namespace))
608 self.h.write('struct _%sObjectProxy\n'%(self.namespace))
610 self.h.write(' /*< private >*/\n')
611 self.h.write(' GDBusObjectProxy parent_instance;\n')
612 self.h.write(' %sObjectProxyPrivate *priv;\n'%(self.namespace))
615 self.h.write('struct _%sObjectProxyClass\n'%(self.namespace))
617 self.h.write(' GDBusObjectProxyClass parent_class;\n')
620 self.h.write('GType %sobject_proxy_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
622 if self.generate_autocleanup in ('objects', 'all'):
623 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
624 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectProxy, g_object_unref)\n' % (self.namespace))
625 self.h.write('#endif\n')
627 self.h.write('%sObjectProxy *%sobject_proxy_new (GDBusConnection *connection, const gchar *object_path);\n'%(self.namespace, self.ns_lower))
629 self.h.write('#define %sTYPE_OBJECT_SKELETON (%sobject_skeleton_get_type ())\n'%(self.ns_upper, self.ns_lower))
630 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))
631 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))
632 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))
633 self.h.write('#define %sIS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
634 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))
636 self.h.write('typedef struct _%sObjectSkeleton %sObjectSkeleton;\n'%(self.namespace, self.namespace))
637 self.h.write('typedef struct _%sObjectSkeletonClass %sObjectSkeletonClass;\n'%(self.namespace, self.namespace))
638 self.h.write('typedef struct _%sObjectSkeletonPrivate %sObjectSkeletonPrivate;\n'%(self.namespace, self.namespace))
640 self.h.write('struct _%sObjectSkeleton\n'%(self.namespace))
642 self.h.write(' /*< private >*/\n')
643 self.h.write(' GDBusObjectSkeleton parent_instance;\n')
644 self.h.write(' %sObjectSkeletonPrivate *priv;\n'%(self.namespace))
647 self.h.write('struct _%sObjectSkeletonClass\n'%(self.namespace))
649 self.h.write(' GDBusObjectSkeletonClass parent_class;\n')
652 self.h.write('GType %sobject_skeleton_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
654 if self.generate_autocleanup in ('objects', 'all'):
655 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
656 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectSkeleton, g_object_unref)\n' % (self.namespace))
657 self.h.write('#endif\n')
659 self.h.write('%sObjectSkeleton *%sobject_skeleton_new (const gchar *object_path);\n'
660 %(self.namespace, self.ns_lower))
661 for i in self.ifaces:
663 self.h.write('G_GNUC_DEPRECATED ')
664 self.h.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_);\n'
665 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
668 self.h.write('/* ---- */\n')
670 self.h.write('#define %sTYPE_OBJECT_MANAGER_CLIENT (%sobject_manager_client_get_type ())\n'%(self.ns_upper, self.ns_lower))
671 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))
672 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))
673 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))
674 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))
675 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))
677 self.h.write('typedef struct _%sObjectManagerClient %sObjectManagerClient;\n'%(self.namespace, self.namespace))
678 self.h.write('typedef struct _%sObjectManagerClientClass %sObjectManagerClientClass;\n'%(self.namespace, self.namespace))
679 self.h.write('typedef struct _%sObjectManagerClientPrivate %sObjectManagerClientPrivate;\n'%(self.namespace, self.namespace))
681 self.h.write('struct _%sObjectManagerClient\n'%(self.namespace))
683 self.h.write(' /*< private >*/\n')
684 self.h.write(' GDBusObjectManagerClient parent_instance;\n')
685 self.h.write(' %sObjectManagerClientPrivate *priv;\n'%(self.namespace))
688 self.h.write('struct _%sObjectManagerClientClass\n'%(self.namespace))
690 self.h.write(' GDBusObjectManagerClientClass parent_class;\n')
693 if self.generate_autocleanup in ('objects', 'all'):
694 self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
695 self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectManagerClient, g_object_unref)\n' % (self.namespace))
696 self.h.write('#endif\n')
698 self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
700 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))
702 self.h.write('void %sobject_manager_client_new (\n'
703 ' GDBusConnection *connection,\n'
704 ' GDBusObjectManagerClientFlags flags,\n'
705 ' const gchar *name,\n'
706 ' const gchar *object_path,\n'
707 ' GCancellable *cancellable,\n'
708 ' GAsyncReadyCallback callback,\n'
709 ' gpointer user_data);\n'
711 self.h.write('GDBusObjectManager *%sobject_manager_client_new_finish (\n'
712 ' GAsyncResult *res,\n'
713 ' GError **error);\n'
715 self.h.write('GDBusObjectManager *%sobject_manager_client_new_sync (\n'
716 ' GDBusConnection *connection,\n'
717 ' GDBusObjectManagerClientFlags flags,\n'
718 ' const gchar *name,\n'
719 ' const gchar *object_path,\n'
720 ' GCancellable *cancellable,\n'
721 ' GError **error);\n'
724 self.h.write('void %sobject_manager_client_new_for_bus (\n'
725 ' GBusType bus_type,\n'
726 ' GDBusObjectManagerClientFlags flags,\n'
727 ' const gchar *name,\n'
728 ' const gchar *object_path,\n'
729 ' GCancellable *cancellable,\n'
730 ' GAsyncReadyCallback callback,\n'
731 ' gpointer user_data);\n'
733 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_finish (\n'
734 ' GAsyncResult *res,\n'
735 ' GError **error);\n'
737 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_sync (\n'
738 ' GBusType bus_type,\n'
739 ' GDBusObjectManagerClientFlags flags,\n'
740 ' const gchar *name,\n'
741 ' const gchar *object_path,\n'
742 ' GCancellable *cancellable,\n'
743 ' GError **error);\n'
747 # ----------------------------------------------------------------------------------------------------
749 def generate_outro(self):
753 '#endif /* __%s__ */\n'%(self.header_guard))
755 # ----------------------------------------------------------------------------------------------------
757 def generate_annotations(self, prefix, annotations):
758 if annotations == None:
762 for a in annotations:
763 #self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
765 # skip internal annotations
766 if a.key.startswith('org.gtk.GDBus'):
769 self.c.write('static const GDBusAnnotationInfo %s_%d =\n'
773 ' (gchar *) "%s",\n'%(prefix, n, a.key, a.value))
774 if len(a.annotations) == 0:
775 self.c.write(' NULL\n')
777 self.c.write(' (GDBusAnnotationInfo **) &%s_%d_pointers\n'%(prefix, n))
783 self.c.write('static const GDBusAnnotationInfo * const %s_pointers[] =\n'
786 for a in annotations:
787 if a.key.startswith('org.gtk.GDBus'):
789 self.c.write(' &%s_%d,\n'%(prefix, m))
791 self.c.write(' NULL\n'
796 def generate_args(self, prefix, args):
798 num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
800 self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
805 ' (gchar *) "%s",\n'%(prefix, a.name, a.name, a.signature))
807 self.c.write(' NULL\n')
809 self.c.write(' (GDBusAnnotationInfo **) &%s_arg_%s_annotation_info_pointers\n'%(prefix, a.name))
810 self.c.write(' },\n')
811 if not utils.lookup_annotation(a.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
812 self.c.write(' FALSE\n')
814 self.c.write(' TRUE\n')
819 self.c.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
822 self.c.write(' &%s_%s,\n'%(prefix, a.name))
823 self.c.write(' NULL\n'
827 def generate_introspection_for_interface(self, i):
828 self.c.write('/* ---- Introspection data for %s ---- */\n'
831 if len(i.methods) > 0:
834 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
836 self.generate_args('_%s_method_info_%s_IN_ARG'%(i.name_lower, m.name_lower), m.in_args)
837 self.generate_args('_%s_method_info_%s_OUT_ARG'%(i.name_lower, m.name_lower), m.out_args)
839 num_anno = self.generate_annotations('_%s_method_%s_annotation_info'%(i.name_lower, m.name_lower), m.annotations)
841 self.c.write('static const _ExtendedGDBusMethodInfo _%s_method_info_%s =\n'
845 ' (gchar *) "%s",\n'%(i.name_lower, m.name_lower, m.name))
846 if len(m.in_args) == 0:
847 self.c.write(' NULL,\n')
849 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_IN_ARG_pointers,\n'%(i.name_lower, m.name_lower))
850 if len(m.out_args) == 0:
851 self.c.write(' NULL,\n')
853 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_OUT_ARG_pointers,\n'%(i.name_lower, m.name_lower))
855 self.c.write(' NULL\n')
857 self.c.write(' (GDBusAnnotationInfo **) &_%s_method_%s_annotation_info_pointers\n'%(i.name_lower, m.name_lower))
861 %(m.name_hyphen, 'TRUE' if unix_fd else 'FALSE'))
865 self.c.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] =\n'
866 '{\n'%(i.name_lower))
868 self.c.write(' &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
869 self.c.write(' NULL\n'
875 if len(i.signals) > 0:
877 self.generate_args('_%s_signal_info_%s_ARG'%(i.name_lower, s.name_lower), s.args)
879 num_anno = self.generate_annotations('_%s_signal_%s_annotation_info'%(i.name_lower, s.name_lower), s.annotations)
880 self.c.write('static const _ExtendedGDBusSignalInfo _%s_signal_info_%s =\n'
884 ' (gchar *) "%s",\n'%(i.name_lower, s.name_lower, s.name))
886 self.c.write(' NULL,\n')
888 self.c.write(' (GDBusArgInfo **) &_%s_signal_info_%s_ARG_pointers,\n'%(i.name_lower, s.name_lower))
890 self.c.write(' NULL\n')
892 self.c.write(' (GDBusAnnotationInfo **) &_%s_signal_%s_annotation_info_pointers\n'%(i.name_lower, s.name_lower))
899 self.c.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
900 '{\n'%(i.name_lower))
902 self.c.write(' &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
903 self.c.write(' NULL\n'
909 if len(i.properties) > 0:
910 for p in i.properties:
911 if p.readable and p.writable:
912 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
914 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE'
916 access = 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
918 access = 'G_DBUS_PROPERTY_INFO_FLAGS_NONE'
919 num_anno = self.generate_annotations('_%s_property_%s_annotation_info'%(i.name_lower, p.name_lower), p.annotations)
920 self.c.write('static const _ExtendedGDBusPropertyInfo _%s_property_info_%s =\n'
926 ' %s,\n'%(i.name_lower, p.name_lower, p.name, p.arg.signature, access))
928 self.c.write(' NULL\n')
930 self.c.write(' (GDBusAnnotationInfo **) &_%s_property_%s_annotation_info_pointers\n'%(i.name_lower, p.name_lower))
934 if not utils.lookup_annotation(p.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
935 self.c.write(' FALSE\n')
937 self.c.write(' TRUE\n')
941 self.c.write('static const _ExtendedGDBusPropertyInfo * const _%s_property_info_pointers[] =\n'
942 '{\n'%(i.name_lower))
943 for p in i.properties:
944 self.c.write(' &_%s_property_info_%s,\n'%(i.name_lower, p.name_lower))
945 self.c.write(' NULL\n'
949 num_anno = self.generate_annotations('_%s_annotation_info'%(i.name_lower), i.annotations)
950 self.c.write('static const _ExtendedGDBusInterfaceInfo _%s_interface_info =\n'
954 ' (gchar *) "%s",\n'%(i.name_lower, i.name))
955 if len(i.methods) == 0:
956 self.c.write(' NULL,\n')
958 self.c.write(' (GDBusMethodInfo **) &_%s_method_info_pointers,\n'%(i.name_lower))
959 if len(i.signals) == 0:
960 self.c.write(' NULL,\n')
962 self.c.write(' (GDBusSignalInfo **) &_%s_signal_info_pointers,\n'%(i.name_lower))
963 if len(i.properties) == 0:
964 self.c.write(' NULL,\n')
966 self.c.write(' (GDBusPropertyInfo **) &_%s_property_info_pointers,\n'%(i.name_lower))
968 self.c.write(' NULL\n')
970 self.c.write(' (GDBusAnnotationInfo **) &_%s_annotation_info_pointers\n'%(i.name_lower))
977 self.c.write(self.docbook_gen.expand(
979 ' * %s_interface_info:\n'
981 ' * Gets a machine-readable description of the #%s D-Bus interface.\n'
983 ' * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free.\n'
984 %(i.name_lower, i.name), False))
985 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
986 self.c.write('GDBusInterfaceInfo *\n'
987 '%s_interface_info (void)\n'
989 ' return (GDBusInterfaceInfo *) &_%s_interface_info.parent_struct;\n'
991 '\n'%(i.name_lower, i.name_lower))
993 self.c.write(self.docbook_gen.expand(
995 ' * %s_override_properties:\n'
996 ' * @klass: The class structure for a #GObject<!-- -->-derived class.\n'
997 ' * @property_id_begin: The property id to assign to the first overridden property.\n'
999 ' * Overrides all #GObject properties in the #%s interface for a concrete class.\n'
1000 ' * The properties are overridden in the order they are defined.\n'
1002 ' * Returns: The last property id.\n'
1003 %(i.name_lower, i.camel_name), False))
1004 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1005 self.c.write('guint\n'
1006 '%s_override_properties (GObjectClass *klass, guint property_id_begin)\n'
1007 '{\n'%(i.name_lower))
1008 for p in i.properties:
1009 self.c.write (' g_object_class_override_property (klass, property_id_begin++, "%s");\n'%(p.name_hyphen))
1010 self.c.write(' return property_id_begin - 1;\n'
1015 # ----------------------------------------------------------------------------------------------------
1017 def generate_interface(self, i):
1020 self.c.write(self.docbook_gen.expand(
1024 ' * Abstract interface type for the D-Bus interface #%s.\n'
1025 %(i.camel_name, i.name), False))
1026 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1029 self.c.write(self.docbook_gen.expand(
1032 ' * @parent_iface: The parent interface.\n'
1033 %(i.camel_name), False))
1036 if len(i.methods) > 0:
1038 key = (m.since, '_method_%s'%m.name_lower)
1039 value = '@handle_%s: '%(m.name_lower)
1040 value += 'Handler for the #%s::handle-%s signal.'%(i.camel_name, m.name_hyphen)
1041 doc_bits[key] = value
1042 if len(i.signals) > 0:
1044 key = (s.since, '_signal_%s'%s.name_lower)
1045 value = '@%s: '%(s.name_lower)
1046 value += 'Handler for the #%s::%s signal.'%(i.camel_name, s.name_hyphen)
1047 doc_bits[key] = value
1048 if len(i.properties) > 0:
1049 for p in i.properties:
1050 key = (p.since, '_prop_get_%s'%p.name_lower)
1051 value = '@get_%s: '%(p.name_lower)
1052 value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
1053 doc_bits[key] = value
1054 for key in sorted(doc_bits.keys(), key=utils.version_cmp_key):
1055 self.c.write(' * %s\n'%doc_bits[key])
1057 self.c.write(self.docbook_gen.expand(
1059 ' * Virtual table for the D-Bus interface #%s.\n'
1061 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1064 self.c.write('typedef %sIface %sInterface;\n'%(i.camel_name, i.camel_name))
1065 self.c.write('G_DEFINE_INTERFACE (%s, %s, G_TYPE_OBJECT);\n'%(i.camel_name, i.name_lower))
1068 self.c.write('static void\n'
1069 '%s_default_init (%sIface *iface)\n'
1070 '{\n'%(i.name_lower, i.camel_name));
1072 if len(i.methods) > 0:
1073 self.c.write(' /* GObject signals for incoming D-Bus method calls: */\n')
1076 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1078 self.c.write(self.docbook_gen.expand(
1080 ' * %s::handle-%s:\n'
1081 ' * @object: A #%s.\n'
1082 ' * @invocation: A #GDBusMethodInvocation.\n'
1083 %(i.camel_name, m.name_hyphen, i.camel_name), False))
1085 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1087 self.c.write (' * @arg_%s: Argument passed by remote caller.\n'%(a.name))
1088 self.c.write(self.docbook_gen.expand(
1090 ' * Signal emitted when a remote caller is invoking the %s.%s() D-Bus method.\n'
1092 ' * 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'
1094 ' * Returns: %%TRUE if the invocation was handled, %%FALSE to let other signal handlers run.\n'
1095 %(i.name, m.name, i.name_lower, m.name_lower), False))
1096 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 2)
1101 self.c.write(' g_signal_new ("handle-%s",\n'
1102 ' G_TYPE_FROM_INTERFACE (iface),\n'
1103 ' G_SIGNAL_RUN_LAST,\n'
1104 ' G_STRUCT_OFFSET (%sIface, handle_%s),\n'
1105 ' g_signal_accumulator_true_handled,\n'
1106 ' NULL,\n' # accu_data
1107 ' g_cclosure_marshal_generic,\n'
1108 ' G_TYPE_BOOLEAN,\n'
1110 ' G_TYPE_DBUS_METHOD_INVOCATION'
1111 %(m.name_hyphen, i.camel_name, m.name_lower, len(m.in_args) + extra_args))
1113 self.c.write(', G_TYPE_UNIX_FD_LIST')
1115 self.c.write (', %s'%(a.gtype))
1116 self.c.write(');\n')
1119 if len(i.signals) > 0:
1120 self.c.write(' /* GObject signals for received D-Bus signals: */\n')
1122 self.c.write(self.docbook_gen.expand(
1125 ' * @object: A #%s.\n'
1126 %(i.camel_name, s.name_hyphen, i.camel_name), False))
1128 self.c.write (' * @arg_%s: Argument.\n'%(a.name))
1129 self.c.write(self.docbook_gen.expand(
1131 ' * On the client-side, this signal is emitted whenever the D-Bus signal #%s::%s is received.\n'
1133 ' * 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'
1134 %(i.name, s.name), False))
1135 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 2)
1136 self.c.write(' g_signal_new ("%s",\n'
1137 ' G_TYPE_FROM_INTERFACE (iface),\n'
1138 ' G_SIGNAL_RUN_LAST,\n'
1139 ' G_STRUCT_OFFSET (%sIface, %s),\n'
1140 ' NULL,\n' # accumulator
1141 ' NULL,\n' # accu_data
1142 ' g_cclosure_marshal_generic,\n'
1145 %(s.name_hyphen, i.camel_name, s.name_lower, len(s.args)))
1147 self.c.write (', %s'%(a.gtype))
1148 self.c.write(');\n')
1151 if len(i.properties) > 0:
1152 self.c.write(' /* GObject properties for D-Bus properties: */\n')
1153 for p in i.properties:
1154 if p.readable and p.writable:
1155 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.'
1157 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.'
1159 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.'
1161 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1162 self.c.write(self.docbook_gen.expand(
1166 ' * Represents the D-Bus property #%s:%s.\n'
1169 %(i.camel_name, p.name_hyphen, i.name, p.name, hint), False))
1170 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 2)
1171 self.c.write(' g_object_interface_install_property (iface,\n')
1172 if p.arg.gtype == 'G_TYPE_VARIANT':
1173 s = 'g_param_spec_variant ("%s", "%s", "%s", G_VARIANT_TYPE ("%s"), NULL'%(p.name_hyphen, p.name, p.name, p.arg.signature)
1174 elif p.arg.signature == 'b':
1175 s = 'g_param_spec_boolean ("%s", "%s", "%s", FALSE'%(p.name_hyphen, p.name, p.name)
1176 elif p.arg.signature == 'y':
1177 s = 'g_param_spec_uchar ("%s", "%s", "%s", 0, 255, 0'%(p.name_hyphen, p.name, p.name)
1178 elif p.arg.signature == 'n':
1179 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT16, G_MAXINT16, 0'%(p.name_hyphen, p.name, p.name)
1180 elif p.arg.signature == 'q':
1181 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT16, 0'%(p.name_hyphen, p.name, p.name)
1182 elif p.arg.signature == 'i':
1183 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT32, G_MAXINT32, 0'%(p.name_hyphen, p.name, p.name)
1184 elif p.arg.signature == 'u':
1185 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT32, 0'%(p.name_hyphen, p.name, p.name)
1186 elif p.arg.signature == 'x':
1187 s = 'g_param_spec_int64 ("%s", "%s", "%s", G_MININT64, G_MAXINT64, 0'%(p.name_hyphen, p.name, p.name)
1188 elif p.arg.signature == 't':
1189 s = 'g_param_spec_uint64 ("%s", "%s", "%s", 0, G_MAXUINT64, 0'%(p.name_hyphen, p.name, p.name)
1190 elif p.arg.signature == 'd':
1191 s = 'g_param_spec_double ("%s", "%s", "%s", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0'%(p.name_hyphen, p.name, p.name)
1192 elif p.arg.signature == 's':
1193 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1194 elif p.arg.signature == 'o':
1195 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1196 elif p.arg.signature == 'g':
1197 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1198 elif p.arg.signature == 'ay':
1199 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1200 elif p.arg.signature == 'as':
1201 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1202 elif p.arg.signature == 'ao':
1203 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1204 elif p.arg.signature == 'aay':
1205 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1207 raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
1208 self.c.write(' %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
1214 # ----------------------------------------------------------------------------------------------------
1216 def generate_property_accessors(self, i):
1217 for p in i.properties:
1219 if p.readable and p.writable:
1220 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.'
1222 hint = 'Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.'
1224 hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
1226 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1227 self.c.write(self.docbook_gen.expand(
1229 ' * %s_get_%s: (skip)\n'
1230 ' * @object: A #%s.\n'
1232 ' * Gets the value of the #%s:%s D-Bus property.\n'
1236 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1237 if p.arg.free_func != None:
1238 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'
1240 ' * 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'
1241 %(i.name_lower, p.name_lower))
1243 self.c.write(' * Returns: The property value.\n')
1244 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1246 '%s_get_%s (%s *object)\n'
1247 '{\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
1248 self.c.write(' return %s%s_GET_IFACE (object)->get_%s (object);\n'%(i.ns_upper, i.name_upper, p.name_lower))
1251 if p.arg.free_func != None:
1253 self.c.write(self.docbook_gen.expand(
1255 ' * %s_dup_%s: (skip)\n'
1256 ' * @object: A #%s.\n'
1258 ' * Gets a copy of the #%s:%s D-Bus property.\n'
1262 ' * Returns: (transfer full): The property value or %%NULL if the property is not set. The returned value should be freed with %s().\n'
1263 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint, p.arg.free_func), False))
1264 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1266 '%s_dup_%s (%s *object)\n'
1268 ' %svalue;\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in_dup))
1269 self.c.write(' g_object_get (G_OBJECT (object), "%s", &value, NULL);\n'%(p.name_hyphen))
1270 self.c.write(' return value;\n')
1275 if p.readable and p.writable:
1276 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.'
1278 hint = 'Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.'
1280 hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
1282 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1283 self.c.write(self.docbook_gen.expand(
1285 ' * %s_set_%s: (skip)\n'
1286 ' * @object: A #%s.\n'
1287 ' * @value: The value to set.\n'
1289 ' * Sets the #%s:%s D-Bus property to @value.\n'
1292 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1293 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1294 self.c.write('void\n'
1295 '%s_set_%s (%s *object, %svalue)\n'
1296 '{\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
1297 self.c.write(' g_object_set (G_OBJECT (object), "%s", value, NULL);\n'%(p.name_hyphen))
1301 # ---------------------------------------------------------------------------------------------------
1303 def generate_signal_emitters(self, i):
1305 self.c.write(self.docbook_gen.expand(
1308 ' * @object: A #%s.\n'
1309 %(i.name_lower, s.name_lower, i.camel_name), False))
1311 self.c.write(' * @arg_%s: Argument to pass with the signal.\n'%(a.name))
1312 self.c.write(self.docbook_gen.expand(
1314 ' * Emits the #%s::%s D-Bus signal.\n'
1315 %(i.name, s.name), False))
1316 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 0)
1317 self.c.write('void\n'
1319 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
1321 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1324 ' g_signal_emit_by_name (object, "%s"'%(s.name_hyphen))
1326 self.c.write(', arg_%s'%a.name)
1327 self.c.write(');\n')
1331 # ---------------------------------------------------------------------------------------------------
1333 def generate_method_calls(self, i):
1336 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1339 self.c.write('/**\n'
1341 ' * @proxy: A #%sProxy.\n'
1342 %(i.name_lower, m.name_lower, i.camel_name))
1344 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1346 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1347 self.c.write(self.docbook_gen.expand(
1348 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1349 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %%NULL.\n'
1350 ' * @user_data: User data to pass to @callback.\n'
1352 ' * Asynchronously invokes the %s.%s() D-Bus method on @proxy.\n'
1353 ' * 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'
1354 ' * You can then call %s_call_%s_finish() to get the result of the operation.\n'
1356 ' * See %s_call_%s_sync() for the synchronous, blocking version of this method.\n'
1357 %(i.name, m.name, i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1358 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1359 self.c.write('void\n'
1361 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1363 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1365 self.c.write(',\n GUnixFDList *fd_list')
1367 ' GCancellable *cancellable,\n'
1368 ' GAsyncReadyCallback callback,\n'
1369 ' gpointer user_data)\n'
1372 self.c.write(' g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy),\n')
1374 self.c.write(' g_dbus_proxy_call (G_DBUS_PROXY (proxy),\n')
1375 self.c.write(' "%s",\n'
1376 ' g_variant_new ("('%(m.name))
1378 self.c.write('%s'%(a.format_in))
1381 self.c.write(',\n arg_%s'%(a.name))
1383 ' G_DBUS_CALL_FLAGS_NONE,\n'
1386 self.c.write(' fd_list,\n')
1387 self.c.write(' cancellable,\n'
1393 self.c.write('/**\n'
1394 ' * %s_call_%s_finish:\n'
1395 ' * @proxy: A #%sProxy.\n'
1396 %(i.name_lower, m.name_lower, i.camel_name))
1397 for a in m.out_args:
1398 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1400 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1401 self.c.write(self.docbook_gen.expand(
1402 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_call_%s().\n'
1403 ' * @error: Return location for error or %%NULL.\n'
1405 ' * Finishes an operation started with %s_call_%s().\n'
1407 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1408 %(i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1409 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1410 self.c.write('gboolean\n'
1411 '%s_call_%s_finish (\n'
1412 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1413 for a in m.out_args:
1414 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1416 self.c.write(',\n GUnixFDList **out_fd_list')
1418 ' GAsyncResult *res,\n'
1419 ' GError **error)\n'
1421 ' GVariant *_ret;\n')
1423 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error);\n')
1425 self.c.write(' _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);\n')
1426 self.c.write(' if (_ret == NULL)\n'
1428 self.c.write(' g_variant_get (_ret,\n'
1430 for a in m.out_args:
1431 self.c.write('%s'%(a.format_out))
1433 for a in m.out_args:
1434 self.c.write(',\n out_%s'%(a.name))
1436 ' g_variant_unref (_ret);\n')
1437 self.c.write('_out:\n'
1438 ' return _ret != NULL;\n'
1444 self.c.write('/**\n'
1445 ' * %s_call_%s_sync:\n'
1446 ' * @proxy: A #%sProxy.\n'
1447 %(i.name_lower, m.name_lower, i.camel_name))
1449 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1451 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1452 for a in m.out_args:
1453 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1455 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1456 self.c.write(self.docbook_gen.expand(
1457 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1458 ' * @error: Return location for error or %%NULL.\n'
1460 ' * Synchronously invokes the %s.%s() D-Bus method on @proxy. The calling thread is blocked until a reply is received.\n'
1462 ' * See %s_call_%s() for the asynchronous version of this method.\n'
1464 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1465 %(i.name, m.name, i.name_lower, m.name_lower), False))
1466 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1467 self.c.write('gboolean\n'
1468 '%s_call_%s_sync (\n'
1469 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1471 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1473 self.c.write(',\n GUnixFDList *fd_list')
1474 for a in m.out_args:
1475 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1477 self.c.write(',\n GUnixFDList **out_fd_list')
1479 ' GCancellable *cancellable,\n'
1480 ' GError **error)\n'
1482 ' GVariant *_ret;\n')
1484 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy),\n')
1486 self.c.write(' _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),\n')
1487 self.c.write(' "%s",\n'
1488 ' g_variant_new ("('%(m.name))
1490 self.c.write('%s'%(a.format_in))
1493 self.c.write(',\n arg_%s'%(a.name))
1495 ' G_DBUS_CALL_FLAGS_NONE,\n'
1498 self.c.write(' fd_list,\n'
1500 self.c.write(' cancellable,\n'
1502 ' if (_ret == NULL)\n'
1504 self.c.write(' g_variant_get (_ret,\n'
1506 for a in m.out_args:
1507 self.c.write('%s'%(a.format_out))
1509 for a in m.out_args:
1510 self.c.write(',\n out_%s'%(a.name))
1512 ' g_variant_unref (_ret);\n')
1513 self.c.write('_out:\n'
1514 ' return _ret != NULL;\n'
1518 # ---------------------------------------------------------------------------------------------------
1520 def generate_method_completers(self, i):
1523 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1525 self.c.write('/**\n'
1526 ' * %s_complete_%s:\n'
1527 ' * @object: A #%s.\n'
1528 ' * @invocation: (transfer full): A #GDBusMethodInvocation.\n'
1529 %(i.name_lower, m.name_lower, i.camel_name))
1531 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1532 for a in m.out_args:
1533 self.c.write(' * @%s: Parameter to return.\n'%(a.name))
1534 self.c.write(self.docbook_gen.expand(
1536 ' * 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'
1538 ' * This method will free @invocation, you cannot use it afterwards.\n'
1539 %(i.name, m.name), False))
1540 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1541 self.c.write('void\n'
1542 '%s_complete_%s (\n'
1544 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
1546 self.c.write(',\n GUnixFDList *fd_list')
1547 for a in m.out_args:
1548 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1553 self.c.write(' g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,\n'
1554 ' g_variant_new ("(')
1556 self.c.write(' g_dbus_method_invocation_return_value (invocation,\n'
1557 ' g_variant_new ("(')
1558 for a in m.out_args:
1559 self.c.write('%s'%(a.format_in))
1561 for a in m.out_args:
1562 self.c.write(',\n %s'%(a.name))
1564 self.c.write('),\n fd_list);\n')
1566 self.c.write('));\n')
1570 # ---------------------------------------------------------------------------------------------------
1572 def generate_proxy(self, i):
1574 self.c.write('/* ------------------------------------------------------------------------ */\n'
1577 self.c.write(self.docbook_gen.expand(
1581 ' * The #%sProxy structure contains only private data and should only be accessed using the provided API.\n'
1582 %(i.camel_name, i.camel_name), False))
1583 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1586 self.c.write(self.docbook_gen.expand(
1588 ' * %sProxyClass:\n'
1589 ' * @parent_class: The parent class.\n'
1591 ' * Class structure for #%sProxy.\n'
1592 %(i.camel_name, i.camel_name), False))
1593 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1596 self.c.write('struct _%sProxyPrivate\n'
1602 self.c.write('static void %s_proxy_iface_init (%sIface *iface);\n'
1603 '\n'%(i.name_lower, i.camel_name))
1604 self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
1605 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1606 self.c.write(' G_ADD_PRIVATE (%sProxy)\n'%(i.camel_name))
1607 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1608 self.c.write('#else\n')
1609 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1610 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1611 self.c.write('#endif\n')
1614 self.c.write('static void\n'
1615 '%s_proxy_finalize (GObject *object)\n'
1616 '{\n'%(i.name_lower))
1617 self.c.write(' %sProxy *proxy = %s%s_PROXY (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
1618 self.c.write(' g_datalist_clear (&proxy->priv->qdata);\n')
1619 self.c.write(' G_OBJECT_CLASS (%s_proxy_parent_class)->finalize (object);\n'
1621 '\n'%(i.name_lower))
1623 # property accessors
1625 # Note that we are guaranteed that prop_id starts at 1 and is
1626 # laid out in the same order as introspection data pointers
1628 self.c.write('static void\n'
1629 '%s_proxy_get_property (GObject *object,\n'
1632 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
1633 '{\n'%(i.name_lower))
1634 if len(i.properties) > 0:
1635 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1636 ' GVariant *variant;\n'
1637 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1638 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1639 ' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
1640 ' if (info->use_gvariant)\n'
1642 ' g_value_set_variant (value, variant);\n'
1646 # could be that we don't have the value in cache - in that case, we do
1647 # nothing and the user gets the default value for the GType
1648 ' if (variant != NULL)\n'
1649 ' g_dbus_gvariant_to_gvalue (variant, value);\n'
1651 ' if (variant != NULL)\n'
1652 ' g_variant_unref (variant);\n'
1653 %(len(i.properties), i.name_lower))
1656 if len(i.properties) > 0:
1657 self.c.write('static void\n'
1658 '%s_proxy_set_property_cb (GDBusProxy *proxy,\n'
1659 ' GAsyncResult *res,\n'
1660 ' gpointer user_data)\n'
1661 '{\n'%(i.name_lower))
1662 self.c.write(' const _ExtendedGDBusPropertyInfo *info = user_data;\n'
1664 ' GVariant *_ret;\n'
1666 ' _ret = g_dbus_proxy_call_finish (proxy, res, &error);\n'
1669 ' g_warning ("Error setting property \'%%s\' on interface %s: %%s (%%s, %%d)",\n'
1670 ' info->parent_struct.name, \n'
1671 ' error->message, g_quark_to_string (error->domain), error->code);\n'
1672 ' g_error_free (error);\n'
1676 ' g_variant_unref (_ret);\n'
1681 self.c.write('static void\n'
1682 '%s_proxy_set_property (GObject *object,\n'
1684 ' const GValue *value,\n'
1685 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
1686 '{\n'%(i.name_lower))
1687 if len(i.properties) > 0:
1688 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1689 ' GVariant *variant;\n'
1690 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1691 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1692 ' variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
1693 ' g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
1694 ' "org.freedesktop.DBus.Properties.Set",\n'
1695 ' g_variant_new ("(ssv)", "%s", info->parent_struct.name, variant),\n'
1696 ' G_DBUS_CALL_FLAGS_NONE,\n'
1698 ' NULL, (GAsyncReadyCallback) %s_proxy_set_property_cb, (GDBusPropertyInfo *) &info->parent_struct);\n'
1699 ' g_variant_unref (variant);\n'
1700 %(len(i.properties), i.name_lower, i.name, i.name_lower))
1705 self.c.write('static void\n'
1706 '%s_proxy_g_signal (GDBusProxy *proxy,\n'
1707 ' const gchar *sender_name G_GNUC_UNUSED,\n'
1708 ' const gchar *signal_name,\n'
1709 ' GVariant *parameters)\n'
1710 '{\n'%(i.name_lower))
1711 self.c.write(' _ExtendedGDBusSignalInfo *info;\n'
1712 ' GVariantIter iter;\n'
1713 ' GVariant *child;\n'
1714 ' GValue *paramv;\n'
1715 ' gsize num_params;\n'
1717 ' guint signal_id;\n');
1718 # Note: info could be NULL if we are talking to a newer version of the interface
1719 self.c.write(' info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, signal_name);\n'
1720 ' if (info == NULL)\n'
1723 self.c.write (' num_params = g_variant_n_children (parameters);\n'
1724 ' paramv = g_new0 (GValue, num_params + 1);\n'
1725 ' g_value_init (¶mv[0], %sTYPE_%s);\n'
1726 ' g_value_set_object (¶mv[0], proxy);\n'
1727 %(i.ns_upper, i.name_upper))
1728 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
1730 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
1732 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1];\n'
1733 ' if (arg_info->use_gvariant)\n'
1735 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
1736 ' g_value_set_variant (¶mv[n], child);\n'
1740 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
1741 ' g_variant_unref (child);\n'
1744 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
1745 %(i.ns_upper, i.name_upper))
1746 self.c.write(' g_signal_emitv (paramv, signal_id, 0, NULL);\n')
1747 self.c.write(' for (n = 0; n < num_params + 1; n++)\n'
1748 ' g_value_unset (¶mv[n]);\n'
1749 ' g_free (paramv);\n')
1754 self.c.write('static void\n'
1755 '%s_proxy_g_properties_changed (GDBusProxy *_proxy,\n'
1756 ' GVariant *changed_properties,\n'
1757 ' const gchar *const *invalidated_properties)\n'
1758 '{\n'%(i.name_lower))
1759 # Note: info could be NULL if we are talking to a newer version of the interface
1760 self.c.write(' %sProxy *proxy = %s%s_PROXY (_proxy);\n'
1762 ' const gchar *key;\n'
1763 ' GVariantIter *iter;\n'
1764 ' _ExtendedGDBusPropertyInfo *info;\n'
1765 ' g_variant_get (changed_properties, "a{sv}", &iter);\n'
1766 ' while (g_variant_iter_next (iter, "{&sv}", &key, NULL))\n'
1768 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, key);\n'
1769 ' g_datalist_remove_data (&proxy->priv->qdata, key);\n'
1770 ' if (info != NULL)\n'
1771 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1773 ' g_variant_iter_free (iter);\n'
1774 ' for (n = 0; invalidated_properties[n] != NULL; n++)\n'
1776 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, invalidated_properties[n]);\n'
1777 ' g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]);\n'
1778 ' if (info != NULL)\n'
1779 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1783 %(i.camel_name, i.ns_upper, i.name_upper,
1784 i.name_lower, i.name_lower))
1787 for p in i.properties:
1789 if p.arg.free_func != None:
1791 self.c.write('static %s\n'
1792 '%s_proxy_get_%s (%s *object)\n'
1794 ' %sProxy *proxy = %s%s_PROXY (object);\n'
1795 ' GVariant *variant;\n'
1796 ' %svalue = %s;\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name,
1797 i.camel_name, i.ns_upper, i.name_upper,
1798 p.arg.ctype_in, nul_value))
1799 # For some property types, we have to free the returned
1800 # value (or part of it, e.g. the container) because of how
1801 # GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
1804 free_container = False;
1805 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':
1806 free_container = True;
1807 # If already using an old value for strv, objpathv, bytestring_array (see below),
1808 # then just return that... that way the result from multiple consecutive calls
1809 # to the getter are valid as long as they're freed
1812 self.c.write(' value = g_datalist_get_data (&proxy->priv->qdata, \"%s\");\n'
1813 ' if (value != NULL)\n'
1816 self.c.write(' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \"%s\");\n'%(p.name))
1817 if p.arg.gtype == 'G_TYPE_VARIANT':
1818 self.c.write(' value = variant;\n')
1819 self.c.write(' if (variant != NULL)\n')
1820 self.c.write(' g_variant_unref (variant);\n')
1822 self.c.write(' if (variant != NULL)\n'
1825 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':
1826 extra_len = ', NULL'
1827 self.c.write(' value = %s (variant%s);\n'%(p.arg.gvariant_get, extra_len))
1829 self.c.write(' g_datalist_set_data_full (&proxy->priv->qdata, \"%s\", (gpointer) value, g_free);\n'
1831 self.c.write(' g_variant_unref (variant);\n')
1832 self.c.write(' }\n')
1833 self.c.write(' return value;\n')
1838 self.c.write('static void\n'
1839 '%s_proxy_init (%sProxy *proxy)\n'
1841 '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
1842 ' proxy->priv = %s_proxy_get_instance_private (proxy);\n'
1844 ' proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %sTYPE_%s_PROXY, %sProxyPrivate);\n'
1846 ' g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
1849 %(i.name_lower, i.camel_name,
1851 i.ns_upper, i.name_upper, i.camel_name,
1853 self.c.write('static void\n'
1854 '%s_proxy_class_init (%sProxyClass *klass)\n'
1856 ' GObjectClass *gobject_class;\n'
1857 ' GDBusProxyClass *proxy_class;\n'
1859 ' gobject_class = G_OBJECT_CLASS (klass);\n'
1860 ' gobject_class->finalize = %s_proxy_finalize;\n'
1861 ' gobject_class->get_property = %s_proxy_get_property;\n'
1862 ' gobject_class->set_property = %s_proxy_set_property;\n'
1864 ' proxy_class = G_DBUS_PROXY_CLASS (klass);\n'
1865 ' proxy_class->g_signal = %s_proxy_g_signal;\n'
1866 ' proxy_class->g_properties_changed = %s_proxy_g_properties_changed;\n'
1867 '\n'%(i.name_lower, i.camel_name,
1868 i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
1869 if len(i.properties) > 0:
1870 self.c.write(' %s_override_properties (gobject_class, 1);\n\n'%(i.name_lower))
1871 self.c.write('#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
1872 ' g_type_class_add_private (klass, sizeof (%sProxyPrivate));\n'
1873 '#endif\n'%(i.camel_name))
1877 self.c.write('static void\n'
1878 '%s_proxy_iface_init (%sIface *iface)\n'
1879 '{\n'%(i.name_lower, i.camel_name))
1880 for p in i.properties:
1881 self.c.write(' iface->get_%s = %s_proxy_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
1886 self.c.write(self.docbook_gen.expand(
1888 ' * %s_proxy_new:\n'
1889 ' * @connection: A #GDBusConnection.\n'
1890 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1891 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1892 ' * @object_path: An object path.\n'
1893 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1894 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1895 ' * @user_data: User data to pass to @callback.\n'
1897 ' * Asynchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new() for more details.\n'
1899 ' * 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'
1900 ' * You can then call %s_proxy_new_finish() to get the result of the operation.\n'
1902 ' * See %s_proxy_new_sync() for the synchronous, blocking version of this constructor.\n'
1903 %(i.name_lower, i.name, i.name_lower, i.name_lower), False))
1904 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1905 self.c.write('void\n'
1907 ' GDBusConnection *connection,\n'
1908 ' GDBusProxyFlags flags,\n'
1909 ' const gchar *name,\n'
1910 ' const gchar *object_path,\n'
1911 ' GCancellable *cancellable,\n'
1912 ' GAsyncReadyCallback callback,\n'
1913 ' gpointer user_data)\n'
1915 ' 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'
1918 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1919 self.c.write('/**\n'
1920 ' * %s_proxy_new_finish:\n'
1921 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new().\n'
1922 ' * @error: Return location for error or %%NULL\n'
1924 ' * Finishes an operation started with %s_proxy_new().\n'
1926 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1927 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1928 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1929 self.c.write('%s *\n'
1930 '%s_proxy_new_finish (\n'
1931 ' GAsyncResult *res,\n'
1932 ' GError **error)\n'
1935 ' GObject *source_object;\n'
1936 ' source_object = g_async_result_get_source_object (res);\n'
1937 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1938 ' g_object_unref (source_object);\n'
1939 ' if (ret != NULL)\n'
1940 ' return %s%s (ret);\n'
1945 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1946 self.c.write(self.docbook_gen.expand(
1948 ' * %s_proxy_new_sync:\n'
1949 ' * @connection: A #GDBusConnection.\n'
1950 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1951 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1952 ' * @object_path: An object path.\n'
1953 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1954 ' * @error: Return location for error or %%NULL\n'
1956 ' * Synchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new_sync() for more details.\n'
1958 ' * The calling thread is blocked until a reply is received.\n'
1960 ' * See %s_proxy_new() for the asynchronous version of this constructor.\n'
1962 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1963 %(i.name_lower, i.name, i.name_lower, i.camel_name), False))
1964 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1965 self.c.write('%s *\n'
1966 '%s_proxy_new_sync (\n'
1967 ' GDBusConnection *connection,\n'
1968 ' GDBusProxyFlags flags,\n'
1969 ' const gchar *name,\n'
1970 ' const gchar *object_path,\n'
1971 ' GCancellable *cancellable,\n'
1972 ' GError **error)\n'
1974 ' GInitable *ret;\n'
1975 ' 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'
1976 ' if (ret != NULL)\n'
1977 ' return %s%s (ret);\n'
1982 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
1984 self.c.write(self.docbook_gen.expand(
1986 ' * %s_proxy_new_for_bus:\n'
1987 ' * @bus_type: A #GBusType.\n'
1988 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1989 ' * @name: A bus name (well-known or unique).\n'
1990 ' * @object_path: An object path.\n'
1991 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1992 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1993 ' * @user_data: User data to pass to @callback.\n'
1995 ' * Like %s_proxy_new() but takes a #GBusType instead of a #GDBusConnection.\n'
1997 ' * 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'
1998 ' * You can then call %s_proxy_new_for_bus_finish() to get the result of the operation.\n'
2000 ' * See %s_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
2001 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower), False))
2002 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2003 self.c.write('void\n'
2004 '%s_proxy_new_for_bus (\n'
2005 ' GBusType bus_type,\n'
2006 ' GDBusProxyFlags flags,\n'
2007 ' const gchar *name,\n'
2008 ' const gchar *object_path,\n'
2009 ' GCancellable *cancellable,\n'
2010 ' GAsyncReadyCallback callback,\n'
2011 ' gpointer user_data)\n'
2013 ' 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'
2016 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
2017 self.c.write('/**\n'
2018 ' * %s_proxy_new_for_bus_finish:\n'
2019 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new_for_bus().\n'
2020 ' * @error: Return location for error or %%NULL\n'
2022 ' * Finishes an operation started with %s_proxy_new_for_bus().\n'
2024 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2025 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
2026 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2027 self.c.write('%s *\n'
2028 '%s_proxy_new_for_bus_finish (\n'
2029 ' GAsyncResult *res,\n'
2030 ' GError **error)\n'
2033 ' GObject *source_object;\n'
2034 ' source_object = g_async_result_get_source_object (res);\n'
2035 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
2036 ' g_object_unref (source_object);\n'
2037 ' if (ret != NULL)\n'
2038 ' return %s%s (ret);\n'
2043 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
2044 self.c.write(self.docbook_gen.expand(
2046 ' * %s_proxy_new_for_bus_sync:\n'
2047 ' * @bus_type: A #GBusType.\n'
2048 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
2049 ' * @name: A bus name (well-known or unique).\n'
2050 ' * @object_path: An object path.\n'
2051 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
2052 ' * @error: Return location for error or %%NULL\n'
2054 ' * Like %s_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
2056 ' * The calling thread is blocked until a reply is received.\n'
2058 ' * See %s_proxy_new_for_bus() for the asynchronous version of this constructor.\n'
2060 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2061 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name), False))
2062 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2063 self.c.write('%s *\n'
2064 '%s_proxy_new_for_bus_sync (\n'
2065 ' GBusType bus_type,\n'
2066 ' GDBusProxyFlags flags,\n'
2067 ' const gchar *name,\n'
2068 ' const gchar *object_path,\n'
2069 ' GCancellable *cancellable,\n'
2070 ' GError **error)\n'
2072 ' GInitable *ret;\n'
2073 ' 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'
2074 ' if (ret != NULL)\n'
2075 ' return %s%s (ret);\n'
2080 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
2083 # ---------------------------------------------------------------------------------------------------
2085 def generate_skeleton(self, i):
2087 self.c.write('/* ------------------------------------------------------------------------ */\n'
2090 self.c.write(self.docbook_gen.expand(
2094 ' * The #%sSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2095 %(i.camel_name, i.camel_name), False))
2096 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2099 self.c.write(self.docbook_gen.expand(
2101 ' * %sSkeletonClass:\n'
2102 ' * @parent_class: The parent class.\n'
2104 ' * Class structure for #%sSkeleton.\n'
2105 %(i.camel_name, i.camel_name), False))
2106 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2109 self.c.write('struct _%sSkeletonPrivate\n'
2111 ' GValue *properties;\n'
2112 ' GList *changed_properties;\n'
2113 ' GSource *changed_properties_idle_source;\n'
2114 ' GMainContext *context;\n'
2119 self.c.write('static void\n'
2120 '_%s_skeleton_handle_method_call (\n'
2121 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2122 ' const gchar *sender G_GNUC_UNUSED,\n'
2123 ' const gchar *object_path G_GNUC_UNUSED,\n'
2124 ' const gchar *interface_name,\n'
2125 ' const gchar *method_name,\n'
2126 ' GVariant *parameters,\n'
2127 ' GDBusMethodInvocation *invocation,\n'
2128 ' gpointer user_data)\n'
2130 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2131 ' _ExtendedGDBusMethodInfo *info;\n'
2132 ' GVariantIter iter;\n'
2133 ' GVariant *child;\n'
2134 ' GValue *paramv;\n'
2135 ' gsize num_params;\n'
2136 ' guint num_extra;\n'
2138 ' guint signal_id;\n'
2139 ' GValue return_value = G_VALUE_INIT;\n'
2140 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2141 self.c.write(' info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n'
2142 ' g_assert (info != NULL);\n'
2144 self.c.write (' num_params = g_variant_n_children (parameters);\n'
2145 ' num_extra = info->pass_fdlist ? 3 : 2;'
2146 ' paramv = g_new0 (GValue, num_params + num_extra);\n'
2148 ' g_value_init (¶mv[n], %sTYPE_%s);\n'
2149 ' g_value_set_object (¶mv[n++], skeleton);\n'
2150 ' g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION);\n'
2151 ' g_value_set_object (¶mv[n++], invocation);\n'
2152 ' if (info->pass_fdlist)\n'
2154 '#ifdef G_OS_UNIX\n'
2155 ' g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST);\n'
2156 ' g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)));\n'
2158 ' g_assert_not_reached ();\n'
2161 %(i.ns_upper, i.name_upper))
2162 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
2163 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
2165 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra];\n'
2166 ' if (arg_info->use_gvariant)\n'
2168 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
2169 ' g_value_set_variant (¶mv[n], child);\n'
2173 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
2174 ' g_variant_unref (child);\n'
2177 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
2178 %(i.ns_upper, i.name_upper))
2179 self.c.write(' g_value_init (&return_value, G_TYPE_BOOLEAN);\n'
2180 ' g_signal_emitv (paramv, signal_id, 0, &return_value);\n'
2181 ' if (!g_value_get_boolean (&return_value))\n'
2182 ' 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'
2183 ' g_value_unset (&return_value);\n'
2185 self.c.write(' for (n = 0; n < num_params + num_extra; n++)\n'
2186 ' g_value_unset (¶mv[n]);\n'
2187 ' g_free (paramv);\n')
2191 self.c.write('static GVariant *\n'
2192 '_%s_skeleton_handle_get_property (\n'
2193 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2194 ' const gchar *sender G_GNUC_UNUSED,\n'
2195 ' const gchar *object_path G_GNUC_UNUSED,\n'
2196 ' const gchar *interface_name G_GNUC_UNUSED,\n'
2197 ' const gchar *property_name,\n'
2198 ' GError **error,\n'
2199 ' gpointer user_data)\n'
2201 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2202 ' GValue value = G_VALUE_INIT;\n'
2203 ' GParamSpec *pspec;\n'
2204 ' _ExtendedGDBusPropertyInfo *info;\n'
2206 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2207 self.c.write(' ret = NULL;\n'
2208 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2209 ' g_assert (info != NULL);\n'
2210 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2211 ' if (pspec == NULL)\n'
2213 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2217 ' g_value_init (&value, pspec->value_type);\n'
2218 ' g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2219 ' ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
2220 ' g_value_unset (&value);\n'
2227 self.c.write('static gboolean\n'
2228 '_%s_skeleton_handle_set_property (\n'
2229 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2230 ' const gchar *sender G_GNUC_UNUSED,\n'
2231 ' const gchar *object_path G_GNUC_UNUSED,\n'
2232 ' const gchar *interface_name G_GNUC_UNUSED,\n'
2233 ' const gchar *property_name,\n'
2234 ' GVariant *variant,\n'
2235 ' GError **error,\n'
2236 ' gpointer user_data)\n'
2238 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2239 ' GValue value = G_VALUE_INIT;\n'
2240 ' GParamSpec *pspec;\n'
2241 ' _ExtendedGDBusPropertyInfo *info;\n'
2243 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2244 self.c.write(' ret = FALSE;\n'
2245 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2246 ' g_assert (info != NULL);\n'
2247 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2248 ' if (pspec == NULL)\n'
2250 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2254 ' if (info->use_gvariant)\n'
2255 ' g_value_set_variant (&value, variant);\n'
2257 ' g_dbus_gvariant_to_gvalue (variant, &value);\n'
2258 ' g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2259 ' g_value_unset (&value);\n'
2268 self.c.write('static const GDBusInterfaceVTable _%s_skeleton_vtable =\n'
2270 ' _%s_skeleton_handle_method_call,\n'
2271 ' _%s_skeleton_handle_get_property,\n'
2272 ' _%s_skeleton_handle_set_property,\n'
2275 '\n'%(i.name_lower, i.name_lower, i.name_lower, i.name_lower))
2277 self.c.write('static GDBusInterfaceInfo *\n'
2278 '%s_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2280 ' return %s_interface_info ();\n'
2281 %(i.name_lower, i.name_lower))
2285 self.c.write('static GDBusInterfaceVTable *\n'
2286 '%s_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2288 ' return (GDBusInterfaceVTable *) &_%s_skeleton_vtable;\n'
2289 %(i.name_lower, i.name_lower))
2293 self.c.write('static GVariant *\n'
2294 '%s_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton)\n'
2296 ' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2297 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2299 ' GVariantBuilder builder;\n'
2301 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2302 ' if (_%s_interface_info.parent_struct.properties == NULL)\n'
2304 ' for (n = 0; _%s_interface_info.parent_struct.properties[n] != NULL; n++)\n'
2306 ' GDBusPropertyInfo *info = _%s_interface_info.parent_struct.properties[n];\n'
2307 ' if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)\n'
2309 ' GVariant *value;\n'
2310 ' 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'
2311 ' if (value != NULL)\n'
2313 ' g_variant_take_ref (value);\n'
2314 ' g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
2315 ' g_variant_unref (value);\n'
2320 ' return g_variant_builder_end (&builder);\n'
2323 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name))
2325 if len(i.properties) > 0:
2326 self.c.write('static gboolean _%s_emit_changed (gpointer user_data);\n'
2330 self.c.write('static void\n'
2331 '%s_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton)\n'
2334 if len(i.properties) > 0:
2335 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2336 ' gboolean emit_changed = FALSE;\n'
2338 ' g_mutex_lock (&skeleton->priv->lock);\n'
2339 ' if (skeleton->priv->changed_properties_idle_source != NULL)\n'
2341 ' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
2342 ' skeleton->priv->changed_properties_idle_source = NULL;\n'
2343 ' emit_changed = TRUE;\n'
2345 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2347 ' if (emit_changed)\n'
2348 ' _%s_emit_changed (skeleton);\n'
2349 %(i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2354 self.c.write('static void\n'
2355 '_%s_on_signal_%s (\n'
2356 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
2358 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
2361 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n\n'
2362 ' GList *connections, *l;\n'
2363 ' GVariant *signal_variant;\n'
2364 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2365 %(i.camel_name, i.ns_upper, i.name_upper))
2367 ' signal_variant = g_variant_ref_sink (g_variant_new ("(')
2369 self.c.write('%s'%(a.format_in))
2372 self.c.write(',\n arg_%s'%(a.name))
2373 self.c.write('));\n')
2375 self.c.write(' for (l = connections; l != NULL; l = l->next)\n'
2377 ' GDBusConnection *connection = l->data;\n'
2378 ' g_dbus_connection_emit_signal (connection,\n'
2379 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", "%s",\n'
2380 ' signal_variant, NULL);\n'
2383 self.c.write(' g_variant_unref (signal_variant);\n')
2384 self.c.write(' g_list_free_full (connections, g_object_unref);\n')
2388 self.c.write('static void %s_skeleton_iface_init (%sIface *iface);\n'
2389 %(i.name_lower, i.camel_name))
2391 self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
2392 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2393 self.c.write(' G_ADD_PRIVATE (%sSkeleton)\n'%(i.camel_name))
2394 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2395 self.c.write('#else\n')
2396 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2397 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2398 self.c.write('#endif\n')
2401 self.c.write('static void\n'
2402 '%s_skeleton_finalize (GObject *object)\n'
2403 '{\n'%(i.name_lower))
2404 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2405 if len(i.properties) > 0:
2406 self.c.write(' guint n;\n'
2407 ' for (n = 0; n < %d; n++)\n'
2408 ' g_value_unset (&skeleton->priv->properties[n]);\n'%(len(i.properties)))
2409 self.c.write(' g_free (skeleton->priv->properties);\n')
2410 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2411 self.c.write(' if (skeleton->priv->changed_properties_idle_source != NULL)\n')
2412 self.c.write(' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
2413 self.c.write(' g_main_context_unref (skeleton->priv->context);\n')
2414 self.c.write(' g_mutex_clear (&skeleton->priv->lock);\n')
2415 self.c.write(' G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
2417 '\n'%(i.name_lower))
2419 # property accessors (TODO: generate PropertiesChanged signals in setter)
2420 if len(i.properties) > 0:
2421 self.c.write('static void\n'
2422 '%s_skeleton_get_property (GObject *object,\n'
2425 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
2426 '{\n'%(i.name_lower))
2427 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2428 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2429 ' g_mutex_lock (&skeleton->priv->lock);\n'
2430 ' g_value_copy (&skeleton->priv->properties[prop_id - 1], value);\n'
2431 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2432 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
2436 # if property is already scheduled then re-use entry.. though it could be
2439 # foo_set_prop_bar (object, "");
2440 # foo_set_prop_bar (object, "blah");
2442 # say, every update... In this case, where nothing happens, we obviously
2443 # don't want a PropertiesChanged() event. We can easily check for this
2444 # by comparing against the _original value_ recorded before the first
2445 # change event. If the latest value is not different from the original
2446 # one, we can simply ignore the ChangedProperty
2448 self.c.write('static gboolean\n'
2449 '_%s_emit_changed (gpointer user_data)\n'
2451 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2452 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2453 self.c.write(' GList *l;\n'
2454 ' GVariantBuilder builder;\n'
2455 ' GVariantBuilder invalidated_builder;\n'
2456 ' guint num_changes;\n'
2458 ' g_mutex_lock (&skeleton->priv->lock);\n'
2459 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2460 ' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
2461 ' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
2463 ' ChangedProperty *cp = l->data;\n'
2464 ' GVariant *variant;\n'
2465 ' const GValue *cur_value;\n'
2467 ' cur_value = &skeleton->priv->properties[cp->prop_id - 1];\n'
2468 ' if (!_g_value_equal (cur_value, &cp->orig_value))\n'
2470 ' variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature));\n'
2471 ' g_variant_builder_add (&builder, "{sv}", cp->info->parent_struct.name, variant);\n'
2472 ' g_variant_unref (variant);\n'
2476 ' if (num_changes > 0)\n'
2478 ' GList *connections, *ll;\n'
2479 ' GVariant *signal_variant;'
2481 ' signal_variant = g_variant_ref_sink (g_variant_new ("(sa{sv}as)", "%s",\n'
2482 ' &builder, &invalidated_builder));\n'
2483 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2484 ' for (ll = connections; ll != NULL; ll = ll->next)\n'
2486 ' GDBusConnection *connection = ll->data;\n'
2488 ' g_dbus_connection_emit_signal (connection,\n'
2489 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2490 ' "org.freedesktop.DBus.Properties",\n'
2491 ' "PropertiesChanged",\n'
2492 ' signal_variant,\n'
2495 ' g_variant_unref (signal_variant);\n'
2496 ' g_list_free_full (connections, g_object_unref);\n'
2500 ' g_variant_builder_clear (&builder);\n'
2501 ' g_variant_builder_clear (&invalidated_builder);\n'
2504 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2505 self.c.write(' skeleton->priv->changed_properties = NULL;\n')
2506 self.c.write(' skeleton->priv->changed_properties_idle_source = NULL;\n')
2507 self.c.write(' g_mutex_unlock (&skeleton->priv->lock);\n')
2508 self.c.write(' return FALSE;\n'
2511 # holding lock while being called
2512 self.c.write('static void\n'
2513 '_%s_schedule_emit_changed (%sSkeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value)\n'
2515 ' ChangedProperty *cp;\n'
2518 ' for (l = skeleton->priv->changed_properties; l != NULL; l = l->next)\n'
2520 ' ChangedProperty *i_cp = l->data;\n'
2521 ' if (i_cp->info == info)\n'
2527 %(i.name_lower, i.camel_name))
2528 self.c.write(' if (cp == NULL)\n'
2530 ' cp = g_new0 (ChangedProperty, 1);\n'
2531 ' cp->prop_id = prop_id;\n'
2532 ' cp->info = info;\n'
2533 ' skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp);\n'
2534 ' g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value));\n'
2535 ' g_value_copy (orig_value, &cp->orig_value);\n'
2541 # Postpone setting up the refresh source until the ::notify signal is emitted as
2542 # this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
2543 # This is useful when updating several properties from another thread than
2544 # where the idle will be emitted from
2545 self.c.write('static void\n'
2546 '%s_skeleton_notify (GObject *object,\n'
2547 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
2549 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2550 ' g_mutex_lock (&skeleton->priv->lock);\n'
2551 ' if (skeleton->priv->changed_properties != NULL &&\n'
2552 ' skeleton->priv->changed_properties_idle_source == NULL)\n'
2554 ' skeleton->priv->changed_properties_idle_source = g_idle_source_new ();\n'
2555 ' g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);\n'
2556 ' g_source_set_callback (skeleton->priv->changed_properties_idle_source, _%s_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);\n'
2557 ' g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _%s_emit_changed");\n'
2558 ' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
2559 ' g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
2561 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2564 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower, i.name_lower))
2566 self.c.write('static void\n'
2567 '%s_skeleton_set_property (GObject *object,\n'
2569 ' const GValue *value,\n'
2570 ' GParamSpec *pspec)\n'
2571 '{\n'%(i.name_lower))
2572 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2573 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2574 ' g_mutex_lock (&skeleton->priv->lock);\n'
2575 ' g_object_freeze_notify (object);\n'
2576 ' if (!_g_value_equal (value, &skeleton->priv->properties[prop_id - 1]))\n'
2578 ' if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
2579 ' _%s_schedule_emit_changed (skeleton, _%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties[prop_id - 1]);\n'
2580 ' g_value_copy (value, &skeleton->priv->properties[prop_id - 1]);\n'
2581 ' g_object_notify_by_pspec (object, pspec);\n'
2583 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2584 ' g_object_thaw_notify (object);\n'
2585 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
2589 self.c.write('static void\n'
2590 '%s_skeleton_init (%sSkeleton *skeleton)\n'
2592 '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
2593 ' skeleton->priv = %s_skeleton_get_instance_private (skeleton);\n'
2595 ' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
2597 %(i.name_lower, i.camel_name,
2599 i.ns_upper, i.name_upper, i.camel_name))
2600 self.c.write(' g_mutex_init (&skeleton->priv->lock);\n')
2601 self.c.write(' skeleton->priv->context = g_main_context_ref_thread_default ();\n')
2602 if len(i.properties) > 0:
2603 self.c.write(' skeleton->priv->properties = g_new0 (GValue, %d);\n'%(len(i.properties)))
2605 for p in i.properties:
2606 self.c.write(' g_value_init (&skeleton->priv->properties[%d], %s);\n'%(n, p.arg.gtype))
2613 for p in i.properties:
2614 self.c.write('static %s\n'
2615 '%s_skeleton_get_%s (%s *object)\n'
2617 %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
2618 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2619 self.c.write(' %svalue;\n'
2620 ' g_mutex_lock (&skeleton->priv->lock);\n'
2621 ' value = %s (&(skeleton->priv->properties[%d]));\n'
2622 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2623 %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
2624 self.c.write(' return value;\n')
2629 self.c.write('static void\n'
2630 '%s_skeleton_class_init (%sSkeletonClass *klass)\n'
2632 ' GObjectClass *gobject_class;\n'
2633 ' GDBusInterfaceSkeletonClass *skeleton_class;\n'
2635 ' gobject_class = G_OBJECT_CLASS (klass);\n'
2636 ' gobject_class->finalize = %s_skeleton_finalize;\n'
2637 %(i.name_lower, i.camel_name, i.name_lower))
2638 if len(i.properties) > 0:
2639 self.c.write(' gobject_class->get_property = %s_skeleton_get_property;\n'
2640 ' gobject_class->set_property = %s_skeleton_set_property;\n'
2641 ' gobject_class->notify = %s_skeleton_notify;\n'
2642 '\n'%(i.name_lower, i.name_lower, i.name_lower))
2644 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
2646 ' skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);\n');
2647 self.c.write(' skeleton_class->get_info = %s_skeleton_dbus_interface_get_info;\n'%(i.name_lower))
2648 self.c.write(' skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
2649 self.c.write(' skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
2650 self.c.write(' skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
2653 '#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
2654 ' g_type_class_add_private (klass, sizeof (%sSkeletonPrivate));\n'
2655 '#endif\n'%(i.camel_name))
2660 self.c.write('static void\n'
2661 '%s_skeleton_iface_init (%sIface *iface)\n'
2663 %(i.name_lower, i.camel_name))
2665 self.c.write(' iface->%s = _%s_on_signal_%s;\n'
2666 %(s.name_lower, i.name_lower, s.name_lower))
2667 for p in i.properties:
2668 self.c.write(' iface->get_%s = %s_skeleton_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
2673 self.c.write(self.docbook_gen.expand(
2675 ' * %s_skeleton_new:\n'
2677 ' * Creates a skeleton object for the D-Bus interface #%s.\n'
2679 ' * Returns: (transfer full) (type %sSkeleton): The skeleton object.\n'
2680 %(i.name_lower, i.name, i.camel_name), False))
2681 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2682 self.c.write('%s *\n'
2683 '%s_skeleton_new (void)\n'
2685 ' return %s%s (g_object_new (%sTYPE_%s_SKELETON, NULL));\n'
2687 '\n'%(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
2689 # ---------------------------------------------------------------------------------------------------
2691 def generate_object(self):
2692 self.c.write('/* ------------------------------------------------------------------------\n'
2693 ' * Code for Object, ObjectProxy and ObjectSkeleton\n'
2694 ' * ------------------------------------------------------------------------\n'
2698 self.c.write(self.docbook_gen.expand(
2700 ' * SECTION:%sObject\n'
2701 ' * @title: %sObject\n'
2702 ' * @short_description: Specialized GDBusObject types\n'
2704 ' * 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'
2706 %(self.namespace, self.namespace, self.namespace, self.namespace, self.namespace), False))
2709 self.c.write(self.docbook_gen.expand(
2713 ' * The #%sObject type is a specialized container of interfaces.\n'
2715 %(self.namespace, self.namespace), False))
2718 self.c.write(self.docbook_gen.expand(
2720 ' * %sObjectIface:\n'
2721 ' * @parent_iface: The parent interface.\n'
2723 ' * Virtual table for the #%sObject interface.\n'
2725 %(self.namespace, self.namespace), False))
2728 self.c.write('typedef %sObjectIface %sObjectInterface;\n'%(self.namespace, self.namespace))
2729 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))
2731 self.c.write('static void\n'
2732 '%sobject_default_init (%sObjectIface *iface)\n'
2734 %(self.ns_lower, self.namespace));
2735 for i in self.ifaces:
2736 self.c.write(self.docbook_gen.expand(
2740 ' * The #%s instance corresponding to the D-Bus interface #%s, if any.\n'
2742 ' * Connect to the #GObject::notify signal to get informed of property changes.\n'
2743 %(self.namespace, i.name_hyphen, i.camel_name, i.name), False))
2744 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 2)
2745 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'
2747 %(i.name_hyphen, i.name_hyphen, i.name_hyphen, self.ns_upper, i.name_upper))
2751 for i in self.ifaces:
2752 self.c.write(self.docbook_gen.expand(
2754 ' * %sobject_get_%s:\n'
2755 ' * @object: A #%sObject.\n'
2757 ' * Gets the #%s instance for the D-Bus interface #%s on @object, if any.\n'
2759 ' * Returns: (transfer full): A #%s that must be freed with g_object_unref() or %%NULL if @object does not implement the interface.\n'
2760 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.name, i.camel_name), False))
2761 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2762 self.c.write ('%s *%sobject_get_%s (%sObject *object)\n'
2763 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2765 ' GDBusInterface *ret;\n'
2766 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2767 ' if (ret == NULL)\n'
2769 ' return %s%s (ret);\n'
2772 %(i.name, self.ns_upper, i.name_upper))
2774 for i in self.ifaces:
2775 self.c.write(self.docbook_gen.expand(
2777 ' * %sobject_peek_%s: (skip)\n'
2778 ' * @object: A #%sObject.\n'
2780 ' * Like %sobject_get_%s() but doesn\'t increase the reference count on the returned object.\n'
2782 ' * <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'
2784 ' * 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'
2785 %(self.ns_lower, i.name_upper.lower(), self.namespace, self.ns_lower, i.name_upper.lower(), i.camel_name), False))
2786 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2787 self.c.write ('%s *%sobject_peek_%s (%sObject *object)\n'
2788 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2790 ' GDBusInterface *ret;\n'
2791 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2792 ' if (ret == NULL)\n'
2794 ' g_object_unref (ret);\n'
2795 ' return %s%s (ret);\n'
2798 %(i.name, self.ns_upper, i.name_upper))
2800 # shared by ObjectProxy and ObjectSkeleton classes
2801 self.c.write('static void\n'
2802 '%sobject_notify (GDBusObject *object, GDBusInterface *interface)\n'
2804 ' _ExtendedGDBusInterfaceInfo *info = (_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface);\n'
2805 ' /* info can be NULL if the other end is using a D-Bus interface we don\'t know\n'
2806 ' * anything about, for example old generated code in this process talking to\n'
2807 ' * newer generated code in the other process. */\n'
2808 ' if (info != NULL)\n'
2809 ' g_object_notify (G_OBJECT (object), info->hyphen_name);\n'
2814 self.c.write(self.docbook_gen.expand(
2816 ' * %sObjectProxy:\n'
2818 ' * The #%sObjectProxy structure contains only private data and should only be accessed using the provided API.\n'
2819 %(self.namespace, self.namespace), False))
2820 self.c.write(' */\n')
2822 self.c.write(self.docbook_gen.expand(
2824 ' * %sObjectProxyClass:\n'
2825 ' * @parent_class: The parent class.\n'
2827 ' * Class structure for #%sObjectProxy.\n'
2828 %(self.namespace, self.namespace), False))
2829 self.c.write(' */\n')
2832 self.c.write('static void\n'
2833 '%sobject_proxy__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2837 %(self.ns_lower, self.ns_lower, self.namespace))
2838 self.c.write('static void\n'
2839 '%sobject_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2841 ' iface->interface_added = %sobject_notify;\n'
2842 ' iface->interface_removed = %sobject_notify;\n'
2845 %(self.ns_lower, self.ns_lower, self.ns_lower))
2847 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectProxy, %sobject_proxy, G_TYPE_DBUS_OBJECT_PROXY,\n'
2848 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_proxy__%sobject_iface_init)\n'
2849 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_proxy__g_dbus_object_iface_init));\n'
2851 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2853 self.c.write('static void\n'
2854 '%sobject_proxy_init (%sObjectProxy *object G_GNUC_UNUSED)\n'
2857 '\n'%(self.ns_lower, self.namespace))
2858 self.c.write('static void\n'
2859 '%sobject_proxy_set_property (GObject *gobject,\n'
2861 ' const GValue *value G_GNUC_UNUSED,\n'
2862 ' GParamSpec *pspec)\n'
2864 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2868 self.c.write('static void\n'
2869 '%sobject_proxy_get_property (GObject *gobject,\n'
2872 ' GParamSpec *pspec)\n'
2874 ' %sObjectProxy *object = %sOBJECT_PROXY (gobject);\n'
2875 ' GDBusInterface *interface;\n'
2877 ' switch (prop_id)\n'
2879 %(self.ns_lower, self.namespace, self.ns_upper))
2881 for i in self.ifaces:
2882 self.c.write(' case %d:\n'
2883 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2884 ' g_value_take_object (value, interface);\n'
2889 self.c.write(' default:\n'
2890 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2895 self.c.write('static void\n'
2896 '%sobject_proxy_class_init (%sObjectProxyClass *klass)\n'
2898 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2900 ' gobject_class->set_property = %sobject_proxy_set_property;\n'
2901 ' gobject_class->get_property = %sobject_proxy_get_property;\n'
2903 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2905 for i in self.ifaces:
2906 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2908 %(n, i.name_hyphen))
2913 self.c.write(self.docbook_gen.expand(
2915 ' * %sobject_proxy_new:\n'
2916 ' * @connection: A #GDBusConnection.\n'
2917 ' * @object_path: An object path.\n'
2919 ' * Creates a new proxy object.\n'
2921 ' * Returns: (transfer full): The proxy object.\n'
2923 %(self.ns_lower), False))
2924 self.c.write('%sObjectProxy *\n'
2925 '%sobject_proxy_new (GDBusConnection *connection,\n'
2926 ' const gchar *object_path)\n'
2928 ' g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);\n'
2929 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2930 ' return %sOBJECT_PROXY (g_object_new (%sTYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL));\n'
2932 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2934 self.c.write(self.docbook_gen.expand(
2936 ' * %sObjectSkeleton:\n'
2938 ' * The #%sObjectSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2939 %(self.namespace, self.namespace), False))
2940 self.c.write(' */\n')
2942 self.c.write(self.docbook_gen.expand(
2944 ' * %sObjectSkeletonClass:\n'
2945 ' * @parent_class: The parent class.\n'
2947 ' * Class structure for #%sObjectSkeleton.\n'
2948 %(self.namespace, self.namespace), False))
2949 self.c.write(' */\n')
2952 self.c.write('static void\n'
2953 '%sobject_skeleton__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2957 %(self.ns_lower, self.ns_lower, self.namespace))
2959 self.c.write('static void\n'
2960 '%sobject_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2962 ' iface->interface_added = %sobject_notify;\n'
2963 ' iface->interface_removed = %sobject_notify;\n'
2966 %(self.ns_lower, self.ns_lower, self.ns_lower))
2967 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectSkeleton, %sobject_skeleton, G_TYPE_DBUS_OBJECT_SKELETON,\n'
2968 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_skeleton__%sobject_iface_init)\n'
2969 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_skeleton__g_dbus_object_iface_init));\n'
2971 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2973 self.c.write('static void\n'
2974 '%sobject_skeleton_init (%sObjectSkeleton *object G_GNUC_UNUSED)\n'
2977 '\n'%(self.ns_lower, self.namespace))
2978 self.c.write('static void\n'
2979 '%sobject_skeleton_set_property (GObject *gobject,\n'
2981 ' const GValue *value,\n'
2982 ' GParamSpec *pspec)\n'
2984 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2985 ' GDBusInterfaceSkeleton *interface;\n'
2987 ' switch (prop_id)\n'
2989 %(self.ns_lower, self.namespace, self.ns_upper))
2991 for i in self.ifaces:
2992 self.c.write(' case %d:\n'
2993 ' interface = g_value_get_object (value);\n'
2994 ' if (interface != NULL)\n'
2996 ' g_warn_if_fail (%sIS_%s (interface));\n'
2997 ' g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface);\n'
3001 ' g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "%s");\n'
3005 %(n, self.ns_upper, i.name_upper, i.name))
3007 self.c.write(' default:\n'
3008 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
3013 self.c.write('static void\n'
3014 '%sobject_skeleton_get_property (GObject *gobject,\n'
3017 ' GParamSpec *pspec)\n'
3019 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
3020 ' GDBusInterface *interface;\n'
3022 ' switch (prop_id)\n'
3024 %(self.ns_lower, self.namespace, self.ns_upper))
3026 for i in self.ifaces:
3027 self.c.write(' case %d:\n'
3028 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
3029 ' g_value_take_object (value, interface);\n'
3034 self.c.write(' default:\n'
3035 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
3040 self.c.write('static void\n'
3041 '%sobject_skeleton_class_init (%sObjectSkeletonClass *klass)\n'
3043 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
3045 ' gobject_class->set_property = %sobject_skeleton_set_property;\n'
3046 ' gobject_class->get_property = %sobject_skeleton_get_property;\n'
3048 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
3050 for i in self.ifaces:
3051 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
3053 %(n, i.name_hyphen))
3057 self.c.write(self.docbook_gen.expand(
3059 ' * %sobject_skeleton_new:\n'
3060 ' * @object_path: An object path.\n'
3062 ' * Creates a new skeleton object.\n'
3064 ' * Returns: (transfer full): The skeleton object.\n'
3066 %(self.ns_lower), False))
3067 self.c.write('%sObjectSkeleton *\n'
3068 '%sobject_skeleton_new (const gchar *object_path)\n'
3070 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
3071 ' return %sOBJECT_SKELETON (g_object_new (%sTYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL));\n'
3073 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
3074 for i in self.ifaces:
3075 self.c.write(self.docbook_gen.expand(
3077 ' * %sobject_skeleton_set_%s:\n'
3078 ' * @object: A #%sObjectSkeleton.\n'
3079 ' * @interface_: (allow-none): A #%s or %%NULL to clear the interface.\n'
3081 ' * Sets the #%s instance for the D-Bus interface #%s on @object.\n'
3082 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.camel_name, i.name), False))
3083 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
3084 self.c.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_)\n'
3085 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
3087 ' g_object_set (G_OBJECT (object), "%s", interface_, NULL);\n'
3094 def generate_object_manager_client(self):
3095 self.c.write('/* ------------------------------------------------------------------------\n'
3096 ' * Code for ObjectManager client\n'
3097 ' * ------------------------------------------------------------------------\n'
3101 self.c.write(self.docbook_gen.expand(
3103 ' * SECTION:%sObjectManagerClient\n'
3104 ' * @title: %sObjectManagerClient\n'
3105 ' * @short_description: Generated GDBusObjectManagerClient type\n'
3107 ' * This section contains a #GDBusObjectManagerClient that uses %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc.\n'
3109 %(self.namespace, self.namespace, self.ns_lower), False))
3112 self.c.write(self.docbook_gen.expand(
3114 ' * %sObjectManagerClient:\n'
3116 ' * The #%sObjectManagerClient structure contains only private data and should only be accessed using the provided API.\n'
3117 %(self.namespace, self.namespace), False))
3118 self.c.write(' */\n')
3121 self.c.write(self.docbook_gen.expand(
3123 ' * %sObjectManagerClientClass:\n'
3124 ' * @parent_class: The parent class.\n'
3126 ' * Class structure for #%sObjectManagerClient.\n'
3127 %(self.namespace, self.namespace), False))
3128 self.c.write(' */\n')
3132 self.c.write('G_DEFINE_TYPE (%sObjectManagerClient, %sobject_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT);\n'
3134 %(self.namespace, self.ns_lower))
3137 self.c.write('static void\n'
3138 '%sobject_manager_client_init (%sObjectManagerClient *manager G_GNUC_UNUSED)\n'
3141 '\n'%(self.ns_lower, self.namespace))
3142 self.c.write('static void\n'
3143 '%sobject_manager_client_class_init (%sObjectManagerClientClass *klass G_GNUC_UNUSED)\n'
3146 '\n'%(self.ns_lower, self.namespace))
3148 self.c.write(self.docbook_gen.expand(
3150 ' * %sobject_manager_client_get_proxy_type:\n'
3151 ' * @manager: A #GDBusObjectManagerClient.\n'
3152 ' * @object_path: The object path of the remote object (unused).\n'
3153 ' * @interface_name: (allow-none): Interface name of the remote object or %%NULL to get the object proxy #GType.\n'
3154 ' * @user_data: User data (unused).\n'
3156 ' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types.\n'
3158 ' * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %%NULL, otherwise the #GType for #%sObjectProxy.\n'
3159 %(self.ns_lower, self.namespace), False))
3160 self.c.write(' */\n')
3161 self.c.write('GType\n'
3162 '%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'
3165 self.c.write(' static gsize once_init_value = 0;\n'
3166 ' static GHashTable *lookup_hash;\n'
3169 ' if (interface_name == NULL)\n'
3170 ' return %sTYPE_OBJECT_PROXY;\n'
3171 ' if (g_once_init_enter (&once_init_value))\n'
3173 ' lookup_hash = g_hash_table_new (g_str_hash, g_str_equal);\n'
3175 for i in self.ifaces:
3176 self.c.write(' g_hash_table_insert (lookup_hash, (gpointer) "%s", GSIZE_TO_POINTER (%sTYPE_%s_PROXY));\n'
3177 %(i.name, i.ns_upper, i.name_upper))
3178 self.c.write(' g_once_init_leave (&once_init_value, 1);\n'
3180 self.c.write(' ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name));\n'
3181 ' if (ret == (GType) 0)\n'
3182 ' ret = G_TYPE_DBUS_PROXY;\n')
3183 self.c.write(' return ret;\n'
3188 self.c.write(self.docbook_gen.expand(
3190 ' * %sobject_manager_client_new:\n'
3191 ' * @connection: A #GDBusConnection.\n'
3192 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3193 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3194 ' * @object_path: An object path.\n'
3195 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3196 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3197 ' * @user_data: User data to pass to @callback.\n'
3199 ' * Asynchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details.\n'
3201 ' * 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'
3202 ' * You can then call %sobject_manager_client_new_finish() to get the result of the operation.\n'
3204 ' * See %sobject_manager_client_new_sync() for the synchronous, blocking version of this constructor.\n'
3205 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3206 self.c.write(' */\n')
3207 self.c.write('void\n'
3208 '%sobject_manager_client_new (\n'
3209 ' GDBusConnection *connection,\n'
3210 ' GDBusObjectManagerClientFlags flags,\n'
3211 ' const gchar *name,\n'
3212 ' const gchar *object_path,\n'
3213 ' GCancellable *cancellable,\n'
3214 ' GAsyncReadyCallback callback,\n'
3215 ' gpointer user_data)\n'
3217 ' 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'
3220 %(self.ns_lower, self.ns_upper, self.ns_lower))
3221 self.c.write('/**\n'
3222 ' * %sobject_manager_client_new_finish:\n'
3223 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new().\n'
3224 ' * @error: Return location for error or %%NULL\n'
3226 ' * Finishes an operation started with %sobject_manager_client_new().\n'
3228 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3229 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3230 self.c.write(' */\n')
3231 self.c.write('GDBusObjectManager *\n'
3232 '%sobject_manager_client_new_finish (\n'
3233 ' GAsyncResult *res,\n'
3234 ' GError **error)\n'
3237 ' GObject *source_object;\n'
3238 ' source_object = g_async_result_get_source_object (res);\n'
3239 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3240 ' g_object_unref (source_object);\n'
3241 ' if (ret != NULL)\n'
3242 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3248 self.c.write(self.docbook_gen.expand(
3250 ' * %sobject_manager_client_new_sync:\n'
3251 ' * @connection: A #GDBusConnection.\n'
3252 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3253 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3254 ' * @object_path: An object path.\n'
3255 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3256 ' * @error: Return location for error or %%NULL\n'
3258 ' * 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'
3260 ' * The calling thread is blocked until a reply is received.\n'
3262 ' * See %sobject_manager_client_new() for the asynchronous version of this constructor.\n'
3264 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3265 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3266 self.c.write(' */\n')
3267 self.c.write('GDBusObjectManager *\n'
3268 '%sobject_manager_client_new_sync (\n'
3269 ' GDBusConnection *connection,\n'
3270 ' GDBusObjectManagerClientFlags flags,\n'
3271 ' const gchar *name,\n'
3272 ' const gchar *object_path,\n'
3273 ' GCancellable *cancellable,\n'
3274 ' GError **error)\n'
3276 ' GInitable *ret;\n'
3277 ' 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'
3278 ' if (ret != NULL)\n'
3279 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3284 %(self.ns_lower, self.ns_upper, self.ns_lower))
3286 self.c.write(self.docbook_gen.expand(
3288 ' * %sobject_manager_client_new_for_bus:\n'
3289 ' * @bus_type: A #GBusType.\n'
3290 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3291 ' * @name: A bus name (well-known or unique).\n'
3292 ' * @object_path: An object path.\n'
3293 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3294 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3295 ' * @user_data: User data to pass to @callback.\n'
3297 ' * Like %sobject_manager_client_new() but takes a #GBusType instead of a #GDBusConnection.\n'
3299 ' * 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'
3300 ' * You can then call %sobject_manager_client_new_for_bus_finish() to get the result of the operation.\n'
3302 ' * See %sobject_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
3303 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3304 self.c.write(' */\n')
3305 self.c.write('void\n'
3306 '%sobject_manager_client_new_for_bus (\n'
3307 ' GBusType bus_type,\n'
3308 ' GDBusObjectManagerClientFlags flags,\n'
3309 ' const gchar *name,\n'
3310 ' const gchar *object_path,\n'
3311 ' GCancellable *cancellable,\n'
3312 ' GAsyncReadyCallback callback,\n'
3313 ' gpointer user_data)\n'
3315 ' 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'
3318 %(self.ns_lower, self.ns_upper, self.ns_lower))
3319 self.c.write('/**\n'
3320 ' * %sobject_manager_client_new_for_bus_finish:\n'
3321 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new_for_bus().\n'
3322 ' * @error: Return location for error or %%NULL\n'
3324 ' * Finishes an operation started with %sobject_manager_client_new_for_bus().\n'
3326 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3327 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3328 self.c.write(' */\n')
3329 self.c.write('GDBusObjectManager *\n'
3330 '%sobject_manager_client_new_for_bus_finish (\n'
3331 ' GAsyncResult *res,\n'
3332 ' GError **error)\n'
3335 ' GObject *source_object;\n'
3336 ' source_object = g_async_result_get_source_object (res);\n'
3337 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3338 ' g_object_unref (source_object);\n'
3339 ' if (ret != NULL)\n'
3340 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3346 self.c.write(self.docbook_gen.expand(
3348 ' * %sobject_manager_client_new_for_bus_sync:\n'
3349 ' * @bus_type: A #GBusType.\n'
3350 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3351 ' * @name: A bus name (well-known or unique).\n'
3352 ' * @object_path: An object path.\n'
3353 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3354 ' * @error: Return location for error or %%NULL\n'
3356 ' * Like %sobject_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
3358 ' * The calling thread is blocked until a reply is received.\n'
3360 ' * See %sobject_manager_client_new_for_bus() for the asynchronous version of this constructor.\n'
3362 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3363 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3364 self.c.write(' */\n')
3365 self.c.write('GDBusObjectManager *\n'
3366 '%sobject_manager_client_new_for_bus_sync (\n'
3367 ' GBusType bus_type,\n'
3368 ' GDBusObjectManagerClientFlags flags,\n'
3369 ' const gchar *name,\n'
3370 ' const gchar *object_path,\n'
3371 ' GCancellable *cancellable,\n'
3372 ' GError **error)\n'
3374 ' GInitable *ret;\n'
3375 ' 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'
3376 ' if (ret != NULL)\n'
3377 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3382 %(self.ns_lower, self.ns_upper, self.ns_lower))
3385 # ---------------------------------------------------------------------------------------------------
3387 def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
3388 if len(obj.since) > 0:
3391 %(indent, '', indent, '', obj.since))
3393 if isinstance(obj, dbustypes.Interface):
3394 thing = 'The D-Bus interface'
3395 elif isinstance(obj, dbustypes.Method):
3396 thing = 'The D-Bus method'
3397 elif isinstance(obj, dbustypes.Signal):
3398 thing = 'The D-Bus signal'
3399 elif isinstance(obj, dbustypes.Property):
3400 thing = 'The D-Bus property'
3402 raise RuntimeError('Cannot handle object ', obj)
3403 f.write(self.docbook_gen.expand(
3405 '%*s * Deprecated: %s has been deprecated.\n'
3406 %(indent, '', indent, '', thing), False))
3407 f.write('%*s */\n'%(indent, ''))
3409 # ---------------------------------------------------------------------------------------------------
3411 def generate_interface_intro(self, i):
3412 self.c.write('/* ------------------------------------------------------------------------\n'
3413 ' * Code for interface %s\n'
3414 ' * ------------------------------------------------------------------------\n'
3418 self.c.write(self.docbook_gen.expand(
3422 ' * @short_description: Generated C code for the %s D-Bus interface\n'
3424 ' * This section contains code for working with the #%s D-Bus interface in C.\n'
3426 %(i.camel_name, i.camel_name, i.name, i.name), False))
3430 self.generate_intro()
3431 self.declare_types()
3432 for i in self.ifaces:
3433 self.generate_interface_intro(i)
3434 self.generate_introspection_for_interface(i)
3435 self.generate_interface(i)
3436 self.generate_property_accessors(i)
3437 self.generate_signal_emitters(i)
3438 self.generate_method_calls(i)
3439 self.generate_method_completers(i)
3440 self.generate_proxy(i)
3441 self.generate_skeleton(i)
3442 if self.generate_objmanager:
3443 self.generate_object()
3444 self.generate_object_manager_client()
3446 self.generate_outro()