From fa17b4e8d93c715793e35242829b33fef54bddea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 6 Jun 2018 11:07:02 +0200 Subject: bus: optionally call a callbacks for cleanup This adds a function sd_bus_slot_set_destroy_callback() to set a function which can free userdata or perform other cleanups. sd_bus_slot_get_destory_callback() queries the callback, and is included for completeness. Without something like this, for floating asynchronous callbacks, which might be called or not, depending on the sequence of events, it's hard to perform resource cleanup. The alternative would be to always perform the cleanup from the caller too, but that requires more coordination and keeping of some shared state. It's nicer to keep the cleanup contained between the callback and the function that requests the callback. --- man/sd_bus_slot_set_destroy_callback.xml | 105 +++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 man/sd_bus_slot_set_destroy_callback.xml (limited to 'man/sd_bus_slot_set_destroy_callback.xml') diff --git a/man/sd_bus_slot_set_destroy_callback.xml b/man/sd_bus_slot_set_destroy_callback.xml new file mode 100644 index 0000000000..6334444f9a --- /dev/null +++ b/man/sd_bus_slot_set_destroy_callback.xml @@ -0,0 +1,105 @@ + + + + + + + + + sd_bus_slot_set_destroy_callback + systemd + + + + sd_bus_slot_set_destroy_callback + 3 + + + + sd_bus_slot_set_destroy_callback + sd_bus_slot_get_destroy_callback + + Define the callback function for resource cleanup. + + + + + #include <systemd/sd-bus.h> + + + typedef int (*sd_bus_destroy_t) + void *userdata + + + + int sd_bus_slot_set_destroy_callback + sd_bus_slot *slot + sd_bus_destroy_t callback + + + + int sd_bus_slot_get_destroy_callback + sd_bus_slot *slot + sd_bus_destroy_t *callback + + + + + + Description + + sd_bus_slot_set_destroy_callback() sets + callback as the callback function to be called right before the bus slot + object slot is deallocated. The userdata pointer + from the slot object will be passed as the userdata parameter. This + pointer can be set specified as an argument to the constuctor functions, see + sd_bus_add_match3, + or directly, see + sd_bus_set_userdata3. + This callback function is called even if userdata is + NULL. + + sd_bus_slot_get_destroy_callback() returns the current callback + for slot in the callback parameter. + + + + Return Value + + On success, sd_bus_slot_set_destroy_callback() returns 0 or a + positive integer. On failure, it returns a negative errno-style error code. + + sd_bus_slot_get_destroy_callback() returns 1 if the destroy callback + function is set, 0 if not. On failure, it returns a negative errno-style error code. + + + + Errors + + Returned errors may indicate the following problems: + + + + -EINVAL + + The slot parameter is NULL. + + + + + + + + + See Also + + + systemd1, + sd-bus3, + sd_bus_slot_set_floating3 + + + + -- cgit v1.2.1