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