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