3 # GDBus - GLib D-Bus Library
5 # Copyright (C) 2008-2011 Red Hat, Inc.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General
18 # Public License along with this library; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA 02111-1307, USA.
22 # Author: David Zeuthen <davidz@redhat.com>
28 from . import dbustypes
30 # ----------------------------------------------------------------------------------------------------
33 def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, docbook_gen, h, c):
34 self.docbook_gen = docbook_gen
35 self.generate_objmanager = generate_objmanager
39 self.namespace = namespace
40 if len(namespace) > 0:
41 if utils.is_ugly_case(namespace):
42 self.namespace = namespace.replace('_', '')
43 self.ns_upper = namespace.upper() + '_'
44 self.ns_lower = namespace.lower() + '_'
46 self.ns_upper = utils.camel_case_to_uscore(namespace).upper() + '_'
47 self.ns_lower = utils.camel_case_to_uscore(namespace).lower() + '_'
51 self.interface_prefix = interface_prefix
52 self.header_guard = self.h.name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
54 # ----------------------------------------------------------------------------------------------------
56 def generate_intro(self):
58 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
60 ' * The license of this code is the same as for the source it was derived from.\n'
64 self.c.write('#ifdef HAVE_CONFIG_H\n'
65 '# include "config.h"\n'
70 '#include <string.h>\n'
73 self.c.write('#ifdef G_OS_UNIX\n'
74 '# include <gio/gunixfdlist.h>\n'
78 self.c.write('typedef struct\n'
80 ' GDBusArgInfo parent_struct;\n'
81 ' gboolean use_gvariant;\n'
82 '} _ExtendedGDBusArgInfo;\n'
85 self.c.write('typedef struct\n'
87 ' GDBusMethodInfo parent_struct;\n'
88 ' const gchar *signal_name;\n'
89 ' gboolean pass_fdlist;\n'
90 '} _ExtendedGDBusMethodInfo;\n'
93 self.c.write('typedef struct\n'
95 ' GDBusSignalInfo parent_struct;\n'
96 ' const gchar *signal_name;\n'
97 '} _ExtendedGDBusSignalInfo;\n'
100 self.c.write('typedef struct\n'
102 ' GDBusPropertyInfo parent_struct;\n'
103 ' const gchar *hyphen_name;\n'
104 ' gboolean use_gvariant;\n'
105 '} _ExtendedGDBusPropertyInfo;\n'
108 self.c.write('typedef struct\n'
110 ' GDBusInterfaceInfo parent_struct;\n'
111 ' const gchar *hyphen_name;\n'
112 '} _ExtendedGDBusInterfaceInfo;\n'
115 self.c.write('typedef struct\n'
117 ' const _ExtendedGDBusPropertyInfo *info;\n'
119 ' GValue orig_value; /* the value before the change */\n'
120 '} ChangedProperty;\n'
123 '_changed_property_free (ChangedProperty *data)\n'
125 ' g_value_unset (&data->orig_value);\n'
130 self.c.write('static gboolean\n'
131 '_g_strv_equal0 (gchar **a, gchar **b)\n'
133 ' gboolean ret = FALSE;\n'
135 ' if (a == NULL && b == NULL)\n'
140 ' if (a == NULL || b == NULL)\n'
142 ' if (g_strv_length (a) != g_strv_length (b))\n'
144 ' for (n = 0; a[n] != NULL; n++)\n'
145 ' if (g_strcmp0 (a[n], b[n]) != 0)\n'
153 self.c.write('static gboolean\n'
154 '_g_variant_equal0 (GVariant *a, GVariant *b)\n'
156 ' gboolean ret = FALSE;\n'
157 ' if (a == NULL && b == NULL)\n'
162 ' if (a == NULL || b == NULL)\n'
164 ' ret = g_variant_equal (a, b);\n'
170 # simplified - only supports the types we use
171 self.c.write('G_GNUC_UNUSED static gboolean\n'
172 '_g_value_equal (const GValue *a, const GValue *b)\n'
174 ' gboolean ret = FALSE;\n'
175 ' g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b));\n'
176 ' switch (G_VALUE_TYPE (a))\n'
178 ' case G_TYPE_BOOLEAN:\n'
179 ' ret = (g_value_get_boolean (a) == g_value_get_boolean (b));\n'
181 ' case G_TYPE_UCHAR:\n'
182 ' ret = (g_value_get_uchar (a) == g_value_get_uchar (b));\n'
184 ' case G_TYPE_INT:\n'
185 ' ret = (g_value_get_int (a) == g_value_get_int (b));\n'
187 ' case G_TYPE_UINT:\n'
188 ' ret = (g_value_get_uint (a) == g_value_get_uint (b));\n'
190 ' case G_TYPE_INT64:\n'
191 ' ret = (g_value_get_int64 (a) == g_value_get_int64 (b));\n'
193 ' case G_TYPE_UINT64:\n'
194 ' ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n'
196 ' case G_TYPE_DOUBLE:\n'
198 ' /* Avoid -Wfloat-equal warnings by doing a direct bit compare */\n'
199 ' gdouble da = g_value_get_double (a);\n'
200 ' gdouble db = g_value_get_double (b);\n'
201 ' ret = memcmp (&da, &db, sizeof (gdouble)) == 0;\n'
204 ' case G_TYPE_STRING:\n'
205 ' ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n'
207 ' case G_TYPE_VARIANT:\n'
208 ' ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b));\n'
211 ' if (G_VALUE_TYPE (a) == G_TYPE_STRV)\n'
212 ' ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b));\n'
214 ' g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a)));\n'
222 ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
224 ' * The license of this code is the same as for the source it was derived from.\n'
229 '\n'%(config.VERSION, self.header_guard, self.header_guard))
230 self.h.write('#include <gio/gio.h>\n'
235 # ----------------------------------------------------------------------------------------------------
237 def declare_types(self):
238 for i in self.ifaces:
240 self.h.write('/* ------------------------------------------------------------------------ */\n')
241 self.h.write('/* Declarations for %s */\n'%i.name)
244 # First the GInterface
245 self.h.write('#define %sTYPE_%s (%s_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
246 self.h.write('#define %s%s(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_%s, %s))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
247 self.h.write('#define %sIS_%s(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_%s))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
248 self.h.write('#define %s%s_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), %sTYPE_%s, %sIface))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
250 self.h.write('struct _%s;\n'%(i.camel_name))
251 self.h.write('typedef struct _%s %s;\n'%(i.camel_name, i.camel_name))
252 self.h.write('typedef struct _%sIface %sIface;\n'%(i.camel_name, i.camel_name))
254 self.h.write('struct _%sIface\n'%(i.camel_name))
256 self.h.write(' GTypeInterface parent_iface;\n')
258 function_pointers = {}
261 if len(i.methods) > 0:
265 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
267 key = (m.since, '_method_%s'%m.name_lower)
268 value = ' gboolean (*handle_%s) (\n'%(m.name_lower)
269 value += ' %s *object,\n'%(i.camel_name)
270 value += ' GDBusMethodInvocation *invocation'%()
272 value += ',\n GUnixFDList *fd_list'
274 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
276 function_pointers[key] = value
279 if len(i.signals) > 0:
282 key = (s.since, '_signal_%s'%s.name_lower)
283 value = ' void (*%s) (\n'%(s.name_lower)
284 value += ' %s *object'%(i.camel_name)
286 value += ',\n %sarg_%s'%(a.ctype_in, a.name)
288 function_pointers[key] = value
290 # vfuncs for properties
291 if len(i.properties) > 0:
293 for p in i.properties:
294 key = (p.since, '_prop_get_%s'%p.name_lower)
295 value = ' %s (*get_%s) (%s *object);\n\n'%(p.arg.ctype_in, p.name_lower, i.camel_name)
296 function_pointers[key] = value
298 # Sort according to @since tag, then name.. this ensures
299 # that the function pointers don't change order assuming
300 # judicious use of @since
302 # Also use a proper version comparison function so e.g.
303 # 10.0 comes after 2.0.
305 # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
307 for key in sorted(function_pointers.keys(), key=utils.version_cmp_key):
308 self.h.write('%s'%function_pointers[key])
312 self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
314 self.h.write('GDBusInterfaceInfo *%s_interface_info (void);\n'%(i.name_lower))
315 self.h.write('guint %s_override_properties (GObjectClass *klass, guint property_id_begin);\n'%(i.name_lower))
318 # Then method call completion functions
319 if len(i.methods) > 0:
321 self.h.write('/* D-Bus method call completion functions: */\n')
324 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
327 self.h.write('G_GNUC_DEPRECATED ')
328 self.h.write('void %s_complete_%s (\n'
330 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
332 self.h.write(',\n GUnixFDList *fd_list')
334 self.h.write(',\n %s%s'%(a.ctype_in, a.name))
339 # Then signal emission functions
340 if len(i.signals) > 0:
342 self.h.write('/* D-Bus signal emissions functions: */\n')
345 self.h.write('G_GNUC_DEPRECATED ')
346 self.h.write('void %s_emit_%s (\n'
347 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
349 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
354 # Then method call declarations
355 if len(i.methods) > 0:
357 self.h.write('/* D-Bus method calls: */\n')
360 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
364 self.h.write('G_GNUC_DEPRECATED ')
365 self.h.write('void %s_call_%s (\n'
366 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
368 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
370 self.h.write(',\n GUnixFDList *fd_list')
372 ' GCancellable *cancellable,\n'
373 ' GAsyncReadyCallback callback,\n'
374 ' gpointer user_data);\n')
378 self.h.write('G_GNUC_DEPRECATED ')
379 self.h.write('gboolean %s_call_%s_finish (\n'
380 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
382 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
384 self.h.write(',\n GUnixFDList **out_fd_list')
386 ' GAsyncResult *res,\n'
387 ' GError **error);\n')
391 self.h.write('G_GNUC_DEPRECATED ')
392 self.h.write('gboolean %s_call_%s_sync (\n'
393 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
395 self.h.write(',\n %sarg_%s'%(a.ctype_in, a.name))
397 self.h.write(',\n GUnixFDList *fd_list')
399 self.h.write(',\n %sout_%s'%(a.ctype_out, a.name))
401 self.h.write(',\n GUnixFDList **out_fd_list')
403 ' GCancellable *cancellable,\n'
404 ' GError **error);\n')
408 # Then the property accessor declarations
409 if len(i.properties) > 0:
411 self.h.write('/* D-Bus property accessors: */\n')
412 for p in i.properties:
415 self.h.write('G_GNUC_DEPRECATED ')
416 self.h.write('%s%s_get_%s (%s *object);\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
417 if p.arg.free_func != None:
419 self.h.write('G_GNUC_DEPRECATED ')
420 self.h.write('%s%s_dup_%s (%s *object);\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name))
423 self.h.write('G_GNUC_DEPRECATED ')
424 self.h.write('void %s_set_%s (%s *object, %svalue);\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
429 self.h.write('/* ---- */\n')
431 self.h.write('#define %sTYPE_%s_PROXY (%s_proxy_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
432 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))
433 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))
434 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))
435 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))
436 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))
438 self.h.write('typedef struct _%sProxy %sProxy;\n'%(i.camel_name, i.camel_name))
439 self.h.write('typedef struct _%sProxyClass %sProxyClass;\n'%(i.camel_name, i.camel_name))
440 self.h.write('typedef struct _%sProxyPrivate %sProxyPrivate;\n'%(i.camel_name, i.camel_name))
442 self.h.write('struct _%sProxy\n'%(i.camel_name))
444 self.h.write(' /*< private >*/\n')
445 self.h.write(' GDBusProxy parent_instance;\n')
446 self.h.write(' %sProxyPrivate *priv;\n'%(i.camel_name))
449 self.h.write('struct _%sProxyClass\n'%(i.camel_name))
451 self.h.write(' GDBusProxyClass parent_class;\n')
454 self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
458 self.h.write('G_GNUC_DEPRECATED ')
459 self.h.write('void %s_proxy_new (\n'
460 ' GDBusConnection *connection,\n'
461 ' GDBusProxyFlags flags,\n'
462 ' const gchar *name,\n'
463 ' const gchar *object_path,\n'
464 ' GCancellable *cancellable,\n'
465 ' GAsyncReadyCallback callback,\n'
466 ' gpointer user_data);\n'
469 self.h.write('G_GNUC_DEPRECATED ')
470 self.h.write('%s *%s_proxy_new_finish (\n'
471 ' GAsyncResult *res,\n'
472 ' GError **error);\n'
473 %(i.camel_name, i.name_lower))
475 self.h.write('G_GNUC_DEPRECATED ')
476 self.h.write('%s *%s_proxy_new_sync (\n'
477 ' GDBusConnection *connection,\n'
478 ' GDBusProxyFlags flags,\n'
479 ' const gchar *name,\n'
480 ' const gchar *object_path,\n'
481 ' GCancellable *cancellable,\n'
482 ' GError **error);\n'
483 %(i.camel_name, i.name_lower))
486 self.h.write('G_GNUC_DEPRECATED ')
487 self.h.write('void %s_proxy_new_for_bus (\n'
488 ' GBusType bus_type,\n'
489 ' GDBusProxyFlags flags,\n'
490 ' const gchar *name,\n'
491 ' const gchar *object_path,\n'
492 ' GCancellable *cancellable,\n'
493 ' GAsyncReadyCallback callback,\n'
494 ' gpointer user_data);\n'
497 self.h.write('G_GNUC_DEPRECATED ')
498 self.h.write('%s *%s_proxy_new_for_bus_finish (\n'
499 ' GAsyncResult *res,\n'
500 ' GError **error);\n'
501 %(i.camel_name, i.name_lower))
503 self.h.write('G_GNUC_DEPRECATED ')
504 self.h.write('%s *%s_proxy_new_for_bus_sync (\n'
505 ' GBusType bus_type,\n'
506 ' GDBusProxyFlags flags,\n'
507 ' const gchar *name,\n'
508 ' const gchar *object_path,\n'
509 ' GCancellable *cancellable,\n'
510 ' GError **error);\n'
511 %(i.camel_name, i.name_lower))
516 self.h.write('/* ---- */\n')
518 self.h.write('#define %sTYPE_%s_SKELETON (%s_skeleton_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
519 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))
520 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))
521 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))
522 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))
523 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))
525 self.h.write('typedef struct _%sSkeleton %sSkeleton;\n'%(i.camel_name, i.camel_name))
526 self.h.write('typedef struct _%sSkeletonClass %sSkeletonClass;\n'%(i.camel_name, i.camel_name))
527 self.h.write('typedef struct _%sSkeletonPrivate %sSkeletonPrivate;\n'%(i.camel_name, i.camel_name))
529 self.h.write('struct _%sSkeleton\n'%(i.camel_name))
531 self.h.write(' /*< private >*/\n')
532 self.h.write(' GDBusInterfaceSkeleton parent_instance;\n')
533 self.h.write(' %sSkeletonPrivate *priv;\n'%(i.camel_name))
536 self.h.write('struct _%sSkeletonClass\n'%(i.camel_name))
538 self.h.write(' GDBusInterfaceSkeletonClass parent_class;\n')
541 self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
544 self.h.write('G_GNUC_DEPRECATED ')
545 self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
549 # Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
550 if self.generate_objmanager:
552 self.h.write('/* ---- */\n')
554 self.h.write('#define %sTYPE_OBJECT (%sobject_get_type ())\n'%(self.ns_upper, self.ns_lower))
555 self.h.write('#define %sOBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
556 self.h.write('#define %sIS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT))\n'%(self.ns_upper, self.ns_upper))
557 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))
559 self.h.write('struct _%sObject;\n'%(self.namespace))
560 self.h.write('typedef struct _%sObject %sObject;\n'%(self.namespace, self.namespace))
561 self.h.write('typedef struct _%sObjectIface %sObjectIface;\n'%(self.namespace, self.namespace))
563 self.h.write('struct _%sObjectIface\n'%(self.namespace))
565 ' GTypeInterface parent_iface;\n'
568 self.h.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
571 for i in self.ifaces:
573 self.h.write('G_GNUC_DEPRECATED ')
574 self.h.write ('%s *%sobject_get_%s (%sObject *object);\n'
575 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
576 for i in self.ifaces:
578 self.h.write('G_GNUC_DEPRECATED ')
579 self.h.write ('%s *%sobject_peek_%s (%sObject *object);\n'
580 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
582 self.h.write('#define %sTYPE_OBJECT_PROXY (%sobject_proxy_get_type ())\n'%(self.ns_upper, self.ns_lower))
583 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))
584 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))
585 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))
586 self.h.write('#define %sIS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
587 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))
589 self.h.write('typedef struct _%sObjectProxy %sObjectProxy;\n'%(self.namespace, self.namespace))
590 self.h.write('typedef struct _%sObjectProxyClass %sObjectProxyClass;\n'%(self.namespace, self.namespace))
591 self.h.write('typedef struct _%sObjectProxyPrivate %sObjectProxyPrivate;\n'%(self.namespace, self.namespace))
593 self.h.write('struct _%sObjectProxy\n'%(self.namespace))
595 self.h.write(' /*< private >*/\n')
596 self.h.write(' GDBusObjectProxy parent_instance;\n')
597 self.h.write(' %sObjectProxyPrivate *priv;\n'%(self.namespace))
600 self.h.write('struct _%sObjectProxyClass\n'%(self.namespace))
602 self.h.write(' GDBusObjectProxyClass parent_class;\n')
605 self.h.write('GType %sobject_proxy_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
606 self.h.write('%sObjectProxy *%sobject_proxy_new (GDBusConnection *connection, const gchar *object_path);\n'%(self.namespace, self.ns_lower))
608 self.h.write('#define %sTYPE_OBJECT_SKELETON (%sobject_skeleton_get_type ())\n'%(self.ns_upper, self.ns_lower))
609 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))
610 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))
611 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))
612 self.h.write('#define %sIS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
613 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))
615 self.h.write('typedef struct _%sObjectSkeleton %sObjectSkeleton;\n'%(self.namespace, self.namespace))
616 self.h.write('typedef struct _%sObjectSkeletonClass %sObjectSkeletonClass;\n'%(self.namespace, self.namespace))
617 self.h.write('typedef struct _%sObjectSkeletonPrivate %sObjectSkeletonPrivate;\n'%(self.namespace, self.namespace))
619 self.h.write('struct _%sObjectSkeleton\n'%(self.namespace))
621 self.h.write(' /*< private >*/\n')
622 self.h.write(' GDBusObjectSkeleton parent_instance;\n')
623 self.h.write(' %sObjectSkeletonPrivate *priv;\n'%(self.namespace))
626 self.h.write('struct _%sObjectSkeletonClass\n'%(self.namespace))
628 self.h.write(' GDBusObjectSkeletonClass parent_class;\n')
631 self.h.write('GType %sobject_skeleton_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
632 self.h.write('%sObjectSkeleton *%sobject_skeleton_new (const gchar *object_path);\n'
633 %(self.namespace, self.ns_lower))
634 for i in self.ifaces:
636 self.h.write('G_GNUC_DEPRECATED ')
637 self.h.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_);\n'
638 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
641 self.h.write('/* ---- */\n')
643 self.h.write('#define %sTYPE_OBJECT_MANAGER_CLIENT (%sobject_manager_client_get_type ())\n'%(self.ns_upper, self.ns_lower))
644 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))
645 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))
646 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))
647 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))
648 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))
650 self.h.write('typedef struct _%sObjectManagerClient %sObjectManagerClient;\n'%(self.namespace, self.namespace))
651 self.h.write('typedef struct _%sObjectManagerClientClass %sObjectManagerClientClass;\n'%(self.namespace, self.namespace))
652 self.h.write('typedef struct _%sObjectManagerClientPrivate %sObjectManagerClientPrivate;\n'%(self.namespace, self.namespace))
654 self.h.write('struct _%sObjectManagerClient\n'%(self.namespace))
656 self.h.write(' /*< private >*/\n')
657 self.h.write(' GDBusObjectManagerClient parent_instance;\n')
658 self.h.write(' %sObjectManagerClientPrivate *priv;\n'%(self.namespace))
661 self.h.write('struct _%sObjectManagerClientClass\n'%(self.namespace))
663 self.h.write(' GDBusObjectManagerClientClass parent_class;\n')
666 self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
668 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))
670 self.h.write('void %sobject_manager_client_new (\n'
671 ' GDBusConnection *connection,\n'
672 ' GDBusObjectManagerClientFlags flags,\n'
673 ' const gchar *name,\n'
674 ' const gchar *object_path,\n'
675 ' GCancellable *cancellable,\n'
676 ' GAsyncReadyCallback callback,\n'
677 ' gpointer user_data);\n'
679 self.h.write('GDBusObjectManager *%sobject_manager_client_new_finish (\n'
680 ' GAsyncResult *res,\n'
681 ' GError **error);\n'
683 self.h.write('GDBusObjectManager *%sobject_manager_client_new_sync (\n'
684 ' GDBusConnection *connection,\n'
685 ' GDBusObjectManagerClientFlags flags,\n'
686 ' const gchar *name,\n'
687 ' const gchar *object_path,\n'
688 ' GCancellable *cancellable,\n'
689 ' GError **error);\n'
692 self.h.write('void %sobject_manager_client_new_for_bus (\n'
693 ' GBusType bus_type,\n'
694 ' GDBusObjectManagerClientFlags flags,\n'
695 ' const gchar *name,\n'
696 ' const gchar *object_path,\n'
697 ' GCancellable *cancellable,\n'
698 ' GAsyncReadyCallback callback,\n'
699 ' gpointer user_data);\n'
701 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_finish (\n'
702 ' GAsyncResult *res,\n'
703 ' GError **error);\n'
705 self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_sync (\n'
706 ' GBusType bus_type,\n'
707 ' GDBusObjectManagerClientFlags flags,\n'
708 ' const gchar *name,\n'
709 ' const gchar *object_path,\n'
710 ' GCancellable *cancellable,\n'
711 ' GError **error);\n'
715 # ----------------------------------------------------------------------------------------------------
717 def generate_outro(self):
721 '#endif /* __%s__ */\n'%(self.header_guard))
723 # ----------------------------------------------------------------------------------------------------
725 def generate_annotations(self, prefix, annotations):
726 if annotations == None:
730 for a in annotations:
731 #self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
733 # skip internal annotations
734 if a.key.startswith('org.gtk.GDBus'):
737 self.c.write('static const GDBusAnnotationInfo %s_%d =\n'
741 ' (gchar *) "%s",\n'%(prefix, n, a.key, a.value))
742 if len(a.annotations) == 0:
743 self.c.write(' NULL\n')
745 self.c.write(' (GDBusAnnotationInfo **) &%s_%d_pointers\n'%(prefix, n))
751 self.c.write('static const GDBusAnnotationInfo * const %s_pointers[] =\n'
754 for a in annotations:
755 if a.key.startswith('org.gtk.GDBus'):
757 self.c.write(' &%s_%d,\n'%(prefix, m))
759 self.c.write(' NULL\n'
764 def generate_args(self, prefix, args):
766 num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
768 self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
773 ' (gchar *) "%s",\n'%(prefix, a.name, a.name, a.signature))
775 self.c.write(' NULL\n')
777 self.c.write(' (GDBusAnnotationInfo **) &%s_arg_%s_annotation_info_pointers\n'%(prefix, a.name))
778 self.c.write(' },\n')
779 if not utils.lookup_annotation(a.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
780 self.c.write(' FALSE\n')
782 self.c.write(' TRUE\n')
787 self.c.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
790 self.c.write(' &%s_%s,\n'%(prefix, a.name))
791 self.c.write(' NULL\n'
795 def generate_introspection_for_interface(self, i):
796 self.c.write('/* ---- Introspection data for %s ---- */\n'
799 if len(i.methods) > 0:
802 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
804 self.generate_args('_%s_method_info_%s_IN_ARG'%(i.name_lower, m.name_lower), m.in_args)
805 self.generate_args('_%s_method_info_%s_OUT_ARG'%(i.name_lower, m.name_lower), m.out_args)
807 num_anno = self.generate_annotations('_%s_method_%s_annotation_info'%(i.name_lower, m.name_lower), m.annotations)
809 self.c.write('static const _ExtendedGDBusMethodInfo _%s_method_info_%s =\n'
813 ' (gchar *) "%s",\n'%(i.name_lower, m.name_lower, m.name))
814 if len(m.in_args) == 0:
815 self.c.write(' NULL,\n')
817 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_IN_ARG_pointers,\n'%(i.name_lower, m.name_lower))
818 if len(m.out_args) == 0:
819 self.c.write(' NULL,\n')
821 self.c.write(' (GDBusArgInfo **) &_%s_method_info_%s_OUT_ARG_pointers,\n'%(i.name_lower, m.name_lower))
823 self.c.write(' NULL\n')
825 self.c.write(' (GDBusAnnotationInfo **) &_%s_method_%s_annotation_info_pointers\n'%(i.name_lower, m.name_lower))
829 %(m.name_hyphen, 'TRUE' if unix_fd else 'FALSE'))
833 self.c.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] =\n'
834 '{\n'%(i.name_lower))
836 self.c.write(' &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
837 self.c.write(' NULL\n'
843 if len(i.signals) > 0:
845 self.generate_args('_%s_signal_info_%s_ARG'%(i.name_lower, s.name_lower), s.args)
847 num_anno = self.generate_annotations('_%s_signal_%s_annotation_info'%(i.name_lower, s.name_lower), s.annotations)
848 self.c.write('static const _ExtendedGDBusSignalInfo _%s_signal_info_%s =\n'
852 ' (gchar *) "%s",\n'%(i.name_lower, s.name_lower, s.name))
854 self.c.write(' NULL,\n')
856 self.c.write(' (GDBusArgInfo **) &_%s_signal_info_%s_ARG_pointers,\n'%(i.name_lower, s.name_lower))
858 self.c.write(' NULL\n')
860 self.c.write(' (GDBusAnnotationInfo **) &_%s_signal_%s_annotation_info_pointers\n'%(i.name_lower, s.name_lower))
867 self.c.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
868 '{\n'%(i.name_lower))
870 self.c.write(' &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
871 self.c.write(' NULL\n'
877 if len(i.properties) > 0:
878 for p in i.properties:
879 if p.readable and p.writable:
880 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
882 access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE'
884 access = 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
886 access = 'G_DBUS_PROPERTY_INFO_FLAGS_NONE'
887 num_anno = self.generate_annotations('_%s_property_%s_annotation_info'%(i.name_lower, p.name_lower), p.annotations)
888 self.c.write('static const _ExtendedGDBusPropertyInfo _%s_property_info_%s =\n'
894 ' %s,\n'%(i.name_lower, p.name_lower, p.name, p.arg.signature, access))
896 self.c.write(' NULL\n')
898 self.c.write(' (GDBusAnnotationInfo **) &_%s_property_%s_annotation_info_pointers\n'%(i.name_lower, p.name_lower))
902 if not utils.lookup_annotation(p.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
903 self.c.write(' FALSE\n')
905 self.c.write(' TRUE\n')
909 self.c.write('static const _ExtendedGDBusPropertyInfo * const _%s_property_info_pointers[] =\n'
910 '{\n'%(i.name_lower))
911 for p in i.properties:
912 self.c.write(' &_%s_property_info_%s,\n'%(i.name_lower, p.name_lower))
913 self.c.write(' NULL\n'
917 num_anno = self.generate_annotations('_%s_annotation_info'%(i.name_lower), i.annotations)
918 self.c.write('static const _ExtendedGDBusInterfaceInfo _%s_interface_info =\n'
922 ' (gchar *) "%s",\n'%(i.name_lower, i.name))
923 if len(i.methods) == 0:
924 self.c.write(' NULL,\n')
926 self.c.write(' (GDBusMethodInfo **) &_%s_method_info_pointers,\n'%(i.name_lower))
927 if len(i.signals) == 0:
928 self.c.write(' NULL,\n')
930 self.c.write(' (GDBusSignalInfo **) &_%s_signal_info_pointers,\n'%(i.name_lower))
931 if len(i.properties) == 0:
932 self.c.write(' NULL,\n')
934 self.c.write(' (GDBusPropertyInfo **) &_%s_property_info_pointers,\n'%(i.name_lower))
936 self.c.write(' NULL\n')
938 self.c.write(' (GDBusAnnotationInfo **) &_%s_annotation_info_pointers\n'%(i.name_lower))
945 self.c.write(self.docbook_gen.expand(
947 ' * %s_interface_info:\n'
949 ' * Gets a machine-readable description of the #%s D-Bus interface.\n'
951 ' * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free.\n'
952 %(i.name_lower, i.name), False))
953 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
954 self.c.write('GDBusInterfaceInfo *\n'
955 '%s_interface_info (void)\n'
957 ' return (GDBusInterfaceInfo *) &_%s_interface_info.parent_struct;\n'
959 '\n'%(i.name_lower, i.name_lower))
961 self.c.write(self.docbook_gen.expand(
963 ' * %s_override_properties:\n'
964 ' * @klass: The class structure for a #GObject<!-- -->-derived class.\n'
965 ' * @property_id_begin: The property id to assign to the first overridden property.\n'
967 ' * Overrides all #GObject properties in the #%s interface for a concrete class.\n'
968 ' * The properties are overridden in the order they are defined.\n'
970 ' * Returns: The last property id.\n'
971 %(i.name_lower, i.camel_name), False))
972 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
973 self.c.write('guint\n'
974 '%s_override_properties (GObjectClass *klass, guint property_id_begin)\n'
975 '{\n'%(i.name_lower))
976 for p in i.properties:
977 self.c.write (' g_object_class_override_property (klass, property_id_begin++, "%s");\n'%(p.name_hyphen))
978 self.c.write(' return property_id_begin - 1;\n'
983 # ----------------------------------------------------------------------------------------------------
985 def generate_interface(self, i):
988 self.c.write(self.docbook_gen.expand(
992 ' * Abstract interface type for the D-Bus interface #%s.\n'
993 %(i.camel_name, i.name), False))
994 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
997 self.c.write(self.docbook_gen.expand(
1000 ' * @parent_iface: The parent interface.\n'
1001 %(i.camel_name), False))
1004 if len(i.methods) > 0:
1006 key = (m.since, '_method_%s'%m.name_lower)
1007 value = '@handle_%s: '%(m.name_lower)
1008 value += 'Handler for the #%s::handle-%s signal.'%(i.camel_name, m.name_hyphen)
1009 doc_bits[key] = value
1010 if len(i.signals) > 0:
1012 key = (s.since, '_signal_%s'%s.name_lower)
1013 value = '@%s: '%(s.name_lower)
1014 value += 'Handler for the #%s::%s signal.'%(i.camel_name, s.name_hyphen)
1015 doc_bits[key] = value
1016 if len(i.properties) > 0:
1017 for p in i.properties:
1018 key = (p.since, '_prop_get_%s'%p.name_lower)
1019 value = '@get_%s: '%(p.name_lower)
1020 value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
1021 doc_bits[key] = value
1022 for key in sorted(doc_bits.keys(), key=utils.version_cmp_key):
1023 self.c.write(' * %s\n'%doc_bits[key])
1025 self.c.write(self.docbook_gen.expand(
1027 ' * Virtual table for the D-Bus interface #%s.\n'
1029 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1032 self.c.write('typedef %sIface %sInterface;\n'%(i.camel_name, i.camel_name))
1033 self.c.write('G_DEFINE_INTERFACE (%s, %s, G_TYPE_OBJECT);\n'%(i.camel_name, i.name_lower))
1036 self.c.write('static void\n'
1037 '%s_default_init (%sIface *iface)\n'
1038 '{\n'%(i.name_lower, i.camel_name));
1040 if len(i.methods) > 0:
1041 self.c.write(' /* GObject signals for incoming D-Bus method calls: */\n')
1044 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1046 self.c.write(self.docbook_gen.expand(
1048 ' * %s::handle-%s:\n'
1049 ' * @object: A #%s.\n'
1050 ' * @invocation: A #GDBusMethodInvocation.\n'
1051 %(i.camel_name, m.name_hyphen, i.camel_name), False))
1053 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1055 self.c.write (' * @arg_%s: Argument passed by remote caller.\n'%(a.name))
1056 self.c.write(self.docbook_gen.expand(
1058 ' * Signal emitted when a remote caller is invoking the %s.%s() D-Bus method.\n'
1060 ' * 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'
1062 ' * Returns: %%TRUE if the invocation was handled, %%FALSE to let other signal handlers run.\n'
1063 %(i.name, m.name, i.name_lower, m.name_lower), False))
1064 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 2)
1069 self.c.write(' g_signal_new ("handle-%s",\n'
1070 ' G_TYPE_FROM_INTERFACE (iface),\n'
1071 ' G_SIGNAL_RUN_LAST,\n'
1072 ' G_STRUCT_OFFSET (%sIface, handle_%s),\n'
1073 ' g_signal_accumulator_true_handled,\n'
1074 ' NULL,\n' # accu_data
1075 ' g_cclosure_marshal_generic,\n'
1076 ' G_TYPE_BOOLEAN,\n'
1078 ' G_TYPE_DBUS_METHOD_INVOCATION'
1079 %(m.name_hyphen, i.camel_name, m.name_lower, len(m.in_args) + extra_args))
1081 self.c.write(', G_TYPE_UNIX_FD_LIST')
1083 self.c.write (', %s'%(a.gtype))
1084 self.c.write(');\n')
1087 if len(i.signals) > 0:
1088 self.c.write(' /* GObject signals for received D-Bus signals: */\n')
1090 self.c.write(self.docbook_gen.expand(
1093 ' * @object: A #%s.\n'
1094 %(i.camel_name, s.name_hyphen, i.camel_name), False))
1096 self.c.write (' * @arg_%s: Argument.\n'%(a.name))
1097 self.c.write(self.docbook_gen.expand(
1099 ' * On the client-side, this signal is emitted whenever the D-Bus signal #%s::%s is received.\n'
1101 ' * 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'
1102 %(i.name, s.name), False))
1103 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 2)
1104 self.c.write(' g_signal_new ("%s",\n'
1105 ' G_TYPE_FROM_INTERFACE (iface),\n'
1106 ' G_SIGNAL_RUN_LAST,\n'
1107 ' G_STRUCT_OFFSET (%sIface, %s),\n'
1108 ' NULL,\n' # accumulator
1109 ' NULL,\n' # accu_data
1110 ' g_cclosure_marshal_generic,\n'
1113 %(s.name_hyphen, i.camel_name, s.name_lower, len(s.args)))
1115 self.c.write (', %s'%(a.gtype))
1116 self.c.write(');\n')
1119 if len(i.properties) > 0:
1120 self.c.write(' /* GObject properties for D-Bus properties: */\n')
1121 for p in i.properties:
1122 if p.readable and p.writable:
1123 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.'
1125 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.'
1127 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.'
1129 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1130 self.c.write(self.docbook_gen.expand(
1134 ' * Represents the D-Bus property #%s:%s.\n'
1137 %(i.camel_name, p.name_hyphen, i.name, p.name, hint), False))
1138 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 2)
1139 self.c.write(' g_object_interface_install_property (iface,\n')
1140 if p.arg.gtype == 'G_TYPE_VARIANT':
1141 s = 'g_param_spec_variant ("%s", "%s", "%s", G_VARIANT_TYPE ("%s"), NULL'%(p.name_hyphen, p.name, p.name, p.arg.signature)
1142 elif p.arg.signature == 'b':
1143 s = 'g_param_spec_boolean ("%s", "%s", "%s", FALSE'%(p.name_hyphen, p.name, p.name)
1144 elif p.arg.signature == 'y':
1145 s = 'g_param_spec_uchar ("%s", "%s", "%s", 0, 255, 0'%(p.name_hyphen, p.name, p.name)
1146 elif p.arg.signature == 'n':
1147 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT16, G_MAXINT16, 0'%(p.name_hyphen, p.name, p.name)
1148 elif p.arg.signature == 'q':
1149 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT16, 0'%(p.name_hyphen, p.name, p.name)
1150 elif p.arg.signature == 'i':
1151 s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT32, G_MAXINT32, 0'%(p.name_hyphen, p.name, p.name)
1152 elif p.arg.signature == 'u':
1153 s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT32, 0'%(p.name_hyphen, p.name, p.name)
1154 elif p.arg.signature == 'x':
1155 s = 'g_param_spec_int64 ("%s", "%s", "%s", G_MININT64, G_MAXINT64, 0'%(p.name_hyphen, p.name, p.name)
1156 elif p.arg.signature == 't':
1157 s = 'g_param_spec_uint64 ("%s", "%s", "%s", 0, G_MAXUINT64, 0'%(p.name_hyphen, p.name, p.name)
1158 elif p.arg.signature == 'd':
1159 s = 'g_param_spec_double ("%s", "%s", "%s", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0'%(p.name_hyphen, p.name, p.name)
1160 elif p.arg.signature == 's':
1161 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1162 elif p.arg.signature == 'o':
1163 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1164 elif p.arg.signature == 'g':
1165 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1166 elif p.arg.signature == 'ay':
1167 s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
1168 elif p.arg.signature == 'as':
1169 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1170 elif p.arg.signature == 'ao':
1171 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1172 elif p.arg.signature == 'aay':
1173 s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
1175 raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
1176 self.c.write(' %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
1182 # ----------------------------------------------------------------------------------------------------
1184 def generate_property_accessors(self, i):
1185 for p in i.properties:
1187 if p.readable and p.writable:
1188 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.'
1190 hint = 'Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.'
1192 hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
1194 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1195 self.c.write(self.docbook_gen.expand(
1197 ' * %s_get_%s: (skip)\n'
1198 ' * @object: A #%s.\n'
1200 ' * Gets the value of the #%s:%s D-Bus property.\n'
1204 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1205 if p.arg.free_func != None:
1206 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'
1208 ' * 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'
1209 %(i.name_lower, p.name_lower))
1211 self.c.write(' * Returns: The property value.\n')
1212 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1214 '%s_get_%s (%s *object)\n'
1215 '{\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
1216 self.c.write(' return %s%s_GET_IFACE (object)->get_%s (object);\n'%(i.ns_upper, i.name_upper, p.name_lower))
1219 if p.arg.free_func != None:
1221 self.c.write(self.docbook_gen.expand(
1223 ' * %s_dup_%s: (skip)\n'
1224 ' * @object: A #%s.\n'
1226 ' * Gets a copy of the #%s:%s D-Bus property.\n'
1230 ' * Returns: (transfer full): The property value or %%NULL if the property is not set. The returned value should be freed with %s().\n'
1231 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint, p.arg.free_func), False))
1232 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1234 '%s_dup_%s (%s *object)\n'
1236 ' %svalue;\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in_dup))
1237 self.c.write(' g_object_get (G_OBJECT (object), "%s", &value, NULL);\n'%(p.name_hyphen))
1238 self.c.write(' return value;\n')
1243 if p.readable and p.writable:
1244 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.'
1246 hint = 'Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.'
1248 hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
1250 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1251 self.c.write(self.docbook_gen.expand(
1253 ' * %s_set_%s: (skip)\n'
1254 ' * @object: A #%s.\n'
1255 ' * @value: The value to set.\n'
1257 ' * Sets the #%s:%s D-Bus property to @value.\n'
1260 %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
1261 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1262 self.c.write('void\n'
1263 '%s_set_%s (%s *object, %svalue)\n'
1264 '{\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
1265 self.c.write(' g_object_set (G_OBJECT (object), "%s", value, NULL);\n'%(p.name_hyphen))
1269 # ---------------------------------------------------------------------------------------------------
1271 def generate_signal_emitters(self, i):
1273 self.c.write(self.docbook_gen.expand(
1276 ' * @object: A #%s.\n'
1277 %(i.name_lower, s.name_lower, i.camel_name), False))
1279 self.c.write(' * @arg_%s: Argument to pass with the signal.\n'%(a.name))
1280 self.c.write(self.docbook_gen.expand(
1282 ' * Emits the #%s::%s D-Bus signal.\n'
1283 %(i.name, s.name), False))
1284 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 0)
1285 self.c.write('void\n'
1287 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
1289 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1292 ' g_signal_emit_by_name (object, "%s"'%(s.name_hyphen))
1294 self.c.write(', arg_%s'%a.name)
1295 self.c.write(');\n')
1299 # ---------------------------------------------------------------------------------------------------
1301 def generate_method_calls(self, i):
1304 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1307 self.c.write('/**\n'
1309 ' * @proxy: A #%sProxy.\n'
1310 %(i.name_lower, m.name_lower, i.camel_name))
1312 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1314 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1315 self.c.write(self.docbook_gen.expand(
1316 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1317 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %%NULL.\n'
1318 ' * @user_data: User data to pass to @callback.\n'
1320 ' * Asynchronously invokes the %s.%s() D-Bus method on @proxy.\n'
1321 ' * 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'
1322 ' * You can then call %s_call_%s_finish() to get the result of the operation.\n'
1324 ' * See %s_call_%s_sync() for the synchronous, blocking version of this method.\n'
1325 %(i.name, m.name, i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1326 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1327 self.c.write('void\n'
1329 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1331 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1333 self.c.write(',\n GUnixFDList *fd_list')
1335 ' GCancellable *cancellable,\n'
1336 ' GAsyncReadyCallback callback,\n'
1337 ' gpointer user_data)\n'
1340 self.c.write(' g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy),\n')
1342 self.c.write(' g_dbus_proxy_call (G_DBUS_PROXY (proxy),\n')
1343 self.c.write(' "%s",\n'
1344 ' g_variant_new ("('%(m.name))
1346 self.c.write('%s'%(a.format_in))
1349 self.c.write(',\n arg_%s'%(a.name))
1351 ' G_DBUS_CALL_FLAGS_NONE,\n'
1354 self.c.write(' fd_list,\n')
1355 self.c.write(' cancellable,\n'
1361 self.c.write('/**\n'
1362 ' * %s_call_%s_finish:\n'
1363 ' * @proxy: A #%sProxy.\n'
1364 %(i.name_lower, m.name_lower, i.camel_name))
1365 for a in m.out_args:
1366 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1368 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1369 self.c.write(self.docbook_gen.expand(
1370 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_call_%s().\n'
1371 ' * @error: Return location for error or %%NULL.\n'
1373 ' * Finishes an operation started with %s_call_%s().\n'
1375 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1376 %(i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
1377 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1378 self.c.write('gboolean\n'
1379 '%s_call_%s_finish (\n'
1380 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1381 for a in m.out_args:
1382 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1384 self.c.write(',\n GUnixFDList **out_fd_list')
1386 ' GAsyncResult *res,\n'
1387 ' GError **error)\n'
1389 ' GVariant *_ret;\n')
1391 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error);\n')
1393 self.c.write(' _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);\n')
1394 self.c.write(' if (_ret == NULL)\n'
1396 self.c.write(' g_variant_get (_ret,\n'
1398 for a in m.out_args:
1399 self.c.write('%s'%(a.format_out))
1401 for a in m.out_args:
1402 self.c.write(',\n out_%s'%(a.name))
1404 ' g_variant_unref (_ret);\n')
1405 self.c.write('_out:\n'
1406 ' return _ret != NULL;\n'
1412 self.c.write('/**\n'
1413 ' * %s_call_%s_sync:\n'
1414 ' * @proxy: A #%sProxy.\n'
1415 %(i.name_lower, m.name_lower, i.camel_name))
1417 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1419 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1420 for a in m.out_args:
1421 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
1423 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
1424 self.c.write(self.docbook_gen.expand(
1425 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1426 ' * @error: Return location for error or %%NULL.\n'
1428 ' * Synchronously invokes the %s.%s() D-Bus method on @proxy. The calling thread is blocked until a reply is received.\n'
1430 ' * See %s_call_%s() for the asynchronous version of this method.\n'
1432 ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
1433 %(i.name, m.name, i.name_lower, m.name_lower), False))
1434 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1435 self.c.write('gboolean\n'
1436 '%s_call_%s_sync (\n'
1437 ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1439 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
1441 self.c.write(',\n GUnixFDList *fd_list')
1442 for a in m.out_args:
1443 self.c.write(',\n %sout_%s'%(a.ctype_out, a.name))
1445 self.c.write(',\n GUnixFDList **out_fd_list')
1447 ' GCancellable *cancellable,\n'
1448 ' GError **error)\n'
1450 ' GVariant *_ret;\n')
1452 self.c.write(' _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy),\n')
1454 self.c.write(' _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),\n')
1455 self.c.write(' "%s",\n'
1456 ' g_variant_new ("('%(m.name))
1458 self.c.write('%s'%(a.format_in))
1461 self.c.write(',\n arg_%s'%(a.name))
1463 ' G_DBUS_CALL_FLAGS_NONE,\n'
1466 self.c.write(' fd_list,\n'
1468 self.c.write(' cancellable,\n'
1470 ' if (_ret == NULL)\n'
1472 self.c.write(' g_variant_get (_ret,\n'
1474 for a in m.out_args:
1475 self.c.write('%s'%(a.format_out))
1477 for a in m.out_args:
1478 self.c.write(',\n out_%s'%(a.name))
1480 ' g_variant_unref (_ret);\n')
1481 self.c.write('_out:\n'
1482 ' return _ret != NULL;\n'
1486 # ---------------------------------------------------------------------------------------------------
1488 def generate_method_completers(self, i):
1491 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1493 self.c.write('/**\n'
1494 ' * %s_complete_%s:\n'
1495 ' * @object: A #%s.\n'
1496 ' * @invocation: (transfer full): A #GDBusMethodInvocation.\n'
1497 %(i.name_lower, m.name_lower, i.camel_name))
1499 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1500 for a in m.out_args:
1501 self.c.write(' * @%s: Parameter to return.\n'%(a.name))
1502 self.c.write(self.docbook_gen.expand(
1504 ' * 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'
1506 ' * This method will free @invocation, you cannot use it afterwards.\n'
1507 %(i.name, m.name), False))
1508 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
1509 self.c.write('void\n'
1510 '%s_complete_%s (\n'
1512 ' GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
1514 self.c.write(',\n GUnixFDList *fd_list')
1515 for a in m.out_args:
1516 self.c.write(',\n %s%s'%(a.ctype_in, a.name))
1521 self.c.write(' g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,\n'
1522 ' g_variant_new ("(')
1524 self.c.write(' g_dbus_method_invocation_return_value (invocation,\n'
1525 ' g_variant_new ("(')
1526 for a in m.out_args:
1527 self.c.write('%s'%(a.format_in))
1529 for a in m.out_args:
1530 self.c.write(',\n %s'%(a.name))
1532 self.c.write('),\n fd_list);\n')
1534 self.c.write('));\n')
1538 # ---------------------------------------------------------------------------------------------------
1540 def generate_proxy(self, i):
1542 self.c.write('/* ------------------------------------------------------------------------ */\n'
1545 self.c.write(self.docbook_gen.expand(
1549 ' * The #%sProxy structure contains only private data and should only be accessed using the provided API.\n'
1550 %(i.camel_name, i.camel_name), False))
1551 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1554 self.c.write(self.docbook_gen.expand(
1556 ' * %sProxyClass:\n'
1557 ' * @parent_class: The parent class.\n'
1559 ' * Class structure for #%sProxy.\n'
1560 %(i.camel_name, i.camel_name), False))
1561 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1564 self.c.write('struct _%sProxyPrivate\n'
1570 self.c.write('static void %s_proxy_iface_init (%sIface *iface);\n'
1571 '\n'%(i.name_lower, i.camel_name))
1572 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1573 self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
1574 self.c.write(' G_ADD_PRIVATE (%sProxy)\n'%(i.camel_name))
1575 self.c.write('#endif\n')
1576 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1579 self.c.write('static void\n'
1580 '%s_proxy_finalize (GObject *object)\n'
1581 '{\n'%(i.name_lower))
1582 self.c.write(' %sProxy *proxy = %s%s_PROXY (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
1583 self.c.write(' g_datalist_clear (&proxy->priv->qdata);\n')
1584 self.c.write(' G_OBJECT_CLASS (%s_proxy_parent_class)->finalize (object);\n'
1586 '\n'%(i.name_lower))
1588 # property accessors
1590 # Note that we are guaranteed that prop_id starts at 1 and is
1591 # laid out in the same order as introspection data pointers
1593 self.c.write('static void\n'
1594 '%s_proxy_get_property (GObject *object,\n'
1597 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
1598 '{\n'%(i.name_lower))
1599 if len(i.properties) > 0:
1600 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1601 ' GVariant *variant;\n'
1602 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1603 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1604 ' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
1605 ' if (info->use_gvariant)\n'
1607 ' g_value_set_variant (value, variant);\n'
1611 # could be that we don't have the value in cache - in that case, we do
1612 # nothing and the user gets the default value for the GType
1613 ' if (variant != NULL)\n'
1614 ' g_dbus_gvariant_to_gvalue (variant, value);\n'
1616 ' if (variant != NULL)\n'
1617 ' g_variant_unref (variant);\n'
1618 %(len(i.properties), i.name_lower))
1621 if len(i.properties) > 0:
1622 self.c.write('static void\n'
1623 '%s_proxy_set_property_cb (GDBusProxy *proxy,\n'
1624 ' GAsyncResult *res,\n'
1625 ' gpointer user_data)\n'
1626 '{\n'%(i.name_lower))
1627 self.c.write(' const _ExtendedGDBusPropertyInfo *info = user_data;\n'
1630 ' if (!g_dbus_proxy_call_finish (proxy, res, &error))\n'
1632 ' g_warning ("Error setting property \'%%s\' on interface %s: %%s (%%s, %%d)",\n'
1633 ' info->parent_struct.name, \n'
1634 ' error->message, g_quark_to_string (error->domain), error->code);\n'
1635 ' g_error_free (error);\n'
1640 self.c.write('static void\n'
1641 '%s_proxy_set_property (GObject *object,\n'
1643 ' const GValue *value,\n'
1644 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
1645 '{\n'%(i.name_lower))
1646 if len(i.properties) > 0:
1647 self.c.write(' const _ExtendedGDBusPropertyInfo *info;\n'
1648 ' GVariant *variant;\n'
1649 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1650 ' info = _%s_property_info_pointers[prop_id - 1];\n'
1651 ' variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
1652 ' g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
1653 ' "org.freedesktop.DBus.Properties.Set",\n'
1654 ' g_variant_new ("(ssv)", "%s", info->parent_struct.name, variant),\n'
1655 ' G_DBUS_CALL_FLAGS_NONE,\n'
1657 ' NULL, (GAsyncReadyCallback) %s_proxy_set_property_cb, (GDBusPropertyInfo *) &info->parent_struct);\n'
1658 ' g_variant_unref (variant);\n'
1659 %(len(i.properties), i.name_lower, i.name, i.name_lower))
1664 self.c.write('static void\n'
1665 '%s_proxy_g_signal (GDBusProxy *proxy,\n'
1666 ' const gchar *sender_name G_GNUC_UNUSED,\n'
1667 ' const gchar *signal_name,\n'
1668 ' GVariant *parameters)\n'
1669 '{\n'%(i.name_lower))
1670 self.c.write(' _ExtendedGDBusSignalInfo *info;\n'
1671 ' GVariantIter iter;\n'
1672 ' GVariant *child;\n'
1673 ' GValue *paramv;\n'
1674 ' guint num_params;\n'
1676 ' guint signal_id;\n');
1677 # Note: info could be NULL if we are talking to a newer version of the interface
1678 self.c.write(' info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, signal_name);\n'
1679 ' if (info == NULL)\n'
1682 self.c.write (' num_params = g_variant_n_children (parameters);\n'
1683 ' paramv = g_new0 (GValue, num_params + 1);\n'
1684 ' g_value_init (¶mv[0], %sTYPE_%s);\n'
1685 ' g_value_set_object (¶mv[0], proxy);\n'
1686 %(i.ns_upper, i.name_upper))
1687 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
1689 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
1691 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1];\n'
1692 ' if (arg_info->use_gvariant)\n'
1694 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
1695 ' g_value_set_variant (¶mv[n], child);\n'
1699 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
1700 ' g_variant_unref (child);\n'
1703 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
1704 %(i.ns_upper, i.name_upper))
1705 self.c.write(' g_signal_emitv (paramv, signal_id, 0, NULL);\n')
1706 self.c.write(' for (n = 0; n < num_params + 1; n++)\n'
1707 ' g_value_unset (¶mv[n]);\n'
1708 ' g_free (paramv);\n')
1713 self.c.write('static void\n'
1714 '%s_proxy_g_properties_changed (GDBusProxy *_proxy,\n'
1715 ' GVariant *changed_properties,\n'
1716 ' const gchar *const *invalidated_properties)\n'
1717 '{\n'%(i.name_lower))
1718 # Note: info could be NULL if we are talking to a newer version of the interface
1719 self.c.write(' %sProxy *proxy = %s%s_PROXY (_proxy);\n'
1721 ' const gchar *key;\n'
1722 ' GVariantIter *iter;\n'
1723 ' _ExtendedGDBusPropertyInfo *info;\n'
1724 ' g_variant_get (changed_properties, "a{sv}", &iter);\n'
1725 ' while (g_variant_iter_next (iter, "{&sv}", &key, NULL))\n'
1727 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, key);\n'
1728 ' g_datalist_remove_data (&proxy->priv->qdata, key);\n'
1729 ' if (info != NULL)\n'
1730 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1732 ' g_variant_iter_free (iter);\n'
1733 ' for (n = 0; invalidated_properties[n] != NULL; n++)\n'
1735 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, invalidated_properties[n]);\n'
1736 ' g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]);\n'
1737 ' if (info != NULL)\n'
1738 ' g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1742 %(i.camel_name, i.ns_upper, i.name_upper,
1743 i.name_lower, i.name_lower))
1746 for p in i.properties:
1748 if p.arg.free_func != None:
1750 self.c.write('static %s\n'
1751 '%s_proxy_get_%s (%s *object)\n'
1753 ' %sProxy *proxy = %s%s_PROXY (object);\n'
1754 ' GVariant *variant;\n'
1755 ' %svalue = %s;\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name,
1756 i.camel_name, i.ns_upper, i.name_upper,
1757 p.arg.ctype_in, nul_value))
1758 # For some property types, we have to free the returned
1759 # value (or part of it, e.g. the container) because of how
1760 # GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
1763 free_container = False;
1764 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':
1765 free_container = True;
1766 # If already using an old value for strv, objpathv, bytestring_array (see below),
1767 # then just return that... that way the result from multiple consecutive calls
1768 # to the getter are valid as long as they're freed
1771 self.c.write(' value = g_datalist_get_data (&proxy->priv->qdata, \"%s\");\n'
1772 ' if (value != NULL)\n'
1775 self.c.write(' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \"%s\");\n'%(p.name))
1776 if p.arg.gtype == 'G_TYPE_VARIANT':
1777 self.c.write(' value = variant;\n')
1778 self.c.write(' if (variant != NULL)\n')
1779 self.c.write(' g_variant_unref (variant);\n')
1781 self.c.write(' if (variant != NULL)\n'
1784 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':
1785 extra_len = ', NULL'
1786 self.c.write(' value = %s (variant%s);\n'%(p.arg.gvariant_get, extra_len))
1788 self.c.write(' g_datalist_set_data_full (&proxy->priv->qdata, \"%s\", (gpointer) value, g_free);\n'
1790 self.c.write(' g_variant_unref (variant);\n')
1791 self.c.write(' }\n')
1792 self.c.write(' return value;\n')
1797 self.c.write('static void\n'
1798 '%s_proxy_init (%sProxy *proxy)\n'
1800 '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
1801 ' proxy->priv = %s_proxy_get_instance_private (proxy);\n'
1803 ' proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %sTYPE_%s_PROXY, %sProxyPrivate);\n'
1805 ' g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
1808 %(i.name_lower, i.camel_name,
1810 i.ns_upper, i.name_upper, i.camel_name,
1812 self.c.write('static void\n'
1813 '%s_proxy_class_init (%sProxyClass *klass)\n'
1815 ' GObjectClass *gobject_class;\n'
1816 ' GDBusProxyClass *proxy_class;\n'
1818 ' gobject_class = G_OBJECT_CLASS (klass);\n'
1819 ' gobject_class->finalize = %s_proxy_finalize;\n'
1820 ' gobject_class->get_property = %s_proxy_get_property;\n'
1821 ' gobject_class->set_property = %s_proxy_set_property;\n'
1823 ' proxy_class = G_DBUS_PROXY_CLASS (klass);\n'
1824 ' proxy_class->g_signal = %s_proxy_g_signal;\n'
1825 ' proxy_class->g_properties_changed = %s_proxy_g_properties_changed;\n'
1826 '\n'%(i.name_lower, i.camel_name,
1827 i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
1828 if len(i.properties) > 0:
1829 self.c.write(' %s_override_properties (gobject_class, 1);\n\n'%(i.name_lower))
1830 self.c.write('#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
1831 ' g_type_class_add_private (klass, sizeof (%sProxyPrivate));\n'
1832 '#endif\n'%(i.camel_name))
1836 self.c.write('static void\n'
1837 '%s_proxy_iface_init (%sIface *iface)\n'
1838 '{\n'%(i.name_lower, i.camel_name))
1839 for p in i.properties:
1840 self.c.write(' iface->get_%s = %s_proxy_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
1845 self.c.write(self.docbook_gen.expand(
1847 ' * %s_proxy_new:\n'
1848 ' * @connection: A #GDBusConnection.\n'
1849 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1850 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1851 ' * @object_path: An object path.\n'
1852 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1853 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1854 ' * @user_data: User data to pass to @callback.\n'
1856 ' * Asynchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new() for more details.\n'
1858 ' * 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'
1859 ' * You can then call %s_proxy_new_finish() to get the result of the operation.\n'
1861 ' * See %s_proxy_new_sync() for the synchronous, blocking version of this constructor.\n'
1862 %(i.name_lower, i.name, i.name_lower, i.name_lower), False))
1863 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1864 self.c.write('void\n'
1866 ' GDBusConnection *connection,\n'
1867 ' GDBusProxyFlags flags,\n'
1868 ' const gchar *name,\n'
1869 ' const gchar *object_path,\n'
1870 ' GCancellable *cancellable,\n'
1871 ' GAsyncReadyCallback callback,\n'
1872 ' gpointer user_data)\n'
1874 ' 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'
1877 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1878 self.c.write('/**\n'
1879 ' * %s_proxy_new_finish:\n'
1880 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new().\n'
1881 ' * @error: Return location for error or %%NULL\n'
1883 ' * Finishes an operation started with %s_proxy_new().\n'
1885 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1886 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1887 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1888 self.c.write('%s *\n'
1889 '%s_proxy_new_finish (\n'
1890 ' GAsyncResult *res,\n'
1891 ' GError **error)\n'
1894 ' GObject *source_object;\n'
1895 ' source_object = g_async_result_get_source_object (res);\n'
1896 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1897 ' g_object_unref (source_object);\n'
1898 ' if (ret != NULL)\n'
1899 ' return %s%s (ret);\n'
1904 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1905 self.c.write(self.docbook_gen.expand(
1907 ' * %s_proxy_new_sync:\n'
1908 ' * @connection: A #GDBusConnection.\n'
1909 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1910 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1911 ' * @object_path: An object path.\n'
1912 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1913 ' * @error: Return location for error or %%NULL\n'
1915 ' * Synchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new_sync() for more details.\n'
1917 ' * The calling thread is blocked until a reply is received.\n'
1919 ' * See %s_proxy_new() for the asynchronous version of this constructor.\n'
1921 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1922 %(i.name_lower, i.name, i.name_lower, i.camel_name), False))
1923 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1924 self.c.write('%s *\n'
1925 '%s_proxy_new_sync (\n'
1926 ' GDBusConnection *connection,\n'
1927 ' GDBusProxyFlags flags,\n'
1928 ' const gchar *name,\n'
1929 ' const gchar *object_path,\n'
1930 ' GCancellable *cancellable,\n'
1931 ' GError **error)\n'
1933 ' GInitable *ret;\n'
1934 ' 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'
1935 ' if (ret != NULL)\n'
1936 ' return %s%s (ret);\n'
1941 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
1943 self.c.write(self.docbook_gen.expand(
1945 ' * %s_proxy_new_for_bus:\n'
1946 ' * @bus_type: A #GBusType.\n'
1947 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1948 ' * @name: A bus name (well-known or unique).\n'
1949 ' * @object_path: An object path.\n'
1950 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1951 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1952 ' * @user_data: User data to pass to @callback.\n'
1954 ' * Like %s_proxy_new() but takes a #GBusType instead of a #GDBusConnection.\n'
1956 ' * 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'
1957 ' * You can then call %s_proxy_new_for_bus_finish() to get the result of the operation.\n'
1959 ' * See %s_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
1960 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower), False))
1961 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1962 self.c.write('void\n'
1963 '%s_proxy_new_for_bus (\n'
1964 ' GBusType bus_type,\n'
1965 ' GDBusProxyFlags flags,\n'
1966 ' const gchar *name,\n'
1967 ' const gchar *object_path,\n'
1968 ' GCancellable *cancellable,\n'
1969 ' GAsyncReadyCallback callback,\n'
1970 ' gpointer user_data)\n'
1972 ' 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'
1975 %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1976 self.c.write('/**\n'
1977 ' * %s_proxy_new_for_bus_finish:\n'
1978 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new_for_bus().\n'
1979 ' * @error: Return location for error or %%NULL\n'
1981 ' * Finishes an operation started with %s_proxy_new_for_bus().\n'
1983 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1984 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1985 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1986 self.c.write('%s *\n'
1987 '%s_proxy_new_for_bus_finish (\n'
1988 ' GAsyncResult *res,\n'
1989 ' GError **error)\n'
1992 ' GObject *source_object;\n'
1993 ' source_object = g_async_result_get_source_object (res);\n'
1994 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1995 ' g_object_unref (source_object);\n'
1996 ' if (ret != NULL)\n'
1997 ' return %s%s (ret);\n'
2002 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
2003 self.c.write(self.docbook_gen.expand(
2005 ' * %s_proxy_new_for_bus_sync:\n'
2006 ' * @bus_type: A #GBusType.\n'
2007 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
2008 ' * @name: A bus name (well-known or unique).\n'
2009 ' * @object_path: An object path.\n'
2010 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
2011 ' * @error: Return location for error or %%NULL\n'
2013 ' * Like %s_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
2015 ' * The calling thread is blocked until a reply is received.\n'
2017 ' * See %s_proxy_new_for_bus() for the asynchronous version of this constructor.\n'
2019 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2020 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name), False))
2021 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2022 self.c.write('%s *\n'
2023 '%s_proxy_new_for_bus_sync (\n'
2024 ' GBusType bus_type,\n'
2025 ' GDBusProxyFlags flags,\n'
2026 ' const gchar *name,\n'
2027 ' const gchar *object_path,\n'
2028 ' GCancellable *cancellable,\n'
2029 ' GError **error)\n'
2031 ' GInitable *ret;\n'
2032 ' 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'
2033 ' if (ret != NULL)\n'
2034 ' return %s%s (ret);\n'
2039 %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
2042 # ---------------------------------------------------------------------------------------------------
2044 def generate_skeleton(self, i):
2046 self.c.write('/* ------------------------------------------------------------------------ */\n'
2049 self.c.write(self.docbook_gen.expand(
2053 ' * The #%sSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2054 %(i.camel_name, i.camel_name), False))
2055 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2058 self.c.write(self.docbook_gen.expand(
2060 ' * %sSkeletonClass:\n'
2061 ' * @parent_class: The parent class.\n'
2063 ' * Class structure for #%sSkeleton.\n'
2064 %(i.camel_name, i.camel_name), False))
2065 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2068 self.c.write('struct _%sSkeletonPrivate\n'
2070 ' GValue *properties;\n'
2071 ' GList *changed_properties;\n'
2072 ' GSource *changed_properties_idle_source;\n'
2073 ' GMainContext *context;\n'
2078 self.c.write('static void\n'
2079 '_%s_skeleton_handle_method_call (\n'
2080 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2081 ' const gchar *sender G_GNUC_UNUSED,\n'
2082 ' const gchar *object_path G_GNUC_UNUSED,\n'
2083 ' const gchar *interface_name,\n'
2084 ' const gchar *method_name,\n'
2085 ' GVariant *parameters,\n'
2086 ' GDBusMethodInvocation *invocation,\n'
2087 ' gpointer user_data)\n'
2089 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2090 ' _ExtendedGDBusMethodInfo *info;\n'
2091 ' GVariantIter iter;\n'
2092 ' GVariant *child;\n'
2093 ' GValue *paramv;\n'
2094 ' guint num_params;\n'
2095 ' guint num_extra;\n'
2097 ' guint signal_id;\n'
2098 ' GValue return_value = G_VALUE_INIT;\n'
2099 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2100 self.c.write(' info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n'
2101 ' g_assert (info != NULL);\n'
2103 self.c.write (' num_params = g_variant_n_children (parameters);\n'
2104 ' num_extra = info->pass_fdlist ? 3 : 2;'
2105 ' paramv = g_new0 (GValue, num_params + num_extra);\n'
2107 ' g_value_init (¶mv[n], %sTYPE_%s);\n'
2108 ' g_value_set_object (¶mv[n++], skeleton);\n'
2109 ' g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION);\n'
2110 ' g_value_set_object (¶mv[n++], invocation);\n'
2111 ' if (info->pass_fdlist)\n'
2113 '#ifdef G_OS_UNIX\n'
2114 ' g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST);\n'
2115 ' g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)));\n'
2117 ' g_assert_not_reached ();\n'
2120 %(i.ns_upper, i.name_upper))
2121 self.c.write(' g_variant_iter_init (&iter, parameters);\n'
2122 ' while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
2124 ' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra];\n'
2125 ' if (arg_info->use_gvariant)\n'
2127 ' g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
2128 ' g_value_set_variant (¶mv[n], child);\n'
2132 ' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
2133 ' g_variant_unref (child);\n'
2136 self.c.write(' signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
2137 %(i.ns_upper, i.name_upper))
2138 self.c.write(' g_value_init (&return_value, G_TYPE_BOOLEAN);\n'
2139 ' g_signal_emitv (paramv, signal_id, 0, &return_value);\n'
2140 ' if (!g_value_get_boolean (&return_value))\n'
2141 ' 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'
2142 ' g_value_unset (&return_value);\n'
2144 self.c.write(' for (n = 0; n < num_params + num_extra; n++)\n'
2145 ' g_value_unset (¶mv[n]);\n'
2146 ' g_free (paramv);\n')
2150 self.c.write('static GVariant *\n'
2151 '_%s_skeleton_handle_get_property (\n'
2152 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2153 ' const gchar *sender G_GNUC_UNUSED,\n'
2154 ' const gchar *object_path G_GNUC_UNUSED,\n'
2155 ' const gchar *interface_name G_GNUC_UNUSED,\n'
2156 ' const gchar *property_name,\n'
2157 ' GError **error,\n'
2158 ' gpointer user_data)\n'
2160 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2161 ' GValue value = G_VALUE_INIT;\n'
2162 ' GParamSpec *pspec;\n'
2163 ' _ExtendedGDBusPropertyInfo *info;\n'
2165 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2166 self.c.write(' ret = NULL;\n'
2167 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2168 ' g_assert (info != NULL);\n'
2169 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2170 ' if (pspec == NULL)\n'
2172 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2176 ' g_value_init (&value, pspec->value_type);\n'
2177 ' g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2178 ' ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
2179 ' g_value_unset (&value);\n'
2186 self.c.write('static gboolean\n'
2187 '_%s_skeleton_handle_set_property (\n'
2188 ' GDBusConnection *connection G_GNUC_UNUSED,\n'
2189 ' const gchar *sender G_GNUC_UNUSED,\n'
2190 ' const gchar *object_path G_GNUC_UNUSED,\n'
2191 ' const gchar *interface_name G_GNUC_UNUSED,\n'
2192 ' const gchar *property_name,\n'
2193 ' GVariant *variant,\n'
2194 ' GError **error,\n'
2195 ' gpointer user_data)\n'
2197 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2198 ' GValue value = G_VALUE_INIT;\n'
2199 ' GParamSpec *pspec;\n'
2200 ' _ExtendedGDBusPropertyInfo *info;\n'
2202 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2203 self.c.write(' ret = FALSE;\n'
2204 ' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2205 ' g_assert (info != NULL);\n'
2206 ' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2207 ' if (pspec == NULL)\n'
2209 ' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2213 ' if (info->use_gvariant)\n'
2214 ' g_value_set_variant (&value, variant);\n'
2216 ' g_dbus_gvariant_to_gvalue (variant, &value);\n'
2217 ' g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2218 ' g_value_unset (&value);\n'
2227 self.c.write('static const GDBusInterfaceVTable _%s_skeleton_vtable =\n'
2229 ' _%s_skeleton_handle_method_call,\n'
2230 ' _%s_skeleton_handle_get_property,\n'
2231 ' _%s_skeleton_handle_set_property,\n'
2234 '\n'%(i.name_lower, i.name_lower, i.name_lower, i.name_lower))
2236 self.c.write('static GDBusInterfaceInfo *\n'
2237 '%s_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2239 ' return %s_interface_info ();\n'
2240 %(i.name_lower, i.name_lower))
2244 self.c.write('static GDBusInterfaceVTable *\n'
2245 '%s_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2247 ' return (GDBusInterfaceVTable *) &_%s_skeleton_vtable;\n'
2248 %(i.name_lower, i.name_lower))
2252 self.c.write('static GVariant *\n'
2253 '%s_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton)\n'
2255 ' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2256 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2258 ' GVariantBuilder builder;\n'
2260 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2261 ' if (_%s_interface_info.parent_struct.properties == NULL)\n'
2263 ' for (n = 0; _%s_interface_info.parent_struct.properties[n] != NULL; n++)\n'
2265 ' GDBusPropertyInfo *info = _%s_interface_info.parent_struct.properties[n];\n'
2266 ' if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)\n'
2268 ' GVariant *value;\n'
2269 ' 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'
2270 ' if (value != NULL)\n'
2272 ' g_variant_take_ref (value);\n'
2273 ' g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
2274 ' g_variant_unref (value);\n'
2279 ' return g_variant_builder_end (&builder);\n'
2282 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name))
2284 if len(i.properties) > 0:
2285 self.c.write('static gboolean _%s_emit_changed (gpointer user_data);\n'
2289 self.c.write('static void\n'
2290 '%s_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton)\n'
2293 if len(i.properties) > 0:
2294 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2295 ' gboolean emit_changed = FALSE;\n'
2297 ' g_mutex_lock (&skeleton->priv->lock);\n'
2298 ' if (skeleton->priv->changed_properties_idle_source != NULL)\n'
2300 ' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
2301 ' skeleton->priv->changed_properties_idle_source = NULL;\n'
2302 ' emit_changed = TRUE;\n'
2304 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2306 ' if (emit_changed)\n'
2307 ' _%s_emit_changed (skeleton);\n'
2308 %(i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2313 self.c.write('static void\n'
2314 '_%s_on_signal_%s (\n'
2315 ' %s *object'%(i.name_lower, s.name_lower, i.camel_name))
2317 self.c.write(',\n %sarg_%s'%(a.ctype_in, a.name))
2320 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n\n'
2321 ' GList *connections, *l;\n'
2322 ' GVariant *signal_variant;\n'
2323 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2324 %(i.camel_name, i.ns_upper, i.name_upper))
2326 ' signal_variant = g_variant_ref_sink (g_variant_new ("(')
2328 self.c.write('%s'%(a.format_in))
2331 self.c.write(',\n arg_%s'%(a.name))
2332 self.c.write('));\n')
2334 self.c.write(' for (l = connections; l != NULL; l = l->next)\n'
2336 ' GDBusConnection *connection = l->data;\n'
2337 ' g_dbus_connection_emit_signal (connection,\n'
2338 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", "%s",\n'
2339 ' signal_variant, NULL);\n'
2342 self.c.write(' g_variant_unref (signal_variant);\n')
2343 self.c.write(' g_list_free_full (connections, g_object_unref);\n')
2347 self.c.write('static void %s_skeleton_iface_init (%sIface *iface);\n'
2348 %(i.name_lower, i.camel_name))
2350 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2351 self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
2352 self.c.write(' G_ADD_PRIVATE (%sSkeleton)\n'%(i.camel_name))
2353 self.c.write('#endif\n')
2354 self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2357 self.c.write('static void\n'
2358 '%s_skeleton_finalize (GObject *object)\n'
2359 '{\n'%(i.name_lower))
2360 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2361 if len(i.properties) > 0:
2362 self.c.write(' guint n;\n'
2363 ' for (n = 0; n < %d; n++)\n'
2364 ' g_value_unset (&skeleton->priv->properties[n]);\n'%(len(i.properties)))
2365 self.c.write(' g_free (skeleton->priv->properties);\n')
2366 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2367 self.c.write(' if (skeleton->priv->changed_properties_idle_source != NULL)\n')
2368 self.c.write(' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
2369 self.c.write(' g_main_context_unref (skeleton->priv->context);\n')
2370 self.c.write(' g_mutex_clear (&skeleton->priv->lock);\n')
2371 self.c.write(' G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
2373 '\n'%(i.name_lower))
2375 # property accessors (TODO: generate PropertiesChanged signals in setter)
2376 if len(i.properties) > 0:
2377 self.c.write('static void\n'
2378 '%s_skeleton_get_property (GObject *object,\n'
2381 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
2382 '{\n'%(i.name_lower))
2383 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2384 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2385 ' g_mutex_lock (&skeleton->priv->lock);\n'
2386 ' g_value_copy (&skeleton->priv->properties[prop_id - 1], value);\n'
2387 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2388 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
2392 # if property is already scheduled then re-use entry.. though it could be
2395 # foo_set_prop_bar (object, "");
2396 # foo_set_prop_bar (object, "blah");
2398 # say, every update... In this case, where nothing happens, we obviously
2399 # don't want a PropertiesChanged() event. We can easily check for this
2400 # by comparing against the _original value_ recorded before the first
2401 # change event. If the latest value is not different from the original
2402 # one, we can simply ignore the ChangedProperty
2404 self.c.write('static gboolean\n'
2405 '_%s_emit_changed (gpointer user_data)\n'
2407 ' %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2408 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2409 self.c.write(' GList *l;\n'
2410 ' GVariantBuilder builder;\n'
2411 ' GVariantBuilder invalidated_builder;\n'
2412 ' guint num_changes;\n'
2414 ' g_mutex_lock (&skeleton->priv->lock);\n'
2415 ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2416 ' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
2417 ' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
2419 ' ChangedProperty *cp = l->data;\n'
2420 ' GVariant *variant;\n'
2421 ' const GValue *cur_value;\n'
2423 ' cur_value = &skeleton->priv->properties[cp->prop_id - 1];\n'
2424 ' if (!_g_value_equal (cur_value, &cp->orig_value))\n'
2426 ' variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature));\n'
2427 ' g_variant_builder_add (&builder, "{sv}", cp->info->parent_struct.name, variant);\n'
2428 ' g_variant_unref (variant);\n'
2432 ' if (num_changes > 0)\n'
2434 ' GList *connections, *ll;\n'
2435 ' GVariant *signal_variant;'
2437 ' signal_variant = g_variant_ref_sink (g_variant_new ("(sa{sv}as)", "%s",\n'
2438 ' &builder, &invalidated_builder));\n'
2439 ' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2440 ' for (ll = connections; ll != NULL; ll = ll->next)\n'
2442 ' GDBusConnection *connection = ll->data;\n'
2444 ' g_dbus_connection_emit_signal (connection,\n'
2445 ' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2446 ' "org.freedesktop.DBus.Properties",\n'
2447 ' "PropertiesChanged",\n'
2448 ' signal_variant,\n'
2451 ' g_variant_unref (signal_variant);\n'
2452 ' g_list_free_full (connections, g_object_unref);\n'
2456 ' g_variant_builder_clear (&builder);\n'
2457 ' g_variant_builder_clear (&invalidated_builder);\n'
2460 self.c.write(' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2461 self.c.write(' skeleton->priv->changed_properties = NULL;\n')
2462 self.c.write(' skeleton->priv->changed_properties_idle_source = NULL;\n')
2463 self.c.write(' g_mutex_unlock (&skeleton->priv->lock);\n')
2464 self.c.write(' return FALSE;\n'
2467 # holding lock while being called
2468 self.c.write('static void\n'
2469 '_%s_schedule_emit_changed (%sSkeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value)\n'
2471 ' ChangedProperty *cp;\n'
2474 ' for (l = skeleton->priv->changed_properties; l != NULL; l = l->next)\n'
2476 ' ChangedProperty *i_cp = l->data;\n'
2477 ' if (i_cp->info == info)\n'
2483 %(i.name_lower, i.camel_name))
2484 self.c.write(' if (cp == NULL)\n'
2486 ' cp = g_new0 (ChangedProperty, 1);\n'
2487 ' cp->prop_id = prop_id;\n'
2488 ' cp->info = info;\n'
2489 ' skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp);\n'
2490 ' g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value));\n'
2491 ' g_value_copy (orig_value, &cp->orig_value);\n'
2497 # Postpone setting up the refresh source until the ::notify signal is emitted as
2498 # this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
2499 # This is useful when updating several properties from another thread than
2500 # where the idle will be emitted from
2501 self.c.write('static void\n'
2502 '%s_skeleton_notify (GObject *object,\n'
2503 ' GParamSpec *pspec G_GNUC_UNUSED)\n'
2505 ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2506 ' g_mutex_lock (&skeleton->priv->lock);\n'
2507 ' if (skeleton->priv->changed_properties != NULL &&\n'
2508 ' skeleton->priv->changed_properties_idle_source == NULL)\n'
2510 ' skeleton->priv->changed_properties_idle_source = g_idle_source_new ();\n'
2511 ' g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);\n'
2512 ' g_source_set_callback (skeleton->priv->changed_properties_idle_source, _%s_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);\n'
2513 ' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
2514 ' g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
2516 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2519 %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2521 self.c.write('static void\n'
2522 '%s_skeleton_set_property (GObject *object,\n'
2524 ' const GValue *value,\n'
2525 ' GParamSpec *pspec)\n'
2526 '{\n'%(i.name_lower))
2527 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2528 ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2529 ' g_mutex_lock (&skeleton->priv->lock);\n'
2530 ' g_object_freeze_notify (object);\n'
2531 ' if (!_g_value_equal (value, &skeleton->priv->properties[prop_id - 1]))\n'
2533 ' if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
2534 ' _%s_schedule_emit_changed (skeleton, _%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties[prop_id - 1]);\n'
2535 ' g_value_copy (value, &skeleton->priv->properties[prop_id - 1]);\n'
2536 ' g_object_notify_by_pspec (object, pspec);\n'
2538 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2539 ' g_object_thaw_notify (object);\n'
2540 %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
2544 self.c.write('static void\n'
2545 '%s_skeleton_init (%sSkeleton *skeleton)\n'
2547 '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
2548 ' skeleton->priv = %s_skeleton_get_instance_private (skeleton);\n'
2550 ' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
2552 %(i.name_lower, i.camel_name,
2554 i.ns_upper, i.name_upper, i.camel_name))
2555 self.c.write(' g_mutex_init (&skeleton->priv->lock);\n')
2556 self.c.write(' skeleton->priv->context = g_main_context_ref_thread_default ();\n')
2557 if len(i.properties) > 0:
2558 self.c.write(' skeleton->priv->properties = g_new0 (GValue, %d);\n'%(len(i.properties)))
2560 for p in i.properties:
2561 self.c.write(' g_value_init (&skeleton->priv->properties[%d], %s);\n'%(n, p.arg.gtype))
2568 for p in i.properties:
2569 self.c.write('static %s\n'
2570 '%s_skeleton_get_%s (%s *object)\n'
2572 %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
2573 self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2574 self.c.write(' %svalue;\n'
2575 ' g_mutex_lock (&skeleton->priv->lock);\n'
2576 ' value = %s (&(skeleton->priv->properties[%d]));\n'
2577 ' g_mutex_unlock (&skeleton->priv->lock);\n'
2578 %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
2579 self.c.write(' return value;\n')
2584 self.c.write('static void\n'
2585 '%s_skeleton_class_init (%sSkeletonClass *klass)\n'
2587 ' GObjectClass *gobject_class;\n'
2588 ' GDBusInterfaceSkeletonClass *skeleton_class;\n'
2590 ' gobject_class = G_OBJECT_CLASS (klass);\n'
2591 ' gobject_class->finalize = %s_skeleton_finalize;\n'
2592 %(i.name_lower, i.camel_name, i.name_lower))
2593 if len(i.properties) > 0:
2594 self.c.write(' gobject_class->get_property = %s_skeleton_get_property;\n'
2595 ' gobject_class->set_property = %s_skeleton_set_property;\n'
2596 ' gobject_class->notify = %s_skeleton_notify;\n'
2597 '\n'%(i.name_lower, i.name_lower, i.name_lower))
2599 ' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
2601 ' skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);\n');
2602 self.c.write(' skeleton_class->get_info = %s_skeleton_dbus_interface_get_info;\n'%(i.name_lower))
2603 self.c.write(' skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
2604 self.c.write(' skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
2605 self.c.write(' skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
2608 '#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
2609 ' g_type_class_add_private (klass, sizeof (%sSkeletonPrivate));\n'
2610 '#endif\n'%(i.camel_name))
2615 self.c.write('static void\n'
2616 '%s_skeleton_iface_init (%sIface *iface)\n'
2618 %(i.name_lower, i.camel_name))
2620 self.c.write(' iface->%s = _%s_on_signal_%s;\n'
2621 %(s.name_lower, i.name_lower, s.name_lower))
2622 for p in i.properties:
2623 self.c.write(' iface->get_%s = %s_skeleton_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
2628 self.c.write(self.docbook_gen.expand(
2630 ' * %s_skeleton_new:\n'
2632 ' * Creates a skeleton object for the D-Bus interface #%s.\n'
2634 ' * Returns: (transfer full) (type %sSkeleton): The skeleton object.\n'
2635 %(i.name_lower, i.name, i.camel_name), False))
2636 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2637 self.c.write('%s *\n'
2638 '%s_skeleton_new (void)\n'
2640 ' return %s%s (g_object_new (%sTYPE_%s_SKELETON, NULL));\n'
2642 '\n'%(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
2644 # ---------------------------------------------------------------------------------------------------
2646 def generate_object(self):
2647 self.c.write('/* ------------------------------------------------------------------------\n'
2648 ' * Code for Object, ObjectProxy and ObjectSkeleton\n'
2649 ' * ------------------------------------------------------------------------\n'
2653 self.c.write(self.docbook_gen.expand(
2655 ' * SECTION:%sObject\n'
2656 ' * @title: %sObject\n'
2657 ' * @short_description: Specialized GDBusObject types\n'
2659 ' * 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'
2661 %(self.namespace, self.namespace, self.namespace, self.namespace, self.namespace), False))
2664 self.c.write(self.docbook_gen.expand(
2668 ' * The #%sObject type is a specialized container of interfaces.\n'
2670 %(self.namespace, self.namespace), False))
2673 self.c.write(self.docbook_gen.expand(
2675 ' * %sObjectIface:\n'
2676 ' * @parent_iface: The parent interface.\n'
2678 ' * Virtual table for the #%sObject interface.\n'
2680 %(self.namespace, self.namespace), False))
2683 self.c.write('typedef %sObjectIface %sObjectInterface;\n'%(self.namespace, self.namespace))
2684 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))
2686 self.c.write('static void\n'
2687 '%sobject_default_init (%sObjectIface *iface)\n'
2689 %(self.ns_lower, self.namespace));
2690 for i in self.ifaces:
2691 self.c.write(self.docbook_gen.expand(
2695 ' * The #%s instance corresponding to the D-Bus interface #%s, if any.\n'
2697 ' * Connect to the #GObject::notify signal to get informed of property changes.\n'
2698 %(self.namespace, i.name_hyphen, i.camel_name, i.name), False))
2699 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 2)
2700 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'
2702 %(i.name_hyphen, i.name_hyphen, i.name_hyphen, self.ns_upper, i.name_upper))
2706 for i in self.ifaces:
2707 self.c.write(self.docbook_gen.expand(
2709 ' * %sobject_get_%s:\n'
2710 ' * @object: A #%sObject.\n'
2712 ' * Gets the #%s instance for the D-Bus interface #%s on @object, if any.\n'
2714 ' * Returns: (transfer full): A #%s that must be freed with g_object_unref() or %%NULL if @object does not implement the interface.\n'
2715 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.name, i.camel_name), False))
2716 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2717 self.c.write ('%s *%sobject_get_%s (%sObject *object)\n'
2718 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2720 ' GDBusInterface *ret;\n'
2721 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2722 ' if (ret == NULL)\n'
2724 ' return %s%s (ret);\n'
2727 %(i.name, self.ns_upper, i.name_upper))
2729 for i in self.ifaces:
2730 self.c.write(self.docbook_gen.expand(
2732 ' * %sobject_peek_%s: (skip)\n'
2733 ' * @object: A #%sObject.\n'
2735 ' * Like %sobject_get_%s() but doesn\'t increase the reference count on the returned object.\n'
2737 ' * <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'
2739 ' * 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'
2740 %(self.ns_lower, i.name_upper.lower(), self.namespace, self.ns_lower, i.name_upper.lower(), i.camel_name), False))
2741 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2742 self.c.write ('%s *%sobject_peek_%s (%sObject *object)\n'
2743 %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2745 ' GDBusInterface *ret;\n'
2746 ' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2747 ' if (ret == NULL)\n'
2749 ' g_object_unref (ret);\n'
2750 ' return %s%s (ret);\n'
2753 %(i.name, self.ns_upper, i.name_upper))
2755 # shared by ObjectProxy and ObjectSkeleton classes
2756 self.c.write('static void\n'
2757 '%sobject_notify (GDBusObject *object, GDBusInterface *interface)\n'
2759 ' g_object_notify (G_OBJECT (object), ((_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface))->hyphen_name);\n'
2764 self.c.write(self.docbook_gen.expand(
2766 ' * %sObjectProxy:\n'
2768 ' * The #%sObjectProxy structure contains only private data and should only be accessed using the provided API.\n'
2769 %(self.namespace, self.namespace), False))
2770 self.c.write(' */\n')
2772 self.c.write(self.docbook_gen.expand(
2774 ' * %sObjectProxyClass:\n'
2775 ' * @parent_class: The parent class.\n'
2777 ' * Class structure for #%sObjectProxy.\n'
2778 %(self.namespace, self.namespace), False))
2779 self.c.write(' */\n')
2782 self.c.write('static void\n'
2783 '%sobject_proxy__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2787 %(self.ns_lower, self.ns_lower, self.namespace))
2788 self.c.write('static void\n'
2789 '%sobject_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2791 ' iface->interface_added = %sobject_notify;\n'
2792 ' iface->interface_removed = %sobject_notify;\n'
2795 %(self.ns_lower, self.ns_lower, self.ns_lower))
2797 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectProxy, %sobject_proxy, G_TYPE_DBUS_OBJECT_PROXY,\n'
2798 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_proxy__%sobject_iface_init)\n'
2799 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_proxy__g_dbus_object_iface_init));\n'
2801 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2803 self.c.write('static void\n'
2804 '%sobject_proxy_init (%sObjectProxy *object G_GNUC_UNUSED)\n'
2807 '\n'%(self.ns_lower, self.namespace))
2808 self.c.write('static void\n'
2809 '%sobject_proxy_set_property (GObject *gobject,\n'
2811 ' const GValue *value G_GNUC_UNUSED,\n'
2812 ' GParamSpec *pspec)\n'
2814 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2818 self.c.write('static void\n'
2819 '%sobject_proxy_get_property (GObject *gobject,\n'
2822 ' GParamSpec *pspec)\n'
2824 ' %sObjectProxy *object = %sOBJECT_PROXY (gobject);\n'
2825 ' GDBusInterface *interface;\n'
2827 ' switch (prop_id)\n'
2829 %(self.ns_lower, self.namespace, self.ns_upper))
2831 for i in self.ifaces:
2832 self.c.write(' case %d:\n'
2833 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2834 ' g_value_take_object (value, interface);\n'
2839 self.c.write(' default:\n'
2840 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2845 self.c.write('static void\n'
2846 '%sobject_proxy_class_init (%sObjectProxyClass *klass)\n'
2848 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2850 ' gobject_class->set_property = %sobject_proxy_set_property;\n'
2851 ' gobject_class->get_property = %sobject_proxy_get_property;\n'
2853 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2855 for i in self.ifaces:
2856 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
2858 %(n, i.name_hyphen))
2863 self.c.write(self.docbook_gen.expand(
2865 ' * %sobject_proxy_new:\n'
2866 ' * @connection: A #GDBusConnection.\n'
2867 ' * @object_path: An object path.\n'
2869 ' * Creates a new proxy object.\n'
2871 ' * Returns: (transfer full): The proxy object.\n'
2873 %(self.ns_lower), False))
2874 self.c.write('%sObjectProxy *\n'
2875 '%sobject_proxy_new (GDBusConnection *connection,\n'
2876 ' const gchar *object_path)\n'
2878 ' g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);\n'
2879 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2880 ' return %sOBJECT_PROXY (g_object_new (%sTYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL));\n'
2882 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2884 self.c.write(self.docbook_gen.expand(
2886 ' * %sObjectSkeleton:\n'
2888 ' * The #%sObjectSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2889 %(self.namespace, self.namespace), False))
2890 self.c.write(' */\n')
2892 self.c.write(self.docbook_gen.expand(
2894 ' * %sObjectSkeletonClass:\n'
2895 ' * @parent_class: The parent class.\n'
2897 ' * Class structure for #%sObjectSkeleton.\n'
2898 %(self.namespace, self.namespace), False))
2899 self.c.write(' */\n')
2902 self.c.write('static void\n'
2903 '%sobject_skeleton__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2907 %(self.ns_lower, self.ns_lower, self.namespace))
2909 self.c.write('static void\n'
2910 '%sobject_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2912 ' iface->interface_added = %sobject_notify;\n'
2913 ' iface->interface_removed = %sobject_notify;\n'
2916 %(self.ns_lower, self.ns_lower, self.ns_lower))
2917 self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectSkeleton, %sobject_skeleton, G_TYPE_DBUS_OBJECT_SKELETON,\n'
2918 ' G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_skeleton__%sobject_iface_init)\n'
2919 ' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_skeleton__g_dbus_object_iface_init));\n'
2921 %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2923 self.c.write('static void\n'
2924 '%sobject_skeleton_init (%sObjectSkeleton *object G_GNUC_UNUSED)\n'
2927 '\n'%(self.ns_lower, self.namespace))
2928 self.c.write('static void\n'
2929 '%sobject_skeleton_set_property (GObject *gobject,\n'
2931 ' const GValue *value,\n'
2932 ' GParamSpec *pspec)\n'
2934 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2935 ' GDBusInterfaceSkeleton *interface;\n'
2937 ' switch (prop_id)\n'
2939 %(self.ns_lower, self.namespace, self.ns_upper))
2941 for i in self.ifaces:
2942 self.c.write(' case %d:\n'
2943 ' interface = g_value_get_object (value);\n'
2944 ' if (interface != NULL)\n'
2946 ' g_warn_if_fail (%sIS_%s (interface));\n'
2947 ' g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface);\n'
2951 ' g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "%s");\n'
2955 %(n, self.ns_upper, i.name_upper, i.name))
2957 self.c.write(' default:\n'
2958 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2963 self.c.write('static void\n'
2964 '%sobject_skeleton_get_property (GObject *gobject,\n'
2967 ' GParamSpec *pspec)\n'
2969 ' %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2970 ' GDBusInterface *interface;\n'
2972 ' switch (prop_id)\n'
2974 %(self.ns_lower, self.namespace, self.ns_upper))
2976 for i in self.ifaces:
2977 self.c.write(' case %d:\n'
2978 ' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2979 ' g_value_take_object (value, interface);\n'
2984 self.c.write(' default:\n'
2985 ' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2990 self.c.write('static void\n'
2991 '%sobject_skeleton_class_init (%sObjectSkeletonClass *klass)\n'
2993 ' GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2995 ' gobject_class->set_property = %sobject_skeleton_set_property;\n'
2996 ' gobject_class->get_property = %sobject_skeleton_get_property;\n'
2998 %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
3000 for i in self.ifaces:
3001 self.c.write(' g_object_class_override_property (gobject_class, %d, "%s");'
3003 %(n, i.name_hyphen))
3007 self.c.write(self.docbook_gen.expand(
3009 ' * %sobject_skeleton_new:\n'
3010 ' * @object_path: An object path.\n'
3012 ' * Creates a new skeleton object.\n'
3014 ' * Returns: (transfer full): The skeleton object.\n'
3016 %(self.ns_lower), False))
3017 self.c.write('%sObjectSkeleton *\n'
3018 '%sobject_skeleton_new (const gchar *object_path)\n'
3020 ' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
3021 ' return %sOBJECT_SKELETON (g_object_new (%sTYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL));\n'
3023 '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
3024 for i in self.ifaces:
3025 self.c.write(self.docbook_gen.expand(
3027 ' * %sobject_skeleton_set_%s:\n'
3028 ' * @object: A #%sObjectSkeleton.\n'
3029 ' * @interface_: (allow-none): A #%s or %%NULL to clear the interface.\n'
3031 ' * Sets the #%s instance for the D-Bus interface #%s on @object.\n'
3032 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.camel_name, i.name), False))
3033 self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
3034 self.c.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_)\n'
3035 %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
3037 ' g_object_set (G_OBJECT (object), "%s", interface_, NULL);\n'
3044 def generate_object_manager_client(self):
3045 self.c.write('/* ------------------------------------------------------------------------\n'
3046 ' * Code for ObjectManager client\n'
3047 ' * ------------------------------------------------------------------------\n'
3051 self.c.write(self.docbook_gen.expand(
3053 ' * SECTION:%sObjectManagerClient\n'
3054 ' * @title: %sObjectManagerClient\n'
3055 ' * @short_description: Generated GDBusObjectManagerClient type\n'
3057 ' * This section contains a #GDBusObjectManagerClient that uses %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc.\n'
3059 %(self.namespace, self.namespace, self.ns_lower), False))
3062 self.c.write(self.docbook_gen.expand(
3064 ' * %sObjectManagerClient:\n'
3066 ' * The #%sObjectManagerClient structure contains only private data and should only be accessed using the provided API.\n'
3067 %(self.namespace, self.namespace), False))
3068 self.c.write(' */\n')
3071 self.c.write(self.docbook_gen.expand(
3073 ' * %sObjectManagerClientClass:\n'
3074 ' * @parent_class: The parent class.\n'
3076 ' * Class structure for #%sObjectManagerClient.\n'
3077 %(self.namespace, self.namespace), False))
3078 self.c.write(' */\n')
3082 self.c.write('G_DEFINE_TYPE (%sObjectManagerClient, %sobject_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT);\n'
3084 %(self.namespace, self.ns_lower))
3087 self.c.write('static void\n'
3088 '%sobject_manager_client_init (%sObjectManagerClient *manager G_GNUC_UNUSED)\n'
3091 '\n'%(self.ns_lower, self.namespace))
3092 self.c.write('static void\n'
3093 '%sobject_manager_client_class_init (%sObjectManagerClientClass *klass G_GNUC_UNUSED)\n'
3096 '\n'%(self.ns_lower, self.namespace))
3098 self.c.write(self.docbook_gen.expand(
3100 ' * %sobject_manager_client_get_proxy_type:\n'
3101 ' * @manager: A #GDBusObjectManagerClient.\n'
3102 ' * @object_path: The object path of the remote object (unused).\n'
3103 ' * @interface_name: (allow-none): Interface name of the remote object or %%NULL to get the object proxy #GType.\n'
3104 ' * @user_data: User data (unused).\n'
3106 ' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types.\n'
3108 ' * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %%NULL, otherwise the #GType for #%sObjectProxy.\n'
3109 %(self.ns_lower, self.namespace), False))
3110 self.c.write(' */\n')
3111 self.c.write('GType\n'
3112 '%sobject_manager_client_get_proxy_type (GDBusObjectManagerClient *manager G_GNUC_UNUSED, const gchar *object_path G_GNUC_UNUSED, const gchar *interface_name, gpointer user_data G_GNUC_UNUSED)\n'
3115 self.c.write(' static gsize once_init_value = 0;\n'
3116 ' static GHashTable *lookup_hash;\n'
3119 ' if (interface_name == NULL)\n'
3120 ' return %sTYPE_OBJECT_PROXY;\n'
3121 ' if (g_once_init_enter (&once_init_value))\n'
3123 ' lookup_hash = g_hash_table_new (g_str_hash, g_str_equal);\n'
3125 for i in self.ifaces:
3126 self.c.write(' g_hash_table_insert (lookup_hash, (gpointer) "%s", GSIZE_TO_POINTER (%sTYPE_%s_PROXY));\n'
3127 %(i.name, i.ns_upper, i.name_upper))
3128 self.c.write(' g_once_init_leave (&once_init_value, 1);\n'
3130 self.c.write(' ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name));\n'
3131 ' if (ret == (GType) 0)\n'
3132 ' ret = G_TYPE_DBUS_PROXY;\n')
3133 self.c.write(' return ret;\n'
3138 self.c.write(self.docbook_gen.expand(
3140 ' * %sobject_manager_client_new:\n'
3141 ' * @connection: A #GDBusConnection.\n'
3142 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3143 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3144 ' * @object_path: An object path.\n'
3145 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3146 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3147 ' * @user_data: User data to pass to @callback.\n'
3149 ' * Asynchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details.\n'
3151 ' * 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'
3152 ' * You can then call %sobject_manager_client_new_finish() to get the result of the operation.\n'
3154 ' * See %sobject_manager_client_new_sync() for the synchronous, blocking version of this constructor.\n'
3155 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3156 self.c.write(' */\n')
3157 self.c.write('void\n'
3158 '%sobject_manager_client_new (\n'
3159 ' GDBusConnection *connection,\n'
3160 ' GDBusObjectManagerClientFlags flags,\n'
3161 ' const gchar *name,\n'
3162 ' const gchar *object_path,\n'
3163 ' GCancellable *cancellable,\n'
3164 ' GAsyncReadyCallback callback,\n'
3165 ' gpointer user_data)\n'
3167 ' 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'
3170 %(self.ns_lower, self.ns_upper, self.ns_lower))
3171 self.c.write('/**\n'
3172 ' * %sobject_manager_client_new_finish:\n'
3173 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new().\n'
3174 ' * @error: Return location for error or %%NULL\n'
3176 ' * Finishes an operation started with %sobject_manager_client_new().\n'
3178 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3179 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3180 self.c.write(' */\n')
3181 self.c.write('GDBusObjectManager *\n'
3182 '%sobject_manager_client_new_finish (\n'
3183 ' GAsyncResult *res,\n'
3184 ' GError **error)\n'
3187 ' GObject *source_object;\n'
3188 ' source_object = g_async_result_get_source_object (res);\n'
3189 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3190 ' g_object_unref (source_object);\n'
3191 ' if (ret != NULL)\n'
3192 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3198 self.c.write(self.docbook_gen.expand(
3200 ' * %sobject_manager_client_new_sync:\n'
3201 ' * @connection: A #GDBusConnection.\n'
3202 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3203 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3204 ' * @object_path: An object path.\n'
3205 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3206 ' * @error: Return location for error or %%NULL\n'
3208 ' * 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'
3210 ' * The calling thread is blocked until a reply is received.\n'
3212 ' * See %sobject_manager_client_new() for the asynchronous version of this constructor.\n'
3214 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3215 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3216 self.c.write(' */\n')
3217 self.c.write('GDBusObjectManager *\n'
3218 '%sobject_manager_client_new_sync (\n'
3219 ' GDBusConnection *connection,\n'
3220 ' GDBusObjectManagerClientFlags flags,\n'
3221 ' const gchar *name,\n'
3222 ' const gchar *object_path,\n'
3223 ' GCancellable *cancellable,\n'
3224 ' GError **error)\n'
3226 ' GInitable *ret;\n'
3227 ' 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'
3228 ' if (ret != NULL)\n'
3229 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3234 %(self.ns_lower, self.ns_upper, self.ns_lower))
3236 self.c.write(self.docbook_gen.expand(
3238 ' * %sobject_manager_client_new_for_bus:\n'
3239 ' * @bus_type: A #GBusType.\n'
3240 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3241 ' * @name: A bus name (well-known or unique).\n'
3242 ' * @object_path: An object path.\n'
3243 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3244 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3245 ' * @user_data: User data to pass to @callback.\n'
3247 ' * Like %sobject_manager_client_new() but takes a #GBusType instead of a #GDBusConnection.\n'
3249 ' * 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'
3250 ' * You can then call %sobject_manager_client_new_for_bus_finish() to get the result of the operation.\n'
3252 ' * See %sobject_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
3253 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3254 self.c.write(' */\n')
3255 self.c.write('void\n'
3256 '%sobject_manager_client_new_for_bus (\n'
3257 ' GBusType bus_type,\n'
3258 ' GDBusObjectManagerClientFlags flags,\n'
3259 ' const gchar *name,\n'
3260 ' const gchar *object_path,\n'
3261 ' GCancellable *cancellable,\n'
3262 ' GAsyncReadyCallback callback,\n'
3263 ' gpointer user_data)\n'
3265 ' 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'
3268 %(self.ns_lower, self.ns_upper, self.ns_lower))
3269 self.c.write('/**\n'
3270 ' * %sobject_manager_client_new_for_bus_finish:\n'
3271 ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new_for_bus().\n'
3272 ' * @error: Return location for error or %%NULL\n'
3274 ' * Finishes an operation started with %sobject_manager_client_new_for_bus().\n'
3276 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3277 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3278 self.c.write(' */\n')
3279 self.c.write('GDBusObjectManager *\n'
3280 '%sobject_manager_client_new_for_bus_finish (\n'
3281 ' GAsyncResult *res,\n'
3282 ' GError **error)\n'
3285 ' GObject *source_object;\n'
3286 ' source_object = g_async_result_get_source_object (res);\n'
3287 ' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3288 ' g_object_unref (source_object);\n'
3289 ' if (ret != NULL)\n'
3290 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3296 self.c.write(self.docbook_gen.expand(
3298 ' * %sobject_manager_client_new_for_bus_sync:\n'
3299 ' * @bus_type: A #GBusType.\n'
3300 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3301 ' * @name: A bus name (well-known or unique).\n'
3302 ' * @object_path: An object path.\n'
3303 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3304 ' * @error: Return location for error or %%NULL\n'
3306 ' * Like %sobject_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
3308 ' * The calling thread is blocked until a reply is received.\n'
3310 ' * See %sobject_manager_client_new_for_bus() for the asynchronous version of this constructor.\n'
3312 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3313 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3314 self.c.write(' */\n')
3315 self.c.write('GDBusObjectManager *\n'
3316 '%sobject_manager_client_new_for_bus_sync (\n'
3317 ' GBusType bus_type,\n'
3318 ' GDBusObjectManagerClientFlags flags,\n'
3319 ' const gchar *name,\n'
3320 ' const gchar *object_path,\n'
3321 ' GCancellable *cancellable,\n'
3322 ' GError **error)\n'
3324 ' GInitable *ret;\n'
3325 ' 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'
3326 ' if (ret != NULL)\n'
3327 ' return G_DBUS_OBJECT_MANAGER (ret);\n'
3332 %(self.ns_lower, self.ns_upper, self.ns_lower))
3335 # ---------------------------------------------------------------------------------------------------
3337 def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
3338 if len(obj.since) > 0:
3341 %(indent, '', indent, '', obj.since))
3343 if isinstance(obj, dbustypes.Interface):
3344 thing = 'The D-Bus interface'
3345 elif isinstance(obj, dbustypes.Method):
3346 thing = 'The D-Bus method'
3347 elif isinstance(obj, dbustypes.Signal):
3348 thing = 'The D-Bus signal'
3349 elif isinstance(obj, dbustypes.Property):
3350 thing = 'The D-Bus property'
3352 raise RuntimeError('Cannot handle object ', obj)
3353 f.write(self.docbook_gen.expand(
3355 '%*s * Deprecated: %s has been deprecated.\n'
3356 %(indent, '', indent, '', thing), False))
3357 f.write('%*s */\n'%(indent, ''))
3359 # ---------------------------------------------------------------------------------------------------
3361 def generate_interface_intro(self, i):
3362 self.c.write('/* ------------------------------------------------------------------------\n'
3363 ' * Code for interface %s\n'
3364 ' * ------------------------------------------------------------------------\n'
3368 self.c.write(self.docbook_gen.expand(
3372 ' * @short_description: Generated C code for the %s D-Bus interface\n'
3374 ' * This section contains code for working with the #%s D-Bus interface in C.\n'
3376 %(i.camel_name, i.camel_name, i.name, i.name), False))
3380 self.generate_intro()
3381 self.declare_types()
3382 for i in self.ifaces:
3383 self.generate_interface_intro(i)
3384 self.generate_introspection_for_interface(i)
3385 self.generate_interface(i)
3386 self.generate_property_accessors(i)
3387 self.generate_signal_emitters(i)
3388 self.generate_method_calls(i)
3389 self.generate_method_completers(i)
3390 self.generate_proxy(i)
3391 self.generate_skeleton(i)
3392 if self.generate_objmanager:
3393 self.generate_object()
3394 self.generate_object_manager_client()
3396 self.generate_outro()