Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::EventBroker Class Reference

#include <EventBroker.h>

Inheritance diagram for Boardcore::EventBroker:
Collaboration diagram for Boardcore::EventBroker:

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.
 
- Public Member Functions inherited from Boardcore::Singleton< EventBroker >
 Singleton (const Singleton &)=delete
 
Singletonoperator= (const Singleton &)=delete
 
- Public Member Functions inherited from Boardcore::ActiveObject
 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 Public Member Functions inherited from Boardcore::Singleton< EventBroker >
static EventBrokergetInstance ()
 
- Protected Member Functions inherited from Boardcore::Singleton< EventBroker >
 Singleton ()
 
- Protected Member Functions inherited from Boardcore::ActiveObject
bool shouldStop ()
 Tells whether or not the ActiveObject should stop its execution.
 
- Protected Attributes inherited from Boardcore::ActiveObject
miosix::Thread * thread = nullptr
 Gives access to the thread object.
 
std::atomic< bool > stopFlag {false}
 
std::atomic< bool > running {false}
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ EventBroker()

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.

Member Function Documentation

◆ clearDelayedEvents()

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.

◆ post()

void Boardcore::EventBroker::post ( const Event & ev,
uint8_t topic,
EventHandlerBase * subscriber = nullptr )

Posts an event to the specified topic.

Parameters
subscriberIf provided the event won't be forwarded to the given subscriber.

Definition at line 33 of file EventBroker.cpp.

◆ postDelayed()

uint16_t Boardcore::EventBroker::postDelayed ( const Event & ev,
uint8_t topic,
unsigned int delayMs )

Posts an event after the specified delay.

Warning
Events cannot be posted with a delay shorter than EVENT_BROKER_MIN_DELAY
Parameters
event
topic
delayMsDelay in milliseconds.
Returns
Unique id of the delayed event.

Definition at line 59 of file EventBroker.cpp.

◆ removeDelayed()

void Boardcore::EventBroker::removeDelayed ( uint16_t id)

Removes a delayed event before it is posted.

Parameters
idThe id returned by postDelayed(...).

Definition at line 94 of file EventBroker.cpp.

◆ subscribe()

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.

Parameters
subscriber
topic

Definition at line 107 of file EventBroker.cpp.

◆ unsubscribe() [1/2]

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.

Parameters
subscriber

Definition at line 120 of file EventBroker.cpp.

◆ unsubscribe() [2/2]

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.

Parameters
subscriber
topic

Definition at line 113 of file EventBroker.cpp.

Friends And Related Symbol Documentation

◆ Singleton< EventBroker >

friend class Singleton< EventBroker >
friend

Definition at line 50 of file EventBroker.h.


The documentation for this class was generated from the following files: