From: Jürg Billeter Date: Wed, 20 Oct 2010 14:51:11 +0000 (+0200) Subject: D-Bus: Support Cancellable parameter in GDBus clients X-Git-Tag: 0.11.1~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f815f16434555ec8f56d0b95abf2aeea786483aa;p=thirdparty%2Fvala.git D-Bus: Support Cancellable parameter in GDBus clients --- diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala index 34d158db6..65bebfcd8 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 10fbe5408..9cb79c3e4 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 c3c669f54..4c9483f5d 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 826aeb371..9088fb4fd 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;