Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

EventRouter Class Reference

This class will handle distribution of events as well as management of timers. More...

#include <EventRouter.h>

Inheritance diagram for EventRouter:

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 instance of EventRouter to both send (post) and receive (subscribe/listen) to events. (except if you are posting from within a MotionCommand, in which case you should use MotionCommand::postEvent() so that it can correctly handle inter-process communication issues under Aperios (the Aibo's OS) -- under a Unix-based OS, this isn't necessary.) Events posted in non-Main processes will be forwarded to Main for processing.

Event processing is a serialized operation, meaning only one event is ever being processed at a time, and by one listener at a time. The EventRouter contains its own thread lock, so if two threads post events at the same time, the EventRouter will handle ensuring mutual exclusion. Listeners are free to spawn their own threads to handle processing or posting events to avoid being dependent on other listeners' processing times. (Note: threads are not available on the Aibo, so listeners which wish to run on the Aibo are stuck with a "cooperative" multitasking model)

The events available for processing are listed in EventBase::EventGeneratorID_t. Each generator ID's documentation specifies how to interpret the source ID field, and whether you can expect events with that generator ID to be of a subclass of EventBase, such as TextMsgEvent or LocomotionEvent. Many generators send plain EventBase instances.

When multiple listeners are subscribed, the order in which an event is distributed among them is:

  1. "Specific" listeners: any listener which specifies a particular source id. (doesn't matter if they specified type id as well)
    • older listeners get events before more recently added listeners ("FIFO")
  2. "General" listeners: those that subscribe to an entire generator
    • older listeners get events before more recently added listeners ("FIFO")

...but if you're relying on that ordering, there probably should be a cleaner way to do whatever you're doing.

TimerEvents are generally only sent to the generator which requested them. So if EventListener A requests a timer (see addTimer()) with ID 0 at two second intervals, and B requests a timer with ID 0 at three second intervals, each will still only receive the timers they requested - no cross talk. The timer generator is unique in this regard, which is why it is built in as an integral component of the EventRouter. However, EventListener A can receive B's timers if it specifically wants to, via addListener(). See "Timers" below.

If an EventListener/EventTrapper subscribes to the same event source multiple times, it will receive multiple copies of the event. However, the first call to removeListener for a source will remove all subscriptions to that source.
Example: EventListener A subscribes to (buttonEGID,*,*), and twice to (buttonEGID,0,*).

  • If button 0 is pressed, A will get three copies of the event.
  • If button 1 is pressed, A will get one copy.
  • If removeListener(&A,buttonEGID) is called, the (buttonEGID,*,*) is removed, as well as both of (buttonEGID,0,*).
  • If removeListener(&A,buttonEGID,0) is called, both of (buttonEGID,0,*) are removed, but (buttonEGID,*,*) would be untouched.

Timers

addTimer() allows you to request an TimerEvent to be sent at some later point in time, possibly on a repeating basis. Timers are specific to the behavior which requests them, and you do not (and usually should not) call addListener() in order to receive a timer event.

There is an important different between addTimer() and addListener(timerEGID,...)! addTimer will "create" the timer, and will send the timer to the listener which created it when the timer expires. This means that as long as the listener in question does not call addListener(timerEGID), it will only receive its own timers. In other words, with this usage there is no confusion with timer cross-talk between listeners, because each listener is only receiving its own timers.

However, if a listener calls addListener(timerEGID), it will begin receiving all timer events from throughout the system. This allows you to have one behavior "eavesdrop" on another's timers. In order to determine which listener requested/created the timer, you can use the TimerEvent::getTarget() value.

So beware that if you call both addTimer() and addListener(foo,timerEGID), 'foo' will get two calls to processEvent() for its own timers, and one call for all other timers, and will have to know to call TimerEvent::getTarget() to distinguish its timers from other listener's timers (if it cares about the difference...)

Timers are sent to the requesting listener before being broadcast -- EventTrappers cannot filter a listener's own timers, but can prevent the timer from being broadcast to other listeners.

Event processing examples:

Posting events: //method A: basic event posting (EventBase instance is sent) erouter->postEvent(EventBase::aiEGID, 1234, EventBase::statusETID);

//method B: specific event instance is posted (have to use this style to post a subclass) TextMsgEvent txt("hello world"); erouter->postEvent(txt); // or can be done in one line: erouter->postEvent(TextMsgEvent("hello world"))

Receiving events:

  //given an EventListener subclass:
  class YourListener : public EventListener {
  public:
    virtual void processEvent(const EventBase& e) {
      std::cout << "Got: " << e.getName() << std::endl;
    }
  };

  YourListener yourList;

  // subscribes it to all EventBase::aiEGID events:
  erouter->addListener(&yourList, EventBase::aiEGID);

  // subscribes only to button activity from the head, but not other buttons:
  erouter->addListener(&yourList, EventBase::buttonEGID, ERS7Info::HeadButOffset);

Typically in a BehaviorBase subclass, you would just specify 'this' instead of '&yourList'.

Timer processing examples:

Requesting/Creating timers:

  YourListener yourList; // (any EventListener subclass)

  // sends a timer with source ID 123 every 5 seconds to yourList:
  erouter->addTimer(&yourList, 123, 5000);

  // sends a timer with ID 456 after 1 second, *no repeat, one time only*
  erouter->addTimer(&yourList, 456, 1000, false);

  // cancels the first timer
  erouter->removeTimer(&yourList, 123);

  // postpone/update the second timer's settings (*doesn't* create two timers with the same ID)
  erouter->addTimer(&yourList, 456, 2500, false);

Again, typically in a BehaviorBase subclass, you would just specify 'this' instead of '&yourList'.

See also:
EventBase::EventGeneratorID_t for a complete listing of all generators, as well as instructions on how to add new generators.
Tutorials:

Definition at line 174 of file EventRouter.h.

List of all members.

Classes

class  EventMapper
 Does the actual storage of the mapping between EventBase's and the EventListeners/EventTrappers who should receive them. More...
class  PostingStatus
 contains information regarding the progress of posting an event More...
struct  SameID
 Predicate used to remove old events from the same event source from eventQueue (see requeueEvent()). More...
struct  TimerEntry
 Contains all the information needed to maintain a timer by the EventRouter. More...
class  TimerEntryPtrCmp
 Used by STL to sort the timer list in order of activation time. More...

Public Member Functions

 EventRouter ()
 Constructs the router.
virtual ~EventRouter ()
 just calls reset and removeAllTimers()
void reset ()
 erases all listeners, trappers and timers, resets EventRouter
void removeListener (const EventListener *el)
 stops sending ALL events to the listener -- does not remove pending timers however (may need to call removeTimer(el) as well); see remove()
void removeListener (const EventListener *el, EventBase::EventGeneratorID_t egid)
 stops sending specified events from the generator to the listener.
void removeListener (const EventListener *el, EventBase::EventGeneratorID_t egid, size_t sid)
 stops sending specified events from the generator to the listener.
void removeListener (const EventListener *el, EventBase::EventGeneratorID_t egid, size_t sid, EventBase::EventTypeID_t etid)
 stops sending specified events from the generator to the listener.
void removeListener (const EventListener *el, const EventBase &e)
 Uses the generator, source, and type fields of e to remove a listener for that specific tuple.
void remove (const EventListener *el)
 stops all events and timers, shorthand for removeListener(el) and removeTimer(el); Note that trappers are separate, removeTrapper() is not called
void chkTimers ()
 just for debugging
void dispTimers ()
 just for debugging
Posting/Processing Events

void postEvent (EventBase::EventGeneratorID_t egid, size_t sid, EventBase::EventTypeID_t etid, unsigned int dur=0)
 recommended to create and post an event using current buffer setting
void postEvent (EventBase::EventGeneratorID_t egid, size_t 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 (const EventBase &e)
 posts the specified event, but doesn't delete it at the end -- equivalent to processEvent(e)
void queueEvent (EventBase *e)
 Uses a ThreadedMessageQueue to process an event at a later time, as opposed to postEvent() which will process the event immediately.
void requeueEvent (EventBase *e)
 Places e in the same queue as queueEvent(), but removes any other events with the same generator and source first.
void processTimers ()
 determines if timers need to be posted, and posts them if so.
void processEvent (const EventBase &e)
 sends event to its trappers & listeners, but doesn't delete the event at the end (see also postEvent())
EventTranslatorgetForwardingAgent (ProcessID::ProcessID_t proc) const
 returns the forwarding agent for a given process/thread group (see forwards)
void setForwardingAgent (ProcessID::ProcessID_t proc, EventTranslator *trans)
 sets the forwarding agent for a given process/thread group (see forwards)
ThreadedMessageQueue
< EventBase * > & 
getEventQueue ()
 Returns the event queue, to be processed by a callback thread between other behavior processing.
Listener/Trapper Recall

bool isListeningAny (const EventListener *el, EventBase::EventGeneratorID_t egid) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isListeningAny (const EventListener *el, EventBase::EventGeneratorID_t egid, size_t sid) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isListeningAll (const EventListener *el, EventBase::EventGeneratorID_t egid) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isListeningAll (const EventListener *el, EventBase::EventGeneratorID_t egid, size_t sid) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isListening (const EventListener *el, EventBase::EventGeneratorID_t egid, size_t sid, EventBase::EventTypeID_t etid) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isListening (const EventListener *el, const EventBase &e) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isTrappingAny (const EventTrapper *el, EventBase::EventGeneratorID_t egid) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isTrappingAny (const EventTrapper *el, EventBase::EventGeneratorID_t egid, size_t sid) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isTrappingAll (const EventTrapper *el, EventBase::EventGeneratorID_t egid) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isTrappingAll (const EventTrapper *el, EventBase::EventGeneratorID_t egid, size_t sid) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isTrapping (const EventTrapper *el, EventBase::EventGeneratorID_t egid, size_t sid, EventBase::EventTypeID_t etid) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
bool isTrapping (const EventTrapper *el, const EventBase &e) const
 returns true if the specified listener/trapper would receive any events that match the specified criteria
Listener/Trapper Detection

bool hasListeners (EventBase::EventGeneratorID_t egid)
 counts both listeners and trappers, so generators can tell if it even needs to bother generating an event...
bool hasListeners (EventBase::EventGeneratorID_t egid, size_t sid)
 counts both listeners and trappers, so generators can tell if it even needs to bother generating an event...
bool hasListeners (EventBase::EventGeneratorID_t egid, size_t sid, EventBase::EventTypeID_t etid)
 counts both listeners and trappers, so generators can tell if it even needs to bother generating an event...
bool hasListeners (const EventBase &e)
 counts both listeners and trappers, so generators can tell if it even needs to bother generating an event...
Timer Management

void addTimer (EventListener *el, size_t sid, unsigned int delay, bool repeat=true)
 adds a timer if it doesn't exist, or resets the timer if it already exists.
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 (const EventListener *el)
 clears all pending timers for listener el; see remove()
void removeTimer (const EventListener *el, size_t sid)
 clears any pending timers with source id sid for listener el
void removeTimer (const EventListener *el, EventBase &e)
 clears any pending timers with source id matching that of e, but only if e has generator timerEGID
void removeAllTimers ()
 clears all timers for all listeners
unsigned int getNextTimer ()
 returns time of next timer activation
const TimerEntrygetNextTimerInfo (const EventListener *el)
 Returns information of next timer activation (regardless of sid) for an event listener, NULL if none.
const TimerEntrygetNextTimerInfo (const EventListener *el, size_t sid)
 Returns information of next activation for a specific event listener timer entry, NULL if none.
Listener Management

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, size_t sid)
 Adds a listener for all types from a specific source and generator.
void addListener (EventListener *el, EventBase::EventGeneratorID_t egid, size_t sid, EventBase::EventTypeID_t etid)
 Adds a listener for a specific source id and type from a given event generator.
void addListener (EventListener *el, const EventBase &e)
 Uses the generator, source, and type fields of e to add a listener for that specific tuple.
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, size_t sid)
 Adds a trapper for all types from a specific source and generator.
void addTrapper (EventTrapper *el, EventBase::EventGeneratorID_t egid, size_t 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 (const EventTrapper *el, const EventBase &e)
 stops sending specified events from the generator to the trapper.
void removeTrapper (const EventTrapper *el, EventBase::EventGeneratorID_t egid)
 stops sending specified events from the generator to the trapper.
void removeTrapper (const EventTrapper *el, EventBase::EventGeneratorID_t egid, size_t sid)
 stops sending specified events from the generator to the trapper.
void removeTrapper (const EventTrapper *el, EventBase::EventGeneratorID_t egid, size_t sid, EventBase::EventTypeID_t etid)
 stops sending specified events from the generator to the trapper.
void removeTrapper (const EventTrapper *el)
 stops sending ALL events to the trapper

Protected Types

typedef std::vector
< TimerEntry * >::iterator 
timer_it_t
 makes code more readable

Protected Attributes

std::vector< TimerEntry * > timers
 the list of timer entries being maintained, kept sorted by time they go active
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.
std::queue< PostingStatus * > postings
 stores calls to post() currently in progress -- may grow if one postEvent() triggers another; this allows us to finish processing of the original postEvent() before starting the second.
EventTranslatorforwards [ProcessID::NumProcesses]
 This table will be checked on each processEvent to forward the event to some other destination.
ThreadedMessageQueue
< EventBase * > * 
eventQueue
 A queue of events which have been posted from background threads or otherwise desire postponed processing.

Private Member Functions

 EventRouter (const EventRouter &)
 don't call this
EventRouteroperator= (const EventRouter &)
 don't call this

Remote Event/State code



static const int defaultPort = 2424
 Request remote events to be sent to this robot, works like the regular addListeners.
std::list< EventProxy * > proxies
 Request remote events to be sent to this robot, works like the regular addListeners.
std::map< int, RemoteRouter * > rrouters
 Request remote events to be sent to this robot, works like the regular addListeners.
Socketsck
 Request remote events to be sent to this robot, works like the regular addListeners.
int nextProxyPort
 Request remote events to be sent to this robot, works like the regular addListeners.
void addRemoteListener (EventListener *el, int host, EventBase::EventGeneratorID_t egid)
 Request remote events to be sent to this robot, works like the regular addListeners.
void addRemoteListener (EventListener *el, int host, EventBase::EventGeneratorID_t egid, size_t sid)
 Request remote events to be sent to this robot, works like the regular addListeners.
void addRemoteListener (EventListener *el, int host, const EventBase &e)
 Request remote events to be sent to this robot, works like the regular addListeners.
void addRemoteListener (EventListener *el, int host, EventBase::EventGeneratorID_t egid, size_t sid, EventBase::EventTypeID_t etid)
 Request remote events to be sent to this robot, works like the regular addListeners.
void removeRemoteListener (const EventListener *el, int host, EventBase::EventGeneratorID_t egid)
 Stop getting remote events from the given robot.
void removeRemoteListener (const EventListener *el, int host, EventBase::EventGeneratorID_t egid, size_t sid)
 Request remote events to be sent to this robot, works like the regular addListeners.
void removeRemoteListener (const EventListener *el, int host, const EventBase &e)
 Request remote events to be sent to this robot, works like the regular addListeners.
void removeRemoteListener (const EventListener *el, int host, EventBase::EventGeneratorID_t egid, size_t sid, EventBase::EventTypeID_t etid)
 Request remote events to be sent to this robot, works like the regular addListeners.
void requestRemoteStateUpdates (int host, RemoteState::StateType type, unsigned int interval=500)
 Request remote state updates from the remote robot, every interval ms.
void stopRemoteStateUpdates (int host, RemoteState::StateType type)
 Stop getting remote state updates.
bool serveRemoteEventRequests ()
 This is called once on startup; it tells the EventRouter to listen for incoming requests.
int processData (char *data, int bytes)
 This handles incomiung connection requests by starting a new EventProxy.
RemoteRouterremoteRouterForHost (int host)
 Request remote events to be sent to this robot, works like the regular addListeners.

Member Typedef Documentation

typedef std::vector<TimerEntry*>::iterator EventRouter::timer_it_t [protected]

makes code more readable

Definition at line 414 of file EventRouter.h.


Constructor & Destructor Documentation

EventRouter::EventRouter (  ) 

Constructs the router.

Definition at line 26 of file EventRouter.cc.

EventRouter::~EventRouter (  )  [virtual]

just calls reset and removeAllTimers()

Definition at line 40 of file EventRouter.cc.

EventRouter::EventRouter ( const EventRouter  )  [private]

don't call this


Member Function Documentation

void EventRouter::addListener ( EventListener el,
const EventBase e 
)

Uses the generator, source, and type fields of e to add a listener for that specific tuple.

Definition at line 216 of file EventRouter.cc.

void EventRouter::addListener ( EventListener el,
EventBase::EventGeneratorID_t  egid,
size_t  sid,
EventBase::EventTypeID_t  etid 
)

Adds a listener for a specific source id and type from a given event generator.

Definition at line 208 of file EventRouter.cc.

void EventRouter::addListener ( EventListener el,
EventBase::EventGeneratorID_t  egid,
size_t  sid 
)

Adds a listener for all types from a specific source and generator.

Definition at line 199 of file EventRouter.cc.

void EventRouter::addListener ( EventListener el,
EventBase::EventGeneratorID_t  egid 
)

Adds a listener for all events from a given event generator.

Definition at line 191 of file EventRouter.cc.

Referenced by WalkCalibration::activate(), TorqueCalibrate::TakeMeasurementControl::activate(), PostureEditor::activate(), addRemoteListener(), EventGeneratorBase::addSrcListener(), FlashIPAddrBehavior::doEvent(), SensorObserverControl::doSelect(), EventLogger::doSelect(), WorldStateSerializerBehavior::doStart(), WMMonitorBehavior::doStart(), SegCam::doStart(), RegionCam::doStart(), RawCam::doStart(), DualCoding::Lookout::doStart(), KoduInterpreter::NotificationMonitor::doStart(), FlashIPAddrBehavior::doStart(), EventGeneratorBase::doStart(), EStopController::doStart(), EchoBehavior::doStart(), DepthCam::doStart(), DeadReckoningBehavior< ParticleT >::doStart(), Controller::doStart(), CameraBehavior::doStart(), BatteryMonitorBehavior::doStart(), MoCapLogger::gotTxtMsgSingle(), EventProxy::handleRemoteRequest(), BehaviorBase::MonitorMotion::monitor(), ValueEditControl< T >::pause(), WaypointEngineNode< W, mcName, mcDesc >::postStart(), VisualTargetTrans::postStart(), VisualTargetCloseTrans::postStart(), TrackNode::postStart(), TimeOutTrans::postStart(), SpeechNode::postStart(), SignalTrans< T >::postStart(), PilotTrans::postStart(), PilotNode::postStart(), MCNode< T, mcName, mcDesc, completes >::postStart(), MapBuilderNode::postStart(), LogNode::postStart(), GrasperTrans::postStart(), GrasperNode::postStart(), CompletionTrans::postStart(), CompareTrans< T >::postStart(), TextMsgTrans::preStart(), RecordMotionNode::preStart(), DualCoding::MapBuilder::preStart(), LostTargetTrans::preStart(), EventTrans::preStart(), DualCoding::Lookout::processPointAtEvent(), DualCoding::Lookout::processScanEvent(), DualCoding::Lookout::processSearchEvent(), CameraStreamBehavior::receiveData(), MoCapLogger::refresh(), MoCapLogger::registered(), EventLogger::runCommand(), RunSequenceControl< SequenceSize >::selectedFile(), LoadPostureControl::selectedFile(), EventGeneratorBase::setAutoListen(), MCNodeBase::setMC(), DualCoding::Lookout::setupSearch(), DualCoding::Lookout::setupTrack(), GamepadController::start(), SoundNode::startPlaying(), TorqueCalibrate::TakeMeasurementControl::transition(), and DualCoding::Lookout::triggerScanMotionSequence().

void EventRouter::addRemoteListener ( EventListener el,
int  host,
EventBase::EventGeneratorID_t  egid,
size_t  sid,
EventBase::EventTypeID_t  etid 
)

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 245 of file EventRouter.cc.

void EventRouter::addRemoteListener ( EventListener el,
int  host,
const EventBase e 
)

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 241 of file EventRouter.cc.

void EventRouter::addRemoteListener ( EventListener el,
int  host,
EventBase::EventGeneratorID_t  egid,
size_t  sid 
)

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 234 of file EventRouter.cc.

void EventRouter::addRemoteListener ( EventListener el,
int  host,
EventBase::EventGeneratorID_t  egid 
)

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 227 of file EventRouter.cc.

Referenced by addRemoteListener(), and KoduInterpreter::KoduEventListener::listenTo().

void EventRouter::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

Definition at line 277 of file EventRouter.h.

Referenced by addTimer().

void EventRouter::addTimer ( EventListener el,
size_t  sid,
unsigned int  delay,
bool  repeat = true 
)

adds a timer if it doesn't exist, or resets the timer if it already exists.

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 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 132 of file EventRouter.cc.

Referenced by TextMsgTrans::doEvent(), SignalTrans< T >::doEvent(), PilotTrans::doEvent(), LookAtMarkers::Search::doEvent(), LookAtMarkers::TrackMarker::doEvent(), GrasperNode::doEvent(), FlashIPAddrBehavior::doEvent(), CompletionTrans::doEvent(), BatteryMonitorBehavior::doEvent(), LookAtMarkers::Search::doStart(), LookAtMarkers::TrackMarker::doStart(), KoduInterpreter::ReceiveActionRunner::ReceiveActionStart::doStart(), KoduInterpreter::GiveActionRunner::GiveActionStart::doStart(), BatteryMonitorBehavior::doStart(), DualCoding::Lookout::executeRequest(), MoCapLogger::gotTxtMsgSingle(), EventProxy::handleRemoteRequest(), KoduDiscover::KoduDiscover(), FFPlanNode::plan(), FFPlanner::plan(), WaypointEngineNode< W, mcName, mcDesc >::postStart(), RecordMotionNode::preStart(), NullTrans::preStart(), ConnectionMadeTrans::preStart(), PostureEditor::processEvent(), DualCoding::Lookout::processPointAtEvent(), DualCoding::Lookout::processScanEvent(), DualCoding::Lookout::processSearchEvent(), DualCoding::Lookout::processTrackEvent(), SensorObserverControl::RTViewControl::refresh(), PostureEditor::refresh(), ArmController::relax(), RemoteRouter::RemoteRouter(), TimeOutTrans::resetTimer(), FreeMemReportControl::resetTimerFreq(), RemoteRouter::sendRemoteRequest(), FlashIPAddrBehavior::setupSequence(), BatteryMonitorBehavior::startWarning(), TorqueCalibrate::TakeMeasurementControl::takeInput(), and DualCoding::Lookout::triggerScanMotionSequence().

void EventRouter::addTrapper ( EventTrapper el  ) 

adds a trapper for ALL events

Note that since timers are not broadcast, they cannot be trapped. Only the EventListener which requested the timer will receive that timer.

Definition at line 429 of file EventRouter.cc.

void EventRouter::addTrapper ( EventTrapper el,
EventBase::EventGeneratorID_t  egid,
size_t  sid,
EventBase::EventTypeID_t  etid 
)

Adds a trapper for a specific source id and type from a given event generator.

Note that since timers are not broadcast, they cannot be trapped. Only the EventListener which requested the timer will receive that timer.

Definition at line 419 of file EventRouter.cc.

void EventRouter::addTrapper ( EventTrapper el,
EventBase::EventGeneratorID_t  egid,
size_t  sid 
)

Adds a trapper for all types from a specific source and generator.

Note that since timers are not broadcast, they cannot be trapped. Only the EventListener which requested the timer will receive that timer.

Definition at line 409 of file EventRouter.cc.

void EventRouter::addTrapper ( EventTrapper el,
EventBase::EventGeneratorID_t  egid 
)

Adds a trapper for all events from a given event generator.

Note that since timers are not broadcast, they cannot be trapped. Only the EventListener which requested the timer will receive that timer.

Definition at line 400 of file EventRouter.cc.

void EventRouter::addTrapper ( EventTrapper el,
const EventBase e 
)

Adds a trapper for a specific source id and type from a given event generator.

Note that only the broadcasted timers can be trapped. The EventListener which requested the timer will receive that timer before any trapping is done.

Definition at line 391 of file EventRouter.cc.

Referenced by Controller::activate(), addTrapper(), and Controller::takeLine().

void EventRouter::chkTimers (  ) 

just for debugging

Definition at line 480 of file EventRouter.cc.

void EventRouter::dispTimers (  ) 

just for debugging

Definition at line 493 of file EventRouter.cc.

Referenced by chkTimers().

ThreadedMessageQueue<EventBase*>& EventRouter::getEventQueue (  ) 

Returns the event queue, to be processed by a callback thread between other behavior processing.

This is similar to the forwarding agents which handles inter-process events (e.g. from Motion to Main) but in threaded environments (e.g. non-AIBO) we can use this more efficient mechanism. As we drop AIBO support we can transfer forwards to use queueEvent() instead.

To allow future expansion, please use queueEvent() instead of calling ThreadedMessageQueue::send directly via this accessor.

Definition at line 233 of file EventRouter.h.

EventTranslator* EventRouter::getForwardingAgent ( ProcessID::ProcessID_t  proc  )  const

returns the forwarding agent for a given process/thread group (see forwards)

Definition at line 221 of file EventRouter.h.

unsigned int EventRouter::getNextTimer (  ) 

returns time of next timer activation

Definition at line 285 of file EventRouter.h.

const EventRouter::TimerEntry * EventRouter::getNextTimerInfo ( const EventListener el,
size_t  sid 
)

Returns information of next activation for a specific event listener timer entry, NULL if none.

Don't try to use this to edit the timer entry, just call addTimer() again to reset the fields

Definition at line 184 of file EventRouter.cc.

const EventRouter::TimerEntry * EventRouter::getNextTimerInfo ( const EventListener el  ) 

Returns information of next timer activation (regardless of sid) for an event listener, NULL if none.

Don't try to use this to edit the timer entry, just call addTimer() again to reset the fields

Definition at line 177 of file EventRouter.cc.

bool EventRouter::hasListeners ( const EventBase e  ) 

counts both listeners and trappers, so generators can tell if it even needs to bother generating an event...

Definition at line 269 of file EventRouter.h.

Referenced by hasListeners().

bool EventRouter::hasListeners ( EventBase::EventGeneratorID_t  egid,
size_t  sid,
EventBase::EventTypeID_t  etid 
)

counts both listeners and trappers, so generators can tell if it even needs to bother generating an event...

Definition at line 268 of file EventRouter.h.

bool EventRouter::hasListeners ( EventBase::EventGeneratorID_t  egid,
size_t  sid 
)

counts both listeners and trappers, so generators can tell if it even needs to bother generating an event...

Definition at line 267 of file EventRouter.h.

bool EventRouter::hasListeners ( EventBase::EventGeneratorID_t  egid  ) 

counts both listeners and trappers, so generators can tell if it even needs to bother generating an event...

Definition at line 266 of file EventRouter.h.

Referenced by addListener(), addTrapper(), EventGeneratorBase::hasListeners(), removeListener(), and removeTrapper().

bool EventRouter::isListening ( const EventListener el,
const EventBase e 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 246 of file EventRouter.h.

bool EventRouter::isListening ( const EventListener el,
EventBase::EventGeneratorID_t  egid,
size_t  sid,
EventBase::EventTypeID_t  etid 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 245 of file EventRouter.h.

bool EventRouter::isListeningAll ( const EventListener el,
EventBase::EventGeneratorID_t  egid,
size_t  sid 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 244 of file EventRouter.h.

bool EventRouter::isListeningAll ( const EventListener el,
EventBase::EventGeneratorID_t  egid 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 243 of file EventRouter.h.

bool EventRouter::isListeningAny ( const EventListener el,
EventBase::EventGeneratorID_t  egid,
size_t  sid 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 242 of file EventRouter.h.

bool EventRouter::isListeningAny ( const EventListener el,
EventBase::EventGeneratorID_t  egid 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 241 of file EventRouter.h.

bool EventRouter::isTrapping ( const EventTrapper el,
const EventBase e 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 252 of file EventRouter.h.

bool EventRouter::isTrapping ( const EventTrapper el,
EventBase::EventGeneratorID_t  egid,
size_t  sid,
EventBase::EventTypeID_t  etid 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 251 of file EventRouter.h.

bool EventRouter::isTrappingAll ( const EventTrapper el,
EventBase::EventGeneratorID_t  egid,
size_t  sid 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 250 of file EventRouter.h.

bool EventRouter::isTrappingAll ( const EventTrapper el,
EventBase::EventGeneratorID_t  egid 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 249 of file EventRouter.h.

bool EventRouter::isTrappingAny ( const EventTrapper el,
EventBase::EventGeneratorID_t  egid,
size_t  sid 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 248 of file EventRouter.h.

bool EventRouter::isTrappingAny ( const EventTrapper el,
EventBase::EventGeneratorID_t  egid 
) const

returns true if the specified listener/trapper would receive any events that match the specified criteria

Definition at line 247 of file EventRouter.h.

EventRouter& EventRouter::operator= ( const EventRouter  )  [private]

don't call this

void EventRouter::postEvent ( const EventBase e  ) 

posts the specified event, but doesn't delete it at the end -- equivalent to processEvent(e)

Definition at line 192 of file EventRouter.h.

void EventRouter::postEvent ( EventBase::EventGeneratorID_t  egid,
size_t  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

Definition at line 190 of file EventRouter.h.

void EventRouter::postEvent ( EventBase::EventGeneratorID_t  egid,
size_t  sid,
EventBase::EventTypeID_t  etid,
unsigned int  dur = 0 
)

recommended to create and post an event using current buffer setting

Definition at line 189 of file EventRouter.h.

Referenced by addListener(), addTrapper(), WMitem< T >::announce(), Controller::console_callback(), BallDetectionGenerator::createEvent(), MotionManager::doAddMotion(), SegmentedColorGenerator::doEvent(), RLEGenerator::doEvent(), RegionGenerator::doEvent(), RawCameraGenerator::doEvent(), PNGGenerator::doEvent(), PitchDetector::doEvent(), JPEGGenerator::doEvent(), InterleavedYUVGenerator::doEvent(), CDTGenerator::doEvent(), BufferedImageGenerator::doEvent(), BehaviorBase::doEvent(), Transition::doFire(), KoduInterpreter::CompleteSayActuator::doStart(), KoduInterpreter::ReceiveActionRunner::ReceiveActionStart::doStart(), KoduInterpreter::GiveActionRunner::GiveActionSend::doStart(), KoduInterpreter::GiveActionRunner::GiveActionStart::doStart(), Grasper::GrasperFailed::doStart(), Grasper::GrasperSucceeded::doStart(), NoOpEventTranslator::encodeEvent(), SoundManager::endPlay(), DualCoding::MapBuilder::executeRequest(), Grasper::executeRequest(), RandomTrans::fire(), RemoteRouter::forwardEvent(), SoundManager::play(), MotionCommand::postEvent(), StateNode::postStateCompletion(), StateNode::postStateSignal(), StateNode::postStateStart(), StateNode::postStateStop(), GamepadController::processInput(), SoundManager::ProcessMsg(), MotionManager::processMsg(), processTimers(), WorldState::read(), removeListener(), MotionManager::removeMotion(), removeTrapper(), DualCoding::MapBuilder::requestComplete(), DualCoding::Lookout::requestComplete(), SoundManager::stopPlay(), Controller::takeLine(), WMitem_base::unwatch(), RemoteState::update(), and WMitem_base::watch().

int EventRouter::processData ( char *  data,
int  bytes 
) [virtual]

This handles incomiung connection requests by starting a new EventProxy.

Implements SocketListener.

Definition at line 316 of file EventRouter.cc.

void EventRouter::processEvent ( const EventBase e  )  [virtual]

sends event to its trappers & listeners, but doesn't delete the event at the end (see also postEvent())

this posting method is supplied to allow an EventRouter to behave as a listener as well -- the 'routers' really can form a sort of network, if desired. postEvent() is probably a more memnomic interface to use in direct function calls however, so that is the one you should call.

Implements EventListener.

Definition at line 513 of file EventRouter.cc.

Referenced by postEvent().

void EventRouter::processTimers (  ) 

determines if timers need to be posted, and posts them if so.

Call this often to ensure accurate timers.

Todo:
handle recursive calls

Definition at line 73 of file EventRouter.cc.

void EventRouter::queueEvent ( EventBase e  ) 

Uses a ThreadedMessageQueue to process an event at a later time, as opposed to postEvent() which will process the event immediately.

If an event generator is running in a background thread (e.g. DeviceDriver or a behavior thread), it can use this function to post events instead of grabbing the behaviorLock and calling postEvent directly. However, beware building up a backlog of stale events, you may prefer requeueEvent() to ensure only the most up-to-date data is in the queue The event will be processed after all current event processing is completed, similar to a 0-ms timer subscription. The event will be deleted after processing.

Definition at line 66 of file EventRouter.cc.

Referenced by requeueEvent().

RemoteRouter & EventRouter::remoteRouterForHost ( int  host  )  [protected]

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 293 of file EventRouter.cc.

Referenced by addRemoteListener(), removeRemoteListener(), requestRemoteStateUpdates(), and stopRemoteStateUpdates().

void EventRouter::remove ( const EventListener el  ) 

stops all events and timers, shorthand for removeListener(el) and removeTimer(el); Note that trappers are separate, removeTrapper() is not called

Definition at line 358 of file EventRouter.h.

Referenced by TorqueCalibrate::TakeMeasurementControl::deactivate(), MoCapLogger::gotMoCapSingle(), EventRouter::EventMapper::removeMapping(), BehaviorBase::stop(), and EventCallbackAs< EventBase >::~EventCallbackAs().

void EventRouter::removeAllTimers (  ) 

clears all timers for all listeners

Definition at line 171 of file EventRouter.cc.

Referenced by reset(), and ~EventRouter().

void EventRouter::removeListener ( const EventListener el,
const EventBase e 
)

Uses the generator, source, and type fields of e to remove a listener for that specific tuple.

Definition at line 381 of file EventRouter.cc.

void EventRouter::removeListener ( const EventListener el,
EventBase::EventGeneratorID_t  egid,
size_t  sid,
EventBase::EventTypeID_t  etid 
)

stops sending specified events from the generator to the listener.

Definition at line 372 of file EventRouter.cc.

void EventRouter::removeListener ( const EventListener el,
EventBase::EventGeneratorID_t  egid,
size_t  sid 
)

stops sending specified events from the generator to the listener.

Definition at line 360 of file EventRouter.cc.

void EventRouter::removeListener ( const EventListener el,
EventBase::EventGeneratorID_t  egid 
)

stops sending specified events from the generator to the listener.

Definition at line 351 of file EventRouter.cc.

void EventRouter::removeListener ( const EventListener el  ) 

stops sending ALL events to the listener -- does not remove pending timers however (may need to call removeTimer(el) as well); see remove()

Definition at line 339 of file EventRouter.cc.

Referenced by ValueEditControl< T >::activate(), EventLogger::clearSlots(), WalkCalibration::deactivate(), PostureEditor::deactivate(), FlashIPAddrBehavior::doEvent(), SensorObserverControl::doSelect(), EventLogger::doSelect(), WorldStateSerializerBehavior::doStop(), WMMonitorBehavior::doStop(), SegCam::doStop(), RegionCam::doStop(), RawCam::doStop(), HeadController::doStop(), FreeMemReportControl::doStop(), FlashIPAddrBehavior::doStop(), EventGeneratorBase::doStop(), EchoBehavior::doStop(), DepthCam::doStop(), Controller::doStop(), CameraBehavior::doStop(), ArmController::doStop(), EventProxy::handleRemoteRequest(), LogNode::postStart(), TorqueCalibrate::TakeMeasurementControl::processEvent(), RunSequenceControl< SequenceSize >::processEvent(), LoadPostureControl::processEvent(), DualCoding::Lookout::processPointAtEvent(), DualCoding::Lookout::processScanEvent(), DualCoding::Lookout::processSearchEvent(), CameraStreamBehavior::receiveData(), remove(), removeRemoteListener(), EventGeneratorBase::removeSrcListener(), DualCoding::Lookout::requestComplete(), EventLogger::runCommand(), MCNodeBase::setMC(), GamepadController::shutdown(), CompletionTrans::stop(), TorqueCalibrate::TakeMeasurementControl::transition(), BehaviorBase::~BehaviorBase(), LoadPostureControl::~LoadPostureControl(), BehaviorBase::MonitorMotion::~MonitorMotion(), and RunSequenceControl< SequenceSize >::~RunSequenceControl().

void EventRouter::removeRemoteListener ( const EventListener el,
int  host,
EventBase::EventGeneratorID_t  egid,
size_t  sid,
EventBase::EventTypeID_t  etid 
)

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 273 of file EventRouter.cc.

void EventRouter::removeRemoteListener ( const EventListener el,
int  host,
const EventBase e 
)

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 268 of file EventRouter.cc.

void EventRouter::removeRemoteListener ( const EventListener el,
int  host,
EventBase::EventGeneratorID_t  egid,
size_t  sid 
)

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 261 of file EventRouter.cc.

void EventRouter::removeRemoteListener ( const EventListener el,
int  host,
EventBase::EventGeneratorID_t  egid 
)

Stop getting remote events from the given robot.

Definition at line 254 of file EventRouter.cc.

Referenced by removeRemoteListener().

void EventRouter::removeTimer ( const EventListener el,
EventBase e 
)

clears any pending timers with source id matching that of e, but only if e has generator timerEGID

Definition at line 282 of file EventRouter.h.

Referenced by removeTimer().

void EventRouter::removeTimer ( const EventListener el,
size_t  sid 
)

clears any pending timers with source id sid for listener el

Definition at line 162 of file EventRouter.cc.

void EventRouter::removeTrapper ( const EventTrapper el  ) 

stops sending ALL events to the trapper

Definition at line 475 of file EventRouter.cc.

void EventRouter::removeTrapper ( const EventTrapper el,
EventBase::EventGeneratorID_t  egid,
size_t  sid,
EventBase::EventTypeID_t  etid 
)

stops sending specified events from the generator to the trapper.

Definition at line 465 of file EventRouter.cc.

void EventRouter::removeTrapper ( const EventTrapper el,
EventBase::EventGeneratorID_t  egid,
size_t  sid 
)

stops sending specified events from the generator to the trapper.

Definition at line 453 of file EventRouter.cc.

void EventRouter::removeTrapper ( const EventTrapper el,
EventBase::EventGeneratorID_t  egid 
)

stops sending specified events from the generator to the trapper.

Definition at line 444 of file EventRouter.cc.

void EventRouter::removeTrapper ( const EventTrapper el,
const EventBase e 
)

stops sending specified events from the generator to the trapper.

Definition at line 435 of file EventRouter.cc.

Referenced by Controller::deactivate(), removeTrapper(), and Controller::takeLine().

void EventRouter::requestRemoteStateUpdates ( int  host,
RemoteState::StateType  type,
unsigned int  interval = 500 
)

Request remote state updates from the remote robot, every interval ms.

Definition at line 282 of file EventRouter.cc.

void EventRouter::requeueEvent ( EventBase e  ) 

Places e in the same queue as queueEvent(), but removes any other events with the same generator and source first.

For sources only the current value is of significant interest (e.g. sensor readings) this avoids the possibility of a backlog of stale data forming in the case the Main thread blocks and falls behind on processing incoming data

Definition at line 68 of file EventRouter.cc.

void EventRouter::reset (  ) 

erases all listeners, trappers and timers, resets EventRouter

Definition at line 183 of file EventRouter.h.

Referenced by ~EventRouter().

bool EventRouter::serveRemoteEventRequests (  ) 

This is called once on startup; it tells the EventRouter to listen for incoming requests.

Definition at line 306 of file EventRouter.cc.

void EventRouter::setForwardingAgent ( ProcessID::ProcessID_t  proc,
EventTranslator trans 
)

sets the forwarding agent for a given process/thread group (see forwards)

Definition at line 508 of file EventRouter.cc.

void EventRouter::stopRemoteStateUpdates ( int  host,
RemoteState::StateType  type 
)

Stop getting remote state updates.

Definition at line 288 of file EventRouter.cc.


Member Data Documentation

const int EventRouter::defaultPort = 2424 [static]

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 332 of file EventRouter.h.

Referenced by RemoteRouter::RemoteRouter(), and serveRemoteEventRequests().

A queue of events which have been posted from background threads or otherwise desire postponed processing.

This is a more efficient mechanism than forwards, but only available on threaded platforms (e.g. non-AIBO). See queueEvent() and getEventQueue()

Definition at line 547 of file EventRouter.h.

Referenced by getEventQueue(), queueEvent(), requeueEvent(), and ~EventRouter().

EventTranslator* EventRouter::forwards[ProcessID::NumProcesses] [protected]

This table will be checked on each processEvent to forward the event to some other destination.

The main reason for including this functionality is in the uni-process model, we don't want event postings from real time processes like Motion to block on the event queue processing. So with this mechanism we can intercept those events, and queue them in a separate IPC mechanism to be picked up by Main later on.

This might also be handy for other purposes, such as remote event forwarding over the network...

If the EventTranslator's trapEvent returns true, then further processing on the event is skipped. (see EventTranslator::setTrapEventValue() )

Definition at line 541 of file EventRouter.h.

Referenced by EventRouter(), getForwardingAgent(), processEvent(), setForwardingAgent(), and ~EventRouter().

A mapping of which EventListener's should receive events.

Definition at line 508 of file EventRouter.h.

Referenced by addListener(), hasListeners(), isListening(), isListeningAll(), isListeningAny(), processEvent(), removeListener(), and reset().

int EventRouter::nextProxyPort [protected]

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 342 of file EventRouter.h.

Referenced by processData().

std::queue<PostingStatus*> EventRouter::postings [protected]

stores calls to post() currently in progress -- may grow if one postEvent() triggers another; this allows us to finish processing of the original postEvent() before starting the second.

Definition at line 529 of file EventRouter.h.

Referenced by processEvent().

std::list<EventProxy *> EventRouter::proxies [protected]

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 338 of file EventRouter.h.

Referenced by processData(), and ~EventRouter().

std::map<int, RemoteRouter *> EventRouter::rrouters [protected]

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 340 of file EventRouter.h.

Referenced by remoteRouterForHost(), and ~EventRouter().

Socket* EventRouter::sck [protected]

Request remote events to be sent to this robot, works like the regular addListeners.

Definition at line 341 of file EventRouter.h.

Referenced by processData(), and serveRemoteEventRequests().

std::vector<TimerEntry*> EventRouter::timers [protected]

the list of timer entries being maintained, kept sorted by time they go active

Definition at line 415 of file EventRouter.h.

Referenced by addTimer(), chkTimers(), dispTimers(), getNextTimer(), getNextTimerInfo(), processTimers(), removeAllTimers(), and removeTimer().

A mapping of which EventTrapper's should get a chance to trap the event.

Definition at line 507 of file EventRouter.h.

Referenced by addTrapper(), hasListeners(), isTrapping(), isTrappingAll(), isTrappingAny(), processEvent(), removeTrapper(), and reset().


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

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:07 2016 by Doxygen 1.6.3