Hello
I updated the test case to also work with vala-0.10.0 . 

Still not working. 

Is there anybody who can tell about signals in vala + GDBus ?
Regards
Jörn


> Hello
> I've got an issue connecting dbus signals with GDBus. 
> 
> In this mail I send an example showing the problem with two programs
> 'client.vala' and 'server.vala'.
> These two shall run at the same time and the server is sending signals
> every few seconds, while the client connects to these.
> 
> Funny thing is while it is perfectly possible to read properties and
> call functions from the client, I cannot catch signals from the server
> there. Also the notify from the changed property is lost somewhere (but
> I'm not sure if notify is working at all via dbus).
> 
> The signals that are sent from the server every few seconds can be
> watched in 'dbus-monitor' on another commandline window.
> 
> Please give me a hint what I'm doing wrong here. I'm using vala-0.9.8
> release.
> 
> Regards,
> Jörn
> 
> 
> 
> _______________________________________________
> vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list

[DBus (name = "org.example.Demo")]
interface DemoNotify : Object {
	
	public signal void TestSign(string ff);
	public signal void Lctest(string ff);
	
	public abstract string TestProp { owned get; set; }
	
	public abstract int ping (string msg)  throws IOError;
}

void main () {
	try {
		DemoNotify demonotify = Bus.get_proxy_sync(BusType.SESSION, "org.example.Demo", "/org/example/Demo");
		
		demonotify.Lctest.connect( () => { print("signal reached client");});
		
		demonotify.notify.connect( (s,p) => { print("%s\n", p.name); }); 
		
		demonotify.ping ("Hello from Vala");
		
		print("prop:%s\n", demonotify.TestProp);

	}
	catch (IOError e) {
		print("%s\n", e.message);
	}
	new MainLoop(null, false).run();
}

//$ valac --pkg gio-2.0 client.vala
[DBus (name = "org.example.Demo")]
public class DemoServer : Object {

	public signal void Lctest(string ff);
	
	private string _TestProp = "startval";
	public signal void TestSign(string ff);
	public string TestProp {
		owned get{
			return _TestProp;
		}
		set{
			_TestProp = value;
		}
	}
	
	private int counter;
	public int ping (string msg) {
		stdout.printf ("%s\n", msg);
		return counter++;
	}
}

public class Test {
	private DBusConnection conn;
	private int i = 0;
	
	private void on_bus_acquired(DBusConnection connection, string name) {
		print("bus acquired\n");
		try {
			conn = connection;
			var sv = new DemoServer ();
			conn.register_object ("/org/example/Demo", sv);
			Timeout.add_seconds(4, () => {
				sv.TestProp = "fff" + i.to_string(); 
				sv.Lctest("signal from server\n"); 
				i++; 
				return true;
			});
		} 
		catch(IOError e) {
			print("%s\n", e.message);
		}
	}

	private void on_name_acquired(DBusConnection connection, string name) {
		print("name acquired\n");
	}	

	private void on_name_lost(DBusConnection connection, string name) {
		print("name_lost\n");
	}

	public static void main () {
		var t = new Test();
		try {
			uint owner_id = Bus.own_name(BusType.SESSION,
							             "org.example.Demo",
							             GLib.BusNameOwnerFlags.NONE,
							             t.on_bus_acquired,
							             t.on_name_acquired,
							             t.on_name_lost);
		} 
		catch (IOError e) {
			stderr.printf ("%s\n", e.message);
		}
		new MainLoop(null, false).run();
	}
}
//$ valac --pkg gio-2.0 server.vala

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

Reply via email to