[vala/gdbus: 8/8] D-Bus: Support Cancellable parameter in GDBus clients
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/gdbus: 8/8] D-Bus: Support Cancellable parameter in GDBus clients
- Date: Wed, 20 Oct 2010 15:26:17 +0000 (UTC)
commit c09bf76759dfabad11b27ed8511fba3ebfcee31f
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 187e164..6524d66 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -421,6 +421,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);
@@ -428,6 +430,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);
}
}
@@ -459,7 +466,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) {
@@ -482,7 +489,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 ("_callback_"));
ccall.add_argument (new CCodeIdentifier ("_user_data_"));
ccode.add_expression (ccall);
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index 5c521fb..93432b1 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -110,6 +110,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;
@@ -133,6 +137,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)));
@@ -324,6 +333,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;
@@ -784,6 +797,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 7dd3edb..092ec7a 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;
@@ -33,6 +34,14 @@ async void run (Test test) {
} 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]