Question regarding sd_bus_add_match (sd-bus.c):
Is it acceptable (or recommended) to use the same callback for multiple signal match and then using the userdata parameter to distinguish among the different signals? See the sample code below for a reference of what I am trying to do. /*Beginning=========================================*/ int callback(sd_bus_message *message, void *userdata, sd_bus_error *error) { //there should be a lock applied here? if(get_signal_id(userdata) == 1) { //do something } } int main(...) { r = sd_bus_add_match(bus, &slot, "type='signal'", test_callback, userdata); int r; sd_bus *bus = NULL; sd_event *event = NULL; sd_bus_slot *slot = NULL; r = sd_bus_default_system(&bus); assert(r >= 0); r = sd_event_default(&event); assert(r >= 0); void *userdata1 = set_signal_id(1); r = sd_bus_add_match(bus, &slot, "type='signal',interface='org.interface2'", callback, userdata1); void *userdata2 = set_signal_id(2); r = sd_bus_add_match(bus, &slot, "type='signal',interface='org.interface1'", callback, userdata2); r = sd_event_loop(event); assert(r >= 0); bus = sd_bus_flush_close_unref(bus); slot = sd_bus_slot_unref(slot); event = sd_event_unref(event); } /*End =========================================*/ I appreciate your help and your time. Thank you, David J (ema...@icloud.com)
_______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel