3 # GDBus - GLib D-Bus Library
5 # Copyright (C) 2008-2011 Red Hat, Inc.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General
18 # Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 # Author: David Zeuthen <davidz@redhat.com>
26 from . import dbustypes
28 # ----------------------------------------------------------------------------------------------------
31 def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, docbook_gen, h, c):
32 self.docbook_gen = docbook_gen
33 self.generate_objmanager = generate_objmanager
37 self.namespace = namespace
38 if len(namespace) > 0:
39 if utils.is_ugly_case(namespace):
40 self.namespace = namespace.replace('_', '')
41 self.ns_upper = namespace.upper() + '_'
42 self.ns_lower = namespace.lower() + '_'
44 self.ns_upper = utils.camel_case_to_uscore(namespace).upper() + '_'
45 self.ns_lower = utils.camel_case_to_uscore(namespace).lower() + '_'
49 self.interface_prefix = interface_prefix
50 self.header_guard = self.h.name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
52 # ----------------------------------------------------------------------------------------------------
54 def generate_intro(self):
56 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
58 ' * The license of this code is the same as for the source it was derived from.\n'
62 self.c.write('#ifdef HAVE_CONFIG_H\n'
63 '# include "config.h"\n'
68 '#include <string.h>\n'
71 self.c.write('#ifdef G_OS_UNIX\n'
72 '# include <gio/gunixfdlist.h>\n'
76 self.c.write('typedef struct\n'
78 ' GDBusArgInfo parent_struct;\n'
79 ' gboolean use_gvariant;\n'
80 '} _ExtendedGDBusArgInfo;\n'
83 self.c.write('typedef struct\n'
85 ' GDBusMethodInfo parent_struct;\n'
86 ' const gchar *signal_name;\n'
87 ' gboolean pass_fdlist;\n'
88 '} _ExtendedGDBusMethodInfo;\n'
91 self.c.write('typedef struct\n'
93 ' GDBusSignalInfo parent_struct;\n'
94 ' const gchar *signal_name;\n'
95 '} _ExtendedGDBusSignalInfo;\n'
98 self.c.write('typedef struct\n'
100 ' GDBusPropertyInfo parent_struct;\n'
101 ' const gchar *hyphen_name;\n'
102 ' gboolean use_gvariant;\n'
103 '} _ExtendedGDBusPropertyInfo;\n'
106 self.c.write('typedef struct\n'
108 ' GDBusInterfaceInfo parent_struct;\n'
109 ' const gchar *hyphen_name;\n'
110 '} _ExtendedGDBusInterfaceInfo;\n'
113 self.c.write('typedef struct\n'
115 ' const _ExtendedGDBusPropertyInfo *info;\n'
117 ' GValue orig_value; /* the value before the change */\n'
118 '} ChangedProperty;\n'
121 '_changed_property_free (ChangedProperty *data)\n'
123 ' g_value_unset (&data->orig_value);\n'
128 self.c.write('static gboolean\n'
129 '_g_strv_equal0 (gchar **a, gchar **b)\n'
131 ' gboolean ret = FALSE;\n'
133 ' if (a == NULL && b == NULL)\n'
138 ' if (a == NULL || b == NULL)\n'
140 ' if (g_strv_length (a) != g_strv_length (b))\n'
142 ' for (n = 0; a[n] != NULL; n++)\n'
143 ' if (g_strcmp0 (a[n], b[n]) != 0)\n'
151 self.c.write('static gboolean\n'
152 '_g_variant_equal0 (GVariant *a, GVariant *b)\n'
154 ' gboolean ret = FALSE;\n'
155 ' if (a == NULL && b == NULL)\n'
160 ' if (a == NULL || b == NULL)\n'
162 ' ret = g_variant_equal (a, b);\n'
168 # simplified - only supports the types we use
169 self.c.write('G_GNUC_UNUSED static gboolean\n'
170 '_g_value_equal (const GValue *a, const GValue *b)\n'
172 ' gboolean ret = FALSE;\n'
173 ' g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b));\n'
174 ' switch (G_VALUE_TYPE (a))\n'
176 ' case G_TYPE_BOOLEAN:\n'
177 ' ret = (g_value_get_boolean (a) == g_value_get_boolean (b));\n'
179 ' case G_TYPE_UCHAR:\n'
180 ' ret = (g_value_get_uchar (a) == g_value_get_uchar (b));\n'
182 ' case G_TYPE_INT:\n'
183 ' ret = (g_value_get_int (a) == g_value_get_int (b));\n'
185 ' case G_TYPE_UINT:\n'
186 ' ret = (g_value_get_uint (a) == g_value_get_uint (b));\n'
188 ' case G_TYPE_INT64:\n'
189 ' ret = (g_value_get_int64 (a) == g_value_get_int64 (b));\n'
191 ' case G_TYPE_UINT64:\n'
192 ' ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n'
194 ' case G_TYPE_DOUBLE:\n'
196 ' /* Avoid -Wfloat-equal warnings by doing a direct bit compare */\n'
197 ' gdouble da = g_value_get_double (a);\n'
198 ' gdouble db = g_value_get_double (b);\n'
199 ' ret = memcmp (&da, &db, sizeof (gdouble)) == 0;\n'
202 ' case G_TYPE_STRING:\n'
203 ' ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n'
205 ' case G_TYPE_VARIANT:\n'
206 ' ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b));\n'
209 ' if (G_VALUE_TYPE (a) == G_TYPE_STRV)\n'
210 ' ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b));\n'
212 ' g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a)));\n'
220 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
222 ' * The license of this code is the same as for the source it was derived from.\n'
227 '\n'%(config.VERSION, self.header_guard, self.header_guard))
228 self.h.write('#include <gio/gio.h>\n'
233 # ----------------------------------------------------------------------------------------------------
235 def declare_types(self):
236 for i in self.ifaces:
238 self.h.write('/* ------------------------------------------------------------------------ */\n')
239 self.h.write('/* Declarations for %s */\n'%i.name)
242 # First the GInterface
243 self.h.write('#define %sTYPE_%s (%s_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
244 self.h.write('#define %s%s(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_%s, %s))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
245 self.h.write('#define %sIS_%s(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_%s))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
246 self.h.write('#define %s%s_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), %sTYPE_%s, %sIface))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
248 self.h.write('struct _%s;\n'%(i.camel_name))
249 self.h.write('typedef struct _%s %s;\n'%(i.camel_name, i.camel_name))
250 self.h.write('typedef struct _%sIface %sIface;\n'%(i.camel_name, i.camel_name))
252 self.h.write('struct _%sIface\n'%(i.camel_name))
254 self.h.write(' GTypeInterface parent_iface;\n')
256 function_pointers = {}
259 if len(i.methods) > 0:
263 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
265 key = (m.since, '_method_%s'%m.name_lower)
266 value = ' gboolean (*handle_%s) (\n'%(m.name_lower)
267 value += ' %s *object,\n'%(i.camel_name)
268 value += ' GDBusMethodInvocation *invocation'%()
270 value += ',\n GUnixFDList *fd_list'
272 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
274 function_pointers[key] = value
277 if len(i.signals) > 0:
280 key = (s.since, '_signal_%s'%s.name_lower)
281 value = ' void (*%s) (\n'%(s.name_lower)
282 value += ' %s *object'%(i.camel_name)
284 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
286 function_pointers[key] = value
288 # vfuncs for properties
289 if len(i.properties) > 0:
291 for p in i.properties:
292 key = (p.since, '_prop_get_%s'%p.name_lower)
293 value = ' %s (*get_%s) (%s *object);\n\n'%(p.arg.ctype_in, p.name_lower, i.camel_name)
294 function_pointers[key] = value
296 # Sort according to @since tag, then name.. this ensures
297 # that the function pointers don't change order assuming
298 # judicious use of @since
300 # Also use a proper version comparison function so e.g.
301 # 10.0 comes after 2.0.
303 # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
305 for key in sorted(function_pointers.keys(), key=utils.version_cmp_key):
306 self.h.write('%s'%function_pointers[key])
310 self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
312 self.h.write('GDBusInterfaceInfo *%s_interface_info (void);\n'%(i.name_lower))
313 self.h.write('guint %s_override_properties (GObjectClass *klass, guint property_id_begin);\n'%(i.name_lower))
316 # Then method call completion functions
317 if len(i.methods) > 0:
319 self.h.write('/* D-Bus method call completion functions: */\n')
322 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
325 self.h.write('G_GNUC_DEPRECATED ')
326 self.h.write('void %s_complete_%s (\n'
328 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
330 self.h.write(',\n GUnixFDList *fd_list')
332 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
337 # Then signal emission functions
338 if len(i.signals) > 0:
340 self.h.write('/* D-Bus signal emissions functions: */\n')
343 self.h.write('G_GNUC_DEPRECATED ')
344 self.h.write('void %s_emit_%s (\n'
345 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
347 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
352 # Then method call declarations
353 if len(i.methods) > 0:
355 self.h.write('/* D-Bus method calls: */\n')
358 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
362 self.h.write('G_GNUC_DEPRECATED ')
363 self.h.write('void %s_call_%s (\n'
364 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
366 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
368 self.h.write(',\n GUnixFDList *fd_list')
370 ' GCancellable *cancellable,\n'
371 ' GAsyncReadyCallback callback,\n'
372 ' gpointer user_data);\n')
376 self.h.write('G_GNUC_DEPRECATED ')
377 self.h.write('gboolean %s_call_%s_finish (\n'
378 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
380 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
382 self.h.write(',\n GUnixFDList **out_fd_list')
384 ' GAsyncResult *res,\n'
385 ' GError **error);\n')
389 self.h.write('G_GNUC_DEPRECATED ')
390 self.h.write('gboolean %s_call_%s_sync (\n'
391 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
393 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
395 self.h.write(',\n GUnixFDList *fd_list')
397 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
399 self.h.write(',\n GUnixFDList **out_fd_list')
401 ' GCancellable *cancellable,\n'
402 ' GError **error);\n')
406 # Then the property accessor declarations
407 if len(i.properties) > 0:
409 self.h.write('/* D-Bus property accessors: */\n')
410 for p in i.properties:
413 self.h.write('G_GNUC_DEPRECATED ')
414 self.h.write('%s%s_get_%s (%s *object);\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
415 if p.arg.free_func != None:
417 self.h.write('G_GNUC_DEPRECATED ')
418 self.h.write('%s%s_dup_%s (%s *object);\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name))
421 self.h.write('G_GNUC_DEPRECATED ')
422 self.h.write('void %s_set_%s (%s *object, %svalue);\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
427 self.h.write('/* ---- */\n')
429 self.h.write('#define %sTYPE_%s_PROXY (%s_proxy_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
430 self.h.write('#define %s%s_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_%s_PROXY, %sProxy))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
431 self.h.write('#define %s%s_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_%s_PROXY, %sProxyClass))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
432 self.h.write('#define %s%s_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_%s_PROXY, %sProxyClass))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
433 self.h.write('#define %sIS_%s_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_%s_PROXY))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
434 self.h.write('#define %sIS_%s_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_%s_PROXY))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
436 self.h.write('typedef struct _%sProxy %sProxy;\n'%(i.camel_name, i.camel_name))
437 self.h.write('typedef struct _%sProxyClass %sProxyClass;\n'%(i.camel_name, i.camel_name))
438 self.h.write('typedef struct _%sProxyPrivate %sProxyPrivate;\n'%(i.camel_name, i.camel_name))
440 self.h.write('struct _%sProxy\n'%(i.camel_name))
442 self.h.write(' /*< private >*/\n')
443 self.h.write(' GDBusProxy parent_instance;\n')
444 self.h.write(' %sProxyPrivate *priv;\n'%(i.camel_name))
447 self.h.write('struct _%sProxyClass\n'%(i.camel_name))
449 self.h.write(' GDBusProxyClass parent_class;\n')
452 self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
456 self.h.write('G_GNUC_DEPRECATED ')
457 self.h.write('void %s_proxy_new (\n'
458 ' GDBusConnection *connection,\n'
459 ' GDBusProxyFlags flags,\n'
460 ' const gchar *name,\n'
461 ' const gchar *object_path,\n'
462 ' GCancellable *cancellable,\n'
463 ' GAsyncReadyCallback callback,\n'
464 ' gpointer user_data);\n'
467 self.h.write('G_GNUC_DEPRECATED ')
468 self.h.write('%s *%s_proxy_new_finish (\n'
469 ' GAsyncResult *res,\n'
470 ' GError **error);\n'
471 %(i.camel_name, i.name_lower))
473 self.h.write('G_GNUC_DEPRECATED ')
474 self.h.write('%s *%s_proxy_new_sync (\n'
475 ' GDBusConnection *connection,\n'
476 ' GDBusProxyFlags flags,\n'
477 ' const gchar *name,\n'
478 ' const gchar *object_path,\n'
479 ' GCancellable *cancellable,\n'
480 ' GError **error);\n'
481 %(i.camel_name, i.name_lower))
484 self.h.write('G_GNUC_DEPRECATED ')
485 self.h.write('void %s_proxy_new_for_bus (\n'
486 ' GBusType bus_type,\n'
487 ' GDBusProxyFlags flags,\n'
488 ' const gchar *name,\n'
489 ' const gchar *object_path,\n'
490 ' GCancellable *cancellable,\n'
491 ' GAsyncReadyCallback callback,\n'
492 ' gpointer user_data);\n'
495 self.h.write('G_GNUC_DEPRECATED ')
496 self.h.write('%s *%s_proxy_new_for_bus_finish (\n'
497 ' GAsyncResult *res,\n'
498 ' GError **error);\n'
499 %(i.camel_name, i.name_lower))
501 self.h.write('G_GNUC_DEPRECATED ')
502 self.h.write('%s *%s_proxy_new_for_bus_sync (\n'
503 ' GBusType bus_type,\n'
504 ' GDBusProxyFlags flags,\n'
505 ' const gchar *name,\n'
506 ' const gchar *object_path,\n'
507 ' GCancellable *cancellable,\n'
508 ' GError **error);\n'
509 %(i.camel_name, i.name_lower))
514 self.h.write('/* ---- */\n')
516 self.h.write('#define %sTYPE_%s_SKELETON (%s_skeleton_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
517 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))
518 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))
519 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))
520 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))
521 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))
523 self.h.write('typedef struct _%sSkeleton %sSkeleton;\n'%(i.camel_name, i.camel_name))
524 self.h.write('typedef struct _%sSkeletonClass %sSkeletonClass;\n'%(i.camel_name, i.camel_name))
525 self.h.write('typedef struct _%sSkeletonPrivate %sSkeletonPrivate;\n'%(i.camel_name, i.camel_name))
527 self.h.write('struct _%sSkeleton\n'%(i.camel_name))
529 self.h.write(' /*< private >*/\n')
530 self.h.write(' GDBusInterfaceSkeleton parent_instance;\n')
531 self.h.write(' %sSkeletonPrivate *priv;\n'%(i.camel_name))
534 self.h.write('struct _%sSkeletonClass\n'%(i.camel_name))
536 self.h.write(' GDBusInterfaceSkeletonClass parent_class;\n')
539 self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
542 self.h.write('G_GNUC_DEPRECATED ')
543 self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
547 # Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
548 if self.generate_objmanager:
550 self.h.write('/* ---- */\n')
552 self.h.write('#define %sTYPE_OBJECT (%sobject_get_type ())\n'%(self.ns_upper, self.ns_lower))
553 self.h.write('#define %sOBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
554 self.h.write('#define %sIS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT))\n'%(self.ns_upper, self.ns_upper))
555 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))
557 self.h.write('struct _%sObject;\n'%(self.namespace))
558 self.h.write('typedef struct _%sObject %sObject;\n'%(self.namespace, self.namespace))
559 self.h.write('typedef struct _%sObjectIface %sObjectIface;\n'%(self.namespace, self.namespace))
561 self.h.write('struct _%sObjectIface\n'%(self.namespace))
563 ' GTypeInterface parent_iface;\n'
566 self.h.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
569 for i in self.ifaces:
571 self.h.write('G_GNUC_DEPRECATED ')
572 self.h.write ('%s *%sobject_get_%s (%sObject *object);\n'
573 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
574 for i in self.ifaces:
576 self.h.write('G_GNUC_DEPRECATED ')
577 self.h.write ('%s *%sobject_peek_%s (%sObject *object);\n'
578 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
580 self.h.write('#define %sTYPE_OBJECT_PROXY (%sobject_proxy_get_type ())\n'%(self.ns_upper, self.ns_lower))
581 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))
582 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))
583 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))
584 self.h.write('#define %sIS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
585 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))
587 self.h.write('typedef struct _%sObjectProxy %sObjectProxy;\n'%(self.namespace, self.namespace))
588 self.h.write('typedef struct _%sObjectProxyClass %sObjectProxyClass;\n'%(self.namespace, self.namespace))
589 self.h.write('typedef struct _%sObjectProxyPrivate %sObjectProxyPrivate;\n'%(self.namespace, self.namespace))
591 self.h.write('struct _%sObjectProxy\n'%(self.namespace))
593 self.h.write(' /*< private >*/\n')
594 self.h.write(' GDBusObjectProxy parent_instance;\n')
595 self.h.write(' %sObjectProxyPrivate *priv;\n'%(self.namespace))
598 self.h.write('struct _%sObjectProxyClass\n'%(self.namespace))
600 self.h.write(' GDBusObjectProxyClass parent_class;\n')
603 self.h.write('GType %sobject_proxy_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
604 self.h.write('%sObjectProxy *%sobject_proxy_new (GDBusConnection *connection, const gchar *object_path);\n'%(self.namespace, self.ns_lower))
606 self.h.write('#define %sTYPE_OBJECT_SKELETON (%sobject_skeleton_get_type ())\n'%(self.ns_upper, self.ns_lower))
607 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))
608 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))
609 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))
610 self.h.write('#define %sIS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
611 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))
613 self.h.write('typedef struct _%sObjectSkeleton %sObjectSkeleton;\n'%(self.namespace, self.namespace))
614 self.h.write('typedef struct _%sObjectSkeletonClass %sObjectSkeletonClass;\n'%(self.namespace, self.namespace))
615 self.h.write('typedef struct _%sObjectSkeletonPrivate %sObjectSkeletonPrivate;\n'%(self.namespace, self.namespace))
617 self.h.write('struct _%sObjectSkeleton\n'%(self.namespace))
619 self.h.write(' /*< private >*/\n')
620 self.h.write(' GDBusObjectSkeleton parent_instance;\n')
621 self.h.write(' %sObjectSkeletonPrivate *priv;\n'%(self.namespace))
624 self.h.write('struct _%sObjectSkeletonClass\n'%(self.namespace))
626 self.h.write(' GDBusObjectSkeletonClass parent_class;\n')
629 self.h.write('GType %sobject_skeleton_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
630 self.h.write('%sObjectSkeleton *%sobject_skeleton_new (const gchar *object_path);\n'
631 %(self.namespace, self.ns_lower))
632 for i in self.ifaces:
634 self.h.write('G_GNUC_DEPRECATED ')
635 self.h.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_);\n'
636 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
639 self.h.write('/* ---- */\n')
641 self.h.write('#define %sTYPE_OBJECT_MANAGER_CLIENT (%sobject_manager_client_get_type ())\n'%(self.ns_upper, self.ns_lower))
642 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))
643 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))
644 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))
645 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))
646 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))
648 self.h.write('typedef struct _%sObjectManagerClient %sObjectManagerClient;\n'%(self.namespace, self.namespace))
649 self.h.write('typedef struct _%sObjectManagerClientClass %sObjectManagerClientClass;\n'%(self.namespace, self.namespace))
650 self.h.write('typedef struct _%sObjectManagerClientPrivate %sObjectManagerClientPrivate;\n'%(self.namespace, self.namespace))
652 self.h.write('struct _%sObjectManagerClient\n'%(self.namespace))
654 self.h.write(' /*< private >*/\n')
655 self.h.write(' GDBusObjectManagerClient parent_instance;\n')
656 self.h.write(' %sObjectManagerClientPrivate *priv;\n'%(self.namespace))
659 self.h.write('struct _%sObjectManagerClientClass\n'%(self.namespace))
661 self.h.write(' GDBusObjectManagerClientClass parent_class;\n')
664 self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
666 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))
668 self.h.write('void %sobject_manager_client_new (\n'
669 ' GDBusConnection *connection,\n'
670 ' GDBusObjectManagerClientFlags flags,\n'
671 ' const gchar *name,\n'
672 ' const gchar *object_path,\n'
673 ' GCancellable *cancellable,\n'
674 ' GAsyncReadyCallback callback,\n'
675 ' gpointer user_data);\n'
677 self.h.write('GDBusObjectManager *%sobject_manager_client_new_finish (\n'
678 ' GAsyncResult *res,\n'
679 ' GError **error);\n'
681 self.h.write('GDBusObjectManager *%sobject_manager_client_new_sync (\n'
682 ' GDBusConnection *connection,\n'
683 ' GDBusObjectManagerClientFlags flags,\n'
684 ' const gchar *name,\n'
685 ' const gchar *object_path,\n'
686 ' GCancellable *cancellable,\n'
687 ' GError **error);\n'
690 self.h.write('void %sobject_manager_client_new_for_bus (\n'
691 ' GBusType bus_type,\n'
692 ' GDBusObjectManagerClientFlags flags,\n'
693 ' const gchar *name,\n'
694 ' const gchar *object_path,\n'
695 ' GCancellable *cancellable,\n'
696 ' GAsyncReadyCallback callback,\n'
697 ' gpointer user_data);\n'
699 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_finish (\n'
700 ' GAsyncResult *res,\n'
701 ' GError **error);\n'
703 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_sync (\n'
704 ' GBusType bus_type,\n'
705 ' GDBusObjectManagerClientFlags flags,\n'
706 ' const gchar *name,\n'
707 ' const gchar *object_path,\n'
708 ' GCancellable *cancellable,\n'
709 ' GError **error);\n'
713 # ----------------------------------------------------------------------------------------------------
715 def generate_outro(self):
719 '#endif /* __%s__ */\n'%(self.header_guard))
721 # ----------------------------------------------------------------------------------------------------
723 def generate_annotations(self, prefix, annotations):
724 if annotations == None:
728 for a in annotations:
729 #self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
731 # skip internal annotations
732 if a.key.startswith('org.gtk.GDBus'):
735 self.c.write('static const GDBusAnnotationInfo %s_%d =\n'
739 ' (gchar *) "%s",\n'%(prefix, n, a.key, a.value))
740 if len(a.annotations) == 0:
741 self.c.write(' NULL\n')
743 self.c.write(' (GDBusAnnotationInfo **) &%s_%d_pointers\n'%(prefix, n))
749 self.c.write('static const GDBusAnnotationInfo * const %s_pointers[] =\n'
752 for a in annotations:
753 if a.key.startswith('org.gtk.GDBus'):
755 self.c.write(' &%s_%d,\n'%(prefix, m))
757 self.c.write(' NULL\n'
762 def generate_args(self, prefix, args):
764 num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
766 self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
771 ' (gchar *) "%s",\n'%(prefix, a.name, a.name, a.signature))
773 self.c.write(' NULL\n')
775 self.c.write(' (GDBusAnnotationInfo **) &%s_arg_%s_annotation_info_pointers\n'%(prefix, a.name))
776 self.c.write(' },\n')
777 if not utils.lookup_annotation(a.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
778 self.c.write(' FALSE\n')
780 self.c.write(' TRUE\n')
785 self.c.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
788 self.c.write(' &%s_%s,\n'%(prefix, a.name))
789 self.c.write(' NULL\n'
793 def generate_introspection_for_interface(self, i):
794 self.c.write('/* ---- Introspection data for %s ---- */\n'
797 if len(i.methods) > 0:
800 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
802 self.generate_args('_%s_method_info_%s_IN_ARG'%(i.name_lower, m.name_lower), m.in_args)
803 self.generate_args('_%s_method_info_%s_OUT_ARG'%(i.name_lower, m.name_lower), m.out_args)
805 num_anno = self.generate_annotations('_%s_method_%s_annotation_info'%(i.name_lower, m.name_lower), m.annotations)
807 self.c.write('static const _ExtendedGDBusMethodInfo _%s_method_info_%s =\n'
811 ' (gchar *) "%s",\n'%(i.name_lower, m.name_lower, m.name))
812 if len(m.in_args) == 0:
813 self.c.write(' NULL,\n')
815 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_IN_ARG_pointers,\n'%(i.name_lower, m.name_lower))
816 if len(m.out_args) == 0:
817 self.c.write(' NULL,\n')
819 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_OUT_ARG_pointers,\n'%(i.name_lower, m.name_lower))
821 self.c.write(' NULL\n')
823 self.c.write(' (GDBusAnnotationInfo **) &_%s_method_%s_annotation_info_pointers\n'%(i.name_lower, m.name_lower))
827 %(m.name_hyphen, 'TRUE' if unix_fd else 'FALSE'))
831 self.c.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] =\n'
832 '{\n'%(i.name_lower))
834 self.c.write(' &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
835 self.c.write(' NULL\n'
841 if len(i.signals) > 0:
843 self.generate_args('_%s_signal_info_%s_ARG'%(i.name_lower, s.name_lower), s.args)
845 num_anno = self.generate_annotations('_%s_signal_%s_annotation_info'%(i.name_lower, s.name_lower), s.annotations)
846 self.c.write('static const _ExtendedGDBusSignalInfo _%s_signal_info_%s =\n'
850 ' (gchar *) "%s",\n'%(i.name_lower, s.name_lower, s.name))
852 self.c.write(' NULL,\n')
854 self.c.write(' (GDBusArgInfo **) &_%s_signal_info_%s_ARG_pointers,\n'%(i.name_lower, s.name_lower))
856 self.c.write(' NULL\n')
858 self.c.write(' (GDBusAnnotationInfo **) &_%s_signal_%s_annotation_info_pointers\n'%(i.name_lower, s.name_lower))
865 self.c.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
866 '{\n'%(i.name_lower))
868 self.c.write(' &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
869 self.c.write(' NULL\n'
875 if len(i.properties) > 0:
876 for p in i.properties:
877 if p.readable and p.writable:
878 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
880 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE'
882 access = 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
884 access = 'G_DBUS_PROPERTY_INFO_FLAGS_NONE'
885 num_anno = self.generate_annotations('_%s_property_%s_annotation_info'%(i.name_lower, p.name_lower), p.annotations)
886 self.c.write('static const _ExtendedGDBusPropertyInfo _%s_property_info_%s =\n'
892 ' %s,\n'%(i.name_lower, p.name_lower, p.name, p.arg.signature, access))
894 self.c.write(' NULL\n')
896 self.c.write(' (GDBusAnnotationInfo **) &_%s_property_%s_annotation_info_pointers\n'%(i.name_lower, p.name_lower))
900 if not utils.lookup_annotation(p.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
901 self.c.write(' FALSE\n')
903 self.c.write(' TRUE\n')
907 self.c.write('static const _ExtendedGDBusPropertyInfo * const _%s_property_info_pointers[] =\n'
908 '{\n'%(i.name_lower))
909 for p in i.properties:
910 self.c.write(' &_%s_property_info_%s,\n'%(i.name_lower, p.name_lower))
911 self.c.write(' NULL\n'
915 num_anno = self.generate_annotations('_%s_annotation_info'%(i.name_lower), i.annotations)
916 self.c.write('static const _ExtendedGDBusInterfaceInfo _%s_interface_info =\n'
920 ' (gchar *) "%s",\n'%(i.name_lower, i.name))
921 if len(i.methods) == 0:
922 self.c.write(' NULL,\n')
924 self.c.write(' (GDBusMethodInfo **) &_%s_method_info_pointers,\n'%(i.name_lower))
925 if len(i.signals) == 0:
926 self.c.write(' NULL,\n')
928 self.c.write(' (GDBusSignalInfo **) &_%s_signal_info_pointers,\n'%(i.name_lower))
929 if len(i.properties) == 0:
930 self.c.write(' NULL,\n')
932 self.c.write(' (GDBusPropertyInfo **) &_%s_property_info_pointers,\n'%(i.name_lower))
934 self.c.write(' NULL\n')
936 self.c.write(' (GDBusAnnotationInfo **) &_%s_annotation_info_pointers\n'%(i.name_lower))
943 self.c.write(self.docbook_gen.expand(
945 ' * %s_interface_info:\n'
947 ' * Gets a machine-readable description of the #%s D-Bus interface.\n'
949 ' * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free.\n'
950 %(i.name_lower, i.name), False))
951 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
952 self.c.write('GDBusInterfaceInfo *\n'
953 '%s_interface_info (void)\n'
955 ' return (GDBusInterfaceInfo *) &_%s_interface_info.parent_struct;\n'
957 '\n'%(i.name_lower, i.name_lower))
959 self.c.write(self.docbook_gen.expand(
961 ' * %s_override_properties:\n'
962 ' * @klass: The class structure for a #GObject<!-- -->-derived class.\n'
963 ' * @property_id_begin: The property id to assign to the first overridden property.\n'
965 ' * Overrides all #GObject properties in the #%s interface for a concrete class.\n'
966 ' * The properties are overridden in the order they are defined.\n'
968 ' * Returns: The last property id.\n'
969 %(i.name_lower, i.camel_name), False))
970 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
971 self.c.write('guint\n'
972 '%s_override_properties (GObjectClass *klass, guint property_id_begin)\n'
973 '{\n'%(i.name_lower))
974 for p in i.properties:
975 self.c.write (' g_object_class_override_property (klass, property_id_begin++, "%s");\n'%(p.name_hyphen))
976 self.c.write(' return property_id_begin - 1;\n'
981 # ----------------------------------------------------------------------------------------------------
983 def generate_interface(self, i):
986 self.c.write(self.docbook_gen.expand(
990 ' * Abstract interface type for the D-Bus interface #%s.\n'
991 %(i.camel_name, i.name), False))
992 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
995 self.c.write(self.docbook_gen.expand(
998 ' * @parent_iface: The parent interface.\n'
999 %(i.camel_name), False))
1002 if len(i.methods) > 0:
1004 key = (m.since, '_method_%s'%m.name_lower)
1005 value = '@handle_%s: '%(m.name_lower)
1006 value += 'Handler for the #%s::handle-%s signal.'%(i.camel_name, m.name_hyphen)
1007 doc_bits[key] = value
1008 if len(i.signals) > 0:
1010 key = (s.since, '_signal_%s'%s.name_lower)
1011 value = '@%s: '%(s.name_lower)
1012 value += 'Handler for the #%s::%s signal.'%(i.camel_name, s.name_hyphen)
1013 doc_bits[key] = value
1014 if len(i.properties) > 0:
1015 for p in i.properties:
1016 key = (p.since, '_prop_get_%s'%p.name_lower)
1017 value = '@get_%s: '%(p.name_lower)
1018 value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
1019 doc_bits[key] = value
1020 for key in sorted(doc_bits.keys(), key=utils.version_cmp_key):
1021 self.c.write(' * %s\n'%doc_bits[key])
1023 self.c.write(self.docbook_gen.expand(
1025 ' * Virtual table for the D-Bus interface #%s.\n'
1027 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1030 self.c.write('typedef %sIface %sInterface;\n'%(i.camel_name, i.camel_name))
1031 self.c.write('G_DEFINE_INTERFACE (%s, %s, G_TYPE_OBJECT);\n'%(i.camel_name, i.name_lower))
1034 self.c.write('static void\n'
1035 '%s_default_init (%sIface *iface)\n'
1036 '{\n'%(i.name_lower, i.camel_name));
1038 if len(i.methods) > 0:
1039 self.c.write(' /* GObject signals for incoming D-Bus method calls: */\n')
1042 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1044 self.c.write(self.docbook_gen.expand(
1046 ' * %s::handle-%s:\n'
1047 ' * @object: A #%s.\n'
1048 ' * @invocation: A #GDBusMethodInvocation.\n'
1049 %(i.camel_name, m.name_hyphen, i.camel_name), False))
1051 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1053 self.c.write (' * @arg_%s: Argument passed by remote caller.\n'%(a.name))
1054 self.c.write(self.docbook_gen.expand(
1056 ' * Signal emitted when a remote caller is invoking the %s.%s() D-Bus method.\n'
1058 ' * 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'
1060 ' * Returns: %%TRUE if the invocation was handled, %%FALSE to let other signal handlers run.\n'
1061 %(i.name, m.name, i.name_lower, m.name_lower), False))
1062 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 2)
1067 self.c.write(' g_signal_new ("handle-%s",\n'
1068 ' G_TYPE_FROM_INTERFACE (iface),\n'
1069 ' G_SIGNAL_RUN_LAST,\n'
1070 ' G_STRUCT_OFFSET (%sIface, handle_%s),\n'
1071 ' g_signal_accumulator_true_handled,\n'
1072 ' NULL,\n' # accu_data
1073 ' g_cclosure_marshal_generic,\n'
1074 ' G_TYPE_BOOLEAN,\n'
1076 ' G_TYPE_DBUS_METHOD_INVOCATION'
1077 %(m.name_hyphen, i.camel_name, m.name_lower, len(m.in_args) + extra_args))
1079 self.c.write(', G_TYPE_UNIX_FD_LIST')
1081 self.c.write (', %s'%(a.gtype))
1082 self.c.write(');\n')
1085 if len(i.signals) > 0:
1086 self.c.write(' /* GObject signals for received D-Bus signals: */\n')
1088 self.c.write(self.docbook_gen.expand(
1091 ' * @object: A #%s.\n'
1092 %(i.camel_name, s.name_hyphen, i.camel_name), False))
1094 self.c.write (' * @arg_%s: Argument.\n'%(a.name))
1095 self.c.write(self.docbook_gen.expand(
1097 ' * On the client-side, this signal is emitted whenever the D-Bus signal #%s::%s is received.\n'
1099 ' * 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'
1100 %(i.name, s.name), False))
1101 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 2)
1102 self.c.write(' g_signal_new ("%s",\n'
1103 ' G_TYPE_FROM_INTERFACE (iface),\n'
1104 ' G_SIGNAL_RUN_LAST,\n'
1105 ' G_STRUCT_OFFSET (%sIface, %s),\n'
1106 ' NULL,\n' # accumulator
1107 ' NULL,\n' # accu_data
1108 ' g_cclosure_marshal_generic,\n'
1111 %(s.name_hyphen, i.camel_name, s.name_lower, len(s.args)))
1113 self.c.write (', %s'%(a.gtype))
1114 self.c.write(');\n')
1117 if len(i.properties) > 0:
1118 self.c.write(' /* GObject properties for D-Bus properties: */\n')
1119 for p in i.properties:
1120 if p.readable and p.writable:
1121 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.'
1123 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.'
1125 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.'
1127 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1128 self.c.write(self.docbook_gen.expand(
1132 ' * Represents the D-Bus property #%s:%s.\n'
1135 %(i.camel_name, p.name_hyphen, i.name, p.name, hint), False))
1136 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 2)
1137 self.c.write(' g_object_interface_install_property (iface,\n')
1138 if p.arg.gtype == 'G_TYPE_VARIANT':
1139 s = 'g_param_spec_variant ("%s", "%s", "%s", G_VARIANT_TYPE ("%s"), NULL'%(p.name_hyphen, p.name, p.name, p.arg.signature)
1140 elif p.arg.signature == 'b':
1141 s = 'g_param_spec_boolean ("%s", "%s", "%s", FALSE'%(p.name_hyphen, p.name, p.name)
1142 elif p.arg.signature == 'y':
1143 s = 'g_param_spec_uchar ("%s", "%s", "%s", 0, 255, 0'%(p.name_hyphen, p.name, p.name)
1144 elif p.arg.signature == 'n':
1145 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT16, G_MAXINT16, 0'%(p.name_hyphen, p.name, p.name)
1146 elif p.arg.signature == 'q':
1147 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT16, 0'%(p.name_hyphen, p.name, p.name)
1148 elif p.arg.signature == 'i':
1149 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT32, G_MAXINT32, 0'%(p.name_hyphen, p.name, p.name)
1150 elif p.arg.signature == 'u':
1151 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT32, 0'%(p.name_hyphen, p.name, p.name)
1152 elif p.arg.signature == 'x':
1153 s = 'g_param_spec_int64 ("%s", "%s", "%s", G_MININT64, G_MAXINT64, 0'%(p.name_hyphen, p.name, p.name)
1154 elif p.arg.signature == 't':
1155 s = 'g_param_spec_uint64 ("%s", "%s", "%s", 0, G_MAXUINT64, 0'%(p.name_hyphen, p.name, p.name)
1156 elif p.arg.signature == 'd':
1157 s = 'g_param_spec_double ("%s", "%s", "%s", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0'%(p.name_hyphen, p.name, p.name)
1158 elif p.arg.signature == 's':
1159 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1160 elif p.arg.signature == 'o':
1161 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1162 elif p.arg.signature == 'g':
1163 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1164 elif p.arg.signature == 'ay':
1165 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1166 elif p.arg.signature == 'as':
1167 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1168 elif p.arg.signature == 'ao':
1169 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1170 elif p.arg.signature == 'aay':
1171 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1173 raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
1174 self.c.write(' %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
1180 # ----------------------------------------------------------------------------------------------------
1182 def generate_property_accessors(self, i):
1183 for p in i.properties:
1185 if p.readable and p.writable:
1186 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.'
1188 hint = 'Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.'
1190 hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
1192 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1193 self.c.write(self.docbook_gen.expand(
1195 ' * %s_get_%s: (skip)\n'
1196 ' * @object: A #%s.\n'
1198 ' * Gets the value of the #%s:%s D-Bus property.\n'
1202 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1203 if p.arg.free_func != None:
1204 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'
1206 ' * 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'
1207 %(i.name_lower, p.name_lower))
1209 self.c.write(' * Returns: The property value.\n')
1210 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1212 '%s_get_%s (%s *object)\n'
1213 '{\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
1214 self.c.write(' return %s%s_GET_IFACE (object)->get_%s (object);\n'%(i.ns_upper, i.name_upper, p.name_lower))
1217 if p.arg.free_func != None:
1219 self.c.write(self.docbook_gen.expand(
1221 ' * %s_dup_%s: (skip)\n'
1222 ' * @object: A #%s.\n'
1224 ' * Gets a copy of the #%s:%s D-Bus property.\n'
1228 ' * Returns: (transfer full): The property value or %%NULL if the property is not set. The returned value should be freed with %s().\n'
1229 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint, p.arg.free_func), False))
1230 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1232 '%s_dup_%s (%s *object)\n'
1234 ' %svalue;\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in_dup))
1235 self.c.write(' g_object_get (G_OBJECT (object), "%s", &value, NULL);\n'%(p.name_hyphen))
1236 self.c.write(' return value;\n')
1241 if p.readable and p.writable:
1242 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.'
1244 hint = 'Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.'
1246 hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
1248 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1249 self.c.write(self.docbook_gen.expand(
1251 ' * %s_set_%s: (skip)\n'
1252 ' * @object: A #%s.\n'
1253 ' * @value: The value to set.\n'
1255 ' * Sets the #%s:%s D-Bus property to @value.\n'
1258 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1259 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1260 self.c.write('void\n'
1261 '%s_set_%s (%s *object, %svalue)\n'
1262 '{\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
1263 self.c.write(' g_object_set (G_OBJECT (object), "%s", value, NULL);\n'%(p.name_hyphen))
1267 # ---------------------------------------------------------------------------------------------------
1269 def generate_signal_emitters(self, i):
1271 self.c.write(self.docbook_gen.expand(
1274 ' * @object: A #%s.\n'
1275 %(i.name_lower, s.name_lower, i.camel_name), False))
1277 self.c.write(' * @arg_%s: Argument to pass with the signal.\n'%(a.name))
1278 self.c.write(self.docbook_gen.expand(
1280 ' * Emits the #%s::%s D-Bus signal.\n'
1281 %(i.name, s.name), False))
1282 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 0)
1283 self.c.write('void\n'
1285 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
1287 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1290 ' g_signal_emit_by_name (object, "%s"'%(s.name_hyphen))
1292 self.c.write(', arg_%s'%a.name)
1293 self.c.write(');\n')
1297 # ---------------------------------------------------------------------------------------------------
1299 def generate_method_calls(self, i):
1302 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1305 self.c.write('/**\n'
1307 ' * @proxy: A #%sProxy.\n'
1308 %(i.name_lower, m.name_lower, i.camel_name))
1310 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1312 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1313 self.c.write(self.docbook_gen.expand(
1314 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1315 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %%NULL.\n'
1316 ' * @user_data: User data to pass to @callback.\n'
1318 ' * Asynchronously invokes the %s.%s() D-Bus method on @proxy.\n'
1319 ' * 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'
1320 ' * You can then call %s_call_%s_finish() to get the result of the operation.\n'
1322 ' * See %s_call_%s_sync() for the synchronous, blocking version of this method.\n'
1323 %(i.name, m.name, i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1324 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1325 self.c.write('void\n'
1327 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1329 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1331 self.c.write(',\n GUnixFDList *fd_list')
1333 ' GCancellable *cancellable,\n'
1334 ' GAsyncReadyCallback callback,\n'
1335 ' gpointer user_data)\n'
1338 self.c.write(' g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy),\n')
1340 self.c.write(' g_dbus_proxy_call (G_DBUS_PROXY (proxy),\n')
1341 self.c.write(' "%s",\n'
1342 ' g_variant_new ("('%(m.name))
1344 self.c.write('%s'%(a.format_in))
1347 self.c.write(',\n arg_%s'%(a.name))
1349 ' G_DBUS_CALL_FLAGS_NONE,\n'
1352 self.c.write(' fd_list,\n')
1353 self.c.write(' cancellable,\n'
1359 self.c.write('/**\n'
1360 ' * %s_call_%s_finish:\n'
1361 ' * @proxy: A #%sProxy.\n'
1362 %(i.name_lower, m.name_lower, i.camel_name))
1363 for a in m.out_args:
1364 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1366 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1367 self.c.write(self.docbook_gen.expand(
1368 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_call_%s().\n'
1369 ' * @error: Return location for error or %%NULL.\n'
1371 ' * Finishes an operation started with %s_call_%s().\n'
1373 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1374 %(i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1375 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1376 self.c.write('gboolean\n'
1377 '%s_call_%s_finish (\n'
1378 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1379 for a in m.out_args:
1380 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1382 self.c.write(',\n GUnixFDList **out_fd_list')
1384 ' GAsyncResult *res,\n'
1385 ' GError **error)\n'
1387 ' GVariant *_ret;\n')
1389 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error);\n')
1391 self.c.write(' _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);\n')
1392 self.c.write(' if (_ret == NULL)\n'
1394 self.c.write(' g_variant_get (_ret,\n'
1396 for a in m.out_args:
1397 self.c.write('%s'%(a.format_out))
1399 for a in m.out_args:
1400 self.c.write(',\n out_%s'%(a.name))
1402 ' g_variant_unref (_ret);\n')
1403 self.c.write('_out:\n'
1404 ' return _ret != NULL;\n'
1410 self.c.write('/**\n'
1411 ' * %s_call_%s_sync:\n'
1412 ' * @proxy: A #%sProxy.\n'
1413 %(i.name_lower, m.name_lower, i.camel_name))
1415 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1417 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1418 for a in m.out_args:
1419 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1421 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1422 self.c.write(self.docbook_gen.expand(
1423 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1424 ' * @error: Return location for error or %%NULL.\n'
1426 ' * Synchronously invokes the %s.%s() D-Bus method on @proxy. The calling thread is blocked until a reply is received.\n'
1428 ' * See %s_call_%s() for the asynchronous version of this method.\n'
1430 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1431 %(i.name, m.name, i.name_lower, m.name_lower), False))
1432 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1433 self.c.write('gboolean\n'
1434 '%s_call_%s_sync (\n'
1435 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1437 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1439 self.c.write(',\n GUnixFDList *fd_list')
1440 for a in m.out_args:
1441 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1443 self.c.write(',\n GUnixFDList **out_fd_list')
1445 ' GCancellable *cancellable,\n'
1446 ' GError **error)\n'
1448 ' GVariant *_ret;\n')
1450 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy),\n')
1452 self.c.write(' _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),\n')
1453 self.c.write(' "%s",\n'
1454 ' g_variant_new ("('%(m.name))
1456 self.c.write('%s'%(a.format_in))
1459 self.c.write(',\n arg_%s'%(a.name))
1461 ' G_DBUS_CALL_FLAGS_NONE,\n'
1464 self.c.write(' fd_list,\n'
1466 self.c.write(' cancellable,\n'
1468 ' if (_ret == NULL)\n'
1470 self.c.write(' g_variant_get (_ret,\n'
1472 for a in m.out_args:
1473 self.c.write('%s'%(a.format_out))
1475 for a in m.out_args:
1476 self.c.write(',\n out_%s'%(a.name))
1478 ' g_variant_unref (_ret);\n')
1479 self.c.write('_out:\n'
1480 ' return _ret != NULL;\n'
1484 # ---------------------------------------------------------------------------------------------------
1486 def generate_method_completers(self, i):
1489 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1491 self.c.write('/**\n'
1492 ' * %s_complete_%s:\n'
1493 ' * @object: A #%s.\n'
1494 ' * @invocation: (transfer full): A #GDBusMethodInvocation.\n'
1495 %(i.name_lower, m.name_lower, i.camel_name))
1497 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1498 for a in m.out_args:
1499 self.c.write(' * @%s: Parameter to return.\n'%(a.name))
1500 self.c.write(self.docbook_gen.expand(
1502 ' * 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'
1504 ' * This method will free @invocation, you cannot use it afterwards.\n'
1505 %(i.name, m.name), False))
1506 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1507 self.c.write('void\n'
1508 '%s_complete_%s (\n'
1510 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
1512 self.c.write(',\n GUnixFDList *fd_list')
1513 for a in m.out_args:
1514 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1519 self.c.write(' g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,\n'
1520 ' g_variant_new ("(')
1522 self.c.write(' g_dbus_method_invocation_return_value (invocation,\n'
1523 ' g_variant_new ("(')
1524 for a in m.out_args:
1525 self.c.write('%s'%(a.format_in))
1527 for a in m.out_args:
1528 self.c.write(',\n %s'%(a.name))
1530 self.c.write('),\n fd_list);\n')
1532 self.c.write('));\n')
1536 # ---------------------------------------------------------------------------------------------------
1538 def generate_proxy(self, i):
1540 self.c.write('/* ------------------------------------------------------------------------ */\n'
1543 self.c.write(self.docbook_gen.expand(
1547 ' * The #%sProxy structure contains only private data and should only be accessed using the provided API.\n'
1548 %(i.camel_name, i.camel_name), False))
1549 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1552 self.c.write(self.docbook_gen.expand(
1554 ' * %sProxyClass:\n'
1555 ' * @parent_class: The parent class.\n'
1557 ' * Class structure for #%sProxy.\n'
1558 %(i.camel_name, i.camel_name), False))
1559 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1562 self.c.write('struct _%sProxyPrivate\n'
1568 self.c.write('static void %s_proxy_iface_init (%sIface *iface);\n'
1569 '\n'%(i.name_lower, i.camel_name))
1570 self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
1571 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1572 self.c.write(' G_ADD_PRIVATE (%sProxy)\n'%(i.camel_name))
1573 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1574 self.c.write('#else\n')
1575 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1576 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1577 self.c.write('#endif\n')
1580 self.c.write('static void\n'
1581 '%s_proxy_finalize (GObject *object)\n'
1582 '{\n'%(i.name_lower))
1583 self.c.write(' %sProxy *proxy = %s%s_PROXY (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
1584 self.c.write(' g_datalist_clear (&proxy->priv->qdata);\n')
1585 self.c.write(' G_OBJECT_CLASS (%s_proxy_parent_class)->finalize (object);\n'
1587 '\n'%(i.name_lower))
1589 # property accessors
1591 # Note that we are guaranteed that prop_id starts at 1 and is
1592 # laid out in the same order as introspection data pointers
1594 self.c.write('static void\n'
1595 '%s_proxy_get_property (GObject *object,\n'
1598 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
1599 '{\n'%(i.name_lower))
1600 if len(i.properties) > 0:
1601 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1602 ' GVariant *variant;\n'
1603 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1604 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1605 ' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
1606 ' if (info->use_gvariant)\n'
1608 ' g_value_set_variant (value, variant);\n'
1612 # could be that we don't have the value in cache - in that case, we do
1613 # nothing and the user gets the default value for the GType
1614 ' if (variant != NULL)\n'
1615 ' g_dbus_gvariant_to_gvalue (variant, value);\n'
1617 ' if (variant != NULL)\n'
1618 ' g_variant_unref (variant);\n'
1619 %(len(i.properties), i.name_lower))
1622 if len(i.properties) > 0:
1623 self.c.write('static void\n'
1624 '%s_proxy_set_property_cb (GDBusProxy *proxy,\n'
1625 ' GAsyncResult *res,\n'
1626 ' gpointer user_data)\n'
1627 '{\n'%(i.name_lower))
1628 self.c.write(' const _ExtendedGDBusPropertyInfo *info = user_data;\n'
1630 ' GVariant *_ret;\n'
1632 ' _ret = g_dbus_proxy_call_finish (proxy, res, &error);\n'
1635 ' g_warning ("Error setting property \'%%s\' on interface %s: %%s (%%s, %%d)",\n'
1636 ' info->parent_struct.name, \n'
1637 ' error->message, g_quark_to_string (error->domain), error->code);\n'
1638 ' g_error_free (error);\n'
1642 ' g_variant_unref (_ret);\n'
1647 self.c.write('static void\n'
1648 '%s_proxy_set_property (GObject *object,\n'
1650 ' const GValue *value,\n'
1651 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
1652 '{\n'%(i.name_lower))
1653 if len(i.properties) > 0:
1654 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1655 ' GVariant *variant;\n'
1656 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1657 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1658 ' variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
1659 ' g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
1660 ' "org.freedesktop.DBus.Properties.Set",\n'
1661 ' g_variant_new ("(ssv)", "%s", info->parent_struct.name, variant),\n'
1662 ' G_DBUS_CALL_FLAGS_NONE,\n'
1664 ' NULL, (GAsyncReadyCallback) %s_proxy_set_property_cb, (GDBusPropertyInfo *) &info->parent_struct);\n'
1665 ' g_variant_unref (variant);\n'
1666 %(len(i.properties), i.name_lower, i.name, i.name_lower))
1671 self.c.write('static void\n'
1672 '%s_proxy_g_signal (GDBusProxy *proxy,\n'
1673 ' const gchar *sender_name G_GNUC_UNUSED,\n'
1674 ' const gchar *signal_name,\n'
1675 ' GVariant *parameters)\n'
1676 '{\n'%(i.name_lower))
1677 self.c.write(' _ExtendedGDBusSignalInfo *info;\n'
1678 ' GVariantIter iter;\n'
1679 ' GVariant *child;\n'
1680 ' GValue *paramv;\n'
1681 ' guint num_params;\n'
1683 ' guint signal_id;\n');
1684 # Note: info could be NULL if we are talking to a newer version of the interface
1685 self.c.write(' info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, signal_name);\n'
1686 ' if (info == NULL)\n'
1689 self.c.write (' num_params = g_variant_n_children (parameters);\n'
1690 ' paramv = g_new0 (GValue, num_params + 1);\n'
1691 ' g_value_init (¶mv[0], %sTYPE_%s);\n'
1692 ' g_value_set_object (¶mv[0], proxy);\n'
1693 %(i.ns_upper, i.name_upper))
1694 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
1696 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
1698 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1];\n'
1699 ' if (arg_info->use_gvariant)\n'
1701 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
1702 ' g_value_set_variant (¶mv[n], child);\n'
1706 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
1707 ' g_variant_unref (child);\n'
1710 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
1711 %(i.ns_upper, i.name_upper))
1712 self.c.write(' g_signal_emitv (paramv, signal_id, 0, NULL);\n')
1713 self.c.write(' for (n = 0; n < num_params + 1; n++)\n'
1714 ' g_value_unset (¶mv[n]);\n'
1715 ' g_free (paramv);\n')
1720 self.c.write('static void\n'
1721 '%s_proxy_g_properties_changed (GDBusProxy *_proxy,\n'
1722 ' GVariant *changed_properties,\n'
1723 ' const gchar *const *invalidated_properties)\n'
1724 '{\n'%(i.name_lower))
1725 # Note: info could be NULL if we are talking to a newer version of the interface
1726 self.c.write(' %sProxy *proxy = %s%s_PROXY (_proxy);\n'
1728 ' const gchar *key;\n'
1729 ' GVariantIter *iter;\n'
1730 ' _ExtendedGDBusPropertyInfo *info;\n'
1731 ' g_variant_get (changed_properties, "a{sv}", &iter);\n'
1732 ' while (g_variant_iter_next (iter, "{&sv}", &key, NULL))\n'
1734 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, key);\n'
1735 ' g_datalist_remove_data (&proxy->priv->qdata, key);\n'
1736 ' if (info != NULL)\n'
1737 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1739 ' g_variant_iter_free (iter);\n'
1740 ' for (n = 0; invalidated_properties[n] != NULL; n++)\n'
1742 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, invalidated_properties[n]);\n'
1743 ' g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]);\n'
1744 ' if (info != NULL)\n'
1745 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1749 %(i.camel_name, i.ns_upper, i.name_upper,
1750 i.name_lower, i.name_lower))
1753 for p in i.properties:
1755 if p.arg.free_func != None:
1757 self.c.write('static %s\n'
1758 '%s_proxy_get_%s (%s *object)\n'
1760 ' %sProxy *proxy = %s%s_PROXY (object);\n'
1761 ' GVariant *variant;\n'
1762 ' %svalue = %s;\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name,
1763 i.camel_name, i.ns_upper, i.name_upper,
1764 p.arg.ctype_in, nul_value))
1765 # For some property types, we have to free the returned
1766 # value (or part of it, e.g. the container) because of how
1767 # GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
1770 free_container = False;
1771 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':
1772 free_container = True;
1773 # If already using an old value for strv, objpathv, bytestring_array (see below),
1774 # then just return that... that way the result from multiple consecutive calls
1775 # to the getter are valid as long as they're freed
1778 self.c.write(' value = g_datalist_get_data (&proxy->priv->qdata, \"%s\");\n'
1779 ' if (value != NULL)\n'
1782 self.c.write(' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \"%s\");\n'%(p.name))
1783 if p.arg.gtype == 'G_TYPE_VARIANT':
1784 self.c.write(' value = variant;\n')
1785 self.c.write(' if (variant != NULL)\n')
1786 self.c.write(' g_variant_unref (variant);\n')
1788 self.c.write(' if (variant != NULL)\n'
1791 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':
1792 extra_len = ', NULL'
1793 self.c.write(' value = %s (variant%s);\n'%(p.arg.gvariant_get, extra_len))
1795 self.c.write(' g_datalist_set_data_full (&proxy->priv->qdata, \"%s\", (gpointer) value, g_free);\n'
1797 self.c.write(' g_variant_unref (variant);\n')
1798 self.c.write(' }\n')
1799 self.c.write(' return value;\n')
1804 self.c.write('static void\n'
1805 '%s_proxy_init (%sProxy *proxy)\n'
1807 '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
1808 ' proxy->priv = %s_proxy_get_instance_private (proxy);\n'
1810 ' proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %sTYPE_%s_PROXY, %sProxyPrivate);\n'
1812 ' g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
1815 %(i.name_lower, i.camel_name,
1817 i.ns_upper, i.name_upper, i.camel_name,
1819 self.c.write('static void\n'
1820 '%s_proxy_class_init (%sProxyClass *klass)\n'
1822 ' GObjectClass *gobject_class;\n'
1823 ' GDBusProxyClass *proxy_class;\n'
1825 ' gobject_class = G_OBJECT_CLASS (klass);\n'
1826 ' gobject_class->finalize = %s_proxy_finalize;\n'
1827 ' gobject_class->get_property = %s_proxy_get_property;\n'
1828 ' gobject_class->set_property = %s_proxy_set_property;\n'
1830 ' proxy_class = G_DBUS_PROXY_CLASS (klass);\n'
1831 ' proxy_class->g_signal = %s_proxy_g_signal;\n'
1832 ' proxy_class->g_properties_changed = %s_proxy_g_properties_changed;\n'
1833 '\n'%(i.name_lower, i.camel_name,
1834 i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
1835 if len(i.properties) > 0:
1836 self.c.write(' %s_override_properties (gobject_class, 1);\n\n'%(i.name_lower))
1837 self.c.write('#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
1838 ' g_type_class_add_private (klass, sizeof (%sProxyPrivate));\n'
1839 '#endif\n'%(i.camel_name))
1843 self.c.write('static void\n'
1844 '%s_proxy_iface_init (%sIface *iface)\n'
1845 '{\n'%(i.name_lower, i.camel_name))
1846 for p in i.properties:
1847 self.c.write(' iface->get_%s = %s_proxy_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
1852 self.c.write(self.docbook_gen.expand(
1854 ' * %s_proxy_new:\n'
1855 ' * @connection: A #GDBusConnection.\n'
1856 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1857 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1858 ' * @object_path: An object path.\n'
1859 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1860 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1861 ' * @user_data: User data to pass to @callback.\n'
1863 ' * Asynchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new() for more details.\n'
1865 ' * 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'
1866 ' * You can then call %s_proxy_new_finish() to get the result of the operation.\n'
1868 ' * See %s_proxy_new_sync() for the synchronous, blocking version of this constructor.\n'
1869 %(i.name_lower, i.name, i.name_lower, i.name_lower), False))
1870 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1871 self.c.write('void\n'
1873 ' GDBusConnection *connection,\n'
1874 ' GDBusProxyFlags flags,\n'
1875 ' const gchar *name,\n'
1876 ' const gchar *object_path,\n'
1877 ' GCancellable *cancellable,\n'
1878 ' GAsyncReadyCallback callback,\n'
1879 ' gpointer user_data)\n'
1881 ' 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'
1884 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1885 self.c.write('/**\n'
1886 ' * %s_proxy_new_finish:\n'
1887 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new().\n'
1888 ' * @error: Return location for error or %%NULL\n'
1890 ' * Finishes an operation started with %s_proxy_new().\n'
1892 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1893 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1894 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1895 self.c.write('%s *\n'
1896 '%s_proxy_new_finish (\n'
1897 ' GAsyncResult *res,\n'
1898 ' GError **error)\n'
1901 ' GObject *source_object;\n'
1902 ' source_object = g_async_result_get_source_object (res);\n'
1903 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1904 ' g_object_unref (source_object);\n'
1905 ' if (ret != NULL)\n'
1906 ' return %s%s (ret);\n'
1911 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1912 self.c.write(self.docbook_gen.expand(
1914 ' * %s_proxy_new_sync:\n'
1915 ' * @connection: A #GDBusConnection.\n'
1916 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1917 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1918 ' * @object_path: An object path.\n'
1919 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1920 ' * @error: Return location for error or %%NULL\n'
1922 ' * Synchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new_sync() for more details.\n'
1924 ' * The calling thread is blocked until a reply is received.\n'
1926 ' * See %s_proxy_new() for the asynchronous version of this constructor.\n'
1928 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1929 %(i.name_lower, i.name, i.name_lower, i.camel_name), False))
1930 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1931 self.c.write('%s *\n'
1932 '%s_proxy_new_sync (\n'
1933 ' GDBusConnection *connection,\n'
1934 ' GDBusProxyFlags flags,\n'
1935 ' const gchar *name,\n'
1936 ' const gchar *object_path,\n'
1937 ' GCancellable *cancellable,\n'
1938 ' GError **error)\n'
1940 ' GInitable *ret;\n'
1941 ' 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'
1942 ' if (ret != NULL)\n'
1943 ' return %s%s (ret);\n'
1948 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
1950 self.c.write(self.docbook_gen.expand(
1952 ' * %s_proxy_new_for_bus:\n'
1953 ' * @bus_type: A #GBusType.\n'
1954 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1955 ' * @name: A bus name (well-known or unique).\n'
1956 ' * @object_path: An object path.\n'
1957 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1958 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1959 ' * @user_data: User data to pass to @callback.\n'
1961 ' * Like %s_proxy_new() but takes a #GBusType instead of a #GDBusConnection.\n'
1963 ' * 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'
1964 ' * You can then call %s_proxy_new_for_bus_finish() to get the result of the operation.\n'
1966 ' * See %s_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
1967 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower), False))
1968 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1969 self.c.write('void\n'
1970 '%s_proxy_new_for_bus (\n'
1971 ' GBusType bus_type,\n'
1972 ' GDBusProxyFlags flags,\n'
1973 ' const gchar *name,\n'
1974 ' const gchar *object_path,\n'
1975 ' GCancellable *cancellable,\n'
1976 ' GAsyncReadyCallback callback,\n'
1977 ' gpointer user_data)\n'
1979 ' 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'
1982 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1983 self.c.write('/**\n'
1984 ' * %s_proxy_new_for_bus_finish:\n'
1985 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new_for_bus().\n'
1986 ' * @error: Return location for error or %%NULL\n'
1988 ' * Finishes an operation started with %s_proxy_new_for_bus().\n'
1990 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1991 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1992 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1993 self.c.write('%s *\n'
1994 '%s_proxy_new_for_bus_finish (\n'
1995 ' GAsyncResult *res,\n'
1996 ' GError **error)\n'
1999 ' GObject *source_object;\n'
2000 ' source_object = g_async_result_get_source_object (res);\n'
2001 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
2002 ' g_object_unref (source_object);\n'
2003 ' if (ret != NULL)\n'
2004 ' return %s%s (ret);\n'
2009 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
2010 self.c.write(self.docbook_gen.expand(
2012 ' * %s_proxy_new_for_bus_sync:\n'
2013 ' * @bus_type: A #GBusType.\n'
2014 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
2015 ' * @name: A bus name (well-known or unique).\n'
2016 ' * @object_path: An object path.\n'
2017 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
2018 ' * @error: Return location for error or %%NULL\n'
2020 ' * Like %s_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
2022 ' * The calling thread is blocked until a reply is received.\n'
2024 ' * See %s_proxy_new_for_bus() for the asynchronous version of this constructor.\n'
2026 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2027 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name), False))
2028 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2029 self.c.write('%s *\n'
2030 '%s_proxy_new_for_bus_sync (\n'
2031 ' GBusType bus_type,\n'
2032 ' GDBusProxyFlags flags,\n'
2033 ' const gchar *name,\n'
2034 ' const gchar *object_path,\n'
2035 ' GCancellable *cancellable,\n'
2036 ' GError **error)\n'
2038 ' GInitable *ret;\n'
2039 ' 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'
2040 ' if (ret != NULL)\n'
2041 ' return %s%s (ret);\n'
2046 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
2049 # ---------------------------------------------------------------------------------------------------
2051 def generate_skeleton(self, i):
2053 self.c.write('/* ------------------------------------------------------------------------ */\n'
2056 self.c.write(self.docbook_gen.expand(
2060 ' * The #%sSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2061 %(i.camel_name, i.camel_name), False))
2062 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2065 self.c.write(self.docbook_gen.expand(
2067 ' * %sSkeletonClass:\n'
2068 ' * @parent_class: The parent class.\n'
2070 ' * Class structure for #%sSkeleton.\n'
2071 %(i.camel_name, i.camel_name), False))
2072 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2075 self.c.write('struct _%sSkeletonPrivate\n'
2077 ' GValue *properties;\n'
2078 ' GList *changed_properties;\n'
2079 ' GSource *changed_properties_idle_source;\n'
2080 ' GMainContext *context;\n'
2085 self.c.write('static void\n'
2086 '_%s_skeleton_handle_method_call (\n'
2087 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2088 ' const gchar *sender G_GNUC_UNUSED,\n'
2089 ' const gchar *object_path G_GNUC_UNUSED,\n'
2090 ' const gchar *interface_name,\n'
2091 ' const gchar *method_name,\n'
2092 ' GVariant *parameters,\n'
2093 ' GDBusMethodInvocation *invocation,\n'
2094 ' gpointer user_data)\n'
2096 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2097 ' _ExtendedGDBusMethodInfo *info;\n'
2098 ' GVariantIter iter;\n'
2099 ' GVariant *child;\n'
2100 ' GValue *paramv;\n'
2101 ' guint num_params;\n'
2102 ' guint num_extra;\n'
2104 ' guint signal_id;\n'
2105 ' GValue return_value = G_VALUE_INIT;\n'
2106 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2107 self.c.write(' info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n'
2108 ' g_assert (info != NULL);\n'
2110 self.c.write (' num_params = g_variant_n_children (parameters);\n'
2111 ' num_extra = info->pass_fdlist ? 3 : 2;'
2112 ' paramv = g_new0 (GValue, num_params + num_extra);\n'
2114 ' g_value_init (¶mv[n], %sTYPE_%s);\n'
2115 ' g_value_set_object (¶mv[n++], skeleton);\n'
2116 ' g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION);\n'
2117 ' g_value_set_object (¶mv[n++], invocation);\n'
2118 ' if (info->pass_fdlist)\n'
2120 '#ifdef G_OS_UNIX\n'
2121 ' g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST);\n'
2122 ' g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)));\n'
2124 ' g_assert_not_reached ();\n'
2127 %(i.ns_upper, i.name_upper))
2128 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
2129 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
2131 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra];\n'
2132 ' if (arg_info->use_gvariant)\n'
2134 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
2135 ' g_value_set_variant (¶mv[n], child);\n'
2139 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
2140 ' g_variant_unref (child);\n'
2143 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
2144 %(i.ns_upper, i.name_upper))
2145 self.c.write(' g_value_init (&return_value, G_TYPE_BOOLEAN);\n'
2146 ' g_signal_emitv (paramv, signal_id, 0, &return_value);\n'
2147 ' if (!g_value_get_boolean (&return_value))\n'
2148 ' 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'
2149 ' g_value_unset (&return_value);\n'
2151 self.c.write(' for (n = 0; n < num_params + num_extra; n++)\n'
2152 ' g_value_unset (¶mv[n]);\n'
2153 ' g_free (paramv);\n')
2157 self.c.write('static GVariant *\n'
2158 '_%s_skeleton_handle_get_property (\n'
2159 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2160 ' const gchar *sender G_GNUC_UNUSED,\n'
2161 ' const gchar *object_path G_GNUC_UNUSED,\n'
2162 ' const gchar *interface_name G_GNUC_UNUSED,\n'
2163 ' const gchar *property_name,\n'
2164 ' GError **error,\n'
2165 ' gpointer user_data)\n'
2167 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2168 ' GValue value = G_VALUE_INIT;\n'
2169 ' GParamSpec *pspec;\n'
2170 ' _ExtendedGDBusPropertyInfo *info;\n'
2172 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2173 self.c.write(' ret = NULL;\n'
2174 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2175 ' g_assert (info != NULL);\n'
2176 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2177 ' if (pspec == NULL)\n'
2179 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2183 ' g_value_init (&value, pspec->value_type);\n'
2184 ' g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2185 ' ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
2186 ' g_value_unset (&value);\n'
2193 self.c.write('static gboolean\n'
2194 '_%s_skeleton_handle_set_property (\n'
2195 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2196 ' const gchar *sender G_GNUC_UNUSED,\n'
2197 ' const gchar *object_path G_GNUC_UNUSED,\n'
2198 ' const gchar *interface_name G_GNUC_UNUSED,\n'
2199 ' const gchar *property_name,\n'
2200 ' GVariant *variant,\n'
2201 ' GError **error,\n'
2202 ' gpointer user_data)\n'
2204 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2205 ' GValue value = G_VALUE_INIT;\n'
2206 ' GParamSpec *pspec;\n'
2207 ' _ExtendedGDBusPropertyInfo *info;\n'
2209 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2210 self.c.write(' ret = FALSE;\n'
2211 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2212 ' g_assert (info != NULL);\n'
2213 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2214 ' if (pspec == NULL)\n'
2216 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2220 ' if (info->use_gvariant)\n'
2221 ' g_value_set_variant (&value, variant);\n'
2223 ' g_dbus_gvariant_to_gvalue (variant, &value);\n'
2224 ' g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2225 ' g_value_unset (&value);\n'
2234 self.c.write('static const GDBusInterfaceVTable _%s_skeleton_vtable =\n'
2236 ' _%s_skeleton_handle_method_call,\n'
2237 ' _%s_skeleton_handle_get_property,\n'
2238 ' _%s_skeleton_handle_set_property,\n'
2241 '\n'%(i.name_lower, i.name_lower, i.name_lower, i.name_lower))
2243 self.c.write('static GDBusInterfaceInfo *\n'
2244 '%s_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2246 ' return %s_interface_info ();\n'
2247 %(i.name_lower, i.name_lower))
2251 self.c.write('static GDBusInterfaceVTable *\n'
2252 '%s_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2254 ' return (GDBusInterfaceVTable *) &_%s_skeleton_vtable;\n'
2255 %(i.name_lower, i.name_lower))
2259 self.c.write('static GVariant *\n'
2260 '%s_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton)\n'
2262 ' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2263 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2265 ' GVariantBuilder builder;\n'
2267 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2268 ' if (_%s_interface_info.parent_struct.properties == NULL)\n'
2270 ' for (n = 0; _%s_interface_info.parent_struct.properties[n] != NULL; n++)\n'
2272 ' GDBusPropertyInfo *info = _%s_interface_info.parent_struct.properties[n];\n'
2273 ' if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)\n'
2275 ' GVariant *value;\n'
2276 ' 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'
2277 ' if (value != NULL)\n'
2279 ' g_variant_take_ref (value);\n'
2280 ' g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
2281 ' g_variant_unref (value);\n'
2286 ' return g_variant_builder_end (&builder);\n'
2289 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name))
2291 if len(i.properties) > 0:
2292 self.c.write('static gboolean _%s_emit_changed (gpointer user_data);\n'
2296 self.c.write('static void\n'
2297 '%s_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton)\n'
2300 if len(i.properties) > 0:
2301 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2302 ' gboolean emit_changed = FALSE;\n'
2304 ' g_mutex_lock (&skeleton->priv->lock);\n'
2305 ' if (skeleton->priv->changed_properties_idle_source != NULL)\n'
2307 ' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
2308 ' skeleton->priv->changed_properties_idle_source = NULL;\n'
2309 ' emit_changed = TRUE;\n'
2311 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2313 ' if (emit_changed)\n'
2314 ' _%s_emit_changed (skeleton);\n'
2315 %(i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2320 self.c.write('static void\n'
2321 '_%s_on_signal_%s (\n'
2322 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
2324 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
2327 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n\n'
2328 ' GList *connections, *l;\n'
2329 ' GVariant *signal_variant;\n'
2330 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2331 %(i.camel_name, i.ns_upper, i.name_upper))
2333 ' signal_variant = g_variant_ref_sink (g_variant_new ("(')
2335 self.c.write('%s'%(a.format_in))
2338 self.c.write(',\n arg_%s'%(a.name))
2339 self.c.write('));\n')
2341 self.c.write(' for (l = connections; l != NULL; l = l->next)\n'
2343 ' GDBusConnection *connection = l->data;\n'
2344 ' g_dbus_connection_emit_signal (connection,\n'
2345 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", "%s",\n'
2346 ' signal_variant, NULL);\n'
2349 self.c.write(' g_variant_unref (signal_variant);\n')
2350 self.c.write(' g_list_free_full (connections, g_object_unref);\n')
2354 self.c.write('static void %s_skeleton_iface_init (%sIface *iface);\n'
2355 %(i.name_lower, i.camel_name))
2357 self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
2358 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2359 self.c.write(' G_ADD_PRIVATE (%sSkeleton)\n'%(i.camel_name))
2360 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2361 self.c.write('#else\n')
2362 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2363 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2364 self.c.write('#endif\n')
2367 self.c.write('static void\n'
2368 '%s_skeleton_finalize (GObject *object)\n'
2369 '{\n'%(i.name_lower))
2370 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2371 if len(i.properties) > 0:
2372 self.c.write(' guint n;\n'
2373 ' for (n = 0; n < %d; n++)\n'
2374 ' g_value_unset (&skeleton->priv->properties[n]);\n'%(len(i.properties)))
2375 self.c.write(' g_free (skeleton->priv->properties);\n')
2376 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2377 self.c.write(' if (skeleton->priv->changed_properties_idle_source != NULL)\n')
2378 self.c.write(' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
2379 self.c.write(' g_main_context_unref (skeleton->priv->context);\n')
2380 self.c.write(' g_mutex_clear (&skeleton->priv->lock);\n')
2381 self.c.write(' G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
2383 '\n'%(i.name_lower))
2385 # property accessors (TODO: generate PropertiesChanged signals in setter)
2386 if len(i.properties) > 0:
2387 self.c.write('static void\n'
2388 '%s_skeleton_get_property (GObject *object,\n'
2391 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
2392 '{\n'%(i.name_lower))
2393 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2394 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2395 ' g_mutex_lock (&skeleton->priv->lock);\n'
2396 ' g_value_copy (&skeleton->priv->properties[prop_id - 1], value);\n'
2397 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2398 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
2402 # if property is already scheduled then re-use entry.. though it could be
2405 # foo_set_prop_bar (object, "");
2406 # foo_set_prop_bar (object, "blah");
2408 # say, every update... In this case, where nothing happens, we obviously
2409 # don't want a PropertiesChanged() event. We can easily check for this
2410 # by comparing against the _original value_ recorded before the first
2411 # change event. If the latest value is not different from the original
2412 # one, we can simply ignore the ChangedProperty
2414 self.c.write('static gboolean\n'
2415 '_%s_emit_changed (gpointer user_data)\n'
2417 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2418 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2419 self.c.write(' GList *l;\n'
2420 ' GVariantBuilder builder;\n'
2421 ' GVariantBuilder invalidated_builder;\n'
2422 ' guint num_changes;\n'
2424 ' g_mutex_lock (&skeleton->priv->lock);\n'
2425 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2426 ' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
2427 ' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
2429 ' ChangedProperty *cp = l->data;\n'
2430 ' GVariant *variant;\n'
2431 ' const GValue *cur_value;\n'
2433 ' cur_value = &skeleton->priv->properties[cp->prop_id - 1];\n'
2434 ' if (!_g_value_equal (cur_value, &cp->orig_value))\n'
2436 ' variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature));\n'
2437 ' g_variant_builder_add (&builder, "{sv}", cp->info->parent_struct.name, variant);\n'
2438 ' g_variant_unref (variant);\n'
2442 ' if (num_changes > 0)\n'
2444 ' GList *connections, *ll;\n'
2445 ' GVariant *signal_variant;'
2447 ' signal_variant = g_variant_ref_sink (g_variant_new ("(sa{sv}as)", "%s",\n'
2448 ' &builder, &invalidated_builder));\n'
2449 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2450 ' for (ll = connections; ll != NULL; ll = ll->next)\n'
2452 ' GDBusConnection *connection = ll->data;\n'
2454 ' g_dbus_connection_emit_signal (connection,\n'
2455 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2456 ' "org.freedesktop.DBus.Properties",\n'
2457 ' "PropertiesChanged",\n'
2458 ' signal_variant,\n'
2461 ' g_variant_unref (signal_variant);\n'
2462 ' g_list_free_full (connections, g_object_unref);\n'
2466 ' g_variant_builder_clear (&builder);\n'
2467 ' g_variant_builder_clear (&invalidated_builder);\n'
2470 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2471 self.c.write(' skeleton->priv->changed_properties = NULL;\n')
2472 self.c.write(' skeleton->priv->changed_properties_idle_source = NULL;\n')
2473 self.c.write(' g_mutex_unlock (&skeleton->priv->lock);\n')
2474 self.c.write(' return FALSE;\n'
2477 # holding lock while being called
2478 self.c.write('static void\n'
2479 '_%s_schedule_emit_changed (%sSkeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value)\n'
2481 ' ChangedProperty *cp;\n'
2484 ' for (l = skeleton->priv->changed_properties; l != NULL; l = l->next)\n'
2486 ' ChangedProperty *i_cp = l->data;\n'
2487 ' if (i_cp->info == info)\n'
2493 %(i.name_lower, i.camel_name))
2494 self.c.write(' if (cp == NULL)\n'
2496 ' cp = g_new0 (ChangedProperty, 1);\n'
2497 ' cp->prop_id = prop_id;\n'
2498 ' cp->info = info;\n'
2499 ' skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp);\n'
2500 ' g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value));\n'
2501 ' g_value_copy (orig_value, &cp->orig_value);\n'
2507 # Postpone setting up the refresh source until the ::notify signal is emitted as
2508 # this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
2509 # This is useful when updating several properties from another thread than
2510 # where the idle will be emitted from
2511 self.c.write('static void\n'
2512 '%s_skeleton_notify (GObject *object,\n'
2513 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
2515 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2516 ' g_mutex_lock (&skeleton->priv->lock);\n'
2517 ' if (skeleton->priv->changed_properties != NULL &&\n'
2518 ' skeleton->priv->changed_properties_idle_source == NULL)\n'
2520 ' skeleton->priv->changed_properties_idle_source = g_idle_source_new ();\n'
2521 ' g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);\n'
2522 ' g_source_set_callback (skeleton->priv->changed_properties_idle_source, _%s_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);\n'
2523 ' g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _%s_emit_changed");\n'
2524 ' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
2525 ' g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
2527 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2530 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower, i.name_lower))
2532 self.c.write('static void\n'
2533 '%s_skeleton_set_property (GObject *object,\n'
2535 ' const GValue *value,\n'
2536 ' GParamSpec *pspec)\n'
2537 '{\n'%(i.name_lower))
2538 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2539 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2540 ' g_mutex_lock (&skeleton->priv->lock);\n'
2541 ' g_object_freeze_notify (object);\n'
2542 ' if (!_g_value_equal (value, &skeleton->priv->properties[prop_id - 1]))\n'
2544 ' if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
2545 ' _%s_schedule_emit_changed (skeleton, _%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties[prop_id - 1]);\n'
2546 ' g_value_copy (value, &skeleton->priv->properties[prop_id - 1]);\n'
2547 ' g_object_notify_by_pspec (object, pspec);\n'
2549 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2550 ' g_object_thaw_notify (object);\n'
2551 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
2555 self.c.write('static void\n'
2556 '%s_skeleton_init (%sSkeleton *skeleton)\n'
2558 '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
2559 ' skeleton->priv = %s_skeleton_get_instance_private (skeleton);\n'
2561 ' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
2563 %(i.name_lower, i.camel_name,
2565 i.ns_upper, i.name_upper, i.camel_name))
2566 self.c.write(' g_mutex_init (&skeleton->priv->lock);\n')
2567 self.c.write(' skeleton->priv->context = g_main_context_ref_thread_default ();\n')
2568 if len(i.properties) > 0:
2569 self.c.write(' skeleton->priv->properties = g_new0 (GValue, %d);\n'%(len(i.properties)))
2571 for p in i.properties:
2572 self.c.write(' g_value_init (&skeleton->priv->properties[%d], %s);\n'%(n, p.arg.gtype))
2579 for p in i.properties:
2580 self.c.write('static %s\n'
2581 '%s_skeleton_get_%s (%s *object)\n'
2583 %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
2584 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2585 self.c.write(' %svalue;\n'
2586 ' g_mutex_lock (&skeleton->priv->lock);\n'
2587 ' value = %s (&(skeleton->priv->properties[%d]));\n'
2588 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2589 %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
2590 self.c.write(' return value;\n')
2595 self.c.write('static void\n'
2596 '%s_skeleton_class_init (%sSkeletonClass *klass)\n'
2598 ' GObjectClass *gobject_class;\n'
2599 ' GDBusInterfaceSkeletonClass *skeleton_class;\n'
2601 ' gobject_class = G_OBJECT_CLASS (klass);\n'
2602 ' gobject_class->finalize = %s_skeleton_finalize;\n'
2603 %(i.name_lower, i.camel_name, i.name_lower))
2604 if len(i.properties) > 0:
2605 self.c.write(' gobject_class->get_property = %s_skeleton_get_property;\n'
2606 ' gobject_class->set_property = %s_skeleton_set_property;\n'
2607 ' gobject_class->notify = %s_skeleton_notify;\n'
2608 '\n'%(i.name_lower, i.name_lower, i.name_lower))
2610 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
2612 ' skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);\n');
2613 self.c.write(' skeleton_class->get_info = %s_skeleton_dbus_interface_get_info;\n'%(i.name_lower))
2614 self.c.write(' skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
2615 self.c.write(' skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
2616 self.c.write(' skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
2619 '#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
2620 ' g_type_class_add_private (klass, sizeof (%sSkeletonPrivate));\n'
2621 '#endif\n'%(i.camel_name))
2626 self.c.write('static void\n'
2627 '%s_skeleton_iface_init (%sIface *iface)\n'
2629 %(i.name_lower, i.camel_name))
2631 self.c.write(' iface->%s = _%s_on_signal_%s;\n'
2632 %(s.name_lower, i.name_lower, s.name_lower))
2633 for p in i.properties:
2634 self.c.write(' iface->get_%s = %s_skeleton_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
2639 self.c.write(self.docbook_gen.expand(
2641 ' * %s_skeleton_new:\n'
2643 ' * Creates a skeleton object for the D-Bus interface #%s.\n'
2645 ' * Returns: (transfer full) (type %sSkeleton): The skeleton object.\n'
2646 %(i.name_lower, i.name, i.camel_name), False))
2647 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2648 self.c.write('%s *\n'
2649 '%s_skeleton_new (void)\n'
2651 ' return %s%s (g_object_new (%sTYPE_%s_SKELETON, NULL));\n'
2653 '\n'%(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
2655 # ---------------------------------------------------------------------------------------------------
2657 def generate_object(self):
2658 self.c.write('/* ------------------------------------------------------------------------\n'
2659 ' * Code for Object, ObjectProxy and ObjectSkeleton\n'
2660 ' * ------------------------------------------------------------------------\n'
2664 self.c.write(self.docbook_gen.expand(
2666 ' * SECTION:%sObject\n'
2667 ' * @title: %sObject\n'
2668 ' * @short_description: Specialized GDBusObject types\n'
2670 ' * 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'
2672 %(self.namespace, self.namespace, self.namespace, self.namespace, self.namespace), False))
2675 self.c.write(self.docbook_gen.expand(
2679 ' * The #%sObject type is a specialized container of interfaces.\n'
2681 %(self.namespace, self.namespace), False))
2684 self.c.write(self.docbook_gen.expand(
2686 ' * %sObjectIface:\n'
2687 ' * @parent_iface: The parent interface.\n'
2689 ' * Virtual table for the #%sObject interface.\n'
2691 %(self.namespace, self.namespace), False))
2694 self.c.write('typedef %sObjectIface %sObjectInterface;\n'%(self.namespace, self.namespace))
2695 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))
2697 self.c.write('static void\n'
2698 '%sobject_default_init (%sObjectIface *iface)\n'
2700 %(self.ns_lower, self.namespace));
2701 for i in self.ifaces:
2702 self.c.write(self.docbook_gen.expand(
2706 ' * The #%s instance corresponding to the D-Bus interface #%s, if any.\n'
2708 ' * Connect to the #GObject::notify signal to get informed of property changes.\n'
2709 %(self.namespace, i.name_hyphen, i.camel_name, i.name), False))
2710 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 2)
2711 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'
2713 %(i.name_hyphen, i.name_hyphen, i.name_hyphen, self.ns_upper, i.name_upper))
2717 for i in self.ifaces:
2718 self.c.write(self.docbook_gen.expand(
2720 ' * %sobject_get_%s:\n'
2721 ' * @object: A #%sObject.\n'
2723 ' * Gets the #%s instance for the D-Bus interface #%s on @object, if any.\n'
2725 ' * Returns: (transfer full): A #%s that must be freed with g_object_unref() or %%NULL if @object does not implement the interface.\n'
2726 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.name, i.camel_name), False))
2727 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2728 self.c.write ('%s *%sobject_get_%s (%sObject *object)\n'
2729 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2731 ' GDBusInterface *ret;\n'
2732 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2733 ' if (ret == NULL)\n'
2735 ' return %s%s (ret);\n'
2738 %(i.name, self.ns_upper, i.name_upper))
2740 for i in self.ifaces:
2741 self.c.write(self.docbook_gen.expand(
2743 ' * %sobject_peek_%s: (skip)\n'
2744 ' * @object: A #%sObject.\n'
2746 ' * Like %sobject_get_%s() but doesn\'t increase the reference count on the returned object.\n'
2748 ' * <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'
2750 ' * 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'
2751 %(self.ns_lower, i.name_upper.lower(), self.namespace, self.ns_lower, i.name_upper.lower(), i.camel_name), False))
2752 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2753 self.c.write ('%s *%sobject_peek_%s (%sObject *object)\n'
2754 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2756 ' GDBusInterface *ret;\n'
2757 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2758 ' if (ret == NULL)\n'
2760 ' g_object_unref (ret);\n'
2761 ' return %s%s (ret);\n'
2764 %(i.name, self.ns_upper, i.name_upper))
2766 # shared by ObjectProxy and ObjectSkeleton classes
2767 self.c.write('static void\n'
2768 '%sobject_notify (GDBusObject *object, GDBusInterface *interface)\n'
2770 ' _ExtendedGDBusInterfaceInfo *info = (_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface);\n'
2771 ' /* info can be NULL if the other end is using a D-Bus interface we don\'t know\n'
2772 ' * anything about, for example old generated code in this process talking to\n'
2773 ' * newer generated code in the other process. */\n'
2774 ' if (info != NULL)\n'
2775 ' g_object_notify (G_OBJECT (object), info->hyphen_name);\n'
2780 self.c.write(self.docbook_gen.expand(
2782 ' * %sObjectProxy:\n'
2784 ' * The #%sObjectProxy structure contains only private data and should only be accessed using the provided API.\n'
2785 %(self.namespace, self.namespace), False))
2786 self.c.write(' */\n')
2788 self.c.write(self.docbook_gen.expand(
2790 ' * %sObjectProxyClass:\n'
2791 ' * @parent_class: The parent class.\n'
2793 ' * Class structure for #%sObjectProxy.\n'
2794 %(self.namespace, self.namespace), False))
2795 self.c.write(' */\n')
2798 self.c.write('static void\n'
2799 '%sobject_proxy__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2803 %(self.ns_lower, self.ns_lower, self.namespace))
2804 self.c.write('static void\n'
2805 '%sobject_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2807 ' iface->interface_added = %sobject_notify;\n'
2808 ' iface->interface_removed = %sobject_notify;\n'
2811 %(self.ns_lower, self.ns_lower, self.ns_lower))
2813 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectProxy, %sobject_proxy, G_TYPE_DBUS_OBJECT_PROXY,\n'
2814 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_proxy__%sobject_iface_init)\n'
2815 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_proxy__g_dbus_object_iface_init));\n'
2817 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2819 self.c.write('static void\n'
2820 '%sobject_proxy_init (%sObjectProxy *object G_GNUC_UNUSED)\n'
2823 '\n'%(self.ns_lower, self.namespace))
2824 self.c.write('static void\n'
2825 '%sobject_proxy_set_property (GObject *gobject,\n'
2827 ' const GValue *value G_GNUC_UNUSED,\n'
2828 ' GParamSpec *pspec)\n'
2830 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2834 self.c.write('static void\n'
2835 '%sobject_proxy_get_property (GObject *gobject,\n'
2838 ' GParamSpec *pspec)\n'
2840 ' %sObjectProxy *object = %sOBJECT_PROXY (gobject);\n'
2841 ' GDBusInterface *interface;\n'
2843 ' switch (prop_id)\n'
2845 %(self.ns_lower, self.namespace, self.ns_upper))
2847 for i in self.ifaces:
2848 self.c.write(' case %d:\n'
2849 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2850 ' g_value_take_object (value, interface);\n'
2855 self.c.write(' default:\n'
2856 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2861 self.c.write('static void\n'
2862 '%sobject_proxy_class_init (%sObjectProxyClass *klass)\n'
2864 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2866 ' gobject_class->set_property = %sobject_proxy_set_property;\n'
2867 ' gobject_class->get_property = %sobject_proxy_get_property;\n'
2869 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2871 for i in self.ifaces:
2872 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2874 %(n, i.name_hyphen))
2879 self.c.write(self.docbook_gen.expand(
2881 ' * %sobject_proxy_new:\n'
2882 ' * @connection: A #GDBusConnection.\n'
2883 ' * @object_path: An object path.\n'
2885 ' * Creates a new proxy object.\n'
2887 ' * Returns: (transfer full): The proxy object.\n'
2889 %(self.ns_lower), False))
2890 self.c.write('%sObjectProxy *\n'
2891 '%sobject_proxy_new (GDBusConnection *connection,\n'
2892 ' const gchar *object_path)\n'
2894 ' g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);\n'
2895 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2896 ' return %sOBJECT_PROXY (g_object_new (%sTYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL));\n'
2898 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2900 self.c.write(self.docbook_gen.expand(
2902 ' * %sObjectSkeleton:\n'
2904 ' * The #%sObjectSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2905 %(self.namespace, self.namespace), False))
2906 self.c.write(' */\n')
2908 self.c.write(self.docbook_gen.expand(
2910 ' * %sObjectSkeletonClass:\n'
2911 ' * @parent_class: The parent class.\n'
2913 ' * Class structure for #%sObjectSkeleton.\n'
2914 %(self.namespace, self.namespace), False))
2915 self.c.write(' */\n')
2918 self.c.write('static void\n'
2919 '%sobject_skeleton__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2923 %(self.ns_lower, self.ns_lower, self.namespace))
2925 self.c.write('static void\n'
2926 '%sobject_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2928 ' iface->interface_added = %sobject_notify;\n'
2929 ' iface->interface_removed = %sobject_notify;\n'
2932 %(self.ns_lower, self.ns_lower, self.ns_lower))
2933 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectSkeleton, %sobject_skeleton, G_TYPE_DBUS_OBJECT_SKELETON,\n'
2934 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_skeleton__%sobject_iface_init)\n'
2935 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_skeleton__g_dbus_object_iface_init));\n'
2937 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2939 self.c.write('static void\n'
2940 '%sobject_skeleton_init (%sObjectSkeleton *object G_GNUC_UNUSED)\n'
2943 '\n'%(self.ns_lower, self.namespace))
2944 self.c.write('static void\n'
2945 '%sobject_skeleton_set_property (GObject *gobject,\n'
2947 ' const GValue *value,\n'
2948 ' GParamSpec *pspec)\n'
2950 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2951 ' GDBusInterfaceSkeleton *interface;\n'
2953 ' switch (prop_id)\n'
2955 %(self.ns_lower, self.namespace, self.ns_upper))
2957 for i in self.ifaces:
2958 self.c.write(' case %d:\n'
2959 ' interface = g_value_get_object (value);\n'
2960 ' if (interface != NULL)\n'
2962 ' g_warn_if_fail (%sIS_%s (interface));\n'
2963 ' g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface);\n'
2967 ' g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "%s");\n'
2971 %(n, self.ns_upper, i.name_upper, i.name))
2973 self.c.write(' default:\n'
2974 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2979 self.c.write('static void\n'
2980 '%sobject_skeleton_get_property (GObject *gobject,\n'
2983 ' GParamSpec *pspec)\n'
2985 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2986 ' GDBusInterface *interface;\n'
2988 ' switch (prop_id)\n'
2990 %(self.ns_lower, self.namespace, self.ns_upper))
2992 for i in self.ifaces:
2993 self.c.write(' case %d:\n'
2994 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2995 ' g_value_take_object (value, interface);\n'
3000 self.c.write(' default:\n'
3001 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
3006 self.c.write('static void\n'
3007 '%sobject_skeleton_class_init (%sObjectSkeletonClass *klass)\n'
3009 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
3011 ' gobject_class->set_property = %sobject_skeleton_set_property;\n'
3012 ' gobject_class->get_property = %sobject_skeleton_get_property;\n'
3014 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
3016 for i in self.ifaces:
3017 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
3019 %(n, i.name_hyphen))
3023 self.c.write(self.docbook_gen.expand(
3025 ' * %sobject_skeleton_new:\n'
3026 ' * @object_path: An object path.\n'
3028 ' * Creates a new skeleton object.\n'
3030 ' * Returns: (transfer full): The skeleton object.\n'
3032 %(self.ns_lower), False))
3033 self.c.write('%sObjectSkeleton *\n'
3034 '%sobject_skeleton_new (const gchar *object_path)\n'
3036 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
3037 ' return %sOBJECT_SKELETON (g_object_new (%sTYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL));\n'
3039 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
3040 for i in self.ifaces:
3041 self.c.write(self.docbook_gen.expand(
3043 ' * %sobject_skeleton_set_%s:\n'
3044 ' * @object: A #%sObjectSkeleton.\n'
3045 ' * @interface_: (allow-none): A #%s or %%NULL to clear the interface.\n'
3047 ' * Sets the #%s instance for the D-Bus interface #%s on @object.\n'
3048 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.camel_name, i.name), False))
3049 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
3050 self.c.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_)\n'
3051 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
3053 ' g_object_set (G_OBJECT (object), "%s", interface_, NULL);\n'
3060 def generate_object_manager_client(self):
3061 self.c.write('/* ------------------------------------------------------------------------\n'
3062 ' * Code for ObjectManager client\n'
3063 ' * ------------------------------------------------------------------------\n'
3067 self.c.write(self.docbook_gen.expand(
3069 ' * SECTION:%sObjectManagerClient\n'
3070 ' * @title: %sObjectManagerClient\n'
3071 ' * @short_description: Generated GDBusObjectManagerClient type\n'
3073 ' * This section contains a #GDBusObjectManagerClient that uses %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc.\n'
3075 %(self.namespace, self.namespace, self.ns_lower), False))
3078 self.c.write(self.docbook_gen.expand(
3080 ' * %sObjectManagerClient:\n'
3082 ' * The #%sObjectManagerClient structure contains only private data and should only be accessed using the provided API.\n'
3083 %(self.namespace, self.namespace), False))
3084 self.c.write(' */\n')
3087 self.c.write(self.docbook_gen.expand(
3089 ' * %sObjectManagerClientClass:\n'
3090 ' * @parent_class: The parent class.\n'
3092 ' * Class structure for #%sObjectManagerClient.\n'
3093 %(self.namespace, self.namespace), False))
3094 self.c.write(' */\n')
3098 self.c.write('G_DEFINE_TYPE (%sObjectManagerClient, %sobject_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT);\n'
3100 %(self.namespace, self.ns_lower))
3103 self.c.write('static void\n'
3104 '%sobject_manager_client_init (%sObjectManagerClient *manager G_GNUC_UNUSED)\n'
3107 '\n'%(self.ns_lower, self.namespace))
3108 self.c.write('static void\n'
3109 '%sobject_manager_client_class_init (%sObjectManagerClientClass *klass G_GNUC_UNUSED)\n'
3112 '\n'%(self.ns_lower, self.namespace))
3114 self.c.write(self.docbook_gen.expand(
3116 ' * %sobject_manager_client_get_proxy_type:\n'
3117 ' * @manager: A #GDBusObjectManagerClient.\n'
3118 ' * @object_path: The object path of the remote object (unused).\n'
3119 ' * @interface_name: (allow-none): Interface name of the remote object or %%NULL to get the object proxy #GType.\n'
3120 ' * @user_data: User data (unused).\n'
3122 ' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types.\n'
3124 ' * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %%NULL, otherwise the #GType for #%sObjectProxy.\n'
3125 %(self.ns_lower, self.namespace), False))
3126 self.c.write(' */\n')
3127 self.c.write('GType\n'
3128 '%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'
3131 self.c.write(' static gsize once_init_value = 0;\n'
3132 ' static GHashTable *lookup_hash;\n'
3135 ' if (interface_name == NULL)\n'
3136 ' return %sTYPE_OBJECT_PROXY;\n'
3137 ' if (g_once_init_enter (&once_init_value))\n'
3139 ' lookup_hash = g_hash_table_new (g_str_hash, g_str_equal);\n'
3141 for i in self.ifaces:
3142 self.c.write(' g_hash_table_insert (lookup_hash, (gpointer) "%s", GSIZE_TO_POINTER (%sTYPE_%s_PROXY));\n'
3143 %(i.name, i.ns_upper, i.name_upper))
3144 self.c.write(' g_once_init_leave (&once_init_value, 1);\n'
3146 self.c.write(' ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name));\n'
3147 ' if (ret == (GType) 0)\n'
3148 ' ret = G_TYPE_DBUS_PROXY;\n')
3149 self.c.write(' return ret;\n'
3154 self.c.write(self.docbook_gen.expand(
3156 ' * %sobject_manager_client_new:\n'
3157 ' * @connection: A #GDBusConnection.\n'
3158 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3159 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3160 ' * @object_path: An object path.\n'
3161 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3162 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3163 ' * @user_data: User data to pass to @callback.\n'
3165 ' * Asynchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details.\n'
3167 ' * 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'
3168 ' * You can then call %sobject_manager_client_new_finish() to get the result of the operation.\n'
3170 ' * See %sobject_manager_client_new_sync() for the synchronous, blocking version of this constructor.\n'
3171 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3172 self.c.write(' */\n')
3173 self.c.write('void\n'
3174 '%sobject_manager_client_new (\n'
3175 ' GDBusConnection *connection,\n'
3176 ' GDBusObjectManagerClientFlags flags,\n'
3177 ' const gchar *name,\n'
3178 ' const gchar *object_path,\n'
3179 ' GCancellable *cancellable,\n'
3180 ' GAsyncReadyCallback callback,\n'
3181 ' gpointer user_data)\n'
3183 ' 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'
3186 %(self.ns_lower, self.ns_upper, self.ns_lower))
3187 self.c.write('/**\n'
3188 ' * %sobject_manager_client_new_finish:\n'
3189 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new().\n'
3190 ' * @error: Return location for error or %%NULL\n'
3192 ' * Finishes an operation started with %sobject_manager_client_new().\n'
3194 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3195 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3196 self.c.write(' */\n')
3197 self.c.write('GDBusObjectManager *\n'
3198 '%sobject_manager_client_new_finish (\n'
3199 ' GAsyncResult *res,\n'
3200 ' GError **error)\n'
3203 ' GObject *source_object;\n'
3204 ' source_object = g_async_result_get_source_object (res);\n'
3205 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3206 ' g_object_unref (source_object);\n'
3207 ' if (ret != NULL)\n'
3208 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3214 self.c.write(self.docbook_gen.expand(
3216 ' * %sobject_manager_client_new_sync:\n'
3217 ' * @connection: A #GDBusConnection.\n'
3218 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3219 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3220 ' * @object_path: An object path.\n'
3221 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3222 ' * @error: Return location for error or %%NULL\n'
3224 ' * 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'
3226 ' * The calling thread is blocked until a reply is received.\n'
3228 ' * See %sobject_manager_client_new() for the asynchronous version of this constructor.\n'
3230 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3231 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3232 self.c.write(' */\n')
3233 self.c.write('GDBusObjectManager *\n'
3234 '%sobject_manager_client_new_sync (\n'
3235 ' GDBusConnection *connection,\n'
3236 ' GDBusObjectManagerClientFlags flags,\n'
3237 ' const gchar *name,\n'
3238 ' const gchar *object_path,\n'
3239 ' GCancellable *cancellable,\n'
3240 ' GError **error)\n'
3242 ' GInitable *ret;\n'
3243 ' 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'
3244 ' if (ret != NULL)\n'
3245 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3250 %(self.ns_lower, self.ns_upper, self.ns_lower))
3252 self.c.write(self.docbook_gen.expand(
3254 ' * %sobject_manager_client_new_for_bus:\n'
3255 ' * @bus_type: A #GBusType.\n'
3256 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3257 ' * @name: A bus name (well-known or unique).\n'
3258 ' * @object_path: An object path.\n'
3259 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3260 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3261 ' * @user_data: User data to pass to @callback.\n'
3263 ' * Like %sobject_manager_client_new() but takes a #GBusType instead of a #GDBusConnection.\n'
3265 ' * 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'
3266 ' * You can then call %sobject_manager_client_new_for_bus_finish() to get the result of the operation.\n'
3268 ' * See %sobject_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
3269 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3270 self.c.write(' */\n')
3271 self.c.write('void\n'
3272 '%sobject_manager_client_new_for_bus (\n'
3273 ' GBusType bus_type,\n'
3274 ' GDBusObjectManagerClientFlags flags,\n'
3275 ' const gchar *name,\n'
3276 ' const gchar *object_path,\n'
3277 ' GCancellable *cancellable,\n'
3278 ' GAsyncReadyCallback callback,\n'
3279 ' gpointer user_data)\n'
3281 ' 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'
3284 %(self.ns_lower, self.ns_upper, self.ns_lower))
3285 self.c.write('/**\n'
3286 ' * %sobject_manager_client_new_for_bus_finish:\n'
3287 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new_for_bus().\n'
3288 ' * @error: Return location for error or %%NULL\n'
3290 ' * Finishes an operation started with %sobject_manager_client_new_for_bus().\n'
3292 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3293 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3294 self.c.write(' */\n')
3295 self.c.write('GDBusObjectManager *\n'
3296 '%sobject_manager_client_new_for_bus_finish (\n'
3297 ' GAsyncResult *res,\n'
3298 ' GError **error)\n'
3301 ' GObject *source_object;\n'
3302 ' source_object = g_async_result_get_source_object (res);\n'
3303 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3304 ' g_object_unref (source_object);\n'
3305 ' if (ret != NULL)\n'
3306 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3312 self.c.write(self.docbook_gen.expand(
3314 ' * %sobject_manager_client_new_for_bus_sync:\n'
3315 ' * @bus_type: A #GBusType.\n'
3316 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3317 ' * @name: A bus name (well-known or unique).\n'
3318 ' * @object_path: An object path.\n'
3319 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3320 ' * @error: Return location for error or %%NULL\n'
3322 ' * Like %sobject_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
3324 ' * The calling thread is blocked until a reply is received.\n'
3326 ' * See %sobject_manager_client_new_for_bus() for the asynchronous version of this constructor.\n'
3328 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3329 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3330 self.c.write(' */\n')
3331 self.c.write('GDBusObjectManager *\n'
3332 '%sobject_manager_client_new_for_bus_sync (\n'
3333 ' GBusType bus_type,\n'
3334 ' GDBusObjectManagerClientFlags flags,\n'
3335 ' const gchar *name,\n'
3336 ' const gchar *object_path,\n'
3337 ' GCancellable *cancellable,\n'
3338 ' GError **error)\n'
3340 ' GInitable *ret;\n'
3341 ' 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'
3342 ' if (ret != NULL)\n'
3343 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3348 %(self.ns_lower, self.ns_upper, self.ns_lower))
3351 # ---------------------------------------------------------------------------------------------------
3353 def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
3354 if len(obj.since) > 0:
3357 %(indent, '', indent, '', obj.since))
3359 if isinstance(obj, dbustypes.Interface):
3360 thing = 'The D-Bus interface'
3361 elif isinstance(obj, dbustypes.Method):
3362 thing = 'The D-Bus method'
3363 elif isinstance(obj, dbustypes.Signal):
3364 thing = 'The D-Bus signal'
3365 elif isinstance(obj, dbustypes.Property):
3366 thing = 'The D-Bus property'
3368 raise RuntimeError('Cannot handle object ', obj)
3369 f.write(self.docbook_gen.expand(
3371 '%*s * Deprecated: %s has been deprecated.\n'
3372 %(indent, '', indent, '', thing), False))
3373 f.write('%*s */\n'%(indent, ''))
3375 # ---------------------------------------------------------------------------------------------------
3377 def generate_interface_intro(self, i):
3378 self.c.write('/* ------------------------------------------------------------------------\n'
3379 ' * Code for interface %s\n'
3380 ' * ------------------------------------------------------------------------\n'
3384 self.c.write(self.docbook_gen.expand(
3388 ' * @short_description: Generated C code for the %s D-Bus interface\n'
3390 ' * This section contains code for working with the #%s D-Bus interface in C.\n'
3392 %(i.camel_name, i.camel_name, i.name, i.name), False))
3396 self.generate_intro()
3397 self.declare_types()
3398 for i in self.ifaces:
3399 self.generate_interface_intro(i)
3400 self.generate_introspection_for_interface(i)
3401 self.generate_interface(i)
3402 self.generate_property_accessors(i)
3403 self.generate_signal_emitters(i)
3404 self.generate_method_calls(i)
3405 self.generate_method_completers(i)
3406 self.generate_proxy(i)
3407 self.generate_skeleton(i)
3408 if self.generate_objmanager:
3409 self.generate_object()
3410 self.generate_object_manager_client()
3412 self.generate_outro()