diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-04-09 09:32:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-09 09:32:58 +0200 |
commit | ca03142040f944385c9561cb9c030a64535a2e86 (patch) | |
tree | fa9244995805ff10a7d2b45401b06987e2a5aed2 | |
parent | systemd-run: add --slice-inherit (diff) | |
parent | bus: introduce some sd-bus convenience helpers (diff) | |
download | systemd-ca03142040f944385c9561cb9c030a64535a2e86.tar.xz systemd-ca03142040f944385c9561cb9c030a64535a2e86.zip |
Merge pull request #15331 from vcaputo/busdpi
bus: introduce some sd-bus convenience helpers
-rw-r--r-- | src/shared/bus-util.c | 139 | ||||
-rw-r--r-- | src/shared/bus-util.h | 19 |
2 files changed, 158 insertions, 0 deletions
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 4b0a3a3e31..dbbd0dcae6 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1390,3 +1390,142 @@ const struct hash_ops bus_message_hash_ops = { .compare = trivial_compare_func, .free_value = bus_message_unref_wrapper, }; + +/* Shorthand flavors of the sd-bus convenience helpers with destination,path,interface + * strings encapsulated within a single struct. + */ +int bus_call_method_async( + sd_bus *bus, + sd_bus_slot **slot, + const BusAddress *address, + const char *member, + sd_bus_message_handler_t callback, + void *userdata, + const char *types, ...) { + + va_list ap; + int r; + + assert(address); + + va_start(ap, types); + r = sd_bus_call_method_asyncv(bus, slot, address->destination, address->path, address->interface, member, callback, userdata, types, ap); + va_end(ap); + + return r; +} + +int bus_call_method( + sd_bus *bus, + const BusAddress *address, + const char *member, + sd_bus_error *error, + sd_bus_message **reply, + const char *types, ...) { + + va_list ap; + int r; + + assert(address); + + va_start(ap, types); + r = sd_bus_call_methodv(bus, address->destination, address->path, address->interface, member, error, reply, types, ap); + va_end(ap); + + return r; +} + +int bus_get_property( + sd_bus *bus, + const BusAddress *address, + const char *member, + sd_bus_error *error, + sd_bus_message **reply, + const char *type) { + + assert(address); + + return sd_bus_get_property(bus, address->destination, address->path, address->interface, member, error, reply, type); +} + +int bus_get_property_trivial( + sd_bus *bus, + const BusAddress *address, + const char *member, + sd_bus_error *error, + char type, void *ptr) { + + assert(address); + + return sd_bus_get_property_trivial(bus, address->destination, address->path, address->interface, member, error, type, ptr); +} + +int bus_get_property_string( + sd_bus *bus, + const BusAddress *address, + const char *member, + sd_bus_error *error, + char **ret) { + + assert(address); + + return sd_bus_get_property_string(bus, address->destination, address->path, address->interface, member, error, ret); +} + +int bus_get_property_strv( + sd_bus *bus, + const BusAddress *address, + const char *member, + sd_bus_error *error, + char ***ret) { + + assert(address); + + return sd_bus_get_property_strv(bus, address->destination, address->path, address->interface, member, error, ret); +} + +int bus_set_property( + sd_bus *bus, + const BusAddress *address, + const char *member, + sd_bus_error *error, + const char *type, ...) { + + va_list ap; + int r; + + assert(address); + + va_start(ap, type); + r = sd_bus_set_propertyv(bus, address->destination, address->path, address->interface, member, error, type, ap); + va_end(ap); + + return r; +} + +int bus_match_signal( + sd_bus *bus, + sd_bus_slot **ret, + const BusAddress *address, + const char *member, + sd_bus_message_handler_t callback, + void *userdata) { + + assert(address); + + return sd_bus_match_signal(bus, ret, address->destination, address->path, address->interface, member, callback, userdata); +} + +int bus_match_signal_async( + sd_bus *bus, + sd_bus_slot **ret, + const BusAddress *address, + const char *member, + sd_bus_message_handler_t callback, + sd_bus_message_handler_t install_callback, + void *userdata) { + + assert(address); + + return sd_bus_match_signal_async(bus, ret, address->destination, address->path, address->interface, member, callback, install_callback, userdata); +} diff --git a/src/shared/bus-util.h b/src/shared/bus-util.h index db245a791e..f3bdde41ae 100644 --- a/src/shared/bus-util.h +++ b/src/shared/bus-util.h @@ -22,6 +22,12 @@ typedef enum BusTransport { _BUS_TRANSPORT_INVALID = -1 } BusTransport; +typedef struct BusAddress { + const char *destination; + const char *path; + const char *interface; +} BusAddress; + typedef int (*bus_property_set_t) (sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata); struct bus_properties_map { @@ -179,3 +185,16 @@ static inline int bus_open_system_watch_bind(sd_bus **ret) { int bus_reply_pair_array(sd_bus_message *m, char **l); extern const struct hash_ops bus_message_hash_ops; + +/* Shorthand flavors of the sd-bus convenience helpers with destination,path,interface + * strings encapsulated within a single struct. + */ +int bus_call_method_async(sd_bus *bus, sd_bus_slot **slot, const BusAddress *address, const char *member, sd_bus_message_handler_t callback, void *userdata, const char *types, ...); +int bus_call_method(sd_bus *bus, const BusAddress *address, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *types, ...); +int bus_get_property(sd_bus *bus, const BusAddress *address, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *type); +int bus_get_property_trivial(sd_bus *bus, const BusAddress *address, const char *member, sd_bus_error *error, char type, void *ptr); +int bus_get_property_string(sd_bus *bus, const BusAddress *address, const char *member, sd_bus_error *error, char **ret); +int bus_get_property_strv(sd_bus *bus, const BusAddress *address, const char *member, sd_bus_error *error, char ***ret); +int bus_set_property(sd_bus *bus, const BusAddress *address, const char *member, sd_bus_error *error, const char *type, ...); +int bus_match_signal(sd_bus *bus, sd_bus_slot **ret, const BusAddress *address, const char *member, sd_bus_message_handler_t callback, void *userdata); +int bus_match_signal_async(sd_bus *bus, sd_bus_slot **ret, const BusAddress *address, const char *member, sd_bus_message_handler_t callback, sd_bus_message_handler_t install_callback, void *userdata); |