User Manual, Developers Guide and API Documentation

WWW.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 
00028 #include <APPLICATIONS/session/server/WWW.hpp>
00029 
00030 using namespace applications::session::server;
00031 
00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::session::server::WWW,
00033                      applications::session::Session,
00034                      "server.WWW", wns::PyConfigViewCreator);
00035 
00036 WWW::WWW(const wns::pyconfig::View& _pyco) :
00037   Session(_pyco),
00038   sizeOfEmbeddedObjectDistribution(NULL),
00039   sizeOfMainObjectDistribution(NULL),
00040   mainObject(true)
00041 {
00042   wns::pyconfig::View sEOConfig(_pyco, "sizeOfEmbeddedObject");
00043   std::string sEOName = sEOConfig.get<std::string>("__plugin__");
00044   sizeOfEmbeddedObjectDistribution = wns::distribution::DistributionFactory::creator(sEOName)->create(sEOConfig);
00045 
00046   wns::pyconfig::View sMOConfig(_pyco, "sizeOfMainObject");
00047   std::string sMOName = sMOConfig.get<std::string>("__plugin__");
00048   sizeOfMainObjectDistribution = wns::distribution::DistributionFactory::creator(sMOName)->create(sMOConfig);
00049 
00050   settlingTime = _pyco.get<wns::simulator::Time>("settlingTime");
00051 
00052   /* only for probes */
00053   sessionType = www;
00054 
00055   packetFrom = "server.WWW";
00056 }
00057 
00058 WWW::~WWW()
00059 {
00060   if(sizeOfEmbeddedObjectDistribution != NULL)
00061     delete sizeOfEmbeddedObjectDistribution;
00062   sizeOfEmbeddedObjectDistribution = NULL;
00063 
00064   if(sizeOfMainObjectDistribution != NULL)
00065     delete sizeOfMainObjectDistribution;
00066   sizeOfMainObjectDistribution = NULL;
00067 }
00068 
00069 void
00070 WWW::onData(const wns::osi::PDUPtr& _pdu)
00071 {
00072   state = running;
00073 
00074   assureType(_pdu.getPtr(), applications::session::PDU*);
00075 
00076   receivedPacketNumber = static_cast<applications::session::PDU*>(_pdu.getPtr())->getPacketNumber();
00077 
00078   MESSAGE_SINGLE(NORMAL, logger, "APPL: receivedPacketNumber = " << receivedPacketNumber << ".");
00079 
00080   applications::session::Session::incomingProbesCalculation(_pdu);
00081 
00082   lastPacket = static_cast<applications::session::PDU*>(_pdu.getPtr())->getLastPacket();
00083 
00084   if(receivedPacketNumber == 1)
00085     {
00086       firstPacketDelay = packetDelay;
00087     }
00088 
00089   onTimeout(statetimeout);
00090 }
00091 
00092 void
00093 WWW::onTimeout(const Timeout& _t)
00094 {
00095   if(_t == statetimeout)
00096     {
00097       if(mainObject == false)
00098     {
00099       /* Sending embedded object. */
00100 
00101       double distributedValue = (*sizeOfEmbeddedObjectDistribution)();
00102       /* The distributed value is in byte, so it has to be converted to bit! */
00103       packetSize = distributedValue * 8.0;
00104 
00105       applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco);
00106       applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime());
00107 
00108       ++packetNumber;
00109       applicationPDU->setPacketNumber(packetNumber, packetFrom);
00110       MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << ".");
00111 
00112       state = idle;
00113 
00114       if(lastPacket == false)
00115         {
00116           wns::osi::PDUPtr pdu(applicationPDU);
00117           applications::session::Session::outgoingProbesCalculation(pdu);
00118 
00119           connection->sendData(pdu);
00120         }
00121       else
00122         {
00123           /* Sending last embeddedobject and wait till session ends. */
00124           applicationPDU->setLastPacket(true);
00125           wns::osi::PDUPtr pdu(applicationPDU);
00126           applications::session::Session::outgoingProbesCalculation(pdu);
00127 
00128           connection->sendData(pdu);
00129         }
00130     }
00131       else
00132     {
00133       /* Sending main object. */
00134       MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending mainObject.");
00135 
00136       double distributedValue = (*sizeOfMainObjectDistribution)();
00137       /* The distributed value is in byte, so it has to be converted to bit! */
00138       packetSize = distributedValue * 8.0;
00139 
00140       applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco);
00141       applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime());
00142 
00143       packetNumber = 1;
00144       applicationPDU->setPacketNumber(packetNumber, packetFrom);
00145       MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << ".");
00146 
00147       wns::osi::PDUPtr pdu(applicationPDU);
00148       applications::session::Session::outgoingProbesCalculation(pdu);
00149 
00150       connection->sendData(pdu);
00151 
00152       mainObject = false;
00153       state = idle;
00154     }
00155     }
00156   else if(_t == probetimeout)
00157     {
00158       applications::session::Session::onTimeout(_t);
00159     }
00160   else
00161     {
00162       assure(false, "APPL: Unknown timout type =" << _t);
00163     }
00164 }

Generated on Sun May 27 03:32:16 2012 for openWNS by  doxygen 1.5.5