FastArduino  v1.7
C++ library to build fast but small Arduino/AVR projects
events::Dispatcher< EVENT > Class Template Reference

Utility to dispatch an event to a list of EventHandlers that are registered for its type. More...

#include <fastarduino/events.h>

Inheritance diagram for events::Dispatcher< EVENT >:
Collaboration diagram for events::Dispatcher< EVENT >:

Public Member Functions

 Dispatcher (const Dispatcher< EVENT > &)=delete
 
Dispatcher< EVENT > & operator= (const Dispatcher< EVENT > &)=delete
 
void dispatch (const EVENT &event)
 Dispatch the given event to the right EventHandler, based on the event type. More...
 
- Public Member Functions inherited from containers::LinkedList< EventHandler< EVENT > >
 LinkedList (const LinkedList< EventHandler< EVENT > > &)=default
 
LinkedList< EventHandler< EVENT > > & operator= (const LinkedList< EventHandler< EVENT > > &)=delete
 
void insert (T &item) INLINE
 Insert item at the beginning of this list. More...
 
bool remove (T &item) INLINE
 Remove item from this list. More...
 
void traverse (F func)
 Traverse all items of this list and execute f functor. More...
 

Additional Inherited Members

- Public Types inherited from containers::LinkedList< EventHandler< EVENT > >
using T = EventHandler< EVENT >
 The type of items in this list.
 

Detailed Description

template<typename EVENT>
class events::Dispatcher< EVENT >

Utility to dispatch an event to a list of EventHandlers that are registered for its type.

You first create an EventHandler subclass, intantiate it and register it to a Dispatcher; for this, you use containers::LinkedList API which Dispatcher derives from.

NOTE: you should never call any Dispatcher method from an ISR because these methods may last too long for an ISR.

Template Parameters
EVENTthe events::Event<T> handled
See also
containers::LinkedList
EventHandler
Event::type()

Definition at line 239 of file events.h.

Member Function Documentation

◆ dispatch()

template<typename EVENT >
void events::Dispatcher< EVENT >::dispatch ( const EVENT &  event)
inline

Dispatch the given event to the right EventHandler, based on the event type.

Note that if several registered EventHandlers match this event type, then they will all be called with that event.

Parameters
eventthe event to dispatch to the right event handler
See also
EventHandler::on_event()

Definition at line 256 of file events.h.


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