]>
Commit | Line | Data |
---|---|---|
dd418b9a LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2013 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #include "util.h" | |
23 | ||
24 | #include "sd-bus.h" | |
25 | #include "bus-message.h" | |
26 | #include "bus-error.h" | |
27 | #include "bus-kernel.h" | |
28 | ||
29 | int main(int argc, char *argv[]) { | |
30 | _cleanup_close_ int bus_ref = -1; | |
31 | _cleanup_free_ char *bus_name = NULL, *address = NULL; | |
e9a967f9 LP |
32 | _cleanup_bus_message_unref_ sd_bus_message *m = NULL; |
33 | const char *ua = NULL, *ub = NULL, *the_string = NULL; | |
dd418b9a LP |
34 | sd_bus *a, *b; |
35 | int r; | |
36 | ||
37 | bus_ref = bus_kernel_create("deine-mutter", &bus_name); | |
4e3431bc LP |
38 | if (bus_ref == -ENOENT) |
39 | return EXIT_TEST_SKIP; | |
40 | ||
dd418b9a LP |
41 | assert_se(bus_ref >= 0); |
42 | ||
296f3c53 | 43 | address = strappend("kernel:path=", bus_name); |
dd418b9a LP |
44 | assert_se(address); |
45 | ||
46 | r = sd_bus_new(&a); | |
47 | assert_se(r >= 0); | |
48 | ||
49 | r = sd_bus_new(&b); | |
50 | assert_se(r >= 0); | |
51 | ||
52 | r = sd_bus_set_address(a, address); | |
53 | assert_se(r >= 0); | |
54 | ||
55 | r = sd_bus_set_address(b, address); | |
56 | assert_se(r >= 0); | |
57 | ||
58 | r = sd_bus_start(a); | |
59 | assert_se(r >= 0); | |
60 | ||
61 | r = sd_bus_start(b); | |
62 | assert_se(r >= 0); | |
63 | ||
64 | r = sd_bus_get_unique_name(a, &ua); | |
65 | assert_se(r >= 0); | |
66 | ||
296f3c53 | 67 | printf("unique a: %s\n", ua); |
dd418b9a LP |
68 | |
69 | r = sd_bus_get_unique_name(b, &ub); | |
70 | assert_se(r >= 0); | |
71 | ||
296f3c53 LP |
72 | printf("unique b: %s\n", ub); |
73 | ||
a56f19c4 | 74 | r = sd_bus_emit_signal(a, "/foo/bar/waldo", "waldo.com", "Piep", "sss", "I am a string", "/this/is/a/path", "and.this.a.domain.name"); |
e9a967f9 LP |
75 | assert_se(r >= 0); |
76 | ||
77 | r = sd_bus_process(b, &m); | |
78 | assert_se(r > 0); | |
79 | assert_se(m); | |
80 | ||
f9be01f3 LP |
81 | bus_message_dump(m); |
82 | assert_se(sd_bus_message_rewind(m, true) >= 0); | |
83 | ||
e9a967f9 LP |
84 | r = sd_bus_message_read(m, "s", &the_string); |
85 | assert_se(r >= 0); | |
86 | assert_se(streq(the_string, "I am a string")); | |
87 | ||
3583882c LP |
88 | sd_bus_message_unref(m); |
89 | m = NULL; | |
90 | ||
ed7d0b22 | 91 | r = sd_bus_request_name(a, "net.x0pointer.foobar", 0); |
f08838da LP |
92 | assert_se(r >= 0); |
93 | ||
ed7d0b22 | 94 | r = sd_bus_message_new_method_call(b, "net.x0pointer.foobar", "/a/path", "an.inter.face", "AMethod", &m); |
3583882c LP |
95 | assert_se(r >= 0); |
96 | ||
97 | r = sd_bus_send(b, m, NULL); | |
98 | assert_se(r >= 0); | |
99 | ||
100 | for (;;) { | |
101 | sd_bus_message_unref(m); | |
102 | m = NULL; | |
103 | r = sd_bus_process(a, &m); | |
104 | assert_se(r > 0); | |
105 | assert_se(m); | |
106 | ||
107 | bus_message_dump(m); | |
108 | assert_se(sd_bus_message_rewind(m, true) >= 0); | |
2da833ac LP |
109 | |
110 | if (sd_bus_message_is_method_call(m, "an.inter.face", "AMethod")) | |
111 | break; | |
3583882c LP |
112 | } |
113 | ||
ed7d0b22 | 114 | r = sd_bus_release_name(a, "net.x0pointer.foobar"); |
f08838da LP |
115 | assert_se(r >= 0); |
116 | ||
ed7d0b22 | 117 | r = sd_bus_release_name(a, "net.x0pointer.foobar"); |
01f6c9d4 | 118 | assert_se(r == -ESRCH); |
f08838da | 119 | |
296f3c53 LP |
120 | sd_bus_unref(a); |
121 | sd_bus_unref(b); | |
dd418b9a LP |
122 | |
123 | return 0; | |
124 | } |