User Manual, Developers Guide and API Documentation

Generator.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. 16, 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 
00028 #include <CONSTANZE/Generator.hpp>
00029 #include <CONSTANZE/Binding.hpp>
00030 #include <CONSTANZE/ConstanzeComponent.hpp>
00031 
00032 #include <WNS/module/Base.hpp>
00033 #include <WNS/distribution/Distribution.hpp>
00034 #include <WNS/node/Node.hpp>
00035 
00036 using namespace constanze;
00037 
00038 GeneratorBase::GeneratorBase( const wns::pyconfig::View& config) :
00039     pyco(config),
00040     log(config.get("logger")),
00041     binding(NULL),
00042     startTrigger(NULL),
00043     stopTrigger(NULL),
00044     packetCounter(0UL),
00045     bitCounter(0UL)
00046 {
00047 }
00048 
00049 GeneratorBase::~GeneratorBase()
00050 {
00051     MESSAGE_BEGIN(NORMAL, log, m, "Created a total of ");
00052     m << packetCounter << " packets with " << bitCounter << " bits";
00053     if (binding) m << " to IP=" << *binding;
00054     MESSAGE_END();
00055 
00056     if (startTrigger != NULL) delete startTrigger; startTrigger = NULL;
00057     if (stopTrigger != NULL) delete stopTrigger; stopTrigger = NULL;
00058 }
00059 
00060 void GeneratorBase::registerBinding(constanze::Binding* _binding)
00061 {
00062     binding = _binding;
00063     double offset   = pyco.get<simTimeType>("offset");
00064     double duration = pyco.get<simTimeType>("duration");
00065     MESSAGE_SINGLE(NORMAL, log, "registerBinding(@offset="<<offset<<"s for duration="<<duration<<"s)");
00066     startTrigger = new constanze::StartTrigger(binding, this, offset);
00067     // duration==0 means infinite
00068     if (duration != 0.0)
00069         stopTrigger = new constanze::StopTrigger(binding, this, offset + duration);
00070 }
00071 
00072 void GeneratorBase::bindingReady()
00073 {
00074     start();
00075     assure(startTrigger!=NULL,"no startTrigger");
00076     MESSAGE_SINGLE(NORMAL, log, "bindingReady()");
00077     delete startTrigger;
00078     startTrigger = NULL;
00079 }
00080 
00081 void
00082 GeneratorBase::bindingReleased()
00083 {
00084     stop();
00085     assure(stopTrigger!=NULL,"no stopTrigger");
00086     delete stopTrigger;
00087     stopTrigger = NULL;
00088 }
00089 
00090 void GeneratorBase::sendData(const wns::osi::PDUPtr& pdu)
00091 {
00092     binding->sendData(pdu);
00093 }
00094 
00095 void GeneratorBase::countPackets(const int packetSizeBits)
00096 {
00097     packetCounter += 1;
00098     bitCounter += packetSizeBits;
00099 }
00100 
00101 /*************************** Trigger Events *******************************/
00102 
00103 StartTrigger::StartTrigger(constanze::Binding* _binding, constanze::GeneratorBase* _generator, double _startTime) :
00104     binding(_binding),
00105     generator(_generator)
00106 {
00107     setTimeout(_startTime);
00108 }
00109 
00110 
00111 void StartTrigger::onTimeout()
00112 {
00113     binding->initBinding(this);
00114 }
00115 
00116 
00117 void StartTrigger::bindingReady()
00118 {
00119     generator->bindingReady();
00120 }
00121 
00122 
00123 StopTrigger::StopTrigger(constanze::Binding* _binding, constanze::GeneratorBase* _generator, double _stopTime) :
00124     binding(_binding),
00125     generator(_generator)
00126 {
00127     setTimeout(_stopTime);
00128 }
00129 
00130 
00131 void StopTrigger::onTimeout()
00132 {
00133     binding->releaseBinding(this);
00134 }
00135 
00136 
00137 void StopTrigger::bindingReady()
00138 {
00139     generator->bindingReleased();
00140 }
00141 
00142 /*
00143   Local Variables:
00144   mode: c++
00145   fill-column: 80
00146   c-basic-offset: 8
00147   c-comment-only-line-offset: 0
00148   c-tab-always-indent: t
00149   indent-tabs-mode: t
00150   tab-width: 8
00151   End:
00152 */

Generated on Thu May 24 03:32:15 2012 for openWNS by  doxygen 1.5.5