posix: Fix SockAddr cname.
[vala-lang.git] / codegen / valagdbusmodule.vala
blob0fff2c10eafc552f3daef56876b94da22140777b
1 /* valagdbusmodule.vala
3 * Copyright (C) 2010 Jürg Billeter
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.
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.
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 public class Vala.GDBusModule : GVariantModule {
24 public static string? get_dbus_name (TypeSymbol symbol) {
25 var dbus = symbol.get_attribute ("DBus");
26 if (dbus == null) {
27 return null;
30 return dbus.get_string ("name");
33 public static string get_dbus_name_for_member (Symbol symbol) {
34 var dbus = symbol.get_attribute ("DBus");
35 if (dbus != null && dbus.has_argument ("name")) {
36 return dbus.get_string ("name");
39 return Symbol.lower_case_to_camel_case (symbol.name);
42 public override void visit_error_domain (ErrorDomain edomain) {
43 var edomain_dbus_name = get_dbus_name (edomain);
44 if (edomain_dbus_name == null) {
45 base.visit_error_domain (edomain);
46 return;
49 generate_error_domain_declaration (edomain, cfile);
51 if (!edomain.is_internal_symbol ()) {
52 generate_error_domain_declaration (edomain, header_file);
54 if (!edomain.is_private_symbol ()) {
55 generate_error_domain_declaration (edomain, internal_header_file);
58 var error_entries = new CCodeInitializerList ();
59 foreach (ErrorCode ecode in edomain.get_codes ()) {
60 var ecode_dbus_name = get_dbus_name (ecode);
61 if (ecode_dbus_name == null) {
62 ecode_dbus_name = Symbol.lower_case_to_camel_case (ecode.name.down ());
65 var error_entry = new CCodeInitializerList ();
66 error_entry.append (new CCodeIdentifier (ecode.get_cname ()));
67 error_entry.append (new CCodeConstant ("\"%s.%s\"".printf (edomain_dbus_name, ecode_dbus_name)));
68 error_entries.append (error_entry);
71 var cdecl = new CCodeDeclaration ("const GDBusErrorEntry");
72 cdecl.add_declarator (new CCodeVariableDeclarator (edomain.get_lower_case_cname () + "_entries[]", error_entries));
73 cdecl.modifiers = CCodeModifiers.STATIC;
74 cfile.add_constant_declaration (cdecl);
76 string quark_fun_name = edomain.get_lower_case_cprefix () + "quark";
78 var cquark_fun = new CCodeFunction (quark_fun_name, gquark_type.data_type.get_cname ());
79 var cquark_block = new CCodeBlock ();
81 string quark_name = "%squark_volatile".printf (edomain.get_lower_case_cprefix ());
83 cdecl = new CCodeDeclaration ("gsize");
84 cdecl.add_declarator (new CCodeVariableDeclarator (quark_name, new CCodeConstant ("0")));
85 cdecl.modifiers = CCodeModifiers.STATIC | CCodeModifiers.VOLATILE;
86 cquark_block.add_statement (cdecl);
88 var register_call = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_error_register_error_domain"));
89 register_call.add_argument (new CCodeConstant ("\"" + edomain.get_lower_case_cname () + "-quark\""));
90 register_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (quark_name)));
91 register_call.add_argument (new CCodeIdentifier (edomain.get_lower_case_cname () + "_entries"));
92 var nentries = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
93 nentries.add_argument (new CCodeIdentifier (edomain.get_lower_case_cname () + "_entries"));
94 register_call.add_argument (nentries);
95 cquark_block.add_statement (new CCodeExpressionStatement (register_call));
97 cquark_block.add_statement (new CCodeReturnStatement (new CCodeCastExpression (new CCodeIdentifier (quark_name), "GQuark")));
99 cquark_fun.block = cquark_block;
100 cfile.add_function (cquark_fun);
103 public override CCodeFragment register_dbus_info (ObjectTypeSymbol sym) {
104 return new CCodeFragment ();