diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-04-03 22:35:42 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-04-04 13:38:58 -0700 |
commit | 219ab1fbd00c7ee8636e4ae17e0996b5078d556d (patch) | |
tree | 982095d175ac079243965ec4121fc5c49f3676f0 /src/shared/bus-util.c | |
parent | 3d9489ee457a81c0efe0bac3ea899f7470ef506a (diff) | |
download | systemd-219ab1fbd00c7ee8636e4ae17e0996b5078d556d.tar.gz |
bus: introduce some sd-bus convenience helpers
Many of the convenience functions from sd-bus operate on verbose sets
of discrete strings for destination/path/interface/member.
For most callers, destination/path/interface are uniform, and just the
member is distinct.
This commit introduces a new struct encapsulating the
destination/path/interface pointers called BusAddress, and wrapper
functions which take a BusAddress* instead of three strings, and just
pass the encapsulated strings on to the sd-bus convenience functions.
Future commits will update call sites to use these helpers throwing
out a bunch of repetitious destination/path/interface strings littered
throughout the codebase, replacing them with some appropriately named
static structs passed by pointer to these new helpers.
Diffstat (limited to 'src/shared/bus-util.c')
-rw-r--r-- | src/shared/bus-util.c | 139 |
1 files changed, 139 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); +} |