00001
00002 #ifndef INCLUDED_TimeOutTrans_h_
00003 #define INCLUDED_TimeOutTrans_h_
00004
00005 #include "Behaviors/Transition.h"
00006 #include "Events/EventRouter.h"
00007 #include "Shared/MarkScope.h"
00008
00009
00010
00011
00012
00013 class TimeOutTrans : public Transition {
00014 public:
00015
00016 TimeOutTrans(StateNode* destination, unsigned int delay)
00017 : Transition(destination), d(delay),
00018 eventargcount(0), egid(EventBase::unknownEGID), esid(0), etid(EventBase::statusETID) {}
00019
00020
00021 TimeOutTrans(std::string const &name, StateNode* destination, unsigned int delay)
00022 : Transition(name,destination), d(delay),
00023 eventargcount(0), egid(EventBase::unknownEGID), esid(0), etid(EventBase::statusETID) {}
00024
00025
00026 TimeOutTrans(StateNode* destination, unsigned int delay, EventBase::EventGeneratorID_t gid)
00027 : Transition(destination), d(delay),
00028 eventargcount(1), egid(gid), esid(0), etid(EventBase::statusETID) {}
00029
00030
00031 TimeOutTrans(StateNode* destination, unsigned int delay, EventBase::EventGeneratorID_t gid, unsigned int sid)
00032 : Transition(destination), d(delay),
00033 eventargcount(2), egid(gid), esid(sid), etid(EventBase::statusETID) {}
00034
00035
00036 TimeOutTrans(StateNode* destination, unsigned int delay, EventBase::EventGeneratorID_t gid, unsigned int sid, EventBase::EventTypeID_t tid)
00037 : Transition(destination), d(delay),
00038 eventargcount(3), egid(gid), esid(sid), etid(tid) {}
00039
00040
00041 virtual void postStart() {
00042 Transition::postStart();
00043 switch (eventargcount) {
00044 case 1: erouter->addListener(this,egid); break;
00045 case 2: erouter->addListener(this,egid,esid); break;
00046 case 3: erouter->addListener(this,egid,esid,etid); break;
00047 };
00048 resetTimer();
00049 }
00050
00051
00052 void resetTimer() {
00053
00054 erouter->addTimer(this,0,d,false);
00055 }
00056
00057
00058 virtual void doEvent() {
00059
00060 if(event->getGeneratorID()==EventBase::timerEGID)
00061 fire();
00062 else
00063 resetTimer();
00064 }
00065
00066 protected:
00067
00068 unsigned int d;
00069
00070
00071 unsigned int eventargcount;
00072
00073 EventBase::EventGeneratorID_t egid;
00074 unsigned int esid;
00075 EventBase::EventTypeID_t etid;
00076
00077 };
00078
00079
00080
00081
00082
00083
00084 #endif