[vala/wip/tintou/dbus-proxy-set-interface-info: 7/7] gdbus: Use GDBusProxy API to set `g-interface-info` at initialization time
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/tintou/dbus-proxy-set-interface-info: 7/7] gdbus: Use GDBusProxy API to set `g-interface-info` at initialization time
- Date: Sun, 5 Apr 2020 15:19:57 +0000 (UTC)
commit 7392951cad7f76b0cc3de4d830f3ea9970f403bb
Author: Corentin Noël <corentin elementary io>
Date: Fri Apr 3 12:53:27 2020 +0200
gdbus: Use GDBusProxy API to set `g-interface-info` at initialization time
This allows GDBusProxy subclasses to have the g-interface-info assigned
even when the class hasn't been created by Vala itself.
Keep obsolete setting of 'vala-dbus-interface-info' to preserve backwards
compatibility.
codegen/valagdbusclientmodule.vala | 26 ++++++++--------
tests/Makefile.am | 1 +
tests/dbus/interface-info.test | 62 ++++++++++++++++++++++++++++++++++++++
3 files changed, 75 insertions(+), 14 deletions(-)
---
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index 12a7693d2..2327a09aa 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -236,6 +236,17 @@ public class Vala.GDBusClientModule : GDBusModule {
var proxy_instance_init = new CCodeFunction (lower_cname + "_init", "void");
proxy_instance_init.add_parameter (new CCodeParameter ("self", cname + "*"));
proxy_instance_init.modifiers = CCodeModifiers.STATIC;
+ push_function (proxy_instance_init);
+
+ // TODO Replaces setting of "vala-dbus-interface-info"
+ var dbus_proxy_cast = new CCodeFunctionCall (new CCodeIdentifier ("G_DBUS_PROXY"));
+ dbus_proxy_cast.add_argument (new CCodeIdentifier ("self"));
+ var set_interface_info = new CCodeFunctionCall (new CCodeIdentifier
("g_dbus_proxy_set_interface_info"));
+ set_interface_info.add_argument (dbus_proxy_cast);
+ set_interface_info.add_argument (new CCodeCastExpression (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, get_interface_info (iface)), "GDBusInterfaceInfo *"));
+ ccode.add_expression (set_interface_info);
+
+ pop_function ();
cfile.add_function (proxy_instance_init);
generate_proxy_interface_init (iface, iface);
@@ -257,7 +268,6 @@ public class Vala.GDBusClientModule : GDBusModule {
CCodeExpression proxy_type;
CCodeExpression dbus_iface_name;
- CCodeExpression dbus_iface_info;
var object_type = type_arg as ObjectType;
if (object_type != null) {
@@ -292,15 +302,6 @@ public class Vala.GDBusClientModule : GDBusModule {
dbus_iface_name = get_qdata;
}
- var quark = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string"));
- quark.add_argument (new CCodeConstant ("\"vala-dbus-interface-info\""));
-
- var get_qdata = new CCodeFunctionCall (new CCodeIdentifier ("g_type_get_qdata"));
- get_qdata.add_argument (get_type_id_expression (type_arg));
- get_qdata.add_argument (quark);
-
- dbus_iface_info = get_qdata;
-
if (bus_get_proxy_async || conn_get_proxy_async) {
if (ma.member_name == "end" && ma.inner.symbol_reference == ma.symbol_reference) {
// method can fail
@@ -397,10 +398,6 @@ public class Vala.GDBusClientModule : GDBusModule {
ccall.add_argument (get_cvalue (object_path));
ccall.add_argument (new CCodeConstant ("\"g-interface-name\""));
ccall.add_argument (dbus_iface_name);
- if (dbus_iface_info != null) {
- ccall.add_argument (new CCodeConstant ("\"g-interface-info\""));
- ccall.add_argument (dbus_iface_info);
- }
ccall.add_argument (new CCodeConstant ("NULL"));
if (bus_get_proxy_async || conn_get_proxy_async) {
@@ -1212,6 +1209,7 @@ public class Vala.GDBusClientModule : GDBusModule {
block.add_statement (new CCodeExpressionStatement (set_qdata));
+ // TODO Replaced by g_dbus_proxy_set_interface_info() call in *_init
quark = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string"));
quark.add_argument (new CCodeConstant ("\"vala-dbus-interface-info\""));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cca6a2927..88aaac40a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -589,6 +589,7 @@ TESTS = \
dbus/bug783002.test \
dbus/bug792277.vala \
dbus/rawvariants.test \
+ dbus/interface-info.test \
gir/bug651773.test \
gir/bug667751.test \
gir/bug742012.test \
diff --git a/tests/dbus/interface-info.test b/tests/dbus/interface-info.test
new file mode 100644
index 000000000..9b9bca753
--- /dev/null
+++ b/tests/dbus/interface-info.test
@@ -0,0 +1,62 @@
+Packages: gio-2.0
+D-Bus
+
+Program: client
+
+[DBus (name = "org.example.Test")]
+interface Test : Object {
+ [DBus (name = "Baz")]
+ public signal void bar (string j);
+}
+
+MainLoop main_loop;
+
+void main () {
+ // client
+ Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
+
+ unowned GLib.DBusProxy proxy = (GLib.DBusProxy) test;
+ unowned DBusInterfaceInfo? iface_info = proxy.get_interface_info ();
+ assert (iface_info != null);
+ assert (iface_info.signals != null);
+ assert (iface_info.signals[0] != null);
+ assert (iface_info.signals[0].name == "Baz");
+ assert (iface_info.signals[0].args != null);
+ assert (iface_info.signals[0].args[0] != null);
+ assert (iface_info.signals[0].args[0].signature == "s");
+
+ assert (iface_info == (DBusInterfaceInfo?) typeof (Test).get_qdata (Quark.from_string
("vala-dbus-interface-info")));
+}
+
+Program: server
+
+[DBus (name = "org.example.Test")]
+class Test : Object {
+ public signal void foo (int i);
+}
+
+MainLoop main_loop;
+
+void client_exit (Pid pid, int status) {
+ // client finished, terminate server
+ assert (status == 0);
+ main_loop.quit ();
+}
+
+void main () {
+ var conn = Bus.get_sync (BusType.SESSION);
+ conn.register_object ("/org/example/test", new Test ());
+
+ // try to register service in session bus
+ var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus", "RequestName",
+ new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
+ assert ((uint) request_result.get_child_value (0) == 1);
+
+ // server ready, spawn client
+ Pid client_pid;
+ Process.spawn_async (null, { "dbus_interface_info_client" }, null, SpawnFlags.DO_NOT_REAP_CHILD,
null, out client_pid);
+ ChildWatch.add (client_pid, client_exit);
+
+ main_loop = new MainLoop ();
+ main_loop.run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]