[Documentation] [TitleIndex] [WordIndex


Signals and slots provide a means for intra-process communication. The classes here let you have a many-to-many relationship (unlike most event callback techniques), and also templatise the data transfer to allow the coder to customise the event data that is communicated from signal to slot. It also implements a few conditional (event) related classes.




Anywhere that triggers an event requiring a callback to be executed can be implemented with a signal. These can be placed anywhere in your code and can be connected to one or many slots.


Anywhere that a callback function is required can be implemented with a slot. These can be placed anywhere in your code and are initialised with either a static (global) function, or a member function. Once initialised, they can be hooked up to a signal.

Message Data

The signal-slot pairs developed here only ever accept one template argument representing the data to be transmitted from signal to slot. It would be easy to extend this to more (aka SigSlot/Boost) but I have yet to find a need for it - if you wish multiple arguments, simply wrap up your data in a single struct/class. Conceptually, this makes the code more readable anyway.

The data class itself could be as simple as an error id or as complicated as the current state in a fsm. Note that both signal and slot must use the same type.

Compiling & Linking

Include the following at the top of any translation unit:

   1 #include <ecl/sigslots.hpp>
   3 // The types
   4 using ecl::Signal;
   5 using ecl::Slots;

You will also need to link to ecl_sigslots.



2024-07-20 13:20