Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

EventTrans.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_EventTrans_h_
00003 #define INCLUDED_EventTrans_h_
00004 
00005 #include "Behaviors/Transition.h"
00006 #include "Events/EventRouter.h"
00007 
00008 //! causes a transition when the specified event is received
00009 
00010 class EventTrans : public Transition {
00011 private:
00012   int argcount; //!< the number of arguments which were supplied to the constructor (granularity of filtering)
00013   EventBase::EventGeneratorID_t egid; //!< the requested generator
00014   size_t esid; //!< the requested source
00015   unsigned int *esidAddr;
00016   EventBase::EventTypeID_t etid; //!< the requested type
00017 
00018 public:
00019   //!@name Constructors
00020   //! follows general pattern of EventRouter::addListener()
00021   EventTrans(StateNode* destination, EventBase::EventGeneratorID_t gid)
00022     : Transition("EventTrans",destination), argcount(1), egid(gid), esid(0), esidAddr(NULL), etid(EventBase::statusETID)
00023   {}
00024 
00025   EventTrans(StateNode* destination, EventBase::EventGeneratorID_t gid, size_t sid)
00026     : Transition("EventTrans",destination), argcount(2), egid(gid), esid(sid), esidAddr(NULL), etid(EventBase::statusETID)
00027   {}
00028 
00029   EventTrans(StateNode* destination, EventBase::EventGeneratorID_t gid, unsigned int *sidAddr)
00030     : Transition("EventTrans",destination), argcount(2), egid(gid), esid(0), esidAddr(sidAddr), etid(EventBase::statusETID)
00031   {}
00032 
00033   EventTrans(StateNode* destination, EventBase::EventGeneratorID_t gid, size_t sid, EventBase::EventTypeID_t tid)
00034     : Transition("EventTrans",destination), argcount(3), egid(gid), esid(sid), esidAddr(NULL), etid(tid)
00035   {}
00036 
00037   EventTrans(StateNode* destination, EventBase::EventGeneratorID_t gid, unsigned int* sidAddr, EventBase::EventTypeID_t tid)
00038     : Transition("EventTrans",destination), argcount(3), egid(gid), esid(0), esidAddr(sidAddr), etid(tid)
00039   {}
00040 
00041   EventTrans(const std::string& name, StateNode* destination, EventBase::EventGeneratorID_t gid)
00042     : Transition("EventTrans",name,destination), argcount(1), egid(gid), esid(0),  esidAddr(NULL), etid(EventBase::statusETID)
00043   {}
00044 
00045   EventTrans(const std::string& name, StateNode* destination, EventBase::EventGeneratorID_t gid, size_t sid)
00046     : Transition("EventTrans",name,destination), argcount(2), egid(gid), esid(sid),  esidAddr(NULL), etid(EventBase::statusETID)
00047   {}
00048 
00049   EventTrans(const std::string& name, StateNode* destination, EventBase::EventGeneratorID_t gid, unsigned int *sidAddr)
00050     : Transition("EventTrans",name,destination), argcount(2), egid(gid), esid(0),  esidAddr(sidAddr), etid(EventBase::statusETID)
00051   {}
00052 
00053   EventTrans(const std::string& name, StateNode* destination, EventBase::EventGeneratorID_t gid, size_t sid, EventBase::EventTypeID_t tid)
00054     : Transition("EventTrans",name,destination), argcount(3), egid(gid), esid(sid),  esidAddr(NULL), etid(tid)
00055   {}
00056   EventTrans(const std::string& name, StateNode* destination, EventBase::EventGeneratorID_t gid, unsigned int *sidAddr, EventBase::EventTypeID_t tid)
00057     : Transition("EventTrans",name,destination), argcount(3), egid(gid), esid(0),  esidAddr(sidAddr), etid(tid)
00058   {}
00059   //@}
00060 
00061   //! starts listening
00062   virtual void DoStart() {
00063     Transition::DoStart();
00064     if ( esidAddr != 0 )
00065       erouter->addListener(this,egid);  // must check sid dynamically as events come in
00066     else
00067       switch (argcount) {
00068       case 1: erouter->addListener(this,egid); break;
00069       case 2: erouter->addListener(this,egid,esid); break;
00070       case 3: erouter->addListener(this,egid,esid,etid);
00071     };
00072   }
00073 
00074   //! stops listening
00075   virtual void DoStop() {
00076     erouter->removeListener(this);
00077     Transition::DoStop();
00078   }
00079 
00080   //! fire the transition if an event is seen
00081   virtual void processEvent(const EventBase &event) {
00082     if ( esidAddr == 0 )
00083       fire();
00084     else if ( event.getSourceID() == *esidAddr )
00085       if ( argcount == 2 || event.getTypeID() == etid )
00086   fire();
00087   }
00088 
00089 private:
00090   EventTrans(const EventTrans&); //!< do not call
00091   EventTrans& operator=(const EventTrans&); //!< do not call
00092 
00093 };
00094 
00095 /*! @file
00096  * @brief Defines EventTrans, which causes a transition if an event of the specified type occurs
00097  * @author dst (Creator)
00098  *
00099  * $Author: ejt $
00100  * $Name: tekkotsu-4_0 $
00101  * $Revision: 1.9 $
00102  * $State: Exp $
00103  * $Date: 2007/11/13 05:13:31 $
00104  */
00105 
00106 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:53 2007 by Doxygen 1.5.4