OverSim
SimpleUnderlayNCS.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2010 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #include "SimpleUnderlayNCS.h"
25 
26 #include <GlobalNodeListAccess.h>
27 #include <OverlayAccess.h>
28 #include <SimpleNodeEntry.h>
29 #include <SimpleInfo.h>
30 
31 
32 
33 
35  this->neighborCache = neighorCache;
36  SimpleUnderlayCoordsInfo::setDimension(2); //todo set value by parameter
37 
38  PeerInfo* peerInfo =
40  getThisNode().getIp());
41 
42  if(peerInfo == NULL) {
43  throw cRuntimeError("No PeerInfo Found");
44  }
45 
46  SimpleNodeEntry* entry = dynamic_cast<SimpleInfo*>(peerInfo)->getEntry();
47 
49  for (uint8_t i = 0; i < entry->getDim(); i++) {
50  ownCoords->setCoords(i, entry->getCoords(i));
51  }
52 }
53 
54 AbstractNcsNodeInfo* SimpleUnderlayNCS::createNcsInfo(const std::vector<double>& fakeCoords) const {
55 
56  //std::stringstream tempStr;
57 
58  PeerInfo* peerInfo =
60  getThisNode().getIp());
61 
62  if(peerInfo == NULL) {
63  throw cRuntimeError("No PeerInfo Found");
64  }
65 
66  SimpleNodeEntry* entry = dynamic_cast<SimpleInfo*>(peerInfo)->getEntry();
67 
69  for (uint8_t i = 0; i < entry->getDim(); i++) {
70  info->setCoords(i, entry->getCoords(i));
71  }
72 
73  return info;
74 }
75 
77 {
78  return new SimpleUnderlayCoordsInfo();
79 }
80 
82 
83  //return *createNcsInfo(*new std::vector<double>);
84  return *ownCoords;
85 }
86 
88  //createNcsInfo(*new std::vector<double>);
89  return ownCoords->getDistance(abstractInfo);
90 }