gdbus-codegen: Fix crasher in goa-using apps
[platform/upstream/glib.git] / gio / gdbus-2.0 / codegen / codegen.py
1 # -*- Mode: Python -*-
2
3 # GDBus - GLib D-Bus Library
4 #
5 # Copyright (C) 2008-2011 Red Hat, Inc.
6 #
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.
11 #
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.
16 #
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.
21 #
22 # Author: David Zeuthen <davidz@redhat.com>
23
24 import sys
25
26 from . import config
27 from . import utils
28 from . import dbustypes
29
30 # ----------------------------------------------------------------------------------------------------
31
32 class CodeGenerator:
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
36         self.ifaces = ifaces
37         self.h = h
38         self.c = c
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() + '_'
45             else:
46                 self.ns_upper = utils.camel_case_to_uscore(namespace).upper() + '_'
47                 self.ns_lower = utils.camel_case_to_uscore(namespace).lower() + '_'
48         else:
49             self.ns_upper = ''
50             self.ns_lower = ''
51         self.interface_prefix = interface_prefix
52         self.header_guard = self.h.name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
53
54     # ----------------------------------------------------------------------------------------------------
55
56     def generate_intro(self):
57         self.c.write('/*\n'
58                      ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
59                      ' *\n'
60                      ' * The license of this code is the same as for the source it was derived from.\n'
61                      ' */\n'
62                      '\n'
63                      %(config.VERSION))
64         self.c.write('#ifdef HAVE_CONFIG_H\n'
65                      '#  include "config.h"\n'
66                      '#endif\n'
67                      '\n'
68                      '#include "%s"\n'
69                      '\n'
70                      '#include <string.h>\n'
71                      %(self.h.name))
72
73         self.c.write('#ifdef G_OS_UNIX\n'
74                      '#  include <gio/gunixfdlist.h>\n'
75                      '#endif\n'
76                      '\n')
77
78         self.c.write('typedef struct\n'
79                      '{\n'
80                      '  GDBusArgInfo parent_struct;\n'
81                      '  gboolean use_gvariant;\n'
82                      '} _ExtendedGDBusArgInfo;\n'
83                      '\n')
84
85         self.c.write('typedef struct\n'
86                      '{\n'
87                      '  GDBusMethodInfo parent_struct;\n'
88                      '  const gchar *signal_name;\n'
89                      '  gboolean pass_fdlist;\n'
90                      '} _ExtendedGDBusMethodInfo;\n'
91                      '\n')
92
93         self.c.write('typedef struct\n'
94                      '{\n'
95                      '  GDBusSignalInfo parent_struct;\n'
96                      '  const gchar *signal_name;\n'
97                      '} _ExtendedGDBusSignalInfo;\n'
98                      '\n')
99
100         self.c.write('typedef struct\n'
101                      '{\n'
102                      '  GDBusPropertyInfo parent_struct;\n'
103                      '  const gchar *hyphen_name;\n'
104                      '  gboolean use_gvariant;\n'
105                      '} _ExtendedGDBusPropertyInfo;\n'
106                      '\n')
107
108         self.c.write('typedef struct\n'
109                      '{\n'
110                      '  GDBusInterfaceInfo parent_struct;\n'
111                      '  const gchar *hyphen_name;\n'
112                      '} _ExtendedGDBusInterfaceInfo;\n'
113                      '\n')
114
115         self.c.write('typedef struct\n'
116                      '{\n'
117                      '  const _ExtendedGDBusPropertyInfo *info;\n'
118                      '  guint prop_id;\n'
119                      '  GValue orig_value; /* the value before the change */\n'
120                      '} ChangedProperty;\n'
121                      '\n'
122                      'static void\n'
123                      '_changed_property_free (ChangedProperty *data)\n'
124                      '{\n'
125                      '  g_value_unset (&data->orig_value);\n'
126                      '  g_free (data);\n'
127                      '}\n'
128                      '\n')
129
130         self.c.write('static gboolean\n'
131                      '_g_strv_equal0 (gchar **a, gchar **b)\n'
132                      '{\n'
133                      '  gboolean ret = FALSE;\n'
134                      '  guint n;\n'
135                      '  if (a == NULL && b == NULL)\n'
136                      '    {\n'
137                      '      ret = TRUE;\n'
138                      '      goto out;\n'
139                      '    }\n'
140                      '  if (a == NULL || b == NULL)\n'
141                      '    goto out;\n'
142                      '  if (g_strv_length (a) != g_strv_length (b))\n'
143                      '    goto out;\n'
144                      '  for (n = 0; a[n] != NULL; n++)\n'
145                      '    if (g_strcmp0 (a[n], b[n]) != 0)\n'
146                      '      goto out;\n'
147                      '  ret = TRUE;\n'
148                      'out:\n'
149                      '  return ret;\n'
150                      '}\n'
151                      '\n')
152
153         self.c.write('static gboolean\n'
154                      '_g_variant_equal0 (GVariant *a, GVariant *b)\n'
155                      '{\n'
156                      '  gboolean ret = FALSE;\n'
157                      '  if (a == NULL && b == NULL)\n'
158                      '    {\n'
159                      '      ret = TRUE;\n'
160                      '      goto out;\n'
161                      '    }\n'
162                      '  if (a == NULL || b == NULL)\n'
163                      '    goto out;\n'
164                      '  ret = g_variant_equal (a, b);\n'
165                      'out:\n'
166                      '  return ret;\n'
167                      '}\n'
168                      '\n')
169
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'
173                      '{\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'
177                      '    {\n'
178                      '      case G_TYPE_BOOLEAN:\n'
179                      '        ret = (g_value_get_boolean (a) == g_value_get_boolean (b));\n'
180                      '        break;\n'
181                      '      case G_TYPE_UCHAR:\n'
182                      '        ret = (g_value_get_uchar (a) == g_value_get_uchar (b));\n'
183                      '        break;\n'
184                      '      case G_TYPE_INT:\n'
185                      '        ret = (g_value_get_int (a) == g_value_get_int (b));\n'
186                      '        break;\n'
187                      '      case G_TYPE_UINT:\n'
188                      '        ret = (g_value_get_uint (a) == g_value_get_uint (b));\n'
189                      '        break;\n'
190                      '      case G_TYPE_INT64:\n'
191                      '        ret = (g_value_get_int64 (a) == g_value_get_int64 (b));\n'
192                      '        break;\n'
193                      '      case G_TYPE_UINT64:\n'
194                      '        ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n'
195                      '        break;\n'
196                      '      case G_TYPE_DOUBLE:\n'
197                      '        {\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'
202                      '        }\n'
203                      '        break;\n'
204                      '      case G_TYPE_STRING:\n'
205                      '        ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n'
206                      '        break;\n'
207                      '      case G_TYPE_VARIANT:\n'
208                      '        ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b));\n'
209                      '        break;\n'
210                      '      default:\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'
213                      '        else\n'
214                      '          g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a)));\n'
215                      '        break;\n'
216                      '    }\n'
217                      '  return ret;\n'
218                      '}\n'
219                      '\n')
220
221         self.h.write('/*\n'
222                      ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
223                      ' *\n'
224                      ' * The license of this code is the same as for the source it was derived from.\n'
225                      ' */\n'
226                      '\n'
227                      '#ifndef __%s__\n'
228                      '#define __%s__\n'
229                      '\n'%(config.VERSION, self.header_guard, self.header_guard))
230         self.h.write('#include <gio/gio.h>\n'
231                      '\n'
232                      'G_BEGIN_DECLS\n'
233                      '\n')
234
235     # ----------------------------------------------------------------------------------------------------
236
237     def declare_types(self):
238         for i in self.ifaces:
239             self.h.write('\n')
240             self.h.write('/* ------------------------------------------------------------------------ */\n')
241             self.h.write('/* Declarations for %s */\n'%i.name)
242             self.h.write('\n')
243
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))
249             self.h.write('\n')
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))
253             self.h.write('\n')
254             self.h.write('struct _%sIface\n'%(i.camel_name))
255             self.h.write('{\n')
256             self.h.write('  GTypeInterface parent_iface;\n')
257
258             function_pointers = {}
259
260             # vfuncs for methods
261             if len(i.methods) > 0:
262                 self.h.write('\n')
263                 for m in i.methods:
264                     unix_fd = False
265                     if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
266                         unix_fd = True
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'%()
271                     if unix_fd:
272                         value += ',\n    GUnixFDList *fd_list'
273                     for a in m.in_args:
274                         value += ',\n    %sarg_%s'%(a.ctype_in, a.name)
275                     value += ');\n\n'
276                     function_pointers[key] = value
277
278             # vfuncs for signals
279             if len(i.signals) > 0:
280                 self.h.write('\n')
281                 for s in i.signals:
282                     key = (s.since, '_signal_%s'%s.name_lower)
283                     value  = '  void (*%s) (\n'%(s.name_lower)
284                     value += '    %s *object'%(i.camel_name)
285                     for a in s.args:
286                         value += ',\n    %sarg_%s'%(a.ctype_in, a.name)
287                     value += ');\n\n'
288                     function_pointers[key] = value
289
290             # vfuncs for properties
291             if len(i.properties) > 0:
292                 self.h.write('\n')
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
297
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
301             #
302             # Also use a proper version comparison function so e.g.
303             # 10.0 comes after 2.0.
304             #
305             # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
306             # for discussion
307             for key in sorted(function_pointers.keys(), key=utils.version_cmp_key):
308                 self.h.write('%s'%function_pointers[key])
309
310             self.h.write('};\n')
311             self.h.write('\n')
312             self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
313             self.h.write('\n')
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))
316             self.h.write('\n')
317
318             # Then method call completion functions
319             if len(i.methods) > 0:
320                 self.h.write('\n')
321                 self.h.write('/* D-Bus method call completion functions: */\n')
322                 for m in i.methods:
323                     unix_fd = False
324                     if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
325                         unix_fd = True
326                     if m.deprecated:
327                         self.h.write('G_GNUC_DEPRECATED ')
328                     self.h.write('void %s_complete_%s (\n'
329                                  '    %s *object,\n'
330                                  '    GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
331                     if unix_fd:
332                         self.h.write(',\n    GUnixFDList *fd_list')
333                     for a in m.out_args:
334                         self.h.write(',\n    %s%s'%(a.ctype_in, a.name))
335                     self.h.write(');\n')
336                     self.h.write('\n')
337                 self.h.write('\n')
338
339             # Then signal emission functions
340             if len(i.signals) > 0:
341                 self.h.write('\n')
342                 self.h.write('/* D-Bus signal emissions functions: */\n')
343                 for s in i.signals:
344                     if s.deprecated:
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))
348                     for a in s.args:
349                         self.h.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
350                     self.h.write(');\n')
351                     self.h.write('\n')
352                 self.h.write('\n')
353
354             # Then method call declarations
355             if len(i.methods) > 0:
356                 self.h.write('\n')
357                 self.h.write('/* D-Bus method calls: */\n')
358                 for m in i.methods:
359                     unix_fd = False
360                     if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
361                         unix_fd = True
362                     # async begin
363                     if m.deprecated:
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))
367                     for a in m.in_args:
368                         self.h.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
369                     if unix_fd:
370                         self.h.write(',\n    GUnixFDList *fd_list')
371                     self.h.write(',\n'
372                                  '    GCancellable *cancellable,\n'
373                                  '    GAsyncReadyCallback callback,\n'
374                                  '    gpointer user_data);\n')
375                     self.h.write('\n')
376                     # async finish
377                     if m.deprecated:
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))
381                     for a in m.out_args:
382                         self.h.write(',\n    %sout_%s'%(a.ctype_out, a.name))
383                     if unix_fd:
384                         self.h.write(',\n    GUnixFDList **out_fd_list')
385                     self.h.write(',\n'
386                                  '    GAsyncResult *res,\n'
387                                  '    GError **error);\n')
388                     self.h.write('\n')
389                     # sync
390                     if m.deprecated:
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))
394                     for a in m.in_args:
395                         self.h.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
396                     if unix_fd:
397                         self.h.write(',\n    GUnixFDList  *fd_list')
398                     for a in m.out_args:
399                         self.h.write(',\n    %sout_%s'%(a.ctype_out, a.name))
400                     if unix_fd:
401                         self.h.write(',\n    GUnixFDList **out_fd_list')
402                     self.h.write(',\n'
403                                  '    GCancellable *cancellable,\n'
404                                  '    GError **error);\n')
405                     self.h.write('\n')
406                 self.h.write('\n')
407
408             # Then the property accessor declarations
409             if len(i.properties) > 0:
410                 self.h.write('\n')
411                 self.h.write('/* D-Bus property accessors: */\n')
412                 for p in i.properties:
413                     # getter
414                     if p.deprecated:
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:
418                         if p.deprecated:
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))
421                     # setter
422                     if p.deprecated:
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, ))
425                     self.h.write('\n')
426
427             # Then the proxy
428             self.h.write('\n')
429             self.h.write('/* ---- */\n')
430             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))
437             self.h.write('\n')
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))
441             self.h.write('\n')
442             self.h.write('struct _%sProxy\n'%(i.camel_name))
443             self.h.write('{\n')
444             self.h.write('  /*< private >*/\n')
445             self.h.write('  GDBusProxy parent_instance;\n')
446             self.h.write('  %sProxyPrivate *priv;\n'%(i.camel_name))
447             self.h.write('};\n')
448             self.h.write('\n')
449             self.h.write('struct _%sProxyClass\n'%(i.camel_name))
450             self.h.write('{\n')
451             self.h.write('  GDBusProxyClass parent_class;\n')
452             self.h.write('};\n')
453             self.h.write('\n')
454             self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
455
456             self.h.write('\n')
457             if i.deprecated:
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'
467                          %(i.name_lower))
468             if i.deprecated:
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))
474             if i.deprecated:
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))
484             self.h.write('\n')
485             if i.deprecated:
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'
495                          %(i.name_lower))
496             if i.deprecated:
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))
502             if i.deprecated:
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))
512             self.h.write('\n')
513
514             # Then the skeleton
515             self.h.write('\n')
516             self.h.write('/* ---- */\n')
517             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))
524             self.h.write('\n')
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))
528             self.h.write('\n')
529             self.h.write('struct _%sSkeleton\n'%(i.camel_name))
530             self.h.write('{\n')
531             self.h.write('  /*< private >*/\n')
532             self.h.write('  GDBusInterfaceSkeleton parent_instance;\n')
533             self.h.write('  %sSkeletonPrivate *priv;\n'%(i.camel_name))
534             self.h.write('};\n')
535             self.h.write('\n')
536             self.h.write('struct _%sSkeletonClass\n'%(i.camel_name))
537             self.h.write('{\n')
538             self.h.write('  GDBusInterfaceSkeletonClass parent_class;\n')
539             self.h.write('};\n')
540             self.h.write('\n')
541             self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
542             self.h.write('\n')
543             if i.deprecated:
544                 self.h.write('G_GNUC_DEPRECATED ')
545             self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
546
547             self.h.write('\n')
548
549         # Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
550         if self.generate_objmanager:
551             self.h.write('\n')
552             self.h.write('/* ---- */\n')
553             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))
558             self.h.write('\n')
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))
562             self.h.write('\n')
563             self.h.write('struct _%sObjectIface\n'%(self.namespace))
564             self.h.write('{\n'
565                          '  GTypeInterface parent_iface;\n'
566                          '};\n'
567                          '\n')
568             self.h.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
569                          '\n'
570                          %(self.ns_lower))
571             for i in self.ifaces:
572                 if i.deprecated:
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:
577                 if i.deprecated:
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))
581             self.h.write('\n')
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))
588             self.h.write('\n')
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))
592             self.h.write('\n')
593             self.h.write('struct _%sObjectProxy\n'%(self.namespace))
594             self.h.write('{\n')
595             self.h.write('  /*< private >*/\n')
596             self.h.write('  GDBusObjectProxy parent_instance;\n')
597             self.h.write('  %sObjectProxyPrivate *priv;\n'%(self.namespace))
598             self.h.write('};\n')
599             self.h.write('\n')
600             self.h.write('struct _%sObjectProxyClass\n'%(self.namespace))
601             self.h.write('{\n')
602             self.h.write('  GDBusObjectProxyClass parent_class;\n')
603             self.h.write('};\n')
604             self.h.write('\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))
607             self.h.write('\n')
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))
614             self.h.write('\n')
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))
618             self.h.write('\n')
619             self.h.write('struct _%sObjectSkeleton\n'%(self.namespace))
620             self.h.write('{\n')
621             self.h.write('  /*< private >*/\n')
622             self.h.write('  GDBusObjectSkeleton parent_instance;\n')
623             self.h.write('  %sObjectSkeletonPrivate *priv;\n'%(self.namespace))
624             self.h.write('};\n')
625             self.h.write('\n')
626             self.h.write('struct _%sObjectSkeletonClass\n'%(self.namespace))
627             self.h.write('{\n')
628             self.h.write('  GDBusObjectSkeletonClass parent_class;\n')
629             self.h.write('};\n')
630             self.h.write('\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:
635                 if i.deprecated:
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))
639             self.h.write('\n')
640
641             self.h.write('/* ---- */\n')
642             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))
649             self.h.write('\n')
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))
653             self.h.write('\n')
654             self.h.write('struct _%sObjectManagerClient\n'%(self.namespace))
655             self.h.write('{\n')
656             self.h.write('  /*< private >*/\n')
657             self.h.write('  GDBusObjectManagerClient parent_instance;\n')
658             self.h.write('  %sObjectManagerClientPrivate *priv;\n'%(self.namespace))
659             self.h.write('};\n')
660             self.h.write('\n')
661             self.h.write('struct _%sObjectManagerClientClass\n'%(self.namespace))
662             self.h.write('{\n')
663             self.h.write('  GDBusObjectManagerClientClass parent_class;\n')
664             self.h.write('};\n')
665             self.h.write('\n')
666             self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
667             self.h.write('\n')
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))
669             self.h.write('\n')
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'
678                          %(self.ns_lower))
679             self.h.write('GDBusObjectManager *%sobject_manager_client_new_finish (\n'
680                          '    GAsyncResult        *res,\n'
681                          '    GError             **error);\n'
682                          %(self.ns_lower))
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'
690                          %(self.ns_lower))
691             self.h.write('\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'
700                          %(self.ns_lower))
701             self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_finish (\n'
702                          '    GAsyncResult        *res,\n'
703                          '    GError             **error);\n'
704                          %(self.ns_lower))
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'
712                          %(self.ns_lower))
713             self.h.write('\n')
714
715     # ----------------------------------------------------------------------------------------------------
716
717     def generate_outro(self):
718         self.h.write('\n'
719                      'G_END_DECLS\n'
720                      '\n'
721                      '#endif /* __%s__ */\n'%(self.header_guard))
722
723     # ----------------------------------------------------------------------------------------------------
724
725     def generate_annotations(self, prefix, annotations):
726         if annotations == None:
727             return
728
729         n = 0
730         for a in annotations:
731             #self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
732
733             # skip internal annotations
734             if a.key.startswith('org.gtk.GDBus'):
735                 continue
736
737             self.c.write('static const GDBusAnnotationInfo %s_%d =\n'
738                          '{\n'
739                          '  -1,\n'
740                          '  (gchar *) "%s",\n'
741                          '  (gchar *) "%s",\n'%(prefix, n, a.key, a.value))
742             if len(a.annotations) == 0:
743                 self.c.write('  NULL\n')
744             else:
745                 self.c.write('  (GDBusAnnotationInfo **) &%s_%d_pointers\n'%(prefix, n))
746             self.c.write('};\n'
747                          '\n')
748             n += 1
749
750         if n > 0:
751             self.c.write('static const GDBusAnnotationInfo * const %s_pointers[] =\n'
752                              '{\n'%(prefix))
753             m = 0;
754             for a in annotations:
755                 if a.key.startswith('org.gtk.GDBus'):
756                     continue
757                 self.c.write('  &%s_%d,\n'%(prefix, m))
758                 m += 1
759             self.c.write('  NULL\n'
760                          '};\n'
761                          '\n')
762         return n
763
764     def generate_args(self, prefix, args):
765         for a in args:
766             num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
767
768             self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
769                          '{\n'
770                          '  {\n'
771                          '    -1,\n'
772                          '    (gchar *) "%s",\n'
773                          '    (gchar *) "%s",\n'%(prefix, a.name, a.name, a.signature))
774             if num_anno == 0:
775                 self.c.write('    NULL\n')
776             else:
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')
781             else:
782                 self.c.write('  TRUE\n')
783             self.c.write('};\n'
784                          '\n')
785
786         if len(args) > 0:
787             self.c.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
788                              '{\n'%(prefix))
789             for a in args:
790                 self.c.write('  &%s_%s,\n'%(prefix, a.name))
791             self.c.write('  NULL\n'
792                          '};\n'
793                          '\n')
794
795     def generate_introspection_for_interface(self, i):
796             self.c.write('/* ---- Introspection data for %s ---- */\n'
797                          '\n'%(i.name))
798
799             if len(i.methods) > 0:
800                 for m in i.methods:
801                     unix_fd = False
802                     if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
803                         unix_fd = True
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)
806
807                     num_anno = self.generate_annotations('_%s_method_%s_annotation_info'%(i.name_lower, m.name_lower), m.annotations)
808
809                     self.c.write('static const _ExtendedGDBusMethodInfo _%s_method_info_%s =\n'
810                                  '{\n'
811                                  '  {\n'
812                                  '    -1,\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')
816                     else:
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')
820                     else:
821                         self.c.write('    (GDBusArgInfo **) &_%s_method_info_%s_OUT_ARG_pointers,\n'%(i.name_lower, m.name_lower))
822                     if num_anno == 0:
823                         self.c.write('    NULL\n')
824                     else:
825                         self.c.write('    (GDBusAnnotationInfo **) &_%s_method_%s_annotation_info_pointers\n'%(i.name_lower, m.name_lower))
826                     self.c.write('  },\n'
827                                  '  "handle-%s",\n'
828                                  '  %s\n'
829                                  %(m.name_hyphen, 'TRUE' if unix_fd else 'FALSE'))
830                     self.c.write('};\n'
831                                  '\n')
832
833                 self.c.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] =\n'
834                              '{\n'%(i.name_lower))
835                 for m in i.methods:
836                     self.c.write('  &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
837                 self.c.write('  NULL\n'
838                              '};\n'
839                              '\n')
840
841             # ---
842
843             if len(i.signals) > 0:
844                 for s in i.signals:
845                     self.generate_args('_%s_signal_info_%s_ARG'%(i.name_lower, s.name_lower), s.args)
846
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'
849                                  '{\n'
850                                  '  {\n'
851                                  '    -1,\n'
852                                  '    (gchar *) "%s",\n'%(i.name_lower, s.name_lower, s.name))
853                     if len(s.args) == 0:
854                         self.c.write('    NULL,\n')
855                     else:
856                         self.c.write('    (GDBusArgInfo **) &_%s_signal_info_%s_ARG_pointers,\n'%(i.name_lower, s.name_lower))
857                     if num_anno == 0:
858                         self.c.write('    NULL\n')
859                     else:
860                         self.c.write('    (GDBusAnnotationInfo **) &_%s_signal_%s_annotation_info_pointers\n'%(i.name_lower, s.name_lower))
861                     self.c.write('  },\n'
862                                  '  "%s"\n'
863                                  %(s.name_hyphen))
864                     self.c.write('};\n'
865                                  '\n')
866
867                 self.c.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
868                              '{\n'%(i.name_lower))
869                 for s in i.signals:
870                     self.c.write('  &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
871                 self.c.write('  NULL\n'
872                              '};\n'
873                              '\n')
874
875             # ---
876
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'
881                     elif p.readable:
882                         access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE'
883                     elif p.writable:
884                         access = 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
885                     else:
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'
889                                  '{\n'
890                                  '  {\n'
891                                  '    -1,\n'
892                                  '    (gchar *) "%s",\n'
893                                  '    (gchar *) "%s",\n'
894                                  '    %s,\n'%(i.name_lower, p.name_lower, p.name, p.arg.signature, access))
895                     if num_anno == 0:
896                         self.c.write('    NULL\n')
897                     else:
898                         self.c.write('    (GDBusAnnotationInfo **) &_%s_property_%s_annotation_info_pointers\n'%(i.name_lower, p.name_lower))
899                     self.c.write('  },\n'
900                                  '  "%s",\n'
901                                  %(p.name_hyphen))
902                     if not utils.lookup_annotation(p.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
903                         self.c.write('  FALSE\n')
904                     else:
905                         self.c.write('  TRUE\n')
906                     self.c.write('};\n'
907                                  '\n')
908
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'
914                              '};\n'
915                              '\n')
916
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'
919                          '{\n'
920                          '  {\n'
921                          '    -1,\n'
922                          '    (gchar *) "%s",\n'%(i.name_lower, i.name))
923             if len(i.methods) == 0:
924                 self.c.write('    NULL,\n')
925             else:
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')
929             else:
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')
933             else:
934                 self.c.write('    (GDBusPropertyInfo **) &_%s_property_info_pointers,\n'%(i.name_lower))
935             if num_anno == 0:
936                 self.c.write('    NULL\n')
937             else:
938                 self.c.write('    (GDBusAnnotationInfo **) &_%s_annotation_info_pointers\n'%(i.name_lower))
939             self.c.write('  },\n'
940                          '  "%s",\n'
941                          '};\n'
942                          '\n'
943                          %(i.name_hyphen))
944             self.c.write('\n')
945             self.c.write(self.docbook_gen.expand(
946                     '/**\n'
947                     ' * %s_interface_info:\n'
948                     ' *\n'
949                     ' * Gets a machine-readable description of the #%s D-Bus interface.\n'
950                     ' *\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'
956                          '{\n'
957                          '  return (GDBusInterfaceInfo *) &_%s_interface_info.parent_struct;\n'
958                          '}\n'
959                          '\n'%(i.name_lower, i.name_lower))
960
961             self.c.write(self.docbook_gen.expand(
962                     '/**\n'
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'
966                     ' *\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'
969                     ' *\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'
979                          '}\n'
980                          '\n')
981             self.c.write('\n')
982
983     # ----------------------------------------------------------------------------------------------------
984
985     def generate_interface(self, i):
986         self.c.write('\n')
987
988         self.c.write(self.docbook_gen.expand(
989                 '/**\n'
990                 ' * %s:\n'
991                 ' *\n'
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)
995         self.c.write('\n')
996
997         self.c.write(self.docbook_gen.expand(
998                 '/**\n'
999                 ' * %sIface:\n'
1000                 ' * @parent_iface: The parent interface.\n'
1001                 %(i.camel_name), False))
1002
1003         doc_bits = {}
1004         if len(i.methods) > 0:
1005             for m in i.methods:
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:
1011             for s in i.signals:
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])
1024
1025         self.c.write(self.docbook_gen.expand(
1026                 ' *\n'
1027                 ' * Virtual table for the D-Bus interface #%s.\n'
1028                 %(i.name), False))
1029         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1030         self.c.write('\n')
1031
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))
1034         self.c.write('\n')
1035
1036         self.c.write('static void\n'
1037                      '%s_default_init (%sIface *iface)\n'
1038                      '{\n'%(i.name_lower, i.camel_name));
1039
1040         if len(i.methods) > 0:
1041             self.c.write('  /* GObject signals for incoming D-Bus method calls: */\n')
1042             for m in i.methods:
1043                 unix_fd = False
1044                 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1045                     unix_fd = True
1046                 self.c.write(self.docbook_gen.expand(
1047                         '  /**\n'
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))
1052                 if unix_fd:
1053                     self.c.write ('   * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
1054                 for a in m.in_args:
1055                     self.c.write ('   * @arg_%s: Argument passed by remote caller.\n'%(a.name))
1056                 self.c.write(self.docbook_gen.expand(
1057                         '   *\n'
1058                         '   * Signal emitted when a remote caller is invoking the %s.%s() D-Bus method.\n'
1059                         '   *\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'
1061                         '   *\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)
1065                 if unix_fd:
1066                     extra_args = 2
1067                 else:
1068                     extra_args = 1
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'
1077                              '    %d,\n'
1078                              '    G_TYPE_DBUS_METHOD_INVOCATION'
1079                              %(m.name_hyphen, i.camel_name, m.name_lower, len(m.in_args) + extra_args))
1080                 if unix_fd:
1081                     self.c.write(', G_TYPE_UNIX_FD_LIST')
1082                 for a in m.in_args:
1083                     self.c.write (', %s'%(a.gtype))
1084                 self.c.write(');\n')
1085                 self.c.write('\n')
1086
1087         if len(i.signals) > 0:
1088             self.c.write('  /* GObject signals for received D-Bus signals: */\n')
1089             for s in i.signals:
1090                 self.c.write(self.docbook_gen.expand(
1091                         '  /**\n'
1092                         '   * %s::%s:\n'
1093                         '   * @object: A #%s.\n'
1094                         %(i.camel_name, s.name_hyphen, i.camel_name), False))
1095                 for a in s.args:
1096                     self.c.write ('   * @arg_%s: Argument.\n'%(a.name))
1097                 self.c.write(self.docbook_gen.expand(
1098                         '   *\n'
1099                         '   * On the client-side, this signal is emitted whenever the D-Bus signal #%s::%s is received.\n'
1100                         '   *\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'
1111                              '    G_TYPE_NONE,\n'
1112                              '    %d'
1113                              %(s.name_hyphen, i.camel_name, s.name_lower, len(s.args)))
1114                 for a in s.args:
1115                     self.c.write (', %s'%(a.gtype))
1116                 self.c.write(');\n')
1117                 self.c.write('\n')
1118
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.'
1124                 elif p.readable:
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.'
1126                 elif p.writable:
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.'
1128                 else:
1129                     raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1130                 self.c.write(self.docbook_gen.expand(
1131                         '  /**\n'
1132                         '   * %s:%s:\n'
1133                         '   *\n'
1134                         '   * Represents the D-Bus property #%s:%s.\n'
1135                         '   *\n'
1136                         '   * %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)
1174                 else:
1175                     raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
1176                 self.c.write('    %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
1177                 self.c.write('\n')
1178
1179         self.c.write('}\n'
1180                      '\n')
1181
1182     # ----------------------------------------------------------------------------------------------------
1183
1184     def generate_property_accessors(self, i):
1185         for p in i.properties:
1186             # getter
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.'
1189             elif p.readable:
1190                 hint = 'Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.'
1191             elif p.writable:
1192                 hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
1193             else:
1194                 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1195             self.c.write(self.docbook_gen.expand(
1196                     '/**\n'
1197                     ' * %s_get_%s: (skip)\n'
1198                     ' * @object: A #%s.\n'
1199                     ' *\n'
1200                     ' * Gets the value of the #%s:%s D-Bus property.\n'
1201                     ' *\n'
1202                     ' * %s\n'
1203                     ' *\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'
1207                              ' *\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))
1210             else:
1211                 self.c.write(' * Returns: The property value.\n')
1212             self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
1213             self.c.write('%s\n'
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))
1217             self.c.write('}\n')
1218             self.c.write('\n')
1219             if p.arg.free_func != None:
1220
1221                 self.c.write(self.docbook_gen.expand(
1222                         '/**\n'
1223                         ' * %s_dup_%s: (skip)\n'
1224                         ' * @object: A #%s.\n'
1225                         ' *\n'
1226                         ' * Gets a copy of the #%s:%s D-Bus property.\n'
1227                         ' *\n'
1228                         ' * %s\n'
1229                         ' *\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)
1233                 self.c.write('%s\n'
1234                              '%s_dup_%s (%s *object)\n'
1235                              '{\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')
1239                 self.c.write('}\n')
1240                 self.c.write('\n')
1241
1242             # setter
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.'
1245             elif p.readable:
1246                 hint = 'Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.'
1247             elif p.writable:
1248                 hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
1249             else:
1250                 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
1251             self.c.write(self.docbook_gen.expand(
1252                     '/**\n'
1253                     ' * %s_set_%s: (skip)\n'
1254                     ' * @object: A #%s.\n'
1255                     ' * @value: The value to set.\n'
1256                     ' *\n'
1257                     ' * Sets the #%s:%s D-Bus property to @value.\n'
1258                     ' *\n'
1259                     ' * %s\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))
1266             self.c.write('}\n')
1267             self.c.write('\n')
1268
1269     # ---------------------------------------------------------------------------------------------------
1270
1271     def generate_signal_emitters(self, i):
1272         for s in i.signals:
1273             self.c.write(self.docbook_gen.expand(
1274                     '/**\n'
1275                     ' * %s_emit_%s:\n'
1276                     ' * @object: A #%s.\n'
1277                     %(i.name_lower, s.name_lower, i.camel_name), False))
1278             for a in s.args:
1279                 self.c.write(' * @arg_%s: Argument to pass with the signal.\n'%(a.name))
1280             self.c.write(self.docbook_gen.expand(
1281                     ' *\n'
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'
1286                          '%s_emit_%s (\n'
1287                          '    %s *object'%(i.name_lower, s.name_lower, i.camel_name))
1288             for a in s.args:
1289                 self.c.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
1290             self.c.write(')\n'
1291                          '{\n'
1292                          '  g_signal_emit_by_name (object, "%s"'%(s.name_hyphen))
1293             for a in s.args:
1294                 self.c.write(', arg_%s'%a.name)
1295             self.c.write(');\n')
1296             self.c.write('}\n'
1297                          '\n')
1298
1299     # ---------------------------------------------------------------------------------------------------
1300
1301     def generate_method_calls(self, i):
1302         for m in i.methods:
1303             unix_fd = False
1304             if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1305                 unix_fd = True
1306             # async begin
1307             self.c.write('/**\n'
1308                          ' * %s_call_%s:\n'
1309                          ' * @proxy: A #%sProxy.\n'
1310                          %(i.name_lower, m.name_lower, i.camel_name))
1311             for a in m.in_args:
1312                 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1313             if unix_fd:
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'
1319                     ' *\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'
1323                     ' *\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'
1328                          '%s_call_%s (\n'
1329                          '    %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
1330             for a in m.in_args:
1331                 self.c.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
1332             if unix_fd:
1333                 self.c.write(',\n    GUnixFDList *fd_list')
1334             self.c.write(',\n'
1335                          '    GCancellable *cancellable,\n'
1336                          '    GAsyncReadyCallback callback,\n'
1337                          '    gpointer user_data)\n'
1338                          '{\n')
1339             if unix_fd:
1340                 self.c.write('  g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy),\n')
1341             else:
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))
1345             for a in m.in_args:
1346                 self.c.write('%s'%(a.format_in))
1347             self.c.write(')"')
1348             for a in m.in_args:
1349                 self.c.write(',\n                   arg_%s'%(a.name))
1350             self.c.write('),\n'
1351                          '    G_DBUS_CALL_FLAGS_NONE,\n'
1352                          '    -1,\n')
1353             if unix_fd:
1354                 self.c.write('    fd_list,\n')
1355             self.c.write('    cancellable,\n'
1356                          '    callback,\n'
1357                          '    user_data);\n')
1358             self.c.write('}\n'
1359                          '\n')
1360             # async finish
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))
1367             if unix_fd:
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'
1372                     ' *\n'
1373                     ' * Finishes an operation started with %s_call_%s().\n'
1374                     ' *\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))
1383             if unix_fd:
1384                 self.c.write(',\n    GUnixFDList **out_fd_list')
1385             self.c.write(',\n'
1386                          '    GAsyncResult *res,\n'
1387                          '    GError **error)\n'
1388                          '{\n'
1389                          '  GVariant *_ret;\n')
1390             if unix_fd:
1391                 self.c.write('  _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error);\n')
1392             else:
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'
1395                          '    goto _out;\n')
1396             self.c.write('  g_variant_get (_ret,\n'
1397                          '                 \"(')
1398             for a in m.out_args:
1399                 self.c.write('%s'%(a.format_out))
1400             self.c.write(')"')
1401             for a in m.out_args:
1402                 self.c.write(',\n                 out_%s'%(a.name))
1403             self.c.write(');\n'
1404                          '  g_variant_unref (_ret);\n')
1405             self.c.write('_out:\n'
1406                          '  return _ret != NULL;\n'
1407                          '}\n'
1408                          '\n')
1409
1410
1411             # sync
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))
1416             for a in m.in_args:
1417                 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
1418             if unix_fd:
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))
1422             if unix_fd:
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'
1427                     ' *\n'
1428                     ' * Synchronously invokes the %s.%s() D-Bus method on @proxy. The calling thread is blocked until a reply is received.\n'
1429                     ' *\n'
1430                     ' * See %s_call_%s() for the asynchronous version of this method.\n'
1431                     ' *\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))
1438             for a in m.in_args:
1439                 self.c.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
1440             if unix_fd:
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))
1444             if unix_fd:
1445                 self.c.write(',\n    GUnixFDList **out_fd_list')
1446             self.c.write(',\n'
1447                          '    GCancellable *cancellable,\n'
1448                          '    GError **error)\n'
1449                          '{\n'
1450                          '  GVariant *_ret;\n')
1451             if unix_fd:
1452                 self.c.write('  _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy),\n')
1453             else:
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))
1457             for a in m.in_args:
1458                 self.c.write('%s'%(a.format_in))
1459             self.c.write(')"')
1460             for a in m.in_args:
1461                 self.c.write(',\n                   arg_%s'%(a.name))
1462             self.c.write('),\n'
1463                          '    G_DBUS_CALL_FLAGS_NONE,\n'
1464                          '    -1,\n')
1465             if unix_fd:
1466                 self.c.write('    fd_list,\n'
1467                              '    out_fd_list,\n')
1468             self.c.write('    cancellable,\n'
1469                          '    error);\n'
1470                          '  if (_ret == NULL)\n'
1471                          '    goto _out;\n')
1472             self.c.write('  g_variant_get (_ret,\n'
1473                          '                 \"(')
1474             for a in m.out_args:
1475                 self.c.write('%s'%(a.format_out))
1476             self.c.write(')"')
1477             for a in m.out_args:
1478                 self.c.write(',\n                 out_%s'%(a.name))
1479             self.c.write(');\n'
1480                          '  g_variant_unref (_ret);\n')
1481             self.c.write('_out:\n'
1482                          '  return _ret != NULL;\n'
1483                          '}\n'
1484                          '\n')
1485
1486     # ---------------------------------------------------------------------------------------------------
1487
1488     def generate_method_completers(self, i):
1489         for m in i.methods:
1490             unix_fd = False
1491             if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
1492                 unix_fd = True
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))
1498             if unix_fd:
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(
1503                     ' *\n'
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'
1505                     ' *\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'
1511                          '    %s *object,\n'
1512                          '    GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
1513             if unix_fd:
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))
1517             self.c.write(')\n'
1518                          '{\n')
1519
1520             if unix_fd:
1521                 self.c.write('  g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,\n'
1522                              '    g_variant_new ("(')
1523             else:
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))
1528             self.c.write(')"')
1529             for a in m.out_args:
1530                 self.c.write(',\n                   %s'%(a.name))
1531             if unix_fd:
1532                 self.c.write('),\n    fd_list);\n')
1533             else:
1534                 self.c.write('));\n')
1535             self.c.write('}\n'
1536                          '\n')
1537
1538     # ---------------------------------------------------------------------------------------------------
1539
1540     def generate_proxy(self, i):
1541         # class boilerplate
1542         self.c.write('/* ------------------------------------------------------------------------ */\n'
1543                      '\n')
1544
1545         self.c.write(self.docbook_gen.expand(
1546                 '/**\n'
1547                 ' * %sProxy:\n'
1548                 ' *\n'
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)
1552         self.c.write('\n')
1553
1554         self.c.write(self.docbook_gen.expand(
1555                 '/**\n'
1556                 ' * %sProxyClass:\n'
1557                 ' * @parent_class: The parent class.\n'
1558                 ' *\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)
1562         self.c.write('\n')
1563
1564         self.c.write('struct _%sProxyPrivate\n'
1565                      '{\n'
1566                      '  GData *qdata;\n'
1567                      '};\n'
1568                      '\n'%i.camel_name)
1569
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('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
1573         self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1574         self.c.write('                         G_ADD_PRIVATE (%sProxy)\n'%(i.camel_name))
1575         self.c.write('                         G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1576         self.c.write('#else\n')
1577         self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
1578         self.c.write('                         G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
1579         self.c.write('#endif\n')
1580
1581         # finalize
1582         self.c.write('static void\n'
1583                      '%s_proxy_finalize (GObject *object)\n'
1584                      '{\n'%(i.name_lower))
1585         self.c.write('  %sProxy *proxy = %s%s_PROXY (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
1586         self.c.write('  g_datalist_clear (&proxy->priv->qdata);\n')
1587         self.c.write('  G_OBJECT_CLASS (%s_proxy_parent_class)->finalize (object);\n'
1588                      '}\n'
1589                      '\n'%(i.name_lower))
1590
1591         # property accessors
1592         #
1593         # Note that we are guaranteed that prop_id starts at 1 and is
1594         # laid out in the same order as introspection data pointers
1595         #
1596         self.c.write('static void\n'
1597                      '%s_proxy_get_property (GObject      *object,\n'
1598                      '  guint         prop_id,\n'
1599                      '  GValue       *value,\n'
1600                      '  GParamSpec   *pspec G_GNUC_UNUSED)\n'
1601                      '{\n'%(i.name_lower))
1602         if len(i.properties) > 0:
1603             self.c.write('  const _ExtendedGDBusPropertyInfo *info;\n'
1604                          '  GVariant *variant;\n'
1605                          '  g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1606                          '  info = _%s_property_info_pointers[prop_id - 1];\n'
1607                          '  variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
1608                          '  if (info->use_gvariant)\n'
1609                          '    {\n'
1610                          '      g_value_set_variant (value, variant);\n'
1611                          '    }\n'
1612                          '  else\n'
1613                          '    {\n'
1614                          # could be that we don't have the value in cache - in that case, we do
1615                          # nothing and the user gets the default value for the GType
1616                          '      if (variant != NULL)\n'
1617                          '        g_dbus_gvariant_to_gvalue (variant, value);\n'
1618                          '    }\n'
1619                          '  if (variant != NULL)\n'
1620                          '    g_variant_unref (variant);\n'
1621                          %(len(i.properties), i.name_lower))
1622         self.c.write('}\n'
1623                      '\n')
1624         if len(i.properties) > 0:
1625             self.c.write('static void\n'
1626                          '%s_proxy_set_property_cb (GDBusProxy *proxy,\n'
1627                          '  GAsyncResult *res,\n'
1628                          '  gpointer      user_data)\n'
1629                          '{\n'%(i.name_lower))
1630             self.c.write('  const _ExtendedGDBusPropertyInfo *info = user_data;\n'
1631                          '  GError *error;\n'
1632                          '  GVariant *_ret;\n'
1633                          '  error = NULL;\n'
1634                          '  _ret = g_dbus_proxy_call_finish (proxy, res, &error);\n'
1635                          '  if (!_ret)\n'
1636                          '    {\n'
1637                          '      g_warning ("Error setting property \'%%s\' on interface %s: %%s (%%s, %%d)",\n'
1638                          '                 info->parent_struct.name, \n'
1639                          '                 error->message, g_quark_to_string (error->domain), error->code);\n'
1640                          '      g_error_free (error);\n'
1641                          '    }\n'
1642                          '  else\n'
1643                          '    {\n'
1644                          '      g_variant_unref (_ret);\n'
1645                          '    }\n'
1646                          %(i.name))
1647             self.c.write('}\n'
1648                          '\n')
1649         self.c.write('static void\n'
1650                      '%s_proxy_set_property (GObject      *object,\n'
1651                      '  guint         prop_id,\n'
1652                      '  const GValue *value,\n'
1653                      '  GParamSpec   *pspec G_GNUC_UNUSED)\n'
1654                      '{\n'%(i.name_lower))
1655         if len(i.properties) > 0:
1656             self.c.write('  const _ExtendedGDBusPropertyInfo *info;\n'
1657                          '  GVariant *variant;\n'
1658                          '  g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
1659                          '  info = _%s_property_info_pointers[prop_id - 1];\n'
1660                          '  variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
1661                          '  g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
1662                          '    "org.freedesktop.DBus.Properties.Set",\n'
1663                          '    g_variant_new ("(ssv)", "%s", info->parent_struct.name, variant),\n'
1664                          '    G_DBUS_CALL_FLAGS_NONE,\n'
1665                          '    -1,\n'
1666                          '    NULL, (GAsyncReadyCallback) %s_proxy_set_property_cb, (GDBusPropertyInfo *) &info->parent_struct);\n'
1667                          '  g_variant_unref (variant);\n'
1668                          %(len(i.properties), i.name_lower, i.name, i.name_lower))
1669         self.c.write('}\n'
1670                      '\n')
1671
1672         # signal received
1673         self.c.write('static void\n'
1674                      '%s_proxy_g_signal (GDBusProxy *proxy,\n'
1675                      '  const gchar *sender_name G_GNUC_UNUSED,\n'
1676                      '  const gchar *signal_name,\n'
1677                      '  GVariant *parameters)\n'
1678                      '{\n'%(i.name_lower))
1679         self.c.write('  _ExtendedGDBusSignalInfo *info;\n'
1680                      '  GVariantIter iter;\n'
1681                      '  GVariant *child;\n'
1682                      '  GValue *paramv;\n'
1683                      '  guint num_params;\n'
1684                      '  guint n;\n'
1685                      '  guint signal_id;\n');
1686         # Note: info could be NULL if we are talking to a newer version of the interface
1687         self.c.write('  info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, signal_name);\n'
1688                      '  if (info == NULL)\n'
1689                      '    return;\n'
1690                      %(i.name_lower))
1691         self.c.write ('  num_params = g_variant_n_children (parameters);\n'
1692                       '  paramv = g_new0 (GValue, num_params + 1);\n'
1693                       '  g_value_init (&paramv[0], %sTYPE_%s);\n'
1694                       '  g_value_set_object (&paramv[0], proxy);\n'
1695                       %(i.ns_upper, i.name_upper))
1696         self.c.write('  g_variant_iter_init (&iter, parameters);\n'
1697                      '  n = 1;\n'
1698                      '  while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
1699                      '    {\n'
1700                      '      _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1];\n'
1701                      '      if (arg_info->use_gvariant)\n'
1702                      '        {\n'
1703                      '          g_value_init (&paramv[n], G_TYPE_VARIANT);\n'
1704                      '          g_value_set_variant (&paramv[n], child);\n'
1705                      '          n++;\n'
1706                      '        }\n'
1707                      '      else\n'
1708                      '        g_dbus_gvariant_to_gvalue (child, &paramv[n++]);\n'
1709                      '      g_variant_unref (child);\n'
1710                      '    }\n'
1711                      )
1712         self.c.write('  signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
1713                      %(i.ns_upper, i.name_upper))
1714         self.c.write('  g_signal_emitv (paramv, signal_id, 0, NULL);\n')
1715         self.c.write('  for (n = 0; n < num_params + 1; n++)\n'
1716                      '    g_value_unset (&paramv[n]);\n'
1717                      '  g_free (paramv);\n')
1718         self.c.write('}\n'
1719                      '\n')
1720
1721         # property changed
1722         self.c.write('static void\n'
1723                      '%s_proxy_g_properties_changed (GDBusProxy *_proxy,\n'
1724                      '  GVariant *changed_properties,\n'
1725                      '  const gchar *const *invalidated_properties)\n'
1726                      '{\n'%(i.name_lower))
1727         # Note: info could be NULL if we are talking to a newer version of the interface
1728         self.c.write('  %sProxy *proxy = %s%s_PROXY (_proxy);\n'
1729                      '  guint n;\n'
1730                      '  const gchar *key;\n'
1731                      '  GVariantIter *iter;\n'
1732                      '  _ExtendedGDBusPropertyInfo *info;\n'
1733                      '  g_variant_get (changed_properties, "a{sv}", &iter);\n'
1734                      '  while (g_variant_iter_next (iter, "{&sv}", &key, NULL))\n'
1735                      '    {\n'
1736                      '      info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, key);\n'
1737                      '      g_datalist_remove_data (&proxy->priv->qdata, key);\n'
1738                      '      if (info != NULL)\n'
1739                      '        g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1740                      '    }\n'
1741                      '  g_variant_iter_free (iter);\n'
1742                      '  for (n = 0; invalidated_properties[n] != NULL; n++)\n'
1743                      '    {\n'
1744                      '      info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, invalidated_properties[n]);\n'
1745                      '      g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]);\n'
1746                      '      if (info != NULL)\n'
1747                      '        g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
1748                      '    }\n'
1749                      '}\n'
1750                      '\n'
1751                      %(i.camel_name, i.ns_upper, i.name_upper,
1752                        i.name_lower, i.name_lower))
1753
1754         # property vfuncs
1755         for p in i.properties:
1756             nul_value = '0'
1757             if p.arg.free_func != None:
1758                 nul_value = 'NULL'
1759             self.c.write('static %s\n'
1760                          '%s_proxy_get_%s (%s *object)\n'
1761                          '{\n'
1762                          '  %sProxy *proxy = %s%s_PROXY (object);\n'
1763                          '  GVariant *variant;\n'
1764                          '  %svalue = %s;\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name,
1765                                               i.camel_name, i.ns_upper, i.name_upper,
1766                                               p.arg.ctype_in, nul_value))
1767             # For some property types, we have to free the returned
1768             # value (or part of it, e.g. the container) because of how
1769             # GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
1770             # for details
1771             #
1772             free_container = False;
1773             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':
1774                 free_container = True;
1775             # If already using an old value for strv, objpathv, bytestring_array (see below),
1776             # then just return that... that way the result from multiple consecutive calls
1777             # to the getter are valid as long as they're freed
1778             #
1779             if free_container:
1780                 self.c.write('  value = g_datalist_get_data (&proxy->priv->qdata, \"%s\");\n'
1781                              '  if (value != NULL)\n'
1782                              '    return value;\n'
1783                              %(p.name))
1784             self.c.write('  variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \"%s\");\n'%(p.name))
1785             if p.arg.gtype == 'G_TYPE_VARIANT':
1786                 self.c.write('  value = variant;\n')
1787                 self.c.write('  if (variant != NULL)\n')
1788                 self.c.write('    g_variant_unref (variant);\n')
1789             else:
1790                 self.c.write('  if (variant != NULL)\n'
1791                              '    {\n')
1792                 extra_len = ''
1793                 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':
1794                     extra_len = ', NULL'
1795                 self.c.write('      value = %s (variant%s);\n'%(p.arg.gvariant_get, extra_len))
1796                 if free_container:
1797                     self.c.write('      g_datalist_set_data_full (&proxy->priv->qdata, \"%s\", (gpointer) value, g_free);\n'
1798                                  %(p.name))
1799                 self.c.write('      g_variant_unref (variant);\n')
1800                 self.c.write('    }\n')
1801             self.c.write('  return value;\n')
1802             self.c.write('}\n')
1803             self.c.write('\n')
1804
1805         # class boilerplate
1806         self.c.write('static void\n'
1807                      '%s_proxy_init (%sProxy *proxy)\n'
1808                      '{\n'
1809                      '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
1810                      '  proxy->priv = %s_proxy_get_instance_private (proxy);\n'
1811                      '#else\n'
1812                      '  proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %sTYPE_%s_PROXY, %sProxyPrivate);\n'
1813                      '#endif\n\n'
1814                      '  g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
1815                      '}\n'
1816                      '\n'
1817                      %(i.name_lower, i.camel_name,
1818                        i.name_lower,
1819                        i.ns_upper, i.name_upper, i.camel_name,
1820                        i.name_lower))
1821         self.c.write('static void\n'
1822                      '%s_proxy_class_init (%sProxyClass *klass)\n'
1823                      '{\n'
1824                      '  GObjectClass *gobject_class;\n'
1825                      '  GDBusProxyClass *proxy_class;\n'
1826                      '\n'
1827                      '  gobject_class = G_OBJECT_CLASS (klass);\n'
1828                      '  gobject_class->finalize     = %s_proxy_finalize;\n'
1829                      '  gobject_class->get_property = %s_proxy_get_property;\n'
1830                      '  gobject_class->set_property = %s_proxy_set_property;\n'
1831                      '\n'
1832                      '  proxy_class = G_DBUS_PROXY_CLASS (klass);\n'
1833                      '  proxy_class->g_signal = %s_proxy_g_signal;\n'
1834                      '  proxy_class->g_properties_changed = %s_proxy_g_properties_changed;\n'
1835                      '\n'%(i.name_lower, i.camel_name,
1836                            i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
1837         if len(i.properties) > 0:
1838             self.c.write('  %s_override_properties (gobject_class, 1);\n\n'%(i.name_lower))
1839         self.c.write('#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
1840                      '  g_type_class_add_private (klass, sizeof (%sProxyPrivate));\n'
1841                      '#endif\n'%(i.camel_name))
1842         self.c.write('}\n'
1843                      '\n')
1844
1845         self.c.write('static void\n'
1846                      '%s_proxy_iface_init (%sIface *iface)\n'
1847                      '{\n'%(i.name_lower, i.camel_name))
1848         for p in i.properties:
1849             self.c.write('  iface->get_%s = %s_proxy_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
1850         self.c.write('}\n'
1851                      '\n')
1852
1853         # constructors
1854         self.c.write(self.docbook_gen.expand(
1855                 '/**\n'
1856                 ' * %s_proxy_new:\n'
1857                 ' * @connection: A #GDBusConnection.\n'
1858                 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1859                 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1860                 ' * @object_path: An object path.\n'
1861                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1862                 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1863                 ' * @user_data: User data to pass to @callback.\n'
1864                 ' *\n'
1865                 ' * Asynchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new() for more details.\n'
1866                 ' *\n'
1867                 ' * 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'
1868                 ' * You can then call %s_proxy_new_finish() to get the result of the operation.\n'
1869                 ' *\n'
1870                 ' * See %s_proxy_new_sync() for the synchronous, blocking version of this constructor.\n'
1871                 %(i.name_lower, i.name, i.name_lower, i.name_lower), False))
1872         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1873         self.c.write('void\n'
1874                      '%s_proxy_new (\n'
1875                      '    GDBusConnection     *connection,\n'
1876                      '    GDBusProxyFlags      flags,\n'
1877                      '    const gchar         *name,\n'
1878                      '    const gchar         *object_path,\n'
1879                      '    GCancellable        *cancellable,\n'
1880                      '    GAsyncReadyCallback  callback,\n'
1881                      '    gpointer             user_data)\n'
1882                      '{\n'
1883                      '  g_async_initable_new_async (%sTYPE_%s_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "%s", NULL);\n'
1884                      '}\n'
1885                      '\n'
1886                      %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1887         self.c.write('/**\n'
1888                      ' * %s_proxy_new_finish:\n'
1889                      ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new().\n'
1890                      ' * @error: Return location for error or %%NULL\n'
1891                      ' *\n'
1892                      ' * Finishes an operation started with %s_proxy_new().\n'
1893                      ' *\n'
1894                      ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1895                      %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1896         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1897         self.c.write('%s *\n'
1898                      '%s_proxy_new_finish (\n'
1899                      '    GAsyncResult        *res,\n'
1900                      '    GError             **error)\n'
1901                      '{\n'
1902                      '  GObject *ret;\n'
1903                      '  GObject *source_object;\n'
1904                      '  source_object = g_async_result_get_source_object (res);\n'
1905                      '  ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
1906                      '  g_object_unref (source_object);\n'
1907                      '  if (ret != NULL)\n'
1908                      '    return %s%s (ret);\n'
1909                      '  else\n'
1910                      '    return NULL;\n'
1911                      '}\n'
1912                      '\n'
1913                      %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
1914         self.c.write(self.docbook_gen.expand(
1915                 '/**\n'
1916                 ' * %s_proxy_new_sync:\n'
1917                 ' * @connection: A #GDBusConnection.\n'
1918                 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1919                 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
1920                 ' * @object_path: An object path.\n'
1921                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1922                 ' * @error: Return location for error or %%NULL\n'
1923                 ' *\n'
1924                 ' * Synchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new_sync() for more details.\n'
1925                 ' *\n'
1926                 ' * The calling thread is blocked until a reply is received.\n'
1927                 ' *\n'
1928                 ' * See %s_proxy_new() for the asynchronous version of this constructor.\n'
1929                 ' *\n'
1930                 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1931                 %(i.name_lower, i.name, i.name_lower, i.camel_name), False))
1932         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1933         self.c.write('%s *\n'
1934                      '%s_proxy_new_sync (\n'
1935                      '    GDBusConnection     *connection,\n'
1936                      '    GDBusProxyFlags      flags,\n'
1937                      '    const gchar         *name,\n'
1938                      '    const gchar         *object_path,\n'
1939                      '    GCancellable        *cancellable,\n'
1940                      '    GError             **error)\n'
1941                      '{\n'
1942                      '  GInitable *ret;\n'
1943                      '  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'
1944                      '  if (ret != NULL)\n'
1945                      '    return %s%s (ret);\n'
1946                      '  else\n'
1947                      '    return NULL;\n'
1948                      '}\n'
1949                      '\n'
1950                      %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
1951         self.c.write('\n')
1952         self.c.write(self.docbook_gen.expand(
1953                 '/**\n'
1954                 ' * %s_proxy_new_for_bus:\n'
1955                 ' * @bus_type: A #GBusType.\n'
1956                 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
1957                 ' * @name: A bus name (well-known or unique).\n'
1958                 ' * @object_path: An object path.\n'
1959                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
1960                 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
1961                 ' * @user_data: User data to pass to @callback.\n'
1962                 ' *\n'
1963                 ' * Like %s_proxy_new() but takes a #GBusType instead of a #GDBusConnection.\n'
1964                 ' *\n'
1965                 ' * 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'
1966                 ' * You can then call %s_proxy_new_for_bus_finish() to get the result of the operation.\n'
1967                 ' *\n'
1968                 ' * See %s_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
1969                 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower), False))
1970         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1971         self.c.write('void\n'
1972                      '%s_proxy_new_for_bus (\n'
1973                      '    GBusType             bus_type,\n'
1974                      '    GDBusProxyFlags      flags,\n'
1975                      '    const gchar         *name,\n'
1976                      '    const gchar         *object_path,\n'
1977                      '    GCancellable        *cancellable,\n'
1978                      '    GAsyncReadyCallback  callback,\n'
1979                      '    gpointer             user_data)\n'
1980                      '{\n'
1981                      '  g_async_initable_new_async (%sTYPE_%s_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "%s", NULL);\n'
1982                      '}\n'
1983                      '\n'
1984                      %(i.name_lower, i.ns_upper, i.name_upper, i.name))
1985         self.c.write('/**\n'
1986                      ' * %s_proxy_new_for_bus_finish:\n'
1987                      ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new_for_bus().\n'
1988                      ' * @error: Return location for error or %%NULL\n'
1989                      ' *\n'
1990                      ' * Finishes an operation started with %s_proxy_new_for_bus().\n'
1991                      ' *\n'
1992                      ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
1993                      %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
1994         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
1995         self.c.write('%s *\n'
1996                      '%s_proxy_new_for_bus_finish (\n'
1997                      '    GAsyncResult        *res,\n'
1998                      '    GError             **error)\n'
1999                      '{\n'
2000                      '  GObject *ret;\n'
2001                      '  GObject *source_object;\n'
2002                      '  source_object = g_async_result_get_source_object (res);\n'
2003                      '  ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
2004                      '  g_object_unref (source_object);\n'
2005                      '  if (ret != NULL)\n'
2006                      '    return %s%s (ret);\n'
2007                      '  else\n'
2008                      '    return NULL;\n'
2009                      '}\n'
2010                      '\n'
2011                      %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
2012         self.c.write(self.docbook_gen.expand(
2013                 '/**\n'
2014                 ' * %s_proxy_new_for_bus_sync:\n'
2015                 ' * @bus_type: A #GBusType.\n'
2016                 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
2017                 ' * @name: A bus name (well-known or unique).\n'
2018                 ' * @object_path: An object path.\n'
2019                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
2020                 ' * @error: Return location for error or %%NULL\n'
2021                 ' *\n'
2022                 ' * Like %s_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
2023                 ' *\n'
2024                 ' * The calling thread is blocked until a reply is received.\n'
2025                 ' *\n'
2026                 ' * See %s_proxy_new_for_bus() for the asynchronous version of this constructor.\n'
2027                 ' *\n'
2028                 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
2029                 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name), False))
2030         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2031         self.c.write('%s *\n'
2032                      '%s_proxy_new_for_bus_sync (\n'
2033                      '    GBusType             bus_type,\n'
2034                      '    GDBusProxyFlags      flags,\n'
2035                      '    const gchar         *name,\n'
2036                      '    const gchar         *object_path,\n'
2037                      '    GCancellable        *cancellable,\n'
2038                      '    GError             **error)\n'
2039                      '{\n'
2040                      '  GInitable *ret;\n'
2041                      '  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'
2042                      '  if (ret != NULL)\n'
2043                      '    return %s%s (ret);\n'
2044                      '  else\n'
2045                      '    return NULL;\n'
2046                      '}\n'
2047                      '\n'
2048                      %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
2049         self.c.write('\n')
2050
2051     # ---------------------------------------------------------------------------------------------------
2052
2053     def generate_skeleton(self, i):
2054         # class boilerplate
2055         self.c.write('/* ------------------------------------------------------------------------ */\n'
2056                      '\n')
2057
2058         self.c.write(self.docbook_gen.expand(
2059                 '/**\n'
2060                 ' * %sSkeleton:\n'
2061                 ' *\n'
2062                 ' * The #%sSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2063                 %(i.camel_name, i.camel_name), False))
2064         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2065         self.c.write('\n')
2066
2067         self.c.write(self.docbook_gen.expand(
2068                 '/**\n'
2069                 ' * %sSkeletonClass:\n'
2070                 ' * @parent_class: The parent class.\n'
2071                 ' *\n'
2072                 ' * Class structure for #%sSkeleton.\n'
2073                 %(i.camel_name, i.camel_name), False))
2074         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2075         self.c.write('\n')
2076
2077         self.c.write('struct _%sSkeletonPrivate\n'
2078                      '{\n'
2079                      '  GValue *properties;\n'
2080                      '  GList *changed_properties;\n'
2081                      '  GSource *changed_properties_idle_source;\n'
2082                      '  GMainContext *context;\n'
2083                      '  GMutex lock;\n'
2084                      '};\n'
2085                      '\n'%i.camel_name)
2086
2087         self.c.write('static void\n'
2088                      '_%s_skeleton_handle_method_call (\n'
2089                      '  GDBusConnection *connection G_GNUC_UNUSED,\n'
2090                      '  const gchar *sender G_GNUC_UNUSED,\n'
2091                      '  const gchar *object_path G_GNUC_UNUSED,\n'
2092                      '  const gchar *interface_name,\n'
2093                      '  const gchar *method_name,\n'
2094                      '  GVariant *parameters,\n'
2095                      '  GDBusMethodInvocation *invocation,\n'
2096                      '  gpointer user_data)\n'
2097                      '{\n'
2098                      '  %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2099                      '  _ExtendedGDBusMethodInfo *info;\n'
2100                      '  GVariantIter iter;\n'
2101                      '  GVariant *child;\n'
2102                      '  GValue *paramv;\n'
2103                      '  guint num_params;\n'
2104                      '  guint num_extra;\n'
2105                      '  guint n;\n'
2106                      '  guint signal_id;\n'
2107                      '  GValue return_value = G_VALUE_INIT;\n'
2108                      %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2109         self.c.write('  info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n'
2110                      '  g_assert (info != NULL);\n'
2111                      %())
2112         self.c.write ('  num_params = g_variant_n_children (parameters);\n'
2113                       '  num_extra = info->pass_fdlist ? 3 : 2;'
2114                       '  paramv = g_new0 (GValue, num_params + num_extra);\n'
2115                       '  n = 0;\n'
2116                       '  g_value_init (&paramv[n], %sTYPE_%s);\n'
2117                       '  g_value_set_object (&paramv[n++], skeleton);\n'
2118                       '  g_value_init (&paramv[n], G_TYPE_DBUS_METHOD_INVOCATION);\n'
2119                       '  g_value_set_object (&paramv[n++], invocation);\n'
2120                       '  if (info->pass_fdlist)\n'
2121                       '    {\n'
2122                       '#ifdef G_OS_UNIX\n'
2123                       '      g_value_init (&paramv[n], G_TYPE_UNIX_FD_LIST);\n'
2124                       '      g_value_set_object (&paramv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)));\n'
2125                       '#else\n'
2126                       '      g_assert_not_reached ();\n'
2127                       '#endif\n'
2128                       '    }\n'
2129                       %(i.ns_upper, i.name_upper))
2130         self.c.write('  g_variant_iter_init (&iter, parameters);\n'
2131                      '  while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
2132                      '    {\n'
2133                      '      _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra];\n'
2134                      '      if (arg_info->use_gvariant)\n'
2135                      '        {\n'
2136                      '          g_value_init (&paramv[n], G_TYPE_VARIANT);\n'
2137                      '          g_value_set_variant (&paramv[n], child);\n'
2138                      '          n++;\n'
2139                      '        }\n'
2140                      '      else\n'
2141                      '        g_dbus_gvariant_to_gvalue (child, &paramv[n++]);\n'
2142                      '      g_variant_unref (child);\n'
2143                      '    }\n'
2144                      )
2145         self.c.write('  signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
2146                      %(i.ns_upper, i.name_upper))
2147         self.c.write('  g_value_init (&return_value, G_TYPE_BOOLEAN);\n'
2148                      '  g_signal_emitv (paramv, signal_id, 0, &return_value);\n'
2149                      '  if (!g_value_get_boolean (&return_value))\n'
2150                      '    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'
2151                      '  g_value_unset (&return_value);\n'
2152                      )
2153         self.c.write('  for (n = 0; n < num_params + num_extra; n++)\n'
2154                      '    g_value_unset (&paramv[n]);\n'
2155                      '  g_free (paramv);\n')
2156         self.c.write('}\n'
2157                      '\n')
2158
2159         self.c.write('static GVariant *\n'
2160                      '_%s_skeleton_handle_get_property (\n'
2161                      '  GDBusConnection *connection G_GNUC_UNUSED,\n'
2162                      '  const gchar *sender G_GNUC_UNUSED,\n'
2163                      '  const gchar *object_path G_GNUC_UNUSED,\n'
2164                      '  const gchar *interface_name G_GNUC_UNUSED,\n'
2165                      '  const gchar *property_name,\n'
2166                      '  GError **error,\n'
2167                      '  gpointer user_data)\n'
2168                      '{\n'
2169                      '  %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2170                      '  GValue value = G_VALUE_INIT;\n'
2171                      '  GParamSpec *pspec;\n'
2172                      '  _ExtendedGDBusPropertyInfo *info;\n'
2173                      '  GVariant *ret;\n'
2174                      %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2175         self.c.write('  ret = NULL;\n'
2176                      '  info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2177                      '  g_assert (info != NULL);\n'
2178                      '  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2179                      '  if (pspec == NULL)\n'
2180                      '    {\n'
2181                      '      g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2182                      '    }\n'
2183                      '  else\n'
2184                      '    {\n'
2185                      '      g_value_init (&value, pspec->value_type);\n'
2186                      '      g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2187                      '      ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
2188                      '      g_value_unset (&value);\n'
2189                      '    }\n'
2190                      '  return ret;\n'
2191                      '}\n'
2192                      '\n'
2193                      %(i.name_lower))
2194
2195         self.c.write('static gboolean\n'
2196                      '_%s_skeleton_handle_set_property (\n'
2197                      '  GDBusConnection *connection G_GNUC_UNUSED,\n'
2198                      '  const gchar *sender G_GNUC_UNUSED,\n'
2199                      '  const gchar *object_path G_GNUC_UNUSED,\n'
2200                      '  const gchar *interface_name G_GNUC_UNUSED,\n'
2201                      '  const gchar *property_name,\n'
2202                      '  GVariant *variant,\n'
2203                      '  GError **error,\n'
2204                      '  gpointer user_data)\n'
2205                      '{\n'
2206                      '  %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2207                      '  GValue value = G_VALUE_INIT;\n'
2208                      '  GParamSpec *pspec;\n'
2209                      '  _ExtendedGDBusPropertyInfo *info;\n'
2210                      '  gboolean ret;\n'
2211                      %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2212         self.c.write('  ret = FALSE;\n'
2213                      '  info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
2214                      '  g_assert (info != NULL);\n'
2215                      '  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
2216                      '  if (pspec == NULL)\n'
2217                      '    {\n'
2218                      '      g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
2219                      '    }\n'
2220                      '  else\n'
2221                      '    {\n'
2222                      '      if (info->use_gvariant)\n'
2223                      '        g_value_set_variant (&value, variant);\n'
2224                      '      else\n'
2225                      '        g_dbus_gvariant_to_gvalue (variant, &value);\n'
2226                      '      g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
2227                      '      g_value_unset (&value);\n'
2228                      '      ret = TRUE;\n'
2229                      '    }\n'
2230                      '  return ret;\n'
2231                      '}\n'
2232                      '\n'
2233                      %(i.name_lower))
2234
2235
2236         self.c.write('static const GDBusInterfaceVTable _%s_skeleton_vtable =\n'
2237                      '{\n'
2238                      '  _%s_skeleton_handle_method_call,\n'
2239                      '  _%s_skeleton_handle_get_property,\n'
2240                      '  _%s_skeleton_handle_set_property,\n'
2241                      '  {NULL}\n'
2242                      '};\n'
2243                      '\n'%(i.name_lower, i.name_lower, i.name_lower, i.name_lower))
2244
2245         self.c.write('static GDBusInterfaceInfo *\n'
2246                      '%s_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2247                      '{\n'
2248                      '  return %s_interface_info ();\n'
2249                      %(i.name_lower, i.name_lower))
2250         self.c.write('}\n'
2251                      '\n')
2252
2253         self.c.write('static GDBusInterfaceVTable *\n'
2254                      '%s_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
2255                      '{\n'
2256                      '  return (GDBusInterfaceVTable *) &_%s_skeleton_vtable;\n'
2257                      %(i.name_lower, i.name_lower))
2258         self.c.write('}\n'
2259                      '\n')
2260
2261         self.c.write('static GVariant *\n'
2262                      '%s_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton)\n'
2263                      '{\n'
2264                      '  %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2265                      %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2266         self.c.write('\n'
2267                      '  GVariantBuilder builder;\n'
2268                      '  guint n;\n'
2269                      '  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2270                      '  if (_%s_interface_info.parent_struct.properties == NULL)\n'
2271                      '    goto out;\n'
2272                      '  for (n = 0; _%s_interface_info.parent_struct.properties[n] != NULL; n++)\n'
2273                      '    {\n'
2274                      '      GDBusPropertyInfo *info = _%s_interface_info.parent_struct.properties[n];\n'
2275                      '      if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)\n'
2276                      '        {\n'
2277                      '          GVariant *value;\n'
2278                      '          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'
2279                      '          if (value != NULL)\n'
2280                      '            {\n'
2281                      '              g_variant_take_ref (value);\n'
2282                      '              g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
2283                      '              g_variant_unref (value);\n'
2284                      '            }\n'
2285                      '        }\n'
2286                      '    }\n'
2287                      'out:\n'
2288                      '  return g_variant_builder_end (&builder);\n'
2289                      '}\n'
2290                      '\n'
2291                      %(i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name))
2292
2293         if len(i.properties) > 0:
2294             self.c.write('static gboolean _%s_emit_changed (gpointer user_data);\n'
2295                          '\n'
2296                          %(i.name_lower))
2297
2298         self.c.write('static void\n'
2299                      '%s_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton)\n'
2300                      '{\n'
2301                      %(i.name_lower))
2302         if len(i.properties) > 0:
2303             self.c.write('  %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
2304                          '  gboolean emit_changed = FALSE;\n'
2305                          '\n'
2306                          '  g_mutex_lock (&skeleton->priv->lock);\n'
2307                          '  if (skeleton->priv->changed_properties_idle_source != NULL)\n'
2308                          '    {\n'
2309                          '      g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
2310                          '      skeleton->priv->changed_properties_idle_source = NULL;\n'
2311                          '      emit_changed = TRUE;\n'
2312                          '    }\n'
2313                          '  g_mutex_unlock (&skeleton->priv->lock);\n'
2314                          '\n'
2315                          '  if (emit_changed)\n'
2316                          '    _%s_emit_changed (skeleton);\n'
2317                          %(i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2318         self.c.write('}\n'
2319                      '\n')
2320
2321         for s in i.signals:
2322             self.c.write('static void\n'
2323                          '_%s_on_signal_%s (\n'
2324                          '    %s *object'%(i.name_lower, s.name_lower, i.camel_name))
2325             for a in s.args:
2326                 self.c.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
2327             self.c.write(')\n'
2328                          '{\n'
2329                          '  %sSkeleton *skeleton = %s%s_SKELETON (object);\n\n'
2330                          '  GList      *connections, *l;\n'
2331                          '  GVariant   *signal_variant;\n'
2332                          '  connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2333                          %(i.camel_name, i.ns_upper, i.name_upper))
2334             self.c.write('\n'
2335                          '  signal_variant = g_variant_ref_sink (g_variant_new ("(')
2336             for a in s.args:
2337                 self.c.write('%s'%(a.format_in))
2338             self.c.write(')"')
2339             for a in s.args:
2340                 self.c.write(',\n                   arg_%s'%(a.name))
2341             self.c.write('));\n')
2342
2343             self.c.write('  for (l = connections; l != NULL; l = l->next)\n'
2344                          '    {\n'
2345                          '      GDBusConnection *connection = l->data;\n'
2346                          '      g_dbus_connection_emit_signal (connection,\n'
2347                          '        NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", "%s",\n'
2348                          '        signal_variant, NULL);\n'
2349                          '    }\n'
2350                          %(i.name, s.name))
2351             self.c.write('  g_variant_unref (signal_variant);\n')
2352             self.c.write('  g_list_free_full (connections, g_object_unref);\n')
2353             self.c.write('}\n'
2354                          '\n')
2355
2356         self.c.write('static void %s_skeleton_iface_init (%sIface *iface);\n'
2357                      %(i.name_lower, i.camel_name))
2358
2359         self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
2360         self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2361         self.c.write('                         G_ADD_PRIVATE (%sSkeleton)\n'%(i.camel_name))
2362         self.c.write('                         G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2363         self.c.write('#else\n')
2364         self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
2365         self.c.write('                         G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
2366         self.c.write('#endif\n')
2367
2368         # finalize
2369         self.c.write('static void\n'
2370                      '%s_skeleton_finalize (GObject *object)\n'
2371                      '{\n'%(i.name_lower))
2372         self.c.write('  %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2373         if len(i.properties) > 0:
2374             self.c.write('  guint n;\n'
2375                          '  for (n = 0; n < %d; n++)\n'
2376                          '    g_value_unset (&skeleton->priv->properties[n]);\n'%(len(i.properties)))
2377             self.c.write('  g_free (skeleton->priv->properties);\n')
2378         self.c.write('  g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2379         self.c.write('  if (skeleton->priv->changed_properties_idle_source != NULL)\n')
2380         self.c.write('    g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
2381         self.c.write('  g_main_context_unref (skeleton->priv->context);\n')
2382         self.c.write('  g_mutex_clear (&skeleton->priv->lock);\n')
2383         self.c.write('  G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
2384                      '}\n'
2385                      '\n'%(i.name_lower))
2386
2387         # property accessors (TODO: generate PropertiesChanged signals in setter)
2388         if len(i.properties) > 0:
2389             self.c.write('static void\n'
2390                          '%s_skeleton_get_property (GObject      *object,\n'
2391                          '  guint         prop_id,\n'
2392                          '  GValue       *value,\n'
2393                          '  GParamSpec   *pspec G_GNUC_UNUSED)\n'
2394                          '{\n'%(i.name_lower))
2395             self.c.write('  %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2396                          '  g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2397                          '  g_mutex_lock (&skeleton->priv->lock);\n'
2398                          '  g_value_copy (&skeleton->priv->properties[prop_id - 1], value);\n'
2399                          '  g_mutex_unlock (&skeleton->priv->lock);\n'
2400                          %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
2401             self.c.write('}\n'
2402                          '\n')
2403
2404             # if property is already scheduled then re-use entry.. though it could be
2405             # that the user did
2406             #
2407             #  foo_set_prop_bar (object, "");
2408             #  foo_set_prop_bar (object, "blah");
2409             #
2410             # say, every update... In this case, where nothing happens, we obviously
2411             # don't want a PropertiesChanged() event. We can easily check for this
2412             # by comparing against the _original value_ recorded before the first
2413             # change event. If the latest value is not different from the original
2414             # one, we can simply ignore the ChangedProperty
2415             #
2416             self.c.write('static gboolean\n'
2417                          '_%s_emit_changed (gpointer user_data)\n'
2418                          '{\n'
2419                          '  %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
2420                          %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
2421             self.c.write('  GList *l;\n'
2422                          '  GVariantBuilder builder;\n'
2423                          '  GVariantBuilder invalidated_builder;\n'
2424                          '  guint num_changes;\n'
2425                          '\n'
2426                          '  g_mutex_lock (&skeleton->priv->lock);\n'
2427                          '  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
2428                          '  g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
2429                          '  for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
2430                          '    {\n'
2431                          '      ChangedProperty *cp = l->data;\n'
2432                          '      GVariant *variant;\n'
2433                          '      const GValue *cur_value;\n'
2434                          '\n'
2435                          '      cur_value = &skeleton->priv->properties[cp->prop_id - 1];\n'
2436                          '      if (!_g_value_equal (cur_value, &cp->orig_value))\n'
2437                          '        {\n'
2438                          '          variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature));\n'
2439                          '          g_variant_builder_add (&builder, "{sv}", cp->info->parent_struct.name, variant);\n'
2440                          '          g_variant_unref (variant);\n'
2441                          '          num_changes++;\n'
2442                          '        }\n'
2443                          '    }\n'
2444                          '  if (num_changes > 0)\n'
2445                          '    {\n'
2446                          '      GList *connections, *ll;\n'
2447                          '      GVariant *signal_variant;'
2448                          '\n'
2449                          '      signal_variant = g_variant_ref_sink (g_variant_new ("(sa{sv}as)", "%s",\n'
2450                          '                                           &builder, &invalidated_builder));\n'
2451                          '      connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
2452                          '      for (ll = connections; ll != NULL; ll = ll->next)\n'
2453                          '        {\n'
2454                          '          GDBusConnection *connection = ll->data;\n'
2455                          '\n'
2456                          '          g_dbus_connection_emit_signal (connection,\n'
2457                          '                                         NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
2458                          '                                         "org.freedesktop.DBus.Properties",\n'
2459                          '                                         "PropertiesChanged",\n'
2460                          '                                         signal_variant,\n'
2461                          '                                         NULL);\n'
2462                          '        }\n'
2463                          '      g_variant_unref (signal_variant);\n'
2464                          '      g_list_free_full (connections, g_object_unref);\n'
2465                          '    }\n'
2466                          '  else\n'
2467                          '    {\n'
2468                          '      g_variant_builder_clear (&builder);\n'
2469                          '      g_variant_builder_clear (&invalidated_builder);\n'
2470                          '    }\n'
2471                          %(i.name))
2472             self.c.write('  g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
2473             self.c.write('  skeleton->priv->changed_properties = NULL;\n')
2474             self.c.write('  skeleton->priv->changed_properties_idle_source = NULL;\n')
2475             self.c.write('  g_mutex_unlock (&skeleton->priv->lock);\n')
2476             self.c.write('  return FALSE;\n'
2477                          '}\n'
2478                          '\n')
2479             # holding lock while being called
2480             self.c.write('static void\n'
2481                          '_%s_schedule_emit_changed (%sSkeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value)\n'
2482                          '{\n'
2483                          '  ChangedProperty *cp;\n'
2484                          '  GList *l;\n'
2485                          '  cp = NULL;\n'
2486                          '  for (l = skeleton->priv->changed_properties; l != NULL; l = l->next)\n'
2487                          '    {\n'
2488                          '      ChangedProperty *i_cp = l->data;\n'
2489                          '      if (i_cp->info == info)\n'
2490                          '        {\n'
2491                          '          cp = i_cp;\n'
2492                          '          break;\n'
2493                          '        }\n'
2494                          '    }\n'
2495                          %(i.name_lower, i.camel_name))
2496             self.c.write('  if (cp == NULL)\n'
2497                          '    {\n'
2498                          '      cp = g_new0 (ChangedProperty, 1);\n'
2499                          '      cp->prop_id = prop_id;\n'
2500                          '      cp->info = info;\n'
2501                          '      skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp);\n'
2502                          '      g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value));\n'
2503                          '      g_value_copy (orig_value, &cp->orig_value);\n'
2504                          '    }\n'
2505                          '}\n'
2506                          '\n'
2507                          %())
2508
2509             # Postpone setting up the refresh source until the ::notify signal is emitted as
2510             # this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
2511             # This is useful when updating several properties from another thread than
2512             # where the idle will be emitted from
2513             self.c.write('static void\n'
2514                          '%s_skeleton_notify (GObject      *object,\n'
2515                          '  GParamSpec *pspec G_GNUC_UNUSED)\n'
2516                          '{\n'
2517                          '  %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2518                          '  g_mutex_lock (&skeleton->priv->lock);\n'
2519                          '  if (skeleton->priv->changed_properties != NULL &&\n'
2520                          '      skeleton->priv->changed_properties_idle_source == NULL)\n'
2521                          '    {\n'
2522                          '      skeleton->priv->changed_properties_idle_source = g_idle_source_new ();\n'
2523                          '      g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);\n'
2524                          '      g_source_set_callback (skeleton->priv->changed_properties_idle_source, _%s_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);\n'
2525                          '      g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
2526                          '      g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
2527                          '    }\n'
2528                          '  g_mutex_unlock (&skeleton->priv->lock);\n'
2529                          '}\n'
2530                          '\n'
2531                          %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
2532
2533             self.c.write('static void\n'
2534                          '%s_skeleton_set_property (GObject      *object,\n'
2535                          '  guint         prop_id,\n'
2536                          '  const GValue *value,\n'
2537                          '  GParamSpec   *pspec)\n'
2538                          '{\n'%(i.name_lower))
2539             self.c.write('  %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
2540                          '  g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
2541                          '  g_mutex_lock (&skeleton->priv->lock);\n'
2542                          '  g_object_freeze_notify (object);\n'
2543                          '  if (!_g_value_equal (value, &skeleton->priv->properties[prop_id - 1]))\n'
2544                          '    {\n'
2545                          '      if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
2546                          '        _%s_schedule_emit_changed (skeleton, _%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties[prop_id - 1]);\n'
2547                          '      g_value_copy (value, &skeleton->priv->properties[prop_id - 1]);\n'
2548                          '      g_object_notify_by_pspec (object, pspec);\n'
2549                          '    }\n'
2550                          '  g_mutex_unlock (&skeleton->priv->lock);\n'
2551                          '  g_object_thaw_notify (object);\n'
2552                          %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
2553             self.c.write('}\n'
2554                          '\n')
2555
2556         self.c.write('static void\n'
2557                      '%s_skeleton_init (%sSkeleton *skeleton)\n'
2558                      '{\n'
2559                      '#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
2560                      '  skeleton->priv = %s_skeleton_get_instance_private (skeleton);\n'
2561                      '#else\n'
2562                      '  skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
2563                      '#endif\n\n'
2564                      %(i.name_lower, i.camel_name,
2565                        i.name_lower,
2566                        i.ns_upper, i.name_upper, i.camel_name))
2567         self.c.write('  g_mutex_init (&skeleton->priv->lock);\n')
2568         self.c.write('  skeleton->priv->context = g_main_context_ref_thread_default ();\n')
2569         if len(i.properties) > 0:
2570             self.c.write('  skeleton->priv->properties = g_new0 (GValue, %d);\n'%(len(i.properties)))
2571             n = 0
2572             for p in i.properties:
2573                 self.c.write('  g_value_init (&skeleton->priv->properties[%d], %s);\n'%(n, p.arg.gtype))
2574                 n += 1
2575         self.c.write('}\n'
2576                      '\n')
2577
2578         # property vfuncs
2579         n = 0
2580         for p in i.properties:
2581             self.c.write('static %s\n'
2582                          '%s_skeleton_get_%s (%s *object)\n'
2583                          '{\n'
2584                          %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
2585             self.c.write('  %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
2586             self.c.write('  %svalue;\n'
2587                          '  g_mutex_lock (&skeleton->priv->lock);\n'
2588                          '  value = %s (&(skeleton->priv->properties[%d]));\n'
2589                          '  g_mutex_unlock (&skeleton->priv->lock);\n'
2590                          %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
2591             self.c.write('  return value;\n')
2592             self.c.write('}\n')
2593             self.c.write('\n')
2594             n += 1
2595
2596         self.c.write('static void\n'
2597                      '%s_skeleton_class_init (%sSkeletonClass *klass)\n'
2598                      '{\n'
2599                      '  GObjectClass *gobject_class;\n'
2600                      '  GDBusInterfaceSkeletonClass *skeleton_class;\n'
2601                      '\n'
2602                      '  gobject_class = G_OBJECT_CLASS (klass);\n'
2603                      '  gobject_class->finalize = %s_skeleton_finalize;\n'
2604                      %(i.name_lower, i.camel_name, i.name_lower))
2605         if len(i.properties) > 0:
2606             self.c.write('  gobject_class->get_property = %s_skeleton_get_property;\n'
2607                          '  gobject_class->set_property = %s_skeleton_set_property;\n'
2608                          '  gobject_class->notify       = %s_skeleton_notify;\n'
2609                          '\n'%(i.name_lower, i.name_lower, i.name_lower))
2610             self.c.write('\n'
2611                          '  %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
2612         self.c.write('\n'
2613                      '  skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);\n');
2614         self.c.write('  skeleton_class->get_info = %s_skeleton_dbus_interface_get_info;\n'%(i.name_lower))
2615         self.c.write('  skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
2616         self.c.write('  skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
2617         self.c.write('  skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
2618
2619         self.c.write('\n'
2620                      '#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
2621                      '  g_type_class_add_private (klass, sizeof (%sSkeletonPrivate));\n'
2622                      '#endif\n'%(i.camel_name))
2623
2624         self.c.write('}\n'
2625                      '\n')
2626
2627         self.c.write('static void\n'
2628                      '%s_skeleton_iface_init (%sIface *iface)\n'
2629                      '{\n'
2630                      %(i.name_lower, i.camel_name))
2631         for s in i.signals:
2632             self.c.write('  iface->%s = _%s_on_signal_%s;\n'
2633                          %(s.name_lower, i.name_lower, s.name_lower))
2634         for p in i.properties:
2635             self.c.write('  iface->get_%s = %s_skeleton_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
2636         self.c.write('}\n'
2637                      '\n')
2638
2639         # constructors
2640         self.c.write(self.docbook_gen.expand(
2641                 '/**\n'
2642                 ' * %s_skeleton_new:\n'
2643                 ' *\n'
2644                 ' * Creates a skeleton object for the D-Bus interface #%s.\n'
2645                 ' *\n'
2646                 ' * Returns: (transfer full) (type %sSkeleton): The skeleton object.\n'
2647                 %(i.name_lower, i.name, i.camel_name), False))
2648         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2649         self.c.write('%s *\n'
2650                      '%s_skeleton_new (void)\n'
2651                      '{\n'
2652                      '  return %s%s (g_object_new (%sTYPE_%s_SKELETON, NULL));\n'
2653                      '}\n'
2654                      '\n'%(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
2655
2656     # ---------------------------------------------------------------------------------------------------
2657
2658     def generate_object(self):
2659         self.c.write('/* ------------------------------------------------------------------------\n'
2660                      ' * Code for Object, ObjectProxy and ObjectSkeleton\n'
2661                      ' * ------------------------------------------------------------------------\n'
2662                      ' */\n'
2663                      '\n')
2664
2665         self.c.write(self.docbook_gen.expand(
2666                 '/**\n'
2667                 ' * SECTION:%sObject\n'
2668                 ' * @title: %sObject\n'
2669                 ' * @short_description: Specialized GDBusObject types\n'
2670                 ' *\n'
2671                 ' * This section contains the #%sObject, #%sObjectProxy, and #%sObjectSkeleton types which make it easier to work with objects implementing generated types for D-Bus interfaces.\n'
2672                 ' */\n'
2673                 %(self.namespace, self.namespace, self.namespace, self.namespace, self.namespace), False))
2674         self.c.write('\n')
2675
2676         self.c.write(self.docbook_gen.expand(
2677                 '/**\n'
2678                 ' * %sObject:\n'
2679                 ' *\n'
2680                 ' * The #%sObject type is a specialized container of interfaces.\n'
2681                 ' */\n'
2682                 %(self.namespace, self.namespace), False))
2683         self.c.write('\n')
2684
2685         self.c.write(self.docbook_gen.expand(
2686                 '/**\n'
2687                 ' * %sObjectIface:\n'
2688                 ' * @parent_iface: The parent interface.\n'
2689                 ' *\n'
2690                 ' * Virtual table for the #%sObject interface.\n'
2691                 ' */\n'
2692                 %(self.namespace, self.namespace), False))
2693         self.c.write('\n')
2694
2695         self.c.write('typedef %sObjectIface %sObjectInterface;\n'%(self.namespace, self.namespace))
2696         self.c.write('G_DEFINE_INTERFACE_WITH_CODE (%sObject, %sobject, G_TYPE_OBJECT, g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_DBUS_OBJECT));\n'%(self.namespace, self.ns_lower))
2697         self.c.write('\n')
2698         self.c.write('static void\n'
2699                      '%sobject_default_init (%sObjectIface *iface)\n'
2700                      '{\n'
2701                      %(self.ns_lower, self.namespace));
2702         for i in self.ifaces:
2703             self.c.write(self.docbook_gen.expand(
2704                     '  /**\n'
2705                     '   * %sObject:%s:\n'
2706                     '   *\n'
2707                     '   * The #%s instance corresponding to the D-Bus interface #%s, if any.\n'
2708                     '   *\n'
2709                     '   * Connect to the #GObject::notify signal to get informed of property changes.\n'
2710                     %(self.namespace, i.name_hyphen, i.camel_name, i.name), False))
2711             self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 2)
2712             self.c.write('  g_object_interface_install_property (iface, g_param_spec_object ("%s", "%s", "%s", %sTYPE_%s, G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS));\n'
2713                          '\n'
2714                          %(i.name_hyphen, i.name_hyphen, i.name_hyphen, self.ns_upper, i.name_upper))
2715         self.c.write('}\n'
2716                      '\n')
2717
2718         for i in self.ifaces:
2719             self.c.write(self.docbook_gen.expand(
2720                     '/**\n'
2721                     ' * %sobject_get_%s:\n'
2722                     ' * @object: A #%sObject.\n'
2723                     ' *\n'
2724                     ' * Gets the #%s instance for the D-Bus interface #%s on @object, if any.\n'
2725                     ' *\n'
2726                     ' * Returns: (transfer full): A #%s that must be freed with g_object_unref() or %%NULL if @object does not implement the interface.\n'
2727                     %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.name, i.camel_name), False))
2728             self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2729             self.c.write ('%s *%sobject_get_%s (%sObject *object)\n'
2730                           %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2731             self.c.write('{\n'
2732                          '  GDBusInterface *ret;\n'
2733                          '  ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2734                          '  if (ret == NULL)\n'
2735                          '    return NULL;\n'
2736                          '  return %s%s (ret);\n'
2737                          '}\n'
2738                          '\n'
2739                          %(i.name, self.ns_upper, i.name_upper))
2740         self.c.write('\n')
2741         for i in self.ifaces:
2742             self.c.write(self.docbook_gen.expand(
2743                     '/**\n'
2744                     ' * %sobject_peek_%s: (skip)\n'
2745                     ' * @object: A #%sObject.\n'
2746                     ' *\n'
2747                     ' * Like %sobject_get_%s() but doesn\'t increase the reference count on the returned object.\n'
2748                     ' *\n'
2749                     ' * <warning>It is not safe to use the returned object if you are on another thread than the one where the #GDBusObjectManagerClient or #GDBusObjectManagerServer for @object is running.</warning>\n'
2750                     ' *\n'
2751                     ' * 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'
2752                     %(self.ns_lower, i.name_upper.lower(), self.namespace, self.ns_lower, i.name_upper.lower(), i.camel_name), False))
2753             self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
2754             self.c.write ('%s *%sobject_peek_%s (%sObject *object)\n'
2755                           %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
2756             self.c.write('{\n'
2757                          '  GDBusInterface *ret;\n'
2758                          '  ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2759                          '  if (ret == NULL)\n'
2760                          '    return NULL;\n'
2761                          '  g_object_unref (ret);\n'
2762                          '  return %s%s (ret);\n'
2763                          '}\n'
2764                          '\n'
2765                          %(i.name, self.ns_upper, i.name_upper))
2766         self.c.write('\n')
2767         # shared by ObjectProxy and ObjectSkeleton classes
2768         self.c.write('static void\n'
2769                      '%sobject_notify (GDBusObject *object, GDBusInterface *interface)\n'
2770                      '{\n'
2771                      '  _ExtendedGDBusInterfaceInfo *info = (_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface);\n'
2772                      '  /* info can be NULL if the other end is using a D-Bus interface we don\'t know\n'
2773                      '   * anything about, for example old generated code in this process talking to\n'
2774                      '   * newer generated code in the other process. */\n'
2775                      '  if (info != NULL)\n'
2776                      '    g_object_notify (G_OBJECT (object), info->hyphen_name);\n'
2777                      '}\n'
2778                      '\n'
2779                      %(self.ns_lower))
2780
2781         self.c.write(self.docbook_gen.expand(
2782                 '/**\n'
2783                 ' * %sObjectProxy:\n'
2784                 ' *\n'
2785                 ' * The #%sObjectProxy structure contains only private data and should only be accessed using the provided API.\n'
2786                 %(self.namespace, self.namespace), False))
2787         self.c.write(' */\n')
2788         self.c.write('\n')
2789         self.c.write(self.docbook_gen.expand(
2790                 '/**\n'
2791                 ' * %sObjectProxyClass:\n'
2792                 ' * @parent_class: The parent class.\n'
2793                 ' *\n'
2794                 ' * Class structure for #%sObjectProxy.\n'
2795                 %(self.namespace, self.namespace), False))
2796         self.c.write(' */\n')
2797         self.c.write('\n')
2798         # class boilerplate
2799         self.c.write('static void\n'
2800                      '%sobject_proxy__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2801                      '{\n'
2802                      '}\n'
2803                      '\n'
2804                      %(self.ns_lower, self.ns_lower, self.namespace))
2805         self.c.write('static void\n'
2806                      '%sobject_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2807                      '{\n'
2808                      '  iface->interface_added = %sobject_notify;\n'
2809                      '  iface->interface_removed = %sobject_notify;\n'
2810                      '}\n'
2811                      '\n'
2812                      %(self.ns_lower, self.ns_lower, self.ns_lower))
2813         self.c.write('\n')
2814         self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectProxy, %sobject_proxy, G_TYPE_DBUS_OBJECT_PROXY,\n'
2815                      '                         G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_proxy__%sobject_iface_init)\n'
2816                      '                         G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_proxy__g_dbus_object_iface_init));\n'
2817                      '\n'
2818                      %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2819         # class boilerplate
2820         self.c.write('static void\n'
2821                      '%sobject_proxy_init (%sObjectProxy *object G_GNUC_UNUSED)\n'
2822                      '{\n'
2823                      '}\n'
2824                      '\n'%(self.ns_lower, self.namespace))
2825         self.c.write('static void\n'
2826                      '%sobject_proxy_set_property (GObject      *gobject,\n'
2827                      '  guint         prop_id,\n'
2828                      '  const GValue *value G_GNUC_UNUSED,\n'
2829                      '  GParamSpec   *pspec)\n'
2830                      '{\n'
2831                      '  G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2832                      %(self.ns_lower))
2833         self.c.write('}\n'
2834                      '\n'%())
2835         self.c.write('static void\n'
2836                      '%sobject_proxy_get_property (GObject      *gobject,\n'
2837                      '  guint         prop_id,\n'
2838                      '  GValue       *value,\n'
2839                      '  GParamSpec   *pspec)\n'
2840                      '{\n'
2841                      '  %sObjectProxy *object = %sOBJECT_PROXY (gobject);\n'
2842                      '  GDBusInterface *interface;\n'
2843                      '\n'
2844                      '  switch (prop_id)\n'
2845                      '    {\n'
2846                      %(self.ns_lower, self.namespace, self.ns_upper))
2847         n = 1
2848         for i in self.ifaces:
2849             self.c.write('    case %d:\n'
2850                          '      interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2851                          '      g_value_take_object (value, interface);\n'
2852                          '      break;\n'
2853                          '\n'
2854                          %(n, i.name))
2855             n += 1
2856         self.c.write('    default:\n'
2857                      '      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2858                      '      break;\n'
2859                      '  }\n'
2860                      '}\n'
2861                      '\n'%())
2862         self.c.write('static void\n'
2863                      '%sobject_proxy_class_init (%sObjectProxyClass *klass)\n'
2864                      '{\n'
2865                      '  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
2866                      '\n'
2867                      '  gobject_class->set_property = %sobject_proxy_set_property;\n'
2868                      '  gobject_class->get_property = %sobject_proxy_get_property;\n'
2869                      '\n'
2870                      %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
2871         n = 1
2872         for i in self.ifaces:
2873             self.c.write('  g_object_class_override_property (gobject_class, %d, "%s");'
2874                          '\n'
2875                          %(n, i.name_hyphen))
2876             n += 1
2877         self.c.write('}\n'
2878                      '\n')
2879
2880         self.c.write(self.docbook_gen.expand(
2881                 '/**\n'
2882                 ' * %sobject_proxy_new:\n'
2883                 ' * @connection: A #GDBusConnection.\n'
2884                 ' * @object_path: An object path.\n'
2885                 ' *\n'
2886                 ' * Creates a new proxy object.\n'
2887                 ' *\n'
2888                 ' * Returns: (transfer full): The proxy object.\n'
2889                 ' */\n'
2890                 %(self.ns_lower), False))
2891         self.c.write('%sObjectProxy *\n'
2892                      '%sobject_proxy_new (GDBusConnection *connection,\n'
2893                      '  const gchar *object_path)\n'
2894                      '{\n'
2895                      '  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);\n'
2896                      '  g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
2897                      '  return %sOBJECT_PROXY (g_object_new (%sTYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL));\n'
2898                      '}\n'
2899                      '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
2900
2901         self.c.write(self.docbook_gen.expand(
2902                 '/**\n'
2903                 ' * %sObjectSkeleton:\n'
2904                 ' *\n'
2905                 ' * The #%sObjectSkeleton structure contains only private data and should only be accessed using the provided API.\n'
2906                 %(self.namespace, self.namespace), False))
2907         self.c.write(' */\n')
2908         self.c.write('\n')
2909         self.c.write(self.docbook_gen.expand(
2910                 '/**\n'
2911                 ' * %sObjectSkeletonClass:\n'
2912                 ' * @parent_class: The parent class.\n'
2913                 ' *\n'
2914                 ' * Class structure for #%sObjectSkeleton.\n'
2915                 %(self.namespace, self.namespace), False))
2916         self.c.write(' */\n')
2917         self.c.write('\n')
2918         # class boilerplate
2919         self.c.write('static void\n'
2920                      '%sobject_skeleton__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
2921                      '{\n'
2922                      '}\n'
2923                      '\n'
2924                      %(self.ns_lower, self.ns_lower, self.namespace))
2925         self.c.write('\n')
2926         self.c.write('static void\n'
2927                      '%sobject_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
2928                      '{\n'
2929                      '  iface->interface_added = %sobject_notify;\n'
2930                      '  iface->interface_removed = %sobject_notify;\n'
2931                      '}\n'
2932                      '\n'
2933                      %(self.ns_lower, self.ns_lower, self.ns_lower))
2934         self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectSkeleton, %sobject_skeleton, G_TYPE_DBUS_OBJECT_SKELETON,\n'
2935                      '                         G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_skeleton__%sobject_iface_init)\n'
2936                      '                         G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_skeleton__g_dbus_object_iface_init));\n'
2937                      '\n'
2938                      %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
2939         # class boilerplate
2940         self.c.write('static void\n'
2941                      '%sobject_skeleton_init (%sObjectSkeleton *object G_GNUC_UNUSED)\n'
2942                      '{\n'
2943                      '}\n'
2944                      '\n'%(self.ns_lower, self.namespace))
2945         self.c.write('static void\n'
2946                      '%sobject_skeleton_set_property (GObject      *gobject,\n'
2947                      '  guint         prop_id,\n'
2948                      '  const GValue *value,\n'
2949                      '  GParamSpec   *pspec)\n'
2950                      '{\n'
2951                      '  %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2952                      '  GDBusInterfaceSkeleton *interface;\n'
2953                      '\n'
2954                      '  switch (prop_id)\n'
2955                      '    {\n'
2956                      %(self.ns_lower, self.namespace, self.ns_upper))
2957         n = 1
2958         for i in self.ifaces:
2959             self.c.write('    case %d:\n'
2960                          '      interface = g_value_get_object (value);\n'
2961                          '      if (interface != NULL)\n'
2962                          '        {\n'
2963                          '          g_warn_if_fail (%sIS_%s (interface));\n'
2964                          '          g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface);\n'
2965                          '        }\n'
2966                          '      else\n'
2967                          '        {\n'
2968                          '          g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "%s");\n'
2969                          '        }\n'
2970                          '      break;\n'
2971                          '\n'
2972                          %(n, self.ns_upper, i.name_upper, i.name))
2973             n += 1
2974         self.c.write('    default:\n'
2975                      '      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
2976                      '      break;\n'
2977                      '  }\n'
2978                      '}\n'
2979                      '\n'%())
2980         self.c.write('static void\n'
2981                      '%sobject_skeleton_get_property (GObject      *gobject,\n'
2982                      '  guint         prop_id,\n'
2983                      '  GValue       *value,\n'
2984                      '  GParamSpec   *pspec)\n'
2985                      '{\n'
2986                      '  %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
2987                      '  GDBusInterface *interface;\n'
2988                      '\n'
2989                      '  switch (prop_id)\n'
2990                      '    {\n'
2991                      %(self.ns_lower, self.namespace, self.ns_upper))
2992         n = 1
2993         for i in self.ifaces:
2994             self.c.write('    case %d:\n'
2995                          '      interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
2996                          '      g_value_take_object (value, interface);\n'
2997                          '      break;\n'
2998                          '\n'
2999                          %(n, i.name))
3000             n += 1
3001         self.c.write('    default:\n'
3002                      '      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
3003                      '      break;\n'
3004                      '  }\n'
3005                      '}\n'
3006                      '\n'%())
3007         self.c.write('static void\n'
3008                      '%sobject_skeleton_class_init (%sObjectSkeletonClass *klass)\n'
3009                      '{\n'
3010                      '  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
3011                      '\n'
3012                      '  gobject_class->set_property = %sobject_skeleton_set_property;\n'
3013                      '  gobject_class->get_property = %sobject_skeleton_get_property;\n'
3014                      '\n'
3015                      %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
3016         n = 1
3017         for i in self.ifaces:
3018             self.c.write('  g_object_class_override_property (gobject_class, %d, "%s");'
3019                          '\n'
3020                          %(n, i.name_hyphen))
3021             n += 1
3022         self.c.write('}\n'
3023                      '\n')
3024         self.c.write(self.docbook_gen.expand(
3025                 '/**\n'
3026                 ' * %sobject_skeleton_new:\n'
3027                 ' * @object_path: An object path.\n'
3028                 ' *\n'
3029                 ' * Creates a new skeleton object.\n'
3030                 ' *\n'
3031                 ' * Returns: (transfer full): The skeleton object.\n'
3032                 ' */\n'
3033                 %(self.ns_lower), False))
3034         self.c.write('%sObjectSkeleton *\n'
3035                      '%sobject_skeleton_new (const gchar *object_path)\n'
3036                      '{\n'
3037                      '  g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
3038                      '  return %sOBJECT_SKELETON (g_object_new (%sTYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL));\n'
3039                      '}\n'
3040                      '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
3041         for i in self.ifaces:
3042             self.c.write(self.docbook_gen.expand(
3043                     '/**\n'
3044                     ' * %sobject_skeleton_set_%s:\n'
3045                     ' * @object: A #%sObjectSkeleton.\n'
3046                     ' * @interface_: (allow-none): A #%s or %%NULL to clear the interface.\n'
3047                     ' *\n'
3048                     ' * Sets the #%s instance for the D-Bus interface #%s on @object.\n'
3049                     %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.camel_name, i.name), False))
3050             self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
3051             self.c.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_)\n'
3052                           %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
3053             self.c.write('{\n'
3054                          '  g_object_set (G_OBJECT (object), "%s", interface_, NULL);\n'
3055                          '}\n'
3056                          '\n'
3057                          %(i.name_hyphen))
3058         self.c.write('\n')
3059
3060
3061     def generate_object_manager_client(self):
3062         self.c.write('/* ------------------------------------------------------------------------\n'
3063                      ' * Code for ObjectManager client\n'
3064                      ' * ------------------------------------------------------------------------\n'
3065                      ' */\n'
3066                      '\n')
3067
3068         self.c.write(self.docbook_gen.expand(
3069                 '/**\n'
3070                 ' * SECTION:%sObjectManagerClient\n'
3071                 ' * @title: %sObjectManagerClient\n'
3072                 ' * @short_description: Generated GDBusObjectManagerClient type\n'
3073                 ' *\n'
3074                 ' * This section contains a #GDBusObjectManagerClient that uses %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc.\n'
3075                 ' */\n'
3076                 %(self.namespace, self.namespace, self.ns_lower), False))
3077         self.c.write('\n')
3078
3079         self.c.write(self.docbook_gen.expand(
3080                 '/**\n'
3081                 ' * %sObjectManagerClient:\n'
3082                 ' *\n'
3083                 ' * The #%sObjectManagerClient structure contains only private data and should only be accessed using the provided API.\n'
3084                 %(self.namespace, self.namespace), False))
3085         self.c.write(' */\n')
3086         self.c.write('\n')
3087
3088         self.c.write(self.docbook_gen.expand(
3089                 '/**\n'
3090                 ' * %sObjectManagerClientClass:\n'
3091                 ' * @parent_class: The parent class.\n'
3092                 ' *\n'
3093                 ' * Class structure for #%sObjectManagerClient.\n'
3094                 %(self.namespace, self.namespace), False))
3095         self.c.write(' */\n')
3096         self.c.write('\n')
3097
3098         # class boilerplate
3099         self.c.write('G_DEFINE_TYPE (%sObjectManagerClient, %sobject_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT);\n'
3100                      '\n'
3101                      %(self.namespace, self.ns_lower))
3102
3103         # class boilerplate
3104         self.c.write('static void\n'
3105                      '%sobject_manager_client_init (%sObjectManagerClient *manager G_GNUC_UNUSED)\n'
3106                      '{\n'
3107                      '}\n'
3108                      '\n'%(self.ns_lower, self.namespace))
3109         self.c.write('static void\n'
3110                      '%sobject_manager_client_class_init (%sObjectManagerClientClass *klass G_GNUC_UNUSED)\n'
3111                      '{\n'
3112                      '}\n'
3113                      '\n'%(self.ns_lower, self.namespace))
3114
3115         self.c.write(self.docbook_gen.expand(
3116                 '/**\n'
3117                 ' * %sobject_manager_client_get_proxy_type:\n'
3118                 ' * @manager: A #GDBusObjectManagerClient.\n'
3119                 ' * @object_path: The object path of the remote object (unused).\n'
3120                 ' * @interface_name: (allow-none): Interface name of the remote object or %%NULL to get the object proxy #GType.\n'
3121                 ' * @user_data: User data (unused).\n'
3122                 ' *\n'
3123                 ' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types.\n'
3124                 ' *\n'
3125                 ' * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %%NULL, otherwise the #GType for #%sObjectProxy.\n'
3126                 %(self.ns_lower, self.namespace), False))
3127         self.c.write(' */\n')
3128         self.c.write('GType\n'
3129                      '%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'
3130                      '{\n'
3131                      %(self.ns_lower))
3132         self.c.write('  static gsize once_init_value = 0;\n'
3133                      '  static GHashTable *lookup_hash;\n'
3134                      '  GType ret;\n'
3135                      '\n'
3136                      '  if (interface_name == NULL)\n'
3137                      '    return %sTYPE_OBJECT_PROXY;\n'
3138                      '  if (g_once_init_enter (&once_init_value))\n'
3139                      '    {\n'
3140                      '      lookup_hash = g_hash_table_new (g_str_hash, g_str_equal);\n'
3141                      %(self.ns_upper))
3142         for i in self.ifaces:
3143             self.c.write('      g_hash_table_insert (lookup_hash, (gpointer) "%s", GSIZE_TO_POINTER (%sTYPE_%s_PROXY));\n'
3144                          %(i.name, i.ns_upper, i.name_upper))
3145         self.c.write('      g_once_init_leave (&once_init_value, 1);\n'
3146                      '    }\n')
3147         self.c.write('  ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name));\n'
3148                      '  if (ret == (GType) 0)\n'
3149                      '    ret = G_TYPE_DBUS_PROXY;\n')
3150         self.c.write('  return ret;\n'
3151                      '}\n'
3152                      '\n')
3153
3154         # constructors
3155         self.c.write(self.docbook_gen.expand(
3156                 '/**\n'
3157                 ' * %sobject_manager_client_new:\n'
3158                 ' * @connection: A #GDBusConnection.\n'
3159                 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3160                 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3161                 ' * @object_path: An object path.\n'
3162                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3163                 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3164                 ' * @user_data: User data to pass to @callback.\n'
3165                 ' *\n'
3166                 ' * Asynchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details.\n'
3167                 ' *\n'
3168                 ' * 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'
3169                 ' * You can then call %sobject_manager_client_new_finish() to get the result of the operation.\n'
3170                 ' *\n'
3171                 ' * See %sobject_manager_client_new_sync() for the synchronous, blocking version of this constructor.\n'
3172                 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3173         self.c.write(' */\n')
3174         self.c.write('void\n'
3175                      '%sobject_manager_client_new (\n'
3176                      '    GDBusConnection        *connection,\n'
3177                      '    GDBusObjectManagerClientFlags  flags,\n'
3178                      '    const gchar            *name,\n'
3179                      '    const gchar            *object_path,\n'
3180                      '    GCancellable           *cancellable,\n'
3181                      '    GAsyncReadyCallback     callback,\n'
3182                      '    gpointer                user_data)\n'
3183                      '{\n'
3184                      '  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'
3185                      '}\n'
3186                      '\n'
3187                      %(self.ns_lower, self.ns_upper, self.ns_lower))
3188         self.c.write('/**\n'
3189                      ' * %sobject_manager_client_new_finish:\n'
3190                      ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new().\n'
3191                      ' * @error: Return location for error or %%NULL\n'
3192                      ' *\n'
3193                      ' * Finishes an operation started with %sobject_manager_client_new().\n'
3194                      ' *\n'
3195                      ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3196                      %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3197         self.c.write(' */\n')
3198         self.c.write('GDBusObjectManager *\n'
3199                      '%sobject_manager_client_new_finish (\n'
3200                      '    GAsyncResult        *res,\n'
3201                      '    GError             **error)\n'
3202                      '{\n'
3203                      '  GObject *ret;\n'
3204                      '  GObject *source_object;\n'
3205                      '  source_object = g_async_result_get_source_object (res);\n'
3206                      '  ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3207                      '  g_object_unref (source_object);\n'
3208                      '  if (ret != NULL)\n'
3209                      '    return G_DBUS_OBJECT_MANAGER (ret);\n'
3210                      '  else\n'
3211                      '    return NULL;\n'
3212                      '}\n'
3213                      '\n'
3214                      %(self.ns_lower))
3215         self.c.write(self.docbook_gen.expand(
3216                 '/**\n'
3217                 ' * %sobject_manager_client_new_sync:\n'
3218                 ' * @connection: A #GDBusConnection.\n'
3219                 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3220                 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
3221                 ' * @object_path: An object path.\n'
3222                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3223                 ' * @error: Return location for error or %%NULL\n'
3224                 ' *\n'
3225                 ' * Synchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new_sync() for more details.\n'
3226                 ' *\n'
3227                 ' * The calling thread is blocked until a reply is received.\n'
3228                 ' *\n'
3229                 ' * See %sobject_manager_client_new() for the asynchronous version of this constructor.\n'
3230                 ' *\n'
3231                 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3232                 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3233         self.c.write(' */\n')
3234         self.c.write('GDBusObjectManager *\n'
3235                      '%sobject_manager_client_new_sync (\n'
3236                      '    GDBusConnection        *connection,\n'
3237                      '    GDBusObjectManagerClientFlags  flags,\n'
3238                      '    const gchar            *name,\n'
3239                      '    const gchar            *object_path,\n'
3240                      '    GCancellable           *cancellable,\n'
3241                      '    GError                **error)\n'
3242                      '{\n'
3243                      '  GInitable *ret;\n'
3244                      '  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'
3245                      '  if (ret != NULL)\n'
3246                      '    return G_DBUS_OBJECT_MANAGER (ret);\n'
3247                      '  else\n'
3248                      '    return NULL;\n'
3249                      '}\n'
3250                      '\n'
3251                      %(self.ns_lower, self.ns_upper, self.ns_lower))
3252         self.c.write('\n')
3253         self.c.write(self.docbook_gen.expand(
3254                 '/**\n'
3255                 ' * %sobject_manager_client_new_for_bus:\n'
3256                 ' * @bus_type: A #GBusType.\n'
3257                 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3258                 ' * @name: A bus name (well-known or unique).\n'
3259                 ' * @object_path: An object path.\n'
3260                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3261                 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
3262                 ' * @user_data: User data to pass to @callback.\n'
3263                 ' *\n'
3264                 ' * Like %sobject_manager_client_new() but takes a #GBusType instead of a #GDBusConnection.\n'
3265                 ' *\n'
3266                 ' * 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'
3267                 ' * You can then call %sobject_manager_client_new_for_bus_finish() to get the result of the operation.\n'
3268                 ' *\n'
3269                 ' * See %sobject_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
3270                 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
3271         self.c.write(' */\n')
3272         self.c.write('void\n'
3273                      '%sobject_manager_client_new_for_bus (\n'
3274                      '    GBusType                bus_type,\n'
3275                      '    GDBusObjectManagerClientFlags  flags,\n'
3276                      '    const gchar            *name,\n'
3277                      '    const gchar            *object_path,\n'
3278                      '    GCancellable           *cancellable,\n'
3279                      '    GAsyncReadyCallback     callback,\n'
3280                      '    gpointer                user_data)\n'
3281                      '{\n'
3282                      '  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'
3283                      '}\n'
3284                      '\n'
3285                      %(self.ns_lower, self.ns_upper, self.ns_lower))
3286         self.c.write('/**\n'
3287                      ' * %sobject_manager_client_new_for_bus_finish:\n'
3288                      ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new_for_bus().\n'
3289                      ' * @error: Return location for error or %%NULL\n'
3290                      ' *\n'
3291                      ' * Finishes an operation started with %sobject_manager_client_new_for_bus().\n'
3292                      ' *\n'
3293                      ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3294                      %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
3295         self.c.write(' */\n')
3296         self.c.write('GDBusObjectManager *\n'
3297                      '%sobject_manager_client_new_for_bus_finish (\n'
3298                      '    GAsyncResult        *res,\n'
3299                      '    GError             **error)\n'
3300                      '{\n'
3301                      '  GObject *ret;\n'
3302                      '  GObject *source_object;\n'
3303                      '  source_object = g_async_result_get_source_object (res);\n'
3304                      '  ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
3305                      '  g_object_unref (source_object);\n'
3306                      '  if (ret != NULL)\n'
3307                      '    return G_DBUS_OBJECT_MANAGER (ret);\n'
3308                      '  else\n'
3309                      '    return NULL;\n'
3310                      '}\n'
3311                      '\n'
3312                      %(self.ns_lower))
3313         self.c.write(self.docbook_gen.expand(
3314                 '/**\n'
3315                 ' * %sobject_manager_client_new_for_bus_sync:\n'
3316                 ' * @bus_type: A #GBusType.\n'
3317                 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
3318                 ' * @name: A bus name (well-known or unique).\n'
3319                 ' * @object_path: An object path.\n'
3320                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
3321                 ' * @error: Return location for error or %%NULL\n'
3322                 ' *\n'
3323                 ' * Like %sobject_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
3324                 ' *\n'
3325                 ' * The calling thread is blocked until a reply is received.\n'
3326                 ' *\n'
3327                 ' * See %sobject_manager_client_new_for_bus() for the asynchronous version of this constructor.\n'
3328                 ' *\n'
3329                 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
3330                 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
3331         self.c.write(' */\n')
3332         self.c.write('GDBusObjectManager *\n'
3333                      '%sobject_manager_client_new_for_bus_sync (\n'
3334                      '    GBusType                bus_type,\n'
3335                      '    GDBusObjectManagerClientFlags  flags,\n'
3336                      '    const gchar            *name,\n'
3337                      '    const gchar            *object_path,\n'
3338                      '    GCancellable           *cancellable,\n'
3339                      '    GError                **error)\n'
3340                      '{\n'
3341                      '  GInitable *ret;\n'
3342                      '  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'
3343                      '  if (ret != NULL)\n'
3344                      '    return G_DBUS_OBJECT_MANAGER (ret);\n'
3345                      '  else\n'
3346                      '    return NULL;\n'
3347                      '}\n'
3348                      '\n'
3349                      %(self.ns_lower, self.ns_upper, self.ns_lower))
3350         self.c.write('\n')
3351
3352     # ---------------------------------------------------------------------------------------------------
3353
3354     def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
3355         if len(obj.since) > 0:
3356             f.write('%*s *\n'
3357                     '%*s * Since: %s\n'
3358                     %(indent, '', indent, '', obj.since))
3359         if obj.deprecated:
3360             if isinstance(obj, dbustypes.Interface):
3361                 thing = 'The D-Bus interface'
3362             elif isinstance(obj, dbustypes.Method):
3363                 thing = 'The D-Bus method'
3364             elif isinstance(obj, dbustypes.Signal):
3365                 thing = 'The D-Bus signal'
3366             elif isinstance(obj, dbustypes.Property):
3367                 thing = 'The D-Bus property'
3368             else:
3369                 raise RuntimeError('Cannot handle object ', obj)
3370             f.write(self.docbook_gen.expand(
3371                     '%*s *\n'
3372                     '%*s * Deprecated: %s has been deprecated.\n'
3373                     %(indent, '', indent, '', thing), False))
3374         f.write('%*s */\n'%(indent, ''))
3375
3376     # ---------------------------------------------------------------------------------------------------
3377
3378     def generate_interface_intro(self, i):
3379         self.c.write('/* ------------------------------------------------------------------------\n'
3380                      ' * Code for interface %s\n'
3381                      ' * ------------------------------------------------------------------------\n'
3382                      ' */\n'
3383                      '\n'%(i.name))
3384
3385         self.c.write(self.docbook_gen.expand(
3386                 '/**\n'
3387                 ' * SECTION:%s\n'
3388                 ' * @title: %s\n'
3389                 ' * @short_description: Generated C code for the %s D-Bus interface\n'
3390                 ' *\n'
3391                 ' * This section contains code for working with the #%s D-Bus interface in C.\n'
3392                 ' */\n'
3393                 %(i.camel_name, i.camel_name, i.name, i.name), False))
3394         self.c.write('\n')
3395
3396     def generate(self):
3397         self.generate_intro()
3398         self.declare_types()
3399         for i in self.ifaces:
3400             self.generate_interface_intro(i)
3401             self.generate_introspection_for_interface(i)
3402             self.generate_interface(i)
3403             self.generate_property_accessors(i)
3404             self.generate_signal_emitters(i)
3405             self.generate_method_calls(i)
3406             self.generate_method_completers(i)
3407             self.generate_proxy(i)
3408             self.generate_skeleton(i)
3409         if self.generate_objmanager:
3410             self.generate_object()
3411             self.generate_object_manager_client()
3412
3413         self.generate_outro()