Update Friulian translation
[glib.git] / gio / gdbus-2.0 / codegen / dbustypes.py
blobb163cb93566fedf3bd42cd8e20da5a0d697de038
1 # -*- Mode: Python -*-
3 # GDBus - GLib D-Bus Library
5 # Copyright (C) 2008-2011 Red Hat, Inc.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General
18 # Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 # Author: David Zeuthen <davidz@redhat.com>
22 from . import utils
24 class Annotation:
25 def __init__(self, key, value):
26 self.key = key
27 self.value = value
28 self.annotations = []
30 class Arg:
31 def __init__(self, name, signature):
32 self.name = name
33 self.signature = signature
34 self.annotations = []
35 self.doc_string = ''
36 self.since = ''
38 def post_process(self, interface_prefix, cns, cns_upper, cns_lower, arg_number):
39 if len(self.doc_string) == 0:
40 self.doc_string = utils.lookup_docs(self.annotations)
41 if len(self.since) == 0:
42 self.since = utils.lookup_since(self.annotations)
44 if self.name == None:
45 self.name = 'unnamed_arg%d'%arg_number
46 # default to GVariant
47 self.ctype_in_g = 'GVariant *'
48 self.ctype_in = 'GVariant *'
49 self.ctype_in_dup = 'GVariant *'
50 self.ctype_out = 'GVariant **'
51 self.gtype = 'G_TYPE_VARIANT'
52 self.free_func = 'g_variant_unref'
53 self.format_in = '@' + self.signature
54 self.format_out = '@' + self.signature
55 self.gvariant_get = 'XXX'
56 self.gvalue_get = 'g_value_get_variant'
57 if not utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
58 if self.signature == 'b':
59 self.ctype_in_g = 'gboolean '
60 self.ctype_in = 'gboolean '
61 self.ctype_out = 'gboolean *'
62 self.gtype = 'G_TYPE_BOOLEAN'
63 self.free_func = None
64 self.format_in = 'b'
65 self.format_out = 'b'
66 self.gvariant_get = 'g_variant_get_boolean'
67 self.gvalue_get = 'g_value_get_boolean'
68 elif self.signature == 'y':
69 self.ctype_in_g = 'guchar '
70 self.ctype_in = 'guchar '
71 self.ctype_out = 'guchar *'
72 self.gtype = 'G_TYPE_UCHAR'
73 self.free_func = None
74 self.format_in = 'y'
75 self.format_out = 'y'
76 self.gvariant_get = 'g_variant_get_byte'
77 self.gvalue_get = 'g_value_get_uchar'
78 elif self.signature == 'n':
79 self.ctype_in_g = 'gint '
80 self.ctype_in = 'gint16 '
81 self.ctype_out = 'gint16 *'
82 self.gtype = 'G_TYPE_INT'
83 self.free_func = None
84 self.format_in = 'n'
85 self.format_out = 'n'
86 self.gvariant_get = 'g_variant_get_int16'
87 self.gvalue_get = 'g_value_get_int'
88 elif self.signature == 'q':
89 self.ctype_in_g = 'guint '
90 self.ctype_in = 'guint16 '
91 self.ctype_out = 'guint16 *'
92 self.gtype = 'G_TYPE_UINT'
93 self.free_func = None
94 self.format_in = 'q'
95 self.format_out = 'q'
96 self.gvariant_get = 'g_variant_get_uint16'
97 self.gvalue_get = 'g_value_get_uint'
98 elif self.signature == 'i':
99 self.ctype_in_g = 'gint '
100 self.ctype_in = 'gint '
101 self.ctype_out = 'gint *'
102 self.gtype = 'G_TYPE_INT'
103 self.free_func = None
104 self.format_in = 'i'
105 self.format_out = 'i'
106 self.gvariant_get = 'g_variant_get_int32'
107 self.gvalue_get = 'g_value_get_int'
108 elif self.signature == 'u':
109 self.ctype_in_g = 'guint '
110 self.ctype_in = 'guint '
111 self.ctype_out = 'guint *'
112 self.gtype = 'G_TYPE_UINT'
113 self.free_func = None
114 self.format_in = 'u'
115 self.format_out = 'u'
116 self.gvariant_get = 'g_variant_get_uint32'
117 self.gvalue_get = 'g_value_get_uint'
118 elif self.signature == 'x':
119 self.ctype_in_g = 'gint64 '
120 self.ctype_in = 'gint64 '
121 self.ctype_out = 'gint64 *'
122 self.gtype = 'G_TYPE_INT64'
123 self.free_func = None
124 self.format_in = 'x'
125 self.format_out = 'x'
126 self.gvariant_get = 'g_variant_get_int64'
127 self.gvalue_get = 'g_value_get_int64'
128 elif self.signature == 't':
129 self.ctype_in_g = 'guint64 '
130 self.ctype_in = 'guint64 '
131 self.ctype_out = 'guint64 *'
132 self.gtype = 'G_TYPE_UINT64'
133 self.free_func = None
134 self.format_in = 't'
135 self.format_out = 't'
136 self.gvariant_get = 'g_variant_get_uint64'
137 self.gvalue_get = 'g_value_get_uint64'
138 elif self.signature == 'd':
139 self.ctype_in_g = 'gdouble '
140 self.ctype_in = 'gdouble '
141 self.ctype_out = 'gdouble *'
142 self.gtype = 'G_TYPE_DOUBLE'
143 self.free_func = None
144 self.format_in = 'd'
145 self.format_out = 'd'
146 self.gvariant_get = 'g_variant_get_double'
147 self.gvalue_get = 'g_value_get_double'
148 elif self.signature == 's':
149 self.ctype_in_g = 'const gchar *'
150 self.ctype_in = 'const gchar *'
151 self.ctype_in_dup = 'gchar *'
152 self.ctype_out = 'gchar **'
153 self.gtype = 'G_TYPE_STRING'
154 self.free_func = 'g_free'
155 self.format_in = 's'
156 self.format_out = 's'
157 self.gvariant_get = 'g_variant_get_string'
158 self.gvalue_get = 'g_value_get_string'
159 elif self.signature == 'o':
160 self.ctype_in_g = 'const gchar *'
161 self.ctype_in = 'const gchar *'
162 self.ctype_in_dup = 'gchar *'
163 self.ctype_out = 'gchar **'
164 self.gtype = 'G_TYPE_STRING'
165 self.free_func = 'g_free'
166 self.format_in = 'o'
167 self.format_out = 'o'
168 self.gvariant_get = 'g_variant_get_string'
169 self.gvalue_get = 'g_value_get_string'
170 elif self.signature == 'g':
171 self.ctype_in_g = 'const gchar *'
172 self.ctype_in = 'const gchar *'
173 self.ctype_in_dup = 'gchar *'
174 self.ctype_out = 'gchar **'
175 self.gtype = 'G_TYPE_STRING'
176 self.free_func = 'g_free'
177 self.format_in = 'g'
178 self.format_out = 'g'
179 self.gvariant_get = 'g_variant_get_string'
180 self.gvalue_get = 'g_value_get_string'
181 elif self.signature == 'ay':
182 self.ctype_in_g = 'const gchar *'
183 self.ctype_in = 'const gchar *'
184 self.ctype_in_dup = 'gchar *'
185 self.ctype_out = 'gchar **'
186 self.gtype = 'G_TYPE_STRING'
187 self.free_func = 'g_free'
188 self.format_in = '^ay'
189 self.format_out = '^ay'
190 self.gvariant_get = 'g_variant_get_bytestring'
191 self.gvalue_get = 'g_value_get_string'
192 elif self.signature == 'as':
193 self.ctype_in_g = 'const gchar *const *'
194 self.ctype_in = 'const gchar *const *'
195 self.ctype_in_dup = 'gchar **'
196 self.ctype_out = 'gchar ***'
197 self.gtype = 'G_TYPE_STRV'
198 self.free_func = 'g_strfreev'
199 self.format_in = '^as'
200 self.format_out = '^as'
201 self.gvariant_get = 'g_variant_get_strv'
202 self.gvalue_get = 'g_value_get_boxed'
203 elif self.signature == 'ao':
204 self.ctype_in_g = 'const gchar *const *'
205 self.ctype_in = 'const gchar *const *'
206 self.ctype_in_dup = 'gchar **'
207 self.ctype_out = 'gchar ***'
208 self.gtype = 'G_TYPE_STRV'
209 self.free_func = 'g_strfreev'
210 self.format_in = '^ao'
211 self.format_out = '^ao'
212 self.gvariant_get = 'g_variant_get_objv'
213 self.gvalue_get = 'g_value_get_boxed'
214 elif self.signature == 'aay':
215 self.ctype_in_g = 'const gchar *const *'
216 self.ctype_in = 'const gchar *const *'
217 self.ctype_in_dup = 'gchar **'
218 self.ctype_out = 'gchar ***'
219 self.gtype = 'G_TYPE_STRV'
220 self.free_func = 'g_strfreev'
221 self.format_in = '^aay'
222 self.format_out = '^aay'
223 self.gvariant_get = 'g_variant_get_bytestring_array'
224 self.gvalue_get = 'g_value_get_boxed'
226 class Method:
227 def __init__(self, name):
228 self.name = name
229 self.in_args = []
230 self.out_args = []
231 self.annotations = []
232 self.doc_string = ''
233 self.since = ''
234 self.deprecated = False
236 def post_process(self, interface_prefix, cns, cns_upper, cns_lower, containing_iface):
237 if len(self.doc_string) == 0:
238 self.doc_string = utils.lookup_docs(self.annotations)
239 if len(self.since) == 0:
240 self.since = utils.lookup_since(self.annotations)
241 if len(self.since) == 0:
242 self.since = containing_iface.since
244 name = self.name
245 overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
246 if utils.is_ugly_case(overridden_name):
247 self.name_lower = overridden_name.lower()
248 else:
249 if overridden_name:
250 name = overridden_name
251 self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
252 self.name_hyphen = self.name_lower.replace('_', '-')
254 arg_count = 0
255 for a in self.in_args:
256 a.post_process(interface_prefix, cns, cns_upper, cns_lower, arg_count)
257 arg_count += 1
259 for a in self.out_args:
260 a.post_process(interface_prefix, cns, cns_upper, cns_lower, arg_count)
261 arg_count += 1
263 if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
264 self.deprecated = True
266 class Signal:
267 def __init__(self, name):
268 self.name = name
269 self.args = []
270 self.annotations = []
271 self.doc_string = ''
272 self.since = ''
273 self.deprecated = False
275 def post_process(self, interface_prefix, cns, cns_upper, cns_lower, containing_iface):
276 if len(self.doc_string) == 0:
277 self.doc_string = utils.lookup_docs(self.annotations)
278 if len(self.since) == 0:
279 self.since = utils.lookup_since(self.annotations)
280 if len(self.since) == 0:
281 self.since = containing_iface.since
283 name = self.name
284 overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
285 if utils.is_ugly_case(overridden_name):
286 self.name_lower = overridden_name.lower()
287 else:
288 if overridden_name:
289 name = overridden_name
290 self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
291 self.name_hyphen = self.name_lower.replace('_', '-')
293 arg_count = 0
294 for a in self.args:
295 a.post_process(interface_prefix, cns, cns_upper, cns_lower, arg_count)
296 arg_count += 1
298 if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
299 self.deprecated = True
301 class Property:
302 def __init__(self, name, signature, access):
303 self.name = name
304 self.signature = signature
305 self.access = access
306 self.annotations = []
307 self.arg = Arg('value', self.signature)
308 self.arg.annotations = self.annotations
309 self.readable = False
310 self.writable = False
311 if self.access == 'readwrite':
312 self.readable = True
313 self.writable = True
314 elif self.access == 'read':
315 self.readable = True
316 elif self.access == 'write':
317 self.writable = True
318 else:
319 raise RuntimeError('Invalid access type %s'%self.access)
320 self.doc_string = ''
321 self.since = ''
322 self.deprecated = False
324 def post_process(self, interface_prefix, cns, cns_upper, cns_lower, containing_iface):
325 if len(self.doc_string) == 0:
326 self.doc_string = utils.lookup_docs(self.annotations)
327 if len(self.since) == 0:
328 self.since = utils.lookup_since(self.annotations)
329 if len(self.since) == 0:
330 self.since = containing_iface.since
332 name = self.name
333 overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
334 if utils.is_ugly_case(overridden_name):
335 self.name_lower = overridden_name.lower()
336 else:
337 if overridden_name:
338 name = overridden_name
339 self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
340 self.name_hyphen = self.name_lower.replace('_', '-')
341 # don't clash with the GType getter, e.g.: GType foo_bar_get_type (void); G_GNUC_CONST
342 if self.name_lower == 'type':
343 self.name_lower = 'type_'
345 # recalculate arg
346 self.arg.annotations = self.annotations
347 self.arg.post_process(interface_prefix, cns, cns_upper, cns_lower, 0)
349 if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
350 self.deprecated = True
352 class Interface:
353 def __init__(self, name):
354 self.name = name
355 self.methods = []
356 self.signals = []
357 self.properties = []
358 self.annotations = []
359 self.doc_string = ''
360 self.doc_string_brief = ''
361 self.since = ''
362 self.deprecated = False
364 def post_process(self, interface_prefix, c_namespace):
365 if len(self.doc_string) == 0:
366 self.doc_string = utils.lookup_docs(self.annotations)
367 if len(self.doc_string_brief) == 0:
368 self.doc_string_brief = utils.lookup_brief_docs(self.annotations)
369 if len(self.since) == 0:
370 self.since = utils.lookup_since(self.annotations)
372 if len(c_namespace) > 0:
373 if utils.is_ugly_case(c_namespace):
374 cns = c_namespace.replace('_', '')
375 cns_upper = c_namespace.upper() + '_'
376 cns_lower = c_namespace.lower() + '_'
377 else:
378 cns = c_namespace
379 cns_upper = utils.camel_case_to_uscore(c_namespace).upper() + '_'
380 cns_lower = utils.camel_case_to_uscore(c_namespace).lower() + '_'
381 else:
382 cns = ''
383 cns_upper = ''
384 cns_lower = ''
386 overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
387 if utils.is_ugly_case(overridden_name):
388 name = overridden_name.replace('_', '')
389 name_with_ns = cns + name
390 self.name_without_prefix = name
391 self.camel_name = name_with_ns
392 self.ns_upper = cns_upper
393 self.name_lower = cns_lower + overridden_name.lower()
394 self.name_upper = overridden_name.upper()
396 #raise RuntimeError('handle Ugly_Case ', overridden_name)
397 else:
398 if overridden_name:
399 name = overridden_name
400 else:
401 name = self.name
402 if name.startswith(interface_prefix):
403 name = name[len(interface_prefix):]
404 self.name_without_prefix = name
405 name = utils.strip_dots(name)
406 name_with_ns = utils.strip_dots(cns + '.' + name)
407 self.camel_name = name_with_ns
408 self.ns_upper = cns_upper
409 self.name_lower = cns_lower + utils.camel_case_to_uscore(name)
410 self.name_upper = utils.camel_case_to_uscore(name).upper()
412 self.name_hyphen = self.name_upper.lower().replace('_', '-')
414 if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
415 self.deprecated = True
417 for m in self.methods:
418 m.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
420 for s in self.signals:
421 s.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
423 for p in self.properties:
424 p.post_process(interface_prefix, cns, cns_upper, cns_lower, self)