![]() |
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/flowseparator/NotFoundStrategy.hpp> 00029 #include <WNS/ldk/flowseparator/CreatorStrategy.hpp> 00030 #include <WNS/ldk/flowseparator/FlowInfoProvider.hpp> 00031 00032 #include <WNS/ldk/tools/FakeFU.hpp> 00033 #include <WNS/ldk/FUNConfigCreator.hpp> 00034 #include <WNS/ldk/Layer.hpp> 00035 00036 using namespace wns::ldk::flowseparator; 00037 using namespace wns::ldk; 00038 00039 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00040 Complain, 00041 NotFoundStrategy, 00042 "complain", 00043 FUNConfigCreator); 00044 00045 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00046 CreateOnFirstCompound, 00047 NotFoundStrategy, 00048 "createonfirstcompound", 00049 FUNConfigCreator); 00050 00051 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00052 CreateOnValidFlow, 00053 NotFoundStrategy, 00054 "createonvalidflow", 00055 FUNConfigCreator); 00056 00057 NotFoundStrategy::~NotFoundStrategy() 00058 { 00059 } 00060 00061 00062 Complain::Complain(fun::FUN* /* fuNet */, const pyconfig::View& /* config */) 00063 { 00064 } 00065 00066 00067 Complain::Complain() 00068 { 00069 } 00070 00071 00072 FunctionalUnit* 00073 Complain::ifNotFound(const ConstKeyPtr& /* key */) const 00074 { 00075 throw wns::Exception("flowseparator::Complain: no matching instance!"); 00076 } 00077 00078 FunctionalUnit* 00079 Complain::createPrototype() const 00080 { 00081 return new wns::ldk::tools::FakeFU(); 00082 } 00083 00084 void 00085 Complain::onFUNCreated() 00086 {} 00087 00088 CreateOnFirstCompound::CreateOnFirstCompound(fun::FUN* fuNet, const pyconfig::View& config) : 00089 creator() 00090 { 00091 pyconfig::View creatorConfig(config, "creator"); 00092 std::string creatorName = creatorConfig.get<std::string>("__plugin__"); 00093 creator = std::auto_ptr<CreatorStrategy>( 00094 flowseparator::CreatorStrategyFactory::creator(creatorName)->create(fuNet, creatorConfig)); 00095 } 00096 00097 CreateOnFirstCompound::CreateOnFirstCompound(CreatorStrategy* _creator) : 00098 creator(_creator) 00099 {} 00100 00101 CreateOnFirstCompound::~CreateOnFirstCompound() 00102 { 00103 } 00104 00105 FunctionalUnit* 00106 CreateOnFirstCompound::ifNotFound(const ConstKeyPtr& /* key */) const 00107 { 00108 return creator->create(); 00109 } 00110 00111 FunctionalUnit* 00112 CreateOnFirstCompound::createPrototype() const 00113 { 00114 return creator->createPrototype(); 00115 } 00116 00117 void 00118 CreateOnFirstCompound::onFUNCreated() 00119 {} 00120 00121 00122 CreateOnValidFlow::CreateOnValidFlow(fun::FUN* fuNet, const pyconfig::View& config) : 00123 fun(fuNet), 00124 creator(), 00125 flowInfo(NULL), 00126 flowInfoProviderName(config.get<std::string>("flowInfoProviderName")) 00127 { 00128 pyconfig::View creatorConfig(config, "creator"); 00129 std::string creatorName = creatorConfig.get<std::string>("__plugin__"); 00130 creator = std::auto_ptr<CreatorStrategy>( 00131 flowseparator::CreatorStrategyFactory::creator(creatorName)->create(fuNet, creatorConfig)); 00132 } 00133 00134 CreateOnValidFlow::CreateOnValidFlow(CreatorStrategy* _creator, FlowInfoProvider* _flowInfo) : 00135 fun(NULL), 00136 creator(_creator), 00137 flowInfo(_flowInfo), 00138 flowInfoProviderName("") 00139 {} 00140 00141 CreateOnValidFlow::~CreateOnValidFlow() 00142 { 00143 } 00144 00145 FunctionalUnit* 00146 CreateOnValidFlow::ifNotFound(const ConstKeyPtr& key) const 00147 { 00148 if ( flowInfo->isValidFlow(key) ) 00149 { 00150 return creator->create(); 00151 } 00152 else 00153 { 00154 std::string error = "flowseparator::CreateOnValidFlow: Can't create FU for this flow: " + key->str() + ". FlowInfoProvider says flow is not valid."; 00155 throw wns::Exception(error); 00156 } 00157 } 00158 00159 FunctionalUnit* 00160 CreateOnValidFlow::createPrototype() const 00161 { 00162 return creator->createPrototype(); 00163 } 00164 00165 void 00166 CreateOnValidFlow::onFUNCreated() 00167 { 00168 assure(fun != NULL, "flowseparator::CreateOnValidFlow: invalid FUN"); 00169 00170 // set pointer to FlowInfoProvider 00171 flowInfo = fun->getLayer()->getControlService<FlowInfoProvider>(flowInfoProviderName); 00172 } 00173
1.5.5