User Manual, Developers Guide and API Documentation

WaitingForACK.cpp

Go to the documentation of this file.
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 #include <GLUE/arqfsm/stopandwait/WaitingForACK.hpp>
00014 #include <GLUE/arqfsm/stopandwait/ReadyForTransmission.hpp>
00015 #include <GLUE/arqfsm/stopandwait/FSMFU.hpp>
00016 
00017 using namespace glue::arqfsm::stopandwait;
00018 using namespace wns::ldk;
00019 
00020 STATIC_FACTORY_REGISTER_WITH_CREATOR(WaitingForACK,
00021                      StateInterface,
00022                      "glue_arqfsm_stopandwait_WaitingForACK",
00023                      wns::fsm::FSMConfigCreator);
00024 
00025 void
00026 WaitingForACK::onInitState()
00027 {
00028     assureType(getFU(), FSMFU*);
00029     FSMFU* fsmfu = dynamic_cast<FSMFU*>(getFU());
00030 
00031     fsmfu->setTimeout(vars().resendTimeout);
00032 } // onInitState
00033 
00034 
00035 void
00036 WaitingForACK::onExitState()
00037 {
00038     assureType(getFU(), FSMFU*);
00039     FSMFU* fsmfu = dynamic_cast<FSMFU*>(getFU());
00040 
00041     fsmfu->cancelTimeout();
00042 } // onExitState
00043 
00044 
00045 StateInterface*
00046 WaitingForACK::onSendData(const CompoundPtr&)
00047 {
00048     throw wns::Exception("Invalid signal (onsendData) in state WaitingForACK");
00049 
00050     return this;
00051 } // onSendData
00052 
00053 
00054 StateInterface*
00055 WaitingForACK::onACK(int sequenceNumber)
00056 {
00057     if(sequenceNumber != vars().NS)
00058     {
00059         MESSAGE_BEGIN(NORMAL, vars().logger, m, getFUNName());
00060         m << " Unexpected RR frame"
00061           << " expected " << vars().NS
00062           << " received " << sequenceNumber;
00063         MESSAGE_END();
00064 
00065         return this;
00066     }
00067 
00068     MESSAGE_BEGIN(NORMAL, vars().logger, m, getFUNName());
00069     m << " RR frame " << sequenceNumber;
00070     MESSAGE_END();
00071 
00072     vars().activeCompound = CompoundPtr();
00073     vars().sendNow = false;
00074 
00075     sendWakeup();
00076     return getFSM()->createState<ReadyForTransmission>();
00077 } // onACK
00078 
00079 
00080 StateInterface*
00081 WaitingForACK::onWakeup()
00082 {
00083     if (vars().ackCompound && isAccepting(vars().ackCompound))
00084     {
00085         sendSendData(vars().ackCompound);
00086         vars().ackCompound = CompoundPtr();
00087     }
00088 
00089     if (vars().sendNow == true && isAccepting(vars().activeCompound))
00090     {
00091         sendSendData(vars().activeCompound->copy());
00092         vars().sendNow = false;
00093     }
00094 
00095     return this;
00096 } // onWakeup
00097 
00098 
00099 void
00100 WaitingForACK::onIsAccepting(bool& accepting) const
00101 {
00102     accepting = false;
00103 } // onIsAccepting
00104 
00105 
00106 StateInterface*
00107 WaitingForACK::onTimeout()
00108 {
00109     assure(vars().activeCompound, "Unexpected timeout.");
00110 
00111     assureType(getFU(), FSMFU*);
00112     FSMFU* fsmfu = dynamic_cast<FSMFU*>(getFU());
00113 
00114     fsmfu->setTimeout(vars().resendTimeout);
00115 
00116     if (isAccepting(vars().activeCompound))
00117         sendSendData(vars().activeCompound->copy());
00118     else
00119         vars().sendNow = true;
00120 
00121     return this;
00122 } // onTimeout
00123 
00124 
00125 

Generated on Sat May 26 03:31:56 2012 for openWNS by  doxygen 1.5.5