~openwns-possum/openwns-wimac/changedProbeName

« back to all changes in this revision

Viewing changes to src/compoundSwitch/CompoundSwitch.cpp

  • Committer: Maciej Muehleisen
  • Date: 2009-07-22 12:49:42 UTC
  • mfrom: (9.1.5 WiMAC--main--1.0)
  • Revision ID: mue@comnets.rwth-aachen.de-20090722124942-kxtxdewdcwaapl2q
Merged with internal ComNets WNS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * This file is part of openWNS (open Wireless Network Simulator)
3
 
 * _____________________________________________________________________________
4
 
 *
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
 
 * _____________________________________________________________________________
13
 
 *
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;
17
 
 *
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
21
 
 * details.
22
 
 *
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/>.
25
 
 *
26
 
 ******************************************************************************/
27
 
 
28
 
#include <WIMAC/compoundSwitch/CompoundSwitch.hpp>
29
 
#include <WIMAC/compoundSwitch/Filter.hpp>
30
 
 
31
 
#include <WNS/pyconfig/View.hpp>
32
 
#include <WNS/Assure.hpp>
33
 
 
34
 
 
35
 
using namespace wimac;
36
 
using namespace wimac::compoundSwitch;
37
 
 
38
 
 
39
 
STATIC_FACTORY_REGISTER_WITH_CREATOR(CompoundSwitch,
40
 
                                                                         wns::ldk::FunctionalUnit,
41
 
                                                                         "wimac.compoundSwitch.CompoundSwitch",
42
 
                                                                         wns::ldk::FUNConfigCreator);
43
 
 
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>(),
50
 
    friends_(),
51
 
        logger_("WNS","CompoundSwitch")
52
 
{
53
 
 
54
 
    //////// configure all onData Filter
55
 
        int nOnDataFilter = config.len("onDataFilters");
56
 
 
57
 
    MESSAGE_BEGIN(NORMAL, logger_, m, "");
58
 
    m << getFUN()->getName()
59
 
          << ": configuring onDataFilters.   Number of onDataFilter:   " << nOnDataFilter;
60
 
        MESSAGE_END();
61
 
 
62
 
        for ( int i = 0; i < nOnDataFilter; ++i )
63
 
                 {
64
 
                         wns::pyconfig::View onDataFilterConfig( config, "onDataFilters", i );
65
 
                         std::string pluginName
66
 
                                 = onDataFilterConfig.get<std::string>("__plugin__");
67
 
 
68
 
                         Filter* onDataFilter( FilterFactory::creator(pluginName)
69
 
                                                                   ->create( this, onDataFilterConfig ) );
70
 
 
71
 
                         getDeliverer()->addFilter(onDataFilter);
72
 
                 }
73
 
 
74
 
 
75
 
    //////// configure all sendData Filter
76
 
        int nSendDataFilter = config.len("sendDataFilters");
77
 
 
78
 
    MESSAGE_BEGIN(NORMAL, logger_, m, "");
79
 
    m << getFUN()->getName()
80
 
          << ": configuring sendDataFilters. Number of sendDataFilter: " << nSendDataFilter;
81
 
        MESSAGE_END();
82
 
 
83
 
        for ( int i = 0; i < nSendDataFilter; ++i )
84
 
                 {
85
 
                         wns::pyconfig::View sendDataFilterConfig( config, "sendDataFilters", i );
86
 
                         std::string pluginName
87
 
                                 = sendDataFilterConfig.get<std::string>("__plugin__");
88
 
 
89
 
                         Filter* sendDataFilter( FilterFactory::creator(pluginName)
90
 
                                                                         ->create( this, sendDataFilterConfig ) );
91
 
 
92
 
                         getConnector()->addFilter(sendDataFilter);
93
 
                 }
94
 
 
95
 
} // CompoundSwitch
96
 
 
97
 
 
98
 
 
99
 
CompoundSwitch::~CompoundSwitch()
100
 
{
101
 
 
102
 
} // ~CompoundSwitch
103
 
 
104
 
 
105
 
 
106
 
void
107
 
CompoundSwitch::onFUNCreated()
108
 
{
109
 
        getDeliverer()->onFUNCreated();
110
 
        getConnector()->onFUNCreated();
111
 
 
112
 
        printFilterAssociation();
113
 
 
114
 
}
115
 
 
116
 
 
117
 
 
118
 
wns::ldk::FunctionalUnit*
119
 
CompoundSwitch::findFUNFriend(std::string friendName)
120
 
{
121
 
        return getFUN()->findFriend<FunctionalUnit*>(friendName);
122
 
}
123
 
 
124
 
 
125
 
 
126
 
////////// private functions ///////////////////////////////
127
 
 
128
 
void
129
 
CompoundSwitch::doSendData(const wns::ldk::CompoundPtr& compound)
130
 
{
131
 
        MESSAGE_BEGIN(NORMAL, logger_, m, "");
132
 
        m << getFUN()->getName() << ": Outgoing compound catch by filter: "
133
 
          << getConnector()->getFilter(compound)->getName();
134
 
        MESSAGE_END();
135
 
        getConnector()->getAcceptor(compound)->sendData(compound);
136
 
} // doSendData
137
 
 
138
 
 
139
 
 
140
 
void
141
 
CompoundSwitch::doOnData(const wns::ldk::CompoundPtr& compound)
142
 
{
143
 
        MESSAGE_BEGIN(NORMAL, logger_, m, "");
144
 
        m << getFUN()->getName() << ": Incomming compound catch by filter: "
145
 
          << getDeliverer()->getFilter(compound)->getName();
146
 
        MESSAGE_END();
147
 
        getDeliverer()->getAcceptor(compound)->onData(compound);
148
 
} // doOnData
149
 
 
150
 
 
151
 
 
152
 
bool
153
 
CompoundSwitch::doIsAccepting(const wns::ldk::CompoundPtr& compound) const
154
 
{
155
 
        return getConnector()->hasAcceptor(compound);
156
 
 
157
 
}
158
 
 
159
 
 
160
 
void
161
 
CompoundSwitch::doWakeup()
162
 
{
163
 
        getReceptor()->wakeup();
164
 
}
165
 
 
166
 
 
167
 
void
168
 
CompoundSwitch::printFilterAssociation()
169
 
{
170
 
    // onData
171
 
        MESSAGE_BEGIN(NORMAL, logger_, m, "");
172
 
    m << getFUN()->getName()
173
 
          <<": onData association:   [ Filter, Functional Unit ]";
174
 
        MESSAGE_END();
175
 
 
176
 
        wns::ldk::Link::ExchangeContainer fus = getDeliverer()->get();
177
 
        CompoundSwitchDeliverer::Filters filters = getDeliverer()->getAllFilter();
178
 
 
179
 
    assure(filters.size()==fus.size(),"Number of FUs mismatch the number of Filters");
180
 
 
181
 
        CompoundSwitchDeliverer::Filters::iterator itFilter = filters.begin();
182
 
        for(wns::ldk::Link::ExchangeContainer::const_iterator itFU = fus.begin();
183
 
                itFU != fus.end();++itFU)
184
 
        {
185
 
                MESSAGE_BEGIN(NORMAL, logger_, m, "");
186
 
                m << getFUN()->getName() << "                        ( "
187
 
                  << (*itFilter)->getName() << ", " <<(*itFU)->getName() << " )";
188
 
                MESSAGE_END();
189
 
                ++itFilter;
190
 
        }
191
 
 
192
 
    //sendData
193
 
        MESSAGE_BEGIN(NORMAL, logger_, m, "");
194
 
        m << getFUN()->getName()
195
 
          << ": sendData association: [ Filter, Functional Unit ]";
196
 
        MESSAGE_END();
197
 
 
198
 
        fus = getConnector()->get();
199
 
        filters = getConnector()->getAllFilter();
200
 
 
201
 
    assure(filters.size()==fus.size(),"Number of FUs mismatch the number of Filters");
202
 
 
203
 
        itFilter = filters.begin();
204
 
        for(wns::ldk::Link::ExchangeContainer::const_iterator itFU = fus.begin();
205
 
                itFU != fus.end();++itFU)
206
 
        {
207
 
                MESSAGE_BEGIN(NORMAL, logger_, m, "");
208
 
                m << getFUN()->getName() << "                        ( "
209
 
                  <<(*itFilter)->getName() << ", " <<(*itFU)->getName() << " )";
210
 
                MESSAGE_END();
211
 
                ++itFilter;
212
 
        }
213
 
 
214
 
}
215
 
 
216
 
 
217
 
 
218