Download this file

NamingInformation.cc    136 lines (110 with data), 4.4 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
//
// 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 "NamingInformation.h"
//Constants
const char* ELEM_NAMINGTABLE = "NamingInfo";
const char* ELEM_SYNONYM = "Synonym";
Define_Module(NamingInformation);
void NamingInformation::initialize()
{
//Parse XML config
parseConfig(par(PAR_CONFIGDATA).xmlValue());
//Init watchers
WATCH_LIST(NamingInfoTable);
}
void NamingInformation::addNamingEntry(const APN& apn) {
NamingInfoTable.push_back(NamingInformationEntry(apn));
}
NamingInformationEntry* NamingInformation::findNamingEntryByApn(const APN& apn) {
for (NamingItem it = NamingInfoTable.begin(); it != NamingInfoTable.end(); ++it) {
if (it->getApn() == apn)
return &(*it);
}
return NULL;
}
void NamingInformation::addNewSynonym(const APN& apn, const APN& synonym) {
findNamingEntryByApn(apn)->addSynonym(synonym);
}
void NamingInformation::removeNamingEntry(const APN& apn) {
NamingInfoTable.remove(*(findNamingEntryByApn(apn)));
}
NamingInformationEntry* NamingInformation::findNamingEntryBySynonym(const APN& synonym) {
for (NamingItem it = NamingInfoTable.begin(); it != NamingInfoTable.end(); ++it) {
if (it->hasSynonym(synonym))
return &(*it);
}
return NULL;
}
const APN* NamingInformation::findApnBySynonym(const APN& synonym) {
NamingInformationEntry* entry = findNamingEntryBySynonym(synonym);
return entry ? &(entry->getApn()) : NULL;
}
void NamingInformation::handleMessage(cMessage *msg)
{
}
const APNList NamingInformation::findAllApnNames(const APN& apn) {
NamingInformationEntry* entry1 = findNamingEntryByApn(apn);
NamingInformationEntry* entry2 = findNamingEntryBySynonym(apn);
APNList result = APNList();
//APN does not exist within NamingInfo
if (entry1 == NULL && entry2 == NULL) {
EV << "No NamingInfo thus considering " << apn << " as unique!" << endl;
result.push_back(apn);
}
//APN without any synonyms
else if (entry1 != NULL && entry2 == NULL) {
result.push_back(apn);
}
//Found based on synonym
else if (entry1 == NULL && entry2 != NULL) {
result = entry2->getSynonyms();
result.push_back(apn);
}
//Inconsistancy where two different NI are returned
else {
EV << "NamingInfo contains inconsistency" << endl
<< *entry1 << endl
<< *entry2 << endl;
}
return result;
}
void NamingInformation::parseConfig(cXMLElement* config) {
cXMLElement* mainTag = NULL;
if (config != NULL && config->hasChildren() && config->getFirstChildWithTag(ELEM_NAMINGTABLE))
mainTag = config->getFirstChildWithTag(ELEM_NAMINGTABLE);
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_SYNONYM))) {
EV << "\nError when parsing NaimingInfo record" << endl;
continue;
}
APN newapn = APN(m->getAttribute(ATTR_APN));
addNamingEntry(newapn);
cXMLElementList synonymlist = m->getChildrenByTagName(ELEM_SYNONYM);
for (cXMLElementList::const_iterator jt = synonymlist.begin(); jt != synonymlist.end(); ++jt) {
cXMLElement* n = *jt;
if (!(n->getAttribute(ATTR_APN))) {
EV << "\nError when parsing Synonym record" << endl;
continue;
}
addNewSynonym(newapn, APN(n->getAttribute(ATTR_APN)));
}
}
}