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) > 1:
41 self.ns_upper = utils.camel_case_to_uscore(namespace).upper() + '_'
42 self.ns_lower = utils.camel_case_to_uscore(namespace).lower() + '_'
46 self.interface_prefix = interface_prefix
47 self.header_guard = self.h.name.upper().replace('.', '_').replace('-', '_')
49 # ----------------------------------------------------------------------------------------------------
51 def generate_intro(self):
53 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
55 ' * The license of this code is the same as for the source it was derived from.\n'
59 self.c.write('#ifdef HAVE_CONFIG_H\n'
60 '# include "config.h"\n'
66 self.c.write('#ifdef G_OS_UNIX\n'
67 '# include <gio/gunixfdlist.h>\n'
71 self.c.write('typedef struct\n'
73 ' GDBusArgInfo parent_struct;\n'
74 ' gboolean use_gvariant;\n'
75 '} _ExtendedGDBusArgInfo;\n'
78 self.c.write('typedef struct\n'
80 ' GDBusMethodInfo parent_struct;\n'
81 ' const gchar *signal_name;\n'
82 ' gboolean pass_fdlist;\n'
83 '} _ExtendedGDBusMethodInfo;\n'
86 self.c.write('typedef struct\n'
88 ' GDBusSignalInfo parent_struct;\n'
89 ' const gchar *signal_name;\n'
90 '} _ExtendedGDBusSignalInfo;\n'
93 self.c.write('typedef struct\n'
95 ' GDBusPropertyInfo parent_struct;\n'
96 ' const gchar *hyphen_name;\n'
97 ' gboolean use_gvariant;\n'
98 '} _ExtendedGDBusPropertyInfo;\n'
101 self.c.write('typedef struct\n'
103 ' GDBusInterfaceInfo parent_struct;\n'
104 ' const gchar *hyphen_name;\n'
105 '} _ExtendedGDBusInterfaceInfo;\n'
108 self.c.write('typedef struct\n'
110 ' const _ExtendedGDBusPropertyInfo *info;\n'
112 ' GValue orig_value; /* the value before the change */\n'
113 '} ChangedProperty;\n'
116 '_changed_property_free (ChangedProperty *data)\n'
118 ' g_value_unset (&data->orig_value);\n'
123 self.c.write('static gboolean\n'
124 '_g_strv_equal0 (gchar **a, gchar **b)\n'
126 ' gboolean ret = FALSE;\n'
128 ' if (a == NULL && b == NULL)\n'
133 ' if (a == NULL || b == NULL)\n'
135 ' if (g_strv_length (a) != g_strv_length (b))\n'
137 ' for (n = 0; a[n] != NULL; n++)\n'
138 ' if (g_strcmp0 (a[n], b[n]) != 0)\n'
146 self.c.write('static gboolean\n'
147 '_g_variant_equal0 (GVariant *a, GVariant *b)\n'
149 ' gboolean ret = FALSE;\n'
150 ' if (a == NULL && b == NULL)\n'
155 ' if (a == NULL || b == NULL)\n'
157 ' ret = g_variant_equal (a, b);\n'
163 # simplified - only supports the types we use
164 self.c.write('G_GNUC_UNUSED static gboolean\n'
165 '_g_value_equal (const GValue *a, const GValue *b)\n'
167 ' gboolean ret = FALSE;\n'
168 ' g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b));\n'
169 ' switch (G_VALUE_TYPE (a))\n'
171 ' case G_TYPE_BOOLEAN:\n'
172 ' ret = (g_value_get_boolean (a) == g_value_get_boolean (b));\n'
174 ' case G_TYPE_UCHAR:\n'
175 ' ret = (g_value_get_uchar (a) == g_value_get_uchar (b));\n'
177 ' case G_TYPE_INT:\n'
178 ' ret = (g_value_get_int (a) == g_value_get_int (b));\n'
180 ' case G_TYPE_UINT:\n'
181 ' ret = (g_value_get_uint (a) == g_value_get_uint (b));\n'
183 ' case G_TYPE_INT64:\n'
184 ' ret = (g_value_get_int64 (a) == g_value_get_int64 (b));\n'
186 ' case G_TYPE_UINT64:\n'
187 ' ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n'
189 ' case G_TYPE_DOUBLE:\n'
190 ' ret = (g_value_get_double (a) == g_value_get_double (b));\n'
192 ' case G_TYPE_STRING:\n'
193 ' ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n'
195 ' case G_TYPE_VARIANT:\n'
196 ' ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b));\n'
199 ' if (G_VALUE_TYPE (a) == G_TYPE_STRV)\n'
200 ' ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b));\n'
202 ' g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a)));\n'
210 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
212 ' * The license of this code is the same as for the source it was derived from.\n'
217 '\n'%(config.VERSION, self.header_guard, self.header_guard))
218 self.h.write('#include <gio/gio.h>\n'
223 # ----------------------------------------------------------------------------------------------------
225 def declare_types(self):
226 for i in self.ifaces:
228 self.h.write('/* ------------------------------------------------------------------------ */\n')
229 self.h.write('/* Declarations for %s */\n'%i.name)
232 # First the GInterface
233 self.h.write('#define %sTYPE_%s (%s_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
234 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))
235 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))
236 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))
238 self.h.write('struct _%s;\n'%(i.camel_name))
239 self.h.write('typedef struct _%s %s;\n'%(i.camel_name, i.camel_name))
240 self.h.write('typedef struct _%sIface %sIface;\n'%(i.camel_name, i.camel_name))
242 self.h.write('struct _%sIface\n'%(i.camel_name))
244 self.h.write(' GTypeInterface parent_iface;\n')
246 function_pointers = {}
249 if len(i.methods) > 0:
253 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
255 key = (m.since, '_method_%s'%m.name_lower)
256 value = ' gboolean (*handle_%s) (\n'%(m.name_lower)
257 value += ' %s *object,\n'%(i.camel_name)
258 value += ' GDBusMethodInvocation *invocation'%()
260 value += ',\n GUnixFDList *fd_list'
262 value += ',\n %s%s'%(a.ctype_in, a.name)
264 function_pointers[key] = value
267 if len(i.signals) > 0:
270 key = (s.since, '_signal_%s'%s.name_lower)
271 value = ' void (*%s) (\n'%(s.name_lower)
272 value += ' %s *object'%(i.camel_name)
274 value += ',\n %s%s'%(a.ctype_in, a.name)
276 function_pointers[key] = value
278 # vfuncs for properties
279 if len(i.properties) > 0:
281 for p in i.properties:
282 key = (p.since, '_prop_get_%s'%p.name_lower)
283 value = ' %s (*get_%s) (%s *object);\n\n'%(p.arg.ctype_in, p.name_lower, i.camel_name)
284 function_pointers[key] = value
286 # Sort according to @since tag, then name.. this ensures
287 # that the function pointers don't change order assuming
288 # judicious use of @since
290 # Also use a proper version comparison function so e.g.
291 # 10.0 comes after 2.0.
293 # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
295 keys = function_pointers.keys()
297 keys.sort(cmp=utils.my_version_cmp)
299 self.h.write('%s'%function_pointers[key])
303 self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
305 self.h.write('GDBusInterfaceInfo *%s_interface_info (void);\n'%(i.name_lower))
306 self.h.write('guint %s_override_properties (GObjectClass *klass, guint property_id_begin);\n'%(i.name_lower))
309 # Then method call completion functions
310 if len(i.methods) > 0:
312 self.h.write('/* D-Bus method call completion functions: */\n')
315 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
318 self.h.write('G_GNUC_DEPRECATED ')
319 self.h.write('void %s_complete_%s (\n'
321 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
323 self.h.write(',\n GUnixFDList *fd_list')
325 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
330 # Then signal emission functions
331 if len(i.signals) > 0:
333 self.h.write('/* D-Bus signal emissions functions: */\n')
336 self.h.write('G_GNUC_DEPRECATED ')
337 self.h.write('void %s_emit_%s (\n'
338 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
340 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
345 # Then method call declarations
346 if len(i.methods) > 0:
348 self.h.write('/* D-Bus method calls: */\n')
351 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
355 self.h.write('G_GNUC_DEPRECATED ')
356 self.h.write('void %s_call_%s (\n'
357 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
359 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
361 self.h.write(',\n GUnixFDList *fd_list')
363 ' GCancellable *cancellable,\n'
364 ' GAsyncReadyCallback callback,\n'
365 ' gpointer user_data);\n')
369 self.h.write('G_GNUC_DEPRECATED ')
370 self.h.write('gboolean %s_call_%s_finish (\n'
371 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
373 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
375 self.h.write(',\n GUnixFDList **out_fd_list')
377 ' GAsyncResult *res,\n'
378 ' GError **error);\n')
382 self.h.write('G_GNUC_DEPRECATED ')
383 self.h.write('gboolean %s_call_%s_sync (\n'
384 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
386 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
388 self.h.write(',\n GUnixFDList *fd_list')
390 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
392 self.h.write(',\n GUnixFDList **out_fd_list')
394 ' GCancellable *cancellable,\n'
395 ' GError **error);\n')
399 # Then the property accessor declarations
400 if len(i.properties) > 0:
402 self.h.write('/* D-Bus property accessors: */\n')
403 for p in i.properties:
406 self.h.write('G_GNUC_DEPRECATED ')
407 self.h.write('%s%s_get_%s (%s *object);\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
408 if p.arg.free_func != None:
410 self.h.write('G_GNUC_DEPRECATED ')
411 self.h.write('%s%s_dup_%s (%s *object);\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name))
414 self.h.write('G_GNUC_DEPRECATED ')
415 self.h.write('void %s_set_%s (%s *object, %svalue);\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
420 self.h.write('/* ---- */\n')
422 self.h.write('#define %sTYPE_%s_PROXY (%s_proxy_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
423 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))
424 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))
425 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))
426 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))
427 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))
429 self.h.write('typedef struct _%sProxy %sProxy;\n'%(i.camel_name, i.camel_name))
430 self.h.write('typedef struct _%sProxyClass %sProxyClass;\n'%(i.camel_name, i.camel_name))
431 self.h.write('typedef struct _%sProxyPrivate %sProxyPrivate;\n'%(i.camel_name, i.camel_name))
433 self.h.write('struct _%sProxy\n'%(i.camel_name))
435 self.h.write(' /*< private >*/\n')
436 self.h.write(' GDBusProxy parent_instance;\n')
437 self.h.write(' %sProxyPrivate *priv;\n'%(i.camel_name))
440 self.h.write('struct _%sProxyClass\n'%(i.camel_name))
442 self.h.write(' GDBusProxyClass parent_class;\n')
445 self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
449 self.h.write('G_GNUC_DEPRECATED ')
450 self.h.write('void %s_proxy_new (\n'
451 ' GDBusConnection *connection,\n'
452 ' GDBusProxyFlags flags,\n'
453 ' const gchar *name,\n'
454 ' const gchar *object_path,\n'
455 ' GCancellable *cancellable,\n'
456 ' GAsyncReadyCallback callback,\n'
457 ' gpointer user_data);\n'
460 self.h.write('G_GNUC_DEPRECATED ')
461 self.h.write('%s *%s_proxy_new_finish (\n'
462 ' GAsyncResult *res,\n'
463 ' GError **error);\n'
464 %(i.camel_name, i.name_lower))
466 self.h.write('G_GNUC_DEPRECATED ')
467 self.h.write('%s *%s_proxy_new_sync (\n'
468 ' GDBusConnection *connection,\n'
469 ' GDBusProxyFlags flags,\n'
470 ' const gchar *name,\n'
471 ' const gchar *object_path,\n'
472 ' GCancellable *cancellable,\n'
473 ' GError **error);\n'
474 %(i.camel_name, i.name_lower))
477 self.h.write('G_GNUC_DEPRECATED ')
478 self.h.write('void %s_proxy_new_for_bus (\n'
479 ' GBusType bus_type,\n'
480 ' GDBusProxyFlags flags,\n'
481 ' const gchar *name,\n'
482 ' const gchar *object_path,\n'
483 ' GCancellable *cancellable,\n'
484 ' GAsyncReadyCallback callback,\n'
485 ' gpointer user_data);\n'
488 self.h.write('G_GNUC_DEPRECATED ')
489 self.h.write('%s *%s_proxy_new_for_bus_finish (\n'
490 ' GAsyncResult *res,\n'
491 ' GError **error);\n'
492 %(i.camel_name, i.name_lower))
494 self.h.write('G_GNUC_DEPRECATED ')
495 self.h.write('%s *%s_proxy_new_for_bus_sync (\n'
496 ' GBusType bus_type,\n'
497 ' GDBusProxyFlags flags,\n'
498 ' const gchar *name,\n'
499 ' const gchar *object_path,\n'
500 ' GCancellable *cancellable,\n'
501 ' GError **error);\n'
502 %(i.camel_name, i.name_lower))
507 self.h.write('/* ---- */\n')
509 self.h.write('#define %sTYPE_%s_SKELETON (%s_skeleton_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
510 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))
511 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))
512 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))
513 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))
514 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))
516 self.h.write('typedef struct _%sSkeleton %sSkeleton;\n'%(i.camel_name, i.camel_name))
517 self.h.write('typedef struct _%sSkeletonClass %sSkeletonClass;\n'%(i.camel_name, i.camel_name))
518 self.h.write('typedef struct _%sSkeletonPrivate %sSkeletonPrivate;\n'%(i.camel_name, i.camel_name))
520 self.h.write('struct _%sSkeleton\n'%(i.camel_name))
522 self.h.write(' /*< private >*/\n')
523 self.h.write(' GDBusInterfaceSkeleton parent_instance;\n')
524 self.h.write(' %sSkeletonPrivate *priv;\n'%(i.camel_name))
527 self.h.write('struct _%sSkeletonClass\n'%(i.camel_name))
529 self.h.write(' GDBusInterfaceSkeletonClass parent_class;\n')
532 self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
535 self.h.write('G_GNUC_DEPRECATED ')
536 self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
540 # Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
541 if self.generate_objmanager:
543 self.h.write('/* ---- */\n')
545 self.h.write('#define %sTYPE_OBJECT (%sobject_get_type ())\n'%(self.ns_upper, self.ns_lower))
546 self.h.write('#define %sOBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
547 self.h.write('#define %sIS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT))\n'%(self.ns_upper, self.ns_upper))
548 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))
550 self.h.write('struct _%sObject;\n'%(self.namespace))
551 self.h.write('typedef struct _%sObject %sObject;\n'%(self.namespace, self.namespace))
552 self.h.write('typedef struct _%sObjectIface %sObjectIface;\n'%(self.namespace, self.namespace))
554 self.h.write('struct _%sObjectIface\n'%(self.namespace))
556 ' GTypeInterface parent_iface;\n'
559 self.h.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
562 for i in self.ifaces:
564 self.h.write('G_GNUC_DEPRECATED ')
565 self.h.write ('%s *%sobject_get_%s (%sObject *object);\n'
566 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
567 for i in self.ifaces:
569 self.h.write('G_GNUC_DEPRECATED ')
570 self.h.write ('%s *%sobject_peek_%s (%sObject *object);\n'
571 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
573 self.h.write('#define %sTYPE_OBJECT_PROXY (%sobject_proxy_get_type ())\n'%(self.ns_upper, self.ns_lower))
574 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))
575 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))
576 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))
577 self.h.write('#define %sIS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
578 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))
580 self.h.write('typedef struct _%sObjectProxy %sObjectProxy;\n'%(self.namespace, self.namespace))
581 self.h.write('typedef struct _%sObjectProxyClass %sObjectProxyClass;\n'%(self.namespace, self.namespace))
582 self.h.write('typedef struct _%sObjectProxyPrivate %sObjectProxyPrivate;\n'%(self.namespace, self.namespace))
584 self.h.write('struct _%sObjectProxy\n'%(self.namespace))
586 self.h.write(' /*< private >*/\n')
587 self.h.write(' GDBusObjectProxy parent_instance;\n')
588 self.h.write(' %sObjectProxyPrivate *priv;\n'%(self.namespace))
591 self.h.write('struct _%sObjectProxyClass\n'%(self.namespace))
593 self.h.write(' GDBusObjectProxyClass parent_class;\n')
596 self.h.write('GType %sobject_proxy_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
597 self.h.write('%sObjectProxy *%sobject_proxy_new (GDBusConnection *connection, const gchar *object_path);\n'%(self.namespace, self.ns_lower))
599 self.h.write('#define %sTYPE_OBJECT_SKELETON (%sobject_skeleton_get_type ())\n'%(self.ns_upper, self.ns_lower))
600 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))
601 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))
602 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))
603 self.h.write('#define %sIS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
604 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))
606 self.h.write('typedef struct _%sObjectSkeleton %sObjectSkeleton;\n'%(self.namespace, self.namespace))
607 self.h.write('typedef struct _%sObjectSkeletonClass %sObjectSkeletonClass;\n'%(self.namespace, self.namespace))
608 self.h.write('typedef struct _%sObjectSkeletonPrivate %sObjectSkeletonPrivate;\n'%(self.namespace, self.namespace))
610 self.h.write('struct _%sObjectSkeleton\n'%(self.namespace))
612 self.h.write(' /*< private >*/\n')
613 self.h.write(' GDBusObjectSkeleton parent_instance;\n')
614 self.h.write(' %sObjectSkeletonPrivate *priv;\n'%(self.namespace))
617 self.h.write('struct _%sObjectSkeletonClass\n'%(self.namespace))
619 self.h.write(' GDBusObjectSkeletonClass parent_class;\n')
622 self.h.write('GType %sobject_skeleton_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
623 self.h.write('%sObjectSkeleton *%sobject_skeleton_new (const gchar *object_path);\n'
624 %(self.namespace, self.ns_lower))
625 for i in self.ifaces:
627 self.h.write('G_GNUC_DEPRECATED ')
628 self.h.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_);\n'
629 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
632 self.h.write('/* ---- */\n')
634 self.h.write('#define %sTYPE_OBJECT_MANAGER_CLIENT (%sobject_manager_client_get_type ())\n'%(self.ns_upper, self.ns_lower))
635 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))
636 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))
637 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))
638 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))
639 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))
641 self.h.write('typedef struct _%sObjectManagerClient %sObjectManagerClient;\n'%(self.namespace, self.namespace))
642 self.h.write('typedef struct _%sObjectManagerClientClass %sObjectManagerClientClass;\n'%(self.namespace, self.namespace))
643 self.h.write('typedef struct _%sObjectManagerClientPrivate %sObjectManagerClientPrivate;\n'%(self.namespace, self.namespace))
645 self.h.write('struct _%sObjectManagerClient\n'%(self.namespace))
647 self.h.write(' /*< private >*/\n')
648 self.h.write(' GDBusObjectManagerClient parent_instance;\n')
649 self.h.write(' %sObjectManagerClientPrivate *priv;\n'%(self.namespace))
652 self.h.write('struct _%sObjectManagerClientClass\n'%(self.namespace))
654 self.h.write(' GDBusObjectManagerClientClass parent_class;\n')
657 self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
659 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))
661 self.h.write('void %sobject_manager_client_new (\n'
662 ' GDBusConnection *connection,\n'
663 ' GDBusObjectManagerClientFlags flags,\n'
664 ' const gchar *name,\n'
665 ' const gchar *object_path,\n'
666 ' GCancellable *cancellable,\n'
667 ' GAsyncReadyCallback callback,\n'
668 ' gpointer user_data);\n'
670 self.h.write('GDBusObjectManager *%sobject_manager_client_new_finish (\n'
671 ' GAsyncResult *res,\n'
672 ' GError **error);\n'
674 self.h.write('GDBusObjectManager *%sobject_manager_client_new_sync (\n'
675 ' GDBusConnection *connection,\n'
676 ' GDBusObjectManagerClientFlags flags,\n'
677 ' const gchar *name,\n'
678 ' const gchar *object_path,\n'
679 ' GCancellable *cancellable,\n'
680 ' GError **error);\n'
683 self.h.write('void %sobject_manager_client_new_for_bus (\n'
684 ' GBusType bus_type,\n'
685 ' GDBusObjectManagerClientFlags flags,\n'
686 ' const gchar *name,\n'
687 ' const gchar *object_path,\n'
688 ' GCancellable *cancellable,\n'
689 ' GAsyncReadyCallback callback,\n'
690 ' gpointer user_data);\n'
692 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_finish (\n'
693 ' GAsyncResult *res,\n'
694 ' GError **error);\n'
696 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_sync (\n'
697 ' GBusType bus_type,\n'
698 ' GDBusObjectManagerClientFlags flags,\n'
699 ' const gchar *name,\n'
700 ' const gchar *object_path,\n'
701 ' GCancellable *cancellable,\n'
702 ' GError **error);\n'
706 # ----------------------------------------------------------------------------------------------------
708 def generate_outro(self):
712 '#endif /* __%s__ */\n'%(self.header_guard))
714 # ----------------------------------------------------------------------------------------------------
716 def generate_annotations(self, prefix, annotations):
717 if annotations == None:
721 for a in annotations:
722 #self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
724 # skip internal annotations
725 if a.key.startswith('org.gtk.GDBus'):
728 self.c.write('static const GDBusAnnotationInfo %s_%d =\n'
732 ' "%s",\n'%(prefix, n, a.key, a.value))
733 if len(a.annotations) == 0:
734 self.c.write(' NULL\n')
736 self.c.write(' (GDBusAnnotationInfo **) &%s_%d_pointers\n'%(prefix, n))
742 self.c.write('static const GDBusAnnotationInfo * const %s_pointers[] =\n'
745 for a in annotations:
746 if a.key.startswith('org.gtk.GDBus'):
748 self.c.write(' &%s_%d,\n'%(prefix, m))
750 self.c.write(' NULL\n'
755 def generate_args(self, prefix, args):
757 num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
759 self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
764 ' "%s",\n'%(prefix, a.name, a.name, a.signature))
766 self.c.write(' NULL\n')
768 self.c.write(' (GDBusAnnotationInfo **) &%s_arg_%s_annotation_info_pointers\n'%(prefix, a.name))
769 self.c.write(' },\n')
770 if not utils.lookup_annotation(a.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
771 self.c.write(' FALSE\n')
773 self.c.write(' TRUE\n')
778 self.c.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
781 self.c.write(' &%s_%s,\n'%(prefix, a.name))
782 self.c.write(' NULL\n'
786 def generate_introspection_for_interface(self, i):
787 self.c.write('/* ---- Introspection data for %s ---- */\n'
790 if len(i.methods) > 0:
793 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
795 self.generate_args('_%s_method_info_%s_IN_ARG'%(i.name_lower, m.name_lower), m.in_args)
796 self.generate_args('_%s_method_info_%s_OUT_ARG'%(i.name_lower, m.name_lower), m.out_args)
798 num_anno = self.generate_annotations('_%s_method_%s_annotation_info'%(i.name_lower, m.name_lower), m.annotations)
800 self.c.write('static const _ExtendedGDBusMethodInfo _%s_method_info_%s =\n'
804 ' "%s",\n'%(i.name_lower, m.name_lower, m.name))
805 if len(m.in_args) == 0:
806 self.c.write(' NULL,\n')
808 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_IN_ARG_pointers,\n'%(i.name_lower, m.name_lower))
809 if len(m.out_args) == 0:
810 self.c.write(' NULL,\n')
812 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_OUT_ARG_pointers,\n'%(i.name_lower, m.name_lower))
814 self.c.write(' NULL\n')
816 self.c.write(' (GDBusAnnotationInfo **) &_%s_method_%s_annotation_info_pointers\n'%(i.name_lower, m.name_lower))
820 %(m.name_hyphen, 'TRUE' if unix_fd else 'FALSE'))
824 self.c.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] =\n'
825 '{\n'%(i.name_lower))
827 self.c.write(' &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
828 self.c.write(' NULL\n'
834 if len(i.signals) > 0:
836 self.generate_args('_%s_signal_info_%s_ARG'%(i.name_lower, s.name_lower), s.args)
838 num_anno = self.generate_annotations('_%s_signal_%s_annotation_info'%(i.name_lower, s.name_lower), s.annotations)
839 self.c.write('static const _ExtendedGDBusSignalInfo _%s_signal_info_%s =\n'
843 ' "%s",\n'%(i.name_lower, s.name_lower, s.name))
845 self.c.write(' NULL,\n')
847 self.c.write(' (GDBusArgInfo **) &_%s_signal_info_%s_ARG_pointers,\n'%(i.name_lower, s.name_lower))
849 self.c.write(' NULL\n')
851 self.c.write(' (GDBusAnnotationInfo **) &_%s_signal_%s_annotation_info_pointers\n'%(i.name_lower, s.name_lower))
858 self.c.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
859 '{\n'%(i.name_lower))
861 self.c.write(' &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
862 self.c.write(' NULL\n'
868 if len(i.properties) > 0:
869 for p in i.properties:
870 if p.readable and p.writable:
871 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
873 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE'
875 access = 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
877 access = 'G_DBUS_PROPERTY_INFO_FLAGS_NONE'
878 num_anno = self.generate_annotations('_%s_property_%s_annotation_info'%(i.name_lower, p.name_lower), p.annotations)
879 self.c.write('static const _ExtendedGDBusPropertyInfo _%s_property_info_%s =\n'
885 ' %s,\n'%(i.name_lower, p.name_lower, p.name, p.arg.signature, access))
887 self.c.write(' NULL\n')
889 self.c.write(' (GDBusAnnotationInfo **) &_%s_property_%s_annotation_info_pointers\n'%(i.name_lower, p.name_lower))
893 if not utils.lookup_annotation(p.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
894 self.c.write(' FALSE\n')
896 self.c.write(' TRUE\n')
900 self.c.write('static const _ExtendedGDBusPropertyInfo * const _%s_property_info_pointers[] =\n'
901 '{\n'%(i.name_lower))
902 for p in i.properties:
903 self.c.write(' &_%s_property_info_%s,\n'%(i.name_lower, p.name_lower))
904 self.c.write(' NULL\n'
908 num_anno = self.generate_annotations('_%s_annotation_info'%(i.name_lower), i.annotations)
909 self.c.write('static const _ExtendedGDBusInterfaceInfo _%s_interface_info =\n'
913 ' "%s",\n'%(i.name_lower, i.name))
914 if len(i.methods) == 0:
915 self.c.write(' NULL,\n')
917 self.c.write(' (GDBusMethodInfo **) &_%s_method_info_pointers,\n'%(i.name_lower))
918 if len(i.signals) == 0:
919 self.c.write(' NULL,\n')
921 self.c.write(' (GDBusSignalInfo **) &_%s_signal_info_pointers,\n'%(i.name_lower))
922 if len(i.properties) == 0:
923 self.c.write(' NULL,\n')
925 self.c.write(' (GDBusPropertyInfo **) &_%s_property_info_pointers,\n'%(i.name_lower))
927 self.c.write(' NULL\n')
929 self.c.write(' (GDBusAnnotationInfo **) &_%s_annotation_info_pointers\n'%(i.name_lower))
936 self.c.write(self.docbook_gen.expand(
938 ' * %s_interface_info:\n'
940 ' * Gets a machine-readable description of the #%s D-Bus interface.\n'
942 ' * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free.\n'
943 %(i.name_lower, i.name), False))
944 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
945 self.c.write('GDBusInterfaceInfo *\n'
946 '%s_interface_info (void)\n'
948 ' return (GDBusInterfaceInfo *) &_%s_interface_info;\n'
950 '\n'%(i.name_lower, i.name_lower))
952 self.c.write(self.docbook_gen.expand(
954 ' * %s_override_properties:\n'
955 ' * @klass: The class structure for a #GObject<!-- -->-derived class.\n'
956 ' * @property_id_begin: The property id to assign to the first overridden property.\n'
958 ' * Overrides all #GObject properties in the #%s interface for a concrete class.\n'
959 ' * The properties are overridden in the order they are defined.\n'
961 ' * Returns: The last property id.\n'
962 %(i.name_lower, i.camel_name), False))
963 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
964 self.c.write('guint\n'
965 '%s_override_properties (GObjectClass *klass, guint property_id_begin)\n'
966 '{\n'%(i.name_lower))
967 for p in i.properties:
968 self.c.write (' g_object_class_override_property (klass, property_id_begin++, "%s");\n'%(p.name_hyphen))
969 self.c.write(' return property_id_begin - 1;\n'
974 # ----------------------------------------------------------------------------------------------------
976 def generate_interface(self, i):
979 self.c.write(self.docbook_gen.expand(
983 ' * Abstract interface type for the D-Bus interface #%s.\n'
984 %(i.camel_name, i.name), False))
985 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
988 self.c.write(self.docbook_gen.expand(
991 ' * @parent_iface: The parent interface.\n'
992 %(i.camel_name), False))
995 if len(i.methods) > 0:
997 key = (m.since, '_method_%s'%m.name_lower)
998 value = '@handle_%s: '%(m.name_lower)
999 value += 'Handler for the #%s::handle-%s signal.'%(i.camel_name, m.name_hyphen)
1000 doc_bits[key] = value
1001 if len(i.signals) > 0:
1003 key = (s.since, '_signal_%s'%s.name_lower)
1004 value = '@%s: '%(s.name_lower)
1005 value += 'Handler for the #%s::%s signal.'%(i.camel_name, s.name_hyphen)
1006 doc_bits[key] = value
1007 if len(i.properties) > 0:
1008 for p in i.properties:
1009 key = (p.since, '_prop_get_%s'%p.name_lower)
1010 value = '@get_%s: '%(p.name_lower)
1011 value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
1012 doc_bits[key] = value
1013 keys = doc_bits.keys()
1015 keys.sort(cmp=utils.my_version_cmp)
1017 self.c.write(' * %s\n'%doc_bits[key])
1018 self.c.write(self.docbook_gen.expand(
1020 ' * Virtual table for the D-Bus interface #%s.\n'
1022 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1025 self.c.write('static void\n'
1026 '%s_default_init (%sIface *iface)\n'
1027 '{\n'%(i.name_lower, i.camel_name));
1029 if len(i.methods) > 0:
1030 self.c.write(' /* GObject signals for incoming D-Bus method calls: */\n')
1033 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1035 self.c.write(self.docbook_gen.expand(
1037 ' * %s::handle-%s:\n'
1038 ' * @object: A #%s.\n'
1039 ' * @invocation: A #GDBusMethodInvocation.\n'
1040 %(i.camel_name, m.name_hyphen, i.camel_name), False))
1042 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1044 self.c.write (' * @%s: Argument passed by remote caller.\n'%(a.name))
1045 self.c.write(self.docbook_gen.expand(
1047 ' * Signal emitted when a remote caller is invoking the %s.%s() D-Bus method.\n'
1049 ' * 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'
1051 ' * Returns: %%TRUE if the invocation was handled, %%FALSE to let other signal handlers run.\n'
1052 %(i.name, m.name, i.name_lower, m.name_lower), False))
1053 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 2)
1058 self.c.write(' g_signal_new ("handle-%s",\n'
1059 ' G_TYPE_FROM_INTERFACE (iface),\n'
1060 ' G_SIGNAL_RUN_LAST,\n'
1061 ' G_STRUCT_OFFSET (%sIface, handle_%s),\n'
1062 ' g_signal_accumulator_true_handled,\n'
1063 ' NULL,\n' # accu_data
1064 ' g_cclosure_marshal_generic,\n'
1065 ' G_TYPE_BOOLEAN,\n'
1067 ' G_TYPE_DBUS_METHOD_INVOCATION'
1068 %(m.name_hyphen, i.camel_name, m.name_lower, len(m.in_args) + extra_args))
1070 self.c.write(', G_TYPE_UNIX_FD_LIST')
1072 self.c.write (', %s'%(a.gtype))
1073 self.c.write(');\n')
1076 if len(i.signals) > 0:
1077 self.c.write(' /* GObject signals for received D-Bus signals: */\n')
1079 self.c.write(self.docbook_gen.expand(
1082 ' * @object: A #%s.\n'
1083 %(i.camel_name, s.name_hyphen, i.camel_name), False))
1085 self.c.write (' * @%s: Argument.\n'%(a.name))
1086 self.c.write(self.docbook_gen.expand(
1088 ' * On the client-side, this signal is emitted whenever the D-Bus signal #%s::%s is received.\n'
1090 ' * 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'
1091 %(i.name, s.name), False))
1092 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 2)
1093 self.c.write(' g_signal_new ("%s",\n'
1094 ' G_TYPE_FROM_INTERFACE (iface),\n'
1095 ' G_SIGNAL_RUN_LAST,\n'
1096 ' G_STRUCT_OFFSET (%sIface, %s),\n'
1097 ' NULL,\n' # accumulator
1098 ' NULL,\n' # accu_data
1099 ' g_cclosure_marshal_generic,\n'
1102 %(s.name_hyphen, i.camel_name, s.name_lower, len(s.args)))
1104 self.c.write (', %s'%(a.gtype))
1105 self.c.write(');\n')
1108 if len(i.properties) > 0:
1109 self.c.write(' /* GObject properties for D-Bus properties: */\n')
1110 for p in i.properties:
1111 if p.readable and p.writable:
1112 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.'
1114 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.'
1116 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.'
1118 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1119 self.c.write(self.docbook_gen.expand(
1123 ' * Represents the D-Bus property #%s:%s.\n'
1126 %(i.camel_name, p.name_hyphen, i.name, p.name, hint), False))
1127 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 2)
1128 self.c.write(' g_object_interface_install_property (iface,\n')
1129 if p.arg.gtype == 'G_TYPE_VARIANT':
1130 s = 'g_param_spec_variant ("%s", "%s", "%s", G_VARIANT_TYPE ("%s"), NULL'%(p.name_hyphen, p.name, p.name, p.arg.signature)
1131 elif p.arg.signature == 'b':
1132 s = 'g_param_spec_boolean ("%s", "%s", "%s", FALSE'%(p.name_hyphen, p.name, p.name)
1133 elif p.arg.signature == 'y':
1134 s = 'g_param_spec_uchar ("%s", "%s", "%s", 0, 255, 0'%(p.name_hyphen, p.name, p.name)
1135 elif p.arg.signature == 'n':
1136 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT16, G_MAXINT16, 0'%(p.name_hyphen, p.name, p.name)
1137 elif p.arg.signature == 'q':
1138 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT16, 0'%(p.name_hyphen, p.name, p.name)
1139 elif p.arg.signature == 'i':
1140 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT32, G_MAXINT32, 0'%(p.name_hyphen, p.name, p.name)
1141 elif p.arg.signature == 'u':
1142 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT32, 0'%(p.name_hyphen, p.name, p.name)
1143 elif p.arg.signature == 'x':
1144 s = 'g_param_spec_int64 ("%s", "%s", "%s", G_MININT64, G_MAXINT64, 0'%(p.name_hyphen, p.name, p.name)
1145 elif p.arg.signature == 't':
1146 s = 'g_param_spec_uint64 ("%s", "%s", "%s", 0, G_MAXUINT64, 0'%(p.name_hyphen, p.name, p.name)
1147 elif p.arg.signature == 'd':
1148 s = 'g_param_spec_double ("%s", "%s", "%s", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0'%(p.name_hyphen, p.name, p.name)
1149 elif p.arg.signature == 's':
1150 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1151 elif p.arg.signature == 'o':
1152 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1153 elif p.arg.signature == 'g':
1154 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1155 elif p.arg.signature == 'ay':
1156 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1157 elif p.arg.signature == 'as':
1158 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1159 elif p.arg.signature == 'ao':
1160 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1161 elif p.arg.signature == 'aay':
1162 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1164 raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
1165 self.c.write(' %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
1171 self.c.write('typedef %sIface %sInterface;\n'%(i.camel_name, i.camel_name))
1172 self.c.write('G_DEFINE_INTERFACE (%s, %s, G_TYPE_OBJECT);\n'%(i.camel_name, i.name_lower))
1175 # ----------------------------------------------------------------------------------------------------
1177 def generate_property_accessors(self, i):
1178 for p in i.properties:
1180 if p.readable and p.writable:
1181 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.'
1183 hint = 'Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.'
1185 hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
1187 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1188 self.c.write(self.docbook_gen.expand(
1190 ' * %s_get_%s: (skip)\n'
1191 ' * @object: A #%s.\n'
1193 ' * Gets the value of the #%s:%s D-Bus property.\n'
1197 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1198 if p.arg.free_func != None:
1199 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'
1201 ' * 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'
1202 %(i.name_lower, p.name_lower))
1204 self.c.write(' * Returns: The property value.\n')
1205 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1207 '%s_get_%s (%s *object)\n'
1208 '{\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
1209 self.c.write(' return %s%s_GET_IFACE (object)->get_%s (object);\n'%(i.ns_upper, i.name_upper, p.name_lower))
1212 if p.arg.free_func != None:
1214 self.c.write(self.docbook_gen.expand(
1216 ' * %s_dup_%s: (skip)\n'
1217 ' * @object: A #%s.\n'
1219 ' * Gets a copy of the #%s:%s D-Bus property.\n'
1223 ' * Returns: (transfer full): The property value or %%NULL if the property is not set. The returned value should be freed with %s().\n'
1224 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint, p.arg.free_func), False))
1225 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1227 '%s_dup_%s (%s *object)\n'
1229 ' %svalue;\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in_dup))
1230 self.c.write(' g_object_get (G_OBJECT (object), "%s", &value, NULL);\n'%(p.name_hyphen))
1231 self.c.write(' return value;\n')
1236 if p.readable and p.writable:
1237 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.'
1239 hint = 'Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.'
1241 hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
1243 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1244 self.c.write(self.docbook_gen.expand(
1246 ' * %s_set_%s: (skip)\n'
1247 ' * @object: A #%s.\n'
1248 ' * @value: The value to set.\n'
1250 ' * Sets the #%s:%s D-Bus property to @value.\n'
1253 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1254 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1255 self.c.write('void\n'
1256 '%s_set_%s (%s *object, %svalue)\n'
1257 '{\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
1258 self.c.write(' g_object_set (G_OBJECT (object), "%s", value, NULL);\n'%(p.name_hyphen))
1262 # ---------------------------------------------------------------------------------------------------
1264 def generate_signal_emitters(self, i):
1266 self.c.write(self.docbook_gen.expand(
1269 ' * @object: A #%s.\n'
1270 %(i.name_lower, s.name_lower, i.camel_name), False))
1272 self.c.write(' * @%s: Argument to pass with the signal.\n'%(a.name))
1273 self.c.write(self.docbook_gen.expand(
1275 ' * Emits the #%s::%s D-Bus signal.\n'
1276 %(i.name, s.name), False))
1277 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 0)
1278 self.c.write('void\n'
1280 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
1282 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1285 ' g_signal_emit_by_name (object, "%s"'%(s.name_hyphen))
1287 self.c.write(', %s'%a.name)
1288 self.c.write(');\n')
1292 # ---------------------------------------------------------------------------------------------------
1294 def generate_method_calls(self, i):
1297 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1300 self.c.write('/**\n'
1302 ' * @proxy: A #%sProxy.\n'
1303 %(i.name_lower, m.name_lower, i.camel_name))
1305 self.c.write(' * @%s: Argument to pass with the method invocation.\n'%(a.name))
1307 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1308 self.c.write(self.docbook_gen.expand(
1309 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1310 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %%NULL.\n'
1311 ' * @user_data: User data to pass to @callback.\n'
1313 ' * Asynchronously invokes the %s.%s() D-Bus method on @proxy.\n'
1314 ' * 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'
1315 ' * You can then call %s_call_%s_finish() to get the result of the operation.\n'
1317 ' * See %s_call_%s_sync() for the synchronous, blocking version of this method.\n'
1318 %(i.name, m.name, i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1319 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1320 self.c.write('void\n'
1322 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1324 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1326 self.c.write(',\n GUnixFDList *fd_list')
1328 ' GCancellable *cancellable,\n'
1329 ' GAsyncReadyCallback callback,\n'
1330 ' gpointer user_data)\n'
1333 self.c.write(' g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy),\n')
1335 self.c.write(' g_dbus_proxy_call (G_DBUS_PROXY (proxy),\n')
1336 self.c.write(' "%s",\n'
1337 ' g_variant_new ("('%(m.name))
1339 self.c.write('%s'%(a.format_in))
1342 self.c.write(',\n %s'%(a.name))
1344 ' G_DBUS_CALL_FLAGS_NONE,\n'
1347 self.c.write(' fd_list,\n')
1348 self.c.write(' cancellable,\n'
1354 self.c.write('/**\n'
1355 ' * %s_call_%s_finish:\n'
1356 ' * @proxy: A #%sProxy.\n'
1357 %(i.name_lower, m.name_lower, i.camel_name))
1358 for a in m.out_args:
1359 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1361 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1362 self.c.write(self.docbook_gen.expand(
1363 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_call_%s().\n'
1364 ' * @error: Return location for error or %%NULL.\n'
1366 ' * Finishes an operation started with %s_call_%s().\n'
1368 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1369 %(i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1370 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1371 self.c.write('gboolean\n'
1372 '%s_call_%s_finish (\n'
1373 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1374 for a in m.out_args:
1375 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1377 self.c.write(',\n GUnixFDList **out_fd_list')
1379 ' GAsyncResult *res,\n'
1380 ' GError **error)\n'
1382 ' GVariant *_ret;\n')
1384 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error);\n')
1386 self.c.write(' _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);\n')
1387 self.c.write(' if (_ret == NULL)\n'
1389 self.c.write(' g_variant_get (_ret,\n'
1391 for a in m.out_args:
1392 self.c.write('%s'%(a.format_out))
1394 for a in m.out_args:
1395 self.c.write(',\n out_%s'%(a.name))
1397 ' g_variant_unref (_ret);\n')
1398 self.c.write('_out:\n'
1399 ' return _ret != NULL;\n'
1405 self.c.write('/**\n'
1406 ' * %s_call_%s_sync:\n'
1407 ' * @proxy: A #%sProxy.\n'
1408 %(i.name_lower, m.name_lower, i.camel_name))
1410 self.c.write(' * @%s: Argument to pass with the method invocation.\n'%(a.name))
1412 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1413 for a in m.out_args:
1414 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1416 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1417 self.c.write(self.docbook_gen.expand(
1418 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1419 ' * @error: Return location for error or %%NULL.\n'
1421 ' * Synchronously invokes the %s.%s() D-Bus method on @proxy. The calling thread is blocked until a reply is received.\n'
1423 ' * See %s_call_%s() for the asynchronous version of this method.\n'
1425 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1426 %(i.name, m.name, i.name_lower, m.name_lower), False))
1427 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1428 self.c.write('gboolean\n'
1429 '%s_call_%s_sync (\n'
1430 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1432 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1434 self.c.write(',\n GUnixFDList *fd_list')
1435 for a in m.out_args:
1436 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1438 self.c.write(',\n GUnixFDList **out_fd_list')
1440 ' GCancellable *cancellable,\n'
1441 ' GError **error)\n'
1443 ' GVariant *_ret;\n')
1445 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy),\n')
1447 self.c.write(' _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),\n')
1448 self.c.write(' "%s",\n'
1449 ' g_variant_new ("('%(m.name))
1451 self.c.write('%s'%(a.format_in))
1454 self.c.write(',\n %s'%(a.name))
1456 ' G_DBUS_CALL_FLAGS_NONE,\n'
1459 self.c.write(' fd_list,\n'
1461 self.c.write(' cancellable,\n'
1463 ' if (_ret == NULL)\n'
1465 self.c.write(' g_variant_get (_ret,\n'
1467 for a in m.out_args:
1468 self.c.write('%s'%(a.format_out))
1470 for a in m.out_args:
1471 self.c.write(',\n out_%s'%(a.name))
1473 ' g_variant_unref (_ret);\n')
1474 self.c.write('_out:\n'
1475 ' return _ret != NULL;\n'
1479 # ---------------------------------------------------------------------------------------------------
1481 def generate_method_completers(self, i):
1484 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1486 self.c.write('/**\n'
1487 ' * %s_complete_%s:\n'
1488 ' * @object: A #%s.\n'
1489 ' * @invocation: (transfer full): A #GDBusMethodInvocation.\n'
1490 %(i.name_lower, m.name_lower, i.camel_name))
1492 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1493 for a in m.out_args:
1494 self.c.write(' * @%s: Parameter to return.\n'%(a.name))
1495 self.c.write(self.docbook_gen.expand(
1497 ' * 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'
1499 ' * This method will free @invocation, you cannot use it afterwards.\n'
1500 %(i.name, m.name), False))
1501 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1502 self.c.write('void\n'
1503 '%s_complete_%s (\n'
1505 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
1507 self.c.write(',\n GUnixFDList *fd_list')
1508 for a in m.out_args:
1509 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1514 self.c.write(' g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,\n'
1515 ' g_variant_new ("(')
1517 self.c.write(' g_dbus_method_invocation_return_value (invocation,\n'
1518 ' g_variant_new ("(')
1519 for a in m.out_args:
1520 self.c.write('%s'%(a.format_in))
1522 for a in m.out_args:
1523 self.c.write(',\n %s'%(a.name))
1525 self.c.write('),\n fd_list);\n')
1527 self.c.write('));\n')
1531 # ---------------------------------------------------------------------------------------------------
1533 def generate_proxy(self, i):
1535 self.c.write('/* ------------------------------------------------------------------------ */\n'
1538 self.c.write(self.docbook_gen.expand(
1542 ' * The #%sProxy structure contains only private data and should only be accessed using the provided API.\n'
1543 %(i.camel_name, i.camel_name), False))
1544 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1547 self.c.write(self.docbook_gen.expand(
1549 ' * %sProxyClass:\n'
1550 ' * @parent_class: The parent class.\n'
1552 ' * Class structure for #%sProxy.\n'
1553 %(i.camel_name, i.camel_name), False))
1554 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1557 self.c.write('struct _%sProxyPrivate\n'
1563 self.c.write('static void %s_proxy_iface_init (%sIface *iface);\n'
1564 '\n'%(i.name_lower, i.camel_name))
1565 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1566 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1569 self.c.write('static void\n'
1570 '%s_proxy_finalize (GObject *object)\n'
1571 '{\n'%(i.name_lower))
1572 self.c.write(' %sProxy *proxy = %s%s_PROXY (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
1573 self.c.write(' g_datalist_clear (&proxy->priv->qdata);\n')
1574 self.c.write(' G_OBJECT_CLASS (%s_proxy_parent_class)->finalize (object);\n'
1576 '\n'%(i.name_lower))
1578 # property accessors
1580 # Note that we are guaranteed that prop_id starts at 1 and is
1581 # laid out in the same order as introspection data pointers
1583 self.c.write('static void\n'
1584 '%s_proxy_get_property (GObject *object,\n'
1587 ' GParamSpec *pspec)\n'
1588 '{\n'%(i.name_lower))
1589 if len(i.properties) > 0:
1590 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1591 ' GVariant *variant;\n'
1592 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1593 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1594 ' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
1595 ' if (info->use_gvariant)\n'
1597 ' g_value_set_variant (value, variant);\n'
1601 # could be that we don't have the value in cache - in that case, we do
1602 # nothing and the user gets the default value for the GType
1603 ' if (variant != NULL)\n'
1604 ' g_dbus_gvariant_to_gvalue (variant, value);\n'
1606 ' if (variant != NULL)\n'
1607 ' g_variant_unref (variant);\n'
1608 %(len(i.properties), i.name_lower))
1611 if len(i.properties) > 0:
1612 self.c.write('static void\n'
1613 '%s_proxy_set_property_cb (GDBusProxy *proxy,\n'
1614 ' GAsyncResult *res,\n'
1615 ' gpointer user_data)\n'
1616 '{\n'%(i.name_lower))
1617 self.c.write(' const _ExtendedGDBusPropertyInfo *info = user_data;\n'
1620 ' if (!g_dbus_proxy_call_finish (proxy, res, &error))\n'
1622 ' g_warning ("Error setting property `%%s\' on interface %s: %%s (%%s, %%d)",\n'
1623 ' info->parent_struct.name, \n'
1624 ' error->message, g_quark_to_string (error->domain), error->code);\n'
1625 ' g_error_free (error);\n'
1630 self.c.write('static void\n'
1631 '%s_proxy_set_property (GObject *object,\n'
1633 ' const GValue *value,\n'
1634 ' GParamSpec *pspec)\n'
1635 '{\n'%(i.name_lower))
1636 if len(i.properties) > 0:
1637 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1638 ' GVariant *variant;\n'
1639 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1640 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1641 ' variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
1642 ' g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
1643 ' "org.freedesktop.DBus.Properties.Set",\n'
1644 ' g_variant_new ("(ssv)", "%s", info->parent_struct.name, variant),\n'
1645 ' G_DBUS_CALL_FLAGS_NONE,\n'
1647 ' NULL, (GAsyncReadyCallback) %s_proxy_set_property_cb, (gpointer) info);\n'
1648 ' g_variant_unref (variant);\n'
1649 %(len(i.properties), i.name_lower, i.name, i.name_lower))
1654 self.c.write('static void\n'
1655 '%s_proxy_g_signal (GDBusProxy *proxy,\n'
1656 ' const gchar *sender_name,\n'
1657 ' const gchar *signal_name,\n'
1658 ' GVariant *parameters)\n'
1659 '{\n'%(i.name_lower))
1660 self.c.write(' _ExtendedGDBusSignalInfo *info;\n'
1661 ' GVariantIter iter;\n'
1662 ' GVariant *child;\n'
1663 ' GValue *paramv;\n'
1664 ' guint num_params;\n'
1666 ' guint signal_id;\n');
1667 # Note: info could be NULL if we are talking to a newer version of the interface
1668 self.c.write(' info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_%s_interface_info, signal_name);\n'
1669 ' if (info == NULL)\n'
1672 self.c.write (' num_params = g_variant_n_children (parameters);\n'
1673 ' paramv = g_new0 (GValue, num_params + 1);\n'
1674 ' g_value_init (¶mv[0], %sTYPE_%s);\n'
1675 ' g_value_set_object (¶mv[0], proxy);\n'
1676 %(i.ns_upper, i.name_upper))
1677 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
1679 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
1681 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1];\n'
1682 ' if (arg_info->use_gvariant)\n'
1684 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
1685 ' g_value_set_variant (¶mv[n], child);\n'
1689 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
1690 ' g_variant_unref (child);\n'
1693 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
1694 %(i.ns_upper, i.name_upper))
1695 self.c.write(' g_signal_emitv (paramv, signal_id, 0, NULL);\n')
1696 self.c.write(' for (n = 0; n < num_params + 1; n++)\n'
1697 ' g_value_unset (¶mv[n]);\n'
1698 ' g_free (paramv);\n')
1703 self.c.write('static void\n'
1704 '%s_proxy_g_properties_changed (GDBusProxy *_proxy,\n'
1705 ' GVariant *changed_properties,\n'
1706 ' const gchar *const *invalidated_properties)\n'
1707 '{\n'%(i.name_lower))
1708 # Note: info could be NULL if we are talking to a newer version of the interface
1709 self.c.write(' %sProxy *proxy = %s%s_PROXY (_proxy);\n'
1711 ' const gchar *key;\n'
1712 ' GVariantIter *iter;\n'
1713 ' _ExtendedGDBusPropertyInfo *info;\n'
1714 ' g_variant_get (changed_properties, "a{sv}", &iter);\n'
1715 ' while (g_variant_iter_next (iter, "{&sv}", &key, NULL))\n'
1717 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, key);\n'
1718 ' g_datalist_remove_data (&proxy->priv->qdata, key);\n'
1719 ' if (info != NULL)\n'
1720 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1722 ' g_variant_iter_free (iter);\n'
1723 ' for (n = 0; invalidated_properties[n] != NULL; n++)\n'
1725 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, invalidated_properties[n]);\n'
1726 ' g_datalist_remove_data (&proxy->priv->qdata, key);\n'
1727 ' if (info != NULL)\n'
1728 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1732 %(i.camel_name, i.ns_upper, i.name_upper,
1733 i.name_lower, i.name_lower))
1736 for p in i.properties:
1738 if p.arg.free_func != None:
1740 self.c.write('static %s\n'
1741 '%s_proxy_get_%s (%s *object)\n'
1743 ' %sProxy *proxy = %s%s_PROXY (object);\n'
1744 ' GVariant *variant;\n'
1745 ' %svalue = %s;\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name,
1746 i.camel_name, i.ns_upper, i.name_upper,
1747 p.arg.ctype_in, nul_value))
1748 # For some property types, we have to free the returned
1749 # value (or part of it, e.g. the container) because of how
1750 # GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
1753 free_container = False;
1754 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':
1755 free_container = True;
1756 # If already using an old value for strv, objpathv, bytestring_array (see below),
1757 # then just return that... that way the result from multiple consecutive calls
1758 # to the getter are valid as long as they're freed
1761 self.c.write(' value = g_datalist_get_data (&proxy->priv->qdata, \"%s\");\n'
1762 ' if (value != NULL)\n'
1765 self.c.write(' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \"%s\");\n'%(p.name))
1766 if p.arg.gtype == 'G_TYPE_VARIANT':
1767 self.c.write(' value = variant;\n')
1768 self.c.write(' if (variant != NULL)\n')
1769 self.c.write(' g_variant_unref (variant);\n')
1771 self.c.write(' if (variant != NULL)\n'
1774 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':
1775 extra_len = ', NULL'
1776 self.c.write(' value = %s (variant%s);\n'%(p.arg.gvariant_get, extra_len))
1778 self.c.write(' g_datalist_set_data_full (&proxy->priv->qdata, \"%s\", (gpointer) value, g_free);\n'
1780 self.c.write(' g_variant_unref (variant);\n')
1781 self.c.write(' }\n')
1782 self.c.write(' return value;\n')
1787 self.c.write('static void\n'
1788 '%s_proxy_init (%sProxy *proxy)\n'
1790 ' proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %sTYPE_%s_PROXY, %sProxyPrivate);\n'
1791 ' g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
1794 %(i.name_lower, i.camel_name,
1795 i.ns_upper, i.name_upper, i.camel_name,
1797 self.c.write('static void\n'
1798 '%s_proxy_class_init (%sProxyClass *klass)\n'
1800 ' GObjectClass *gobject_class;\n'
1801 ' GDBusProxyClass *proxy_class;\n'
1803 ' g_type_class_add_private (klass, sizeof (%sProxyPrivate));\n'
1805 ' gobject_class = G_OBJECT_CLASS (klass);\n'
1806 ' gobject_class->finalize = %s_proxy_finalize;\n'
1807 ' gobject_class->get_property = %s_proxy_get_property;\n'
1808 ' gobject_class->set_property = %s_proxy_set_property;\n'
1810 ' proxy_class = G_DBUS_PROXY_CLASS (klass);\n'
1811 ' proxy_class->g_signal = %s_proxy_g_signal;\n'
1812 ' proxy_class->g_properties_changed = %s_proxy_g_properties_changed;\n'
1813 '\n'%(i.name_lower, i.camel_name,
1815 i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
1816 if len(i.properties) > 0:
1818 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
1822 self.c.write('static void\n'
1823 '%s_proxy_iface_init (%sIface *iface)\n'
1824 '{\n'%(i.name_lower, i.camel_name))
1825 for p in i.properties:
1826 self.c.write(' iface->get_%s = %s_proxy_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
1831 self.c.write(self.docbook_gen.expand(
1833 ' * %s_proxy_new:\n'
1834 ' * @connection: A #GDBusConnection.\n'
1835 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1836 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1837 ' * @object_path: An object path.\n'
1838 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1839 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1840 ' * @user_data: User data to pass to @callback.\n'
1842 ' * Asynchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new() for more details.\n'
1844 ' * 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'
1845 ' * You can then call %s_proxy_new_finish() to get the result of the operation.\n'
1847 ' * See %s_proxy_new_sync() for the synchronous, blocking version of this constructor.\n'
1848 %(i.name_lower, i.name, i.name_lower, i.name_lower), False))
1849 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1850 self.c.write('void\n'
1852 ' GDBusConnection *connection,\n'
1853 ' GDBusProxyFlags flags,\n'
1854 ' const gchar *name,\n'
1855 ' const gchar *object_path,\n'
1856 ' GCancellable *cancellable,\n'
1857 ' GAsyncReadyCallback callback,\n'
1858 ' gpointer user_data)\n'
1860 ' 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'
1863 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1864 self.c.write('/**\n'
1865 ' * %s_proxy_new_finish:\n'
1866 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new().\n'
1867 ' * @error: Return location for error or %%NULL\n'
1869 ' * Finishes an operation started with %s_proxy_new().\n'
1871 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1872 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1873 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1874 self.c.write('%s *\n'
1875 '%s_proxy_new_finish (\n'
1876 ' GAsyncResult *res,\n'
1877 ' GError **error)\n'
1880 ' GObject *source_object;\n'
1881 ' source_object = g_async_result_get_source_object (res);\n'
1882 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1883 ' g_object_unref (source_object);\n'
1884 ' if (ret != NULL)\n'
1885 ' return %s%s (ret);\n'
1890 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1891 self.c.write(self.docbook_gen.expand(
1893 ' * %s_proxy_new_sync:\n'
1894 ' * @connection: A #GDBusConnection.\n'
1895 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1896 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1897 ' * @object_path: An object path.\n'
1898 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1899 ' * @error: Return location for error or %%NULL\n'
1901 ' * Synchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new_sync() for more details.\n'
1903 ' * The calling thread is blocked until a reply is received.\n'
1905 ' * See %s_proxy_new() for the asynchronous version of this constructor.\n'
1907 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1908 %(i.name_lower, i.name, i.name_lower, i.camel_name), False))
1909 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1910 self.c.write('%s *\n'
1911 '%s_proxy_new_sync (\n'
1912 ' GDBusConnection *connection,\n'
1913 ' GDBusProxyFlags flags,\n'
1914 ' const gchar *name,\n'
1915 ' const gchar *object_path,\n'
1916 ' GCancellable *cancellable,\n'
1917 ' GError **error)\n'
1919 ' GInitable *ret;\n'
1920 ' 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'
1921 ' if (ret != NULL)\n'
1922 ' return %s%s (ret);\n'
1927 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
1929 self.c.write(self.docbook_gen.expand(
1931 ' * %s_proxy_new_for_bus:\n'
1932 ' * @bus_type: A #GBusType.\n'
1933 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1934 ' * @name: A bus name (well-known or unique).\n'
1935 ' * @object_path: An object path.\n'
1936 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1937 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1938 ' * @user_data: User data to pass to @callback.\n'
1940 ' * Like %s_proxy_new() but takes a #GBusType instead of a #GDBusConnection.\n'
1942 ' * 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'
1943 ' * You can then call %s_proxy_new_for_bus_finish() to get the result of the operation.\n'
1945 ' * See %s_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
1946 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower), False))
1947 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1948 self.c.write('void\n'
1949 '%s_proxy_new_for_bus (\n'
1950 ' GBusType bus_type,\n'
1951 ' GDBusProxyFlags flags,\n'
1952 ' const gchar *name,\n'
1953 ' const gchar *object_path,\n'
1954 ' GCancellable *cancellable,\n'
1955 ' GAsyncReadyCallback callback,\n'
1956 ' gpointer user_data)\n'
1958 ' 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'
1961 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1962 self.c.write('/**\n'
1963 ' * %s_proxy_new_for_bus_finish:\n'
1964 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new_for_bus().\n'
1965 ' * @error: Return location for error or %%NULL\n'
1967 ' * Finishes an operation started with %s_proxy_new_for_bus().\n'
1969 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1970 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1971 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1972 self.c.write('%s *\n'
1973 '%s_proxy_new_for_bus_finish (\n'
1974 ' GAsyncResult *res,\n'
1975 ' GError **error)\n'
1978 ' GObject *source_object;\n'
1979 ' source_object = g_async_result_get_source_object (res);\n'
1980 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1981 ' g_object_unref (source_object);\n'
1982 ' if (ret != NULL)\n'
1983 ' return %s%s (ret);\n'
1988 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1989 self.c.write(self.docbook_gen.expand(
1991 ' * %s_proxy_new_for_bus_sync:\n'
1992 ' * @bus_type: A #GBusType.\n'
1993 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1994 ' * @name: A bus name (well-known or unique).\n'
1995 ' * @object_path: An object path.\n'
1996 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1997 ' * @error: Return location for error or %%NULL\n'
1999 ' * Like %s_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
2001 ' * The calling thread is blocked until a reply is received.\n'
2003 ' * See %s_proxy_new_for_bus() for the asynchronous version of this constructor.\n'
2005 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2006 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name), False))
2007 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2008 self.c.write('%s *\n'
2009 '%s_proxy_new_for_bus_sync (\n'
2010 ' GBusType bus_type,\n'
2011 ' GDBusProxyFlags flags,\n'
2012 ' const gchar *name,\n'
2013 ' const gchar *object_path,\n'
2014 ' GCancellable *cancellable,\n'
2015 ' GError **error)\n'
2017 ' GInitable *ret;\n'
2018 ' 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'
2019 ' if (ret != NULL)\n'
2020 ' return %s%s (ret);\n'
2025 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
2028 # ---------------------------------------------------------------------------------------------------
2030 def generate_skeleton(self, i):
2032 self.c.write('/* ------------------------------------------------------------------------ */\n'
2035 self.c.write(self.docbook_gen.expand(
2039 ' * The #%sSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2040 %(i.camel_name, i.camel_name), False))
2041 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2044 self.c.write(self.docbook_gen.expand(
2046 ' * %sSkeletonClass:\n'
2047 ' * @parent_class: The parent class.\n'
2049 ' * Class structure for #%sSkeleton.\n'
2050 %(i.camel_name, i.camel_name), False))
2051 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2054 self.c.write('struct _%sSkeletonPrivate\n'
2056 ' GValueArray *properties;\n'
2057 ' GList *changed_properties;\n'
2058 ' GSource *changed_properties_idle_source;\n'
2059 ' GMainContext *context;\n'
2064 self.c.write('static void\n'
2065 '_%s_skeleton_handle_method_call (\n'
2066 ' GDBusConnection *connection,\n'
2067 ' const gchar *sender,\n'
2068 ' const gchar *object_path,\n'
2069 ' const gchar *interface_name,\n'
2070 ' const gchar *method_name,\n'
2071 ' GVariant *parameters,\n'
2072 ' GDBusMethodInvocation *invocation,\n'
2073 ' gpointer user_data)\n'
2075 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2076 ' _ExtendedGDBusMethodInfo *info;\n'
2077 ' GVariantIter iter;\n'
2078 ' GVariant *child;\n'
2079 ' GValue *paramv;\n'
2080 ' guint num_params;\n'
2081 ' guint num_extra;\n'
2083 ' guint signal_id;\n'
2084 ' GValue return_value = {0};\n'
2085 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2086 self.c.write(' info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n'
2087 ' g_assert (info != NULL);\n'
2089 self.c.write (' num_params = g_variant_n_children (parameters);\n'
2090 ' num_extra = info->pass_fdlist ? 3 : 2;'
2091 ' paramv = g_new0 (GValue, num_params + num_extra);\n'
2093 ' g_value_init (¶mv[n], %sTYPE_%s);\n'
2094 ' g_value_set_object (¶mv[n++], skeleton);\n'
2095 ' g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION);\n'
2096 ' g_value_set_object (¶mv[n++], invocation);\n'
2097 ' if (info->pass_fdlist)\n'
2099 '#ifdef G_OS_UNIX\n'
2100 ' g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST);\n'
2101 ' g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)));\n'
2103 ' g_assert_not_reached ();\n'
2106 %(i.ns_upper, i.name_upper))
2107 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
2108 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
2110 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra];\n'
2111 ' if (arg_info->use_gvariant)\n'
2113 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
2114 ' g_value_set_variant (¶mv[n], child);\n'
2118 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
2119 ' g_variant_unref (child);\n'
2122 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
2123 %(i.ns_upper, i.name_upper))
2124 self.c.write(' g_value_init (&return_value, G_TYPE_BOOLEAN);\n'
2125 ' g_signal_emitv (paramv, signal_id, 0, &return_value);\n'
2126 ' if (!g_value_get_boolean (&return_value))\n'
2127 ' 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'
2128 ' g_value_unset (&return_value);\n'
2130 self.c.write(' for (n = 0; n < num_params + num_extra; n++)\n'
2131 ' g_value_unset (¶mv[n]);\n'
2132 ' g_free (paramv);\n')
2136 self.c.write('static GVariant *\n'
2137 '_%s_skeleton_handle_get_property (\n'
2138 ' GDBusConnection *connection,\n'
2139 ' const gchar *sender,\n'
2140 ' const gchar *object_path,\n'
2141 ' const gchar *interface_name,\n'
2142 ' const gchar *property_name,\n'
2143 ' GError **error,\n'
2144 ' gpointer user_data)\n'
2146 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2147 ' GValue value = {0};\n'
2148 ' GParamSpec *pspec;\n'
2149 ' _ExtendedGDBusPropertyInfo *info;\n'
2151 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2152 self.c.write(' ret = NULL;\n'
2153 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, property_name);\n'
2154 ' g_assert (info != NULL);\n'
2155 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2156 ' if (pspec == NULL)\n'
2158 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2162 ' g_value_init (&value, pspec->value_type);\n'
2163 ' g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2164 ' ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
2165 ' g_value_unset (&value);\n'
2172 self.c.write('static gboolean\n'
2173 '_%s_skeleton_handle_set_property (\n'
2174 ' GDBusConnection *connection,\n'
2175 ' const gchar *sender,\n'
2176 ' const gchar *object_path,\n'
2177 ' const gchar *interface_name,\n'
2178 ' const gchar *property_name,\n'
2179 ' GVariant *variant,\n'
2180 ' GError **error,\n'
2181 ' gpointer user_data)\n'
2183 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2184 ' GValue value = {0};\n'
2185 ' GParamSpec *pspec;\n'
2186 ' _ExtendedGDBusPropertyInfo *info;\n'
2188 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2189 self.c.write(' ret = FALSE;\n'
2190 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, property_name);\n'
2191 ' g_assert (info != NULL);\n'
2192 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2193 ' if (pspec == NULL)\n'
2195 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2199 ' if (info->use_gvariant)\n'
2200 ' g_value_set_variant (&value, variant);\n'
2202 ' g_dbus_gvariant_to_gvalue (variant, &value);\n'
2203 ' g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2204 ' g_value_unset (&value);\n'
2213 self.c.write('static const GDBusInterfaceVTable _%s_skeleton_vtable =\n'
2215 ' _%s_skeleton_handle_method_call,\n'
2216 ' _%s_skeleton_handle_get_property,\n'
2217 ' _%s_skeleton_handle_set_property\n'
2219 '\n'%(i.name_lower, i.name_lower, i.name_lower, i.name_lower))
2221 self.c.write('static GDBusInterfaceInfo *\n'
2222 '%s_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton)\n'
2224 ' return %s_interface_info ();\n'
2225 %(i.name_lower, i.name_lower))
2229 self.c.write('static GDBusInterfaceVTable *\n'
2230 '%s_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton)\n'
2232 ' return (GDBusInterfaceVTable *) &_%s_skeleton_vtable;\n'
2233 %(i.name_lower, i.name_lower))
2237 self.c.write('static GVariant *\n'
2238 '%s_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton)\n'
2240 ' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2241 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2243 ' GVariantBuilder builder;\n'
2245 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2246 ' if (_%s_interface_info.parent_struct.properties == NULL)\n'
2248 ' for (n = 0; _%s_interface_info.parent_struct.properties[n] != NULL; n++)\n'
2250 ' GDBusPropertyInfo *info = _%s_interface_info.parent_struct.properties[n];\n'
2251 ' if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)\n'
2253 ' GVariant *value;\n'
2254 ' 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'
2255 ' if (value != NULL)\n'
2257 ' g_variant_take_ref (value);\n'
2258 ' g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
2259 ' g_variant_unref (value);\n'
2264 ' return g_variant_builder_end (&builder);\n'
2267 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name))
2269 if len(i.properties) > 0:
2270 self.c.write('static gboolean _%s_emit_changed (gpointer user_data);\n'
2274 self.c.write('static void\n'
2275 '%s_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton)\n'
2278 if len(i.properties) > 0:
2279 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2280 ' gboolean emit_changed = FALSE;\n'
2282 ' g_mutex_lock (skeleton->priv->lock);\n'
2283 ' if (skeleton->priv->changed_properties_idle_source != NULL)\n'
2285 ' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
2286 ' skeleton->priv->changed_properties_idle_source = NULL;\n'
2287 ' emit_changed = TRUE;\n'
2289 ' g_mutex_unlock (skeleton->priv->lock);\n'
2291 ' if (emit_changed)\n'
2292 ' _%s_emit_changed (skeleton);\n'
2293 %(i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2298 self.c.write('static void\n'
2299 '_%s_on_signal_%s (\n'
2300 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
2302 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
2305 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2306 ' GDBusConnection *connection = g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2307 %(i.camel_name, i.ns_upper, i.name_upper))
2308 self.c.write(' if (connection == NULL)\n'
2310 ' g_dbus_connection_emit_signal (connection,\n'
2311 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", "%s",\n'
2312 ' g_variant_new ("('
2315 self.c.write('%s'%(a.format_in))
2318 self.c.write(',\n %s'%(a.name))
2319 self.c.write('), NULL);\n')
2323 self.c.write('static void %s_skeleton_iface_init (%sIface *iface);\n'
2324 %(i.name_lower, i.camel_name))
2326 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2327 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2330 self.c.write('static void\n'
2331 '%s_skeleton_finalize (GObject *object)\n'
2332 '{\n'%(i.name_lower))
2333 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2334 if len(i.properties) > 0:
2335 self.c.write(' g_value_array_free (skeleton->priv->properties);\n')
2336 self.c.write(' g_list_foreach (skeleton->priv->changed_properties, (GFunc) _changed_property_free, NULL);\n')
2337 self.c.write(' g_list_free (skeleton->priv->changed_properties);\n')
2338 self.c.write(' if (skeleton->priv->changed_properties_idle_source != NULL)\n')
2339 self.c.write(' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
2340 self.c.write(' if (skeleton->priv->context != NULL)\n')
2341 self.c.write(' g_main_context_unref (skeleton->priv->context);\n')
2342 self.c.write(' g_mutex_free (skeleton->priv->lock);\n')
2343 self.c.write(' G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
2345 '\n'%(i.name_lower))
2347 # property accessors (TODO: generate PropertiesChanged signals in setter)
2348 if len(i.properties) > 0:
2349 self.c.write('static void\n'
2350 '%s_skeleton_get_property (GObject *object,\n'
2353 ' GParamSpec *pspec)\n'
2354 '{\n'%(i.name_lower))
2355 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2356 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2357 ' g_mutex_lock (skeleton->priv->lock);\n'
2358 ' g_value_copy (&skeleton->priv->properties->values[prop_id - 1], value);\n'
2359 ' g_mutex_unlock (skeleton->priv->lock);\n'
2360 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
2364 # if property is already scheduled then re-use entry.. though it could be
2367 # foo_set_prop_bar (object, "");
2368 # foo_set_prop_bar (object, "blah");
2370 # say, every update... In this case, where nothing happens, we obviously
2371 # don't want a PropertiesChanged() event. We can easily check for this
2372 # by comparing against the _original value_ recorded before the first
2373 # change event. If the latest value is not different from the original
2374 # one, we can simply ignore the ChangedProperty
2376 self.c.write('static gboolean\n'
2377 '_%s_emit_changed (gpointer user_data)\n'
2379 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2380 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2381 self.c.write(' GList *l;\n'
2382 ' GVariantBuilder builder;\n'
2383 ' GVariantBuilder invalidated_builder;\n'
2384 ' guint num_changes;\n'
2386 ' g_mutex_lock (skeleton->priv->lock);\n'
2387 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2388 ' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
2389 ' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
2391 ' ChangedProperty *cp = l->data;\n'
2392 ' GVariant *variant;\n'
2393 ' const GValue *cur_value;\n'
2395 ' cur_value = &skeleton->priv->properties->values[cp->prop_id - 1];\n'
2396 ' if (!_g_value_equal (cur_value, &cp->orig_value))\n'
2398 ' variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature));\n'
2399 ' g_variant_builder_add (&builder, "{sv}", cp->info->parent_struct.name, variant);\n'
2400 ' g_variant_unref (variant);\n'
2404 ' if (num_changes > 0)\n'
2406 ' g_dbus_connection_emit_signal (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2407 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2408 ' "org.freedesktop.DBus.Properties",\n'
2409 ' "PropertiesChanged",\n'
2410 ' g_variant_new ("(sa{sv}as)",\n'
2412 ' &builder, &invalidated_builder),\n'
2417 ' g_variant_builder_clear (&builder);\n'
2418 ' g_variant_builder_clear (&invalidated_builder);\n'
2421 self.c.write(' g_list_foreach (skeleton->priv->changed_properties, (GFunc) _changed_property_free, NULL);\n')
2422 self.c.write(' g_list_free (skeleton->priv->changed_properties);\n')
2423 self.c.write(' skeleton->priv->changed_properties = NULL;\n')
2424 self.c.write(' skeleton->priv->changed_properties_idle_source = NULL;\n')
2425 self.c.write(' g_mutex_unlock (skeleton->priv->lock);\n')
2426 self.c.write(' return FALSE;\n'
2429 # holding lock while being called
2430 self.c.write('static void\n'
2431 '_%s_schedule_emit_changed (%sSkeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value)\n'
2433 ' ChangedProperty *cp;\n'
2436 ' for (l = skeleton->priv->changed_properties; l != NULL; l = l->next)\n'
2438 ' ChangedProperty *i_cp = l->data;\n'
2439 ' if (i_cp->info == info)\n'
2445 %(i.name_lower, i.camel_name))
2446 self.c.write(' if (cp == NULL)\n'
2448 ' cp = g_new0 (ChangedProperty, 1);\n'
2449 ' cp->prop_id = prop_id;\n'
2450 ' cp->info = info;\n'
2451 ' skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp);\n'
2452 ' g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value));\n'
2453 ' g_value_copy (orig_value, &cp->orig_value);\n'
2459 # Postpone setting up the refresh source until the ::notify signal is emitted as
2460 # this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
2461 # This is useful when updating several properties from another thread than
2462 # where the idle will be emitted from
2463 self.c.write('static void\n'
2464 '%s_skeleton_notify (GObject *object,\n'
2465 ' GParamSpec *pspec)\n'
2467 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2468 ' g_mutex_lock (skeleton->priv->lock);\n'
2469 ' if (skeleton->priv->changed_properties != NULL &&\n'
2470 ' skeleton->priv->changed_properties_idle_source == NULL)\n'
2472 ' skeleton->priv->changed_properties_idle_source = g_idle_source_new ();\n'
2473 ' g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);\n'
2474 ' g_source_set_callback (skeleton->priv->changed_properties_idle_source, _%s_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);\n'
2475 ' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
2476 ' g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
2478 ' g_mutex_unlock (skeleton->priv->lock);\n'
2481 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2483 self.c.write('static void\n'
2484 '%s_skeleton_set_property (GObject *object,\n'
2486 ' const GValue *value,\n'
2487 ' GParamSpec *pspec)\n'
2488 '{\n'%(i.name_lower))
2489 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2490 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2491 ' g_mutex_lock (skeleton->priv->lock);\n'
2492 ' g_object_freeze_notify (object);\n'
2493 ' if (!_g_value_equal (value, &skeleton->priv->properties->values[prop_id - 1]))\n'
2495 ' if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
2496 ' _%s_schedule_emit_changed (skeleton, _%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties->values[prop_id - 1]);\n'
2497 ' g_value_copy (value, &skeleton->priv->properties->values[prop_id - 1]);\n'
2498 ' g_object_notify_by_pspec (object, pspec);\n'
2500 ' g_mutex_unlock (skeleton->priv->lock);\n'
2501 ' g_object_thaw_notify (object);\n'
2502 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
2506 self.c.write('static void\n'
2507 '%s_skeleton_init (%sSkeleton *skeleton)\n'
2509 ' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
2510 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.camel_name))
2511 self.c.write(' skeleton->priv->lock = g_mutex_new ();\n')
2512 self.c.write(' skeleton->priv->context = g_main_context_get_thread_default ();\n')
2513 self.c.write(' if (skeleton->priv->context != NULL)\n')
2514 self.c.write(' g_main_context_ref (skeleton->priv->context);\n')
2515 if len(i.properties) > 0:
2516 self.c.write(' skeleton->priv->properties = g_value_array_new (%d);\n'%(len(i.properties)))
2518 for p in i.properties:
2519 self.c.write(' g_value_array_append (skeleton->priv->properties, NULL);\n')
2520 self.c.write(' g_value_init (&skeleton->priv->properties->values[%d], %s);\n'%(n, p.arg.gtype))
2527 for p in i.properties:
2528 self.c.write('static %s\n'
2529 '%s_skeleton_get_%s (%s *object)\n'
2531 %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
2532 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2533 self.c.write(' %svalue;\n'
2534 ' g_mutex_lock (skeleton->priv->lock);\n'
2535 ' value = %s (&(skeleton->priv->properties->values[%d]));\n'
2536 ' g_mutex_unlock (skeleton->priv->lock);\n'
2537 %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
2538 self.c.write(' return value;\n')
2543 self.c.write('static void\n'
2544 '%s_skeleton_class_init (%sSkeletonClass *klass)\n'
2546 ' GObjectClass *gobject_class;\n'
2547 ' GDBusInterfaceSkeletonClass *skeleton_class;\n'
2549 ' g_type_class_add_private (klass, sizeof (%sSkeletonPrivate));\n'
2551 ' gobject_class = G_OBJECT_CLASS (klass);\n'
2552 ' gobject_class->finalize = %s_skeleton_finalize;\n'
2553 %(i.name_lower, i.camel_name, i.camel_name, i.name_lower))
2554 if len(i.properties) > 0:
2555 self.c.write(' gobject_class->get_property = %s_skeleton_get_property;\n'
2556 ' gobject_class->set_property = %s_skeleton_set_property;\n'
2557 ' gobject_class->notify = %s_skeleton_notify;\n'
2558 '\n'%(i.name_lower, i.name_lower, i.name_lower))
2560 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
2562 ' skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);\n');
2563 self.c.write(' skeleton_class->get_info = %s_skeleton_dbus_interface_get_info;\n'%(i.name_lower))
2564 self.c.write(' skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
2565 self.c.write(' skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
2566 self.c.write(' skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
2570 self.c.write('static void\n'
2571 '%s_skeleton_iface_init (%sIface *iface)\n'
2573 %(i.name_lower, i.camel_name))
2575 self.c.write(' iface->%s = _%s_on_signal_%s;\n'
2576 %(s.name_lower, i.name_lower, s.name_lower))
2577 for p in i.properties:
2578 self.c.write(' iface->get_%s = %s_skeleton_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
2583 self.c.write(self.docbook_gen.expand(
2585 ' * %s_skeleton_new:\n'
2587 ' * Creates a skeleton object for the D-Bus interface #%s.\n'
2589 ' * Returns: (transfer full) (type %sSkeleton): The skeleton object.\n'
2590 %(i.name_lower, i.name, i.camel_name), False))
2591 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2592 self.c.write('%s *\n'
2593 '%s_skeleton_new (void)\n'
2595 ' return %s%s (g_object_new (%sTYPE_%s_SKELETON, NULL));\n'
2597 '\n'%(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
2599 # ---------------------------------------------------------------------------------------------------
2601 def generate_object(self):
2602 self.c.write('/* ------------------------------------------------------------------------\n'
2603 ' * Code for Object, ObjectProxy and ObjectSkeleton\n'
2604 ' * ------------------------------------------------------------------------\n'
2608 self.c.write(self.docbook_gen.expand(
2610 ' * SECTION:%sObject\n'
2611 ' * @title: %sObject\n'
2612 ' * @short_description: Specialized GDBusObject types\n'
2614 ' * 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'
2616 %(self.namespace, self.namespace, self.namespace, self.namespace, self.namespace), False))
2619 self.c.write(self.docbook_gen.expand(
2623 ' * The #%sObject type is a specialized container of interfaces.\n'
2625 %(self.namespace, self.namespace), False))
2628 self.c.write(self.docbook_gen.expand(
2630 ' * %sObjectIface:\n'
2631 ' * @parent_iface: The parent interface.\n'
2633 ' * Virtual table for the #%sObject interface.\n'
2635 %(self.namespace, self.namespace), False))
2638 self.c.write('static void\n'
2639 '%sobject_default_init (%sObjectIface *iface)\n'
2641 %(self.ns_lower, self.namespace));
2642 for i in self.ifaces:
2643 self.c.write(self.docbook_gen.expand(
2647 ' * The #%s instance corresponding to the D-Bus interface #%s, if any.\n'
2649 ' * Connect to the #GObject::notify signal to get informed of property changes.\n'
2650 %(self.namespace, i.name_hyphen, i.camel_name, i.name), False))
2651 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 2)
2652 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'
2654 %(i.name_hyphen, i.name_hyphen, i.name_hyphen, self.ns_upper, i.name_upper))
2658 self.c.write('typedef %sObjectIface %sObjectInterface;\n'%(self.namespace, self.namespace))
2659 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))
2662 for i in self.ifaces:
2663 self.c.write(self.docbook_gen.expand(
2665 ' * %sobject_get_%s:\n'
2666 ' * @object: A #%sObject.\n'
2668 ' * Gets the #%s instance for the D-Bus interface #%s on @object, if any.\n'
2670 ' * Returns: (transfer full): A #%s that must be freed with g_object_unref() or %%NULL if @object does not implement the interface.\n'
2671 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.name, i.camel_name), False))
2672 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2673 self.c.write ('%s *%sobject_get_%s (%sObject *object)\n'
2674 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2676 ' GDBusInterface *ret;\n'
2677 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2678 ' if (ret == NULL)\n'
2680 ' return %s%s (ret);\n'
2683 %(i.name, self.ns_upper, i.name_upper))
2685 for i in self.ifaces:
2686 self.c.write(self.docbook_gen.expand(
2688 ' * %sobject_peek_%s: (skip)\n'
2689 ' * @object: A #%sObject.\n'
2691 ' * Like %sobject_get_%s() but doesn\' increase the reference count on the returned object.\n'
2693 ' * <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'
2695 ' * 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'
2696 %(self.ns_lower, i.name_upper.lower(), self.namespace, self.ns_lower, i.name_upper.lower(), i.camel_name), False))
2697 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2698 self.c.write ('%s *%sobject_peek_%s (%sObject *object)\n'
2699 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2701 ' GDBusInterface *ret;\n'
2702 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2703 ' if (ret == NULL)\n'
2705 ' g_object_unref (ret);\n'
2706 ' return %s%s (ret);\n'
2709 %(i.name, self.ns_upper, i.name_upper))
2711 # shared by ObjectProxy and ObjectSkeleton classes
2712 self.c.write('static void\n'
2713 '%sobject_notify (GDBusObject *object, GDBusInterface *interface)\n'
2715 ' g_object_notify (G_OBJECT (object), ((_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface))->hyphen_name);\n'
2720 self.c.write(self.docbook_gen.expand(
2722 ' * %sObjectProxy:\n'
2724 ' * The #%sObjectProxy structure contains only private data and should only be accessed using the provided API.\n'
2725 %(self.namespace, self.namespace), False))
2726 self.c.write(' */\n')
2728 self.c.write(self.docbook_gen.expand(
2730 ' * %sObjectProxyClass:\n'
2731 ' * @parent_class: The parent class.\n'
2733 ' * Class structure for #%sObjectProxy.\n'
2734 %(self.namespace, self.namespace), False))
2735 self.c.write(' */\n')
2738 self.c.write('static void\n'
2739 '%sobject_proxy__%sobject_iface_init (%sObjectIface *iface)\n'
2743 %(self.ns_lower, self.ns_lower, self.namespace))
2744 self.c.write('static void\n'
2745 '%sobject_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2747 ' iface->interface_added = %sobject_notify;\n'
2748 ' iface->interface_removed = %sobject_notify;\n'
2751 %(self.ns_lower, self.ns_lower, self.ns_lower))
2753 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectProxy, %sobject_proxy, G_TYPE_DBUS_OBJECT_PROXY,\n'
2754 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_proxy__%sobject_iface_init)\n'
2755 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_proxy__g_dbus_object_iface_init));\n'
2757 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2759 self.c.write('static void\n'
2760 '%sobject_proxy_init (%sObjectProxy *object)\n'
2763 '\n'%(self.ns_lower, self.namespace))
2764 self.c.write('static void\n'
2765 '%sobject_proxy_set_property (GObject *_object,\n'
2767 ' const GValue *value,\n'
2768 ' GParamSpec *pspec)\n'
2770 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (_object, prop_id, pspec);\n'
2774 self.c.write('static void\n'
2775 '%sobject_proxy_get_property (GObject *_object,\n'
2778 ' GParamSpec *pspec)\n'
2780 ' %sObjectProxy *object = %sOBJECT_PROXY (_object);\n'
2781 ' GDBusInterface *interface;\n'
2783 ' switch (prop_id)\n'
2785 %(self.ns_lower, self.namespace, self.ns_upper))
2787 for i in self.ifaces:
2788 self.c.write(' case %d:\n'
2789 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2790 ' g_value_take_object (value, interface);\n'
2795 self.c.write(' default:\n'
2796 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (_object, prop_id, pspec);\n'
2801 self.c.write('static void\n'
2802 '%sobject_proxy_class_init (%sObjectProxyClass *klass)\n'
2804 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2806 ' gobject_class->set_property = %sobject_proxy_set_property;\n'
2807 ' gobject_class->get_property = %sobject_proxy_get_property;\n'
2809 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2811 for i in self.ifaces:
2812 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2814 %(n, i.name_hyphen))
2819 self.c.write(self.docbook_gen.expand(
2821 ' * %sobject_proxy_new:\n'
2822 ' * @connection: A #GDBusConnection.\n'
2823 ' * @object_path: An object path.\n'
2825 ' * Creates a new proxy object.\n'
2827 ' * Returns: (transfer full): The proxy object.\n'
2829 %(self.ns_lower), False))
2830 self.c.write('%sObjectProxy *\n'
2831 '%sobject_proxy_new (GDBusConnection *connection,\n'
2832 ' const gchar *object_path)\n'
2834 ' g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);\n'
2835 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2836 ' return %sOBJECT_PROXY (g_object_new (%sTYPE_OBJECT_PROXY, "connection", connection, "object-path", object_path, NULL));\n'
2838 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2840 self.c.write(self.docbook_gen.expand(
2842 ' * %sObjectSkeleton:\n'
2844 ' * The #%sObjectSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2845 %(self.namespace, self.namespace), False))
2846 self.c.write(' */\n')
2848 self.c.write(self.docbook_gen.expand(
2850 ' * %sObjectSkeletonClass:\n'
2851 ' * @parent_class: The parent class.\n'
2853 ' * Class structure for #%sObjectSkeleton.\n'
2854 %(self.namespace, self.namespace), False))
2855 self.c.write(' */\n')
2858 self.c.write('static void\n'
2859 '%sobject_skeleton__%sobject_iface_init (%sObjectIface *iface)\n'
2863 %(self.ns_lower, self.ns_lower, self.namespace))
2865 self.c.write('static void\n'
2866 '%sobject_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2868 ' iface->interface_added = %sobject_notify;\n'
2869 ' iface->interface_removed = %sobject_notify;\n'
2872 %(self.ns_lower, self.ns_lower, self.ns_lower))
2873 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectSkeleton, %sobject_skeleton, G_TYPE_DBUS_OBJECT_SKELETON,\n'
2874 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_skeleton__%sobject_iface_init)\n'
2875 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_skeleton__g_dbus_object_iface_init));\n'
2877 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2879 self.c.write('static void\n'
2880 '%sobject_skeleton_init (%sObjectSkeleton *object)\n'
2883 '\n'%(self.ns_lower, self.namespace))
2884 self.c.write('static void\n'
2885 '%sobject_skeleton_set_property (GObject *_object,\n'
2887 ' const GValue *value,\n'
2888 ' GParamSpec *pspec)\n'
2890 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (_object);\n'
2891 ' GDBusInterfaceSkeleton *interface;\n'
2893 ' switch (prop_id)\n'
2895 %(self.ns_lower, self.namespace, self.ns_upper))
2897 for i in self.ifaces:
2898 self.c.write(' case %d:\n'
2899 ' interface = g_value_get_object (value);\n'
2900 ' if (interface != NULL)\n'
2902 ' g_warn_if_fail (%sIS_%s (interface));\n'
2903 ' g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface);\n'
2907 ' g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "%s");\n'
2911 %(n, self.ns_upper, i.name_upper, i.name))
2913 self.c.write(' default:\n'
2914 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (_object, prop_id, pspec);\n'
2919 self.c.write('static void\n'
2920 '%sobject_skeleton_get_property (GObject *_object,\n'
2923 ' GParamSpec *pspec)\n'
2925 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (_object);\n'
2926 ' GDBusInterface *interface;\n'
2928 ' switch (prop_id)\n'
2930 %(self.ns_lower, self.namespace, self.ns_upper))
2932 for i in self.ifaces:
2933 self.c.write(' case %d:\n'
2934 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2935 ' g_value_take_object (value, interface);\n'
2940 self.c.write(' default:\n'
2941 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (_object, prop_id, pspec);\n'
2946 self.c.write('static void\n'
2947 '%sobject_skeleton_class_init (%sObjectSkeletonClass *klass)\n'
2949 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2951 ' gobject_class->set_property = %sobject_skeleton_set_property;\n'
2952 ' gobject_class->get_property = %sobject_skeleton_get_property;\n'
2954 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2956 for i in self.ifaces:
2957 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2959 %(n, i.name_hyphen))
2963 self.c.write(self.docbook_gen.expand(
2965 ' * %sobject_skeleton_new:\n'
2966 ' * @object_path: An object path.\n'
2968 ' * Creates a new skeleton object.\n'
2970 ' * Returns: (transfer full): The skeleton object.\n'
2972 %(self.ns_lower), False))
2973 self.c.write('%sObjectSkeleton *\n'
2974 '%sobject_skeleton_new (const gchar *object_path)\n'
2976 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2977 ' return %sOBJECT_SKELETON (g_object_new (%sTYPE_OBJECT_SKELETON, "object-path", object_path, NULL));\n'
2979 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2980 for i in self.ifaces:
2981 self.c.write(self.docbook_gen.expand(
2983 ' * %sobject_skeleton_set_%s:\n'
2984 ' * @object: A #%sObjectSkeleton.\n'
2985 ' * @interface_: (allow-none): A #%s or %%NULL to clear the interface.\n'
2987 ' * Sets the #%s instance for the D-Bus interface #%s on @object.\n'
2988 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.camel_name, i.name), False))
2989 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2990 self.c.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_)\n'
2991 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
2993 ' g_object_set (G_OBJECT (object), "%s", interface_, NULL);\n'
3000 def generate_object_manager_client(self):
3001 self.c.write('/* ------------------------------------------------------------------------\n'
3002 ' * Code for ObjectManager client\n'
3003 ' * ------------------------------------------------------------------------\n'
3007 self.c.write(self.docbook_gen.expand(
3009 ' * SECTION:%sObjectManagerClient\n'
3010 ' * @title: %sObjectManagerClient\n'
3011 ' * @short_description: Generated GDBusObjectManagerClient type\n'
3013 ' * This section contains a #GDBusObjectManagerClient that uses %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc.\n'
3015 %(self.namespace, self.namespace, self.ns_lower), False))
3018 self.c.write(self.docbook_gen.expand(
3020 ' * %sObjectManagerClient:\n'
3022 ' * The #%sObjectManagerClient structure contains only private data and should only be accessed using the provided API.\n'
3023 %(self.namespace, self.namespace), False))
3024 self.c.write(' */\n')
3027 self.c.write(self.docbook_gen.expand(
3029 ' * %sObjectManagerClientClass:\n'
3030 ' * @parent_class: The parent class.\n'
3032 ' * Class structure for #%sObjectManagerClient.\n'
3033 %(self.namespace, self.namespace), False))
3034 self.c.write(' */\n')
3038 self.c.write('G_DEFINE_TYPE (%sObjectManagerClient, %sobject_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT);\n'
3040 %(self.namespace, self.ns_lower))
3043 self.c.write('static void\n'
3044 '%sobject_manager_client_init (%sObjectManagerClient *manager)\n'
3047 '\n'%(self.ns_lower, self.namespace))
3048 self.c.write('static void\n'
3049 '%sobject_manager_client_class_init (%sObjectManagerClientClass *klass)\n'
3052 '\n'%(self.ns_lower, self.namespace))
3054 self.c.write(self.docbook_gen.expand(
3056 ' * %sobject_manager_client_get_proxy_type:\n'
3057 ' * @manager: A #GDBusObjectManagerClient.\n'
3058 ' * @object_path: The object path of the remote object (unused).\n'
3059 ' * @interface_name: (allow-none): Interface name of the remote object or %%NULL to get the object proxy #GType.\n'
3060 ' * @user_data: User data (unused).\n'
3062 ' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types.\n'
3064 ' * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %%NULL, otherwise the #GType for #%sObjectProxy.\n'
3065 %(self.ns_lower, self.namespace), False))
3066 self.c.write(' */\n')
3067 self.c.write('GType\n'
3068 '%sobject_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data)\n'
3071 self.c.write(' static gsize once_init_value = 0;\n'
3072 ' static GHashTable *lookup_hash;\n'
3075 ' if (interface_name == NULL)\n'
3076 ' return %sTYPE_OBJECT_PROXY;\n'
3077 ' if (g_once_init_enter (&once_init_value))\n'
3079 ' lookup_hash = g_hash_table_new (g_str_hash, g_str_equal);\n'
3081 for i in self.ifaces:
3082 self.c.write(' g_hash_table_insert (lookup_hash, "%s", GSIZE_TO_POINTER (%sTYPE_%s_PROXY));\n'
3083 %(i.name, i.ns_upper, i.name_upper))
3084 self.c.write(' g_once_init_leave (&once_init_value, 1);\n'
3086 self.c.write(' ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name));\n'
3087 ' if (ret == (GType) 0)\n'
3088 ' ret = G_TYPE_DBUS_PROXY;\n')
3089 self.c.write(' return ret;\n'
3094 self.c.write(self.docbook_gen.expand(
3096 ' * %sobject_manager_client_new:\n'
3097 ' * @connection: A #GDBusConnection.\n'
3098 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3099 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3100 ' * @object_path: An object path.\n'
3101 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3102 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3103 ' * @user_data: User data to pass to @callback.\n'
3105 ' * Asynchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details.\n'
3107 ' * 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'
3108 ' * You can then call %sobject_manager_client_new_finish() to get the result of the operation.\n'
3110 ' * See %sobject_manager_client_new_sync() for the synchronous, blocking version of this constructor.\n'
3111 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3112 self.c.write(' */\n')
3113 self.c.write('void\n'
3114 '%sobject_manager_client_new (\n'
3115 ' GDBusConnection *connection,\n'
3116 ' GDBusObjectManagerClientFlags flags,\n'
3117 ' const gchar *name,\n'
3118 ' const gchar *object_path,\n'
3119 ' GCancellable *cancellable,\n'
3120 ' GAsyncReadyCallback callback,\n'
3121 ' gpointer user_data)\n'
3123 ' 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'
3126 %(self.ns_lower, self.ns_upper, self.ns_lower))
3127 self.c.write('/**\n'
3128 ' * %sobject_manager_client_new_finish:\n'
3129 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new().\n'
3130 ' * @error: Return location for error or %%NULL\n'
3132 ' * Finishes an operation started with %sobject_manager_client_new().\n'
3134 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3135 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3136 self.c.write(' */\n')
3137 self.c.write('GDBusObjectManager *\n'
3138 '%sobject_manager_client_new_finish (\n'
3139 ' GAsyncResult *res,\n'
3140 ' GError **error)\n'
3143 ' GObject *source_object;\n'
3144 ' source_object = g_async_result_get_source_object (res);\n'
3145 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3146 ' g_object_unref (source_object);\n'
3147 ' if (ret != NULL)\n'
3148 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3154 self.c.write(self.docbook_gen.expand(
3156 ' * %sobject_manager_client_new_sync:\n'
3157 ' * @connection: A #GDBusConnection.\n'
3158 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3159 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3160 ' * @object_path: An object path.\n'
3161 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3162 ' * @error: Return location for error or %%NULL\n'
3164 ' * 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'
3166 ' * The calling thread is blocked until a reply is received.\n'
3168 ' * See %sobject_manager_client_new() for the asynchronous version of this constructor.\n'
3170 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3171 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3172 self.c.write(' */\n')
3173 self.c.write('GDBusObjectManager *\n'
3174 '%sobject_manager_client_new_sync (\n'
3175 ' GDBusConnection *connection,\n'
3176 ' GDBusObjectManagerClientFlags flags,\n'
3177 ' const gchar *name,\n'
3178 ' const gchar *object_path,\n'
3179 ' GCancellable *cancellable,\n'
3180 ' GError **error)\n'
3182 ' GInitable *ret;\n'
3183 ' 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'
3184 ' if (ret != NULL)\n'
3185 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3190 %(self.ns_lower, self.ns_upper, self.ns_lower))
3192 self.c.write(self.docbook_gen.expand(
3194 ' * %sobject_manager_client_new_for_bus:\n'
3195 ' * @bus_type: A #GBusType.\n'
3196 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3197 ' * @name: A bus name (well-known or unique).\n'
3198 ' * @object_path: An object path.\n'
3199 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3200 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3201 ' * @user_data: User data to pass to @callback.\n'
3203 ' * Like %sobject_manager_client_new() but takes a #GBusType instead of a #GDBusConnection.\n'
3205 ' * 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'
3206 ' * You can then call %sobject_manager_client_new_for_bus_finish() to get the result of the operation.\n'
3208 ' * See %sobject_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
3209 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3210 self.c.write(' */\n')
3211 self.c.write('void\n'
3212 '%sobject_manager_client_new_for_bus (\n'
3213 ' GBusType bus_type,\n'
3214 ' GDBusObjectManagerClientFlags flags,\n'
3215 ' const gchar *name,\n'
3216 ' const gchar *object_path,\n'
3217 ' GCancellable *cancellable,\n'
3218 ' GAsyncReadyCallback callback,\n'
3219 ' gpointer user_data)\n'
3221 ' 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'
3224 %(self.ns_lower, self.ns_upper, self.ns_lower))
3225 self.c.write('/**\n'
3226 ' * %sobject_manager_client_new_for_bus_finish:\n'
3227 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new_for_bus().\n'
3228 ' * @error: Return location for error or %%NULL\n'
3230 ' * Finishes an operation started with %sobject_manager_client_new_for_bus().\n'
3232 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3233 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3234 self.c.write(' */\n')
3235 self.c.write('GDBusObjectManager *\n'
3236 '%sobject_manager_client_new_for_bus_finish (\n'
3237 ' GAsyncResult *res,\n'
3238 ' GError **error)\n'
3241 ' GObject *source_object;\n'
3242 ' source_object = g_async_result_get_source_object (res);\n'
3243 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3244 ' g_object_unref (source_object);\n'
3245 ' if (ret != NULL)\n'
3246 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3252 self.c.write(self.docbook_gen.expand(
3254 ' * %sobject_manager_client_new_for_bus_sync:\n'
3255 ' * @bus_type: A #GBusType.\n'
3256 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3257 ' * @name: A bus name (well-known or unique).\n'
3258 ' * @object_path: An object path.\n'
3259 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3260 ' * @error: Return location for error or %%NULL\n'
3262 ' * Like %sobject_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
3264 ' * The calling thread is blocked until a reply is received.\n'
3266 ' * See %sobject_manager_client_new_for_bus() for the asynchronous version of this constructor.\n'
3268 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3269 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3270 self.c.write(' */\n')
3271 self.c.write('GDBusObjectManager *\n'
3272 '%sobject_manager_client_new_for_bus_sync (\n'
3273 ' GBusType bus_type,\n'
3274 ' GDBusObjectManagerClientFlags flags,\n'
3275 ' const gchar *name,\n'
3276 ' const gchar *object_path,\n'
3277 ' GCancellable *cancellable,\n'
3278 ' GError **error)\n'
3280 ' GInitable *ret;\n'
3281 ' 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'
3282 ' if (ret != NULL)\n'
3283 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3288 %(self.ns_lower, self.ns_upper, self.ns_lower))
3291 # ---------------------------------------------------------------------------------------------------
3293 def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
3294 if len(obj.since) > 0:
3297 %(indent, '', indent, '', obj.since))
3299 if isinstance(obj, dbustypes.Interface):
3300 thing = 'The D-Bus interface'
3301 elif isinstance(obj, dbustypes.Method):
3302 thing = 'The D-Bus method'
3303 elif isinstance(obj, dbustypes.Signal):
3304 thing = 'The D-Bus signal'
3305 elif isinstance(obj, dbustypes.Property):
3306 thing = 'The D-Bus property'
3308 raise RuntimeError('Cannot handle object ', obj)
3309 f.write(self.docbook_gen.expand(
3311 '%*s * Deprecated: %s has been deprecated.\n'
3312 %(indent, '', indent, '', thing), False))
3313 f.write('%*s */\n'%(indent, ''))
3315 # ---------------------------------------------------------------------------------------------------
3317 def generate_interface_intro(self, i):
3318 self.c.write('/* ------------------------------------------------------------------------\n'
3319 ' * Code for interface %s\n'
3320 ' * ------------------------------------------------------------------------\n'
3324 self.c.write(self.docbook_gen.expand(
3328 ' * @short_description: Generated C code for the %s D-Bus interface\n'
3330 ' * This section contains code for working with the #%s D-Bus interface in C.\n'
3332 %(i.camel_name, i.camel_name, i.name, i.name), False))
3336 self.generate_intro()
3337 self.declare_types()
3338 for i in self.ifaces:
3339 self.generate_interface_intro(i)
3340 self.generate_introspection_for_interface(i)
3341 self.generate_interface(i)
3342 self.generate_property_accessors(i)
3343 self.generate_signal_emitters(i)
3344 self.generate_method_calls(i)
3345 self.generate_method_completers(i)
3346 self.generate_proxy(i)
3347 self.generate_skeleton(i)
3348 if self.generate_objmanager:
3349 self.generate_object()
3350 self.generate_object_manager_client()
3351 self.generate_outro()