RINASim  October 2016
Documentation of framework for OMNeT++
Directory.cc
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
23 #include "Directory.h"
24 
25 //Constants
26 const char* ELEM_DIRDATA = "Directory";
27 const char* ELEM_DIF = "DIF";
28 const char* ATTR_IPCADDR = "ipcAddress";
29 const char* ATTR_DIFNAME = "difName";
30 
32 
34  std::ostringstream description;
35  description << Director.size() << " entries";
36  this->getDisplayString().setTagArg("t", 0, description.str().c_str());
37  this->getDisplayString().setTagArg("t", 1, "t");
38 }
39 
41 {
42  //Parse XML config
43  parseConfig(par(PAR_CONFIGDATA).xmlValue());
44 
46  //Init watchers
47  WATCH_LIST(Director);
48 }
49 
51  for(TDirIter it = Director.begin(); it != Director.end(); ++it) {
52  DirectoryEntry entry = *it;
53  if (entry.getApn() == apn)
54  return &(*it);
55  }
56  return NULL;
57 }
58 
59 void Directory::addDirEntry(const APN& apn) {
60  Director.push_back(DirectoryEntry(apn));
61 }
62 
63 std::string Directory::info() const {
64  std::ostringstream os;
65  os << "id=" << this->getId() << endl;
66  return os.str();
67 }
68 
69 void Directory::handleMessage(cMessage *msg)
70 {
71 
72 }
73 
74 void Directory::addNewDif(const APN& apn, const Address& member) {
75  findDirEntryByApn(apn)->addDif(member);
76 }
77 
78 void Directory::removeDirEntry(const APN& apn) {
79  Director.remove(*(findDirEntryByApn(apn)));
80 }
81 
82 void Directory::parseConfig(cXMLElement* config) {
83  cXMLElement* mainTag = NULL;
84  if (config != NULL && config->hasChildren() && config->getFirstChildWithTag(ELEM_DIRDATA))
85  mainTag = config->getFirstChildWithTag(ELEM_DIRDATA);
86  else {
87  EV << "configData parameter not initialized!" << endl;
88  return;
89  }
90 
91  cXMLElementList apnlist = mainTag->getChildrenByTagName(ELEM_APN);
92  for (cXMLElementList::const_iterator it = apnlist.begin(); it != apnlist.end(); ++it) {
93  cXMLElement* m = *it;
94 
95  if (!(m->getAttribute(ATTR_APN) && m->getFirstChildWithTag(ELEM_DIF))) {
96  EV << "\nError when parsing Directory record" << endl;
97  continue;
98  }
99 
100  APN newapn = APN(m->getAttribute(ATTR_APN));
101 
102  addDirEntry(newapn);
103 
104  cXMLElementList diflist = m->getChildrenByTagName(ELEM_DIF);
105  for (cXMLElementList::const_iterator jt = diflist.begin(); jt != diflist.end(); ++jt) {
106  cXMLElement* n = *jt;
107 
108  if (!(n->getAttribute(ATTR_IPCADDR) && n->getAttribute(ATTR_DIFNAME))) {
109  EV << "\nError when parsing DIF record" << endl;
110  continue;
111  }
112 
113  addNewDif(newapn, Address(n->getAttribute(ATTR_IPCADDR), n->getAttribute(ATTR_DIFNAME)));
114  }
115  }
116 
117 }
118 
119 /*
120 void Directory::parseConfig(cXMLElement* config) {
121  cXMLElement* dirXml = NULL;
122  if (config != NULL && config->hasChildren() && config->getFirstChildWithTag(ELEM_DIRDATA))
123  dirXml = config->getFirstChildWithTag(ELEM_DIRDATA);
124  else {
125  EV << "configData parameter not initialized!" << endl;
126  return;
127  }
128 
129  cXMLElementList map = dirXml->getChildrenByTagName(ELEM_DIRMAPPING);
130  cModule* top =
131  this->getModuleByPath("^.^.^");
132  for (cXMLElementList::iterator i = map.begin(); i != map.end(); ++i) {
133  cXMLElement* m = *i;
134 
135  if (!(m->getAttribute(ATTR_APN) && m->getAttribute(ATTR_DIFNAME)
136  && m->getAttribute(ATTR_IPCADDR))) {
137  EV << "\nError when parsing DA-Directory record" << endl
138  << m->getAttribute(ATTR_APN) << "\t"
139  << m->getAttribute(ATTR_IPCADDR) << "\t"
140  << m->getAttribute(ATTR_DIFNAME) << endl;
141  continue;
142  }
143 
144  for (cModule::SubmoduleIterator k(top); !k.end(); k++) {
145  //EV << k()->getFullPath() << endl;
146 
147  cModule* submodp = NULL;
148  for (cModule::SubmoduleIterator j(k()); !j.end(); j++) {
149  //EV << j()->getFullPath() << endl;
150 
151  submodp = j();
152 
153  if (submodp->hasPar(ATTR_IPCADDR)
154  && submodp->hasPar(ATTR_DIFNAME)
155  && !opp_strcmp(submodp->par(ATTR_IPCADDR).stringValue(),
156  m->getAttribute(ATTR_IPCADDR))
157  && !opp_strcmp(submodp->par(ATTR_DIFNAME).stringValue(),
158  m->getAttribute(ATTR_DIFNAME)))
159  break;
160  else
161  submodp = NULL;
162  }
163 
164  //Appropriate IPCProcess found in simulation topology
165  if (submodp) {
166  //EV << "!!!!!OK" << endl;
167  this->addDirEntry(
168  DirectoryEntry(
169  APNamingInfo(APN(m->getAttribute(ATTR_APN))),
170  Address(m->getAttribute(ATTR_IPCADDR),
171  m->getAttribute(ATTR_DIFNAME)),
172  submodp->getFullPath(),
173  dynamic_cast<FABase*>(submodp->getSubmodule(
174  MOD_FLOWALLOC)->getSubmodule(MOD_FA))));
175  }
176  }
177 
178  }
179 }
180 
181 */
std::string info() const
Definition: Directory.cc:63
const char * ATTR_IPCADDR
Definition: Directory.cc:28
Application Process Name class.
Definition: APN.h:36
void addDif(const Address &member)
const char * ELEM_APN
virtual void initialize()
Definition: Directory.cc:40
DirectoryEntry * findDirEntryByApn(const APN &apn)
Definition: Directory.cc:50
const char * PAR_CONFIGDATA
const char * ATTR_APN
TDirectory::iterator TDirIter
Definition: Directory.h:33
void addDirEntry(const APN &apn)
Definition: Directory.cc:59
Define_Module(Directory)
void addNewDif(const APN &apn, const Address &member)
Definition: Directory.cc:74
const char * ELEM_DIRDATA
Definition: Directory.cc:26
const APN & getApn() const
const char * ATTR_DIFNAME
Definition: Directory.cc:29
virtual void handleMessage(cMessage *msg)
Definition: Directory.cc:69
void removeDirEntry(const APN &apn)
Definition: Directory.cc:78
TDirectory Director
Definition: Directory.h:52
Address class holds IPC Process identification.
Definition: Address.h:42
const char * ELEM_DIF
Definition: Directory.cc:27
void updateDisplayString()
Definition: Directory.cc:33
void parseConfig(cXMLElement *config)
Definition: Directory.cc:82