Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::EventRegistry Class Referenceabstract

Global static object for registering event handlers. More...

#include <EventHandler.hxx>

Inheritance diagram for openlcb::EventRegistry:
Singleton< EventRegistry > openlcb::TreeEventHandlers openlcb::VectorEventHandlers

Public Member Functions

virtual void register_handler (const EventRegistryEntry &entry, unsigned mask)=0
 Adds a new event handler to the registry.
 
virtual void unregister_handler (EventHandler *handler, uint32_t user_arg=0, uint32_t user_arg_mask=0)=0
 Removes all registered instances of a given event handler pointer.
 
virtual void reserve (size_t count)
 Prepares storage for adding many event handlers.
 
virtual EventIteratorcreate_iterator ()=0
 Creates a new event iterator. Caller takes ownership of object.
 
unsigned get_epoch ()
 Returns a monotonically increasing number that will change every time the set of registered event handlers change.
 

Static Public Member Functions

static unsigned align_mask (EventId *event, unsigned size)
 Computes the alignment mask for registering an event range.
 
- Static Public Member Functions inherited from Singleton< EventRegistry >
static EventRegistry * instance ()
 
static bool exists ()
 

Protected Member Functions

void set_dirty ()
 Implementations must call this function from register and unregister handler to mark iterators being invalidated.
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (EventRegistry)
 

Private Attributes

unsigned dirtyCounter_ = 0
 This counter will be incremented every time the set of event handlers change (and thus the event iterators are invalidated).
 

Static Private Attributes

static EventRegistryinstance_
 

Detailed Description

Global static object for registering event handlers.

Usage: create one of the implementation classes depending on the resource requirements of your binary. In the event handlers constructor, register the event handler via the singleton pointer.

Definition at line 253 of file EventHandler.hxx.

Constructor & Destructor Documentation

◆ ~EventRegistry()

openlcb::EventRegistry::~EventRegistry ( )
virtual

Definition at line 44 of file EventHandler.cxx.

◆ EventRegistry()

openlcb::EventRegistry::EventRegistry ( )
protected

Definition at line 40 of file EventHandler.cxx.

Member Function Documentation

◆ align_mask()

unsigned openlcb::EventRegistry::align_mask ( EventId *  event,
unsigned  size 
)
static

Computes the alignment mask for registering an event range.

Updates the event by rounding and returns the mask value to be sent to the register_handler function.

Parameters
eventis the event id to be registered. Will be modified.
sizeis the number of events to register from that offset. [event, event+size) will be the registration range.

Definition at line 49 of file EventHandler.cxx.

◆ create_iterator()

virtual EventIterator * openlcb::EventRegistry::create_iterator ( )
pure virtual

Creates a new event iterator. Caller takes ownership of object.

Implemented in openlcb::VectorEventHandlers, and openlcb::TreeEventHandlers.

◆ get_epoch()

unsigned openlcb::EventRegistry::get_epoch ( )
inline

Returns a monotonically increasing number that will change every time the set of registered event handlers change.

Whenever this number changes, the iterators are invalidated and must be cleared.

Definition at line 293 of file EventHandler.hxx.

◆ register_handler()

virtual void openlcb::EventRegistry::register_handler ( const EventRegistryEntry entry,
unsigned  mask 
)
pure virtual

Adds a new event handler to the registry.

Parameters
entryis the structure parametrizingthe registration.
maskis used for registering consecutive events; zero for registering just one event; otherwise use {align_mask} to compute the base value and mask to use for registering a range of events.

Implemented in openlcb::VectorEventHandlers, and openlcb::TreeEventHandlers.

◆ reserve()

virtual void openlcb::EventRegistry::reserve ( size_t  count)
inlinevirtual

Prepares storage for adding many event handlers.

Parameters
counthow many empty slots to reserve.

Reimplemented in openlcb::TreeEventHandlers.

Definition at line 283 of file EventHandler.hxx.

◆ set_dirty()

void openlcb::EventRegistry::set_dirty ( )
inlineprotected

Implementations must call this function from register and unregister handler to mark iterators being invalidated.

Definition at line 303 of file EventHandler.hxx.

◆ unregister_handler()

virtual void openlcb::EventRegistry::unregister_handler ( EventHandler handler,
uint32_t  user_arg = 0,
uint32_t  user_arg_mask = 0 
)
pure virtual

Removes all registered instances of a given event handler pointer.

Parameters
handlerthe handler for which to unregister entries
user_argvalues of the 32-bit user arg to remove
user_arg_mask32-bit mask where to verify user_arg being equal

Implemented in openlcb::VectorEventHandlers, and openlcb::TreeEventHandlers.

Member Data Documentation

◆ dirtyCounter_

unsigned openlcb::EventRegistry::dirtyCounter_ = 0
private

This counter will be incremented every time the set of event handlers change (and thus the event iterators are invalidated).

Definition at line 313 of file EventHandler.hxx.

◆ instance_

EventRegistry* openlcb::EventRegistry::instance_
staticprivate

Definition at line 309 of file EventHandler.hxx.


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