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



[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++;
	}
}


void main () {
	try {
		var conn = Bus.get_sync (BusType.SESSION);
		int i = 0;
		var sv = new DemoServer ();
		conn.register_object ("/org/example/Demo", sv);
		var app = new Application ("org.example.Demo");
		Timeout.add_seconds(4, () => {
			sv.TestProp = "fff" + i.to_string(); 
			sv.Lctest("signal from server\n"); 
			i++; 
			return true;
		});
//		sv.notify["TestProp"].connect( () => { print("notify TestProp\n"); });
		app.run ();
	} 
	catch (IOError e) {
		stderr.printf ("%s\n", e.message);
	}
}

//$ 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