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