diff options
Diffstat (limited to 'src/libsystemd/sd-bus')
-rw-r--r-- | src/libsystemd/sd-bus/bus-internal.h | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-match.c | 10 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-objects.c | 16 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-slot.c | 20 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/sd-bus.c | 28 |
5 files changed, 74 insertions, 2 deletions
diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h index 618e82c98f..f2ccdfd177 100644 --- a/src/libsystemd/sd-bus/bus-internal.h +++ b/src/libsystemd/sd-bus/bus-internal.h @@ -298,6 +298,8 @@ struct sd_bus { sd_bus_message *current_message; sd_bus_slot *current_slot; + sd_bus_message_handler_t current_handler; + void *current_userdata; sd_bus **default_bus_ptr; pid_t tid; diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c index 9e0769caa6..88b61a75be 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -294,11 +294,17 @@ int bus_match_run( sd_bus_slot *slot; slot = container_of(node->leaf.callback, sd_bus_slot, match_callback); - if (bus) + if (bus) { bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = node->leaf.callback->callback; + bus->current_userdata = slot->userdata; + } r = node->leaf.callback->callback(bus, m, slot->userdata, &error_buffer); - if (bus) + if (bus) { + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); + } r = bus_maybe_reply_error(m, r, &error_buffer); if (r != 0) diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c index 78dab8048d..03604091ec 100644 --- a/src/libsystemd/sd-bus/bus-objects.c +++ b/src/libsystemd/sd-bus/bus-objects.c @@ -51,7 +51,9 @@ static int node_vtable_get_userdata( u = s->userdata; if (c->find) { bus->current_slot = sd_bus_slot_ref(s); + bus->current_userdata = u; r = c->find(bus, path, c->interface, u, &u, error); + bus->current_userdata = NULL; bus->current_slot = sd_bus_slot_unref(s); if (r < 0) @@ -123,7 +125,9 @@ static int add_enumerated_to_set( slot = container_of(c, sd_bus_slot, node_enumerator); bus->current_slot = sd_bus_slot_ref(slot); + bus->current_userdata = slot->userdata; r = c->callback(bus, prefix, slot->userdata, &children, error); + bus->current_userdata = NULL; bus->current_slot = sd_bus_slot_unref(slot); if (r < 0) @@ -273,7 +277,11 @@ static int node_callbacks_run( slot = container_of(c, sd_bus_slot, node_callback); bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = c->callback; + bus->current_userdata = slot->userdata; r = c->callback(bus, m, slot->userdata, &error_buffer); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); r = bus_maybe_reply_error(m, r, &error_buffer); @@ -388,7 +396,11 @@ static int method_callbacks_run( slot = container_of(c->parent, sd_bus_slot, node_vtable); bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = c->vtable->x.method.handler; + bus->current_userdata = u; r = c->vtable->x.method.handler(bus, m, u, &error); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); return bus_maybe_reply_error(m, r, &error); @@ -427,7 +439,9 @@ static int invoke_property_get( if (v->x.property.get) { bus->current_slot = sd_bus_slot_ref(slot); + bus->current_userdata = userdata; r = v->x.property.get(bus, path, interface, property, reply, userdata, error); + bus->current_userdata = NULL; bus->current_slot = sd_bus_slot_unref(slot); if (r < 0) @@ -489,7 +503,9 @@ static int invoke_property_set( if (v->x.property.set) { bus->current_slot = sd_bus_slot_ref(slot); + bus->current_userdata = userdata; r = v->x.property.set(bus, path, interface, property, value, userdata, error); + bus->current_userdata = NULL; bus->current_slot = sd_bus_slot_unref(slot); if (r < 0) diff --git a/src/libsystemd/sd-bus/bus-slot.c b/src/libsystemd/sd-bus/bus-slot.c index 5e927511d5..d6793c29e9 100644 --- a/src/libsystemd/sd-bus/bus-slot.c +++ b/src/libsystemd/sd-bus/bus-slot.c @@ -245,3 +245,23 @@ _public_ sd_bus_message *sd_bus_slot_get_current_message(sd_bus_slot *slot) { return slot->bus->current_message; } + +_public_ sd_bus_message_handler_t sd_bus_slot_get_current_handler(sd_bus_slot *slot) { + assert_return(slot, NULL); + assert_return(slot->type >= 0, NULL); + + if (slot->bus->current_slot != slot) + return NULL; + + return slot->bus->current_handler; +} + +_public_ void* sd_bus_slot_get_current_userdata(sd_bus_slot *slot) { + assert_return(slot, NULL); + assert_return(slot->type >= 0, NULL); + + if (slot->bus->current_slot != slot) + return NULL; + + return slot->bus->current_userdata; +} diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 0fadd1699e..83233fd7e6 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -2102,7 +2102,11 @@ static int process_timeout(sd_bus *bus) { bus->current_message = m; bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = c->callback; + bus->current_userdata = slot->userdata; r = c->callback(bus, m, slot->userdata, &error_buffer); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); bus->current_message = NULL; @@ -2194,7 +2198,11 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) { } bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = c->callback; + bus->current_userdata = slot->userdata; r = c->callback(bus, m, slot->userdata, &error_buffer); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); if (slot->floating) { @@ -2235,7 +2243,11 @@ static int process_filter(sd_bus *bus, sd_bus_message *m) { slot = container_of(l, sd_bus_slot, filter_callback); bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = l->callback; + bus->current_userdata = slot->userdata; r = l->callback(bus, m, slot->userdata, &error_buffer); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); r = bus_maybe_reply_error(m, r, &error_buffer); @@ -2512,7 +2524,11 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) { bus->current_message = m; bus->current_slot = sd_bus_slot_ref(slot); + bus->current_handler = c->callback; + bus->current_userdata = slot->userdata; r = c->callback(bus, m, slot->userdata, &error_buffer); + bus->current_userdata = NULL; + bus->current_handler = NULL; bus->current_slot = sd_bus_slot_unref(slot); bus->current_message = NULL; @@ -3113,6 +3129,18 @@ _public_ sd_bus_slot* sd_bus_get_current_slot(sd_bus *bus) { return bus->current_slot; } +_public_ sd_bus_message_handler_t sd_bus_get_current_handler(sd_bus *bus) { + assert_return(bus, NULL); + + return bus->current_handler; +} + +_public_ void* sd_bus_get_current_userdata(sd_bus *bus) { + assert_return(bus, NULL); + + return bus->current_userdata; +} + static int bus_default(int (*bus_open)(sd_bus **), sd_bus **default_bus, sd_bus **ret) { sd_bus *b = NULL; int r; |