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