]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
D-Bus: Use builder API for interface_method_call in GDBus servers
authorJürg Billeter <j@bitron.ch>
Tue, 19 Oct 2010 06:23:24 +0000 (08:23 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 23 Oct 2010 16:11:46 +0000 (18:11 +0200)
codegen/valagdbusservermodule.vala

index 7bb9a4313292af29d2b3db15c0b83d8ef5ef6205..4e28f366b7c76e8b3f389e15723dfce6c4a85286 100644 (file)
@@ -556,20 +556,12 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
                cfunc.modifiers |= CCodeModifiers.STATIC;
 
-               cfile.add_function_declaration (cfunc);
+               push_function (cfunc);
 
-               var block = new CCodeBlock ();
-               cfunc.block = block;
+               ccode.add_declaration ("gpointer*", new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
+               ccode.add_declaration ("gpointer", new CCodeVariableDeclarator ("object", new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0"))));
 
-               var cdecl = new CCodeDeclaration ("gpointer*");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
-               block.add_statement (cdecl);
-
-               cdecl = new CCodeDeclaration ("gpointer");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("object", new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0"))));
-               block.add_statement (cdecl);
-
-               CCodeIfStatement clastif = null;
+               bool first = true;
 
                foreach (Method m in sym.get_methods ()) {
                        if (m is CreationMethod || m.binding != MemberBinding.INSTANCE
@@ -584,25 +576,25 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                        ccheck.add_argument (new CCodeIdentifier ("method_name"));
                        ccheck.add_argument (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (m))));
 
-                       var callblock = new CCodeBlock ();
+                       if (first) {
+                               ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")));
+                               first = false;
+                       } else {
+                               ccode.else_if (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")));
+                       }
 
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier (generate_dbus_wrapper (m, sym)));
                        ccall.add_argument (new CCodeIdentifier ("object"));
                        ccall.add_argument (new CCodeIdentifier ("parameters"));
                        ccall.add_argument (new CCodeIdentifier ("invocation"));
+                       ccode.add_expression (ccall);
+               }
 
-                       callblock.add_statement (new CCodeExpressionStatement (ccall));
-
-                       var cif = new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")), callblock);
-                       if (clastif == null) {
-                               block.add_statement (cif);
-                       } else {
-                               clastif.false_statement = cif;
-                       }
+               ccode.close ();
 
-                       clastif = cif;
-               }
+               pop_function ();
 
+               cfile.add_function_declaration (cfunc);
                cfile.add_function (cfunc);
        }