AVRToolsPlus
A library wof higher-level tools for AVR ATmega328 and ATmega2560 Microcontrollers
|
This namespace bundles the Event Manager functionality. It provides logical cohesion for functions implement the Event Manager and prevents namespace collisions. More...
Typedefs | |
typedef void(* | EventListener) (int eventCode, int eventParam) |
Type for an event listener (a.k.a. callback) function. | |
Enumerations | |
enum | GenericEvents |
This enum provides common event names, purely for user convenience. | |
enum | EventPriority |
EventManager recognizes two kinds of events. By default, events are are queued as low priority, but these constants can be used to explicitly set the priority when queueing events. More... | |
Functions | |
bool | addListener (int eventCode, EventListener listener) |
Add an (event, listener) pair listener to the dispatch table. More... | |
bool | removeListener (int eventCode, EventListener listener) |
Remove this (event, listener) pair from the dispatch table. Other listener pairs with the same function or event code will not be affected. More... | |
int | removeListener (EventListener listener) |
Remove all occurrances of a listener from the dispatch table, regardless of the event code. returns number removed. More... | |
bool | enableListener (int eventCode, EventListener listener, bool enable) |
Enable or disable an (event, listener) pair entry in the dispatch table. More... | |
bool | isListenerEnabled (int eventCode, EventListener listener) |
Obtain the the current enabled/disabled state of an (eventCode, listener) pair. More... | |
bool | setDefaultListener (EventListener listener) |
Set a default listener. The default listener is a callback function that is called when an event with no listener is processed. More... | |
void | removeDefaultListener () |
Remvoes the default listener. The default listener is a callback function that is called when an event with no listener is processed. | |
void | enableDefaultListener (bool enable) |
Enable or disable the default listener. The default listener is a callback function that is called when an event with no listener is processed. More... | |
bool | isListenerListEmpty () |
Check if the listener list (a.k.a., dispatch table) is empty. More... | |
bool | isListenerListFull () |
Check if the listener list (a.k.a., dispatch table) is full. More... | |
int | numListeners () |
Get the number of listeners in the dispatch table. More... | |
bool | isEventQueueEmpty (EventPriority pri=kLowPriority) |
Check if the event queue is empty. More... | |
bool | isEventQueueFull (EventPriority pri=kLowPriority) |
Check if the event queue is full. More... | |
int | getNumEventsInQueue (EventPriority pri=kLowPriority) |
Get the number of events in the event queue. More... | |
bool | queueEvent (int eventCode, int eventParam, EventPriority pri=kLowPriority) |
Tries to add an event into the event queue. More... | |
int | processEvent () |
Processes one event from the event queue and dispatches it to the corresponding listeners stored in the dispatch table. More... | |
int | processAllEvents () |
Processes all the events in the event queues and dispatches them to the corresponding listeners stored in the dispatch table. More... | |
This namespace bundles the Event Manager functionality. It provides logical cohesion for functions implement the Event Manager and prevents namespace collisions.
EventManager recognizes two kinds of events. By default, events are are queued as low priority, but these constants can be used to explicitly set the priority when queueing events.
bool EventManager::addListener | ( | int | eventCode, |
EventListener | listener | ||
) |
Add an (event, listener) pair listener to the dispatch table.
eventCode
the event code this listener listens for. listener
the listener to be called when there is an event with this eventCode.void EventManager::enableDefaultListener | ( | bool | enable | ) |
Enable or disable the default listener. The default listener is a callback function that is called when an event with no listener is processed.
enable
pass true to enable the default listener, false to disable it. bool EventManager::enableListener | ( | int | eventCode, |
EventListener | listener, | ||
bool | enable | ||
) |
Enable or disable an (event, listener) pair entry in the dispatch table.
eventCode
the event code of the (event, listener) pair to be enabled or disabled. listener
the listener of the (event, listener) pair to be enabled or disabled. enable
pass true to enable the (event, listener) pair, false to disable it.int EventManager::getNumEventsInQueue | ( | EventPriority | pri = kLowPriority | ) |
Get the number of events in the event queue.
pri
the desired event queue: kLowPriority or kHighPriority. Defaults to kLowPriority.bool EventManager::isEventQueueEmpty | ( | EventPriority | pri = kLowPriority | ) |
Check if the event queue is empty.
pri
the desired event queue: kLowPriority or kHighPriority. Defaults to kLowPriority.bool EventManager::isEventQueueFull | ( | EventPriority | pri = kLowPriority | ) |
Check if the event queue is full.
pri
the desired event queue: kLowPriority or kHighPriority. Defaults to kLowPriority.bool EventManager::isListenerEnabled | ( | int | eventCode, |
EventListener | listener | ||
) |
Obtain the the current enabled/disabled state of an (eventCode, listener) pair.
eventCode
the event code of the (event, listener) pair. listener
the listener of the (event, listener) pair.bool EventManager::isListenerListEmpty | ( | ) |
Check if the listener list (a.k.a., dispatch table) is empty.
bool EventManager::isListenerListFull | ( | ) |
Check if the listener list (a.k.a., dispatch table) is full.
int EventManager::numListeners | ( | ) |
Get the number of listeners in the dispatch table.
int EventManager::processAllEvents | ( | ) |
Processes all the events in the event queues and dispatches them to the corresponding listeners stored in the dispatch table.
Events are taken preferentially from the high priority queue. If the high priority queue is empty, then events are taken from the low prioirty queue.
All listeners associated with the event that are enabled will be called. Disabled listeners are not called.
The event processed is removed from the event queue (even if there is no listener to handle it).
int EventManager::processEvent | ( | ) |
Processes one event from the event queue and dispatches it to the corresponding listeners stored in the dispatch table.
Events are taken preferentially from the high priority queue. If the high priority queue is empty, then events are taken from the low prioirty queue.
All listeners associated with the event that are enabled will be called. Disabled listeners are not called.
The event processed is removed from the event queue (even if there is no listener to handle it).
bool EventManager::queueEvent | ( | int | eventCode, |
int | eventParam, | ||
EventPriority | pri = kLowPriority |
||
) |
Tries to add an event into the event queue.
eventCode
identifies the event to be added. eventParam
an integer parameter associated with this event. pri
specifies which queue gets the event: kLowPriority or kHighPriority. Defaults to kLowPriority.bool EventManager::removeListener | ( | int | eventCode, |
EventListener | listener | ||
) |
Remove this (event, listener) pair from the dispatch table. Other listener pairs with the same function or event code will not be affected.
eventCode
the event code of the (event, listener) pair to be removed. listener
the listener of the (event, listener) pair to be removed.int EventManager::removeListener | ( | EventListener | listener | ) |
Remove all occurrances of a listener from the dispatch table, regardless of the event code. returns number removed.
This function is useful when one listener handles many different events.
listener
the listener to be removed.bool EventManager::setDefaultListener | ( | EventListener | listener | ) |
Set a default listener. The default listener is a callback function that is called when an event with no listener is processed.
listener
the listener to be set as the default listener.listener
is null.