Hello,

during the last two days I tried to figure out how to use signals with
dbus. There were a couple of problems, finally a testcase was created,
showing that signals are woking fine:
http://git.gnome.org/browse/vala/diff/tests/dbus/signals.test

But this does not work in all cases. The attached testcase shows that
signals do not work, if the client casts the dbus.object to the original
class and not an interface (as in the testcase above).

Hopefully the testcase is correct and it shows the problem.

Greetings
-fabian

From af119aeb8f499029f23afcb936019930d84abea3 Mon Sep 17 00:00:00 2001
From: Fabian Deutsch <[email protected]>
Date: Mon, 22 Mar 2010 14:47:04 +0100
Subject: [PATCH] D-Bus: Add loopback signals test.

Signed-off-by: Fabian Deutsch <[email protected]>
---
 tests/dbus/signals-loopback.test |   56 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)
 create mode 100644 tests/dbus/signals-loopback.test

diff --git a/tests/dbus/signals-loopback.test b/tests/dbus/signals-loopback.test
new file mode 100644
index 0000000..69a8a1d
--- /dev/null
+++ b/tests/dbus/signals-loopback.test
@@ -0,0 +1,56 @@
+Packages: dbus-glib-1
+
+Program: loopback
+
+[DBus (name = "org.example.Test")]
+class Test : Object {
+	public signal void foo (int i);
+
+	public void do_foo (int i) {
+		this.foo (i);
+	}
+}
+
+MainLoop main_loop;
+Test server;
+
+void client_exit (Pid pid, int status) {
+	// client finished, terminate server
+	assert (status == 0);
+	main_loop.quit ();
+}
+
+void main () {
+	var conn = DBus.Bus.get (DBus.BusType.SESSION);
+	dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus");
+
+	// try to register service in session bus
+	uint request_name_result = bus.request_name ("org.example.Test", (uint) 0);
+	if (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER)
+	{
+		// start server
+		server = new Test ();
+		conn.register_object ("/org/example/test", server);
+
+		// server ready, spawn client
+		Pid client_pid;
+		Process.spawn_async (null, { "test", "/dbus/signals/loopback" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
+		ChildWatch.add (client_pid, client_exit);
+	}
+	else
+	{
+		// client
+		var test = (Test) conn.get_object ("org.example.Test", "/org/example/test");
+
+		test.foo.connect ((i) => {
+			assert (i == 42);
+			main_loop.quit ();
+		});
+
+		test.do_foo (42);
+	}
+	
+	main_loop = new MainLoop (null, false);
+	main_loop.run ();
+}
+
-- 
1.7.0.1

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to