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, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA 02111-1307, USA.
22 # Author: David Zeuthen <davidz@redhat.com>
28 from . import dbustypes
30 # ----------------------------------------------------------------------------------------------------
33 def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, docbook_gen, h, c):
34 self.docbook_gen = docbook_gen
35 self.generate_objmanager = generate_objmanager
39 self.namespace = namespace
40 if len(namespace) > 0:
41 if utils.is_ugly_case(namespace):
42 self.namespace = namespace.replace('_', '')
43 self.ns_upper = namespace.upper() + '_'
44 self.ns_lower = namespace.lower() + '_'
46 self.ns_upper = utils.camel_case_to_uscore(namespace).upper() + '_'
47 self.ns_lower = utils.camel_case_to_uscore(namespace).lower() + '_'
51 self.interface_prefix = interface_prefix
52 self.header_guard = self.h.name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
54 # ----------------------------------------------------------------------------------------------------
56 def generate_intro(self):
58 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
60 ' * The license of this code is the same as for the source it was derived from.\n'
64 self.c.write('#ifdef HAVE_CONFIG_H\n'
65 '# include "config.h"\n'
70 '#include <string.h>\n'
73 self.c.write('#ifdef G_OS_UNIX\n'
74 '# include <gio/gunixfdlist.h>\n'
78 self.c.write('typedef struct\n'
80 ' GDBusArgInfo parent_struct;\n'
81 ' gboolean use_gvariant;\n'
82 '} _ExtendedGDBusArgInfo;\n'
85 self.c.write('typedef struct\n'
87 ' GDBusMethodInfo parent_struct;\n'
88 ' const gchar *signal_name;\n'
89 ' gboolean pass_fdlist;\n'
90 '} _ExtendedGDBusMethodInfo;\n'
93 self.c.write('typedef struct\n'
95 ' GDBusSignalInfo parent_struct;\n'
96 ' const gchar *signal_name;\n'
97 '} _ExtendedGDBusSignalInfo;\n'
100 self.c.write('typedef struct\n'
102 ' GDBusPropertyInfo parent_struct;\n'
103 ' const gchar *hyphen_name;\n'
104 ' gboolean use_gvariant;\n'
105 '} _ExtendedGDBusPropertyInfo;\n'
108 self.c.write('typedef struct\n'
110 ' GDBusInterfaceInfo parent_struct;\n'
111 ' const gchar *hyphen_name;\n'
112 '} _ExtendedGDBusInterfaceInfo;\n'
115 self.c.write('typedef struct\n'
117 ' const _ExtendedGDBusPropertyInfo *info;\n'
119 ' GValue orig_value; /* the value before the change */\n'
120 '} ChangedProperty;\n'
123 '_changed_property_free (ChangedProperty *data)\n'
125 ' g_value_unset (&data->orig_value);\n'
130 self.c.write('static gboolean\n'
131 '_g_strv_equal0 (gchar **a, gchar **b)\n'
133 ' gboolean ret = FALSE;\n'
135 ' if (a == NULL && b == NULL)\n'
140 ' if (a == NULL || b == NULL)\n'
142 ' if (g_strv_length (a) != g_strv_length (b))\n'
144 ' for (n = 0; a[n] != NULL; n++)\n'
145 ' if (g_strcmp0 (a[n], b[n]) != 0)\n'
153 self.c.write('static gboolean\n'
154 '_g_variant_equal0 (GVariant *a, GVariant *b)\n'
156 ' gboolean ret = FALSE;\n'
157 ' if (a == NULL && b == NULL)\n'
162 ' if (a == NULL || b == NULL)\n'
164 ' ret = g_variant_equal (a, b);\n'
170 # simplified - only supports the types we use
171 self.c.write('G_GNUC_UNUSED static gboolean\n'
172 '_g_value_equal (const GValue *a, const GValue *b)\n'
174 ' gboolean ret = FALSE;\n'
175 ' g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b));\n'
176 ' switch (G_VALUE_TYPE (a))\n'
178 ' case G_TYPE_BOOLEAN:\n'
179 ' ret = (g_value_get_boolean (a) == g_value_get_boolean (b));\n'
181 ' case G_TYPE_UCHAR:\n'
182 ' ret = (g_value_get_uchar (a) == g_value_get_uchar (b));\n'
184 ' case G_TYPE_INT:\n'
185 ' ret = (g_value_get_int (a) == g_value_get_int (b));\n'
187 ' case G_TYPE_UINT:\n'
188 ' ret = (g_value_get_uint (a) == g_value_get_uint (b));\n'
190 ' case G_TYPE_INT64:\n'
191 ' ret = (g_value_get_int64 (a) == g_value_get_int64 (b));\n'
193 ' case G_TYPE_UINT64:\n'
194 ' ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n'
196 ' case G_TYPE_DOUBLE:\n'
198 ' /* Avoid -Wfloat-equal warnings by doing a direct bit compare */\n'
199 ' gdouble da = g_value_get_double (a);\n'
200 ' gdouble db = g_value_get_double (b);\n'
201 ' ret = memcmp (&da, &db, sizeof (gdouble)) == 0;\n'
204 ' case G_TYPE_STRING:\n'
205 ' ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n'
207 ' case G_TYPE_VARIANT:\n'
208 ' ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b));\n'
211 ' if (G_VALUE_TYPE (a) == G_TYPE_STRV)\n'
212 ' ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b));\n'
214 ' g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a)));\n'
222 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
224 ' * The license of this code is the same as for the source it was derived from.\n'
229 '\n'%(config.VERSION, self.header_guard, self.header_guard))
230 self.h.write('#include <gio/gio.h>\n'
235 # ----------------------------------------------------------------------------------------------------
237 def declare_types(self):
238 for i in self.ifaces:
240 self.h.write('/* ------------------------------------------------------------------------ */\n')
241 self.h.write('/* Declarations for %s */\n'%i.name)
244 # First the GInterface
245 self.h.write('#define %sTYPE_%s (%s_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
246 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))
247 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))
248 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))
250 self.h.write('struct _%s;\n'%(i.camel_name))
251 self.h.write('typedef struct _%s %s;\n'%(i.camel_name, i.camel_name))
252 self.h.write('typedef struct _%sIface %sIface;\n'%(i.camel_name, i.camel_name))
254 self.h.write('struct _%sIface\n'%(i.camel_name))
256 self.h.write(' GTypeInterface parent_iface;\n')
258 function_pointers = {}
261 if len(i.methods) > 0:
265 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
267 key = (m.since, '_method_%s'%m.name_lower)
268 value = ' gboolean (*handle_%s) (\n'%(m.name_lower)
269 value += ' %s *object,\n'%(i.camel_name)
270 value += ' GDBusMethodInvocation *invocation'%()
272 value += ',\n GUnixFDList *fd_list'
274 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
276 function_pointers[key] = value
279 if len(i.signals) > 0:
282 key = (s.since, '_signal_%s'%s.name_lower)
283 value = ' void (*%s) (\n'%(s.name_lower)
284 value += ' %s *object'%(i.camel_name)
286 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
288 function_pointers[key] = value
290 # vfuncs for properties
291 if len(i.properties) > 0:
293 for p in i.properties:
294 key = (p.since, '_prop_get_%s'%p.name_lower)
295 value = ' %s (*get_%s) (%s *object);\n\n'%(p.arg.ctype_in, p.name_lower, i.camel_name)
296 function_pointers[key] = value
298 # Sort according to @since tag, then name.. this ensures
299 # that the function pointers don't change order assuming
300 # judicious use of @since
302 # Also use a proper version comparison function so e.g.
303 # 10.0 comes after 2.0.
305 # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
307 keys = function_pointers.keys()
309 keys.sort(cmp=utils.my_version_cmp)
311 self.h.write('%s'%function_pointers[key])
315 self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
317 self.h.write('GDBusInterfaceInfo *%s_interface_info (void);\n'%(i.name_lower))
318 self.h.write('guint %s_override_properties (GObjectClass *klass, guint property_id_begin);\n'%(i.name_lower))
321 # Then method call completion functions
322 if len(i.methods) > 0:
324 self.h.write('/* D-Bus method call completion functions: */\n')
327 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
330 self.h.write('G_GNUC_DEPRECATED ')
331 self.h.write('void %s_complete_%s (\n'
333 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
335 self.h.write(',\n GUnixFDList *fd_list')
337 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
342 # Then signal emission functions
343 if len(i.signals) > 0:
345 self.h.write('/* D-Bus signal emissions functions: */\n')
348 self.h.write('G_GNUC_DEPRECATED ')
349 self.h.write('void %s_emit_%s (\n'
350 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
352 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
357 # Then method call declarations
358 if len(i.methods) > 0:
360 self.h.write('/* D-Bus method calls: */\n')
363 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
367 self.h.write('G_GNUC_DEPRECATED ')
368 self.h.write('void %s_call_%s (\n'
369 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
371 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
373 self.h.write(',\n GUnixFDList *fd_list')
375 ' GCancellable *cancellable,\n'
376 ' GAsyncReadyCallback callback,\n'
377 ' gpointer user_data);\n')
381 self.h.write('G_GNUC_DEPRECATED ')
382 self.h.write('gboolean %s_call_%s_finish (\n'
383 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
385 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
387 self.h.write(',\n GUnixFDList **out_fd_list')
389 ' GAsyncResult *res,\n'
390 ' GError **error);\n')
394 self.h.write('G_GNUC_DEPRECATED ')
395 self.h.write('gboolean %s_call_%s_sync (\n'
396 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
398 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
400 self.h.write(',\n GUnixFDList *fd_list')
402 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
404 self.h.write(',\n GUnixFDList **out_fd_list')
406 ' GCancellable *cancellable,\n'
407 ' GError **error);\n')
411 # Then the property accessor declarations
412 if len(i.properties) > 0:
414 self.h.write('/* D-Bus property accessors: */\n')
415 for p in i.properties:
418 self.h.write('G_GNUC_DEPRECATED ')
419 self.h.write('%s%s_get_%s (%s *object);\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
420 if p.arg.free_func != None:
422 self.h.write('G_GNUC_DEPRECATED ')
423 self.h.write('%s%s_dup_%s (%s *object);\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name))
426 self.h.write('G_GNUC_DEPRECATED ')
427 self.h.write('void %s_set_%s (%s *object, %svalue);\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
432 self.h.write('/* ---- */\n')
434 self.h.write('#define %sTYPE_%s_PROXY (%s_proxy_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
435 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))
436 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))
437 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))
438 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))
439 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))
441 self.h.write('typedef struct _%sProxy %sProxy;\n'%(i.camel_name, i.camel_name))
442 self.h.write('typedef struct _%sProxyClass %sProxyClass;\n'%(i.camel_name, i.camel_name))
443 self.h.write('typedef struct _%sProxyPrivate %sProxyPrivate;\n'%(i.camel_name, i.camel_name))
445 self.h.write('struct _%sProxy\n'%(i.camel_name))
447 self.h.write(' /*< private >*/\n')
448 self.h.write(' GDBusProxy parent_instance;\n')
449 self.h.write(' %sProxyPrivate *priv;\n'%(i.camel_name))
452 self.h.write('struct _%sProxyClass\n'%(i.camel_name))
454 self.h.write(' GDBusProxyClass parent_class;\n')
457 self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
461 self.h.write('G_GNUC_DEPRECATED ')
462 self.h.write('void %s_proxy_new (\n'
463 ' GDBusConnection *connection,\n'
464 ' GDBusProxyFlags flags,\n'
465 ' const gchar *name,\n'
466 ' const gchar *object_path,\n'
467 ' GCancellable *cancellable,\n'
468 ' GAsyncReadyCallback callback,\n'
469 ' gpointer user_data);\n'
472 self.h.write('G_GNUC_DEPRECATED ')
473 self.h.write('%s *%s_proxy_new_finish (\n'
474 ' GAsyncResult *res,\n'
475 ' GError **error);\n'
476 %(i.camel_name, i.name_lower))
478 self.h.write('G_GNUC_DEPRECATED ')
479 self.h.write('%s *%s_proxy_new_sync (\n'
480 ' GDBusConnection *connection,\n'
481 ' GDBusProxyFlags flags,\n'
482 ' const gchar *name,\n'
483 ' const gchar *object_path,\n'
484 ' GCancellable *cancellable,\n'
485 ' GError **error);\n'
486 %(i.camel_name, i.name_lower))
489 self.h.write('G_GNUC_DEPRECATED ')
490 self.h.write('void %s_proxy_new_for_bus (\n'
491 ' GBusType bus_type,\n'
492 ' GDBusProxyFlags flags,\n'
493 ' const gchar *name,\n'
494 ' const gchar *object_path,\n'
495 ' GCancellable *cancellable,\n'
496 ' GAsyncReadyCallback callback,\n'
497 ' gpointer user_data);\n'
500 self.h.write('G_GNUC_DEPRECATED ')
501 self.h.write('%s *%s_proxy_new_for_bus_finish (\n'
502 ' GAsyncResult *res,\n'
503 ' GError **error);\n'
504 %(i.camel_name, i.name_lower))
506 self.h.write('G_GNUC_DEPRECATED ')
507 self.h.write('%s *%s_proxy_new_for_bus_sync (\n'
508 ' GBusType bus_type,\n'
509 ' GDBusProxyFlags flags,\n'
510 ' const gchar *name,\n'
511 ' const gchar *object_path,\n'
512 ' GCancellable *cancellable,\n'
513 ' GError **error);\n'
514 %(i.camel_name, i.name_lower))
519 self.h.write('/* ---- */\n')
521 self.h.write('#define %sTYPE_%s_SKELETON (%s_skeleton_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
522 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))
523 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))
524 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))
525 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))
526 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))
528 self.h.write('typedef struct _%sSkeleton %sSkeleton;\n'%(i.camel_name, i.camel_name))
529 self.h.write('typedef struct _%sSkeletonClass %sSkeletonClass;\n'%(i.camel_name, i.camel_name))
530 self.h.write('typedef struct _%sSkeletonPrivate %sSkeletonPrivate;\n'%(i.camel_name, i.camel_name))
532 self.h.write('struct _%sSkeleton\n'%(i.camel_name))
534 self.h.write(' /*< private >*/\n')
535 self.h.write(' GDBusInterfaceSkeleton parent_instance;\n')
536 self.h.write(' %sSkeletonPrivate *priv;\n'%(i.camel_name))
539 self.h.write('struct _%sSkeletonClass\n'%(i.camel_name))
541 self.h.write(' GDBusInterfaceSkeletonClass parent_class;\n')
544 self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
547 self.h.write('G_GNUC_DEPRECATED ')
548 self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
552 # Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
553 if self.generate_objmanager:
555 self.h.write('/* ---- */\n')
557 self.h.write('#define %sTYPE_OBJECT (%sobject_get_type ())\n'%(self.ns_upper, self.ns_lower))
558 self.h.write('#define %sOBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
559 self.h.write('#define %sIS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT))\n'%(self.ns_upper, self.ns_upper))
560 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))
562 self.h.write('struct _%sObject;\n'%(self.namespace))
563 self.h.write('typedef struct _%sObject %sObject;\n'%(self.namespace, self.namespace))
564 self.h.write('typedef struct _%sObjectIface %sObjectIface;\n'%(self.namespace, self.namespace))
566 self.h.write('struct _%sObjectIface\n'%(self.namespace))
568 ' GTypeInterface parent_iface;\n'
571 self.h.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
574 for i in self.ifaces:
576 self.h.write('G_GNUC_DEPRECATED ')
577 self.h.write ('%s *%sobject_get_%s (%sObject *object);\n'
578 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
579 for i in self.ifaces:
581 self.h.write('G_GNUC_DEPRECATED ')
582 self.h.write ('%s *%sobject_peek_%s (%sObject *object);\n'
583 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
585 self.h.write('#define %sTYPE_OBJECT_PROXY (%sobject_proxy_get_type ())\n'%(self.ns_upper, self.ns_lower))
586 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))
587 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))
588 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))
589 self.h.write('#define %sIS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
590 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))
592 self.h.write('typedef struct _%sObjectProxy %sObjectProxy;\n'%(self.namespace, self.namespace))
593 self.h.write('typedef struct _%sObjectProxyClass %sObjectProxyClass;\n'%(self.namespace, self.namespace))
594 self.h.write('typedef struct _%sObjectProxyPrivate %sObjectProxyPrivate;\n'%(self.namespace, self.namespace))
596 self.h.write('struct _%sObjectProxy\n'%(self.namespace))
598 self.h.write(' /*< private >*/\n')
599 self.h.write(' GDBusObjectProxy parent_instance;\n')
600 self.h.write(' %sObjectProxyPrivate *priv;\n'%(self.namespace))
603 self.h.write('struct _%sObjectProxyClass\n'%(self.namespace))
605 self.h.write(' GDBusObjectProxyClass parent_class;\n')
608 self.h.write('GType %sobject_proxy_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
609 self.h.write('%sObjectProxy *%sobject_proxy_new (GDBusConnection *connection, const gchar *object_path);\n'%(self.namespace, self.ns_lower))
611 self.h.write('#define %sTYPE_OBJECT_SKELETON (%sobject_skeleton_get_type ())\n'%(self.ns_upper, self.ns_lower))
612 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))
613 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))
614 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))
615 self.h.write('#define %sIS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
616 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))
618 self.h.write('typedef struct _%sObjectSkeleton %sObjectSkeleton;\n'%(self.namespace, self.namespace))
619 self.h.write('typedef struct _%sObjectSkeletonClass %sObjectSkeletonClass;\n'%(self.namespace, self.namespace))
620 self.h.write('typedef struct _%sObjectSkeletonPrivate %sObjectSkeletonPrivate;\n'%(self.namespace, self.namespace))
622 self.h.write('struct _%sObjectSkeleton\n'%(self.namespace))
624 self.h.write(' /*< private >*/\n')
625 self.h.write(' GDBusObjectSkeleton parent_instance;\n')
626 self.h.write(' %sObjectSkeletonPrivate *priv;\n'%(self.namespace))
629 self.h.write('struct _%sObjectSkeletonClass\n'%(self.namespace))
631 self.h.write(' GDBusObjectSkeletonClass parent_class;\n')
634 self.h.write('GType %sobject_skeleton_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
635 self.h.write('%sObjectSkeleton *%sobject_skeleton_new (const gchar *object_path);\n'
636 %(self.namespace, self.ns_lower))
637 for i in self.ifaces:
639 self.h.write('G_GNUC_DEPRECATED ')
640 self.h.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_);\n'
641 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
644 self.h.write('/* ---- */\n')
646 self.h.write('#define %sTYPE_OBJECT_MANAGER_CLIENT (%sobject_manager_client_get_type ())\n'%(self.ns_upper, self.ns_lower))
647 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))
648 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))
649 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))
650 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))
651 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))
653 self.h.write('typedef struct _%sObjectManagerClient %sObjectManagerClient;\n'%(self.namespace, self.namespace))
654 self.h.write('typedef struct _%sObjectManagerClientClass %sObjectManagerClientClass;\n'%(self.namespace, self.namespace))
655 self.h.write('typedef struct _%sObjectManagerClientPrivate %sObjectManagerClientPrivate;\n'%(self.namespace, self.namespace))
657 self.h.write('struct _%sObjectManagerClient\n'%(self.namespace))
659 self.h.write(' /*< private >*/\n')
660 self.h.write(' GDBusObjectManagerClient parent_instance;\n')
661 self.h.write(' %sObjectManagerClientPrivate *priv;\n'%(self.namespace))
664 self.h.write('struct _%sObjectManagerClientClass\n'%(self.namespace))
666 self.h.write(' GDBusObjectManagerClientClass parent_class;\n')
669 self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
671 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))
673 self.h.write('void %sobject_manager_client_new (\n'
674 ' GDBusConnection *connection,\n'
675 ' GDBusObjectManagerClientFlags flags,\n'
676 ' const gchar *name,\n'
677 ' const gchar *object_path,\n'
678 ' GCancellable *cancellable,\n'
679 ' GAsyncReadyCallback callback,\n'
680 ' gpointer user_data);\n'
682 self.h.write('GDBusObjectManager *%sobject_manager_client_new_finish (\n'
683 ' GAsyncResult *res,\n'
684 ' GError **error);\n'
686 self.h.write('GDBusObjectManager *%sobject_manager_client_new_sync (\n'
687 ' GDBusConnection *connection,\n'
688 ' GDBusObjectManagerClientFlags flags,\n'
689 ' const gchar *name,\n'
690 ' const gchar *object_path,\n'
691 ' GCancellable *cancellable,\n'
692 ' GError **error);\n'
695 self.h.write('void %sobject_manager_client_new_for_bus (\n'
696 ' GBusType bus_type,\n'
697 ' GDBusObjectManagerClientFlags flags,\n'
698 ' const gchar *name,\n'
699 ' const gchar *object_path,\n'
700 ' GCancellable *cancellable,\n'
701 ' GAsyncReadyCallback callback,\n'
702 ' gpointer user_data);\n'
704 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_finish (\n'
705 ' GAsyncResult *res,\n'
706 ' GError **error);\n'
708 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_sync (\n'
709 ' GBusType bus_type,\n'
710 ' GDBusObjectManagerClientFlags flags,\n'
711 ' const gchar *name,\n'
712 ' const gchar *object_path,\n'
713 ' GCancellable *cancellable,\n'
714 ' GError **error);\n'
718 # ----------------------------------------------------------------------------------------------------
720 def generate_outro(self):
724 '#endif /* __%s__ */\n'%(self.header_guard))
726 # ----------------------------------------------------------------------------------------------------
728 def generate_annotations(self, prefix, annotations):
729 if annotations == None:
733 for a in annotations:
734 #self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
736 # skip internal annotations
737 if a.key.startswith('org.gtk.GDBus'):
740 self.c.write('static const GDBusAnnotationInfo %s_%d =\n'
744 ' (gchar *) "%s",\n'%(prefix, n, a.key, a.value))
745 if len(a.annotations) == 0:
746 self.c.write(' NULL\n')
748 self.c.write(' (GDBusAnnotationInfo **) &%s_%d_pointers\n'%(prefix, n))
754 self.c.write('static const GDBusAnnotationInfo * const %s_pointers[] =\n'
757 for a in annotations:
758 if a.key.startswith('org.gtk.GDBus'):
760 self.c.write(' &%s_%d,\n'%(prefix, m))
762 self.c.write(' NULL\n'
767 def generate_args(self, prefix, args):
769 num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
771 self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
776 ' (gchar *) "%s",\n'%(prefix, a.name, a.name, a.signature))
778 self.c.write(' NULL\n')
780 self.c.write(' (GDBusAnnotationInfo **) &%s_arg_%s_annotation_info_pointers\n'%(prefix, a.name))
781 self.c.write(' },\n')
782 if not utils.lookup_annotation(a.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
783 self.c.write(' FALSE\n')
785 self.c.write(' TRUE\n')
790 self.c.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
793 self.c.write(' &%s_%s,\n'%(prefix, a.name))
794 self.c.write(' NULL\n'
798 def generate_introspection_for_interface(self, i):
799 self.c.write('/* ---- Introspection data for %s ---- */\n'
802 if len(i.methods) > 0:
805 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
807 self.generate_args('_%s_method_info_%s_IN_ARG'%(i.name_lower, m.name_lower), m.in_args)
808 self.generate_args('_%s_method_info_%s_OUT_ARG'%(i.name_lower, m.name_lower), m.out_args)
810 num_anno = self.generate_annotations('_%s_method_%s_annotation_info'%(i.name_lower, m.name_lower), m.annotations)
812 self.c.write('static const _ExtendedGDBusMethodInfo _%s_method_info_%s =\n'
816 ' (gchar *) "%s",\n'%(i.name_lower, m.name_lower, m.name))
817 if len(m.in_args) == 0:
818 self.c.write(' NULL,\n')
820 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_IN_ARG_pointers,\n'%(i.name_lower, m.name_lower))
821 if len(m.out_args) == 0:
822 self.c.write(' NULL,\n')
824 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_OUT_ARG_pointers,\n'%(i.name_lower, m.name_lower))
826 self.c.write(' NULL\n')
828 self.c.write(' (GDBusAnnotationInfo **) &_%s_method_%s_annotation_info_pointers\n'%(i.name_lower, m.name_lower))
832 %(m.name_hyphen, 'TRUE' if unix_fd else 'FALSE'))
836 self.c.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] =\n'
837 '{\n'%(i.name_lower))
839 self.c.write(' &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
840 self.c.write(' NULL\n'
846 if len(i.signals) > 0:
848 self.generate_args('_%s_signal_info_%s_ARG'%(i.name_lower, s.name_lower), s.args)
850 num_anno = self.generate_annotations('_%s_signal_%s_annotation_info'%(i.name_lower, s.name_lower), s.annotations)
851 self.c.write('static const _ExtendedGDBusSignalInfo _%s_signal_info_%s =\n'
855 ' (gchar *) "%s",\n'%(i.name_lower, s.name_lower, s.name))
857 self.c.write(' NULL,\n')
859 self.c.write(' (GDBusArgInfo **) &_%s_signal_info_%s_ARG_pointers,\n'%(i.name_lower, s.name_lower))
861 self.c.write(' NULL\n')
863 self.c.write(' (GDBusAnnotationInfo **) &_%s_signal_%s_annotation_info_pointers\n'%(i.name_lower, s.name_lower))
870 self.c.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
871 '{\n'%(i.name_lower))
873 self.c.write(' &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
874 self.c.write(' NULL\n'
880 if len(i.properties) > 0:
881 for p in i.properties:
882 if p.readable and p.writable:
883 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
885 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE'
887 access = 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
889 access = 'G_DBUS_PROPERTY_INFO_FLAGS_NONE'
890 num_anno = self.generate_annotations('_%s_property_%s_annotation_info'%(i.name_lower, p.name_lower), p.annotations)
891 self.c.write('static const _ExtendedGDBusPropertyInfo _%s_property_info_%s =\n'
897 ' %s,\n'%(i.name_lower, p.name_lower, p.name, p.arg.signature, access))
899 self.c.write(' NULL\n')
901 self.c.write(' (GDBusAnnotationInfo **) &_%s_property_%s_annotation_info_pointers\n'%(i.name_lower, p.name_lower))
905 if not utils.lookup_annotation(p.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
906 self.c.write(' FALSE\n')
908 self.c.write(' TRUE\n')
912 self.c.write('static const _ExtendedGDBusPropertyInfo * const _%s_property_info_pointers[] =\n'
913 '{\n'%(i.name_lower))
914 for p in i.properties:
915 self.c.write(' &_%s_property_info_%s,\n'%(i.name_lower, p.name_lower))
916 self.c.write(' NULL\n'
920 num_anno = self.generate_annotations('_%s_annotation_info'%(i.name_lower), i.annotations)
921 self.c.write('static const _ExtendedGDBusInterfaceInfo _%s_interface_info =\n'
925 ' (gchar *) "%s",\n'%(i.name_lower, i.name))
926 if len(i.methods) == 0:
927 self.c.write(' NULL,\n')
929 self.c.write(' (GDBusMethodInfo **) &_%s_method_info_pointers,\n'%(i.name_lower))
930 if len(i.signals) == 0:
931 self.c.write(' NULL,\n')
933 self.c.write(' (GDBusSignalInfo **) &_%s_signal_info_pointers,\n'%(i.name_lower))
934 if len(i.properties) == 0:
935 self.c.write(' NULL,\n')
937 self.c.write(' (GDBusPropertyInfo **) &_%s_property_info_pointers,\n'%(i.name_lower))
939 self.c.write(' NULL\n')
941 self.c.write(' (GDBusAnnotationInfo **) &_%s_annotation_info_pointers\n'%(i.name_lower))
948 self.c.write(self.docbook_gen.expand(
950 ' * %s_interface_info:\n'
952 ' * Gets a machine-readable description of the #%s D-Bus interface.\n'
954 ' * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free.\n'
955 %(i.name_lower, i.name), False))
956 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
957 self.c.write('GDBusInterfaceInfo *\n'
958 '%s_interface_info (void)\n'
960 ' return (GDBusInterfaceInfo *) &_%s_interface_info;\n'
962 '\n'%(i.name_lower, i.name_lower))
964 self.c.write(self.docbook_gen.expand(
966 ' * %s_override_properties:\n'
967 ' * @klass: The class structure for a #GObject<!-- -->-derived class.\n'
968 ' * @property_id_begin: The property id to assign to the first overridden property.\n'
970 ' * Overrides all #GObject properties in the #%s interface for a concrete class.\n'
971 ' * The properties are overridden in the order they are defined.\n'
973 ' * Returns: The last property id.\n'
974 %(i.name_lower, i.camel_name), False))
975 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
976 self.c.write('guint\n'
977 '%s_override_properties (GObjectClass *klass, guint property_id_begin)\n'
978 '{\n'%(i.name_lower))
979 for p in i.properties:
980 self.c.write (' g_object_class_override_property (klass, property_id_begin++, "%s");\n'%(p.name_hyphen))
981 self.c.write(' return property_id_begin - 1;\n'
986 # ----------------------------------------------------------------------------------------------------
988 def generate_interface(self, i):
991 self.c.write(self.docbook_gen.expand(
995 ' * Abstract interface type for the D-Bus interface #%s.\n'
996 %(i.camel_name, i.name), False))
997 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1000 self.c.write(self.docbook_gen.expand(
1003 ' * @parent_iface: The parent interface.\n'
1004 %(i.camel_name), False))
1007 if len(i.methods) > 0:
1009 key = (m.since, '_method_%s'%m.name_lower)
1010 value = '@handle_%s: '%(m.name_lower)
1011 value += 'Handler for the #%s::handle-%s signal.'%(i.camel_name, m.name_hyphen)
1012 doc_bits[key] = value
1013 if len(i.signals) > 0:
1015 key = (s.since, '_signal_%s'%s.name_lower)
1016 value = '@%s: '%(s.name_lower)
1017 value += 'Handler for the #%s::%s signal.'%(i.camel_name, s.name_hyphen)
1018 doc_bits[key] = value
1019 if len(i.properties) > 0:
1020 for p in i.properties:
1021 key = (p.since, '_prop_get_%s'%p.name_lower)
1022 value = '@get_%s: '%(p.name_lower)
1023 value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
1024 doc_bits[key] = value
1025 keys = doc_bits.keys()
1027 keys.sort(cmp=utils.my_version_cmp)
1029 self.c.write(' * %s\n'%doc_bits[key])
1030 self.c.write(self.docbook_gen.expand(
1032 ' * Virtual table for the D-Bus interface #%s.\n'
1034 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1037 self.c.write('static void\n'
1038 '%s_default_init (%sIface *iface)\n'
1039 '{\n'%(i.name_lower, i.camel_name));
1041 if len(i.methods) > 0:
1042 self.c.write(' /* GObject signals for incoming D-Bus method calls: */\n')
1045 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1047 self.c.write(self.docbook_gen.expand(
1049 ' * %s::handle-%s:\n'
1050 ' * @object: A #%s.\n'
1051 ' * @invocation: A #GDBusMethodInvocation.\n'
1052 %(i.camel_name, m.name_hyphen, i.camel_name), False))
1054 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1056 self.c.write (' * @arg_%s: Argument passed by remote caller.\n'%(a.name))
1057 self.c.write(self.docbook_gen.expand(
1059 ' * Signal emitted when a remote caller is invoking the %s.%s() D-Bus method.\n'
1061 ' * 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'
1063 ' * Returns: %%TRUE if the invocation was handled, %%FALSE to let other signal handlers run.\n'
1064 %(i.name, m.name, i.name_lower, m.name_lower), False))
1065 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 2)
1070 self.c.write(' g_signal_new ("handle-%s",\n'
1071 ' G_TYPE_FROM_INTERFACE (iface),\n'
1072 ' G_SIGNAL_RUN_LAST,\n'
1073 ' G_STRUCT_OFFSET (%sIface, handle_%s),\n'
1074 ' g_signal_accumulator_true_handled,\n'
1075 ' NULL,\n' # accu_data
1076 ' g_cclosure_marshal_generic,\n'
1077 ' G_TYPE_BOOLEAN,\n'
1079 ' G_TYPE_DBUS_METHOD_INVOCATION'
1080 %(m.name_hyphen, i.camel_name, m.name_lower, len(m.in_args) + extra_args))
1082 self.c.write(', G_TYPE_UNIX_FD_LIST')
1084 self.c.write (', %s'%(a.gtype))
1085 self.c.write(');\n')
1088 if len(i.signals) > 0:
1089 self.c.write(' /* GObject signals for received D-Bus signals: */\n')
1091 self.c.write(self.docbook_gen.expand(
1094 ' * @object: A #%s.\n'
1095 %(i.camel_name, s.name_hyphen, i.camel_name), False))
1097 self.c.write (' * @arg_%s: Argument.\n'%(a.name))
1098 self.c.write(self.docbook_gen.expand(
1100 ' * On the client-side, this signal is emitted whenever the D-Bus signal #%s::%s is received.\n'
1102 ' * 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'
1103 %(i.name, s.name), False))
1104 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 2)
1105 self.c.write(' g_signal_new ("%s",\n'
1106 ' G_TYPE_FROM_INTERFACE (iface),\n'
1107 ' G_SIGNAL_RUN_LAST,\n'
1108 ' G_STRUCT_OFFSET (%sIface, %s),\n'
1109 ' NULL,\n' # accumulator
1110 ' NULL,\n' # accu_data
1111 ' g_cclosure_marshal_generic,\n'
1114 %(s.name_hyphen, i.camel_name, s.name_lower, len(s.args)))
1116 self.c.write (', %s'%(a.gtype))
1117 self.c.write(');\n')
1120 if len(i.properties) > 0:
1121 self.c.write(' /* GObject properties for D-Bus properties: */\n')
1122 for p in i.properties:
1123 if p.readable and p.writable:
1124 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.'
1126 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.'
1128 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.'
1130 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1131 self.c.write(self.docbook_gen.expand(
1135 ' * Represents the D-Bus property #%s:%s.\n'
1138 %(i.camel_name, p.name_hyphen, i.name, p.name, hint), False))
1139 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 2)
1140 self.c.write(' g_object_interface_install_property (iface,\n')
1141 if p.arg.gtype == 'G_TYPE_VARIANT':
1142 s = 'g_param_spec_variant ("%s", "%s", "%s", G_VARIANT_TYPE ("%s"), NULL'%(p.name_hyphen, p.name, p.name, p.arg.signature)
1143 elif p.arg.signature == 'b':
1144 s = 'g_param_spec_boolean ("%s", "%s", "%s", FALSE'%(p.name_hyphen, p.name, p.name)
1145 elif p.arg.signature == 'y':
1146 s = 'g_param_spec_uchar ("%s", "%s", "%s", 0, 255, 0'%(p.name_hyphen, p.name, p.name)
1147 elif p.arg.signature == 'n':
1148 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT16, G_MAXINT16, 0'%(p.name_hyphen, p.name, p.name)
1149 elif p.arg.signature == 'q':
1150 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT16, 0'%(p.name_hyphen, p.name, p.name)
1151 elif p.arg.signature == 'i':
1152 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT32, G_MAXINT32, 0'%(p.name_hyphen, p.name, p.name)
1153 elif p.arg.signature == 'u':
1154 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT32, 0'%(p.name_hyphen, p.name, p.name)
1155 elif p.arg.signature == 'x':
1156 s = 'g_param_spec_int64 ("%s", "%s", "%s", G_MININT64, G_MAXINT64, 0'%(p.name_hyphen, p.name, p.name)
1157 elif p.arg.signature == 't':
1158 s = 'g_param_spec_uint64 ("%s", "%s", "%s", 0, G_MAXUINT64, 0'%(p.name_hyphen, p.name, p.name)
1159 elif p.arg.signature == 'd':
1160 s = 'g_param_spec_double ("%s", "%s", "%s", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0'%(p.name_hyphen, p.name, p.name)
1161 elif p.arg.signature == 's':
1162 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1163 elif p.arg.signature == 'o':
1164 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1165 elif p.arg.signature == 'g':
1166 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1167 elif p.arg.signature == 'ay':
1168 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1169 elif p.arg.signature == 'as':
1170 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1171 elif p.arg.signature == 'ao':
1172 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1173 elif p.arg.signature == 'aay':
1174 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1176 raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
1177 self.c.write(' %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
1183 self.c.write('typedef %sIface %sInterface;\n'%(i.camel_name, i.camel_name))
1184 self.c.write('G_DEFINE_INTERFACE (%s, %s, G_TYPE_OBJECT);\n'%(i.camel_name, i.name_lower))
1187 # ----------------------------------------------------------------------------------------------------
1189 def generate_property_accessors(self, i):
1190 for p in i.properties:
1192 if p.readable and p.writable:
1193 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.'
1195 hint = 'Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.'
1197 hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
1199 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1200 self.c.write(self.docbook_gen.expand(
1202 ' * %s_get_%s: (skip)\n'
1203 ' * @object: A #%s.\n'
1205 ' * Gets the value of the #%s:%s D-Bus property.\n'
1209 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1210 if p.arg.free_func != None:
1211 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'
1213 ' * 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'
1214 %(i.name_lower, p.name_lower))
1216 self.c.write(' * Returns: The property value.\n')
1217 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1219 '%s_get_%s (%s *object)\n'
1220 '{\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
1221 self.c.write(' return %s%s_GET_IFACE (object)->get_%s (object);\n'%(i.ns_upper, i.name_upper, p.name_lower))
1224 if p.arg.free_func != None:
1226 self.c.write(self.docbook_gen.expand(
1228 ' * %s_dup_%s: (skip)\n'
1229 ' * @object: A #%s.\n'
1231 ' * Gets a copy of the #%s:%s D-Bus property.\n'
1235 ' * Returns: (transfer full): The property value or %%NULL if the property is not set. The returned value should be freed with %s().\n'
1236 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint, p.arg.free_func), False))
1237 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1239 '%s_dup_%s (%s *object)\n'
1241 ' %svalue;\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in_dup))
1242 self.c.write(' g_object_get (G_OBJECT (object), "%s", &value, NULL);\n'%(p.name_hyphen))
1243 self.c.write(' return value;\n')
1248 if p.readable and p.writable:
1249 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.'
1251 hint = 'Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.'
1253 hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
1255 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1256 self.c.write(self.docbook_gen.expand(
1258 ' * %s_set_%s: (skip)\n'
1259 ' * @object: A #%s.\n'
1260 ' * @value: The value to set.\n'
1262 ' * Sets the #%s:%s D-Bus property to @value.\n'
1265 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1266 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1267 self.c.write('void\n'
1268 '%s_set_%s (%s *object, %svalue)\n'
1269 '{\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
1270 self.c.write(' g_object_set (G_OBJECT (object), "%s", value, NULL);\n'%(p.name_hyphen))
1274 # ---------------------------------------------------------------------------------------------------
1276 def generate_signal_emitters(self, i):
1278 self.c.write(self.docbook_gen.expand(
1281 ' * @object: A #%s.\n'
1282 %(i.name_lower, s.name_lower, i.camel_name), False))
1284 self.c.write(' * @arg_%s: Argument to pass with the signal.\n'%(a.name))
1285 self.c.write(self.docbook_gen.expand(
1287 ' * Emits the #%s::%s D-Bus signal.\n'
1288 %(i.name, s.name), False))
1289 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 0)
1290 self.c.write('void\n'
1292 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
1294 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1297 ' g_signal_emit_by_name (object, "%s"'%(s.name_hyphen))
1299 self.c.write(', arg_%s'%a.name)
1300 self.c.write(');\n')
1304 # ---------------------------------------------------------------------------------------------------
1306 def generate_method_calls(self, i):
1309 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1312 self.c.write('/**\n'
1314 ' * @proxy: A #%sProxy.\n'
1315 %(i.name_lower, m.name_lower, i.camel_name))
1317 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1319 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1320 self.c.write(self.docbook_gen.expand(
1321 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1322 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %%NULL.\n'
1323 ' * @user_data: User data to pass to @callback.\n'
1325 ' * Asynchronously invokes the %s.%s() D-Bus method on @proxy.\n'
1326 ' * 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'
1327 ' * You can then call %s_call_%s_finish() to get the result of the operation.\n'
1329 ' * See %s_call_%s_sync() for the synchronous, blocking version of this method.\n'
1330 %(i.name, m.name, i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1331 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1332 self.c.write('void\n'
1334 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1336 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1338 self.c.write(',\n GUnixFDList *fd_list')
1340 ' GCancellable *cancellable,\n'
1341 ' GAsyncReadyCallback callback,\n'
1342 ' gpointer user_data)\n'
1345 self.c.write(' g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy),\n')
1347 self.c.write(' g_dbus_proxy_call (G_DBUS_PROXY (proxy),\n')
1348 self.c.write(' "%s",\n'
1349 ' g_variant_new ("('%(m.name))
1351 self.c.write('%s'%(a.format_in))
1354 self.c.write(',\n arg_%s'%(a.name))
1356 ' G_DBUS_CALL_FLAGS_NONE,\n'
1359 self.c.write(' fd_list,\n')
1360 self.c.write(' cancellable,\n'
1366 self.c.write('/**\n'
1367 ' * %s_call_%s_finish:\n'
1368 ' * @proxy: A #%sProxy.\n'
1369 %(i.name_lower, m.name_lower, i.camel_name))
1370 for a in m.out_args:
1371 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1373 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1374 self.c.write(self.docbook_gen.expand(
1375 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_call_%s().\n'
1376 ' * @error: Return location for error or %%NULL.\n'
1378 ' * Finishes an operation started with %s_call_%s().\n'
1380 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1381 %(i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1382 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1383 self.c.write('gboolean\n'
1384 '%s_call_%s_finish (\n'
1385 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1386 for a in m.out_args:
1387 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1389 self.c.write(',\n GUnixFDList **out_fd_list')
1391 ' GAsyncResult *res,\n'
1392 ' GError **error)\n'
1394 ' GVariant *_ret;\n')
1396 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error);\n')
1398 self.c.write(' _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);\n')
1399 self.c.write(' if (_ret == NULL)\n'
1401 self.c.write(' g_variant_get (_ret,\n'
1403 for a in m.out_args:
1404 self.c.write('%s'%(a.format_out))
1406 for a in m.out_args:
1407 self.c.write(',\n out_%s'%(a.name))
1409 ' g_variant_unref (_ret);\n')
1410 self.c.write('_out:\n'
1411 ' return _ret != NULL;\n'
1417 self.c.write('/**\n'
1418 ' * %s_call_%s_sync:\n'
1419 ' * @proxy: A #%sProxy.\n'
1420 %(i.name_lower, m.name_lower, i.camel_name))
1422 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1424 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1425 for a in m.out_args:
1426 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1428 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1429 self.c.write(self.docbook_gen.expand(
1430 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1431 ' * @error: Return location for error or %%NULL.\n'
1433 ' * Synchronously invokes the %s.%s() D-Bus method on @proxy. The calling thread is blocked until a reply is received.\n'
1435 ' * See %s_call_%s() for the asynchronous version of this method.\n'
1437 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1438 %(i.name, m.name, i.name_lower, m.name_lower), False))
1439 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1440 self.c.write('gboolean\n'
1441 '%s_call_%s_sync (\n'
1442 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1444 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1446 self.c.write(',\n GUnixFDList *fd_list')
1447 for a in m.out_args:
1448 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1450 self.c.write(',\n GUnixFDList **out_fd_list')
1452 ' GCancellable *cancellable,\n'
1453 ' GError **error)\n'
1455 ' GVariant *_ret;\n')
1457 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy),\n')
1459 self.c.write(' _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),\n')
1460 self.c.write(' "%s",\n'
1461 ' g_variant_new ("('%(m.name))
1463 self.c.write('%s'%(a.format_in))
1466 self.c.write(',\n arg_%s'%(a.name))
1468 ' G_DBUS_CALL_FLAGS_NONE,\n'
1471 self.c.write(' fd_list,\n'
1473 self.c.write(' cancellable,\n'
1475 ' if (_ret == NULL)\n'
1477 self.c.write(' g_variant_get (_ret,\n'
1479 for a in m.out_args:
1480 self.c.write('%s'%(a.format_out))
1482 for a in m.out_args:
1483 self.c.write(',\n out_%s'%(a.name))
1485 ' g_variant_unref (_ret);\n')
1486 self.c.write('_out:\n'
1487 ' return _ret != NULL;\n'
1491 # ---------------------------------------------------------------------------------------------------
1493 def generate_method_completers(self, i):
1496 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1498 self.c.write('/**\n'
1499 ' * %s_complete_%s:\n'
1500 ' * @object: A #%s.\n'
1501 ' * @invocation: (transfer full): A #GDBusMethodInvocation.\n'
1502 %(i.name_lower, m.name_lower, i.camel_name))
1504 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1505 for a in m.out_args:
1506 self.c.write(' * @%s: Parameter to return.\n'%(a.name))
1507 self.c.write(self.docbook_gen.expand(
1509 ' * 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'
1511 ' * This method will free @invocation, you cannot use it afterwards.\n'
1512 %(i.name, m.name), False))
1513 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1514 self.c.write('void\n'
1515 '%s_complete_%s (\n'
1517 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
1519 self.c.write(',\n GUnixFDList *fd_list')
1520 for a in m.out_args:
1521 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1526 self.c.write(' g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,\n'
1527 ' g_variant_new ("(')
1529 self.c.write(' g_dbus_method_invocation_return_value (invocation,\n'
1530 ' g_variant_new ("(')
1531 for a in m.out_args:
1532 self.c.write('%s'%(a.format_in))
1534 for a in m.out_args:
1535 self.c.write(',\n %s'%(a.name))
1537 self.c.write('),\n fd_list);\n')
1539 self.c.write('));\n')
1543 # ---------------------------------------------------------------------------------------------------
1545 def generate_proxy(self, i):
1547 self.c.write('/* ------------------------------------------------------------------------ */\n'
1550 self.c.write(self.docbook_gen.expand(
1554 ' * The #%sProxy structure contains only private data and should only be accessed using the provided API.\n'
1555 %(i.camel_name, i.camel_name), False))
1556 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1559 self.c.write(self.docbook_gen.expand(
1561 ' * %sProxyClass:\n'
1562 ' * @parent_class: The parent class.\n'
1564 ' * Class structure for #%sProxy.\n'
1565 %(i.camel_name, i.camel_name), False))
1566 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1569 self.c.write('struct _%sProxyPrivate\n'
1575 self.c.write('static void %s_proxy_iface_init (%sIface *iface);\n'
1576 '\n'%(i.name_lower, i.camel_name))
1577 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1578 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1581 self.c.write('static void\n'
1582 '%s_proxy_finalize (GObject *object)\n'
1583 '{\n'%(i.name_lower))
1584 self.c.write(' %sProxy *proxy = %s%s_PROXY (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
1585 self.c.write(' g_datalist_clear (&proxy->priv->qdata);\n')
1586 self.c.write(' G_OBJECT_CLASS (%s_proxy_parent_class)->finalize (object);\n'
1588 '\n'%(i.name_lower))
1590 # property accessors
1592 # Note that we are guaranteed that prop_id starts at 1 and is
1593 # laid out in the same order as introspection data pointers
1595 self.c.write('static void\n'
1596 '%s_proxy_get_property (GObject *object,\n'
1599 ' GParamSpec *pspec)\n'
1600 '{\n'%(i.name_lower))
1601 if len(i.properties) > 0:
1602 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1603 ' GVariant *variant;\n'
1604 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1605 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1606 ' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
1607 ' if (info->use_gvariant)\n'
1609 ' g_value_set_variant (value, variant);\n'
1613 # could be that we don't have the value in cache - in that case, we do
1614 # nothing and the user gets the default value for the GType
1615 ' if (variant != NULL)\n'
1616 ' g_dbus_gvariant_to_gvalue (variant, value);\n'
1618 ' if (variant != NULL)\n'
1619 ' g_variant_unref (variant);\n'
1620 %(len(i.properties), i.name_lower))
1623 if len(i.properties) > 0:
1624 self.c.write('static void\n'
1625 '%s_proxy_set_property_cb (GDBusProxy *proxy,\n'
1626 ' GAsyncResult *res,\n'
1627 ' gpointer user_data)\n'
1628 '{\n'%(i.name_lower))
1629 self.c.write(' const _ExtendedGDBusPropertyInfo *info = user_data;\n'
1632 ' if (!g_dbus_proxy_call_finish (proxy, res, &error))\n'
1634 ' g_warning ("Error setting property `%%s\' on interface %s: %%s (%%s, %%d)",\n'
1635 ' info->parent_struct.name, \n'
1636 ' error->message, g_quark_to_string (error->domain), error->code);\n'
1637 ' g_error_free (error);\n'
1642 self.c.write('static void\n'
1643 '%s_proxy_set_property (GObject *object,\n'
1645 ' const GValue *value,\n'
1646 ' GParamSpec *pspec)\n'
1647 '{\n'%(i.name_lower))
1648 if len(i.properties) > 0:
1649 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1650 ' GVariant *variant;\n'
1651 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1652 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1653 ' variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
1654 ' g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
1655 ' "org.freedesktop.DBus.Properties.Set",\n'
1656 ' g_variant_new ("(ssv)", "%s", info->parent_struct.name, variant),\n'
1657 ' G_DBUS_CALL_FLAGS_NONE,\n'
1659 ' NULL, (GAsyncReadyCallback) %s_proxy_set_property_cb, (gpointer) info);\n'
1660 ' g_variant_unref (variant);\n'
1661 %(len(i.properties), i.name_lower, i.name, i.name_lower))
1666 self.c.write('static void\n'
1667 '%s_proxy_g_signal (GDBusProxy *proxy,\n'
1668 ' const gchar *sender_name,\n'
1669 ' const gchar *signal_name,\n'
1670 ' GVariant *parameters)\n'
1671 '{\n'%(i.name_lower))
1672 self.c.write(' _ExtendedGDBusSignalInfo *info;\n'
1673 ' GVariantIter iter;\n'
1674 ' GVariant *child;\n'
1675 ' GValue *paramv;\n'
1676 ' guint num_params;\n'
1678 ' guint signal_id;\n');
1679 # Note: info could be NULL if we are talking to a newer version of the interface
1680 self.c.write(' info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_%s_interface_info, signal_name);\n'
1681 ' if (info == NULL)\n'
1684 self.c.write (' num_params = g_variant_n_children (parameters);\n'
1685 ' paramv = g_new0 (GValue, num_params + 1);\n'
1686 ' g_value_init (¶mv[0], %sTYPE_%s);\n'
1687 ' g_value_set_object (¶mv[0], proxy);\n'
1688 %(i.ns_upper, i.name_upper))
1689 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
1691 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
1693 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1];\n'
1694 ' if (arg_info->use_gvariant)\n'
1696 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
1697 ' g_value_set_variant (¶mv[n], child);\n'
1701 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
1702 ' g_variant_unref (child);\n'
1705 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
1706 %(i.ns_upper, i.name_upper))
1707 self.c.write(' g_signal_emitv (paramv, signal_id, 0, NULL);\n')
1708 self.c.write(' for (n = 0; n < num_params + 1; n++)\n'
1709 ' g_value_unset (¶mv[n]);\n'
1710 ' g_free (paramv);\n')
1715 self.c.write('static void\n'
1716 '%s_proxy_g_properties_changed (GDBusProxy *_proxy,\n'
1717 ' GVariant *changed_properties,\n'
1718 ' const gchar *const *invalidated_properties)\n'
1719 '{\n'%(i.name_lower))
1720 # Note: info could be NULL if we are talking to a newer version of the interface
1721 self.c.write(' %sProxy *proxy = %s%s_PROXY (_proxy);\n'
1723 ' const gchar *key;\n'
1724 ' GVariantIter *iter;\n'
1725 ' _ExtendedGDBusPropertyInfo *info;\n'
1726 ' g_variant_get (changed_properties, "a{sv}", &iter);\n'
1727 ' while (g_variant_iter_next (iter, "{&sv}", &key, NULL))\n'
1729 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, key);\n'
1730 ' g_datalist_remove_data (&proxy->priv->qdata, key);\n'
1731 ' if (info != NULL)\n'
1732 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1734 ' g_variant_iter_free (iter);\n'
1735 ' for (n = 0; invalidated_properties[n] != NULL; n++)\n'
1737 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, invalidated_properties[n]);\n'
1738 ' g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]);\n'
1739 ' if (info != NULL)\n'
1740 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1744 %(i.camel_name, i.ns_upper, i.name_upper,
1745 i.name_lower, i.name_lower))
1748 for p in i.properties:
1750 if p.arg.free_func != None:
1752 self.c.write('static %s\n'
1753 '%s_proxy_get_%s (%s *object)\n'
1755 ' %sProxy *proxy = %s%s_PROXY (object);\n'
1756 ' GVariant *variant;\n'
1757 ' %svalue = %s;\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name,
1758 i.camel_name, i.ns_upper, i.name_upper,
1759 p.arg.ctype_in, nul_value))
1760 # For some property types, we have to free the returned
1761 # value (or part of it, e.g. the container) because of how
1762 # GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
1765 free_container = False;
1766 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':
1767 free_container = True;
1768 # If already using an old value for strv, objpathv, bytestring_array (see below),
1769 # then just return that... that way the result from multiple consecutive calls
1770 # to the getter are valid as long as they're freed
1773 self.c.write(' value = g_datalist_get_data (&proxy->priv->qdata, \"%s\");\n'
1774 ' if (value != NULL)\n'
1777 self.c.write(' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \"%s\");\n'%(p.name))
1778 if p.arg.gtype == 'G_TYPE_VARIANT':
1779 self.c.write(' value = variant;\n')
1780 self.c.write(' if (variant != NULL)\n')
1781 self.c.write(' g_variant_unref (variant);\n')
1783 self.c.write(' if (variant != NULL)\n'
1786 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':
1787 extra_len = ', NULL'
1788 self.c.write(' value = %s (variant%s);\n'%(p.arg.gvariant_get, extra_len))
1790 self.c.write(' g_datalist_set_data_full (&proxy->priv->qdata, \"%s\", (gpointer) value, g_free);\n'
1792 self.c.write(' g_variant_unref (variant);\n')
1793 self.c.write(' }\n')
1794 self.c.write(' return value;\n')
1799 self.c.write('static void\n'
1800 '%s_proxy_init (%sProxy *proxy)\n'
1802 ' proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %sTYPE_%s_PROXY, %sProxyPrivate);\n'
1803 ' g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
1806 %(i.name_lower, i.camel_name,
1807 i.ns_upper, i.name_upper, i.camel_name,
1809 self.c.write('static void\n'
1810 '%s_proxy_class_init (%sProxyClass *klass)\n'
1812 ' GObjectClass *gobject_class;\n'
1813 ' GDBusProxyClass *proxy_class;\n'
1815 ' g_type_class_add_private (klass, sizeof (%sProxyPrivate));\n'
1817 ' gobject_class = G_OBJECT_CLASS (klass);\n'
1818 ' gobject_class->finalize = %s_proxy_finalize;\n'
1819 ' gobject_class->get_property = %s_proxy_get_property;\n'
1820 ' gobject_class->set_property = %s_proxy_set_property;\n'
1822 ' proxy_class = G_DBUS_PROXY_CLASS (klass);\n'
1823 ' proxy_class->g_signal = %s_proxy_g_signal;\n'
1824 ' proxy_class->g_properties_changed = %s_proxy_g_properties_changed;\n'
1825 '\n'%(i.name_lower, i.camel_name,
1827 i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
1828 if len(i.properties) > 0:
1830 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
1834 self.c.write('static void\n'
1835 '%s_proxy_iface_init (%sIface *iface)\n'
1836 '{\n'%(i.name_lower, i.camel_name))
1837 for p in i.properties:
1838 self.c.write(' iface->get_%s = %s_proxy_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
1843 self.c.write(self.docbook_gen.expand(
1845 ' * %s_proxy_new:\n'
1846 ' * @connection: A #GDBusConnection.\n'
1847 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1848 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1849 ' * @object_path: An object path.\n'
1850 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1851 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1852 ' * @user_data: User data to pass to @callback.\n'
1854 ' * Asynchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new() for more details.\n'
1856 ' * 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'
1857 ' * You can then call %s_proxy_new_finish() to get the result of the operation.\n'
1859 ' * See %s_proxy_new_sync() for the synchronous, blocking version of this constructor.\n'
1860 %(i.name_lower, i.name, i.name_lower, i.name_lower), False))
1861 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1862 self.c.write('void\n'
1864 ' GDBusConnection *connection,\n'
1865 ' GDBusProxyFlags flags,\n'
1866 ' const gchar *name,\n'
1867 ' const gchar *object_path,\n'
1868 ' GCancellable *cancellable,\n'
1869 ' GAsyncReadyCallback callback,\n'
1870 ' gpointer user_data)\n'
1872 ' 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'
1875 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1876 self.c.write('/**\n'
1877 ' * %s_proxy_new_finish:\n'
1878 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new().\n'
1879 ' * @error: Return location for error or %%NULL\n'
1881 ' * Finishes an operation started with %s_proxy_new().\n'
1883 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1884 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1885 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1886 self.c.write('%s *\n'
1887 '%s_proxy_new_finish (\n'
1888 ' GAsyncResult *res,\n'
1889 ' GError **error)\n'
1892 ' GObject *source_object;\n'
1893 ' source_object = g_async_result_get_source_object (res);\n'
1894 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1895 ' g_object_unref (source_object);\n'
1896 ' if (ret != NULL)\n'
1897 ' return %s%s (ret);\n'
1902 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1903 self.c.write(self.docbook_gen.expand(
1905 ' * %s_proxy_new_sync:\n'
1906 ' * @connection: A #GDBusConnection.\n'
1907 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1908 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1909 ' * @object_path: An object path.\n'
1910 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1911 ' * @error: Return location for error or %%NULL\n'
1913 ' * Synchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new_sync() for more details.\n'
1915 ' * The calling thread is blocked until a reply is received.\n'
1917 ' * See %s_proxy_new() for the asynchronous version of this constructor.\n'
1919 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1920 %(i.name_lower, i.name, i.name_lower, i.camel_name), False))
1921 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1922 self.c.write('%s *\n'
1923 '%s_proxy_new_sync (\n'
1924 ' GDBusConnection *connection,\n'
1925 ' GDBusProxyFlags flags,\n'
1926 ' const gchar *name,\n'
1927 ' const gchar *object_path,\n'
1928 ' GCancellable *cancellable,\n'
1929 ' GError **error)\n'
1931 ' GInitable *ret;\n'
1932 ' 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'
1933 ' if (ret != NULL)\n'
1934 ' return %s%s (ret);\n'
1939 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
1941 self.c.write(self.docbook_gen.expand(
1943 ' * %s_proxy_new_for_bus:\n'
1944 ' * @bus_type: A #GBusType.\n'
1945 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1946 ' * @name: A bus name (well-known or unique).\n'
1947 ' * @object_path: An object path.\n'
1948 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1949 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1950 ' * @user_data: User data to pass to @callback.\n'
1952 ' * Like %s_proxy_new() but takes a #GBusType instead of a #GDBusConnection.\n'
1954 ' * 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'
1955 ' * You can then call %s_proxy_new_for_bus_finish() to get the result of the operation.\n'
1957 ' * See %s_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
1958 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower), False))
1959 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1960 self.c.write('void\n'
1961 '%s_proxy_new_for_bus (\n'
1962 ' GBusType bus_type,\n'
1963 ' GDBusProxyFlags flags,\n'
1964 ' const gchar *name,\n'
1965 ' const gchar *object_path,\n'
1966 ' GCancellable *cancellable,\n'
1967 ' GAsyncReadyCallback callback,\n'
1968 ' gpointer user_data)\n'
1970 ' 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'
1973 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1974 self.c.write('/**\n'
1975 ' * %s_proxy_new_for_bus_finish:\n'
1976 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new_for_bus().\n'
1977 ' * @error: Return location for error or %%NULL\n'
1979 ' * Finishes an operation started with %s_proxy_new_for_bus().\n'
1981 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1982 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1983 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1984 self.c.write('%s *\n'
1985 '%s_proxy_new_for_bus_finish (\n'
1986 ' GAsyncResult *res,\n'
1987 ' GError **error)\n'
1990 ' GObject *source_object;\n'
1991 ' source_object = g_async_result_get_source_object (res);\n'
1992 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1993 ' g_object_unref (source_object);\n'
1994 ' if (ret != NULL)\n'
1995 ' return %s%s (ret);\n'
2000 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
2001 self.c.write(self.docbook_gen.expand(
2003 ' * %s_proxy_new_for_bus_sync:\n'
2004 ' * @bus_type: A #GBusType.\n'
2005 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
2006 ' * @name: A bus name (well-known or unique).\n'
2007 ' * @object_path: An object path.\n'
2008 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
2009 ' * @error: Return location for error or %%NULL\n'
2011 ' * Like %s_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
2013 ' * The calling thread is blocked until a reply is received.\n'
2015 ' * See %s_proxy_new_for_bus() for the asynchronous version of this constructor.\n'
2017 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2018 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name), False))
2019 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2020 self.c.write('%s *\n'
2021 '%s_proxy_new_for_bus_sync (\n'
2022 ' GBusType bus_type,\n'
2023 ' GDBusProxyFlags flags,\n'
2024 ' const gchar *name,\n'
2025 ' const gchar *object_path,\n'
2026 ' GCancellable *cancellable,\n'
2027 ' GError **error)\n'
2029 ' GInitable *ret;\n'
2030 ' 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'
2031 ' if (ret != NULL)\n'
2032 ' return %s%s (ret);\n'
2037 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
2040 # ---------------------------------------------------------------------------------------------------
2042 def generate_skeleton(self, i):
2044 self.c.write('/* ------------------------------------------------------------------------ */\n'
2047 self.c.write(self.docbook_gen.expand(
2051 ' * The #%sSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2052 %(i.camel_name, i.camel_name), False))
2053 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2056 self.c.write(self.docbook_gen.expand(
2058 ' * %sSkeletonClass:\n'
2059 ' * @parent_class: The parent class.\n'
2061 ' * Class structure for #%sSkeleton.\n'
2062 %(i.camel_name, i.camel_name), False))
2063 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2066 self.c.write('struct _%sSkeletonPrivate\n'
2068 ' GValue *properties;\n'
2069 ' GList *changed_properties;\n'
2070 ' GSource *changed_properties_idle_source;\n'
2071 ' GMainContext *context;\n'
2076 self.c.write('static void\n'
2077 '_%s_skeleton_handle_method_call (\n'
2078 ' GDBusConnection *connection,\n'
2079 ' const gchar *sender,\n'
2080 ' const gchar *object_path,\n'
2081 ' const gchar *interface_name,\n'
2082 ' const gchar *method_name,\n'
2083 ' GVariant *parameters,\n'
2084 ' GDBusMethodInvocation *invocation,\n'
2085 ' gpointer user_data)\n'
2087 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2088 ' _ExtendedGDBusMethodInfo *info;\n'
2089 ' GVariantIter iter;\n'
2090 ' GVariant *child;\n'
2091 ' GValue *paramv;\n'
2092 ' guint num_params;\n'
2093 ' guint num_extra;\n'
2095 ' guint signal_id;\n'
2096 ' GValue return_value = G_VALUE_INIT;\n'
2097 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2098 self.c.write(' info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n'
2099 ' g_assert (info != NULL);\n'
2101 self.c.write (' num_params = g_variant_n_children (parameters);\n'
2102 ' num_extra = info->pass_fdlist ? 3 : 2;'
2103 ' paramv = g_new0 (GValue, num_params + num_extra);\n'
2105 ' g_value_init (¶mv[n], %sTYPE_%s);\n'
2106 ' g_value_set_object (¶mv[n++], skeleton);\n'
2107 ' g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION);\n'
2108 ' g_value_set_object (¶mv[n++], invocation);\n'
2109 ' if (info->pass_fdlist)\n'
2111 '#ifdef G_OS_UNIX\n'
2112 ' g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST);\n'
2113 ' g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)));\n'
2115 ' g_assert_not_reached ();\n'
2118 %(i.ns_upper, i.name_upper))
2119 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
2120 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
2122 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra];\n'
2123 ' if (arg_info->use_gvariant)\n'
2125 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
2126 ' g_value_set_variant (¶mv[n], child);\n'
2130 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
2131 ' g_variant_unref (child);\n'
2134 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
2135 %(i.ns_upper, i.name_upper))
2136 self.c.write(' g_value_init (&return_value, G_TYPE_BOOLEAN);\n'
2137 ' g_signal_emitv (paramv, signal_id, 0, &return_value);\n'
2138 ' if (!g_value_get_boolean (&return_value))\n'
2139 ' 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'
2140 ' g_value_unset (&return_value);\n'
2142 self.c.write(' for (n = 0; n < num_params + num_extra; n++)\n'
2143 ' g_value_unset (¶mv[n]);\n'
2144 ' g_free (paramv);\n')
2148 self.c.write('static GVariant *\n'
2149 '_%s_skeleton_handle_get_property (\n'
2150 ' GDBusConnection *connection,\n'
2151 ' const gchar *sender,\n'
2152 ' const gchar *object_path,\n'
2153 ' const gchar *interface_name,\n'
2154 ' const gchar *property_name,\n'
2155 ' GError **error,\n'
2156 ' gpointer user_data)\n'
2158 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2159 ' GValue value = G_VALUE_INIT;\n'
2160 ' GParamSpec *pspec;\n'
2161 ' _ExtendedGDBusPropertyInfo *info;\n'
2163 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2164 self.c.write(' ret = NULL;\n'
2165 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, property_name);\n'
2166 ' g_assert (info != NULL);\n'
2167 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2168 ' if (pspec == NULL)\n'
2170 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2174 ' g_value_init (&value, pspec->value_type);\n'
2175 ' g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2176 ' ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
2177 ' g_value_unset (&value);\n'
2184 self.c.write('static gboolean\n'
2185 '_%s_skeleton_handle_set_property (\n'
2186 ' GDBusConnection *connection,\n'
2187 ' const gchar *sender,\n'
2188 ' const gchar *object_path,\n'
2189 ' const gchar *interface_name,\n'
2190 ' const gchar *property_name,\n'
2191 ' GVariant *variant,\n'
2192 ' GError **error,\n'
2193 ' gpointer user_data)\n'
2195 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2196 ' GValue value = G_VALUE_INIT;\n'
2197 ' GParamSpec *pspec;\n'
2198 ' _ExtendedGDBusPropertyInfo *info;\n'
2200 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2201 self.c.write(' ret = FALSE;\n'
2202 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, property_name);\n'
2203 ' g_assert (info != NULL);\n'
2204 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2205 ' if (pspec == NULL)\n'
2207 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2211 ' if (info->use_gvariant)\n'
2212 ' g_value_set_variant (&value, variant);\n'
2214 ' g_dbus_gvariant_to_gvalue (variant, &value);\n'
2215 ' g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2216 ' g_value_unset (&value);\n'
2225 self.c.write('static const GDBusInterfaceVTable _%s_skeleton_vtable =\n'
2227 ' _%s_skeleton_handle_method_call,\n'
2228 ' _%s_skeleton_handle_get_property,\n'
2229 ' _%s_skeleton_handle_set_property\n'
2231 '\n'%(i.name_lower, i.name_lower, i.name_lower, i.name_lower))
2233 self.c.write('static GDBusInterfaceInfo *\n'
2234 '%s_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton)\n'
2236 ' return %s_interface_info ();\n'
2237 %(i.name_lower, i.name_lower))
2241 self.c.write('static GDBusInterfaceVTable *\n'
2242 '%s_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton)\n'
2244 ' return (GDBusInterfaceVTable *) &_%s_skeleton_vtable;\n'
2245 %(i.name_lower, i.name_lower))
2249 self.c.write('static GVariant *\n'
2250 '%s_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton)\n'
2252 ' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2253 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2255 ' GVariantBuilder builder;\n'
2257 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2258 ' if (_%s_interface_info.parent_struct.properties == NULL)\n'
2260 ' for (n = 0; _%s_interface_info.parent_struct.properties[n] != NULL; n++)\n'
2262 ' GDBusPropertyInfo *info = _%s_interface_info.parent_struct.properties[n];\n'
2263 ' if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)\n'
2265 ' GVariant *value;\n'
2266 ' 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'
2267 ' if (value != NULL)\n'
2269 ' g_variant_take_ref (value);\n'
2270 ' g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
2271 ' g_variant_unref (value);\n'
2276 ' return g_variant_builder_end (&builder);\n'
2279 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name))
2281 if len(i.properties) > 0:
2282 self.c.write('static gboolean _%s_emit_changed (gpointer user_data);\n'
2286 self.c.write('static void\n'
2287 '%s_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton)\n'
2290 if len(i.properties) > 0:
2291 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2292 ' gboolean emit_changed = FALSE;\n'
2294 ' g_mutex_lock (&skeleton->priv->lock);\n'
2295 ' if (skeleton->priv->changed_properties_idle_source != NULL)\n'
2297 ' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
2298 ' skeleton->priv->changed_properties_idle_source = NULL;\n'
2299 ' emit_changed = TRUE;\n'
2301 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2303 ' if (emit_changed)\n'
2304 ' _%s_emit_changed (skeleton);\n'
2305 %(i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2310 self.c.write('static void\n'
2311 '_%s_on_signal_%s (\n'
2312 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
2314 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
2317 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n\n'
2318 ' GList *connections, *l;\n'
2319 ' GVariant *signal_variant;\n'
2320 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2321 %(i.camel_name, i.ns_upper, i.name_upper))
2323 ' signal_variant = g_variant_ref_sink (g_variant_new ("(')
2325 self.c.write('%s'%(a.format_in))
2328 self.c.write(',\n arg_%s'%(a.name))
2329 self.c.write('));\n')
2331 self.c.write(' for (l = connections; l != NULL; l = l->next)\n'
2333 ' GDBusConnection *connection = l->data;\n'
2334 ' g_dbus_connection_emit_signal (connection,\n'
2335 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", "%s",\n'
2336 ' signal_variant, NULL);\n'
2339 self.c.write(' g_variant_unref (signal_variant);\n')
2340 self.c.write(' g_list_free_full (connections, g_object_unref);\n')
2344 self.c.write('static void %s_skeleton_iface_init (%sIface *iface);\n'
2345 %(i.name_lower, i.camel_name))
2347 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2348 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2351 self.c.write('static void\n'
2352 '%s_skeleton_finalize (GObject *object)\n'
2353 '{\n'%(i.name_lower))
2354 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2355 if len(i.properties) > 0:
2356 self.c.write(' guint n;\n'
2357 ' for (n = 0; n < %d; n++)\n'
2358 ' g_value_unset (&skeleton->priv->properties[n]);\n'%(len(i.properties)))
2359 self.c.write(' g_free (skeleton->priv->properties);\n')
2360 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2361 self.c.write(' if (skeleton->priv->changed_properties_idle_source != NULL)\n')
2362 self.c.write(' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
2363 self.c.write(' g_main_context_unref (skeleton->priv->context);\n')
2364 self.c.write(' g_mutex_clear (&skeleton->priv->lock);\n')
2365 self.c.write(' G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
2367 '\n'%(i.name_lower))
2369 # property accessors (TODO: generate PropertiesChanged signals in setter)
2370 if len(i.properties) > 0:
2371 self.c.write('static void\n'
2372 '%s_skeleton_get_property (GObject *object,\n'
2375 ' GParamSpec *pspec)\n'
2376 '{\n'%(i.name_lower))
2377 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2378 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2379 ' g_mutex_lock (&skeleton->priv->lock);\n'
2380 ' g_value_copy (&skeleton->priv->properties[prop_id - 1], value);\n'
2381 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2382 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
2386 # if property is already scheduled then re-use entry.. though it could be
2389 # foo_set_prop_bar (object, "");
2390 # foo_set_prop_bar (object, "blah");
2392 # say, every update... In this case, where nothing happens, we obviously
2393 # don't want a PropertiesChanged() event. We can easily check for this
2394 # by comparing against the _original value_ recorded before the first
2395 # change event. If the latest value is not different from the original
2396 # one, we can simply ignore the ChangedProperty
2398 self.c.write('static gboolean\n'
2399 '_%s_emit_changed (gpointer user_data)\n'
2401 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2402 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2403 self.c.write(' GList *l;\n'
2404 ' GVariantBuilder builder;\n'
2405 ' GVariantBuilder invalidated_builder;\n'
2406 ' guint num_changes;\n'
2408 ' g_mutex_lock (&skeleton->priv->lock);\n'
2409 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2410 ' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
2411 ' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
2413 ' ChangedProperty *cp = l->data;\n'
2414 ' GVariant *variant;\n'
2415 ' const GValue *cur_value;\n'
2417 ' cur_value = &skeleton->priv->properties[cp->prop_id - 1];\n'
2418 ' if (!_g_value_equal (cur_value, &cp->orig_value))\n'
2420 ' variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature));\n'
2421 ' g_variant_builder_add (&builder, "{sv}", cp->info->parent_struct.name, variant);\n'
2422 ' g_variant_unref (variant);\n'
2426 ' if (num_changes > 0)\n'
2428 ' GList *connections, *l;\n'
2429 ' GVariant *signal_variant;'
2431 ' signal_variant = g_variant_ref_sink (g_variant_new ("(sa{sv}as)", "%s",\n'
2432 ' &builder, &invalidated_builder));\n'
2433 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2434 ' for (l = connections; l != NULL; l = l->next)\n'
2436 ' GDBusConnection *connection = l->data;\n'
2438 ' g_dbus_connection_emit_signal (connection,\n'
2439 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2440 ' "org.freedesktop.DBus.Properties",\n'
2441 ' "PropertiesChanged",\n'
2442 ' signal_variant,\n'
2445 ' g_variant_unref (signal_variant);\n'
2446 ' g_list_free_full (connections, g_object_unref);\n'
2450 ' g_variant_builder_clear (&builder);\n'
2451 ' g_variant_builder_clear (&invalidated_builder);\n'
2454 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2455 self.c.write(' skeleton->priv->changed_properties = NULL;\n')
2456 self.c.write(' skeleton->priv->changed_properties_idle_source = NULL;\n')
2457 self.c.write(' g_mutex_unlock (&skeleton->priv->lock);\n')
2458 self.c.write(' return FALSE;\n'
2461 # holding lock while being called
2462 self.c.write('static void\n'
2463 '_%s_schedule_emit_changed (%sSkeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value)\n'
2465 ' ChangedProperty *cp;\n'
2468 ' for (l = skeleton->priv->changed_properties; l != NULL; l = l->next)\n'
2470 ' ChangedProperty *i_cp = l->data;\n'
2471 ' if (i_cp->info == info)\n'
2477 %(i.name_lower, i.camel_name))
2478 self.c.write(' if (cp == NULL)\n'
2480 ' cp = g_new0 (ChangedProperty, 1);\n'
2481 ' cp->prop_id = prop_id;\n'
2482 ' cp->info = info;\n'
2483 ' skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp);\n'
2484 ' g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value));\n'
2485 ' g_value_copy (orig_value, &cp->orig_value);\n'
2491 # Postpone setting up the refresh source until the ::notify signal is emitted as
2492 # this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
2493 # This is useful when updating several properties from another thread than
2494 # where the idle will be emitted from
2495 self.c.write('static void\n'
2496 '%s_skeleton_notify (GObject *object,\n'
2497 ' GParamSpec *pspec)\n'
2499 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2500 ' g_mutex_lock (&skeleton->priv->lock);\n'
2501 ' if (skeleton->priv->changed_properties != NULL &&\n'
2502 ' skeleton->priv->changed_properties_idle_source == NULL)\n'
2504 ' skeleton->priv->changed_properties_idle_source = g_idle_source_new ();\n'
2505 ' g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);\n'
2506 ' g_source_set_callback (skeleton->priv->changed_properties_idle_source, _%s_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);\n'
2507 ' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
2508 ' g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
2510 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2513 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2515 self.c.write('static void\n'
2516 '%s_skeleton_set_property (GObject *object,\n'
2518 ' const GValue *value,\n'
2519 ' GParamSpec *pspec)\n'
2520 '{\n'%(i.name_lower))
2521 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2522 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2523 ' g_mutex_lock (&skeleton->priv->lock);\n'
2524 ' g_object_freeze_notify (object);\n'
2525 ' if (!_g_value_equal (value, &skeleton->priv->properties[prop_id - 1]))\n'
2527 ' if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
2528 ' _%s_schedule_emit_changed (skeleton, _%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties[prop_id - 1]);\n'
2529 ' g_value_copy (value, &skeleton->priv->properties[prop_id - 1]);\n'
2530 ' g_object_notify_by_pspec (object, pspec);\n'
2532 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2533 ' g_object_thaw_notify (object);\n'
2534 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
2538 self.c.write('static void\n'
2539 '%s_skeleton_init (%sSkeleton *skeleton)\n'
2541 ' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
2542 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.camel_name))
2543 self.c.write(' g_mutex_init (&skeleton->priv->lock);\n')
2544 self.c.write(' skeleton->priv->context = g_main_context_ref_thread_default ();\n')
2545 if len(i.properties) > 0:
2546 self.c.write(' skeleton->priv->properties = g_new0 (GValue, %d);\n'%(len(i.properties)))
2548 for p in i.properties:
2549 self.c.write(' g_value_init (&skeleton->priv->properties[%d], %s);\n'%(n, p.arg.gtype))
2556 for p in i.properties:
2557 self.c.write('static %s\n'
2558 '%s_skeleton_get_%s (%s *object)\n'
2560 %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
2561 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2562 self.c.write(' %svalue;\n'
2563 ' g_mutex_lock (&skeleton->priv->lock);\n'
2564 ' value = %s (&(skeleton->priv->properties[%d]));\n'
2565 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2566 %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
2567 self.c.write(' return value;\n')
2572 self.c.write('static void\n'
2573 '%s_skeleton_class_init (%sSkeletonClass *klass)\n'
2575 ' GObjectClass *gobject_class;\n'
2576 ' GDBusInterfaceSkeletonClass *skeleton_class;\n'
2578 ' g_type_class_add_private (klass, sizeof (%sSkeletonPrivate));\n'
2580 ' gobject_class = G_OBJECT_CLASS (klass);\n'
2581 ' gobject_class->finalize = %s_skeleton_finalize;\n'
2582 %(i.name_lower, i.camel_name, i.camel_name, i.name_lower))
2583 if len(i.properties) > 0:
2584 self.c.write(' gobject_class->get_property = %s_skeleton_get_property;\n'
2585 ' gobject_class->set_property = %s_skeleton_set_property;\n'
2586 ' gobject_class->notify = %s_skeleton_notify;\n'
2587 '\n'%(i.name_lower, i.name_lower, i.name_lower))
2589 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
2591 ' skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);\n');
2592 self.c.write(' skeleton_class->get_info = %s_skeleton_dbus_interface_get_info;\n'%(i.name_lower))
2593 self.c.write(' skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
2594 self.c.write(' skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
2595 self.c.write(' skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
2599 self.c.write('static void\n'
2600 '%s_skeleton_iface_init (%sIface *iface)\n'
2602 %(i.name_lower, i.camel_name))
2604 self.c.write(' iface->%s = _%s_on_signal_%s;\n'
2605 %(s.name_lower, i.name_lower, s.name_lower))
2606 for p in i.properties:
2607 self.c.write(' iface->get_%s = %s_skeleton_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
2612 self.c.write(self.docbook_gen.expand(
2614 ' * %s_skeleton_new:\n'
2616 ' * Creates a skeleton object for the D-Bus interface #%s.\n'
2618 ' * Returns: (transfer full) (type %sSkeleton): The skeleton object.\n'
2619 %(i.name_lower, i.name, i.camel_name), False))
2620 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2621 self.c.write('%s *\n'
2622 '%s_skeleton_new (void)\n'
2624 ' return %s%s (g_object_new (%sTYPE_%s_SKELETON, NULL));\n'
2626 '\n'%(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
2628 # ---------------------------------------------------------------------------------------------------
2630 def generate_object(self):
2631 self.c.write('/* ------------------------------------------------------------------------\n'
2632 ' * Code for Object, ObjectProxy and ObjectSkeleton\n'
2633 ' * ------------------------------------------------------------------------\n'
2637 self.c.write(self.docbook_gen.expand(
2639 ' * SECTION:%sObject\n'
2640 ' * @title: %sObject\n'
2641 ' * @short_description: Specialized GDBusObject types\n'
2643 ' * 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'
2645 %(self.namespace, self.namespace, self.namespace, self.namespace, self.namespace), False))
2648 self.c.write(self.docbook_gen.expand(
2652 ' * The #%sObject type is a specialized container of interfaces.\n'
2654 %(self.namespace, self.namespace), False))
2657 self.c.write(self.docbook_gen.expand(
2659 ' * %sObjectIface:\n'
2660 ' * @parent_iface: The parent interface.\n'
2662 ' * Virtual table for the #%sObject interface.\n'
2664 %(self.namespace, self.namespace), False))
2667 self.c.write('static void\n'
2668 '%sobject_default_init (%sObjectIface *iface)\n'
2670 %(self.ns_lower, self.namespace));
2671 for i in self.ifaces:
2672 self.c.write(self.docbook_gen.expand(
2676 ' * The #%s instance corresponding to the D-Bus interface #%s, if any.\n'
2678 ' * Connect to the #GObject::notify signal to get informed of property changes.\n'
2679 %(self.namespace, i.name_hyphen, i.camel_name, i.name), False))
2680 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 2)
2681 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'
2683 %(i.name_hyphen, i.name_hyphen, i.name_hyphen, self.ns_upper, i.name_upper))
2687 self.c.write('typedef %sObjectIface %sObjectInterface;\n'%(self.namespace, self.namespace))
2688 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))
2691 for i in self.ifaces:
2692 self.c.write(self.docbook_gen.expand(
2694 ' * %sobject_get_%s:\n'
2695 ' * @object: A #%sObject.\n'
2697 ' * Gets the #%s instance for the D-Bus interface #%s on @object, if any.\n'
2699 ' * Returns: (transfer full): A #%s that must be freed with g_object_unref() or %%NULL if @object does not implement the interface.\n'
2700 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.name, i.camel_name), False))
2701 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2702 self.c.write ('%s *%sobject_get_%s (%sObject *object)\n'
2703 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2705 ' GDBusInterface *ret;\n'
2706 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2707 ' if (ret == NULL)\n'
2709 ' return %s%s (ret);\n'
2712 %(i.name, self.ns_upper, i.name_upper))
2714 for i in self.ifaces:
2715 self.c.write(self.docbook_gen.expand(
2717 ' * %sobject_peek_%s: (skip)\n'
2718 ' * @object: A #%sObject.\n'
2720 ' * Like %sobject_get_%s() but doesn\'t increase the reference count on the returned object.\n'
2722 ' * <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'
2724 ' * 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'
2725 %(self.ns_lower, i.name_upper.lower(), self.namespace, self.ns_lower, i.name_upper.lower(), i.camel_name), False))
2726 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2727 self.c.write ('%s *%sobject_peek_%s (%sObject *object)\n'
2728 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2730 ' GDBusInterface *ret;\n'
2731 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2732 ' if (ret == NULL)\n'
2734 ' g_object_unref (ret);\n'
2735 ' return %s%s (ret);\n'
2738 %(i.name, self.ns_upper, i.name_upper))
2740 # shared by ObjectProxy and ObjectSkeleton classes
2741 self.c.write('static void\n'
2742 '%sobject_notify (GDBusObject *object, GDBusInterface *interface)\n'
2744 ' g_object_notify (G_OBJECT (object), ((_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface))->hyphen_name);\n'
2749 self.c.write(self.docbook_gen.expand(
2751 ' * %sObjectProxy:\n'
2753 ' * The #%sObjectProxy structure contains only private data and should only be accessed using the provided API.\n'
2754 %(self.namespace, self.namespace), False))
2755 self.c.write(' */\n')
2757 self.c.write(self.docbook_gen.expand(
2759 ' * %sObjectProxyClass:\n'
2760 ' * @parent_class: The parent class.\n'
2762 ' * Class structure for #%sObjectProxy.\n'
2763 %(self.namespace, self.namespace), False))
2764 self.c.write(' */\n')
2767 self.c.write('static void\n'
2768 '%sobject_proxy__%sobject_iface_init (%sObjectIface *iface)\n'
2772 %(self.ns_lower, self.ns_lower, self.namespace))
2773 self.c.write('static void\n'
2774 '%sobject_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2776 ' iface->interface_added = %sobject_notify;\n'
2777 ' iface->interface_removed = %sobject_notify;\n'
2780 %(self.ns_lower, self.ns_lower, self.ns_lower))
2782 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectProxy, %sobject_proxy, G_TYPE_DBUS_OBJECT_PROXY,\n'
2783 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_proxy__%sobject_iface_init)\n'
2784 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_proxy__g_dbus_object_iface_init));\n'
2786 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2788 self.c.write('static void\n'
2789 '%sobject_proxy_init (%sObjectProxy *object)\n'
2792 '\n'%(self.ns_lower, self.namespace))
2793 self.c.write('static void\n'
2794 '%sobject_proxy_set_property (GObject *gobject,\n'
2796 ' const GValue *value,\n'
2797 ' GParamSpec *pspec)\n'
2799 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2803 self.c.write('static void\n'
2804 '%sobject_proxy_get_property (GObject *gobject,\n'
2807 ' GParamSpec *pspec)\n'
2809 ' %sObjectProxy *object = %sOBJECT_PROXY (gobject);\n'
2810 ' GDBusInterface *interface;\n'
2812 ' switch (prop_id)\n'
2814 %(self.ns_lower, self.namespace, self.ns_upper))
2816 for i in self.ifaces:
2817 self.c.write(' case %d:\n'
2818 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2819 ' g_value_take_object (value, interface);\n'
2824 self.c.write(' default:\n'
2825 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2830 self.c.write('static void\n'
2831 '%sobject_proxy_class_init (%sObjectProxyClass *klass)\n'
2833 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2835 ' gobject_class->set_property = %sobject_proxy_set_property;\n'
2836 ' gobject_class->get_property = %sobject_proxy_get_property;\n'
2838 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2840 for i in self.ifaces:
2841 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2843 %(n, i.name_hyphen))
2848 self.c.write(self.docbook_gen.expand(
2850 ' * %sobject_proxy_new:\n'
2851 ' * @connection: A #GDBusConnection.\n'
2852 ' * @object_path: An object path.\n'
2854 ' * Creates a new proxy object.\n'
2856 ' * Returns: (transfer full): The proxy object.\n'
2858 %(self.ns_lower), False))
2859 self.c.write('%sObjectProxy *\n'
2860 '%sobject_proxy_new (GDBusConnection *connection,\n'
2861 ' const gchar *object_path)\n'
2863 ' g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);\n'
2864 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2865 ' return %sOBJECT_PROXY (g_object_new (%sTYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL));\n'
2867 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2869 self.c.write(self.docbook_gen.expand(
2871 ' * %sObjectSkeleton:\n'
2873 ' * The #%sObjectSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2874 %(self.namespace, self.namespace), False))
2875 self.c.write(' */\n')
2877 self.c.write(self.docbook_gen.expand(
2879 ' * %sObjectSkeletonClass:\n'
2880 ' * @parent_class: The parent class.\n'
2882 ' * Class structure for #%sObjectSkeleton.\n'
2883 %(self.namespace, self.namespace), False))
2884 self.c.write(' */\n')
2887 self.c.write('static void\n'
2888 '%sobject_skeleton__%sobject_iface_init (%sObjectIface *iface)\n'
2892 %(self.ns_lower, self.ns_lower, self.namespace))
2894 self.c.write('static void\n'
2895 '%sobject_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2897 ' iface->interface_added = %sobject_notify;\n'
2898 ' iface->interface_removed = %sobject_notify;\n'
2901 %(self.ns_lower, self.ns_lower, self.ns_lower))
2902 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectSkeleton, %sobject_skeleton, G_TYPE_DBUS_OBJECT_SKELETON,\n'
2903 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_skeleton__%sobject_iface_init)\n'
2904 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_skeleton__g_dbus_object_iface_init));\n'
2906 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2908 self.c.write('static void\n'
2909 '%sobject_skeleton_init (%sObjectSkeleton *object)\n'
2912 '\n'%(self.ns_lower, self.namespace))
2913 self.c.write('static void\n'
2914 '%sobject_skeleton_set_property (GObject *gobject,\n'
2916 ' const GValue *value,\n'
2917 ' GParamSpec *pspec)\n'
2919 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2920 ' GDBusInterfaceSkeleton *interface;\n'
2922 ' switch (prop_id)\n'
2924 %(self.ns_lower, self.namespace, self.ns_upper))
2926 for i in self.ifaces:
2927 self.c.write(' case %d:\n'
2928 ' interface = g_value_get_object (value);\n'
2929 ' if (interface != NULL)\n'
2931 ' g_warn_if_fail (%sIS_%s (interface));\n'
2932 ' g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface);\n'
2936 ' g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "%s");\n'
2940 %(n, self.ns_upper, i.name_upper, i.name))
2942 self.c.write(' default:\n'
2943 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2948 self.c.write('static void\n'
2949 '%sobject_skeleton_get_property (GObject *gobject,\n'
2952 ' GParamSpec *pspec)\n'
2954 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2955 ' GDBusInterface *interface;\n'
2957 ' switch (prop_id)\n'
2959 %(self.ns_lower, self.namespace, self.ns_upper))
2961 for i in self.ifaces:
2962 self.c.write(' case %d:\n'
2963 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2964 ' g_value_take_object (value, interface);\n'
2969 self.c.write(' default:\n'
2970 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2975 self.c.write('static void\n'
2976 '%sobject_skeleton_class_init (%sObjectSkeletonClass *klass)\n'
2978 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2980 ' gobject_class->set_property = %sobject_skeleton_set_property;\n'
2981 ' gobject_class->get_property = %sobject_skeleton_get_property;\n'
2983 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2985 for i in self.ifaces:
2986 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2988 %(n, i.name_hyphen))
2992 self.c.write(self.docbook_gen.expand(
2994 ' * %sobject_skeleton_new:\n'
2995 ' * @object_path: An object path.\n'
2997 ' * Creates a new skeleton object.\n'
2999 ' * Returns: (transfer full): The skeleton object.\n'
3001 %(self.ns_lower), False))
3002 self.c.write('%sObjectSkeleton *\n'
3003 '%sobject_skeleton_new (const gchar *object_path)\n'
3005 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
3006 ' return %sOBJECT_SKELETON (g_object_new (%sTYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL));\n'
3008 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
3009 for i in self.ifaces:
3010 self.c.write(self.docbook_gen.expand(
3012 ' * %sobject_skeleton_set_%s:\n'
3013 ' * @object: A #%sObjectSkeleton.\n'
3014 ' * @interface_: (allow-none): A #%s or %%NULL to clear the interface.\n'
3016 ' * Sets the #%s instance for the D-Bus interface #%s on @object.\n'
3017 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.camel_name, i.name), False))
3018 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
3019 self.c.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_)\n'
3020 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
3022 ' g_object_set (G_OBJECT (object), "%s", interface_, NULL);\n'
3029 def generate_object_manager_client(self):
3030 self.c.write('/* ------------------------------------------------------------------------\n'
3031 ' * Code for ObjectManager client\n'
3032 ' * ------------------------------------------------------------------------\n'
3036 self.c.write(self.docbook_gen.expand(
3038 ' * SECTION:%sObjectManagerClient\n'
3039 ' * @title: %sObjectManagerClient\n'
3040 ' * @short_description: Generated GDBusObjectManagerClient type\n'
3042 ' * This section contains a #GDBusObjectManagerClient that uses %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc.\n'
3044 %(self.namespace, self.namespace, self.ns_lower), False))
3047 self.c.write(self.docbook_gen.expand(
3049 ' * %sObjectManagerClient:\n'
3051 ' * The #%sObjectManagerClient structure contains only private data and should only be accessed using the provided API.\n'
3052 %(self.namespace, self.namespace), False))
3053 self.c.write(' */\n')
3056 self.c.write(self.docbook_gen.expand(
3058 ' * %sObjectManagerClientClass:\n'
3059 ' * @parent_class: The parent class.\n'
3061 ' * Class structure for #%sObjectManagerClient.\n'
3062 %(self.namespace, self.namespace), False))
3063 self.c.write(' */\n')
3067 self.c.write('G_DEFINE_TYPE (%sObjectManagerClient, %sobject_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT);\n'
3069 %(self.namespace, self.ns_lower))
3072 self.c.write('static void\n'
3073 '%sobject_manager_client_init (%sObjectManagerClient *manager)\n'
3076 '\n'%(self.ns_lower, self.namespace))
3077 self.c.write('static void\n'
3078 '%sobject_manager_client_class_init (%sObjectManagerClientClass *klass)\n'
3081 '\n'%(self.ns_lower, self.namespace))
3083 self.c.write(self.docbook_gen.expand(
3085 ' * %sobject_manager_client_get_proxy_type:\n'
3086 ' * @manager: A #GDBusObjectManagerClient.\n'
3087 ' * @object_path: The object path of the remote object (unused).\n'
3088 ' * @interface_name: (allow-none): Interface name of the remote object or %%NULL to get the object proxy #GType.\n'
3089 ' * @user_data: User data (unused).\n'
3091 ' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types.\n'
3093 ' * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %%NULL, otherwise the #GType for #%sObjectProxy.\n'
3094 %(self.ns_lower, self.namespace), False))
3095 self.c.write(' */\n')
3096 self.c.write('GType\n'
3097 '%sobject_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data)\n'
3100 self.c.write(' static gsize once_init_value = 0;\n'
3101 ' static GHashTable *lookup_hash;\n'
3104 ' if (interface_name == NULL)\n'
3105 ' return %sTYPE_OBJECT_PROXY;\n'
3106 ' if (g_once_init_enter (&once_init_value))\n'
3108 ' lookup_hash = g_hash_table_new (g_str_hash, g_str_equal);\n'
3110 for i in self.ifaces:
3111 self.c.write(' g_hash_table_insert (lookup_hash, (gpointer) "%s", GSIZE_TO_POINTER (%sTYPE_%s_PROXY));\n'
3112 %(i.name, i.ns_upper, i.name_upper))
3113 self.c.write(' g_once_init_leave (&once_init_value, 1);\n'
3115 self.c.write(' ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name));\n'
3116 ' if (ret == (GType) 0)\n'
3117 ' ret = G_TYPE_DBUS_PROXY;\n')
3118 self.c.write(' return ret;\n'
3123 self.c.write(self.docbook_gen.expand(
3125 ' * %sobject_manager_client_new:\n'
3126 ' * @connection: A #GDBusConnection.\n'
3127 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3128 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3129 ' * @object_path: An object path.\n'
3130 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3131 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3132 ' * @user_data: User data to pass to @callback.\n'
3134 ' * Asynchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details.\n'
3136 ' * 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'
3137 ' * You can then call %sobject_manager_client_new_finish() to get the result of the operation.\n'
3139 ' * See %sobject_manager_client_new_sync() for the synchronous, blocking version of this constructor.\n'
3140 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3141 self.c.write(' */\n')
3142 self.c.write('void\n'
3143 '%sobject_manager_client_new (\n'
3144 ' GDBusConnection *connection,\n'
3145 ' GDBusObjectManagerClientFlags flags,\n'
3146 ' const gchar *name,\n'
3147 ' const gchar *object_path,\n'
3148 ' GCancellable *cancellable,\n'
3149 ' GAsyncReadyCallback callback,\n'
3150 ' gpointer user_data)\n'
3152 ' 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'
3155 %(self.ns_lower, self.ns_upper, self.ns_lower))
3156 self.c.write('/**\n'
3157 ' * %sobject_manager_client_new_finish:\n'
3158 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new().\n'
3159 ' * @error: Return location for error or %%NULL\n'
3161 ' * Finishes an operation started with %sobject_manager_client_new().\n'
3163 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3164 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3165 self.c.write(' */\n')
3166 self.c.write('GDBusObjectManager *\n'
3167 '%sobject_manager_client_new_finish (\n'
3168 ' GAsyncResult *res,\n'
3169 ' GError **error)\n'
3172 ' GObject *source_object;\n'
3173 ' source_object = g_async_result_get_source_object (res);\n'
3174 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3175 ' g_object_unref (source_object);\n'
3176 ' if (ret != NULL)\n'
3177 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3183 self.c.write(self.docbook_gen.expand(
3185 ' * %sobject_manager_client_new_sync:\n'
3186 ' * @connection: A #GDBusConnection.\n'
3187 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3188 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3189 ' * @object_path: An object path.\n'
3190 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3191 ' * @error: Return location for error or %%NULL\n'
3193 ' * 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'
3195 ' * The calling thread is blocked until a reply is received.\n'
3197 ' * See %sobject_manager_client_new() for the asynchronous version of this constructor.\n'
3199 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3200 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3201 self.c.write(' */\n')
3202 self.c.write('GDBusObjectManager *\n'
3203 '%sobject_manager_client_new_sync (\n'
3204 ' GDBusConnection *connection,\n'
3205 ' GDBusObjectManagerClientFlags flags,\n'
3206 ' const gchar *name,\n'
3207 ' const gchar *object_path,\n'
3208 ' GCancellable *cancellable,\n'
3209 ' GError **error)\n'
3211 ' GInitable *ret;\n'
3212 ' 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'
3213 ' if (ret != NULL)\n'
3214 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3219 %(self.ns_lower, self.ns_upper, self.ns_lower))
3221 self.c.write(self.docbook_gen.expand(
3223 ' * %sobject_manager_client_new_for_bus:\n'
3224 ' * @bus_type: A #GBusType.\n'
3225 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3226 ' * @name: A bus name (well-known or unique).\n'
3227 ' * @object_path: An object path.\n'
3228 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3229 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3230 ' * @user_data: User data to pass to @callback.\n'
3232 ' * Like %sobject_manager_client_new() but takes a #GBusType instead of a #GDBusConnection.\n'
3234 ' * 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'
3235 ' * You can then call %sobject_manager_client_new_for_bus_finish() to get the result of the operation.\n'
3237 ' * See %sobject_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
3238 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3239 self.c.write(' */\n')
3240 self.c.write('void\n'
3241 '%sobject_manager_client_new_for_bus (\n'
3242 ' GBusType bus_type,\n'
3243 ' GDBusObjectManagerClientFlags flags,\n'
3244 ' const gchar *name,\n'
3245 ' const gchar *object_path,\n'
3246 ' GCancellable *cancellable,\n'
3247 ' GAsyncReadyCallback callback,\n'
3248 ' gpointer user_data)\n'
3250 ' 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'
3253 %(self.ns_lower, self.ns_upper, self.ns_lower))
3254 self.c.write('/**\n'
3255 ' * %sobject_manager_client_new_for_bus_finish:\n'
3256 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new_for_bus().\n'
3257 ' * @error: Return location for error or %%NULL\n'
3259 ' * Finishes an operation started with %sobject_manager_client_new_for_bus().\n'
3261 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3262 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3263 self.c.write(' */\n')
3264 self.c.write('GDBusObjectManager *\n'
3265 '%sobject_manager_client_new_for_bus_finish (\n'
3266 ' GAsyncResult *res,\n'
3267 ' GError **error)\n'
3270 ' GObject *source_object;\n'
3271 ' source_object = g_async_result_get_source_object (res);\n'
3272 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3273 ' g_object_unref (source_object);\n'
3274 ' if (ret != NULL)\n'
3275 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3281 self.c.write(self.docbook_gen.expand(
3283 ' * %sobject_manager_client_new_for_bus_sync:\n'
3284 ' * @bus_type: A #GBusType.\n'
3285 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3286 ' * @name: A bus name (well-known or unique).\n'
3287 ' * @object_path: An object path.\n'
3288 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3289 ' * @error: Return location for error or %%NULL\n'
3291 ' * Like %sobject_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
3293 ' * The calling thread is blocked until a reply is received.\n'
3295 ' * See %sobject_manager_client_new_for_bus() for the asynchronous version of this constructor.\n'
3297 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3298 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3299 self.c.write(' */\n')
3300 self.c.write('GDBusObjectManager *\n'
3301 '%sobject_manager_client_new_for_bus_sync (\n'
3302 ' GBusType bus_type,\n'
3303 ' GDBusObjectManagerClientFlags flags,\n'
3304 ' const gchar *name,\n'
3305 ' const gchar *object_path,\n'
3306 ' GCancellable *cancellable,\n'
3307 ' GError **error)\n'
3309 ' GInitable *ret;\n'
3310 ' 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'
3311 ' if (ret != NULL)\n'
3312 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3317 %(self.ns_lower, self.ns_upper, self.ns_lower))
3320 # ---------------------------------------------------------------------------------------------------
3322 def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
3323 if len(obj.since) > 0:
3326 %(indent, '', indent, '', obj.since))
3328 if isinstance(obj, dbustypes.Interface):
3329 thing = 'The D-Bus interface'
3330 elif isinstance(obj, dbustypes.Method):
3331 thing = 'The D-Bus method'
3332 elif isinstance(obj, dbustypes.Signal):
3333 thing = 'The D-Bus signal'
3334 elif isinstance(obj, dbustypes.Property):
3335 thing = 'The D-Bus property'
3337 raise RuntimeError('Cannot handle object ', obj)
3338 f.write(self.docbook_gen.expand(
3340 '%*s * Deprecated: %s has been deprecated.\n'
3341 %(indent, '', indent, '', thing), False))
3342 f.write('%*s */\n'%(indent, ''))
3344 # ---------------------------------------------------------------------------------------------------
3346 def generate_interface_intro(self, i):
3347 self.c.write('/* ------------------------------------------------------------------------\n'
3348 ' * Code for interface %s\n'
3349 ' * ------------------------------------------------------------------------\n'
3353 self.c.write(self.docbook_gen.expand(
3357 ' * @short_description: Generated C code for the %s D-Bus interface\n'
3359 ' * This section contains code for working with the #%s D-Bus interface in C.\n'
3361 %(i.camel_name, i.camel_name, i.name, i.name), False))
3365 self.generate_intro()
3366 self.declare_types()
3367 for i in self.ifaces:
3368 self.generate_interface_intro(i)
3369 self.generate_introspection_for_interface(i)
3370 self.generate_interface(i)
3371 self.generate_property_accessors(i)
3372 self.generate_signal_emitters(i)
3373 self.generate_method_calls(i)
3374 self.generate_method_completers(i)
3375 self.generate_proxy(i)
3376 self.generate_skeleton(i)
3377 if self.generate_objmanager:
3378 self.generate_object()
3379 self.generate_object_manager_client()
3380 self.generate_outro()