EventRouter Class Reference#include <EventRouter.h>
Inheritance diagram for EventRouter:
[legend]List of all members.
Detailed Description
This class will handle distribution of events as well as management of timers.
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:
- "Specific" listeners: any listener which specifies a particular source id. (It doesn't matter if they specify a type id or not.)
- older listeners get events before younger listeners
- "General" listeners: those that subscribe to an entire generator
- older listeners get events before younger listeners
...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...
- See also:
- EventBase::EventGeneratorID_t for a complete listing of all generators, as well as instructions on how to add new generators.
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
|
|
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
|
|
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...
|
|
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
|
|
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
|
|
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 (calls doSendEvent() )
|
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.
|
Member Typedef Documentation
Constructor & Destructor Documentation
EventRouter::EventRouter |
( |
|
) |
|
|
virtual EventRouter::~EventRouter |
( |
|
) |
[inline, virtual] |
|
Member Function Documentation
|
Adds a listener for a specific source id and type from a given event generator.
Definition at line 82 of file EventRouter.cc. |
|
Adds a listener for all types from a specific source and generator.
Definition at line 78 of file EventRouter.cc. |
|
Adds a listener for all events from a given event generator.
Definition at line 75 of file EventRouter.cc. |
|
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 ).
Definition at line 69 of file EventRouter.cc.
Referenced by WalkCalibration::activate(), BatteryCheckControl::activate(), SensorObserverControl::doSelect(), EventLogger::doSelect(), WorldStateVelDaemon::DoStart(), WorldStateSerializerBehavior::DoStart(), WMMonitorBehavior::DoStart(), WalkToTargetMachine::DoStart(), WalkControllerBehavior::DoStart(), VisualTargetTrans::DoStart(), VisualTargetCloseTrans::DoStart(), StareAtBallBehavior::DoStart(), SoundTestBehavior::DoStart(), SimpleChaseBallBehavior::DoStart(), SegCamBehavior::DoStart(), RawCamBehavior::DoStart(), PlayMotionSequenceNode< SIZE >::DoStart(), MCRepeater::DoStart(), HeadPointControllerBehavior::DoStart(), HeadLevelBehavior::DoStart(), FollowHeadBehavior::DoStart(), ExploreMachine::DoStart(), EventGeneratorBase::DoStart(), EStopControllerBehavior::DoStart(), DriveMeBehavior::DoStart(), Controller::DoStart(), CompareTrans< T >::DoStart(), ChaseBallBehavior::DoStart(), CameraBehavior::DoStart(), BatteryMonitorBehavior::DoStart(), BanditMachine::WaitNode::DoStart(), AutoGetupBehavior::DoStart(), AlanBehavior::DoStart(), ValueEditControl< T >::pause(), MCRepeater::processEvent(), FollowHeadBehavior::processEvent(), AutoGetupBehavior::processEvent(), RunSequenceControl< SequenceSize >::selectedFile(), and LoadPostureControl::selectedFile(). |
|
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. |
void EventRouter::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.
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 - Parameters:
-
el | the EventListener to send the timer event to |
sid | the source ID to use on that event (if you need to send more info, send a pointer to a struct of your devising, typecasted as int) |
delay | the delay between the first (and future) calls |
repeat | set to true if you want to keep receiving this event, otherwise it will only send once |
Definition at line 48 of file EventRouter.cc.
Referenced by addListener(), addTimer(), StartupBehavior::DoStart(), DriveMeBehavior::DoStart(), BanditMachine::WaitNode::DoStart(), DriveMeBehavior::processEvent(), BatteryMonitorBehavior::processEvent(), TimeOutTrans::resetTimer(), FreeMemReportControl::resetTimerFreq(), WalkControllerBehavior::runCommand(), HeadPointControllerBehavior::runCommand(), and BatteryMonitorBehavior::startWarning(). |
|
Adds a trapper for a specific source id and type from a given event generator.
Definition at line 100 of file EventRouter.h. |
|
Adds a trapper for all types from a specific source and generator.
Definition at line 99 of file EventRouter.h. |
|
Adds a trapper for all events from a given event generator.
Definition at line 98 of file EventRouter.h. |
void EventRouter::chkTimers |
( |
|
) |
[inline, protected] |
|
void EventRouter::dispTimers |
( |
|
) |
[inline, protected] |
|
void EventRouter::doSendBuffer |
( |
|
) |
[protected] |
|
void EventRouter::doSendEvent |
( |
const EventBase & |
e |
) |
[protected] |
|
|
does the work of sending an event
Be aware this is an O(n^2) where n is the number of listeners for a particular event. This is because after each call to processEvent, the list of listeners could have changed so each listener much be verified before it is sent an event. New listeners won't get the current event, but neither should listeners which have just be removed
Definition at line 148 of file EventRouter.cc.
Referenced by doSendBuffer(), and processEvent(). |
|
clears timers and removes listener from all events
Definition at line 93 of file EventRouter.h.
Referenced by ValueEditControl< T >::activate(), WalkCalibration::deactivate(), LoadPostureControl::deactivate(), BatteryCheckControl::deactivate(), SensorObserverControl::doSelect(), WorldStateVelDaemon::DoStop(), WorldStateSerializerBehavior::DoStop(), WMMonitorBehavior::DoStop(), WalkToTargetMachine::DoStop(), WalkControllerBehavior::DoStop(), VisualTargetTrans::DoStop(), VisualTargetCloseTrans::DoStop(), TimeOutTrans::DoStop(), StareAtBallBehavior::DoStop(), SimpleChaseBallBehavior::DoStop(), SegCamBehavior::DoStop(), RawCamBehavior::DoStop(), PlayMotionSequenceNode< SIZE >::DoStop(), MCRepeater::DoStop(), HeadPointControllerBehavior::DoStop(), HeadLevelBehavior::DoStop(), FreeMemReportControl::DoStop(), FollowHeadBehavior::DoStop(), ExploreMachine::DoStop(), EventGeneratorBase::DoStop(), EStopControllerBehavior::DoStop(), DriveMeBehavior::DoStop(), Controller::DoStop(), CompareTrans< T >::DoStop(), ChaseBallBehavior::DoStop(), CameraBehavior::DoStop(), BatteryMonitorBehavior::DoStop(), BanditMachine::WaitNode::DoStop(), AutoGetupBehavior::DoStop(), AlanBehavior::DoStop(), BatteryCheckControl::pause(), MCRepeater::processEvent(), BanditMachine::WaitNode::processEvent(), and AlanBehavior::processEvent(). |
unsigned int EventRouter::getBufferTime |
( |
|
) |
[inline] |
|
|
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. |
|
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. |
void EventRouter::postEvent |
( |
EventBase * |
e |
) |
[inline] |
|
|
recommended to create and post an event using current buffer setting
Definition at line 53 of file EventRouter.h. |
|
recommended to create and post an event using current buffer setting
Definition at line 52 of file EventRouter.h. |
|
recommended to create and post an event using current buffer setting
Definition at line 51 of file EventRouter.h.
Referenced by WMitem< T >::announce(), WorldState::chkEvent(), Controller::console_callback(), BallDetectionGenerator::createEvent(), StateNode::DoStart(), StateNode::DoStop(), SoundManager::endPlay(), MMCombo::GotImage(), SoundManager::Play(), WorldStateVelDaemon::processEvent(), SegmentedColorGenerator::processEvent(), RLEGenerator::processEvent(), RegionGenerator::processEvent(), RawCameraGenerator::processEvent(), JPEGGenerator::processEvent(), InterleavedYUVGenerator::processEvent(), CDTGenerator::processEvent(), WorldState::read(), SoundManager::ReceivedMsg(), MotionManager::receivedMsg(), MotionManager::removeMotion(), MMCombo::RPOPENR_notify(), EventTranslator::sendEvent(), SoundManager::StopPlay(), Controller::takeLine(), WMitem_base::unwatch(), and WMitem_base::watch(). |
void EventRouter::processEvent |
( |
const EventBase & |
e |
) |
[virtual] |
|
|
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.
Referenced by postEvent(). |
void EventRouter::processEventBuffer |
( |
|
) |
|
|
void EventRouter::processTimers |
( |
|
) |
|
|
void EventRouter::removeAllTimers |
( |
|
) |
|
|
|
stops sending ALL events to the listener
Definition at line 92 of file EventRouter.h. |
|
stops sending specified events from the generator to the listener.
Definition at line 90 of file EventRouter.h. |
|
stops sending specified events from the generator to the listener.
Definition at line 89 of file EventRouter.h. |
|
stops sending specified events from the generator to the listener.
Definition at line 88 of file EventRouter.h. |
void EventRouter::removeTimer |
( |
EventListener * |
el, |
|
|
unsigned int |
sid |
|
) |
|
|
|
clears any pending timers with source id sid for listener el
Definition at line 104 of file EventRouter.cc. |
void EventRouter::removeTrapper |
( |
EventTrapper * |
el |
) |
[inline] |
|
|
stops sending ALL events to the trapper
Definition at line 110 of file EventRouter.h. |
|
stops sending specified events from the generator to the trapper.
Definition at line 108 of file EventRouter.h. |
|
stops sending specified events from the generator to the trapper.
Definition at line 107 of file EventRouter.h. |
|
stops sending specified events from the generator to the trapper.
Definition at line 106 of file EventRouter.h. |
void EventRouter::reset |
( |
|
) |
[inline] |
|
void EventRouter::setBufferTime |
( |
unsigned int |
t |
) |
[inline] |
|
Member Data Documentation
The documentation for this class was generated from the following files:
|