mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-16 00:46:03 +08:00
58 lines
2.8 KiB
Plaintext
58 lines
2.8 KiB
Plaintext
Callback Service
|
|
This template class allows easier integration of 'C' style events (such as interrupt vectors) and C++ handlers.
|
|
It can allow abstraction between low level events such as interrupts and their application dependent handlers.
|
|
The handlers may be any combination of global, static or member functions.
|
|
It utilises the templated function wrapper. See here.
|
|
|
|
The callbacks are identified by an id. The values of the ids must range from zero or a specified offset, up to the maximum number of specified callbacks. Calling an unused callback id will either do nothing or, if the user has specified a handler, call this with the id of the callback.
|
|
|
|
There are functions that use both runtime and compile time checks of the callback id.
|
|
Compile time is preferable.
|
|
____________________________________________________________________________________________________
|
|
Member functions
|
|
|
|
template <const size_t RANGE, const size_t OFFSET = 0U>
|
|
etl::callback_service
|
|
|
|
RANGE The id range of the callbacks.
|
|
OFFSET The starting id for the range.
|
|
____________________________________________________________________________________________________
|
|
callback_service()
|
|
|
|
Sets all of the callbacks to route to the unhandled callback.
|
|
Sets the unhandled callback to default (do nothing).
|
|
____________________________________________________________________________________________________
|
|
template <const size_t ID>
|
|
void register_callback(etl::ifunction<size_t>& callback)
|
|
|
|
Registers callback with the id specified in the template parameter.
|
|
A compile time error will occur if the id is out of range.
|
|
____________________________________________________________________________________________________
|
|
void register_callback(size_t id, etl::ifunction<size_t>& callback)
|
|
|
|
Registers callback with the id specified in the template parameter.
|
|
The registration will be ignored if the id is out of range.
|
|
____________________________________________________________________________________________________
|
|
void register_unhandled_callback(etl::ifunction<size_t>& callback)
|
|
|
|
Registers the callback to be used for unhandled ids.
|
|
____________________________________________________________________________________________________
|
|
template <const size_t ID>
|
|
void callback()
|
|
|
|
Calls the callback associated with the id.
|
|
Calls the unhandled callback if the id has not been registered.
|
|
A compile time error will occur if the id is out of range.
|
|
____________________________________________________________________________________________________
|
|
void callback(const size_t id)
|
|
|
|
Calls the callback associated with the id.
|
|
Calls the unhandled callback if the id has not been registered or if is out of range.
|
|
____________________________________________________________________________________________________
|
|
Example
|
|
|
|
Tutorial
|
|
|
|
See the example project in etl\examples\FunctionInterruptSimulation
|
|
|