1
/*******************************************************************************
2
* This file is part of openWNS (open Wireless Network Simulator)
3
* _____________________________________________________________________________
5
* Copyright (C) 2004-2009
6
* Chair of Communication Networks (ComNets)
7
* Kopernikusstr. 5, D-52074 Aachen, Germany
8
* phone: ++49-241-80-27910,
9
* fax: ++49-241-80-22242
10
* email: info@openwns.org
11
* www: http://www.openwns.org
12
* _____________________________________________________________________________
14
* openWNS is free software; you can redistribute it and/or modify it under the
15
* terms of the GNU Lesser General Public License version 2 as published by the
16
* Free Software Foundation;
18
* openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
19
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
23
* You should have received a copy of the GNU Lesser General Public License
24
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
******************************************************************************/
28
#include <WIMAC/compoundSwitch/CompoundSwitch.hpp>
29
#include <WIMAC/compoundSwitch/Filter.hpp>
31
#include <WNS/pyconfig/View.hpp>
32
#include <WNS/Assure.hpp>
35
using namespace wimac;
36
using namespace wimac::compoundSwitch;
39
STATIC_FACTORY_REGISTER_WITH_CREATOR(CompoundSwitch,
40
wns::ldk::FunctionalUnit,
41
"wimac.compoundSwitch.CompoundSwitch",
42
wns::ldk::FUNConfigCreator);
44
CompoundSwitch::CompoundSwitch(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config) :
45
wns::ldk::CommandTypeSpecifier<CompoundSwitchCommand>(fun),
46
wns::ldk::HasReceptor<>(),
47
wns::ldk::HasConnector<CompoundSwitchConnector>(),
48
wns::ldk::HasDeliverer<CompoundSwitchDeliverer>(),
49
wns::Cloneable<CompoundSwitch>(),
51
logger_("WNS","CompoundSwitch")
54
//////// configure all onData Filter
55
int nOnDataFilter = config.len("onDataFilters");
57
MESSAGE_BEGIN(NORMAL, logger_, m, "");
58
m << getFUN()->getName()
59
<< ": configuring onDataFilters. Number of onDataFilter: " << nOnDataFilter;
62
for ( int i = 0; i < nOnDataFilter; ++i )
64
wns::pyconfig::View onDataFilterConfig( config, "onDataFilters", i );
65
std::string pluginName
66
= onDataFilterConfig.get<std::string>("__plugin__");
68
Filter* onDataFilter( FilterFactory::creator(pluginName)
69
->create( this, onDataFilterConfig ) );
71
getDeliverer()->addFilter(onDataFilter);
75
//////// configure all sendData Filter
76
int nSendDataFilter = config.len("sendDataFilters");
78
MESSAGE_BEGIN(NORMAL, logger_, m, "");
79
m << getFUN()->getName()
80
<< ": configuring sendDataFilters. Number of sendDataFilter: " << nSendDataFilter;
83
for ( int i = 0; i < nSendDataFilter; ++i )
85
wns::pyconfig::View sendDataFilterConfig( config, "sendDataFilters", i );
86
std::string pluginName
87
= sendDataFilterConfig.get<std::string>("__plugin__");
89
Filter* sendDataFilter( FilterFactory::creator(pluginName)
90
->create( this, sendDataFilterConfig ) );
92
getConnector()->addFilter(sendDataFilter);
99
CompoundSwitch::~CompoundSwitch()
107
CompoundSwitch::onFUNCreated()
109
getDeliverer()->onFUNCreated();
110
getConnector()->onFUNCreated();
112
printFilterAssociation();
118
wns::ldk::FunctionalUnit*
119
CompoundSwitch::findFUNFriend(std::string friendName)
121
return getFUN()->findFriend<FunctionalUnit*>(friendName);
126
////////// private functions ///////////////////////////////
129
CompoundSwitch::doSendData(const wns::ldk::CompoundPtr& compound)
131
MESSAGE_BEGIN(NORMAL, logger_, m, "");
132
m << getFUN()->getName() << ": Outgoing compound catch by filter: "
133
<< getConnector()->getFilter(compound)->getName();
135
getConnector()->getAcceptor(compound)->sendData(compound);
141
CompoundSwitch::doOnData(const wns::ldk::CompoundPtr& compound)
143
MESSAGE_BEGIN(NORMAL, logger_, m, "");
144
m << getFUN()->getName() << ": Incomming compound catch by filter: "
145
<< getDeliverer()->getFilter(compound)->getName();
147
getDeliverer()->getAcceptor(compound)->onData(compound);
153
CompoundSwitch::doIsAccepting(const wns::ldk::CompoundPtr& compound) const
155
return getConnector()->hasAcceptor(compound);
161
CompoundSwitch::doWakeup()
163
getReceptor()->wakeup();
168
CompoundSwitch::printFilterAssociation()
171
MESSAGE_BEGIN(NORMAL, logger_, m, "");
172
m << getFUN()->getName()
173
<<": onData association: [ Filter, Functional Unit ]";
176
wns::ldk::Link::ExchangeContainer fus = getDeliverer()->get();
177
CompoundSwitchDeliverer::Filters filters = getDeliverer()->getAllFilter();
179
assure(filters.size()==fus.size(),"Number of FUs mismatch the number of Filters");
181
CompoundSwitchDeliverer::Filters::iterator itFilter = filters.begin();
182
for(wns::ldk::Link::ExchangeContainer::const_iterator itFU = fus.begin();
183
itFU != fus.end();++itFU)
185
MESSAGE_BEGIN(NORMAL, logger_, m, "");
186
m << getFUN()->getName() << " ( "
187
<< (*itFilter)->getName() << ", " <<(*itFU)->getName() << " )";
193
MESSAGE_BEGIN(NORMAL, logger_, m, "");
194
m << getFUN()->getName()
195
<< ": sendData association: [ Filter, Functional Unit ]";
198
fus = getConnector()->get();
199
filters = getConnector()->getAllFilter();
201
assure(filters.size()==fus.size(),"Number of FUs mismatch the number of Filters");
203
itFilter = filters.begin();
204
for(wns::ldk::Link::ExchangeContainer::const_iterator itFU = fus.begin();
205
itFU != fus.end();++itFU)
207
MESSAGE_BEGIN(NORMAL, logger_, m, "");
208
m << getFUN()->getName() << " ( "
209
<<(*itFilter)->getName() << ", " <<(*itFU)->getName() << " )";