TextMsgTrans.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_TextMsgTrans_h_
00003 #define INCLUDED_TextMsgTrans_h_
00004
00005 #include "Behaviors/Transition.h"
00006 #include "Events/TextMsgEvent.h"
00007 #include "Events/EventRouter.h"
00008 #include "Shared/MarkScope.h"
00009
00010
00011 class TextMsgTrans : public Transition {
00012
00013
00014
00015
00016 public:
00017
00018 TextMsgTrans(StateNode* destination, const std::string& message)
00019 : Transition(destination), msg(message), haveMsg(true), savedEvent()
00020 {}
00021
00022
00023 TextMsgTrans(const std::string& name, StateNode* destination, const std::string& message)
00024 : Transition(name,destination), msg(message), haveMsg(true), savedEvent()
00025 {}
00026
00027
00028 TextMsgTrans(const std::string& name, StateNode* destination)
00029 : Transition(name,destination), msg(), haveMsg(false), savedEvent()
00030 {}
00031
00032
00033
00034
00035
00036 public:
00037 virtual void preStart() {
00038 Transition::preStart();
00039 erouter->addListener(this, EventBase::textmsgEGID );
00040 }
00041
00042 virtual void doEvent() {
00043 if ( event->getGeneratorID() == EventBase::textmsgEGID ) {
00044
00045
00046 if ( haveMsg ) {
00047 if ( const TextMsgEvent *txtev = dynamic_cast<const TextMsgEvent*>(event) ) {
00048 if ( txtev->getText() == msg )
00049 fire(*event);
00050 else
00051 return;
00052 }
00053 }
00054
00055
00056
00057 else {
00058 savedEvent = *event;
00059 erouter->addTimer(this, 1, 1, false);
00060 }
00061 }
00062
00063
00064 else if ( event->getGeneratorID() == EventBase::timerEGID )
00065 fire(savedEvent);
00066 }
00067
00068 static std::string getClassDescription() { return "Fires when a matching string is received"; }
00069 virtual std::string getDescription() const { return getClassDescription(); }
00070
00071
00072
00073
00074
00075 protected:
00076 std::string msg;
00077 bool haveMsg;
00078 TextMsgEvent savedEvent;
00079
00080
00081
00082
00083
00084 private:
00085
00086
00087
00088
00089
00090 TextMsgTrans(const TextMsgTrans&);
00091 TextMsgTrans& operator=(const TextMsgTrans&);
00092 };
00093
00094
00095
00096
00097
00098
00099 #endif