![]() |
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/Stub.hpp> 00029 00030 #include <cstdlib> 00031 #include <functional> 00032 00033 using namespace wns::ldk; 00034 using namespace wns::ldk::tools; 00035 00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(Stub, FunctionalUnit, "wns.tools.Stub", FUNConfigCreator); 00037 00038 StubBase::StubBase() : 00039 HasReceptor<>(), 00040 HasConnector<>(), 00041 HasDeliverer<>(), 00042 00043 received(ContainerType()), 00044 sent(ContainerType()), 00045 wakeupCalled(), 00046 onFUNCreatedCalled(), 00047 stepping(false), 00048 accepting(true), 00049 addToPCISize(0), 00050 addToPDUSize(0), 00051 compoundAcceptanceSize(0) 00052 { 00053 } 00054 00055 StubBase::~StubBase() 00056 { 00057 flush(); 00058 } 00059 00060 void 00061 StubBase::setStepping(bool _stepping) 00062 { 00063 stepping = _stepping; 00064 } 00065 00066 00067 void 00068 StubBase::setSizes(Bit _addToPCISize, Bit _addToPDUSize) 00069 { 00070 addToPCISize = _addToPCISize; 00071 addToPDUSize = _addToPDUSize; 00072 } 00073 00074 00075 void 00076 StubBase::setAcceptanceSize(Bit compoundSize) 00077 { 00078 compoundAcceptanceSize = compoundSize; 00079 } 00080 00081 00082 void 00083 StubBase::flush() 00084 { 00085 received.clear(); 00086 sent.clear(); 00087 } 00088 00089 00090 void 00091 StubBase::open(bool wakeup) 00092 { 00093 accepting = true; 00094 if(wakeup) 00095 getReceptor()->wakeup(); 00096 } 00097 00098 00099 void 00100 StubBase::close() 00101 { 00102 accepting = false; 00103 } 00104 00105 00106 void 00107 StubBase::step() 00108 { 00109 stepping = true; 00110 open(); 00111 stepping = false; 00112 } 00113 00114 00115 bool 00116 StubBase::doIsAccepting(const CompoundPtr& compound) const 00117 { 00118 if(!accepting) 00119 { 00120 return false; 00121 } 00122 00123 if (compoundAcceptanceSize > 0) 00124 { 00125 Bit commandPoolSize = 0; 00126 Bit dataSize = 0; 00127 00128 CompoundPtr compoundCopy = compound->copy(); 00129 activateCommand(compoundCopy->getCommandPool()); 00130 getFUN()->calculateSizes(compoundCopy->getCommandPool(), commandPoolSize, dataSize, this); 00131 00132 if(commandPoolSize + dataSize > compoundAcceptanceSize) 00133 return false; 00134 } 00135 00136 if(getConnector()->size() == 0) 00137 { 00138 return true; 00139 } 00140 00141 return getConnector()->hasAcceptor(compound); 00142 } 00143 00144 00145 void 00146 StubBase::doSendData(const CompoundPtr& compound) 00147 { 00148 assure(compound != CompoundPtr(), "sendData called with an invalid compound."); 00149 00150 if (compound->getCommandPool() && this->registeredAtProxy()) 00151 { 00152 if (this->getFUN()->getProxy()->commandIsActivated(compound->getCommandPool(), this) == false) 00153 { 00154 this->activateCommand(compound->getCommandPool()); 00155 } 00156 } 00157 00158 if (this->stepping) 00159 { 00160 this->close(); 00161 } 00162 00163 sent.push_back(compound); 00164 00165 if (this->getConnector()->size()) 00166 { 00167 this->getConnector()->getAcceptor(compound)->sendData(compound); 00168 } 00169 00170 assure(this->integrityCheck(), "Integrity check failed."); 00171 } 00172 00173 00174 void 00175 StubBase::doOnData(const CompoundPtr& compound) 00176 { 00177 assure(compound != CompoundPtr(), "Not a valid PDU."); 00178 00179 received.push_back(compound); 00180 00181 if(getDeliverer()->size()) { 00182 getDeliverer()->getAcceptor(compound)->onData(compound); 00183 } 00184 00185 assure(integrityCheck(), "Integrity check failed."); 00186 } 00187 00188 00189 void 00190 StubBase::doWakeup() 00191 { 00192 ++wakeupCalled; 00193 00194 getReceptor()->wakeup(); 00195 } 00196 00197 void 00198 StubBase::calculateSizes(const CommandPool* commandPool, Bit& commandPoolSize, Bit& dataSize) const 00199 { 00200 getFUN()->calculateSizes(commandPool, commandPoolSize, dataSize, this); 00201 00202 commandPoolSize += addToPCISize; 00203 dataSize += addToPDUSize; 00204 } 00205 00206 void 00207 StubBase::onFUNCreated() 00208 { 00209 ++onFUNCreatedCalled; 00210 } 00211 00212 bool 00213 StubBase::integrityCheck() 00214 { 00215 for(ContainerType::iterator i = received.begin(); i != received.end(); ++i) 00216 if((*i)->getRefCount() < 1) 00217 return false; 00218 00219 for(ContainerType::iterator i = sent.begin(); i != sent.end(); ++i) 00220 if((*i)->getRefCount() < 1) 00221 return false; 00222 00223 return true; 00224 } 00225 00226 00227 Stub::Stub(fun::FUN* fuNet, const pyconfig::View& /* config */) : 00228 StubBase(), 00229 CommandTypeSpecifier<StubCommand>(fuNet), 00230 Cloneable<Stub>(), 00231 sequenceNumber(0) 00232 { 00233 } 00234 00235 00236 void 00237 Stub::doSendData(const CompoundPtr& compound) 00238 { 00239 if (compound->getCommandPool() && this->registeredAtProxy()) 00240 { 00241 if (this->getFUN()->getProxy()->commandIsActivated(compound->getCommandPool(), this) == false) 00242 { 00243 this->activateCommand(compound->getCommandPool()); 00244 } 00245 StubCommand* sc = this->getCommand(compound->getCommandPool()); 00246 sc->magic.sendDataTime = wns::simulator::getEventScheduler()->getTime(); 00247 sc->magic.sequenceNumber = sequenceNumber; 00248 sequenceNumber++; 00249 } 00250 StubBase::doSendData(compound); 00251 } 00252 00253 void 00254 Stub::doOnData(const CompoundPtr& compound) 00255 { 00256 if (compound->getCommandPool() && this->registeredAtProxy()) 00257 { 00258 if (this->getFUN()->getProxy()->commandIsActivated(compound->getCommandPool(), this) == false) 00259 { 00260 this->activateCommand(compound->getCommandPool()); 00261 } 00262 StubCommand* sc = this->getCommand(compound->getCommandPool()); 00263 sc->magic.onDataTime = wns::simulator::getEventScheduler()->getTime(); 00264 } 00265 StubBase::doOnData(compound); 00266 } 00267 00268
1.5.5