diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-05-15 01:15:30 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-05-15 01:15:30 +0200 |
commit | 19befb2d5fc087f96e40ddc432b2cc9385666209 (patch) | |
tree | 4a28a54ed25ba8fb57578f639b2691749c9c935e /src/libsystemd/sd-bus/bus-util.c | |
parent | 9a78148e40402b44f361f4fbf63bb97a21aeac0b (diff) |
sd-bus: introduce sd_bus_slot objects encapsulating callbacks or vtables attached to a bus connection
This makes callback behaviour more like sd-event or sd-resolve, and
creates proper object for unregistering callbacks.
Taking the refernce to the slot is optional. If not taken life time of
the slot will be bound to the underlying bus object (or in the case of
an async call until the reply has been recieved).
Diffstat (limited to 'src/libsystemd/sd-bus/bus-util.c')
-rw-r--r-- | src/libsystemd/sd-bus/bus-util.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c index 84b3fc5af5..b5b3c857b8 100644 --- a/src/libsystemd/sd-bus/bus-util.c +++ b/src/libsystemd/sd-bus/bus-util.c @@ -77,7 +77,7 @@ int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) { if (r < 0) return -ENOMEM; - r = sd_bus_add_match(bus, match, name_owner_change_callback, e); + r = sd_bus_add_match(bus, NULL, match, name_owner_change_callback, e); if (r < 0) return r; @@ -251,17 +251,16 @@ typedef struct AsyncPolkitQuery { sd_bus_message *request, *reply; sd_bus_message_handler_t callback; void *userdata; - uint64_t serial; + sd_bus_slot *slot; Hashmap *registry; } AsyncPolkitQuery; -static void async_polkit_query_free(sd_bus *b, AsyncPolkitQuery *q) { +static void async_polkit_query_free(AsyncPolkitQuery *q) { if (!q) return; - if (q->serial > 0 && b) - sd_bus_call_async_cancel(b, q->serial); + sd_bus_slot_unref(q->slot); if (q->registry && q->request) hashmap_remove(q->registry, q->request); @@ -281,8 +280,8 @@ static int async_polkit_callback(sd_bus *bus, sd_bus_message *reply, void *userd assert(reply); assert(q); + q->slot = sd_bus_slot_unref(q->slot); q->reply = sd_bus_message_ref(reply); - q->serial = 0; r = sd_bus_message_rewind(q->request, true); if (r < 0) { @@ -294,7 +293,8 @@ static int async_polkit_callback(sd_bus *bus, sd_bus_message *reply, void *userd r = bus_maybe_reply_error(q->request, r, &error_buffer); finish: - async_polkit_query_free(bus, q); + async_polkit_query_free(q); + return r; } @@ -413,15 +413,15 @@ int bus_verify_polkit_async( r = hashmap_put(*registry, m, q); if (r < 0) { - async_polkit_query_free(bus, q); + async_polkit_query_free(q); return r; } q->registry = *registry; - r = sd_bus_call_async(bus, pk, async_polkit_callback, q, 0, &q->serial); + r = sd_bus_call_async(bus, &q->slot, pk, async_polkit_callback, q, 0); if (r < 0) { - async_polkit_query_free(bus, q); + async_polkit_query_free(q); return r; } @@ -436,7 +436,7 @@ void bus_verify_polkit_async_registry_free(sd_bus *bus, Hashmap *registry) { AsyncPolkitQuery *q; while ((q = hashmap_steal_first(registry))) - async_polkit_query_free(bus, q); + async_polkit_query_free(q); hashmap_free(registry); #endif |