Download this file

Directory.cc    167 lines (135 with data), 5.6 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// 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 "Directory.h"
//Constants
const char* ELEM_DIRDATA = "Directory";
const char* ELEM_DIF = "DIF";
const char* ATTR_IPCADDR = "ipcAddress";
const char* ATTR_DIFNAME = "difName";
Define_Module(Directory);
void Directory::initialize()
{
//Parse XML config
parseConfig(par(PAR_CONFIGDATA).xmlValue());
//Init watchers
WATCH_LIST(Director);
}
DirectoryEntry* Directory::findDirEntryByApn(const APN& apn) {
for(TDirIter it = Director.begin(); it != Director.end(); ++it) {
DirectoryEntry entry = *it;
if (entry.getApn() == apn)
return &(*it);
}
return NULL;
}
void Directory::addDirEntry(const APN& apn) {
Director.push_back(DirectoryEntry(apn));
}
std::string Directory::info() const {
std::ostringstream os;
os << "id=" << this->getId() << endl;
return os.str();
}
void Directory::handleMessage(cMessage *msg)
{
}
void Directory::addNewDif(const APN& apn, const Address& member) {
findDirEntryByApn(apn)->addDif(member);
}
void Directory::removeDirEntry(const APN& apn) {
Director.remove(*(findDirEntryByApn(apn)));
}
void Directory::parseConfig(cXMLElement* config) {
cXMLElement* mainTag = NULL;
if (config != NULL && config->hasChildren() && config->getFirstChildWithTag(ELEM_DIRDATA))
mainTag = config->getFirstChildWithTag(ELEM_DIRDATA);
else {
EV << "configData parameter not initialized!" << endl;
return;
}
cXMLElementList apnlist = mainTag->getChildrenByTagName(ELEM_APN);
for (cXMLElementList::const_iterator it = apnlist.begin(); it != apnlist.end(); ++it) {
cXMLElement* m = *it;
if (!(m->getAttribute(ATTR_APN) && m->getFirstChildWithTag(ELEM_DIF))) {
EV << "\nError when parsing Directory record" << endl;
continue;
}
APN newapn = APN(m->getAttribute(ATTR_APN));
addDirEntry(newapn);
cXMLElementList diflist = m->getChildrenByTagName(ELEM_DIF);
for (cXMLElementList::const_iterator jt = diflist.begin(); jt != diflist.end(); ++jt) {
cXMLElement* n = *jt;
if (!(n->getAttribute(ATTR_IPCADDR) && n->getAttribute(ATTR_DIFNAME))) {
EV << "\nError when parsing DIF record" << endl;
continue;
}
addNewDif(newapn, Address(n->getAttribute(ATTR_IPCADDR), n->getAttribute(ATTR_DIFNAME)));
}
}
}
/*
void Directory::parseConfig(cXMLElement* config) {
cXMLElement* dirXml = NULL;
if (config != NULL && config->hasChildren() && config->getFirstChildWithTag(ELEM_DIRDATA))
dirXml = config->getFirstChildWithTag(ELEM_DIRDATA);
else {
EV << "configData parameter not initialized!" << endl;
return;
}
cXMLElementList map = dirXml->getChildrenByTagName(ELEM_DIRMAPPING);
cModule* top =
this->getParentModule()->getParentModule()->getParentModule();
for (cXMLElementList::iterator i = map.begin(); i != map.end(); ++i) {
cXMLElement* m = *i;
if (!(m->getAttribute(ATTR_APN) && m->getAttribute(ATTR_DIFNAME)
&& m->getAttribute(ATTR_IPCADDR))) {
EV << "\nError when parsing DA-Directory record" << endl
<< m->getAttribute(ATTR_APN) << "\t"
<< m->getAttribute(ATTR_IPCADDR) << "\t"
<< m->getAttribute(ATTR_DIFNAME) << endl;
continue;
}
for (cModule::SubmoduleIterator k(top); !k.end(); k++) {
//EV << k()->getFullPath() << endl;
cModule* submodp = NULL;
for (cModule::SubmoduleIterator j(k()); !j.end(); j++) {
//EV << j()->getFullPath() << endl;
submodp = j();
if (submodp->hasPar(ATTR_IPCADDR)
&& submodp->hasPar(ATTR_DIFNAME)
&& !opp_strcmp(submodp->par(ATTR_IPCADDR).stringValue(),
m->getAttribute(ATTR_IPCADDR))
&& !opp_strcmp(submodp->par(ATTR_DIFNAME).stringValue(),
m->getAttribute(ATTR_DIFNAME)))
break;
else
submodp = NULL;
}
//Appropriate IPCProcess found in simulation topology
if (submodp) {
//EV << "!!!!!OK" << endl;
this->addDirEntry(
DirectoryEntry(
APNamingInfo(APN(m->getAttribute(ATTR_APN))),
Address(m->getAttribute(ATTR_IPCADDR),
m->getAttribute(ATTR_DIFNAME)),
submodp->getFullPath(),
dynamic_cast<FABase*>(submodp->getSubmodule(
MOD_FLOWALLOC)->getSubmodule(MOD_FA))));
}
}
}
}
*/