![]() |
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/fun/Sub.hpp> 00029 00030 #include <WNS/ldk/Layer.hpp> 00031 #include <WNS/ldk/FunctionalUnit.hpp> 00032 #include <WNS/ldk/CommandPool.hpp> 00033 #include <WNS/ldk/CommandProxy.hpp> 00034 #include <WNS/ldk/LinkHandlerInterface.hpp> 00035 00036 using namespace ::wns::ldk; 00037 using namespace ::wns::ldk::fun; 00038 00039 00040 Sub::Sub(fun::FUN* fuNet) : 00041 parent(fuNet), 00042 layer(parent->getLayer()), 00043 proxy(parent->getProxy()), 00044 fuMap(), 00045 linkHandler(parent->getLinkHandler()), 00046 nameParentFU("None") 00047 { 00048 } // Sub 00049 00050 00051 void 00052 Sub::onFUNCreated() 00053 { 00054 for(FunctionalUnitMap::iterator it = fuMap.begin(); 00055 it != fuMap.end(); 00056 ++it) { 00057 it->second->onFUNCreated(); 00058 } 00059 } 00060 00061 00062 Sub::~Sub() 00063 { 00064 for(FunctionalUnitMap::iterator it = fuMap.begin(); 00065 it != fuMap.end(); 00066 ++it) 00067 delete it->second; 00068 } // ~Sub 00069 00070 00071 CommandProxy* 00072 Sub::getProxy() const 00073 { 00074 return this->proxy; 00075 } // getProxy 00076 00077 00078 void 00079 Sub::addFunctionalUnit(const std::string& commandName, 00080 const std::string& functionalUnitName, 00081 FunctionalUnit* functionalUnit) 00082 { 00083 assure(functionalUnit, "tried to add invalid functionalUnit."); 00084 00085 if(this->_knowsFunctionalUnit(functionalUnitName)) 00086 throw Exception("FunctionalUnit " + functionalUnitName + " already added."); 00087 00088 functionalUnit->setName(functionalUnitName); 00089 00090 this->fuMap[functionalUnitName] = functionalUnit; 00091 this->getProxy()->addFunctionalUnit(commandName, functionalUnit); 00092 } // addFunctionalUnit 00093 00094 00095 void 00096 Sub::addFunctionalUnit(const std::string& name, FunctionalUnit* functionalUnit) 00097 { 00098 assure(functionalUnit, "tried to add invalid functionalUnit."); 00099 00100 if(this->_knowsFunctionalUnit(name)) 00101 throw Exception("FunctionalUnit " + name + " already added."); 00102 00103 functionalUnit->setName(name); 00104 00105 this->fuMap[name] = functionalUnit; 00106 this->getProxy()->addFunctionalUnit(name, functionalUnit); 00107 } // addFunctionalUnit 00108 00109 00110 void 00111 Sub::removeFunctionalUnit(const std::string& name) 00112 { 00113 if(!this->knowsFunctionalUnit(name)) 00114 throw Exception("FunctionalUnit " + name + " is not registered."); 00115 00116 // remove command of FU from command pool 00117 this->getProxy()->removeFunctionalUnit(name); 00118 00119 this->fuMap.erase(name); 00120 } // removeFunctionalUnit 00121 00122 00123 FunctionalUnit* 00124 Sub::getFunctionalUnit(const std::string& name) const 00125 { 00126 FunctionalUnitMap::const_iterator it = this->fuMap.find(name); 00127 00128 if(it != this->fuMap.end()) 00129 return it->second; 00130 00131 return parent->getFunctionalUnit(name); 00132 } // getFunctionalUnit 00133 00134 00135 bool 00136 Sub::_knowsFunctionalUnit(const std::string& name) const 00137 { 00138 FunctionalUnitMap::const_iterator it = this->fuMap.find(name); 00139 00140 return it != this->fuMap.end(); 00141 } // _knowsFunctionalUnit 00142 00143 00144 bool 00145 Sub::knowsFunctionalUnit(const std::string& name) const 00146 { 00147 if(_knowsFunctionalUnit(name)) 00148 return true; 00149 00150 return parent->knowsFunctionalUnit(name); 00151 } // knowsFunctionalUnit 00152 00153 00154 void 00155 Sub::connectFunctionalUnit(const std::string& upperName, const std::string& lowerName, 00156 const std::string& srcPort, const std::string& dstPort) 00157 { 00158 FunctionalUnit* upper = this->getFunctionalUnit(upperName); 00159 FunctionalUnit* lower = this->getFunctionalUnit(lowerName); 00160 00161 upper->connect(lower, srcPort, dstPort); 00162 } // connectFunctionalUnit 00163 00164 00165 void 00166 Sub::upConnectFunctionalUnit(const std::string& upperName, const std::string& lowerName, 00167 const std::string& srcPort, const std::string& dstPort) 00168 { 00169 FunctionalUnit* upper = this->getFunctionalUnit(upperName); 00170 FunctionalUnit* lower = this->getFunctionalUnit(lowerName); 00171 00172 upper->upConnect(lower, srcPort, dstPort); 00173 } // connectFunctionalUnit 00174 00175 00176 void 00177 Sub::downConnectFunctionalUnit(const std::string& upperName, const std::string& lowerName, 00178 const std::string& srcPort, const std::string& dstPort) 00179 { 00180 FunctionalUnit* upper = this->getFunctionalUnit(upperName); 00181 FunctionalUnit* lower = this->getFunctionalUnit(lowerName); 00182 00183 upper->downConnect(lower, srcPort, dstPort); 00184 } // connectFunctionalUnit 00185 00186 /* 00187 void 00188 Sub::reconfigureFUN(const wns::pyconfig::View&) 00189 { 00190 throw wns::Exception("Reconfiguration of SubFUNs is not supported yet."); 00191 } // reconfigureFUN 00192 */ 00193 00194 void 00195 Sub::removeFUsFromCommandPool() 00196 { 00197 for(FunctionalUnitMap::iterator it = fuMap.begin(); 00198 it != fuMap.end(); 00199 ++it) 00200 { 00201 getProxy()->removeFunctionalUnit(it->first); 00202 } 00203 } // removeFUsFromCommandPool 00204 00205 /* 00206 template <RECEPTACLETYPE> 00207 void 00208 translateLink(Link<RECEPTACLETYPE>* link, 00209 const std::map<RECEPTACLETYPE*,RECEPTACLETYPE*>& translate) 00210 { 00211 Link::ExchangeContainer src = link->get(); 00212 Link::ExchangeContainer dst; 00213 00214 for(Link::ExchangeContainer::iterator linkDestination = src.begin(); 00215 linkDestination != src.end(); 00216 ++linkDestination) { 00217 00218 TranslationMap::const_iterator newLinkDestination = translate.find(*linkDestination); 00219 if(newLinkDestination != translate.end()) { 00220 dst.push_back(newLinkDestination->second); 00221 } 00222 } 00223 00224 link->set(dst); 00225 } // translateLink 00226 00227 00228 Sub* 00229 Sub::clone() const 00230 { 00231 fun::Sub* sub = new Sub(parent); 00232 00233 for(FunctionalUnitMap::const_iterator it = fuMap.begin(); 00234 it != fuMap.end(); 00235 ++it) { 00236 00237 FunctionalUnit* other = dynamic_cast<FunctionalUnit*>(it->second->clone()); 00238 sub->fuMap[it->first] = other; 00239 translate[it->second] = other; 00240 } 00241 00242 for(FunctionalUnitMap::const_iterator it = sub->fuMap.begin(); 00243 it != sub->fuMap.end(); 00244 ++it) { 00245 00246 translateLink(it->second->getReceptor(), translate); 00247 translateLink(it->second->getConnector(), translate); 00248 translateLink(it->second->getDeliverer(), translate); 00249 } 00250 00251 return sub; 00252 } // clone 00253 */ 00254 00255 // 00256 // Layer delegations 00257 // 00258 00259 00260 ILayer* 00261 Sub::getLayer() const 00262 { 00263 return this->layer; 00264 } // getLayer 00265 00266 00267 std::string 00268 Sub::getName() const 00269 { 00270 return this->getLayer()->getName(); 00271 } // getName 00272 00273 void 00274 Sub::setNameParentFU(std::string _name) 00275 { 00276 nameParentFU = _name; 00277 } 00278 00279 00280 std::string 00281 Sub::getNameParentFU() const 00282 { 00283 return nameParentFU; 00284 } 00285 00286 00287 LinkHandlerInterface* 00288 Sub::getLinkHandler() const 00289 { 00290 return linkHandler; 00291 } 00292 00293 CommandReaderInterface* 00294 Sub::getCommandReader(const std::string& commandName) const 00295 { 00296 return proxy->getCommandReader(commandName); 00297 } 00298 00299
1.5.5