[vala/gdbus: 2/8] D-Bus: Use builder API for interface_method_call in GDBus servers



commit 9fddf10db54b22a590fc8f92021c0a75b4881e9d
Author: Jürg Billeter <j bitron ch>
Date:   Tue Oct 19 08:23:24 2010 +0200

    D-Bus: Use builder API for interface_method_call in GDBus servers

 codegen/valagdbusservermodule.vala |   38 ++++++++++++++---------------------
 1 files changed, 15 insertions(+), 23 deletions(-)
---
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index 28acf76..05156ca 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -550,20 +550,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
@@ -578,25 +570,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);
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]