Skyward boardcore
|
#include <EventBroker.h>
Public Member Functions | |
void | post (const Event &ev, uint8_t topic, EventHandlerBase *subscriber=nullptr) |
uint16_t | postDelayed (const Event &ev, uint8_t topic, unsigned int delayMs) |
void | removeDelayed (uint16_t id) |
void | subscribe (EventHandlerBase *subscriber, uint8_t topic) |
void | unsubscribe (EventHandlerBase *subscriber, uint8_t topic) |
Unsubscribe an EventHandler from a specific topic This function should be used only for testing purposes. | |
void | unsubscribe (EventHandlerBase *subscriber) |
Unsubribe an EventHandler from all the topics it is subscribed to. This function should be used only for testing purposes. | |
void | clearDelayedEvents () |
Unschedules all pending events. This function should be used only for testing purposes. | |
EventBroker () | |
Construct a new Event Broker object. | |
![]() | |
Singleton (const Singleton &)=delete | |
Singleton & | operator= (const Singleton &)=delete |
![]() | |
ActiveObject (unsigned int stacksize=miosix::STACK_DEFAULT_FOR_PTHREAD, miosix::Priority priority=miosix::MAIN_PRIORITY) | |
virtual | ~ActiveObject () |
virtual bool | start () |
Start the thread associated with this active object. | |
virtual void | stop () |
Signals the runner thread to terminate and joins the thread. | |
bool | isRunning () |
Friends | |
class | Singleton< EventBroker > |
Additional Inherited Members | |
![]() | |
static EventBroker & | getInstance () |
![]() | |
Singleton () | |
![]() | |
bool | shouldStop () |
Tells whether or not the ActiveObject should stop its execution. | |
![]() | |
miosix::Thread * | thread = nullptr |
Gives access to the thread object. | |
std::atomic< bool > | stopFlag {false} |
std::atomic< bool > | running {false} |
The EventBroker class implements the pub-sub paradigm to dispatch events to multiple objects. An object of type FSM can subscribe to a topic in the public topics enum and publish an event into it. The event will be posted in to each FSM object subscribed to that specific topic.
Definition at line 58 of file EventBroker.h.
Boardcore::EventBroker::EventBroker | ( | ) |
Construct a new Event Broker object.
Public access required for testing purposes. Use the singleton interface to access this class in production code.
Definition at line 31 of file EventBroker.cpp.
void Boardcore::EventBroker::clearDelayedEvents | ( | ) |
Unschedules all pending events. This function should be used only for testing purposes.
Definition at line 127 of file EventBroker.cpp.
void Boardcore::EventBroker::post | ( | const Event & | ev, |
uint8_t | topic, | ||
EventHandlerBase * | subscriber = nullptr ) |
Posts an event to the specified topic.
subscriber | If provided the event won't be forwarded to the given subscriber. |
Definition at line 33 of file EventBroker.cpp.
uint16_t Boardcore::EventBroker::postDelayed | ( | const Event & | ev, |
uint8_t | topic, | ||
unsigned int | delayMs ) |
Posts an event after the specified delay.
event | |
topic | |
delayMs | Delay in milliseconds. |
Definition at line 59 of file EventBroker.cpp.
void Boardcore::EventBroker::removeDelayed | ( | uint16_t | id | ) |
Removes a delayed event before it is posted.
id | The id returned by postDelayed(...). |
Definition at line 94 of file EventBroker.cpp.
void Boardcore::EventBroker::subscribe | ( | EventHandlerBase * | subscriber, |
uint8_t | topic ) |
Subscribe to a specific topic. DO NOT call it in response to an event, or it will cause a deadlock.
subscriber | |
topic |
Definition at line 107 of file EventBroker.cpp.
void Boardcore::EventBroker::unsubscribe | ( | EventHandlerBase * | subscriber | ) |
Unsubribe an EventHandler from all the topics it is subscribed to. This function should be used only for testing purposes.
subscriber |
Definition at line 120 of file EventBroker.cpp.
void Boardcore::EventBroker::unsubscribe | ( | EventHandlerBase * | subscriber, |
uint8_t | topic ) |
Unsubscribe an EventHandler from a specific topic This function should be used only for testing purposes.
subscriber | |
topic |
Definition at line 113 of file EventBroker.cpp.
|
friend |
Definition at line 50 of file EventBroker.h.