[vala/gdbus: 9/11] D-Bus: Support Cancellable parameter in GDBus clients



commit 19e9cd45a6b47d68a9364d81461257779399edba
Author: Jürg Billeter <j bitron ch>
Date:   Wed Oct 20 16:51:11 2010 +0200

    D-Bus: Support Cancellable parameter in GDBus clients

 codegen/valagdbusclientmodule.vala |   11 +++++++++--
 codegen/valagdbusservermodule.vala |   17 +++++++++++++++++
 tests/dbus/async-errors.test       |   14 ++++++++++++++
 tests/dbus/errors.test             |   12 ++++++++++++
 4 files changed, 52 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index 34d158d..65bebfc 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -459,6 +459,8 @@ public class Vala.GDBusClientModule : GDBusModule {
 			ccode.add_declaration ("GUnixFDList", new CCodeVariableDeclarator ("*_fd_list"));
 			ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_fd_list"), new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_new"))));
 
+			CCodeExpression cancellable = new CCodeConstant ("NULL");
+
 			foreach (FormalParameter param in m.get_parameters ()) {
 				if (param.direction == ParameterDirection.IN) {
 					CCodeExpression expr = new CCodeIdentifier (param.name);
@@ -466,6 +468,11 @@ public class Vala.GDBusClientModule : GDBusModule {
 						expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, expr);
 					}
 
+					if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") {
+						cancellable = expr;
+						continue;
+					}
+
 					send_dbus_value (param.variable_type, new CCodeIdentifier ("_arguments_builder"), expr, param);
 				}
 			}
@@ -497,7 +504,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 				ccall.add_argument (new CCodeConstant ("G_DBUS_SEND_MESSAGE_FLAGS_NONE"));
 				ccall.add_argument (timeout);
 				ccall.add_argument (new CCodeConstant ("NULL"));
-				ccall.add_argument (new CCodeConstant ("NULL"));
+				ccall.add_argument (cancellable);
 				ccall.add_argument (new CCodeIdentifier ("error"));
 				ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_reply_message"), ccall));
 			} else if (call_type == CallType.NO_REPLY) {
@@ -520,7 +527,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 				ccall.add_argument (new CCodeConstant ("G_DBUS_SEND_MESSAGE_FLAGS_NONE"));
 				ccall.add_argument (timeout);
 				ccall.add_argument (new CCodeConstant ("NULL"));
-				ccall.add_argument (new CCodeConstant ("NULL"));
+				ccall.add_argument (cancellable);
 
 				// use wrapper as source_object wouldn't be correct otherwise
 				ccall.add_argument (new CCodeIdentifier (generate_async_callback_wrapper ()));
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index 10fbe54..9cb79c3 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -116,6 +116,10 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 					continue;
 				}
 
+				if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") {
+					continue;
+				}
+
 				var owned_type = param.variable_type.copy ();
 				owned_type.value_owned = true;
 
@@ -139,6 +143,11 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		foreach (FormalParameter param in m.get_parameters ()) {
 			if (param.direction == ParameterDirection.IN && !ready) {
+				if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") {
+					ccall.add_argument (new CCodeConstant ("NULL"));
+					continue;
+				}
+
 				var st = param.variable_type.data_type as Struct;
 				if (st != null && !st.is_simple_type ()) {
 					ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (param.name)));
@@ -330,6 +339,10 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		foreach (FormalParameter param in m.get_parameters ()) {
 			if ((param.direction == ParameterDirection.IN && !ready) ||
 			    (param.direction == ParameterDirection.OUT && !no_reply && (!m.coroutine || ready))) {
+				if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") {
+					continue;
+				}
+
 				var owned_type = param.variable_type.copy ();
 				owned_type.value_owned = true;
 
@@ -790,6 +803,10 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			var out_args_info = new CCodeInitializerList ();
 
 			foreach (FormalParameter param in m.get_parameters ()) {
+				if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") {
+					continue;
+				}
+
 				var info = new CCodeInitializerList ();
 				info.append (new CCodeConstant ("-1"));
 				info.append (new CCodeConstant ("\"%s\"".printf (param.name)));
diff --git a/tests/dbus/async-errors.test b/tests/dbus/async-errors.test
index c3c669f..4c9483f 100644
--- a/tests/dbus/async-errors.test
+++ b/tests/dbus/async-errors.test
@@ -8,6 +8,7 @@ interface Test : Object {
 	public abstract async void test_void () throws Error;
 	public abstract async int test_int (int i, out int j) throws Error;
 	public abstract async string test_string (string s, out string t) throws Error;
+	public abstract async void test_cancellable (Cancellable? cancellable = null) throws Error;
 }
 
 MainLoop main_loop;
@@ -35,6 +36,14 @@ async void run () {
 	} catch {
 	}
 
+	try {
+		var cancellable = new Cancellable ();
+		cancellable.cancel ();
+		yield test.test_cancellable (cancellable);
+		assert_not_reached ();
+	} catch {
+	}
+
 	main_loop.quit ();
 }
 
@@ -67,6 +76,11 @@ class Test : Object {
 		yield;
 		throw new IOError.FAILED ("Operation failed");
 	}
+
+	public async void test_cancellable (Cancellable? cancellable = null) throws Error {
+		Idle.add (test_cancellable.callback);
+		yield;
+	}
 }
 
 MainLoop main_loop;
diff --git a/tests/dbus/errors.test b/tests/dbus/errors.test
index 826aeb3..9088fb4 100644
--- a/tests/dbus/errors.test
+++ b/tests/dbus/errors.test
@@ -8,6 +8,7 @@ interface Test : Object {
 	public abstract void test_void () throws Error;
 	public abstract int test_int (int i, out int j) throws Error;
 	public abstract string test_string (string s, out string t) throws Error;
+	public abstract void test_cancellable (Cancellable? cancellable = null) throws Error;
 }
 
 void main () {
@@ -35,6 +36,14 @@ void main () {
 		assert_not_reached ();
 	} catch {
 	}
+
+	try {
+		var cancellable = new Cancellable ();
+		cancellable.cancel ();
+		test.test_cancellable (cancellable);
+		assert_not_reached ();
+	} catch {
+	}
 }
 
 Program: server
@@ -52,6 +61,9 @@ class Test : Object {
 	public string test_string (string s, out string t) throws Error {
 		throw new IOError.FAILED ("Operation failed");
 	}
+
+	public void test_cancellable (Cancellable? cancellable = null) throws Error {
+	}
 }
 
 MainLoop main_loop;



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