Child: [65cd22] (diff)

Download this file

ConnectionTable.cc    126 lines (108 with data), 3.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#include "ConnectionTable.h"
Define_Module(ConnectionTable);
void ConnectionTable::initialize()
{
WATCH_LIST(ConTable);
//Insert info to the ConnectionTable
//Scan all AEs in DAP and add them to table
// for (cModule::SubmoduleIterator i(this->getParentModule()); !i.end(); i++) {
// cModule *submodp = i();
// if (dynamic_cast<AEBase*>(submodp))
// insertNewAe(dynamic_cast<AEBase*>(submodp));
// }
}
std::string ConnectionTable::info() const {
std::stringstream os;
os << "id=" << this->getId() << endl;
/*
for(TCTConstIter it = ConTable.begin(); it != ConTable.end(); ++it )
{
ConnectionTableEntry cte = *it;
os << cte << endl;
}
*/
return os.str();
}
void ConnectionTable::insertNew(Flow* flow) {
Enter_Method("insertNew()");
this->insert(ConnectionTableEntry(flow));
}
void ConnectionTable::insertNew(Flow* flow, cGate* nIn, cGate* nOut) {
Enter_Method("insertNew()");
this->insert(ConnectionTableEntry(flow, nIn, nOut));
}
void ConnectionTable::insert(const ConnectionTableEntry& entry) {
Enter_Method("insert()");
ConTable.push_back(entry);
}
void ConnectionTable::remove() {
}
ConnectionTableEntry* ConnectionTable::findEntryByFlow(Flow* flow) {
for(TCTIter it = ConTable.begin(); it != ConTable.end(); ++it) {
//EV << "Comparing" << it->getFlowObject() << " and " << flow << endl;
//EV << "=========NOVY=========\n" << it->getFlowObject()->info() << endl;
//EV << "=========STARY=========\n" << flow->info() << endl;
if ( it->getFlowObject() == flow )
return &(*it);
}
return NULL;
}
bool ConnectionTable::setSouthGates(Flow* flow, cGate* sIn, cGate* sOut) {
ConnectionTableEntry* cte = this->findEntryByFlow(flow);
if (cte) {
cte->setSouthGateIn(sIn);
cte->setSouthGateOut(sOut);
return true;
}
else
return false;
}
bool ConnectionTable::setNorthGates(Flow* flow, cGate* nIn, cGate* nOut) {
ConnectionTableEntry* cte = this->findEntryByFlow(flow);
if (cte) {
cte->setNorthGateIn(nIn);
cte->setNorthGateOut(nOut);
return true;
}
else
return false;
}
bool ConnectionTable::setFa(Flow* flow, FABase* fa) {
ConnectionTableEntry* cte = this->findEntryByFlow(flow);
if (cte) {
cte->setFlowAlloc(fa);
return true;
}
else
return false;
}
cGate* ConnectionTable::findOutputGate(cGate* input) {
for(TCTIter it = ConTable.begin(); it != ConTable.end(); ++it) {
if ( it->getNorthGateIn() == input )
return it->getSouthGateOut();
if ( it->getSouthGateIn() == input )
return it->getNorthGateOut();
}
return NULL;
}
void ConnectionTable::handleMessage(cMessage *msg)
{
}
FABase* ConnectionTable::getFa(Flow* flow) {
ConnectionTableEntry* cte = this->findEntryByFlow(flow);
return cte ? cte->getFlowAlloc() : NULL;
}