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