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(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(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(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(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(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(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(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(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(name,destination), argcount(3), egid(gid), esid(sid),  esidAddr(NULL), etid(tid)
00055   {}
00056   
00057   EventTrans(const std::string& name, StateNode* destination, EventBase::EventGeneratorID_t gid, unsigned int *sidAddr, EventBase::EventTypeID_t tid)
00058     : Transition(name,destination), argcount(3), egid(gid), esid(0),  esidAddr(sidAddr), etid(tid)
00059   {}
00060   //@}
00061   
00062   //! starts listening
00063   virtual void preStart() {
00064     Transition::preStart();
00065     if ( esidAddr != 0 )
00066       erouter->addListener(this,egid);  // must check sid dynamically as events come in
00067     else {
00068       switch (argcount) {
00069         case 1: erouter->addListener(this,egid); break;
00070         case 2: erouter->addListener(this,egid,esid); break;
00071         case 3: erouter->addListener(this,egid,esid,etid); break;
00072       }
00073     }
00074   }
00075   
00076   //! fire the transition if an event is seen
00077   virtual void doEvent() {
00078     if ( esidAddr == 0 )
00079       fire(*event);
00080     else if ( event->getSourceID() == *esidAddr )
00081       if ( argcount == 2 || event->getTypeID() == etid )
00082         fire(*event);
00083   }
00084   
00085 private:
00086   EventTrans(const EventTrans&); //!< do not call
00087   EventTrans& operator=(const EventTrans&); //!< do not call
00088 };
00089 
00090 /*! @file
00091  * @brief Defines EventTrans, which causes a transition if an event of the specified type occurs
00092  * @author dst (Creator)
00093  */
00094 
00095 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:38 2016 by Doxygen 1.6.3