Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
#include <EventRouter.h>
Inheritance diagram for EventRouter:
Classes must inherit from EventListener and/or EventTrapper in order to receive events.
Use the global erouter
EventRouter to post and subscribe to events
When multiple listeners are subscribed, the order in which an event is distributed among them looks like this:
...but if you're relying on that ordering, there should be a cleaner way to do whatever you're doing.
If one behaviors unsubscribes another one during a processEvent(), that behavior will still get the "current" event before the unsubscription takes place.
Buffering events has not been tested thoroughly...
Definition at line 40 of file EventRouter.h.
Public Member Functions | |
EventRouter () | |
Constructs the router, buffertime defaults to 1. | |
virtual | ~EventRouter () |
just calls reset and removeAllTimers() | |
void | reset () |
erases all listeners, trappers and timers, resets EventRouter | |
void | setBufferTime (unsigned int t) |
sets the time to wait between buffer clears, see EventRouter::buffertime | |
unsigned int | getBufferTime () |
returns the time to wait between buffer clears, see EventRouter::buffertime | |
Posting/Processing Events | |
void | postEvent (EventBase::EventGeneratorID_t egid, unsigned int sid, EventBase::EventTypeID_t etid, unsigned int dur) |
recommended to create and post an event using current buffer setting | |
void | postEvent (EventBase::EventGeneratorID_t egid, unsigned int sid, EventBase::EventTypeID_t etid, unsigned int dur, const std::string &n, float m) |
recommended to create and post an event using current buffer setting | |
void | postEvent (EventBase *e) |
recommended to create and post an event using current buffer setting | |
void | processTimers () |
determines if timers need to be posted, and posts them if so. | |
void | processEventBuffer () |
clears the event buffer, deletes events as it does so. | |
void | processEvent (const EventBase &e) |
forces unbuffered - sends event *now*. Will clear the buffer first if needed to ensure proper event ordering | |
Listener Detection | |
bool | hasListeners (EventBase::EventGeneratorID_t egid) |
counts both listeners and trappers, so stuff can tell if it even needs to bother generating an event... | |
bool | hasListeners (EventBase::EventGeneratorID_t egid, unsigned int sid) |
counts both listeners and trappers, so stuff can tell if it even needs to bother generating an event... | |
bool | hasListeners (EventBase::EventGeneratorID_t egid, unsigned int sid, EventBase::EventTypeID_t etid) |
counts both listeners and trappers, so stuff can tell if it even needs to bother generating an event... | |
Timer Management | |
void | addTimer (EventListener *el, unsigned int sid, unsigned int delay, bool repeat=true) |
adds a timer or sets a timer if it doesn't already exist. | |
void | addTimer (EventListener *el, const EventBase &e, bool repeat=true) |
calls the other addTimer() with the event's source id and duration, doesn't check to see if the generator is timerEGID | |
void | removeTimer (EventListener *el) |
clears all pending timers for listener el | |
void | removeTimer (EventListener *el, unsigned int sid) |
clears any pending timers with source id sid for listener el | |
void | removeAllTimers () |
clears all timers for all listeners | |
Listener Management | |
void | addListener (EventListener *el, const EventBase &e) |
Adds a listener for a specific source id and type from a given event generator, adding a Timer event will invoke addTimer(el, e.getSourceID(), e.getDuration(), true ). | |
void | addListener (EventListener *el, EventBase::EventGeneratorID_t egid) |
Adds a listener for all events from a given event generator. | |
void | addListener (EventListener *el, EventBase::EventGeneratorID_t egid, unsigned int sid) |
Adds a listener for all types from a specific source and generator. | |
void | addListener (EventListener *el, EventBase::EventGeneratorID_t egid, unsigned int sid, EventBase::EventTypeID_t etid) |
Adds a listener for a specific source id and type from a given event generator. | |
void | removeListener (EventListener *el, const EventBase &e) |
stops sending specified events from the generator to the listener. If a timer is passed it will invoke removeTimer(el, e.getSourceID()) | |
void | removeListener (EventListener *el, EventBase::EventGeneratorID_t egid) |
stops sending specified events from the generator to the listener. | |
void | removeListener (EventListener *el, EventBase::EventGeneratorID_t egid, unsigned int sid) |
stops sending specified events from the generator to the listener. | |
void | removeListener (EventListener *el, EventBase::EventGeneratorID_t egid, unsigned int sid, EventBase::EventTypeID_t etid) |
stops sending specified events from the generator to the listener. | |
void | removeListener (EventListener *el) |
stops sending ALL events to the listener | |
void | forgetListener (EventListener *el) |
clears timers and removes listener from all events | |
Trapper Management | |
void | addTrapper (EventTrapper *el, const EventBase &e) |
Adds a trapper for a specific source id and type from a given event generator. | |
void | addTrapper (EventTrapper *el, EventBase::EventGeneratorID_t egid) |
Adds a trapper for all events from a given event generator. | |
void | addTrapper (EventTrapper *el, EventBase::EventGeneratorID_t egid, unsigned int sid) |
Adds a trapper for all types from a specific source and generator. | |
void | addTrapper (EventTrapper *el, EventBase::EventGeneratorID_t egid, unsigned int sid, EventBase::EventTypeID_t etid) |
Adds a trapper for a specific source id and type from a given event generator. | |
void | addTrapper (EventTrapper *el) |
adds a trapper for ALL events | |
void | removeTrapper (EventTrapper *el, const EventBase &e) |
stops sending specified events from the generator to the trapper. | |
void | removeTrapper (EventTrapper *el, EventBase::EventGeneratorID_t egid) |
stops sending specified events from the generator to the trapper. | |
void | removeTrapper (EventTrapper *el, EventBase::EventGeneratorID_t egid, unsigned int sid) |
stops sending specified events from the generator to the trapper. | |
void | removeTrapper (EventTrapper *el, EventBase::EventGeneratorID_t egid, unsigned int sid, EventBase::EventTypeID_t etid) |
stops sending specified events from the generator to the trapper. | |
void | removeTrapper (EventTrapper *el) |
stops sending ALL events to the trapper | |
Protected Types | |
typedef std::vector< TimerEntry * >::iterator | timer_it_t |
makes code more readable | |
Protected Member Functions | |
void | doSendBuffer () |
does the work of clearing the buffer | |
void | doSendEvent (const EventBase &e) |
does the work of sending an event | |
void | chkTimers () |
just for debugging | |
void | dispTimers () |
just for debugging | |
Protected Attributes | |
std::vector< TimerEntry * > | timers |
the list of timer entries being maintained, kept sorted by time they go active | |
std::vector< EventBase * > | events |
used to store buffered events | |
bool | doSendBufferLock |
in case of recursive calls to processEventBuffer()/doSendBuffer() | |
unsigned int | lastBufClear |
time of last event buffer clear | |
unsigned int | buffertime |
The time between clearings of the buffer. | |
EventMapper | trappers |
A mapping of which EventTrapper's should get a chance to trap the event. | |
EventMapper | listeners |
A mapping of which EventListener's should receive events. |
|
makes code more readable
Definition at line 146 of file EventRouter.h. |
|
Constructs the router, buffertime defaults to 1.
Definition at line 7 of file EventRouter.cc. |
|
just calls reset and removeAllTimers()
Definition at line 43 of file EventRouter.h. References removeAllTimers(), and reset(). |
|
Adds a listener for a specific source id and type from a given event generator.
Definition at line 82 of file EventRouter.cc. References EventRouter::EventMapper::addMapping(), and listeners. |
|
Adds a listener for all types from a specific source and generator.
Definition at line 78 of file EventRouter.cc. References EventRouter::EventMapper::addMapping(), EventBase::EventTypeID_t, listeners, and EventBase::numETIDs. |
|
Adds a listener for all events from a given event generator.
Definition at line 75 of file EventRouter.cc. References EventRouter::EventMapper::addMapping(), and listeners. |
|
Adds a listener for a specific source id and type from a given event generator, adding a Timer event will invoke addTimer(el, e.getSourceID(), e.getDuration(),
Definition at line 69 of file EventRouter.cc. References EventRouter::EventMapper::addMapping(), addTimer(), EventBase::getDuration(), EventBase::getGeneratorID(), EventBase::getSourceID(), EventBase::getTypeID(), listeners, and EventBase::timerEGID. |
|
calls the other addTimer() with the event's source id and duration, doesn't check to see if the generator is timerEGID
Definition at line 74 of file EventRouter.h. References addTimer(), EventBase::getDuration(), and EventBase::getSourceID(). |
|
adds a timer or sets a timer if it doesn't already exist. timers are unique by EventListener and source ID - can't have two timers for the same el and sid a delay of 0 with repeating will cause an event to be sent at every opportunity, use very sparingly a delay of -1U will call removeTimer() if it already exists, otherwise is ignored
Definition at line 48 of file EventRouter.cc. References removeTimer(), timer_it_t, and timers. |
|
adds a trapper for ALL events
Definition at line 102 of file EventRouter.h. References EventRouter::EventMapper::addMapping(), EventBase::EventGeneratorID_t, EventBase::numEGIDs, and trappers. |
|
Adds a trapper for a specific source id and type from a given event generator.
Definition at line 100 of file EventRouter.h. References EventRouter::EventMapper::addMapping(), and trappers. |
|
Adds a trapper for all types from a specific source and generator.
Definition at line 99 of file EventRouter.h. References EventRouter::EventMapper::addMapping(), EventBase::EventTypeID_t, EventBase::numETIDs, and trappers. |
|
Adds a trapper for all events from a given event generator.
Definition at line 98 of file EventRouter.h. References EventRouter::EventMapper::addMapping(), and trappers. |
|
Adds a trapper for a specific source id and type from a given event generator.
Definition at line 97 of file EventRouter.h. References EventRouter::EventMapper::addMapping(), EventBase::getGeneratorID(), EventBase::getSourceID(), EventBase::getTypeID(), and trappers. |
|
just for debugging
Definition at line 150 of file EventRouter.h. References dispTimers(), timer_it_t, and timers. |
|
just for debugging
Definition at line 161 of file EventRouter.h. References get_time(), timer_it_t, and timers. |
|
does the work of clearing the buffer
Definition at line 123 of file EventRouter.cc. References doSendBufferLock, doSendEvent(), events, get_time(), and lastBufClear. |
|
does the work of sending an event
Definition at line 148 of file EventRouter.cc. References EventRouter::EventMapper::getMapping(), listeners, and trappers. |
|
clears timers and removes listener from all events
Definition at line 93 of file EventRouter.h. References removeListener(), and removeTimer(). |
|
returns the time to wait between buffer clears, see EventRouter::buffertime
Definition at line 47 of file EventRouter.h. References buffertime. |
|
counts both listeners and trappers, so stuff can tell if it even needs to bother generating an event...
Definition at line 69 of file EventRouter.h. References EventRouter::EventMapper::hasMapping(), listeners, and trappers. |
|
counts both listeners and trappers, so stuff can tell if it even needs to bother generating an event...
Definition at line 68 of file EventRouter.h. References EventRouter::EventMapper::hasMapping(), listeners, and trappers. |
|
counts both listeners and trappers, so stuff can tell if it even needs to bother generating an event...
Definition at line 67 of file EventRouter.h. References EventRouter::EventMapper::hasMapping(), listeners, and trappers. |
|
recommended to create and post an event using current buffer setting
Definition at line 53 of file EventRouter.h. References buffertime, events, and processEvent(). |
|
recommended to create and post an event using current buffer setting
Definition at line 52 of file EventRouter.h. References buffertime, events, and processEvent(). |
|
recommended to create and post an event using current buffer setting
Definition at line 51 of file EventRouter.h. References buffertime, events, and processEvent(). |
|
forces unbuffered - sends event *now*. Will clear the buffer first if needed to ensure proper event ordering
Implements EventListener. Definition at line 142 of file EventRouter.cc. References doSendBuffer(), doSendEvent(), and events. |
|
clears the event buffer, deletes events as it does so.
Definition at line 119 of file EventRouter.cc. References doSendBuffer(), and events. |
|
determines if timers need to be posted, and posts them if so. Call this often to ensure accurate timers. Also, will clear event buffer before sending timer events in order to ensure correct ordering of event reception Definition at line 12 of file EventRouter.cc. References buffertime, get_time(), lastBufClear, processEventBuffer(), sort(), EventBase::statusETID, timer_it_t, EventBase::timerEGID, and timers. |
|
clears all timers for all listeners
Definition at line 113 of file EventRouter.cc. References timer_it_t, and timers. |
|
stops sending ALL events to the listener
Definition at line 92 of file EventRouter.h. References EventRouter::EventMapper::clean(), EventBase::EventGeneratorID_t, listeners, EventBase::numEGIDs, and EventRouter::EventMapper::removeMapping(). |
|
stops sending specified events from the generator to the listener.
Definition at line 90 of file EventRouter.h. References EventRouter::EventMapper::clean(), listeners, and EventRouter::EventMapper::removeMapping(). |
|
stops sending specified events from the generator to the listener.
Definition at line 89 of file EventRouter.h. References EventRouter::EventMapper::clean(), EventBase::EventTypeID_t, listeners, EventBase::numETIDs, and EventRouter::EventMapper::removeMapping(). |
|
stops sending specified events from the generator to the listener.
Definition at line 88 of file EventRouter.h. References EventRouter::EventMapper::clean(), listeners, and EventRouter::EventMapper::removeMapping(). |
|
stops sending specified events from the generator to the listener. If a timer is passed it will invoke removeTimer(el, e.getSourceID())
Definition at line 86 of file EventRouter.cc. References EventRouter::EventMapper::clean(), EventBase::getGeneratorID(), EventBase::getSourceID(), EventBase::getTypeID(), listeners, EventRouter::EventMapper::removeMapping(), removeTimer(), and EventBase::timerEGID. |
|
clears any pending timers with source id sid for listener el
Definition at line 104 of file EventRouter.cc. References timer_it_t, and timers. |
|
clears all pending timers for listener el
Definition at line 95 of file EventRouter.cc. References timer_it_t, and timers. |
|
stops sending ALL events to the trapper
Definition at line 110 of file EventRouter.h. References EventRouter::EventMapper::clean(), EventBase::EventGeneratorID_t, EventBase::numEGIDs, EventRouter::EventMapper::removeMapping(), and trappers. |
|
stops sending specified events from the generator to the trapper.
Definition at line 108 of file EventRouter.h. References EventRouter::EventMapper::clean(), EventRouter::EventMapper::removeMapping(), and trappers. |
|
stops sending specified events from the generator to the trapper.
Definition at line 107 of file EventRouter.h. References EventRouter::EventMapper::clean(), EventBase::EventTypeID_t, EventBase::numETIDs, EventRouter::EventMapper::removeMapping(), and trappers. |
|
stops sending specified events from the generator to the trapper.
Definition at line 106 of file EventRouter.h. References EventRouter::EventMapper::clean(), EventRouter::EventMapper::removeMapping(), and trappers. |
|
stops sending specified events from the generator to the trapper.
Definition at line 105 of file EventRouter.h. References EventRouter::EventMapper::clean(), EventBase::getGeneratorID(), EventBase::getSourceID(), EventBase::getTypeID(), EventRouter::EventMapper::removeMapping(), and trappers. |
|
erases all listeners, trappers and timers, resets EventRouter
Definition at line 44 of file EventRouter.h. References EventRouter::EventMapper::clear(), listeners, removeAllTimers(), and trappers. |
|
sets the time to wait between buffer clears, see EventRouter::buffertime
Definition at line 46 of file EventRouter.h. References buffertime. |
|
The time between clearings of the buffer. 0 will not use the buffer, events are routed upon posting 1 will clear the buffer at next call to processTimers() or processEventBuffer() a larger value will cause a delay of that number of milliseconds since the last clearing Definition at line 175 of file EventRouter.h. |
|
in case of recursive calls to processEventBuffer()/doSendBuffer()
Definition at line 173 of file EventRouter.h. |
|
used to store buffered events
Definition at line 172 of file EventRouter.h. |
|
time of last event buffer clear
Definition at line 174 of file EventRouter.h. |
|
A mapping of which EventListener's should receive events.
Definition at line 235 of file EventRouter.h. |
|
the list of timer entries being maintained, kept sorted by time they go active
Definition at line 147 of file EventRouter.h. |
|
A mapping of which EventTrapper's should get a chance to trap the event.
Definition at line 234 of file EventRouter.h. |
Tekkotsu v1.4 |
Generated Sat Jul 19 00:08:56 2003 by Doxygen 1.3.2 |