[vala] D-Bus: Fix tiny code duplication for method calls in GDBus clients



commit 4a04aaaf720503de0304da06247e5bea06958cd4
Author: Jürg Billeter <j bitron ch>
Date:   Mon Oct 18 13:58:37 2010 +0200

    D-Bus: Fix tiny code duplication for method calls in GDBus clients

 codegen/valagdbusclientmodule.vala |   21 ++++-----------------
 1 files changed, 4 insertions(+), 17 deletions(-)
---
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index 7729d8a..5302195 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -55,7 +55,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 		push_function (func);
 
 		if (dynamic_method.dynamic_type.data_type == dbus_proxy_type) {
-			generate_dbus_method_wrapper (method);
+			generate_marshalling (method, CallType.SYNC, null, method.name);
 		} else {
 			Report.error (method.source_reference, "dynamic methods are not supported for `%s'".printf (dynamic_method.dynamic_type.to_string ()));
 		}
@@ -66,13 +66,6 @@ public class Vala.GDBusClientModule : GDBusModule {
 		cfile.add_function (func);
 	}
 
-	void generate_dbus_method_wrapper (Method m) {
-		ccode.add_declaration ("GVariant", new CCodeVariableDeclarator ("*_arguments"));
-		ccode.add_declaration ("GVariant", new CCodeVariableDeclarator ("*_reply"));
-
-		generate_marshalling (m, CallType.SYNC, null, m.name);
-	}
-
 	void generate_proxy_interface_init (Interface main_iface, Interface iface) {
 		// also generate proxy for prerequisites
 		foreach (var prereq in iface.get_prerequisites ()) {
@@ -385,6 +378,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 	void generate_marshalling (Method m, CallType call_type, string? iface_name, string? method_name) {
 		if (call_type != CallType.FINISH) {
+			ccode.add_declaration ("GVariant", new CCodeVariableDeclarator ("*_arguments"));
 			ccode.add_declaration ("GVariantBuilder", new CCodeVariableDeclarator ("_arguments_builder"));
 
 			var builder_init = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_init"));
@@ -477,6 +471,8 @@ public class Vala.GDBusClientModule : GDBusModule {
 		}
 
 		if (call_type == CallType.SYNC || call_type == CallType.FINISH) {
+			ccode.add_declaration ("GVariant", new CCodeVariableDeclarator ("*_reply"));
+
 			// return on error
 			ccode.open_if (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("_reply")));
 			return_default_value (m.return_type);
@@ -569,11 +565,6 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 		push_function (function);
 
-		ccode.add_declaration ("GVariant", new CCodeVariableDeclarator ("*_arguments"));
-		if (!no_reply) {
-			ccode.add_declaration ("GVariant", new CCodeVariableDeclarator ("*_reply"));
-		}
-
 		generate_marshalling (m, no_reply ? CallType.NO_REPLY : CallType.SYNC, dbus_iface_name, "%s.%s".printf (dbus_iface_name, get_dbus_name_for_member (m)));
 
 		pop_function ();
@@ -601,8 +592,6 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 		push_function (function);
 
-		ccode.add_declaration ("GVariant", new CCodeVariableDeclarator ("*_arguments"));
-
 		generate_marshalling (m, CallType.ASYNC, dbus_iface_name, "%s.%s".printf (dbus_iface_name, get_dbus_name_for_member (m)));
 
 		pop_function ();
@@ -627,8 +616,6 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 		push_function (function);
 
-		ccode.add_declaration ("GVariant", new CCodeVariableDeclarator ("*_reply"));
-
 		generate_marshalling (m, CallType.FINISH, null, null);
 
 		pop_function ();



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