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