6 [DBus (name = "org.example.Test")]
7 interface Test : Object {
8 public abstract async void test_void () throws Error;
9 public abstract async int test_int (int i, out int j) throws Error;
10 public abstract async string test_string (string s, out string t) throws Error;
11 public abstract async void test_cancellable (Cancellable? cancellable = null) throws Error;
17 Test test = yield Bus.get_proxy (BusType.SESSION, "org.example.Test", "/org/example/test");
20 yield test.test_void ();
21 assert_not_reached ();
27 k = yield test.test_int (42, out j);
28 assert_not_reached ();
34 u = yield test.test_string ("hello", out t);
35 assert_not_reached ();
40 var cancellable = new Cancellable ();
41 cancellable.cancel ();
42 yield test.test_cancellable (cancellable);
43 assert_not_reached ();
54 main_loop = new MainLoop (null, false);
60 [DBus (name = "org.example.Test")]
62 public async void test_void () throws Error {
63 Idle.add (test_void.callback);
65 throw new IOError.FAILED ("Operation failed");
68 public async int test_int (int i, out int j) throws Error {
69 Idle.add (test_int.callback);
71 throw new IOError.FAILED ("Operation failed");
74 public async string test_string (string s, out string t) throws Error {
75 Idle.add (test_string.callback);
77 throw new IOError.FAILED ("Operation failed");
80 public async void test_cancellable (Cancellable? cancellable = null) throws Error {
81 Idle.add (test_cancellable.callback);
88 void client_exit (Pid pid, int status) {
89 // client finished, terminate server
95 var conn = Bus.get_sync (BusType.SESSION);
96 conn.register_object ("/org/example/test", new Test ());
98 // try to register service in session bus
99 var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
100 new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
101 assert ((uint) request_result.get_child_value (0) == 1);
103 // server ready, spawn client
105 Process.spawn_async (null, { "test", "/dbus/async-errors/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
106 ChildWatch.add (client_pid, client_exit);
108 main_loop = new MainLoop ();