[systemd-devel] sd_bus_add_match callback
David J
emacsd at icloud.com
Tue Apr 7 21:54:58 UTC 2020
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 (emacsd at icloud.com)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20200407/f0c5c4e9/attachment.htm>
More information about the systemd-devel
mailing list