3 # GDBus - GLib D-Bus Library
5 # Copyright (C) 2008-2011 Red Hat, Inc.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General
18 # Public License along with this library; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA 02111-1307, USA.
22 # Author: David Zeuthen <davidz@redhat.com>
28 from . import dbustypes
30 # ----------------------------------------------------------------------------------------------------
33 def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, docbook_gen, h, c):
34 self.docbook_gen = docbook_gen
35 self.generate_objmanager = generate_objmanager
39 self.namespace = namespace
40 if len(namespace) > 0:
41 if utils.is_ugly_case(namespace):
42 self.namespace = namespace.replace('_', '')
43 self.ns_upper = namespace.upper() + '_'
44 self.ns_lower = namespace.lower() + '_'
46 self.ns_upper = utils.camel_case_to_uscore(namespace).upper() + '_'
47 self.ns_lower = utils.camel_case_to_uscore(namespace).lower() + '_'
51 self.interface_prefix = interface_prefix
52 self.header_guard = self.h.name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
54 # ----------------------------------------------------------------------------------------------------
56 def generate_intro(self):
58 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
60 ' * The license of this code is the same as for the source it was derived from.\n'
64 self.c.write('#ifdef HAVE_CONFIG_H\n'
65 '# include "config.h"\n'
71 self.c.write('#ifdef G_OS_UNIX\n'
72 '# include <gio/gunixfdlist.h>\n'
76 self.c.write('typedef struct\n'
78 ' GDBusArgInfo parent_struct;\n'
79 ' gboolean use_gvariant;\n'
80 '} _ExtendedGDBusArgInfo;\n'
83 self.c.write('typedef struct\n'
85 ' GDBusMethodInfo parent_struct;\n'
86 ' const gchar *signal_name;\n'
87 ' gboolean pass_fdlist;\n'
88 '} _ExtendedGDBusMethodInfo;\n'
91 self.c.write('typedef struct\n'
93 ' GDBusSignalInfo parent_struct;\n'
94 ' const gchar *signal_name;\n'
95 '} _ExtendedGDBusSignalInfo;\n'
98 self.c.write('typedef struct\n'
100 ' GDBusPropertyInfo parent_struct;\n'
101 ' const gchar *hyphen_name;\n'
102 ' gboolean use_gvariant;\n'
103 '} _ExtendedGDBusPropertyInfo;\n'
106 self.c.write('typedef struct\n'
108 ' GDBusInterfaceInfo parent_struct;\n'
109 ' const gchar *hyphen_name;\n'
110 '} _ExtendedGDBusInterfaceInfo;\n'
113 self.c.write('typedef struct\n'
115 ' const _ExtendedGDBusPropertyInfo *info;\n'
117 ' GValue orig_value; /* the value before the change */\n'
118 '} ChangedProperty;\n'
121 '_changed_property_free (ChangedProperty *data)\n'
123 ' g_value_unset (&data->orig_value);\n'
128 self.c.write('static gboolean\n'
129 '_g_strv_equal0 (gchar **a, gchar **b)\n'
131 ' gboolean ret = FALSE;\n'
133 ' if (a == NULL && b == NULL)\n'
138 ' if (a == NULL || b == NULL)\n'
140 ' if (g_strv_length (a) != g_strv_length (b))\n'
142 ' for (n = 0; a[n] != NULL; n++)\n'
143 ' if (g_strcmp0 (a[n], b[n]) != 0)\n'
151 self.c.write('static gboolean\n'
152 '_g_variant_equal0 (GVariant *a, GVariant *b)\n'
154 ' gboolean ret = FALSE;\n'
155 ' if (a == NULL && b == NULL)\n'
160 ' if (a == NULL || b == NULL)\n'
162 ' ret = g_variant_equal (a, b);\n'
168 # simplified - only supports the types we use
169 self.c.write('G_GNUC_UNUSED static gboolean\n'
170 '_g_value_equal (const GValue *a, const GValue *b)\n'
172 ' gboolean ret = FALSE;\n'
173 ' g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b));\n'
174 ' switch (G_VALUE_TYPE (a))\n'
176 ' case G_TYPE_BOOLEAN:\n'
177 ' ret = (g_value_get_boolean (a) == g_value_get_boolean (b));\n'
179 ' case G_TYPE_UCHAR:\n'
180 ' ret = (g_value_get_uchar (a) == g_value_get_uchar (b));\n'
182 ' case G_TYPE_INT:\n'
183 ' ret = (g_value_get_int (a) == g_value_get_int (b));\n'
185 ' case G_TYPE_UINT:\n'
186 ' ret = (g_value_get_uint (a) == g_value_get_uint (b));\n'
188 ' case G_TYPE_INT64:\n'
189 ' ret = (g_value_get_int64 (a) == g_value_get_int64 (b));\n'
191 ' case G_TYPE_UINT64:\n'
192 ' ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n'
194 ' case G_TYPE_DOUBLE:\n'
195 ' ret = (g_value_get_double (a) == g_value_get_double (b));\n'
197 ' case G_TYPE_STRING:\n'
198 ' ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n'
200 ' case G_TYPE_VARIANT:\n'
201 ' ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b));\n'
204 ' if (G_VALUE_TYPE (a) == G_TYPE_STRV)\n'
205 ' ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b));\n'
207 ' g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a)));\n'
215 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
217 ' * The license of this code is the same as for the source it was derived from.\n'
222 '\n'%(config.VERSION, self.header_guard, self.header_guard))
223 self.h.write('#include <gio/gio.h>\n'
228 # ----------------------------------------------------------------------------------------------------
230 def declare_types(self):
231 for i in self.ifaces:
233 self.h.write('/* ------------------------------------------------------------------------ */\n')
234 self.h.write('/* Declarations for %s */\n'%i.name)
237 # First the GInterface
238 self.h.write('#define %sTYPE_%s (%s_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
239 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))
240 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))
241 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))
243 self.h.write('struct _%s;\n'%(i.camel_name))
244 self.h.write('typedef struct _%s %s;\n'%(i.camel_name, i.camel_name))
245 self.h.write('typedef struct _%sIface %sIface;\n'%(i.camel_name, i.camel_name))
247 self.h.write('struct _%sIface\n'%(i.camel_name))
249 self.h.write(' GTypeInterface parent_iface;\n')
251 function_pointers = {}
254 if len(i.methods) > 0:
258 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
260 key = (m.since, '_method_%s'%m.name_lower)
261 value = ' gboolean (*handle_%s) (\n'%(m.name_lower)
262 value += ' %s *object,\n'%(i.camel_name)
263 value += ' GDBusMethodInvocation *invocation'%()
265 value += ',\n GUnixFDList *fd_list'
267 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
269 function_pointers[key] = value
272 if len(i.signals) > 0:
275 key = (s.since, '_signal_%s'%s.name_lower)
276 value = ' void (*%s) (\n'%(s.name_lower)
277 value += ' %s *object'%(i.camel_name)
279 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
281 function_pointers[key] = value
283 # vfuncs for properties
284 if len(i.properties) > 0:
286 for p in i.properties:
287 key = (p.since, '_prop_get_%s'%p.name_lower)
288 value = ' %s (*get_%s) (%s *object);\n\n'%(p.arg.ctype_in, p.name_lower, i.camel_name)
289 function_pointers[key] = value
291 # Sort according to @since tag, then name.. this ensures
292 # that the function pointers don't change order assuming
293 # judicious use of @since
295 # Also use a proper version comparison function so e.g.
296 # 10.0 comes after 2.0.
298 # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
300 keys = function_pointers.keys()
302 keys.sort(cmp=utils.my_version_cmp)
304 self.h.write('%s'%function_pointers[key])
308 self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
310 self.h.write('GDBusInterfaceInfo *%s_interface_info (void);\n'%(i.name_lower))
311 self.h.write('guint %s_override_properties (GObjectClass *klass, guint property_id_begin);\n'%(i.name_lower))
314 # Then method call completion functions
315 if len(i.methods) > 0:
317 self.h.write('/* D-Bus method call completion functions: */\n')
320 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
323 self.h.write('G_GNUC_DEPRECATED ')
324 self.h.write('void %s_complete_%s (\n'
326 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
328 self.h.write(',\n GUnixFDList *fd_list')
330 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
335 # Then signal emission functions
336 if len(i.signals) > 0:
338 self.h.write('/* D-Bus signal emissions functions: */\n')
341 self.h.write('G_GNUC_DEPRECATED ')
342 self.h.write('void %s_emit_%s (\n'
343 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
345 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
350 # Then method call declarations
351 if len(i.methods) > 0:
353 self.h.write('/* D-Bus method calls: */\n')
356 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
360 self.h.write('G_GNUC_DEPRECATED ')
361 self.h.write('void %s_call_%s (\n'
362 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
364 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
366 self.h.write(',\n GUnixFDList *fd_list')
368 ' GCancellable *cancellable,\n'
369 ' GAsyncReadyCallback callback,\n'
370 ' gpointer user_data);\n')
374 self.h.write('G_GNUC_DEPRECATED ')
375 self.h.write('gboolean %s_call_%s_finish (\n'
376 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
378 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
380 self.h.write(',\n GUnixFDList **out_fd_list')
382 ' GAsyncResult *res,\n'
383 ' GError **error);\n')
387 self.h.write('G_GNUC_DEPRECATED ')
388 self.h.write('gboolean %s_call_%s_sync (\n'
389 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
391 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
393 self.h.write(',\n GUnixFDList *fd_list')
395 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
397 self.h.write(',\n GUnixFDList **out_fd_list')
399 ' GCancellable *cancellable,\n'
400 ' GError **error);\n')
404 # Then the property accessor declarations
405 if len(i.properties) > 0:
407 self.h.write('/* D-Bus property accessors: */\n')
408 for p in i.properties:
411 self.h.write('G_GNUC_DEPRECATED ')
412 self.h.write('%s%s_get_%s (%s *object);\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
413 if p.arg.free_func != None:
415 self.h.write('G_GNUC_DEPRECATED ')
416 self.h.write('%s%s_dup_%s (%s *object);\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name))
419 self.h.write('G_GNUC_DEPRECATED ')
420 self.h.write('void %s_set_%s (%s *object, %svalue);\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
425 self.h.write('/* ---- */\n')
427 self.h.write('#define %sTYPE_%s_PROXY (%s_proxy_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
428 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))
429 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))
430 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))
431 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))
432 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))
434 self.h.write('typedef struct _%sProxy %sProxy;\n'%(i.camel_name, i.camel_name))
435 self.h.write('typedef struct _%sProxyClass %sProxyClass;\n'%(i.camel_name, i.camel_name))
436 self.h.write('typedef struct _%sProxyPrivate %sProxyPrivate;\n'%(i.camel_name, i.camel_name))
438 self.h.write('struct _%sProxy\n'%(i.camel_name))
440 self.h.write(' /*< private >*/\n')
441 self.h.write(' GDBusProxy parent_instance;\n')
442 self.h.write(' %sProxyPrivate *priv;\n'%(i.camel_name))
445 self.h.write('struct _%sProxyClass\n'%(i.camel_name))
447 self.h.write(' GDBusProxyClass parent_class;\n')
450 self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
454 self.h.write('G_GNUC_DEPRECATED ')
455 self.h.write('void %s_proxy_new (\n'
456 ' GDBusConnection *connection,\n'
457 ' GDBusProxyFlags flags,\n'
458 ' const gchar *name,\n'
459 ' const gchar *object_path,\n'
460 ' GCancellable *cancellable,\n'
461 ' GAsyncReadyCallback callback,\n'
462 ' gpointer user_data);\n'
465 self.h.write('G_GNUC_DEPRECATED ')
466 self.h.write('%s *%s_proxy_new_finish (\n'
467 ' GAsyncResult *res,\n'
468 ' GError **error);\n'
469 %(i.camel_name, i.name_lower))
471 self.h.write('G_GNUC_DEPRECATED ')
472 self.h.write('%s *%s_proxy_new_sync (\n'
473 ' GDBusConnection *connection,\n'
474 ' GDBusProxyFlags flags,\n'
475 ' const gchar *name,\n'
476 ' const gchar *object_path,\n'
477 ' GCancellable *cancellable,\n'
478 ' GError **error);\n'
479 %(i.camel_name, i.name_lower))
482 self.h.write('G_GNUC_DEPRECATED ')
483 self.h.write('void %s_proxy_new_for_bus (\n'
484 ' GBusType bus_type,\n'
485 ' GDBusProxyFlags flags,\n'
486 ' const gchar *name,\n'
487 ' const gchar *object_path,\n'
488 ' GCancellable *cancellable,\n'
489 ' GAsyncReadyCallback callback,\n'
490 ' gpointer user_data);\n'
493 self.h.write('G_GNUC_DEPRECATED ')
494 self.h.write('%s *%s_proxy_new_for_bus_finish (\n'
495 ' GAsyncResult *res,\n'
496 ' GError **error);\n'
497 %(i.camel_name, i.name_lower))
499 self.h.write('G_GNUC_DEPRECATED ')
500 self.h.write('%s *%s_proxy_new_for_bus_sync (\n'
501 ' GBusType bus_type,\n'
502 ' GDBusProxyFlags flags,\n'
503 ' const gchar *name,\n'
504 ' const gchar *object_path,\n'
505 ' GCancellable *cancellable,\n'
506 ' GError **error);\n'
507 %(i.camel_name, i.name_lower))
512 self.h.write('/* ---- */\n')
514 self.h.write('#define %sTYPE_%s_SKELETON (%s_skeleton_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
515 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))
516 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))
517 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))
518 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))
519 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))
521 self.h.write('typedef struct _%sSkeleton %sSkeleton;\n'%(i.camel_name, i.camel_name))
522 self.h.write('typedef struct _%sSkeletonClass %sSkeletonClass;\n'%(i.camel_name, i.camel_name))
523 self.h.write('typedef struct _%sSkeletonPrivate %sSkeletonPrivate;\n'%(i.camel_name, i.camel_name))
525 self.h.write('struct _%sSkeleton\n'%(i.camel_name))
527 self.h.write(' /*< private >*/\n')
528 self.h.write(' GDBusInterfaceSkeleton parent_instance;\n')
529 self.h.write(' %sSkeletonPrivate *priv;\n'%(i.camel_name))
532 self.h.write('struct _%sSkeletonClass\n'%(i.camel_name))
534 self.h.write(' GDBusInterfaceSkeletonClass parent_class;\n')
537 self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
540 self.h.write('G_GNUC_DEPRECATED ')
541 self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
545 # Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
546 if self.generate_objmanager:
548 self.h.write('/* ---- */\n')
550 self.h.write('#define %sTYPE_OBJECT (%sobject_get_type ())\n'%(self.ns_upper, self.ns_lower))
551 self.h.write('#define %sOBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
552 self.h.write('#define %sIS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT))\n'%(self.ns_upper, self.ns_upper))
553 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))
555 self.h.write('struct _%sObject;\n'%(self.namespace))
556 self.h.write('typedef struct _%sObject %sObject;\n'%(self.namespace, self.namespace))
557 self.h.write('typedef struct _%sObjectIface %sObjectIface;\n'%(self.namespace, self.namespace))
559 self.h.write('struct _%sObjectIface\n'%(self.namespace))
561 ' GTypeInterface parent_iface;\n'
564 self.h.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
567 for i in self.ifaces:
569 self.h.write('G_GNUC_DEPRECATED ')
570 self.h.write ('%s *%sobject_get_%s (%sObject *object);\n'
571 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
572 for i in self.ifaces:
574 self.h.write('G_GNUC_DEPRECATED ')
575 self.h.write ('%s *%sobject_peek_%s (%sObject *object);\n'
576 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
578 self.h.write('#define %sTYPE_OBJECT_PROXY (%sobject_proxy_get_type ())\n'%(self.ns_upper, self.ns_lower))
579 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))
580 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))
581 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))
582 self.h.write('#define %sIS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
583 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))
585 self.h.write('typedef struct _%sObjectProxy %sObjectProxy;\n'%(self.namespace, self.namespace))
586 self.h.write('typedef struct _%sObjectProxyClass %sObjectProxyClass;\n'%(self.namespace, self.namespace))
587 self.h.write('typedef struct _%sObjectProxyPrivate %sObjectProxyPrivate;\n'%(self.namespace, self.namespace))
589 self.h.write('struct _%sObjectProxy\n'%(self.namespace))
591 self.h.write(' /*< private >*/\n')
592 self.h.write(' GDBusObjectProxy parent_instance;\n')
593 self.h.write(' %sObjectProxyPrivate *priv;\n'%(self.namespace))
596 self.h.write('struct _%sObjectProxyClass\n'%(self.namespace))
598 self.h.write(' GDBusObjectProxyClass parent_class;\n')
601 self.h.write('GType %sobject_proxy_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
602 self.h.write('%sObjectProxy *%sobject_proxy_new (GDBusConnection *connection, const gchar *object_path);\n'%(self.namespace, self.ns_lower))
604 self.h.write('#define %sTYPE_OBJECT_SKELETON (%sobject_skeleton_get_type ())\n'%(self.ns_upper, self.ns_lower))
605 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))
606 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))
607 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))
608 self.h.write('#define %sIS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
609 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))
611 self.h.write('typedef struct _%sObjectSkeleton %sObjectSkeleton;\n'%(self.namespace, self.namespace))
612 self.h.write('typedef struct _%sObjectSkeletonClass %sObjectSkeletonClass;\n'%(self.namespace, self.namespace))
613 self.h.write('typedef struct _%sObjectSkeletonPrivate %sObjectSkeletonPrivate;\n'%(self.namespace, self.namespace))
615 self.h.write('struct _%sObjectSkeleton\n'%(self.namespace))
617 self.h.write(' /*< private >*/\n')
618 self.h.write(' GDBusObjectSkeleton parent_instance;\n')
619 self.h.write(' %sObjectSkeletonPrivate *priv;\n'%(self.namespace))
622 self.h.write('struct _%sObjectSkeletonClass\n'%(self.namespace))
624 self.h.write(' GDBusObjectSkeletonClass parent_class;\n')
627 self.h.write('GType %sobject_skeleton_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
628 self.h.write('%sObjectSkeleton *%sobject_skeleton_new (const gchar *object_path);\n'
629 %(self.namespace, self.ns_lower))
630 for i in self.ifaces:
632 self.h.write('G_GNUC_DEPRECATED ')
633 self.h.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_);\n'
634 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
637 self.h.write('/* ---- */\n')
639 self.h.write('#define %sTYPE_OBJECT_MANAGER_CLIENT (%sobject_manager_client_get_type ())\n'%(self.ns_upper, self.ns_lower))
640 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))
641 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))
642 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))
643 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))
644 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))
646 self.h.write('typedef struct _%sObjectManagerClient %sObjectManagerClient;\n'%(self.namespace, self.namespace))
647 self.h.write('typedef struct _%sObjectManagerClientClass %sObjectManagerClientClass;\n'%(self.namespace, self.namespace))
648 self.h.write('typedef struct _%sObjectManagerClientPrivate %sObjectManagerClientPrivate;\n'%(self.namespace, self.namespace))
650 self.h.write('struct _%sObjectManagerClient\n'%(self.namespace))
652 self.h.write(' /*< private >*/\n')
653 self.h.write(' GDBusObjectManagerClient parent_instance;\n')
654 self.h.write(' %sObjectManagerClientPrivate *priv;\n'%(self.namespace))
657 self.h.write('struct _%sObjectManagerClientClass\n'%(self.namespace))
659 self.h.write(' GDBusObjectManagerClientClass parent_class;\n')
662 self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
664 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))
666 self.h.write('void %sobject_manager_client_new (\n'
667 ' GDBusConnection *connection,\n'
668 ' GDBusObjectManagerClientFlags flags,\n'
669 ' const gchar *name,\n'
670 ' const gchar *object_path,\n'
671 ' GCancellable *cancellable,\n'
672 ' GAsyncReadyCallback callback,\n'
673 ' gpointer user_data);\n'
675 self.h.write('GDBusObjectManager *%sobject_manager_client_new_finish (\n'
676 ' GAsyncResult *res,\n'
677 ' GError **error);\n'
679 self.h.write('GDBusObjectManager *%sobject_manager_client_new_sync (\n'
680 ' GDBusConnection *connection,\n'
681 ' GDBusObjectManagerClientFlags flags,\n'
682 ' const gchar *name,\n'
683 ' const gchar *object_path,\n'
684 ' GCancellable *cancellable,\n'
685 ' GError **error);\n'
688 self.h.write('void %sobject_manager_client_new_for_bus (\n'
689 ' GBusType bus_type,\n'
690 ' GDBusObjectManagerClientFlags flags,\n'
691 ' const gchar *name,\n'
692 ' const gchar *object_path,\n'
693 ' GCancellable *cancellable,\n'
694 ' GAsyncReadyCallback callback,\n'
695 ' gpointer user_data);\n'
697 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_finish (\n'
698 ' GAsyncResult *res,\n'
699 ' GError **error);\n'
701 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_sync (\n'
702 ' GBusType bus_type,\n'
703 ' GDBusObjectManagerClientFlags flags,\n'
704 ' const gchar *name,\n'
705 ' const gchar *object_path,\n'
706 ' GCancellable *cancellable,\n'
707 ' GError **error);\n'
711 # ----------------------------------------------------------------------------------------------------
713 def generate_outro(self):
717 '#endif /* __%s__ */\n'%(self.header_guard))
719 # ----------------------------------------------------------------------------------------------------
721 def generate_annotations(self, prefix, annotations):
722 if annotations == None:
726 for a in annotations:
727 #self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
729 # skip internal annotations
730 if a.key.startswith('org.gtk.GDBus'):
733 self.c.write('static const GDBusAnnotationInfo %s_%d =\n'
737 ' "%s",\n'%(prefix, n, a.key, a.value))
738 if len(a.annotations) == 0:
739 self.c.write(' NULL\n')
741 self.c.write(' (GDBusAnnotationInfo **) &%s_%d_pointers\n'%(prefix, n))
747 self.c.write('static const GDBusAnnotationInfo * const %s_pointers[] =\n'
750 for a in annotations:
751 if a.key.startswith('org.gtk.GDBus'):
753 self.c.write(' &%s_%d,\n'%(prefix, m))
755 self.c.write(' NULL\n'
760 def generate_args(self, prefix, args):
762 num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
764 self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
769 ' "%s",\n'%(prefix, a.name, a.name, a.signature))
771 self.c.write(' NULL\n')
773 self.c.write(' (GDBusAnnotationInfo **) &%s_arg_%s_annotation_info_pointers\n'%(prefix, a.name))
774 self.c.write(' },\n')
775 if not utils.lookup_annotation(a.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
776 self.c.write(' FALSE\n')
778 self.c.write(' TRUE\n')
783 self.c.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
786 self.c.write(' &%s_%s,\n'%(prefix, a.name))
787 self.c.write(' NULL\n'
791 def generate_introspection_for_interface(self, i):
792 self.c.write('/* ---- Introspection data for %s ---- */\n'
795 if len(i.methods) > 0:
798 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
800 self.generate_args('_%s_method_info_%s_IN_ARG'%(i.name_lower, m.name_lower), m.in_args)
801 self.generate_args('_%s_method_info_%s_OUT_ARG'%(i.name_lower, m.name_lower), m.out_args)
803 num_anno = self.generate_annotations('_%s_method_%s_annotation_info'%(i.name_lower, m.name_lower), m.annotations)
805 self.c.write('static const _ExtendedGDBusMethodInfo _%s_method_info_%s =\n'
809 ' "%s",\n'%(i.name_lower, m.name_lower, m.name))
810 if len(m.in_args) == 0:
811 self.c.write(' NULL,\n')
813 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_IN_ARG_pointers,\n'%(i.name_lower, m.name_lower))
814 if len(m.out_args) == 0:
815 self.c.write(' NULL,\n')
817 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_OUT_ARG_pointers,\n'%(i.name_lower, m.name_lower))
819 self.c.write(' NULL\n')
821 self.c.write(' (GDBusAnnotationInfo **) &_%s_method_%s_annotation_info_pointers\n'%(i.name_lower, m.name_lower))
825 %(m.name_hyphen, 'TRUE' if unix_fd else 'FALSE'))
829 self.c.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] =\n'
830 '{\n'%(i.name_lower))
832 self.c.write(' &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
833 self.c.write(' NULL\n'
839 if len(i.signals) > 0:
841 self.generate_args('_%s_signal_info_%s_ARG'%(i.name_lower, s.name_lower), s.args)
843 num_anno = self.generate_annotations('_%s_signal_%s_annotation_info'%(i.name_lower, s.name_lower), s.annotations)
844 self.c.write('static const _ExtendedGDBusSignalInfo _%s_signal_info_%s =\n'
848 ' "%s",\n'%(i.name_lower, s.name_lower, s.name))
850 self.c.write(' NULL,\n')
852 self.c.write(' (GDBusArgInfo **) &_%s_signal_info_%s_ARG_pointers,\n'%(i.name_lower, s.name_lower))
854 self.c.write(' NULL\n')
856 self.c.write(' (GDBusAnnotationInfo **) &_%s_signal_%s_annotation_info_pointers\n'%(i.name_lower, s.name_lower))
863 self.c.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
864 '{\n'%(i.name_lower))
866 self.c.write(' &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
867 self.c.write(' NULL\n'
873 if len(i.properties) > 0:
874 for p in i.properties:
875 if p.readable and p.writable:
876 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
878 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE'
880 access = 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
882 access = 'G_DBUS_PROPERTY_INFO_FLAGS_NONE'
883 num_anno = self.generate_annotations('_%s_property_%s_annotation_info'%(i.name_lower, p.name_lower), p.annotations)
884 self.c.write('static const _ExtendedGDBusPropertyInfo _%s_property_info_%s =\n'
890 ' %s,\n'%(i.name_lower, p.name_lower, p.name, p.arg.signature, access))
892 self.c.write(' NULL\n')
894 self.c.write(' (GDBusAnnotationInfo **) &_%s_property_%s_annotation_info_pointers\n'%(i.name_lower, p.name_lower))
898 if not utils.lookup_annotation(p.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
899 self.c.write(' FALSE\n')
901 self.c.write(' TRUE\n')
905 self.c.write('static const _ExtendedGDBusPropertyInfo * const _%s_property_info_pointers[] =\n'
906 '{\n'%(i.name_lower))
907 for p in i.properties:
908 self.c.write(' &_%s_property_info_%s,\n'%(i.name_lower, p.name_lower))
909 self.c.write(' NULL\n'
913 num_anno = self.generate_annotations('_%s_annotation_info'%(i.name_lower), i.annotations)
914 self.c.write('static const _ExtendedGDBusInterfaceInfo _%s_interface_info =\n'
918 ' "%s",\n'%(i.name_lower, i.name))
919 if len(i.methods) == 0:
920 self.c.write(' NULL,\n')
922 self.c.write(' (GDBusMethodInfo **) &_%s_method_info_pointers,\n'%(i.name_lower))
923 if len(i.signals) == 0:
924 self.c.write(' NULL,\n')
926 self.c.write(' (GDBusSignalInfo **) &_%s_signal_info_pointers,\n'%(i.name_lower))
927 if len(i.properties) == 0:
928 self.c.write(' NULL,\n')
930 self.c.write(' (GDBusPropertyInfo **) &_%s_property_info_pointers,\n'%(i.name_lower))
932 self.c.write(' NULL\n')
934 self.c.write(' (GDBusAnnotationInfo **) &_%s_annotation_info_pointers\n'%(i.name_lower))
941 self.c.write(self.docbook_gen.expand(
943 ' * %s_interface_info:\n'
945 ' * Gets a machine-readable description of the #%s D-Bus interface.\n'
947 ' * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free.\n'
948 %(i.name_lower, i.name), False))
949 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
950 self.c.write('GDBusInterfaceInfo *\n'
951 '%s_interface_info (void)\n'
953 ' return (GDBusInterfaceInfo *) &_%s_interface_info;\n'
955 '\n'%(i.name_lower, i.name_lower))
957 self.c.write(self.docbook_gen.expand(
959 ' * %s_override_properties:\n'
960 ' * @klass: The class structure for a #GObject<!-- -->-derived class.\n'
961 ' * @property_id_begin: The property id to assign to the first overridden property.\n'
963 ' * Overrides all #GObject properties in the #%s interface for a concrete class.\n'
964 ' * The properties are overridden in the order they are defined.\n'
966 ' * Returns: The last property id.\n'
967 %(i.name_lower, i.camel_name), False))
968 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
969 self.c.write('guint\n'
970 '%s_override_properties (GObjectClass *klass, guint property_id_begin)\n'
971 '{\n'%(i.name_lower))
972 for p in i.properties:
973 self.c.write (' g_object_class_override_property (klass, property_id_begin++, "%s");\n'%(p.name_hyphen))
974 self.c.write(' return property_id_begin - 1;\n'
979 # ----------------------------------------------------------------------------------------------------
981 def generate_interface(self, i):
984 self.c.write(self.docbook_gen.expand(
988 ' * Abstract interface type for the D-Bus interface #%s.\n'
989 %(i.camel_name, i.name), False))
990 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
993 self.c.write(self.docbook_gen.expand(
996 ' * @parent_iface: The parent interface.\n'
997 %(i.camel_name), False))
1000 if len(i.methods) > 0:
1002 key = (m.since, '_method_%s'%m.name_lower)
1003 value = '@handle_%s: '%(m.name_lower)
1004 value += 'Handler for the #%s::handle-%s signal.'%(i.camel_name, m.name_hyphen)
1005 doc_bits[key] = value
1006 if len(i.signals) > 0:
1008 key = (s.since, '_signal_%s'%s.name_lower)
1009 value = '@%s: '%(s.name_lower)
1010 value += 'Handler for the #%s::%s signal.'%(i.camel_name, s.name_hyphen)
1011 doc_bits[key] = value
1012 if len(i.properties) > 0:
1013 for p in i.properties:
1014 key = (p.since, '_prop_get_%s'%p.name_lower)
1015 value = '@get_%s: '%(p.name_lower)
1016 value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
1017 doc_bits[key] = value
1018 keys = doc_bits.keys()
1020 keys.sort(cmp=utils.my_version_cmp)
1022 self.c.write(' * %s\n'%doc_bits[key])
1023 self.c.write(self.docbook_gen.expand(
1025 ' * Virtual table for the D-Bus interface #%s.\n'
1027 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1030 self.c.write('static void\n'
1031 '%s_default_init (%sIface *iface)\n'
1032 '{\n'%(i.name_lower, i.camel_name));
1034 if len(i.methods) > 0:
1035 self.c.write(' /* GObject signals for incoming D-Bus method calls: */\n')
1038 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1040 self.c.write(self.docbook_gen.expand(
1042 ' * %s::handle-%s:\n'
1043 ' * @object: A #%s.\n'
1044 ' * @invocation: A #GDBusMethodInvocation.\n'
1045 %(i.camel_name, m.name_hyphen, i.camel_name), False))
1047 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1049 self.c.write (' * @arg_%s: Argument passed by remote caller.\n'%(a.name))
1050 self.c.write(self.docbook_gen.expand(
1052 ' * Signal emitted when a remote caller is invoking the %s.%s() D-Bus method.\n'
1054 ' * 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'
1056 ' * Returns: %%TRUE if the invocation was handled, %%FALSE to let other signal handlers run.\n'
1057 %(i.name, m.name, i.name_lower, m.name_lower), False))
1058 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 2)
1063 self.c.write(' g_signal_new ("handle-%s",\n'
1064 ' G_TYPE_FROM_INTERFACE (iface),\n'
1065 ' G_SIGNAL_RUN_LAST,\n'
1066 ' G_STRUCT_OFFSET (%sIface, handle_%s),\n'
1067 ' g_signal_accumulator_true_handled,\n'
1068 ' NULL,\n' # accu_data
1069 ' g_cclosure_marshal_generic,\n'
1070 ' G_TYPE_BOOLEAN,\n'
1072 ' G_TYPE_DBUS_METHOD_INVOCATION'
1073 %(m.name_hyphen, i.camel_name, m.name_lower, len(m.in_args) + extra_args))
1075 self.c.write(', G_TYPE_UNIX_FD_LIST')
1077 self.c.write (', %s'%(a.gtype))
1078 self.c.write(');\n')
1081 if len(i.signals) > 0:
1082 self.c.write(' /* GObject signals for received D-Bus signals: */\n')
1084 self.c.write(self.docbook_gen.expand(
1087 ' * @object: A #%s.\n'
1088 %(i.camel_name, s.name_hyphen, i.camel_name), False))
1090 self.c.write (' * @arg_%s: Argument.\n'%(a.name))
1091 self.c.write(self.docbook_gen.expand(
1093 ' * On the client-side, this signal is emitted whenever the D-Bus signal #%s::%s is received.\n'
1095 ' * 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'
1096 %(i.name, s.name), False))
1097 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 2)
1098 self.c.write(' g_signal_new ("%s",\n'
1099 ' G_TYPE_FROM_INTERFACE (iface),\n'
1100 ' G_SIGNAL_RUN_LAST,\n'
1101 ' G_STRUCT_OFFSET (%sIface, %s),\n'
1102 ' NULL,\n' # accumulator
1103 ' NULL,\n' # accu_data
1104 ' g_cclosure_marshal_generic,\n'
1107 %(s.name_hyphen, i.camel_name, s.name_lower, len(s.args)))
1109 self.c.write (', %s'%(a.gtype))
1110 self.c.write(');\n')
1113 if len(i.properties) > 0:
1114 self.c.write(' /* GObject properties for D-Bus properties: */\n')
1115 for p in i.properties:
1116 if p.readable and p.writable:
1117 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.'
1119 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.'
1121 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.'
1123 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1124 self.c.write(self.docbook_gen.expand(
1128 ' * Represents the D-Bus property #%s:%s.\n'
1131 %(i.camel_name, p.name_hyphen, i.name, p.name, hint), False))
1132 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 2)
1133 self.c.write(' g_object_interface_install_property (iface,\n')
1134 if p.arg.gtype == 'G_TYPE_VARIANT':
1135 s = 'g_param_spec_variant ("%s", "%s", "%s", G_VARIANT_TYPE ("%s"), NULL'%(p.name_hyphen, p.name, p.name, p.arg.signature)
1136 elif p.arg.signature == 'b':
1137 s = 'g_param_spec_boolean ("%s", "%s", "%s", FALSE'%(p.name_hyphen, p.name, p.name)
1138 elif p.arg.signature == 'y':
1139 s = 'g_param_spec_uchar ("%s", "%s", "%s", 0, 255, 0'%(p.name_hyphen, p.name, p.name)
1140 elif p.arg.signature == 'n':
1141 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT16, G_MAXINT16, 0'%(p.name_hyphen, p.name, p.name)
1142 elif p.arg.signature == 'q':
1143 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT16, 0'%(p.name_hyphen, p.name, p.name)
1144 elif p.arg.signature == 'i':
1145 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT32, G_MAXINT32, 0'%(p.name_hyphen, p.name, p.name)
1146 elif p.arg.signature == 'u':
1147 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT32, 0'%(p.name_hyphen, p.name, p.name)
1148 elif p.arg.signature == 'x':
1149 s = 'g_param_spec_int64 ("%s", "%s", "%s", G_MININT64, G_MAXINT64, 0'%(p.name_hyphen, p.name, p.name)
1150 elif p.arg.signature == 't':
1151 s = 'g_param_spec_uint64 ("%s", "%s", "%s", 0, G_MAXUINT64, 0'%(p.name_hyphen, p.name, p.name)
1152 elif p.arg.signature == 'd':
1153 s = 'g_param_spec_double ("%s", "%s", "%s", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0'%(p.name_hyphen, p.name, p.name)
1154 elif p.arg.signature == 's':
1155 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1156 elif p.arg.signature == 'o':
1157 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1158 elif p.arg.signature == 'g':
1159 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1160 elif p.arg.signature == 'ay':
1161 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1162 elif p.arg.signature == 'as':
1163 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1164 elif p.arg.signature == 'ao':
1165 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1166 elif p.arg.signature == 'aay':
1167 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1169 raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
1170 self.c.write(' %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
1176 self.c.write('typedef %sIface %sInterface;\n'%(i.camel_name, i.camel_name))
1177 self.c.write('G_DEFINE_INTERFACE (%s, %s, G_TYPE_OBJECT);\n'%(i.camel_name, i.name_lower))
1180 # ----------------------------------------------------------------------------------------------------
1182 def generate_property_accessors(self, i):
1183 for p in i.properties:
1185 if p.readable and p.writable:
1186 hint = 'Since this D-Bus property is both readable and writable, it is meaningful to use this function on both the client- and service-side.'
1188 hint = 'Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.'
1190 hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
1192 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1193 self.c.write(self.docbook_gen.expand(
1195 ' * %s_get_%s: (skip)\n'
1196 ' * @object: A #%s.\n'
1198 ' * Gets the value of the #%s:%s D-Bus property.\n'
1202 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1203 if p.arg.free_func != None:
1204 self.c.write(' * <warning>The returned value is only valid until the property changes so on the client-side it is only safe to use this function on the thread where @object was constructed. Use %s_dup_%s() if on another thread.</warning>\n'
1206 ' * Returns: (transfer none): The property value or %%NULL if the property is not set. Do not free the returned value, it belongs to @object.\n'
1207 %(i.name_lower, p.name_lower))
1209 self.c.write(' * Returns: The property value.\n')
1210 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1212 '%s_get_%s (%s *object)\n'
1213 '{\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
1214 self.c.write(' return %s%s_GET_IFACE (object)->get_%s (object);\n'%(i.ns_upper, i.name_upper, p.name_lower))
1217 if p.arg.free_func != None:
1219 self.c.write(self.docbook_gen.expand(
1221 ' * %s_dup_%s: (skip)\n'
1222 ' * @object: A #%s.\n'
1224 ' * Gets a copy of the #%s:%s D-Bus property.\n'
1228 ' * Returns: (transfer full): The property value or %%NULL if the property is not set. The returned value should be freed with %s().\n'
1229 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint, p.arg.free_func), False))
1230 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1232 '%s_dup_%s (%s *object)\n'
1234 ' %svalue;\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in_dup))
1235 self.c.write(' g_object_get (G_OBJECT (object), "%s", &value, NULL);\n'%(p.name_hyphen))
1236 self.c.write(' return value;\n')
1241 if p.readable and p.writable:
1242 hint = 'Since this D-Bus property is both readable and writable, it is meaningful to use this function on both the client- and service-side.'
1244 hint = 'Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.'
1246 hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
1248 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1249 self.c.write(self.docbook_gen.expand(
1251 ' * %s_set_%s: (skip)\n'
1252 ' * @object: A #%s.\n'
1253 ' * @value: The value to set.\n'
1255 ' * Sets the #%s:%s D-Bus property to @value.\n'
1258 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1259 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1260 self.c.write('void\n'
1261 '%s_set_%s (%s *object, %svalue)\n'
1262 '{\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
1263 self.c.write(' g_object_set (G_OBJECT (object), "%s", value, NULL);\n'%(p.name_hyphen))
1267 # ---------------------------------------------------------------------------------------------------
1269 def generate_signal_emitters(self, i):
1271 self.c.write(self.docbook_gen.expand(
1274 ' * @object: A #%s.\n'
1275 %(i.name_lower, s.name_lower, i.camel_name), False))
1277 self.c.write(' * @arg_%s: Argument to pass with the signal.\n'%(a.name))
1278 self.c.write(self.docbook_gen.expand(
1280 ' * Emits the #%s::%s D-Bus signal.\n'
1281 %(i.name, s.name), False))
1282 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 0)
1283 self.c.write('void\n'
1285 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
1287 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1290 ' g_signal_emit_by_name (object, "%s"'%(s.name_hyphen))
1292 self.c.write(', arg_%s'%a.name)
1293 self.c.write(');\n')
1297 # ---------------------------------------------------------------------------------------------------
1299 def generate_method_calls(self, i):
1302 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1305 self.c.write('/**\n'
1307 ' * @proxy: A #%sProxy.\n'
1308 %(i.name_lower, m.name_lower, i.camel_name))
1310 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1312 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1313 self.c.write(self.docbook_gen.expand(
1314 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1315 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %%NULL.\n'
1316 ' * @user_data: User data to pass to @callback.\n'
1318 ' * Asynchronously invokes the %s.%s() D-Bus method on @proxy.\n'
1319 ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
1320 ' * You can then call %s_call_%s_finish() to get the result of the operation.\n'
1322 ' * See %s_call_%s_sync() for the synchronous, blocking version of this method.\n'
1323 %(i.name, m.name, i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1324 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1325 self.c.write('void\n'
1327 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1329 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1331 self.c.write(',\n GUnixFDList *fd_list')
1333 ' GCancellable *cancellable,\n'
1334 ' GAsyncReadyCallback callback,\n'
1335 ' gpointer user_data)\n'
1338 self.c.write(' g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy),\n')
1340 self.c.write(' g_dbus_proxy_call (G_DBUS_PROXY (proxy),\n')
1341 self.c.write(' "%s",\n'
1342 ' g_variant_new ("('%(m.name))
1344 self.c.write('%s'%(a.format_in))
1347 self.c.write(',\n arg_%s'%(a.name))
1349 ' G_DBUS_CALL_FLAGS_NONE,\n'
1352 self.c.write(' fd_list,\n')
1353 self.c.write(' cancellable,\n'
1359 self.c.write('/**\n'
1360 ' * %s_call_%s_finish:\n'
1361 ' * @proxy: A #%sProxy.\n'
1362 %(i.name_lower, m.name_lower, i.camel_name))
1363 for a in m.out_args:
1364 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1366 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1367 self.c.write(self.docbook_gen.expand(
1368 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_call_%s().\n'
1369 ' * @error: Return location for error or %%NULL.\n'
1371 ' * Finishes an operation started with %s_call_%s().\n'
1373 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1374 %(i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1375 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1376 self.c.write('gboolean\n'
1377 '%s_call_%s_finish (\n'
1378 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1379 for a in m.out_args:
1380 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1382 self.c.write(',\n GUnixFDList **out_fd_list')
1384 ' GAsyncResult *res,\n'
1385 ' GError **error)\n'
1387 ' GVariant *_ret;\n')
1389 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error);\n')
1391 self.c.write(' _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);\n')
1392 self.c.write(' if (_ret == NULL)\n'
1394 self.c.write(' g_variant_get (_ret,\n'
1396 for a in m.out_args:
1397 self.c.write('%s'%(a.format_out))
1399 for a in m.out_args:
1400 self.c.write(',\n out_%s'%(a.name))
1402 ' g_variant_unref (_ret);\n')
1403 self.c.write('_out:\n'
1404 ' return _ret != NULL;\n'
1410 self.c.write('/**\n'
1411 ' * %s_call_%s_sync:\n'
1412 ' * @proxy: A #%sProxy.\n'
1413 %(i.name_lower, m.name_lower, i.camel_name))
1415 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1417 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1418 for a in m.out_args:
1419 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1421 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1422 self.c.write(self.docbook_gen.expand(
1423 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1424 ' * @error: Return location for error or %%NULL.\n'
1426 ' * Synchronously invokes the %s.%s() D-Bus method on @proxy. The calling thread is blocked until a reply is received.\n'
1428 ' * See %s_call_%s() for the asynchronous version of this method.\n'
1430 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1431 %(i.name, m.name, i.name_lower, m.name_lower), False))
1432 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1433 self.c.write('gboolean\n'
1434 '%s_call_%s_sync (\n'
1435 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1437 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1439 self.c.write(',\n GUnixFDList *fd_list')
1440 for a in m.out_args:
1441 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1443 self.c.write(',\n GUnixFDList **out_fd_list')
1445 ' GCancellable *cancellable,\n'
1446 ' GError **error)\n'
1448 ' GVariant *_ret;\n')
1450 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy),\n')
1452 self.c.write(' _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),\n')
1453 self.c.write(' "%s",\n'
1454 ' g_variant_new ("('%(m.name))
1456 self.c.write('%s'%(a.format_in))
1459 self.c.write(',\n arg_%s'%(a.name))
1461 ' G_DBUS_CALL_FLAGS_NONE,\n'
1464 self.c.write(' fd_list,\n'
1466 self.c.write(' cancellable,\n'
1468 ' if (_ret == NULL)\n'
1470 self.c.write(' g_variant_get (_ret,\n'
1472 for a in m.out_args:
1473 self.c.write('%s'%(a.format_out))
1475 for a in m.out_args:
1476 self.c.write(',\n out_%s'%(a.name))
1478 ' g_variant_unref (_ret);\n')
1479 self.c.write('_out:\n'
1480 ' return _ret != NULL;\n'
1484 # ---------------------------------------------------------------------------------------------------
1486 def generate_method_completers(self, i):
1489 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1491 self.c.write('/**\n'
1492 ' * %s_complete_%s:\n'
1493 ' * @object: A #%s.\n'
1494 ' * @invocation: (transfer full): A #GDBusMethodInvocation.\n'
1495 %(i.name_lower, m.name_lower, i.camel_name))
1497 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1498 for a in m.out_args:
1499 self.c.write(' * @%s: Parameter to return.\n'%(a.name))
1500 self.c.write(self.docbook_gen.expand(
1502 ' * Helper function used in service implementations to finish handling invocations of the %s.%s() D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar.\n'
1504 ' * This method will free @invocation, you cannot use it afterwards.\n'
1505 %(i.name, m.name), False))
1506 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1507 self.c.write('void\n'
1508 '%s_complete_%s (\n'
1510 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
1512 self.c.write(',\n GUnixFDList *fd_list')
1513 for a in m.out_args:
1514 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1519 self.c.write(' g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,\n'
1520 ' g_variant_new ("(')
1522 self.c.write(' g_dbus_method_invocation_return_value (invocation,\n'
1523 ' g_variant_new ("(')
1524 for a in m.out_args:
1525 self.c.write('%s'%(a.format_in))
1527 for a in m.out_args:
1528 self.c.write(',\n %s'%(a.name))
1530 self.c.write('),\n fd_list);\n')
1532 self.c.write('));\n')
1536 # ---------------------------------------------------------------------------------------------------
1538 def generate_proxy(self, i):
1540 self.c.write('/* ------------------------------------------------------------------------ */\n'
1543 self.c.write(self.docbook_gen.expand(
1547 ' * The #%sProxy structure contains only private data and should only be accessed using the provided API.\n'
1548 %(i.camel_name, i.camel_name), False))
1549 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1552 self.c.write(self.docbook_gen.expand(
1554 ' * %sProxyClass:\n'
1555 ' * @parent_class: The parent class.\n'
1557 ' * Class structure for #%sProxy.\n'
1558 %(i.camel_name, i.camel_name), False))
1559 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1562 self.c.write('struct _%sProxyPrivate\n'
1568 self.c.write('static void %s_proxy_iface_init (%sIface *iface);\n'
1569 '\n'%(i.name_lower, i.camel_name))
1570 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1571 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1574 self.c.write('static void\n'
1575 '%s_proxy_finalize (GObject *object)\n'
1576 '{\n'%(i.name_lower))
1577 self.c.write(' %sProxy *proxy = %s%s_PROXY (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
1578 self.c.write(' g_datalist_clear (&proxy->priv->qdata);\n')
1579 self.c.write(' G_OBJECT_CLASS (%s_proxy_parent_class)->finalize (object);\n'
1581 '\n'%(i.name_lower))
1583 # property accessors
1585 # Note that we are guaranteed that prop_id starts at 1 and is
1586 # laid out in the same order as introspection data pointers
1588 self.c.write('static void\n'
1589 '%s_proxy_get_property (GObject *object,\n'
1592 ' GParamSpec *pspec)\n'
1593 '{\n'%(i.name_lower))
1594 if len(i.properties) > 0:
1595 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1596 ' GVariant *variant;\n'
1597 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1598 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1599 ' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
1600 ' if (info->use_gvariant)\n'
1602 ' g_value_set_variant (value, variant);\n'
1606 # could be that we don't have the value in cache - in that case, we do
1607 # nothing and the user gets the default value for the GType
1608 ' if (variant != NULL)\n'
1609 ' g_dbus_gvariant_to_gvalue (variant, value);\n'
1611 ' if (variant != NULL)\n'
1612 ' g_variant_unref (variant);\n'
1613 %(len(i.properties), i.name_lower))
1616 if len(i.properties) > 0:
1617 self.c.write('static void\n'
1618 '%s_proxy_set_property_cb (GDBusProxy *proxy,\n'
1619 ' GAsyncResult *res,\n'
1620 ' gpointer user_data)\n'
1621 '{\n'%(i.name_lower))
1622 self.c.write(' const _ExtendedGDBusPropertyInfo *info = user_data;\n'
1625 ' if (!g_dbus_proxy_call_finish (proxy, res, &error))\n'
1627 ' g_warning ("Error setting property `%%s\' on interface %s: %%s (%%s, %%d)",\n'
1628 ' info->parent_struct.name, \n'
1629 ' error->message, g_quark_to_string (error->domain), error->code);\n'
1630 ' g_error_free (error);\n'
1635 self.c.write('static void\n'
1636 '%s_proxy_set_property (GObject *object,\n'
1638 ' const GValue *value,\n'
1639 ' GParamSpec *pspec)\n'
1640 '{\n'%(i.name_lower))
1641 if len(i.properties) > 0:
1642 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1643 ' GVariant *variant;\n'
1644 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1645 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1646 ' variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
1647 ' g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
1648 ' "org.freedesktop.DBus.Properties.Set",\n'
1649 ' g_variant_new ("(ssv)", "%s", info->parent_struct.name, variant),\n'
1650 ' G_DBUS_CALL_FLAGS_NONE,\n'
1652 ' NULL, (GAsyncReadyCallback) %s_proxy_set_property_cb, (gpointer) info);\n'
1653 ' g_variant_unref (variant);\n'
1654 %(len(i.properties), i.name_lower, i.name, i.name_lower))
1659 self.c.write('static void\n'
1660 '%s_proxy_g_signal (GDBusProxy *proxy,\n'
1661 ' const gchar *sender_name,\n'
1662 ' const gchar *signal_name,\n'
1663 ' GVariant *parameters)\n'
1664 '{\n'%(i.name_lower))
1665 self.c.write(' _ExtendedGDBusSignalInfo *info;\n'
1666 ' GVariantIter iter;\n'
1667 ' GVariant *child;\n'
1668 ' GValue *paramv;\n'
1669 ' guint num_params;\n'
1671 ' guint signal_id;\n');
1672 # Note: info could be NULL if we are talking to a newer version of the interface
1673 self.c.write(' info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_%s_interface_info, signal_name);\n'
1674 ' if (info == NULL)\n'
1677 self.c.write (' num_params = g_variant_n_children (parameters);\n'
1678 ' paramv = g_new0 (GValue, num_params + 1);\n'
1679 ' g_value_init (¶mv[0], %sTYPE_%s);\n'
1680 ' g_value_set_object (¶mv[0], proxy);\n'
1681 %(i.ns_upper, i.name_upper))
1682 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
1684 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
1686 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1];\n'
1687 ' if (arg_info->use_gvariant)\n'
1689 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
1690 ' g_value_set_variant (¶mv[n], child);\n'
1694 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
1695 ' g_variant_unref (child);\n'
1698 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
1699 %(i.ns_upper, i.name_upper))
1700 self.c.write(' g_signal_emitv (paramv, signal_id, 0, NULL);\n')
1701 self.c.write(' for (n = 0; n < num_params + 1; n++)\n'
1702 ' g_value_unset (¶mv[n]);\n'
1703 ' g_free (paramv);\n')
1708 self.c.write('static void\n'
1709 '%s_proxy_g_properties_changed (GDBusProxy *_proxy,\n'
1710 ' GVariant *changed_properties,\n'
1711 ' const gchar *const *invalidated_properties)\n'
1712 '{\n'%(i.name_lower))
1713 # Note: info could be NULL if we are talking to a newer version of the interface
1714 self.c.write(' %sProxy *proxy = %s%s_PROXY (_proxy);\n'
1716 ' const gchar *key;\n'
1717 ' GVariantIter *iter;\n'
1718 ' _ExtendedGDBusPropertyInfo *info;\n'
1719 ' g_variant_get (changed_properties, "a{sv}", &iter);\n'
1720 ' while (g_variant_iter_next (iter, "{&sv}", &key, NULL))\n'
1722 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, key);\n'
1723 ' g_datalist_remove_data (&proxy->priv->qdata, key);\n'
1724 ' if (info != NULL)\n'
1725 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1727 ' g_variant_iter_free (iter);\n'
1728 ' for (n = 0; invalidated_properties[n] != NULL; n++)\n'
1730 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, invalidated_properties[n]);\n'
1731 ' g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]);\n'
1732 ' if (info != NULL)\n'
1733 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1737 %(i.camel_name, i.ns_upper, i.name_upper,
1738 i.name_lower, i.name_lower))
1741 for p in i.properties:
1743 if p.arg.free_func != None:
1745 self.c.write('static %s\n'
1746 '%s_proxy_get_%s (%s *object)\n'
1748 ' %sProxy *proxy = %s%s_PROXY (object);\n'
1749 ' GVariant *variant;\n'
1750 ' %svalue = %s;\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name,
1751 i.camel_name, i.ns_upper, i.name_upper,
1752 p.arg.ctype_in, nul_value))
1753 # For some property types, we have to free the returned
1754 # value (or part of it, e.g. the container) because of how
1755 # GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
1758 free_container = False;
1759 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':
1760 free_container = True;
1761 # If already using an old value for strv, objpathv, bytestring_array (see below),
1762 # then just return that... that way the result from multiple consecutive calls
1763 # to the getter are valid as long as they're freed
1766 self.c.write(' value = g_datalist_get_data (&proxy->priv->qdata, \"%s\");\n'
1767 ' if (value != NULL)\n'
1770 self.c.write(' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \"%s\");\n'%(p.name))
1771 if p.arg.gtype == 'G_TYPE_VARIANT':
1772 self.c.write(' value = variant;\n')
1773 self.c.write(' if (variant != NULL)\n')
1774 self.c.write(' g_variant_unref (variant);\n')
1776 self.c.write(' if (variant != NULL)\n'
1779 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':
1780 extra_len = ', NULL'
1781 self.c.write(' value = %s (variant%s);\n'%(p.arg.gvariant_get, extra_len))
1783 self.c.write(' g_datalist_set_data_full (&proxy->priv->qdata, \"%s\", (gpointer) value, g_free);\n'
1785 self.c.write(' g_variant_unref (variant);\n')
1786 self.c.write(' }\n')
1787 self.c.write(' return value;\n')
1792 self.c.write('static void\n'
1793 '%s_proxy_init (%sProxy *proxy)\n'
1795 ' proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %sTYPE_%s_PROXY, %sProxyPrivate);\n'
1796 ' g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
1799 %(i.name_lower, i.camel_name,
1800 i.ns_upper, i.name_upper, i.camel_name,
1802 self.c.write('static void\n'
1803 '%s_proxy_class_init (%sProxyClass *klass)\n'
1805 ' GObjectClass *gobject_class;\n'
1806 ' GDBusProxyClass *proxy_class;\n'
1808 ' g_type_class_add_private (klass, sizeof (%sProxyPrivate));\n'
1810 ' gobject_class = G_OBJECT_CLASS (klass);\n'
1811 ' gobject_class->finalize = %s_proxy_finalize;\n'
1812 ' gobject_class->get_property = %s_proxy_get_property;\n'
1813 ' gobject_class->set_property = %s_proxy_set_property;\n'
1815 ' proxy_class = G_DBUS_PROXY_CLASS (klass);\n'
1816 ' proxy_class->g_signal = %s_proxy_g_signal;\n'
1817 ' proxy_class->g_properties_changed = %s_proxy_g_properties_changed;\n'
1818 '\n'%(i.name_lower, i.camel_name,
1820 i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
1821 if len(i.properties) > 0:
1823 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
1827 self.c.write('static void\n'
1828 '%s_proxy_iface_init (%sIface *iface)\n'
1829 '{\n'%(i.name_lower, i.camel_name))
1830 for p in i.properties:
1831 self.c.write(' iface->get_%s = %s_proxy_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
1836 self.c.write(self.docbook_gen.expand(
1838 ' * %s_proxy_new:\n'
1839 ' * @connection: A #GDBusConnection.\n'
1840 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1841 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1842 ' * @object_path: An object path.\n'
1843 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1844 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1845 ' * @user_data: User data to pass to @callback.\n'
1847 ' * Asynchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new() for more details.\n'
1849 ' * 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'
1850 ' * You can then call %s_proxy_new_finish() to get the result of the operation.\n'
1852 ' * See %s_proxy_new_sync() for the synchronous, blocking version of this constructor.\n'
1853 %(i.name_lower, i.name, i.name_lower, i.name_lower), False))
1854 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1855 self.c.write('void\n'
1857 ' GDBusConnection *connection,\n'
1858 ' GDBusProxyFlags flags,\n'
1859 ' const gchar *name,\n'
1860 ' const gchar *object_path,\n'
1861 ' GCancellable *cancellable,\n'
1862 ' GAsyncReadyCallback callback,\n'
1863 ' gpointer user_data)\n'
1865 ' 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'
1868 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1869 self.c.write('/**\n'
1870 ' * %s_proxy_new_finish:\n'
1871 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new().\n'
1872 ' * @error: Return location for error or %%NULL\n'
1874 ' * Finishes an operation started with %s_proxy_new().\n'
1876 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1877 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1878 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1879 self.c.write('%s *\n'
1880 '%s_proxy_new_finish (\n'
1881 ' GAsyncResult *res,\n'
1882 ' GError **error)\n'
1885 ' GObject *source_object;\n'
1886 ' source_object = g_async_result_get_source_object (res);\n'
1887 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1888 ' g_object_unref (source_object);\n'
1889 ' if (ret != NULL)\n'
1890 ' return %s%s (ret);\n'
1895 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1896 self.c.write(self.docbook_gen.expand(
1898 ' * %s_proxy_new_sync:\n'
1899 ' * @connection: A #GDBusConnection.\n'
1900 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1901 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1902 ' * @object_path: An object path.\n'
1903 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1904 ' * @error: Return location for error or %%NULL\n'
1906 ' * Synchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new_sync() for more details.\n'
1908 ' * The calling thread is blocked until a reply is received.\n'
1910 ' * See %s_proxy_new() for the asynchronous version of this constructor.\n'
1912 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1913 %(i.name_lower, i.name, i.name_lower, i.camel_name), False))
1914 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1915 self.c.write('%s *\n'
1916 '%s_proxy_new_sync (\n'
1917 ' GDBusConnection *connection,\n'
1918 ' GDBusProxyFlags flags,\n'
1919 ' const gchar *name,\n'
1920 ' const gchar *object_path,\n'
1921 ' GCancellable *cancellable,\n'
1922 ' GError **error)\n'
1924 ' GInitable *ret;\n'
1925 ' 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'
1926 ' if (ret != NULL)\n'
1927 ' return %s%s (ret);\n'
1932 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
1934 self.c.write(self.docbook_gen.expand(
1936 ' * %s_proxy_new_for_bus:\n'
1937 ' * @bus_type: A #GBusType.\n'
1938 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1939 ' * @name: A bus name (well-known or unique).\n'
1940 ' * @object_path: An object path.\n'
1941 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1942 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1943 ' * @user_data: User data to pass to @callback.\n'
1945 ' * Like %s_proxy_new() but takes a #GBusType instead of a #GDBusConnection.\n'
1947 ' * 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'
1948 ' * You can then call %s_proxy_new_for_bus_finish() to get the result of the operation.\n'
1950 ' * See %s_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
1951 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower), False))
1952 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1953 self.c.write('void\n'
1954 '%s_proxy_new_for_bus (\n'
1955 ' GBusType bus_type,\n'
1956 ' GDBusProxyFlags flags,\n'
1957 ' const gchar *name,\n'
1958 ' const gchar *object_path,\n'
1959 ' GCancellable *cancellable,\n'
1960 ' GAsyncReadyCallback callback,\n'
1961 ' gpointer user_data)\n'
1963 ' 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'
1966 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1967 self.c.write('/**\n'
1968 ' * %s_proxy_new_for_bus_finish:\n'
1969 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new_for_bus().\n'
1970 ' * @error: Return location for error or %%NULL\n'
1972 ' * Finishes an operation started with %s_proxy_new_for_bus().\n'
1974 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1975 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1976 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1977 self.c.write('%s *\n'
1978 '%s_proxy_new_for_bus_finish (\n'
1979 ' GAsyncResult *res,\n'
1980 ' GError **error)\n'
1983 ' GObject *source_object;\n'
1984 ' source_object = g_async_result_get_source_object (res);\n'
1985 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1986 ' g_object_unref (source_object);\n'
1987 ' if (ret != NULL)\n'
1988 ' return %s%s (ret);\n'
1993 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1994 self.c.write(self.docbook_gen.expand(
1996 ' * %s_proxy_new_for_bus_sync:\n'
1997 ' * @bus_type: A #GBusType.\n'
1998 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1999 ' * @name: A bus name (well-known or unique).\n'
2000 ' * @object_path: An object path.\n'
2001 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
2002 ' * @error: Return location for error or %%NULL\n'
2004 ' * Like %s_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
2006 ' * The calling thread is blocked until a reply is received.\n'
2008 ' * See %s_proxy_new_for_bus() for the asynchronous version of this constructor.\n'
2010 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2011 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name), False))
2012 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2013 self.c.write('%s *\n'
2014 '%s_proxy_new_for_bus_sync (\n'
2015 ' GBusType bus_type,\n'
2016 ' GDBusProxyFlags flags,\n'
2017 ' const gchar *name,\n'
2018 ' const gchar *object_path,\n'
2019 ' GCancellable *cancellable,\n'
2020 ' GError **error)\n'
2022 ' GInitable *ret;\n'
2023 ' 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'
2024 ' if (ret != NULL)\n'
2025 ' return %s%s (ret);\n'
2030 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
2033 # ---------------------------------------------------------------------------------------------------
2035 def generate_skeleton(self, i):
2037 self.c.write('/* ------------------------------------------------------------------------ */\n'
2040 self.c.write(self.docbook_gen.expand(
2044 ' * The #%sSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2045 %(i.camel_name, i.camel_name), False))
2046 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2049 self.c.write(self.docbook_gen.expand(
2051 ' * %sSkeletonClass:\n'
2052 ' * @parent_class: The parent class.\n'
2054 ' * Class structure for #%sSkeleton.\n'
2055 %(i.camel_name, i.camel_name), False))
2056 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2059 self.c.write('struct _%sSkeletonPrivate\n'
2061 ' GValueArray *properties;\n'
2062 ' GList *changed_properties;\n'
2063 ' GSource *changed_properties_idle_source;\n'
2064 ' GMainContext *context;\n'
2069 self.c.write('static void\n'
2070 '_%s_skeleton_handle_method_call (\n'
2071 ' GDBusConnection *connection,\n'
2072 ' const gchar *sender,\n'
2073 ' const gchar *object_path,\n'
2074 ' const gchar *interface_name,\n'
2075 ' const gchar *method_name,\n'
2076 ' GVariant *parameters,\n'
2077 ' GDBusMethodInvocation *invocation,\n'
2078 ' gpointer user_data)\n'
2080 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2081 ' _ExtendedGDBusMethodInfo *info;\n'
2082 ' GVariantIter iter;\n'
2083 ' GVariant *child;\n'
2084 ' GValue *paramv;\n'
2085 ' guint num_params;\n'
2086 ' guint num_extra;\n'
2088 ' guint signal_id;\n'
2089 ' GValue return_value = {0};\n'
2090 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2091 self.c.write(' info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n'
2092 ' g_assert (info != NULL);\n'
2094 self.c.write (' num_params = g_variant_n_children (parameters);\n'
2095 ' num_extra = info->pass_fdlist ? 3 : 2;'
2096 ' paramv = g_new0 (GValue, num_params + num_extra);\n'
2098 ' g_value_init (¶mv[n], %sTYPE_%s);\n'
2099 ' g_value_set_object (¶mv[n++], skeleton);\n'
2100 ' g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION);\n'
2101 ' g_value_set_object (¶mv[n++], invocation);\n'
2102 ' if (info->pass_fdlist)\n'
2104 '#ifdef G_OS_UNIX\n'
2105 ' g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST);\n'
2106 ' g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)));\n'
2108 ' g_assert_not_reached ();\n'
2111 %(i.ns_upper, i.name_upper))
2112 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
2113 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
2115 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra];\n'
2116 ' if (arg_info->use_gvariant)\n'
2118 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
2119 ' g_value_set_variant (¶mv[n], child);\n'
2123 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
2124 ' g_variant_unref (child);\n'
2127 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
2128 %(i.ns_upper, i.name_upper))
2129 self.c.write(' g_value_init (&return_value, G_TYPE_BOOLEAN);\n'
2130 ' g_signal_emitv (paramv, signal_id, 0, &return_value);\n'
2131 ' if (!g_value_get_boolean (&return_value))\n'
2132 ' 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'
2133 ' g_value_unset (&return_value);\n'
2135 self.c.write(' for (n = 0; n < num_params + num_extra; n++)\n'
2136 ' g_value_unset (¶mv[n]);\n'
2137 ' g_free (paramv);\n')
2141 self.c.write('static GVariant *\n'
2142 '_%s_skeleton_handle_get_property (\n'
2143 ' GDBusConnection *connection,\n'
2144 ' const gchar *sender,\n'
2145 ' const gchar *object_path,\n'
2146 ' const gchar *interface_name,\n'
2147 ' const gchar *property_name,\n'
2148 ' GError **error,\n'
2149 ' gpointer user_data)\n'
2151 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2152 ' GValue value = {0};\n'
2153 ' GParamSpec *pspec;\n'
2154 ' _ExtendedGDBusPropertyInfo *info;\n'
2156 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2157 self.c.write(' ret = NULL;\n'
2158 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, property_name);\n'
2159 ' g_assert (info != NULL);\n'
2160 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2161 ' if (pspec == NULL)\n'
2163 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2167 ' g_value_init (&value, pspec->value_type);\n'
2168 ' g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2169 ' ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
2170 ' g_value_unset (&value);\n'
2177 self.c.write('static gboolean\n'
2178 '_%s_skeleton_handle_set_property (\n'
2179 ' GDBusConnection *connection,\n'
2180 ' const gchar *sender,\n'
2181 ' const gchar *object_path,\n'
2182 ' const gchar *interface_name,\n'
2183 ' const gchar *property_name,\n'
2184 ' GVariant *variant,\n'
2185 ' GError **error,\n'
2186 ' gpointer user_data)\n'
2188 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2189 ' GValue value = {0};\n'
2190 ' GParamSpec *pspec;\n'
2191 ' _ExtendedGDBusPropertyInfo *info;\n'
2193 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2194 self.c.write(' ret = FALSE;\n'
2195 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info, property_name);\n'
2196 ' g_assert (info != NULL);\n'
2197 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2198 ' if (pspec == NULL)\n'
2200 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2204 ' if (info->use_gvariant)\n'
2205 ' g_value_set_variant (&value, variant);\n'
2207 ' g_dbus_gvariant_to_gvalue (variant, &value);\n'
2208 ' g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2209 ' g_value_unset (&value);\n'
2218 self.c.write('static const GDBusInterfaceVTable _%s_skeleton_vtable =\n'
2220 ' _%s_skeleton_handle_method_call,\n'
2221 ' _%s_skeleton_handle_get_property,\n'
2222 ' _%s_skeleton_handle_set_property\n'
2224 '\n'%(i.name_lower, i.name_lower, i.name_lower, i.name_lower))
2226 self.c.write('static GDBusInterfaceInfo *\n'
2227 '%s_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton)\n'
2229 ' return %s_interface_info ();\n'
2230 %(i.name_lower, i.name_lower))
2234 self.c.write('static GDBusInterfaceVTable *\n'
2235 '%s_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton)\n'
2237 ' return (GDBusInterfaceVTable *) &_%s_skeleton_vtable;\n'
2238 %(i.name_lower, i.name_lower))
2242 self.c.write('static GVariant *\n'
2243 '%s_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton)\n'
2245 ' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2246 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2248 ' GVariantBuilder builder;\n'
2250 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2251 ' if (_%s_interface_info.parent_struct.properties == NULL)\n'
2253 ' for (n = 0; _%s_interface_info.parent_struct.properties[n] != NULL; n++)\n'
2255 ' GDBusPropertyInfo *info = _%s_interface_info.parent_struct.properties[n];\n'
2256 ' if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)\n'
2258 ' GVariant *value;\n'
2259 ' 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'
2260 ' if (value != NULL)\n'
2262 ' g_variant_take_ref (value);\n'
2263 ' g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
2264 ' g_variant_unref (value);\n'
2269 ' return g_variant_builder_end (&builder);\n'
2272 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name))
2274 if len(i.properties) > 0:
2275 self.c.write('static gboolean _%s_emit_changed (gpointer user_data);\n'
2279 self.c.write('static void\n'
2280 '%s_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton)\n'
2283 if len(i.properties) > 0:
2284 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2285 ' gboolean emit_changed = FALSE;\n'
2287 ' g_mutex_lock (&skeleton->priv->lock);\n'
2288 ' if (skeleton->priv->changed_properties_idle_source != NULL)\n'
2290 ' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
2291 ' skeleton->priv->changed_properties_idle_source = NULL;\n'
2292 ' emit_changed = TRUE;\n'
2294 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2296 ' if (emit_changed)\n'
2297 ' _%s_emit_changed (skeleton);\n'
2298 %(i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2303 self.c.write('static void\n'
2304 '_%s_on_signal_%s (\n'
2305 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
2307 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
2310 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2311 ' GDBusConnection *connection = g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2312 %(i.camel_name, i.ns_upper, i.name_upper))
2313 self.c.write(' if (connection == NULL)\n'
2315 ' g_dbus_connection_emit_signal (connection,\n'
2316 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", "%s",\n'
2317 ' g_variant_new ("('
2320 self.c.write('%s'%(a.format_in))
2323 self.c.write(',\n arg_%s'%(a.name))
2324 self.c.write('), NULL);\n')
2328 self.c.write('static void %s_skeleton_iface_init (%sIface *iface);\n'
2329 %(i.name_lower, i.camel_name))
2331 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2332 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2335 self.c.write('static void\n'
2336 '%s_skeleton_finalize (GObject *object)\n'
2337 '{\n'%(i.name_lower))
2338 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2339 if len(i.properties) > 0:
2340 self.c.write(' g_value_array_free (skeleton->priv->properties);\n')
2341 self.c.write(' g_list_foreach (skeleton->priv->changed_properties, (GFunc) _changed_property_free, NULL);\n')
2342 self.c.write(' g_list_free (skeleton->priv->changed_properties);\n')
2343 self.c.write(' if (skeleton->priv->changed_properties_idle_source != NULL)\n')
2344 self.c.write(' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
2345 self.c.write(' if (skeleton->priv->context != NULL)\n')
2346 self.c.write(' g_main_context_unref (skeleton->priv->context);\n')
2347 self.c.write(' g_mutex_clear (&skeleton->priv->lock);\n')
2348 self.c.write(' G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
2350 '\n'%(i.name_lower))
2352 # property accessors (TODO: generate PropertiesChanged signals in setter)
2353 if len(i.properties) > 0:
2354 self.c.write('static void\n'
2355 '%s_skeleton_get_property (GObject *object,\n'
2358 ' GParamSpec *pspec)\n'
2359 '{\n'%(i.name_lower))
2360 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2361 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2362 ' g_mutex_lock (&skeleton->priv->lock);\n'
2363 ' g_value_copy (&skeleton->priv->properties->values[prop_id - 1], value);\n'
2364 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2365 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
2369 # if property is already scheduled then re-use entry.. though it could be
2372 # foo_set_prop_bar (object, "");
2373 # foo_set_prop_bar (object, "blah");
2375 # say, every update... In this case, where nothing happens, we obviously
2376 # don't want a PropertiesChanged() event. We can easily check for this
2377 # by comparing against the _original value_ recorded before the first
2378 # change event. If the latest value is not different from the original
2379 # one, we can simply ignore the ChangedProperty
2381 self.c.write('static gboolean\n'
2382 '_%s_emit_changed (gpointer user_data)\n'
2384 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2385 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2386 self.c.write(' GList *l;\n'
2387 ' GVariantBuilder builder;\n'
2388 ' GVariantBuilder invalidated_builder;\n'
2389 ' guint num_changes;\n'
2391 ' g_mutex_lock (&skeleton->priv->lock);\n'
2392 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2393 ' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
2394 ' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
2396 ' ChangedProperty *cp = l->data;\n'
2397 ' GVariant *variant;\n'
2398 ' const GValue *cur_value;\n'
2400 ' cur_value = &skeleton->priv->properties->values[cp->prop_id - 1];\n'
2401 ' if (!_g_value_equal (cur_value, &cp->orig_value))\n'
2403 ' variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature));\n'
2404 ' g_variant_builder_add (&builder, "{sv}", cp->info->parent_struct.name, variant);\n'
2405 ' g_variant_unref (variant);\n'
2409 ' if (num_changes > 0)\n'
2411 ' g_dbus_connection_emit_signal (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2412 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2413 ' "org.freedesktop.DBus.Properties",\n'
2414 ' "PropertiesChanged",\n'
2415 ' g_variant_new ("(sa{sv}as)",\n'
2417 ' &builder, &invalidated_builder),\n'
2422 ' g_variant_builder_clear (&builder);\n'
2423 ' g_variant_builder_clear (&invalidated_builder);\n'
2426 self.c.write(' g_list_foreach (skeleton->priv->changed_properties, (GFunc) _changed_property_free, NULL);\n')
2427 self.c.write(' g_list_free (skeleton->priv->changed_properties);\n')
2428 self.c.write(' skeleton->priv->changed_properties = NULL;\n')
2429 self.c.write(' skeleton->priv->changed_properties_idle_source = NULL;\n')
2430 self.c.write(' g_mutex_unlock (&skeleton->priv->lock);\n')
2431 self.c.write(' return FALSE;\n'
2434 # holding lock while being called
2435 self.c.write('static void\n'
2436 '_%s_schedule_emit_changed (%sSkeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value)\n'
2438 ' ChangedProperty *cp;\n'
2441 ' for (l = skeleton->priv->changed_properties; l != NULL; l = l->next)\n'
2443 ' ChangedProperty *i_cp = l->data;\n'
2444 ' if (i_cp->info == info)\n'
2450 %(i.name_lower, i.camel_name))
2451 self.c.write(' if (cp == NULL)\n'
2453 ' cp = g_new0 (ChangedProperty, 1);\n'
2454 ' cp->prop_id = prop_id;\n'
2455 ' cp->info = info;\n'
2456 ' skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp);\n'
2457 ' g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value));\n'
2458 ' g_value_copy (orig_value, &cp->orig_value);\n'
2464 # Postpone setting up the refresh source until the ::notify signal is emitted as
2465 # this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
2466 # This is useful when updating several properties from another thread than
2467 # where the idle will be emitted from
2468 self.c.write('static void\n'
2469 '%s_skeleton_notify (GObject *object,\n'
2470 ' GParamSpec *pspec)\n'
2472 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2473 ' g_mutex_lock (&skeleton->priv->lock);\n'
2474 ' if (skeleton->priv->changed_properties != NULL &&\n'
2475 ' skeleton->priv->changed_properties_idle_source == NULL)\n'
2477 ' skeleton->priv->changed_properties_idle_source = g_idle_source_new ();\n'
2478 ' g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);\n'
2479 ' g_source_set_callback (skeleton->priv->changed_properties_idle_source, _%s_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);\n'
2480 ' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
2481 ' g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
2483 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2486 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2488 self.c.write('static void\n'
2489 '%s_skeleton_set_property (GObject *object,\n'
2491 ' const GValue *value,\n'
2492 ' GParamSpec *pspec)\n'
2493 '{\n'%(i.name_lower))
2494 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2495 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2496 ' g_mutex_lock (&skeleton->priv->lock);\n'
2497 ' g_object_freeze_notify (object);\n'
2498 ' if (!_g_value_equal (value, &skeleton->priv->properties->values[prop_id - 1]))\n'
2500 ' if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
2501 ' _%s_schedule_emit_changed (skeleton, _%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties->values[prop_id - 1]);\n'
2502 ' g_value_copy (value, &skeleton->priv->properties->values[prop_id - 1]);\n'
2503 ' g_object_notify_by_pspec (object, pspec);\n'
2505 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2506 ' g_object_thaw_notify (object);\n'
2507 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
2511 self.c.write('static void\n'
2512 '%s_skeleton_init (%sSkeleton *skeleton)\n'
2514 ' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
2515 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.camel_name))
2516 self.c.write(' g_mutex_init (&skeleton->priv->lock);\n')
2517 self.c.write(' skeleton->priv->context = g_main_context_get_thread_default ();\n')
2518 self.c.write(' if (skeleton->priv->context != NULL)\n')
2519 self.c.write(' g_main_context_ref (skeleton->priv->context);\n')
2520 if len(i.properties) > 0:
2521 self.c.write(' skeleton->priv->properties = g_value_array_new (%d);\n'%(len(i.properties)))
2523 for p in i.properties:
2524 self.c.write(' g_value_array_append (skeleton->priv->properties, NULL);\n')
2525 self.c.write(' g_value_init (&skeleton->priv->properties->values[%d], %s);\n'%(n, p.arg.gtype))
2532 for p in i.properties:
2533 self.c.write('static %s\n'
2534 '%s_skeleton_get_%s (%s *object)\n'
2536 %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
2537 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2538 self.c.write(' %svalue;\n'
2539 ' g_mutex_lock (&skeleton->priv->lock);\n'
2540 ' value = %s (&(skeleton->priv->properties->values[%d]));\n'
2541 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2542 %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
2543 self.c.write(' return value;\n')
2548 self.c.write('static void\n'
2549 '%s_skeleton_class_init (%sSkeletonClass *klass)\n'
2551 ' GObjectClass *gobject_class;\n'
2552 ' GDBusInterfaceSkeletonClass *skeleton_class;\n'
2554 ' g_type_class_add_private (klass, sizeof (%sSkeletonPrivate));\n'
2556 ' gobject_class = G_OBJECT_CLASS (klass);\n'
2557 ' gobject_class->finalize = %s_skeleton_finalize;\n'
2558 %(i.name_lower, i.camel_name, i.camel_name, i.name_lower))
2559 if len(i.properties) > 0:
2560 self.c.write(' gobject_class->get_property = %s_skeleton_get_property;\n'
2561 ' gobject_class->set_property = %s_skeleton_set_property;\n'
2562 ' gobject_class->notify = %s_skeleton_notify;\n'
2563 '\n'%(i.name_lower, i.name_lower, i.name_lower))
2565 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
2567 ' skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);\n');
2568 self.c.write(' skeleton_class->get_info = %s_skeleton_dbus_interface_get_info;\n'%(i.name_lower))
2569 self.c.write(' skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
2570 self.c.write(' skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
2571 self.c.write(' skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
2575 self.c.write('static void\n'
2576 '%s_skeleton_iface_init (%sIface *iface)\n'
2578 %(i.name_lower, i.camel_name))
2580 self.c.write(' iface->%s = _%s_on_signal_%s;\n'
2581 %(s.name_lower, i.name_lower, s.name_lower))
2582 for p in i.properties:
2583 self.c.write(' iface->get_%s = %s_skeleton_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
2588 self.c.write(self.docbook_gen.expand(
2590 ' * %s_skeleton_new:\n'
2592 ' * Creates a skeleton object for the D-Bus interface #%s.\n'
2594 ' * Returns: (transfer full) (type %sSkeleton): The skeleton object.\n'
2595 %(i.name_lower, i.name, i.camel_name), False))
2596 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2597 self.c.write('%s *\n'
2598 '%s_skeleton_new (void)\n'
2600 ' return %s%s (g_object_new (%sTYPE_%s_SKELETON, NULL));\n'
2602 '\n'%(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
2604 # ---------------------------------------------------------------------------------------------------
2606 def generate_object(self):
2607 self.c.write('/* ------------------------------------------------------------------------\n'
2608 ' * Code for Object, ObjectProxy and ObjectSkeleton\n'
2609 ' * ------------------------------------------------------------------------\n'
2613 self.c.write(self.docbook_gen.expand(
2615 ' * SECTION:%sObject\n'
2616 ' * @title: %sObject\n'
2617 ' * @short_description: Specialized GDBusObject types\n'
2619 ' * 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'
2621 %(self.namespace, self.namespace, self.namespace, self.namespace, self.namespace), False))
2624 self.c.write(self.docbook_gen.expand(
2628 ' * The #%sObject type is a specialized container of interfaces.\n'
2630 %(self.namespace, self.namespace), False))
2633 self.c.write(self.docbook_gen.expand(
2635 ' * %sObjectIface:\n'
2636 ' * @parent_iface: The parent interface.\n'
2638 ' * Virtual table for the #%sObject interface.\n'
2640 %(self.namespace, self.namespace), False))
2643 self.c.write('static void\n'
2644 '%sobject_default_init (%sObjectIface *iface)\n'
2646 %(self.ns_lower, self.namespace));
2647 for i in self.ifaces:
2648 self.c.write(self.docbook_gen.expand(
2652 ' * The #%s instance corresponding to the D-Bus interface #%s, if any.\n'
2654 ' * Connect to the #GObject::notify signal to get informed of property changes.\n'
2655 %(self.namespace, i.name_hyphen, i.camel_name, i.name), False))
2656 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 2)
2657 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'
2659 %(i.name_hyphen, i.name_hyphen, i.name_hyphen, self.ns_upper, i.name_upper))
2663 self.c.write('typedef %sObjectIface %sObjectInterface;\n'%(self.namespace, self.namespace))
2664 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))
2667 for i in self.ifaces:
2668 self.c.write(self.docbook_gen.expand(
2670 ' * %sobject_get_%s:\n'
2671 ' * @object: A #%sObject.\n'
2673 ' * Gets the #%s instance for the D-Bus interface #%s on @object, if any.\n'
2675 ' * Returns: (transfer full): A #%s that must be freed with g_object_unref() or %%NULL if @object does not implement the interface.\n'
2676 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.name, i.camel_name), False))
2677 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2678 self.c.write ('%s *%sobject_get_%s (%sObject *object)\n'
2679 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2681 ' GDBusInterface *ret;\n'
2682 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2683 ' if (ret == NULL)\n'
2685 ' return %s%s (ret);\n'
2688 %(i.name, self.ns_upper, i.name_upper))
2690 for i in self.ifaces:
2691 self.c.write(self.docbook_gen.expand(
2693 ' * %sobject_peek_%s: (skip)\n'
2694 ' * @object: A #%sObject.\n'
2696 ' * Like %sobject_get_%s() but doesn\' increase the reference count on the returned object.\n'
2698 ' * <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'
2700 ' * 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'
2701 %(self.ns_lower, i.name_upper.lower(), self.namespace, self.ns_lower, i.name_upper.lower(), i.camel_name), False))
2702 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2703 self.c.write ('%s *%sobject_peek_%s (%sObject *object)\n'
2704 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2706 ' GDBusInterface *ret;\n'
2707 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2708 ' if (ret == NULL)\n'
2710 ' g_object_unref (ret);\n'
2711 ' return %s%s (ret);\n'
2714 %(i.name, self.ns_upper, i.name_upper))
2716 # shared by ObjectProxy and ObjectSkeleton classes
2717 self.c.write('static void\n'
2718 '%sobject_notify (GDBusObject *object, GDBusInterface *interface)\n'
2720 ' g_object_notify (G_OBJECT (object), ((_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface))->hyphen_name);\n'
2725 self.c.write(self.docbook_gen.expand(
2727 ' * %sObjectProxy:\n'
2729 ' * The #%sObjectProxy structure contains only private data and should only be accessed using the provided API.\n'
2730 %(self.namespace, self.namespace), False))
2731 self.c.write(' */\n')
2733 self.c.write(self.docbook_gen.expand(
2735 ' * %sObjectProxyClass:\n'
2736 ' * @parent_class: The parent class.\n'
2738 ' * Class structure for #%sObjectProxy.\n'
2739 %(self.namespace, self.namespace), False))
2740 self.c.write(' */\n')
2743 self.c.write('static void\n'
2744 '%sobject_proxy__%sobject_iface_init (%sObjectIface *iface)\n'
2748 %(self.ns_lower, self.ns_lower, self.namespace))
2749 self.c.write('static void\n'
2750 '%sobject_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2752 ' iface->interface_added = %sobject_notify;\n'
2753 ' iface->interface_removed = %sobject_notify;\n'
2756 %(self.ns_lower, self.ns_lower, self.ns_lower))
2758 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectProxy, %sobject_proxy, G_TYPE_DBUS_OBJECT_PROXY,\n'
2759 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_proxy__%sobject_iface_init)\n'
2760 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_proxy__g_dbus_object_iface_init));\n'
2762 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2764 self.c.write('static void\n'
2765 '%sobject_proxy_init (%sObjectProxy *object)\n'
2768 '\n'%(self.ns_lower, self.namespace))
2769 self.c.write('static void\n'
2770 '%sobject_proxy_set_property (GObject *gobject,\n'
2772 ' const GValue *value,\n'
2773 ' GParamSpec *pspec)\n'
2775 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2779 self.c.write('static void\n'
2780 '%sobject_proxy_get_property (GObject *gobject,\n'
2783 ' GParamSpec *pspec)\n'
2785 ' %sObjectProxy *object = %sOBJECT_PROXY (gobject);\n'
2786 ' GDBusInterface *interface;\n'
2788 ' switch (prop_id)\n'
2790 %(self.ns_lower, self.namespace, self.ns_upper))
2792 for i in self.ifaces:
2793 self.c.write(' case %d:\n'
2794 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2795 ' g_value_take_object (value, interface);\n'
2800 self.c.write(' default:\n'
2801 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2806 self.c.write('static void\n'
2807 '%sobject_proxy_class_init (%sObjectProxyClass *klass)\n'
2809 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2811 ' gobject_class->set_property = %sobject_proxy_set_property;\n'
2812 ' gobject_class->get_property = %sobject_proxy_get_property;\n'
2814 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2816 for i in self.ifaces:
2817 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2819 %(n, i.name_hyphen))
2824 self.c.write(self.docbook_gen.expand(
2826 ' * %sobject_proxy_new:\n'
2827 ' * @connection: A #GDBusConnection.\n'
2828 ' * @object_path: An object path.\n'
2830 ' * Creates a new proxy object.\n'
2832 ' * Returns: (transfer full): The proxy object.\n'
2834 %(self.ns_lower), False))
2835 self.c.write('%sObjectProxy *\n'
2836 '%sobject_proxy_new (GDBusConnection *connection,\n'
2837 ' const gchar *object_path)\n'
2839 ' g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);\n'
2840 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2841 ' return %sOBJECT_PROXY (g_object_new (%sTYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL));\n'
2843 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2845 self.c.write(self.docbook_gen.expand(
2847 ' * %sObjectSkeleton:\n'
2849 ' * The #%sObjectSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2850 %(self.namespace, self.namespace), False))
2851 self.c.write(' */\n')
2853 self.c.write(self.docbook_gen.expand(
2855 ' * %sObjectSkeletonClass:\n'
2856 ' * @parent_class: The parent class.\n'
2858 ' * Class structure for #%sObjectSkeleton.\n'
2859 %(self.namespace, self.namespace), False))
2860 self.c.write(' */\n')
2863 self.c.write('static void\n'
2864 '%sobject_skeleton__%sobject_iface_init (%sObjectIface *iface)\n'
2868 %(self.ns_lower, self.ns_lower, self.namespace))
2870 self.c.write('static void\n'
2871 '%sobject_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2873 ' iface->interface_added = %sobject_notify;\n'
2874 ' iface->interface_removed = %sobject_notify;\n'
2877 %(self.ns_lower, self.ns_lower, self.ns_lower))
2878 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectSkeleton, %sobject_skeleton, G_TYPE_DBUS_OBJECT_SKELETON,\n'
2879 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_skeleton__%sobject_iface_init)\n'
2880 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_skeleton__g_dbus_object_iface_init));\n'
2882 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2884 self.c.write('static void\n'
2885 '%sobject_skeleton_init (%sObjectSkeleton *object)\n'
2888 '\n'%(self.ns_lower, self.namespace))
2889 self.c.write('static void\n'
2890 '%sobject_skeleton_set_property (GObject *gobject,\n'
2892 ' const GValue *value,\n'
2893 ' GParamSpec *pspec)\n'
2895 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2896 ' GDBusInterfaceSkeleton *interface;\n'
2898 ' switch (prop_id)\n'
2900 %(self.ns_lower, self.namespace, self.ns_upper))
2902 for i in self.ifaces:
2903 self.c.write(' case %d:\n'
2904 ' interface = g_value_get_object (value);\n'
2905 ' if (interface != NULL)\n'
2907 ' g_warn_if_fail (%sIS_%s (interface));\n'
2908 ' g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface);\n'
2912 ' g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "%s");\n'
2916 %(n, self.ns_upper, i.name_upper, i.name))
2918 self.c.write(' default:\n'
2919 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2924 self.c.write('static void\n'
2925 '%sobject_skeleton_get_property (GObject *gobject,\n'
2928 ' GParamSpec *pspec)\n'
2930 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2931 ' GDBusInterface *interface;\n'
2933 ' switch (prop_id)\n'
2935 %(self.ns_lower, self.namespace, self.ns_upper))
2937 for i in self.ifaces:
2938 self.c.write(' case %d:\n'
2939 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2940 ' g_value_take_object (value, interface);\n'
2945 self.c.write(' default:\n'
2946 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2951 self.c.write('static void\n'
2952 '%sobject_skeleton_class_init (%sObjectSkeletonClass *klass)\n'
2954 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2956 ' gobject_class->set_property = %sobject_skeleton_set_property;\n'
2957 ' gobject_class->get_property = %sobject_skeleton_get_property;\n'
2959 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2961 for i in self.ifaces:
2962 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2964 %(n, i.name_hyphen))
2968 self.c.write(self.docbook_gen.expand(
2970 ' * %sobject_skeleton_new:\n'
2971 ' * @object_path: An object path.\n'
2973 ' * Creates a new skeleton object.\n'
2975 ' * Returns: (transfer full): The skeleton object.\n'
2977 %(self.ns_lower), False))
2978 self.c.write('%sObjectSkeleton *\n'
2979 '%sobject_skeleton_new (const gchar *object_path)\n'
2981 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2982 ' return %sOBJECT_SKELETON (g_object_new (%sTYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL));\n'
2984 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2985 for i in self.ifaces:
2986 self.c.write(self.docbook_gen.expand(
2988 ' * %sobject_skeleton_set_%s:\n'
2989 ' * @object: A #%sObjectSkeleton.\n'
2990 ' * @interface_: (allow-none): A #%s or %%NULL to clear the interface.\n'
2992 ' * Sets the #%s instance for the D-Bus interface #%s on @object.\n'
2993 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.camel_name, i.name), False))
2994 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2995 self.c.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_)\n'
2996 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
2998 ' g_object_set (G_OBJECT (object), "%s", interface_, NULL);\n'
3005 def generate_object_manager_client(self):
3006 self.c.write('/* ------------------------------------------------------------------------\n'
3007 ' * Code for ObjectManager client\n'
3008 ' * ------------------------------------------------------------------------\n'
3012 self.c.write(self.docbook_gen.expand(
3014 ' * SECTION:%sObjectManagerClient\n'
3015 ' * @title: %sObjectManagerClient\n'
3016 ' * @short_description: Generated GDBusObjectManagerClient type\n'
3018 ' * This section contains a #GDBusObjectManagerClient that uses %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc.\n'
3020 %(self.namespace, self.namespace, self.ns_lower), False))
3023 self.c.write(self.docbook_gen.expand(
3025 ' * %sObjectManagerClient:\n'
3027 ' * The #%sObjectManagerClient structure contains only private data and should only be accessed using the provided API.\n'
3028 %(self.namespace, self.namespace), False))
3029 self.c.write(' */\n')
3032 self.c.write(self.docbook_gen.expand(
3034 ' * %sObjectManagerClientClass:\n'
3035 ' * @parent_class: The parent class.\n'
3037 ' * Class structure for #%sObjectManagerClient.\n'
3038 %(self.namespace, self.namespace), False))
3039 self.c.write(' */\n')
3043 self.c.write('G_DEFINE_TYPE (%sObjectManagerClient, %sobject_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT);\n'
3045 %(self.namespace, self.ns_lower))
3048 self.c.write('static void\n'
3049 '%sobject_manager_client_init (%sObjectManagerClient *manager)\n'
3052 '\n'%(self.ns_lower, self.namespace))
3053 self.c.write('static void\n'
3054 '%sobject_manager_client_class_init (%sObjectManagerClientClass *klass)\n'
3057 '\n'%(self.ns_lower, self.namespace))
3059 self.c.write(self.docbook_gen.expand(
3061 ' * %sobject_manager_client_get_proxy_type:\n'
3062 ' * @manager: A #GDBusObjectManagerClient.\n'
3063 ' * @object_path: The object path of the remote object (unused).\n'
3064 ' * @interface_name: (allow-none): Interface name of the remote object or %%NULL to get the object proxy #GType.\n'
3065 ' * @user_data: User data (unused).\n'
3067 ' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types.\n'
3069 ' * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %%NULL, otherwise the #GType for #%sObjectProxy.\n'
3070 %(self.ns_lower, self.namespace), False))
3071 self.c.write(' */\n')
3072 self.c.write('GType\n'
3073 '%sobject_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data)\n'
3076 self.c.write(' static gsize once_init_value = 0;\n'
3077 ' static GHashTable *lookup_hash;\n'
3080 ' if (interface_name == NULL)\n'
3081 ' return %sTYPE_OBJECT_PROXY;\n'
3082 ' if (g_once_init_enter (&once_init_value))\n'
3084 ' lookup_hash = g_hash_table_new (g_str_hash, g_str_equal);\n'
3086 for i in self.ifaces:
3087 self.c.write(' g_hash_table_insert (lookup_hash, "%s", GSIZE_TO_POINTER (%sTYPE_%s_PROXY));\n'
3088 %(i.name, i.ns_upper, i.name_upper))
3089 self.c.write(' g_once_init_leave (&once_init_value, 1);\n'
3091 self.c.write(' ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name));\n'
3092 ' if (ret == (GType) 0)\n'
3093 ' ret = G_TYPE_DBUS_PROXY;\n')
3094 self.c.write(' return ret;\n'
3099 self.c.write(self.docbook_gen.expand(
3101 ' * %sobject_manager_client_new:\n'
3102 ' * @connection: A #GDBusConnection.\n'
3103 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3104 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3105 ' * @object_path: An object path.\n'
3106 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3107 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3108 ' * @user_data: User data to pass to @callback.\n'
3110 ' * Asynchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details.\n'
3112 ' * 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'
3113 ' * You can then call %sobject_manager_client_new_finish() to get the result of the operation.\n'
3115 ' * See %sobject_manager_client_new_sync() for the synchronous, blocking version of this constructor.\n'
3116 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3117 self.c.write(' */\n')
3118 self.c.write('void\n'
3119 '%sobject_manager_client_new (\n'
3120 ' GDBusConnection *connection,\n'
3121 ' GDBusObjectManagerClientFlags flags,\n'
3122 ' const gchar *name,\n'
3123 ' const gchar *object_path,\n'
3124 ' GCancellable *cancellable,\n'
3125 ' GAsyncReadyCallback callback,\n'
3126 ' gpointer user_data)\n'
3128 ' 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'
3131 %(self.ns_lower, self.ns_upper, self.ns_lower))
3132 self.c.write('/**\n'
3133 ' * %sobject_manager_client_new_finish:\n'
3134 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new().\n'
3135 ' * @error: Return location for error or %%NULL\n'
3137 ' * Finishes an operation started with %sobject_manager_client_new().\n'
3139 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3140 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3141 self.c.write(' */\n')
3142 self.c.write('GDBusObjectManager *\n'
3143 '%sobject_manager_client_new_finish (\n'
3144 ' GAsyncResult *res,\n'
3145 ' GError **error)\n'
3148 ' GObject *source_object;\n'
3149 ' source_object = g_async_result_get_source_object (res);\n'
3150 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3151 ' g_object_unref (source_object);\n'
3152 ' if (ret != NULL)\n'
3153 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3159 self.c.write(self.docbook_gen.expand(
3161 ' * %sobject_manager_client_new_sync:\n'
3162 ' * @connection: A #GDBusConnection.\n'
3163 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3164 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3165 ' * @object_path: An object path.\n'
3166 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3167 ' * @error: Return location for error or %%NULL\n'
3169 ' * 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'
3171 ' * The calling thread is blocked until a reply is received.\n'
3173 ' * See %sobject_manager_client_new() for the asynchronous version of this constructor.\n'
3175 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3176 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3177 self.c.write(' */\n')
3178 self.c.write('GDBusObjectManager *\n'
3179 '%sobject_manager_client_new_sync (\n'
3180 ' GDBusConnection *connection,\n'
3181 ' GDBusObjectManagerClientFlags flags,\n'
3182 ' const gchar *name,\n'
3183 ' const gchar *object_path,\n'
3184 ' GCancellable *cancellable,\n'
3185 ' GError **error)\n'
3187 ' GInitable *ret;\n'
3188 ' 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'
3189 ' if (ret != NULL)\n'
3190 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3195 %(self.ns_lower, self.ns_upper, self.ns_lower))
3197 self.c.write(self.docbook_gen.expand(
3199 ' * %sobject_manager_client_new_for_bus:\n'
3200 ' * @bus_type: A #GBusType.\n'
3201 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3202 ' * @name: A bus name (well-known or unique).\n'
3203 ' * @object_path: An object path.\n'
3204 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3205 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3206 ' * @user_data: User data to pass to @callback.\n'
3208 ' * Like %sobject_manager_client_new() but takes a #GBusType instead of a #GDBusConnection.\n'
3210 ' * 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'
3211 ' * You can then call %sobject_manager_client_new_for_bus_finish() to get the result of the operation.\n'
3213 ' * See %sobject_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
3214 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3215 self.c.write(' */\n')
3216 self.c.write('void\n'
3217 '%sobject_manager_client_new_for_bus (\n'
3218 ' GBusType bus_type,\n'
3219 ' GDBusObjectManagerClientFlags flags,\n'
3220 ' const gchar *name,\n'
3221 ' const gchar *object_path,\n'
3222 ' GCancellable *cancellable,\n'
3223 ' GAsyncReadyCallback callback,\n'
3224 ' gpointer user_data)\n'
3226 ' 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'
3229 %(self.ns_lower, self.ns_upper, self.ns_lower))
3230 self.c.write('/**\n'
3231 ' * %sobject_manager_client_new_for_bus_finish:\n'
3232 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new_for_bus().\n'
3233 ' * @error: Return location for error or %%NULL\n'
3235 ' * Finishes an operation started with %sobject_manager_client_new_for_bus().\n'
3237 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3238 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3239 self.c.write(' */\n')
3240 self.c.write('GDBusObjectManager *\n'
3241 '%sobject_manager_client_new_for_bus_finish (\n'
3242 ' GAsyncResult *res,\n'
3243 ' GError **error)\n'
3246 ' GObject *source_object;\n'
3247 ' source_object = g_async_result_get_source_object (res);\n'
3248 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3249 ' g_object_unref (source_object);\n'
3250 ' if (ret != NULL)\n'
3251 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3257 self.c.write(self.docbook_gen.expand(
3259 ' * %sobject_manager_client_new_for_bus_sync:\n'
3260 ' * @bus_type: A #GBusType.\n'
3261 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3262 ' * @name: A bus name (well-known or unique).\n'
3263 ' * @object_path: An object path.\n'
3264 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3265 ' * @error: Return location for error or %%NULL\n'
3267 ' * Like %sobject_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
3269 ' * The calling thread is blocked until a reply is received.\n'
3271 ' * See %sobject_manager_client_new_for_bus() for the asynchronous version of this constructor.\n'
3273 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3274 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3275 self.c.write(' */\n')
3276 self.c.write('GDBusObjectManager *\n'
3277 '%sobject_manager_client_new_for_bus_sync (\n'
3278 ' GBusType bus_type,\n'
3279 ' GDBusObjectManagerClientFlags flags,\n'
3280 ' const gchar *name,\n'
3281 ' const gchar *object_path,\n'
3282 ' GCancellable *cancellable,\n'
3283 ' GError **error)\n'
3285 ' GInitable *ret;\n'
3286 ' 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'
3287 ' if (ret != NULL)\n'
3288 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3293 %(self.ns_lower, self.ns_upper, self.ns_lower))
3296 # ---------------------------------------------------------------------------------------------------
3298 def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
3299 if len(obj.since) > 0:
3302 %(indent, '', indent, '', obj.since))
3304 if isinstance(obj, dbustypes.Interface):
3305 thing = 'The D-Bus interface'
3306 elif isinstance(obj, dbustypes.Method):
3307 thing = 'The D-Bus method'
3308 elif isinstance(obj, dbustypes.Signal):
3309 thing = 'The D-Bus signal'
3310 elif isinstance(obj, dbustypes.Property):
3311 thing = 'The D-Bus property'
3313 raise RuntimeError('Cannot handle object ', obj)
3314 f.write(self.docbook_gen.expand(
3316 '%*s * Deprecated: %s has been deprecated.\n'
3317 %(indent, '', indent, '', thing), False))
3318 f.write('%*s */\n'%(indent, ''))
3320 # ---------------------------------------------------------------------------------------------------
3322 def generate_interface_intro(self, i):
3323 self.c.write('/* ------------------------------------------------------------------------\n'
3324 ' * Code for interface %s\n'
3325 ' * ------------------------------------------------------------------------\n'
3329 self.c.write(self.docbook_gen.expand(
3333 ' * @short_description: Generated C code for the %s D-Bus interface\n'
3335 ' * This section contains code for working with the #%s D-Bus interface in C.\n'
3337 %(i.camel_name, i.camel_name, i.name, i.name), False))
3341 self.generate_intro()
3342 self.declare_types()
3343 for i in self.ifaces:
3344 self.generate_interface_intro(i)
3345 self.generate_introspection_for_interface(i)
3346 self.generate_interface(i)
3347 self.generate_property_accessors(i)
3348 self.generate_signal_emitters(i)
3349 self.generate_method_calls(i)
3350 self.generate_method_completers(i)
3351 self.generate_proxy(i)
3352 self.generate_skeleton(i)
3353 if self.generate_objmanager:
3354 self.generate_object()
3355 self.generate_object_manager_client()
3356 self.generate_outro()