![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /****************************************************************************** 00002 * WNS (Wireless Network Simulator) * 00003 * __________________________________________________________________________ * 00004 * * 00005 * Copyright (C) 2004-2006 * 00006 * Chair of Communication Networks (ComNets) * 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany * 00008 * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242 * 00009 * email: wns@comnets.rwth-aachen.de * 00010 * www: http://wns.comnets.rwth-aachen.de * 00011 ******************************************************************************/ 00012 00013 #ifndef GLUE_ARQFSM_ARQBASESTATE_HPP 00014 #define GLUE_ARQFSM_ARQBASESTATE_HPP 00015 00016 #include <GLUE/arqfsm/InSignals.hpp> 00017 #include <GLUE/arqfsm/OutSignals.hpp> 00018 00019 #include <WNS/ldk/Compound.hpp> 00020 00021 #include <WNS/Exception.hpp> 00022 00023 namespace glue { namespace arqfsm { 00024 00025 template <class FSMFU, class COMMAND> 00026 class ARQBaseState : 00027 public FSMFU::UnhandledSignals, 00028 public InSignals<typename FSMFU::BaseFSM::StateInterface>, 00029 public OutSignals 00030 { 00031 protected: 00032 typedef typename FSMFU::BaseFSM::StateInterface StateInterface; 00033 00034 public: 00035 ARQBaseState(typename FSMFU::BaseFSM* t, const std::string& stateName) : 00036 FSMFU::UnhandledSignals(t, stateName) 00037 {} // ARQBaseState 00038 00039 virtual void 00040 doInitState() 00041 { 00042 onInitState(); 00043 } // doInitState 00044 00045 virtual void 00046 doExitState() 00047 { 00048 onExitState(); 00049 } // doExitState 00050 00051 // FU signals 00052 virtual StateInterface* 00053 doSendData(const wns::ldk::CompoundPtr& compound) 00054 { 00055 return this->onSendData(compound); 00056 } // doSendData 00057 00058 virtual StateInterface* 00059 doOnData(const wns::ldk::CompoundPtr& compound) 00060 { 00061 COMMAND* command = dynamic_cast<COMMAND*>(this->getFU()->getCommand(compound->getCommandPool())); 00062 if (!command) 00063 throw wns::Exception("Invalid command type"); 00064 00065 switch(command->peer.type) 00066 { 00067 case COMMAND::I: 00068 return onI(compound, command->peer.NS); 00069 00070 case COMMAND::ACK: 00071 return onACK(command->peer.NS); 00072 00073 default: 00074 throw wns::Exception("Unknown frame type received."); 00075 } 00076 00077 return this; 00078 } // doOnData 00079 00080 virtual StateInterface* 00081 doWakeup() 00082 { 00083 return this->onWakeup(); 00084 } // doWakeup 00085 00086 virtual void 00087 doIsAccepting(const wns::ldk::CompoundPtr&, bool& accepting) const 00088 { 00089 this->onIsAccepting(accepting); 00090 } // doIsAccepting 00091 00092 protected: 00093 virtual 00094 ~ARQBaseState() 00095 {} // ~ARQBaseState 00096 00097 virtual void 00098 onInitState() 00099 {} // onInitState 00100 00101 virtual void 00102 onExitState() 00103 {} // onExitState 00104 00105 // state signals 00106 void 00107 sendSendData(wns::ldk::CompoundPtr compound) 00108 { 00109 this->getFU()->queueSendData(compound); 00110 } // sendSendData 00111 00112 void 00113 sendOnData(wns::ldk::CompoundPtr compound) 00114 { 00115 this->getFU()->queueOnData(compound); 00116 } // sendOnData 00117 00118 void 00119 sendWakeup() 00120 { 00121 this->getFU()->queueWakeup(); 00122 } // sendWakeup 00123 00124 wns::ldk::CompoundPtr 00125 createReply(wns::ldk::CompoundPtr compound) 00126 { 00127 return wns::ldk::CompoundPtr(new wns::ldk::Compound(this->getFU()->createReply(compound->getCommandPool()))); 00128 } // createReply 00129 00130 bool 00131 isAccepting(wns::ldk::CompoundPtr compound) 00132 { 00133 return this->getFU()->isAccepting(compound); 00134 } // isAccepting 00135 00136 std::string 00137 getFUNName() 00138 { 00139 return this->getFU()->getFUN()->getName(); 00140 } // getFUNName 00141 }; 00142 00143 } // arqfsm 00144 } // glue 00145 00146 #endif // GLUE_ARQFSM_ARQBASESTATE_HPP 00147 00148
1.5.5