Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a 'slot' in sd-bus (C language)

There are several APIs in systemd's sd-bus.h file which optionally take a slot argument. Here's some examples:

int sd_bus_call_async(sd_bus *bus, sd_bus_slot **slot, sd_bus_message *m, sd_bus_message_handler_t callback, void *userdata, uint64_t usec);
int sd_bus_add_filter(sd_bus *bus, sd_bus_slot **slot, sd_bus_message_handler_t callback, void *userdata);
int sd_bus_add_fallback(sd_bus *bus, sd_bus_slot **slot, const char *prefix, sd_bus_message_handler_t callback, void *userdata);

If the calling code specifies NULL then it becomes a "floating slot" which I guess means the calling code doesn't need to worry about it.

Most of the example source code I see out there is like this example project: https://github.com/tasleson/dbus-signals/blob/6d0e43d02d24ed51a17ce7df15a3a0a64ec0170d/spamsignals.c#L160

It takes a slot, and then sometime later it unreferences the slot. But it doesn't actually do anything with it.

like image 737
Benjamin Leinweber Avatar asked Apr 14 '17 15:04

Benjamin Leinweber


People also ask

What is a slot in computer?

A slot may refer to any of the following: 1. When referring to an SD or other memory cards, a slot is the hole the card is placed into. 2. A slot is an opening for a CD-ROM, DVD, and other disc drive that does not use a tray.

What's the signal / slot pattern?

What’s the Signal / Slot Pattern? [...] a language construct [...] which makes it easy to implement the Observer pattern while avoiding boilerplate code. The concept is that GUI widgets can send signals containing event information which can be received by other controls using special functions known as slots. - Wikipedia

What is the oldest type of slot in a computer?

This is the oldest slot type that is still available today. Computers with ISA slots are no longer available from major computer manufacturers, Ram PC Systems still sells industrial class systems with ISA slots. PCI slots were the replacment for ISA slots.

What is a slot in a DVD player?

2. A slot is an opening for a CD-ROM, DVD, and other disc drive that does not use a tray. See our slot load disc drive definition for further information.


2 Answers

Federico is correct, but perhaps more detail would help? The slot is essentially an opaque handle that lets you manage the life-cycle of the object that you are attaching to your sd_bus handle (a vtable, match rule, filter, etc). This is useful when you want to add something and then later remove it.

If the object that you are adding will remain for the lifetime of your process and/or the sd_bus handle you attach it to, then you should probably pass NULL.

like image 59
Chris Steres Avatar answered Oct 18 '22 18:10

Chris Steres


Passing your own slot makes your sd-bus-match life being entangled to the one of the slot. This way, when you unreference the slot, you are also destroying the match.
Otherwise, passing NULL will bound your match's life to the one of bus object itself.
The same goes for other functions you listed:
* sd_bus_call_async with a slot gives you the option to destroy the async call by unreferencing the slot.
*sd_bus_add_filter with a slot will destroy the filter when you unreference the slot.
I am not sure about sd_bus_add_fallback because i never heard about it though.
Check here for function being called when slot gets unreferenced: https://github.com/systemd/systemd/blob/a7753693547233e4a1d6e10b1a8f6515a477f227/src/libsystemd/sd-bus/bus-slot.c#L68

like image 44
Federico Avatar answered Oct 18 '22 17:10

Federico