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_WRITABLE_PROPERTY(
31 "AutomaticStringProperty", "s", NULL
, NULL
,
32 offsetof(object
, name
),
33 SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
34 SD_BUS_WRITABLE_PROPERTY(
35 "AutomaticIntegerProperty", "u", NULL
, NULL
,
36 offsetof(object
, number
),
37 SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
43 errno = r < 0 ? -r : 0; \
44 printf(#x ": %m\n"); \
46 return EXIT_FAILURE; \
49 int main(int argc
, char **argv
) {
50 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
54 object object
= { .number
= 666 };
55 check((object
.name
= strdup("name")) != NULL
);
57 check(sd_bus_add_object_vtable(bus
, NULL
, "/object",
58 "org.freedesktop.systemd.VtableExample",
63 check(sd_bus_wait(bus
, UINT64_MAX
));
64 check(sd_bus_process(bus
, NULL
));