1 Packages: gio-2.0 gio-unix-2.0 posix
6 [DBus (name = "org.example.Test")]
7 interface Test : Object {
8 public abstract UnixInputStream test_in (UnixInputStream i, out UnixInputStream j) throws IOError;
13 Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
15 uint8[] buffer = new uint8[1];
17 int[] pipe1 = new int[2];
18 assert (Posix.pipe (pipe1) == 0);
20 assert (Posix.write (pipe1[1], buffer, 1) == 1);
21 Posix.close (pipe1[1]);
24 k = test.test_in (new UnixInputStream (pipe1[0], true), out j);
26 assert (j.read (buffer) == 1);
27 assert (buffer[0] == 23);
29 assert (k.read (buffer) == 1);
30 assert (buffer[0] == 11);
35 [DBus (name = "org.example.Test")]
37 public UnixInputStream test_in (UnixInputStream i, out UnixInputStream j) throws IOError {
38 uint8[] buffer = new uint8[1];
40 assert (i.read (buffer) == 1);
41 assert (buffer[0] == 42);
43 int[] pipe1 = new int[2];
44 assert (Posix.pipe (pipe1) == 0);
46 assert (Posix.write (pipe1[1], buffer, 1) == 1);
47 Posix.close (pipe1[1]);
49 int[] pipe2 = new int[2];
50 assert (Posix.pipe (pipe2) == 0);
52 assert (Posix.write (pipe2[1], buffer, 1) == 1);
53 Posix.close (pipe2[1]);
55 j = new UnixInputStream (pipe1[0], true);
56 return new UnixInputStream (pipe2[0], true);
62 void client_exit (Pid pid, int status) {
63 // client finished, terminate server
69 var conn = Bus.get_sync (BusType.SESSION);
70 conn.register_object ("/org/example/test", new Test ());
72 // try to register service in session bus
73 var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
74 new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
75 assert ((uint) request_result.get_child_value (0) == 1);
77 // server ready, spawn client
79 Process.spawn_async (null, { "test", "/dbus/filedescriptor/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
80 ChildWatch.add (client_pid, client_exit);
82 main_loop = new MainLoop ();