![]() |
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. 16, 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 <DLL/compoundSwitch/CompoundSwitch.hpp> 00029 #include <DLL/compoundSwitch/Filter.hpp> 00030 00031 #include <WNS/pyconfig/View.hpp> 00032 #include <WNS/Assure.hpp> 00033 00034 using namespace dll::compoundSwitch; 00035 00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(CompoundSwitch, 00037 wns::ldk::FunctionalUnit, 00038 "dll.compoundSwitch.CompoundSwitch", 00039 wns::ldk::FUNConfigCreator); 00040 00041 CompoundSwitch::CompoundSwitch(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config) : 00042 wns::ldk::CommandTypeSpecifier<CompoundSwitchCommand>(fun), 00043 wns::ldk::HasReceptor<>(), 00044 wns::ldk::HasConnector<CompoundSwitchConnector>(), 00045 wns::ldk::HasDeliverer<CompoundSwitchDeliverer>(), 00046 wns::Cloneable<CompoundSwitch>(), 00047 friends_(), 00048 logger_(config.get("logger")), 00049 mustAccept_(config.get<bool>("mustAccept")) 00050 { 00051 // configure all onData Filter 00052 int nOnDataFilter = config.len("onDataFilters"); 00053 00054 MESSAGE_SINGLE(NORMAL, logger_, "Configuring onDataFilters. Number of onDataFilters: " << nOnDataFilter); 00055 00056 for ( int i = 0; i < nOnDataFilter; ++i ) 00057 { 00058 wns::pyconfig::View onDataFilterConfig( config, "onDataFilters", i ); 00059 std::string pluginName = onDataFilterConfig.get<std::string>("__plugin__"); 00060 00061 Filter* onDataFilter( FilterFactory::creator(pluginName) 00062 ->create( this, onDataFilterConfig ) ); 00063 00064 getDeliverer()->addFilter(onDataFilter); 00065 } 00066 00067 // configure all sendData Filter 00068 int nSendDataFilter = config.len("sendDataFilters"); 00069 00070 MESSAGE_SINGLE(NORMAL, logger_, "Configuring sendDataFilters. Number of sendDataFilters: " << nSendDataFilter); 00071 00072 for ( int i = 0; i < nSendDataFilter; ++i ) 00073 { 00074 wns::pyconfig::View sendDataFilterConfig( config, "sendDataFilters", i ); 00075 std::string pluginName = sendDataFilterConfig.get<std::string>("__plugin__"); 00076 00077 Filter* sendDataFilter( FilterFactory::creator(pluginName) 00078 ->create( this, sendDataFilterConfig ) ); 00079 00080 getConnector()->addFilter(sendDataFilter); 00081 } 00082 00083 } // CompoundSwitch 00084 00085 CompoundSwitch::~CompoundSwitch() 00086 { 00087 00088 } // ~CompoundSwitch 00089 00090 void 00091 CompoundSwitch::onFUNCreated() 00092 { 00093 getDeliverer()->onFUNCreated(); 00094 getConnector()->onFUNCreated(mustAccept_); 00095 00096 printFilterAssociation(); 00097 } 00098 00099 wns::ldk::FunctionalUnit* 00100 CompoundSwitch::findFUNFriend(std::string friendName) 00101 { 00102 return getFUN()->findFriend<FunctionalUnit*>(friendName); 00103 } 00104 00106 void 00107 CompoundSwitch::doSendData(const wns::ldk::CompoundPtr& compound) 00108 { 00109 MESSAGE_SINGLE(NORMAL, logger_, "Outgoing compound catch by filter " << getConnector()->getFilter(compound)->getName()); 00110 getConnector()->getAcceptor(compound)->sendData(compound); 00111 } // doSendData 00112 00113 void 00114 CompoundSwitch::doOnData(const wns::ldk::CompoundPtr& compound) 00115 { 00116 MESSAGE_SINGLE(NORMAL, logger_, "Incomming compound catch by filter " << getDeliverer()->getFilter(compound)->getName()); 00117 getDeliverer()->getAcceptor(compound)->onData(compound); 00118 } // doOnData 00119 00120 bool 00121 CompoundSwitch::doIsAccepting(const wns::ldk::CompoundPtr& compound) const 00122 { 00123 return getConnector()->hasAcceptor(compound); 00124 00125 } 00126 00127 void 00128 CompoundSwitch::doWakeup() 00129 { 00130 getReceptor()->wakeup(); 00131 } 00132 00133 void 00134 CompoundSwitch::printFilterAssociation() 00135 { 00136 // onData 00137 MESSAGE_SINGLE(NORMAL, logger_, "onData association: [ Filter -> Functional Unit ]"); 00138 00139 wns::ldk::Link<wns::ldk::IDelivererReceptacle>::ExchangeContainer fus = getDeliverer()->get(); 00140 CompoundSwitchDeliverer::Filters filters = getDeliverer()->getAllFilter(); 00141 00142 if ( filters.size() != fus.size() ) { 00143 std::stringstream ss; 00144 ss << "Configuration Error" << std::endl 00145 << "Number of onData Filters mismatch number of upper FUs in Compound Switch" << std::endl 00146 << "Number of onData Filters: " << filters.size() << " Number of upper FUs: " << fus.size() << std::endl; 00147 throw wns::Exception(ss.str()); 00148 } 00149 00150 CompoundSwitchDeliverer::Filters::iterator itFilter = filters.begin(); 00151 for(wns::ldk::Link<wns::ldk::IDelivererReceptacle>::ExchangeContainer::const_iterator itFU = fus.begin(); 00152 itFU != fus.end();++itFU) 00153 { 00154 MESSAGE_SINGLE(NORMAL, logger_, (*itFilter)->getName() << " -> " << (*itFU)->getFU()->getName()); 00155 ++itFilter; 00156 } 00157 00158 //sendData 00159 MESSAGE_SINGLE(NORMAL, logger_,"sendData association: [ Filter, Functional Unit ]"); 00160 00161 wns::ldk::Link<wns::ldk::IConnectorReceptacle>::ExchangeContainer cons = getConnector()->get(); 00162 filters = getConnector()->getAllFilter(); 00163 00164 if ( filters.size() != cons.size() ) { 00165 std::stringstream ss; 00166 ss << "Configuration Error" << std::endl 00167 << "Number of sendData Filters mismatch number of lower FUs in Compound Switch" << std::endl 00168 << "Number of sendData Filters: " << filters.size() << " Number of lower FUs: " << cons.size() << std::endl; 00169 throw wns::Exception(ss.str()); 00170 } 00171 00172 itFilter = filters.begin(); 00173 for(wns::ldk::Link<wns::ldk::IConnectorReceptacle>::ExchangeContainer::const_iterator itFU = cons.begin(); 00174 itFU != cons.end();++itFU) 00175 { 00176 MESSAGE_SINGLE(NORMAL, logger_, (*itFilter)->getName() << " -> " <<(*itFU)->getFU()->getName()); 00177 ++itFilter; 00178 } 00179 00180 }
1.5.5