/*
 * COMPILE WITH: valac --pkg gio-2.0 test.vala
 * RUN SERVER WITH: ./test server
 * RUN CLIENT WITH: ./test
 */

[DBus (name = "a.small.test")]
public interface Test : Object {
	public abstract double[]  get_normal_array() throws IOError;
	public abstract double[,] get_multi_array()  throws IOError;
}


[DBus (name = "a.small.test")]
public class Foo : Object {
	public double[] get_normal_array() {
		return new double[] { 2.0, 3.0 };
	}

	public double[,] get_multi_array() {
		return new double[,] { { 2.0, 3.0 }, { 4.0, 5.0 } };
	}
}


static int main(string[] args) {

	if(args[1] == "server") {
		var loop = new GLib.MainLoop();
		
		Bus.own_name(GLib.BusType.SESSION, "a.small.test", BusNameOwnerFlags.NONE, (conn) => {
				try {
					conn.register_object("/a/small/test", new Foo());
				} catch(Error e) {
					error(e.message);
				}
			}, () => {}, () => error("Unable to acquire name"));
		
		loop.run();
	} else {
		try {
			Test test = Bus.get_proxy_sync(BusType.SESSION, "a.small.test", "/a/small/test");

			var a = test.get_normal_array();
			message("[ %g, %g ]", a[0], a[1]);

			var b = test.get_multi_array();
			message("[ [ %g, %g ] , [ %g, %g ] ]", b[0,0], b[0,1], b[1,0], b[1,1]);

			//loop.quit ();
		} catch(IOError e) {
			error(e.message);
		}
	}
	return 0;
}
