This avoids use of dynamic storage (malloc/new) and thread safety (mutexes) to provide a very simple sigslots implementation that can be used for *very* embedded development.
This is a light version of ecl_sigslots and provides a very ruthlessly simple signals and slots mechanisms useful for very* embedded development. You can read more about signals and slots in the ecl_sigslots package.
Some differences between from ecl_sigslots - Not thread safe... This is a bit of a vague statement on its own. In essence, its usually important to make sure your signals and slots finish processing any currently executing slots before they self destruct. Most sigslot implementations dont do this, ecl_sigslots does, but ecl_sigslots_lite does not. If you have a monolothic program with a single thread, this probably doesn't matter, but if not, then you must take care to ensure signals and slots close appropriately. On the plus side, there is no dependency on platform api for mutexes. - No disconnects... Adding disconnect capability adds alot of complexity to the sigslots implementation. Lite sigslots assume that signals and slots connections, once fixed until the signal goes out of scope. - No dynamic storage (no heap storage with malloc/new)... This is often verboten with various embedded compilers and introduces alot of system overhead. Lite sigslots allocates memory up front and will not permit overuse thereafter. - Self contained... While utilising things like standard error flag constructors (from ecl_errors) might be convenient, this package is and likely will often be used standalone in a firmware project. As a result, its designed with its own internal mechanisms (e.g. error class). This implies that a simple 'make sources' (refer to ecl_build's documentation for more information) is sufficient to gather header and source files for direct inclusion into a firmware project.
Include the following at the top of any translation unit which requires this library:
As its a template header library, you do not need to link.
Users of lite sigslots don't actually directly use Slot classes (unlike ecl_sigslots). Slots are still there, but they are stored behind the scenes, either in a global slots manager or member slots manager inherited by a class.
Signals and slots need to reserve memory before usage. For global slots, you need to set a static variable before making any connections to slots of that type.
For member slots, your class needs to inherit from the MemberSlots interface and specify the capacity as a template parameter (default is 1).
For signals, simply specify the capacity template parameter (again default is 1) when instantiating the signal. This reflects the number of connections it can handle.
Connections are made via the connect functions, linking directly to the function pointers.
There are some utility functions for debugging.
These are more of a rough coverage test. - src/examples/sigslots.cpp
- <b>Mar 11</b> : redesigned to be self contained. - <b>Feb 11</b> : prototype implementation tested.