Line data Source code
1 : /* valagdbusmodule.vala
2 : *
3 : * Copyright (C) 2010-2012 Jürg Billeter
4 : *
5 : * This library is free software; you can redistribute it and/or
6 : * modify it under the terms of the GNU Lesser General Public
7 : * License as published by the Free Software Foundation; either
8 : * version 2.1 of the License, or (at your option) any later version.
9 :
10 : * This library is distributed in the hope that it will be useful,
11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : * Lesser General Public License for more details.
14 :
15 : * You should have received a copy of the GNU Lesser General Public
16 : * License along with this library; if not, write to the Free Software
17 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 : *
19 : * Author:
20 : * Jürg Billeter <j@bitron.ch>
21 : */
22 :
23 2914 : public class Vala.GDBusModule : GVariantModule {
24 85673 : public static string? get_dbus_name (TypeSymbol symbol) {
25 85673 : return symbol.get_attribute_string ("DBus", "name");
26 : }
27 :
28 317 : public static string get_dbus_name_for_member (Symbol symbol) {
29 317 : var dbus_name = symbol.get_attribute_string ("DBus", "name");
30 317 : if (dbus_name != null) {
31 317 : return dbus_name;
32 : }
33 :
34 314 : return Symbol.lower_case_to_camel_case (symbol.name);
35 : }
36 :
37 50 : public static int get_dbus_timeout_for_member (Symbol symbol) {
38 50 : return symbol.get_attribute_integer ("DBus", "timeout", -1);
39 : }
40 :
41 258 : public static bool is_dbus_visible (CodeNode node) {
42 258 : var dbus_attribute = node.get_attribute ("DBus");
43 42 : if (dbus_attribute != null
44 21 : && dbus_attribute.has_argument ("visible")
45 4 : && !dbus_attribute.get_bool ("visible")) {
46 4 : return false;
47 : }
48 :
49 254 : return true;
50 : }
51 :
52 155 : public static bool is_dbus_no_reply (Method m) {
53 155 : return m.get_attribute_bool ("DBus", "no_reply");
54 : }
55 :
56 59 : public static string dbus_result_name (Method m) {
57 59 : var dbus_name = m.get_attribute_string ("DBus", "result");
58 59 : if (dbus_name != null && dbus_name != "") {
59 59 : return dbus_name;
60 : }
61 :
62 59 : return "result";
63 : }
64 :
65 43 : public override void visit_error_domain (ErrorDomain edomain) {
66 41 : var edomain_dbus_name = get_dbus_name (edomain);
67 41 : if (edomain_dbus_name == null) {
68 39 : base.visit_error_domain (edomain);
69 39 : return;
70 : }
71 :
72 2 : cfile.add_include ("gio/gio.h");
73 :
74 2 : generate_error_domain_declaration (edomain, cfile);
75 :
76 2 : if (!edomain.is_internal_symbol ()) {
77 0 : generate_error_domain_declaration (edomain, header_file);
78 : }
79 2 : if (!edomain.is_private_symbol ()) {
80 2 : generate_error_domain_declaration (edomain, internal_header_file);
81 : }
82 :
83 2 : var error_entries = new CCodeInitializerList ();
84 14 : foreach (ErrorCode ecode in edomain.get_codes ()) {
85 6 : var ecode_dbus_name = get_dbus_name (ecode);
86 6 : if (ecode_dbus_name == null) {
87 6 : ecode_dbus_name = Symbol.lower_case_to_camel_case (ecode.name.ascii_down ());
88 : }
89 :
90 6 : var error_entry = new CCodeInitializerList ();
91 6 : error_entry.append (new CCodeIdentifier (get_ccode_name (ecode)));
92 6 : error_entry.append (new CCodeConstant ("\"%s.%s\"".printf (edomain_dbus_name, ecode_dbus_name)));
93 6 : error_entries.append (error_entry);
94 : }
95 :
96 2 : var cdecl = new CCodeDeclaration ("const GDBusErrorEntry");
97 2 : cdecl.add_declarator (new CCodeVariableDeclarator (get_ccode_lower_case_name (edomain) + "_entries[]", error_entries));
98 2 : cdecl.modifiers = CCodeModifiers.STATIC;
99 2 : cfile.add_constant_declaration (cdecl);
100 :
101 2 : string quark_fun_name = get_ccode_lower_case_prefix (edomain) + "quark";
102 :
103 2 : var cquark_fun = new CCodeFunction (quark_fun_name, get_ccode_name (gquark_type.type_symbol));
104 2 : push_function (cquark_fun);
105 :
106 2 : string quark_name = "%squark_volatile".printf (get_ccode_lower_case_prefix (edomain));
107 :
108 2 : ccode.add_declaration ("gsize", new CCodeVariableDeclarator (quark_name, new CCodeConstant ("0")), CCodeModifiers.STATIC | CCodeModifiers.VOLATILE);
109 :
110 2 : var register_call = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_error_register_error_domain"));
111 2 : register_call.add_argument (new CCodeConstant ("\"" + get_ccode_quark_name (edomain) + "\""));
112 2 : register_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (quark_name)));
113 2 : register_call.add_argument (new CCodeIdentifier (get_ccode_lower_case_name (edomain) + "_entries"));
114 2 : var nentries = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
115 2 : nentries.add_argument (new CCodeIdentifier (get_ccode_lower_case_name (edomain) + "_entries"));
116 2 : register_call.add_argument (nentries);
117 2 : ccode.add_expression (register_call);
118 :
119 2 : ccode.add_return (new CCodeCastExpression (new CCodeIdentifier (quark_name), "GQuark"));
120 :
121 2 : pop_function ();
122 2 : cfile.add_function (cquark_fun);
123 : }
124 :
125 340 : bool is_file_descriptor (DataType type) {
126 340 : if (type is ObjectType) {
127 116 : if (type.type_symbol.get_full_name () == "GLib.UnixInputStream" ||
128 107 : type.type_symbol.get_full_name () == "GLib.UnixOutputStream" ||
129 104 : type.type_symbol.get_full_name () == "GLib.Socket" ||
130 104 : type.type_symbol.get_full_name () == "GLib.FileDescriptorBased") {
131 12 : return true;
132 : }
133 : }
134 :
135 340 : return false;
136 : }
137 :
138 182 : public bool dbus_method_uses_file_descriptor (Method method) {
139 498 : foreach (Parameter param in method.get_parameters ()) {
140 170 : if (is_file_descriptor (param.variable_type)) {
141 12 : return true;
142 : }
143 : }
144 :
145 170 : if (is_file_descriptor (method.return_type)) {
146 12 : return true;
147 : }
148 :
149 182 : return false;
150 : }
151 :
152 118 : CCodeExpression? get_file_descriptor (DataType type, CCodeExpression expr) {
153 118 : if (type is ObjectType) {
154 49 : if (type.type_symbol.get_full_name () == "GLib.UnixInputStream") {
155 10 : var result = new CCodeFunctionCall (new CCodeIdentifier ("g_unix_input_stream_get_fd"));
156 10 : result.add_argument (expr);
157 10 : return result;
158 39 : } else if (type.type_symbol.get_full_name () == "GLib.UnixOutputStream") {
159 1 : var result = new CCodeFunctionCall (new CCodeIdentifier ("g_unix_output_stream_get_fd"));
160 1 : result.add_argument (expr);
161 1 : return result;
162 38 : } else if (type.type_symbol.get_full_name () == "GLib.Socket") {
163 0 : var result = new CCodeFunctionCall (new CCodeIdentifier ("g_socket_get_fd"));
164 0 : result.add_argument (expr);
165 0 : return result;
166 38 : } else if (type.type_symbol.get_full_name () == "GLib.FileDescriptorBased") {
167 0 : var result = new CCodeFunctionCall (new CCodeIdentifier ("g_file_descriptor_based_get_fd"));
168 0 : result.add_argument (expr);
169 0 : return result;
170 : }
171 : }
172 :
173 118 : return null;
174 : }
175 :
176 236 : public void send_dbus_value (DataType type, CCodeExpression builder_expr, CCodeExpression expr, Symbol? sym) {
177 118 : var fd = get_file_descriptor (type, expr);
178 129 : if (fd != null) {
179 : // add file descriptor to the file descriptor list
180 11 : var fd_append = new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_append"));
181 11 : fd_append.add_argument (new CCodeIdentifier ("_fd_list"));
182 11 : fd_append.add_argument (fd);
183 11 : fd_append.add_argument (new CCodeConstant ("NULL"));
184 :
185 : // add index to file descriptor to gvariant
186 11 : var builder_add = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_add"));
187 11 : builder_add.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, builder_expr));
188 11 : builder_add.add_argument (new CCodeConstant ("\"h\""));
189 11 : builder_add.add_argument (fd_append);
190 11 : ccode.add_expression (builder_add);
191 : } else {
192 107 : write_expression (type, builder_expr, expr, sym);
193 : }
194 : }
195 :
196 102 : CCodeExpression? create_from_file_descriptor (DataType type, CCodeExpression expr) {
197 102 : if (type is ObjectType) {
198 45 : if (type.type_symbol.get_full_name () == "GLib.UnixInputStream") {
199 8 : var result = new CCodeFunctionCall (new CCodeIdentifier ("g_unix_input_stream_new"));
200 8 : result.add_argument (expr);
201 8 : result.add_argument (new CCodeConstant ("TRUE"));
202 8 : return new CCodeCastExpression (result, "GUnixInputStream *");
203 37 : } else if (type.type_symbol.get_full_name () == "GLib.UnixOutputStream") {
204 2 : var result = new CCodeFunctionCall (new CCodeIdentifier ("g_unix_output_stream_new"));
205 2 : result.add_argument (expr);
206 2 : result.add_argument (new CCodeConstant ("TRUE"));
207 2 : return new CCodeCastExpression (result, "GUnixOutputStream *");
208 35 : } else if (type.type_symbol.get_full_name () == "GLib.Socket") {
209 0 : var result = new CCodeFunctionCall (new CCodeIdentifier ("g_socket_new_from_fd"));
210 0 : result.add_argument (expr);
211 0 : result.add_argument (new CCodeConstant ("NULL"));
212 0 : return result;
213 : }
214 : }
215 :
216 102 : return null;
217 : }
218 :
219 204 : public void receive_dbus_value (DataType type, CCodeExpression message_expr, CCodeExpression iter_expr, CCodeExpression target_expr, Symbol? sym, CCodeExpression? error_expr = null, out bool may_fail = null) {
220 102 : var fd_list = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_get_unix_fd_list"));
221 102 : fd_list.add_argument (message_expr);
222 :
223 102 : var fd_var = new CCodeIdentifier ("_fd");
224 :
225 102 : var stream = create_from_file_descriptor (type, fd_var);
226 112 : if (stream != null) {
227 10 : var fd_list_var = new CCodeIdentifier ("_fd_list");
228 :
229 10 : var fd = new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_get"));
230 10 : fd.add_argument (fd_list_var);
231 10 : fd.add_argument (new CCodeIdentifier ("_fd_index"));
232 10 : fd.add_argument (error_expr);
233 :
234 10 : ccode.add_assignment (fd_list_var, fd_list);
235 10 : ccode.open_if (fd_list_var);
236 :
237 10 : var get_fd = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_iter_next"));
238 10 : get_fd.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, iter_expr));
239 10 : get_fd.add_argument (new CCodeConstant ("\"h\""));
240 10 : get_fd.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_fd_index")));
241 10 : ccode.add_expression (get_fd);
242 :
243 10 : ccode.add_assignment (fd_var, fd);
244 10 : ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN_OR_EQUAL, fd_var, new CCodeConstant ("0")));
245 :
246 10 : ccode.add_assignment (target_expr, stream);
247 10 : may_fail = true;
248 :
249 10 : ccode.close ();
250 :
251 10 : ccode.add_else ();
252 10 : var set_error = new CCodeFunctionCall (new CCodeIdentifier ("g_set_error_literal"));
253 10 : set_error.add_argument (error_expr);
254 10 : set_error.add_argument (new CCodeIdentifier ("G_IO_ERROR"));
255 10 : set_error.add_argument (new CCodeIdentifier ("G_IO_ERROR_FAILED"));
256 10 : set_error.add_argument (new CCodeConstant ("\"FD List is NULL\""));
257 10 : ccode.add_expression (set_error);
258 10 : ccode.close ();
259 : } else {
260 92 : read_expression (type, iter_expr, target_expr, sym, error_expr, out may_fail);
261 : }
262 : }
263 54 : CCodeExpression get_method_info (ObjectTypeSymbol sym) {
264 54 : var infos = new CCodeInitializerList ();
265 :
266 271 : foreach (Method m in sym.get_methods ()) {
267 123 : if (m is CreationMethod || m.binding != MemberBinding.INSTANCE
268 96 : || m.overrides || m.access != SymbolAccessibility.PUBLIC) {
269 27 : continue;
270 : }
271 96 : if (!is_dbus_visible (m)) {
272 2 : continue;
273 : }
274 :
275 94 : var in_args_info = new CCodeInitializerList ();
276 94 : var out_args_info = new CCodeInitializerList ();
277 :
278 266 : foreach (Parameter param in m.get_parameters ()) {
279 88 : if (param.variable_type is ObjectType && param.variable_type.type_symbol.get_full_name () == "GLib.Cancellable") {
280 4 : continue;
281 : }
282 84 : if (param.variable_type is ObjectType && param.variable_type.type_symbol.get_full_name () == "GLib.BusName") {
283 0 : continue;
284 : }
285 :
286 84 : var info = new CCodeInitializerList ();
287 84 : info.append (new CCodeConstant ("-1"));
288 84 : info.append (new CCodeConstant ("\"%s\"".printf (param.name)));
289 84 : info.append (new CCodeConstant ("\"%s\"".printf (param.variable_type.get_type_signature (param))));
290 84 : info.append (new CCodeConstant ("NULL"));
291 :
292 84 : var cdecl = new CCodeDeclaration ("const GDBusArgInfo");
293 84 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_" + param.name, info));
294 84 : cdecl.modifiers = CCodeModifiers.STATIC;
295 84 : cfile.add_constant_declaration (cdecl);
296 :
297 84 : if (param.direction == ParameterDirection.IN) {
298 57 : in_args_info.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_" + param.name)));
299 : } else {
300 27 : out_args_info.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_" + param.name)));
301 : }
302 : }
303 :
304 153 : if (!(m.return_type is VoidType)) {
305 59 : var info = new CCodeInitializerList ();
306 59 : info.append (new CCodeConstant ("-1"));
307 59 : info.append (new CCodeConstant ("\"%s\"".printf (dbus_result_name (m))));
308 59 : info.append (new CCodeConstant ("\"%s\"".printf (m.return_type.get_type_signature (m))));
309 59 : info.append (new CCodeConstant ("NULL"));
310 :
311 59 : var cdecl = new CCodeDeclaration ("const GDBusArgInfo");
312 59 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_result", info));
313 59 : cdecl.modifiers = CCodeModifiers.STATIC;
314 59 : cfile.add_constant_declaration (cdecl);
315 :
316 59 : out_args_info.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_result")));
317 : }
318 :
319 94 : in_args_info.append (new CCodeConstant ("NULL"));
320 94 : out_args_info.append (new CCodeConstant ("NULL"));
321 :
322 94 : var cdecl = new CCodeDeclaration ("const GDBusArgInfo * const");
323 94 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_in[]", in_args_info));
324 94 : cdecl.modifiers = CCodeModifiers.STATIC;
325 94 : cfile.add_constant_declaration (cdecl);
326 :
327 94 : cdecl = new CCodeDeclaration ("const GDBusArgInfo * const");
328 94 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_out[]", out_args_info));
329 94 : cdecl.modifiers = CCodeModifiers.STATIC;
330 94 : cfile.add_constant_declaration (cdecl);
331 :
332 94 : var info = new CCodeInitializerList ();
333 94 : info.append (new CCodeConstant ("-1"));
334 94 : info.append (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (m))));
335 94 : info.append (new CCodeCastExpression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_in")), "GDBusArgInfo **"));
336 94 : info.append (new CCodeCastExpression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_out")), "GDBusArgInfo **"));
337 94 : info.append (new CCodeConstant ("NULL"));
338 :
339 94 : cdecl = new CCodeDeclaration ("const GDBusMethodInfo");
340 94 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_method_info_" + m.name, info));
341 94 : cdecl.modifiers = CCodeModifiers.STATIC;
342 94 : cfile.add_constant_declaration (cdecl);
343 :
344 94 : infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_method_info_" + m.name)));
345 : }
346 :
347 54 : infos.append (new CCodeConstant ("NULL"));
348 :
349 54 : var cdecl = new CCodeDeclaration ("const GDBusMethodInfo * const");
350 54 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_method_info[]", infos));
351 54 : cdecl.modifiers = CCodeModifiers.STATIC;
352 54 : cfile.add_constant_declaration (cdecl);
353 :
354 54 : return new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_method_info");
355 : }
356 :
357 54 : CCodeExpression get_signal_info (ObjectTypeSymbol sym) {
358 54 : var infos = new CCodeInitializerList ();
359 :
360 76 : foreach (Signal sig in sym.get_signals ()) {
361 12 : if (sig.access != SymbolAccessibility.PUBLIC) {
362 2 : continue;
363 : }
364 10 : if (!is_dbus_visible (sig)) {
365 0 : continue;
366 : }
367 :
368 10 : var args_info = new CCodeInitializerList ();
369 :
370 30 : foreach (Parameter param in sig.get_parameters ()) {
371 10 : var info = new CCodeInitializerList ();
372 10 : info.append (new CCodeConstant ("-1"));
373 10 : info.append (new CCodeConstant ("\"%s\"".printf (param.name)));
374 10 : info.append (new CCodeConstant ("\"%s\"".printf (param.variable_type.get_type_signature (param))));
375 10 : info.append (new CCodeConstant ("NULL"));
376 :
377 10 : var cdecl = new CCodeDeclaration ("const GDBusArgInfo");
378 10 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + get_ccode_lower_case_name (sig) + "_" + param.name, info));
379 10 : cdecl.modifiers = CCodeModifiers.STATIC;
380 10 : cfile.add_constant_declaration (cdecl);
381 :
382 10 : args_info.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + get_ccode_lower_case_name (sig) + "_" + param.name)));
383 : }
384 :
385 10 : args_info.append (new CCodeConstant ("NULL"));
386 :
387 10 : var cdecl = new CCodeDeclaration ("const GDBusArgInfo * const");
388 10 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + get_ccode_lower_case_name (sig) + "[]", args_info));
389 10 : cdecl.modifiers = CCodeModifiers.STATIC;
390 10 : cfile.add_constant_declaration (cdecl);
391 :
392 10 : var info = new CCodeInitializerList ();
393 10 : info.append (new CCodeConstant ("-1"));
394 10 : info.append (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (sig))));
395 10 : info.append (new CCodeCastExpression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + get_ccode_lower_case_name (sig))), "GDBusArgInfo **"));
396 10 : info.append (new CCodeConstant ("NULL"));
397 :
398 10 : cdecl = new CCodeDeclaration ("const GDBusSignalInfo");
399 10 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_signal_info_" + get_ccode_lower_case_name (sig), info));
400 10 : cdecl.modifiers = CCodeModifiers.STATIC;
401 10 : cfile.add_constant_declaration (cdecl);
402 :
403 10 : infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_signal_info_" + get_ccode_lower_case_name (sig))));
404 : }
405 :
406 54 : infos.append (new CCodeConstant ("NULL"));
407 :
408 54 : var cdecl = new CCodeDeclaration ("const GDBusSignalInfo * const");
409 54 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_signal_info[]", infos));
410 54 : cdecl.modifiers = CCodeModifiers.STATIC;
411 54 : cfile.add_constant_declaration (cdecl);
412 :
413 54 : return new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_signal_info");
414 : }
415 :
416 54 : CCodeExpression get_property_info (ObjectTypeSymbol sym) {
417 54 : var infos = new CCodeInitializerList ();
418 :
419 78 : foreach (Property prop in sym.get_properties ()) {
420 12 : if (prop.binding != MemberBinding.INSTANCE
421 12 : || prop.overrides || prop.access != SymbolAccessibility.PUBLIC) {
422 0 : continue;
423 : }
424 12 : if (!is_dbus_visible (prop)) {
425 0 : continue;
426 : }
427 :
428 12 : var info = new CCodeInitializerList ();
429 12 : info.append (new CCodeConstant ("-1"));
430 12 : info.append (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (prop))));
431 12 : info.append (new CCodeConstant ("\"%s\"".printf (prop.property_type.get_type_signature (prop))));
432 12 : if (prop.get_accessor != null && prop.set_accessor != null) {
433 12 : info.append (new CCodeConstant ("G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE"));
434 0 : } else if (prop.get_accessor != null) {
435 0 : info.append (new CCodeConstant ("G_DBUS_PROPERTY_INFO_FLAGS_READABLE"));
436 0 : } else if (prop.set_accessor != null) {
437 0 : info.append (new CCodeConstant ("G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE"));
438 : } else {
439 0 : info.append (new CCodeConstant ("G_DBUS_PROPERTY_INFO_FLAGS_NONE"));
440 : }
441 12 : info.append (new CCodeConstant ("NULL"));
442 :
443 12 : var cdecl = new CCodeDeclaration ("const GDBusPropertyInfo");
444 12 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_property_info_" + prop.name, info));
445 12 : cdecl.modifiers = CCodeModifiers.STATIC;
446 12 : cfile.add_constant_declaration (cdecl);
447 :
448 12 : infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_property_info_" + prop.name)));
449 : }
450 :
451 54 : infos.append (new CCodeConstant ("NULL"));
452 :
453 54 : var cdecl = new CCodeDeclaration ("const GDBusPropertyInfo * const");
454 54 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_property_info[]", infos));
455 54 : cdecl.modifiers = CCodeModifiers.STATIC;
456 54 : cfile.add_constant_declaration (cdecl);
457 :
458 54 : return new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_property_info");
459 : }
460 :
461 108 : void declare_interface_info (ObjectTypeSymbol sym) {
462 54 : var info = new CCodeInitializerList ();
463 54 : info.append (new CCodeConstant ("-1"));
464 54 : info.append (new CCodeConstant ("\"%s\"".printf (get_dbus_name (sym))));
465 54 : info.append (new CCodeCastExpression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_method_info (sym)), "GDBusMethodInfo **"));
466 54 : info.append (new CCodeCastExpression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_signal_info (sym)), "GDBusSignalInfo **"));
467 54 : info.append (new CCodeCastExpression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_property_info (sym)), "GDBusPropertyInfo **"));
468 54 : info.append (new CCodeConstant ("NULL"));
469 :
470 54 : var cdecl = new CCodeDeclaration ("const GDBusInterfaceInfo");
471 54 : cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) + "dbus_interface_info", info));
472 54 : cdecl.modifiers = CCodeModifiers.STATIC;
473 54 : cfile.add_constant_declaration (cdecl);
474 : }
475 :
476 108 : protected CCodeExpression get_interface_info (ObjectTypeSymbol sym) {
477 108 : return new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_interface_info");
478 : }
479 :
480 780 : public override void visit_class (Class cl) {
481 780 : base.visit_class (cl);
482 :
483 780 : visit_object_type_symbol (cl);
484 : }
485 :
486 118 : public override void visit_interface (Interface iface) {
487 118 : base.visit_interface (iface);
488 :
489 118 : visit_object_type_symbol (iface);
490 : }
491 :
492 898 : void visit_object_type_symbol (ObjectTypeSymbol sym) {
493 898 : if (get_dbus_name (sym) == null) {
494 : return;
495 : }
496 :
497 54 : declare_interface_info(sym);
498 : }
499 : }
|