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>
25 def __init__(self
, key
, value
):
31 def __init__(self
, name
, signature
):
33 self
.signature
= signature
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
)
45 self
.name
= 'unnamed_arg%d'%arg_number
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'
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'
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'
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'
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
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
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
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
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
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'
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'
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'
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'
227 def __init__(self
, name
):
231 self
.annotations
= []
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
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()
250 name
= overridden_name
251 self
.name_lower
= utils
.camel_case_to_uscore(name
).lower().replace('-', '_')
252 self
.name_hyphen
= self
.name_lower
.replace('_', '-')
255 for a
in self
.in_args
:
256 a
.post_process(interface_prefix
, cns
, cns_upper
, cns_lower
, arg_count
)
259 for a
in self
.out_args
:
260 a
.post_process(interface_prefix
, cns
, cns_upper
, cns_lower
, arg_count
)
263 if utils
.lookup_annotation(self
.annotations
, 'org.freedesktop.DBus.Deprecated') == 'true':
264 self
.deprecated
= True
267 def __init__(self
, name
):
270 self
.annotations
= []
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
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()
289 name
= overridden_name
290 self
.name_lower
= utils
.camel_case_to_uscore(name
).lower().replace('-', '_')
291 self
.name_hyphen
= self
.name_lower
.replace('_', '-')
295 a
.post_process(interface_prefix
, cns
, cns_upper
, cns_lower
, arg_count
)
298 if utils
.lookup_annotation(self
.annotations
, 'org.freedesktop.DBus.Deprecated') == 'true':
299 self
.deprecated
= True
302 def __init__(self
, name
, signature
, access
):
304 self
.signature
= signature
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':
314 elif self
.access
== 'read':
316 elif self
.access
== 'write':
319 raise RuntimeError('Invalid access type %s'%self
.access
)
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
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()
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_'
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
353 def __init__(self
, name
):
358 self
.annotations
= []
360 self
.doc_string_brief
= ''
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() + '_'
379 cns_upper
= utils
.camel_case_to_uscore(c_namespace
).upper() + '_'
380 cns_lower
= utils
.camel_case_to_uscore(c_namespace
).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)
399 name
= overridden_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
)