]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
D-Bus: Support Cancellable parameter in GDBus clients
authorJürg Billeter <j@bitron.ch>
Wed, 20 Oct 2010 14:51:11 +0000 (16:51 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 23 Oct 2010 16:11:47 +0000 (18:11 +0200)
codegen/valagdbusclientmodule.vala
codegen/valagdbusservermodule.vala
tests/dbus/async-errors.test
tests/dbus/errors.test

index 34d158db6cceb97e59d9e885d0fc176dd896a718..65bebfcd8bbcea77327071dd801b7edca1b383b0 100644 (file)
@@ -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 ()));
index 10fbe5408213929db7e51a0ec32a6bc111a2cc3f..9cb79c3e411112aa0992c3b6c0888dd2f73eb34f 100644 (file)
@@ -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)));
index c3c669f54a66fe546e509d46f6d914301b8b0181..4c9483f5d34c434aac3ab3555027822080873f4c 100644 (file)
@@ -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;
index 826aeb37149e7311f66467be0308ab934153ffd0..9088fb4fddce00c5ea163ac16129e76992a7c6da 100644 (file)
@@ -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;