![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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 <WNS/ldk/tools/ConstantDelay.hpp> 00029 00030 using namespace wns::ldk::tools; 00031 00032 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00033 ConstantDelay, 00034 wns::ldk::FunctionalUnit, 00035 "wns.ldk.tools.ConstantDelay", 00036 wns::ldk::FUNConfigCreator); 00037 00038 ConstantDelay::ConstantDelay(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config_) : 00039 wns::ldk::fu::Plain<ConstantDelay, wns::ldk::EmptyCommand>(fun), 00040 wns::ldk::Delayed<ConstantDelay>(), 00041 currentFrame(), 00042 delay(config_.get<wns::simulator::Time>("delayDuration")), 00043 logger(config_.get("logger")) 00044 { 00045 00046 } 00047 00048 void 00049 ConstantDelay::processIncoming(const wns::ldk::CompoundPtr& compound) 00050 { 00051 getDeliverer()->getAcceptor(compound)->onData(compound); 00052 } 00053 00054 void 00055 ConstantDelay::processOutgoing(const wns::ldk::CompoundPtr& compound) 00056 { 00057 assure(hasCapacity(), "called processOutgoing although no capacity"); 00058 MESSAGE_SINGLE(NORMAL, this->logger, "Ougoing compound, delay for " << delay); 00059 this->currentFrame = compound; 00060 this->setTimeout(delay); 00061 } 00062 00063 bool 00064 ConstantDelay::hasCapacity() const 00065 { 00066 // There is room for exactly one compound 00067 return this->currentFrame == wns::ldk::CompoundPtr(); 00068 } 00069 00070 const wns::ldk::CompoundPtr 00071 ConstantDelay::hasSomethingToSend() const 00072 { 00073 if(hasTimeoutSet()) 00074 { 00075 return(wns::ldk::CompoundPtr()); 00076 } 00077 else 00078 { 00079 return(this->currentFrame); 00080 } 00081 } 00082 00083 wns::ldk::CompoundPtr 00084 ConstantDelay::getSomethingToSend() 00085 { 00086 assure(hasSomethingToSend(), "Called getSomethingToSend without something to send"); 00087 wns::ldk::CompoundPtr it = this->currentFrame; 00088 this->currentFrame = wns::ldk::CompoundPtr(); 00089 00090 return it; 00091 } 00092 00093 void 00094 ConstantDelay::onTimeout() 00095 { 00096 MESSAGE_SINGLE(NORMAL, this->logger, "Delay has passed, send compound"); 00097 tryToSend(); 00098 } 00099 00100 00101
1.5.5