Homepage Demos Overview Downloads Tutorials Reference
Credits

TimeOutTrans.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_TimeOutTrans_h_
00003 #define INCLUDED_TimeOutTrans_h_
00004 
00005 #include "Behaviors/Transition.h"
00006 #include "Events/EventRouter.h"
00007 
00008 //! causes a transition after a specified amount of time has passed
00009 class TimeOutTrans : public Transition {
00010 public:
00011   //! constructor, specify delay in milliseconds
00012   TimeOutTrans(StateNode* destination, unsigned int delay) : Transition("TimeOutTrans",destination), d(delay) {}
00013 
00014   //! constructor, specify delay in milliseconds
00015   TimeOutTrans(const std::string& name, StateNode* destination, unsigned int delay) : Transition("TimeOutTrans",name,destination), d(delay) {}
00016 
00017   //!starts timer
00018   virtual void DoStart() {
00019     Transition::DoStart();
00020     resetTimer(); 
00021   }
00022 
00023   //!stops timer
00024   virtual void DoStop() { erouter->removeListener(this); Transition::DoStop(); }
00025   
00026   //!resets timer
00027   void resetTimer() {
00028     // std::cout << "Reset @ " << get_time() << " stop @ " << get_time()+d << ' ' << this << std::endl;
00029     erouter->addTimer(this,0,d,false);
00030   }
00031 
00032   //!if we receive the timer event, fire()
00033   virtual void processEvent(const EventBase&) {
00034     // std::cout << "Timeout @ " << get_time() << " from " << event.getName() << ' ' << this << std::endl;
00035     fire();
00036   }
00037 
00038 protected:
00039   //! constructor, specify delay in milliseconds
00040   TimeOutTrans(const std::string& classname, const std::string& instancename, StateNode* destination, unsigned int delay) : Transition(classname,instancename,destination), d(delay) {}
00041 
00042   //!amount to delay (in milliseconds) before transition
00043   unsigned int d;
00044 };
00045 
00046 /*! @file
00047  * @brief Defines TimeOutTrans, which causes a transition after a specified amount of time has passed
00048  * @author ejt (Creator)
00049  *
00050  * $Author: ejt $
00051  * $Name: tekkotsu-2_2_1 $
00052  * $Revision: 1.14 $
00053  * $State: Exp $
00054  * $Date: 2004/11/15 22:46:19 $
00055  */
00056 
00057 #endif

Tekkotsu v2.2.1
Generated Tue Nov 23 16:36:40 2004 by Doxygen 1.3.9.1