Exemple #1
0
        public override void visit_error_domain(ErrorDomain edomain)
        {
            if (edomain.comment != null)
            {
                cfile.add_type_definition(new CCodeComment(edomain.comment.content));
            }

            generate_error_domain_declaration(edomain, cfile);

            if (!edomain.is_internal_symbol())
            {
                generate_error_domain_declaration(edomain, header_file);
            }
            if (!edomain.is_private_symbol())
            {
                generate_error_domain_declaration(edomain, internal_header_file);
            }

            string quark_fun_name = get_ccode_lower_case_prefix(edomain) + "quark";

            var cquark_fun = new CCodeFunction(quark_fun_name, get_ccode_name(gquark_type.data_type));

            push_function(cquark_fun);

            var cquark_call = new CCodeFunctionCall(new CCodeIdentifier("g_quark_from_static_string"));

            cquark_call.add_argument(new CCodeConstant("\"" + CCodeBaseModule.get_quark_name(edomain) + "\""));

            ccode.add_return(cquark_call);

            pop_function();
            cfile.add_function(cquark_fun);
        }
Exemple #2
0
        public override void visit_error_domain(ErrorDomain edomain)
        {
            var edomain_dbus_name = get_dbus_name(edomain);

            if (edomain_dbus_name == null)
            {
                base.visit_error_domain(edomain);
                return;
            }

            cfile.add_include("gio/gio.h");

            generate_error_domain_declaration(edomain, cfile);

            if (!edomain.is_internal_symbol())
            {
                generate_error_domain_declaration(edomain, header_file);
            }
            if (!edomain.is_private_symbol())
            {
                generate_error_domain_declaration(edomain, internal_header_file);
            }

            var error_entries = new CCodeInitializerList();

            foreach (ErrorCode ecode in edomain.get_codes())
            {
                var ecode_dbus_name = get_dbus_name(ecode);
                if (ecode_dbus_name == null)
                {
                    ecode_dbus_name = Symbol.lower_case_to_camel_case(ecode.name.ToLower());
                }

                var error_entry = new CCodeInitializerList();
                error_entry.append(new CCodeIdentifier(get_ccode_name(ecode)));
                error_entry.append(new CCodeConstant("\"%s.%s\"".printf(edomain_dbus_name, ecode_dbus_name)));
                error_entries.append(error_entry);
            }

            var cdecl = new CCodeDeclaration("const GDBusErrorEntry");

            cdecl.add_declarator(new CCodeVariableDeclarator(get_ccode_lower_case_name(edomain) + "_entries[]", error_entries));
            cdecl.modifiers = CCodeModifiers.STATIC;
            cfile.add_constant_declaration(cdecl);

            string quark_fun_name = get_ccode_lower_case_prefix(edomain) + "quark";

            var cquark_fun = new CCodeFunction(quark_fun_name, get_ccode_name(gquark_type.data_type));

            push_function(cquark_fun);

            string quark_name = "%squark_volatile".printf(get_ccode_lower_case_prefix(edomain));

            ccode.add_declaration("gsize", new CCodeVariableDeclarator(quark_name, new CCodeConstant("0")), CCodeModifiers.STATIC | CCodeModifiers.VOLATILE);

            var register_call = new CCodeFunctionCall(new CCodeIdentifier("g_dbus_error_register_error_domain"));

            register_call.add_argument(new CCodeConstant("\"" + CCodeBaseModule.get_quark_name(edomain) + "\""));
            register_call.add_argument(new CCodeUnaryExpression(CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier(quark_name)));
            register_call.add_argument(new CCodeIdentifier(get_ccode_lower_case_name(edomain) + "_entries"));
            var nentries = new CCodeFunctionCall(new CCodeIdentifier("G_N_ELEMENTS"));

            nentries.add_argument(new CCodeIdentifier(get_ccode_lower_case_name(edomain) + "_entries"));
            register_call.add_argument(nentries);
            ccode.add_expression(register_call);

            ccode.add_return(new CCodeCastExpression(new CCodeIdentifier(quark_name), "GQuark"));

            pop_function();
            cfile.add_function(cquark_fun);
        }