User Manual, Developers Guide and API Documentation

TimingControl.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 #include "TimingControl.hpp"
00028 
00029 #include <WNS/ldk/fun/FUN.hpp>
00030 #include <WNS/ldk/Layer.hpp>
00031 
00032 #include <WNS/ldk/fcf/CompoundCollector.hpp>
00033 #include <WNS/ldk/fcf/FrameBuilder.hpp>
00034 #include <WNS/logger/Logger.hpp>
00035 //#include <WNS/ldk/fcf/TimingNode.hpp>
00036 
00037 
00038 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00039    wns::ldk::fcf::TimingControl,
00040    wns::ldk::fcf::TimingControlInterface,
00041    "wns.ldk.fcf.TimingControl",
00042    wns::ldk::fcf::FrameBuilderConfigCreator );
00043 
00044 using namespace wns::ldk::fcf;
00045 
00046 TimingControl::TimingControl( FrameBuilder* _frameBuilder, const pyconfig::View& /*config*/ )
00047     : frameBuilder(_frameBuilder),
00048       logger("WNS", "TimingControl"),
00049       running(false)
00050 
00051 {
00052     activeCC = compoundCollectors.end();
00053 }
00054 
00055 void TimingControl::start()
00056 {
00057     activeCC = compoundCollectors.end(); //initinal state
00058     running = true;
00059 
00060     if ( !this->hasPeriodicTimeoutSet() )
00061         this->startPeriodicTimeout(frameBuilder->getFrameDuration());
00062 
00063 }
00064 
00065 void TimingControl::pause()
00066 {
00067     running = false;
00068     activeCC = compoundCollectors.end(); //initial state
00069 }
00070 
00071 void TimingControl::stop()
00072 {
00073     this->cancelPeriodicTimeout();
00074     activeCC = compoundCollectors.end(); //initial state
00075     running = false;
00076 }
00077 
00078 int
00079 TimingControl::getRole(PhaseDescriptorPtr /*p*/)
00080 {
00081     return 0;
00082 }
00083 
00084 void TimingControl::configure()
00085 {
00086     this->onFUNCreated();
00087 }
00088 
00089 void TimingControl::onFUNCreated()
00090 {
00091     FrameBuilder::Descriptors descriptors (
00092         frameBuilder->getAllPhaseDescriptors() );
00093     assure( !descriptors.empty(), "no descriptors are specified" );
00094 
00095     for ( FrameBuilder::Descriptors::const_iterator it = descriptors.begin();
00096           it != descriptors.end();
00097           ++it )
00098     {
00099         //(*it)->getTimingNode()->setTimingControl( this );
00100         compoundCollectors.push_back( (*it)->getCompoundCollector() );
00101     }
00102     activeCC = compoundCollectors.end();
00103     MESSAGE_BEGIN(NORMAL, logger, m, "");
00104     m << compoundCollectors.size() << " compound collectors registered at timing control";
00105     MESSAGE_END();
00106 }
00107 
00108 void TimingControl::nextPhase()
00109 {
00110     if ( activeCC == compoundCollectors.end() )
00111     {
00112         std::stringstream ss;
00113         ss << "timing inconsistency" << std::endl;
00114         ss << "nextPhase() called, but no active compound collector in  ";
00115         ss << getFrameBuilder()->getFUN()->getLayer()->getName() << std::endl;
00116         throw wns::Exception( ss.str() );
00117     }
00118     ++activeCC;
00119     if ( activeCC != compoundCollectors.end() )
00120     {
00121         // update the duration in case it has changed:
00122         MESSAGE_BEGIN(VERBOSE, logger, m, "");
00123         m << getFrameBuilder()->getFUN()->getName() << ": Next TimingNode: updating duration lengths";
00124         MESSAGE_END()
00125         (*activeCC)->start(0);
00126     } else {
00127         MESSAGE_BEGIN(VERBOSE, logger, m, "");
00128         m << getFrameBuilder()->getFUN()->getName() << ": Next TimingNode: Last TimingNode called";
00129         MESSAGE_END()
00130     }
00131 }
00132 
00133 void TimingControl::periodically()
00134 {
00135     //Notify NewFrame-Observers about newFrame
00136     frameBuilder->notifyNewFrameObservers();
00137 
00138     // Only continue if running == true
00139     if ( !running )
00140         return;
00141 
00142     // Frameduration ends before last timing node is called
00143     if (    activeCC != compoundCollectors.end())
00144     {
00145         MESSAGE_BEGIN(NORMAL, logger, m, "");
00146         m << getFrameBuilder()->getFUN()->getLayer()->getName()
00147           << ": FrameBuilder has not received last Frame.";
00148         MESSAGE_END();
00149         //std::stringstream ss;
00150         //ss << getFrameBuilder()->getFUN()->getName();
00151         //ss << ": Timing nodes are still active at begin of frame. \n";
00152         //throw wns::Exception(ss.str());
00153     }
00154 
00155     MESSAGE_BEGIN(NORMAL, logger, m, "");
00156     m << getFrameBuilder()->getFUN()->getName()<< ": Starting Frame";
00157     MESSAGE_END();
00158 
00159     for (CompoundCollectors::iterator it = compoundCollectors.begin();
00160          it != compoundCollectors.end();
00161          ++it ) {
00162         (*it)->startCollection(CompoundCollector::Sending);
00163     }
00164 
00165     for_each( compoundCollectors.begin(), compoundCollectors.end(),
00166           std::mem_fun(&CompoundCollectorInterface::finishCollection));
00167 
00168     activeCC = compoundCollectors.begin();
00169     (*activeCC)->start(0);
00170 }
00171 

Generated on Sun May 27 03:31:43 2012 for openWNS by  doxygen 1.5.5