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 switch ( event->getGeneratorID() ) {
00044
00045 case EventBase::textmsgEGID:
00046
00047 if ( haveMsg ) {
00048 if ( const TextMsgEvent *txtev = dynamic_cast<const TextMsgEvent*>(event) ) {
00049 if ( txtev->getText() == msg )
00050 fire(*event);
00051 else
00052 return;
00053 }
00054 }
00055
00056
00057
00058 else {
00059 savedEvent = *event;
00060 erouter->addTimer(this, 9999, 1, false);
00061 }
00062 break;
00063
00064
00065 case EventBase::timerEGID:
00066 fire(savedEvent);
00067 break;
00068
00069 default:
00070 std::cout << "TextMsgTrans received unexpected event type: " << event->getDescription() << std::endl;
00071 }
00072 }
00073
00074 static std::string getClassDescription() { return "Fires when a matching string is received"; }
00075 virtual std::string getDescription() const { return getClassDescription(); }
00076
00077
00078
00079
00080
00081 protected:
00082 std::string msg;
00083 bool haveMsg;
00084 TextMsgEvent savedEvent;
00085
00086
00087
00088
00089
00090 private:
00091
00092
00093
00094
00095
00096 TextMsgTrans(const TextMsgTrans&);
00097 TextMsgTrans& operator=(const TextMsgTrans&);
00098 };
00099
00100
00101
00102
00103
00104
00105 #endif