6 #include <systemd/sd-bus.h>
8 #define _cleanup_(f) __attribute__((cleanup(f)))
10 typedef struct object
{
15 static int method(sd_bus_message
*m
, void *userdata
, sd_bus_error
*error
) {
16 printf("Got called with userdata=%p\n", userdata
);
20 static const sd_bus_vtable vtable
[] = {
21 SD_BUS_VTABLE_START(0),
23 "Method1", "s", "s", method
, 0),
24 SD_BUS_METHOD_WITH_NAMES_OFFSET(
26 "so", SD_BUS_PARAM(string
) SD_BUS_PARAM(path
),
27 "s", SD_BUS_PARAM(returnstring
),
28 method
, offsetof(object
, number
),
29 SD_BUS_VTABLE_DEPRECATED
),
30 SD_BUS_METHOD_WITH_ARGS_OFFSET(
32 SD_BUS_ARGS("s", string
, "o", path
),
33 SD_BUS_RESULT("s", returnstring
),
34 method
, offsetof(object
, number
),
35 SD_BUS_VTABLE_UNPRIVILEGED
),
36 SD_BUS_METHOD_WITH_ARGS(
41 SD_BUS_VTABLE_UNPRIVILEGED
),
46 SD_BUS_SIGNAL_WITH_NAMES(
48 "so", SD_BUS_PARAM(string
) SD_BUS_PARAM(path
),
50 SD_BUS_SIGNAL_WITH_ARGS(
52 SD_BUS_ARGS("s", string
, "o", path
),
54 SD_BUS_WRITABLE_PROPERTY(
55 "AutomaticStringProperty", "s", NULL
, NULL
,
56 offsetof(object
, name
),
57 SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
58 SD_BUS_WRITABLE_PROPERTY(
59 "AutomaticIntegerProperty", "u", NULL
, NULL
,
60 offsetof(object
, number
),
61 SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
67 errno = r < 0 ? -r : 0; \
68 printf(#x ": %m\n"); \
70 return EXIT_FAILURE; \
73 int main(int argc
, char **argv
) {
74 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
78 object object
= { .number
= 666 };
79 check((object
.name
= strdup("name")) != NULL
);
81 check(sd_bus_add_object_vtable(bus
, NULL
, "/object",
82 "org.freedesktop.systemd.VtableExample",
87 check(sd_bus_wait(bus
, UINT64_MAX
));
88 check(sd_bus_process(bus
, NULL
));