00001 // Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH) 00002 // 00003 // This program is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU General Public License 00005 // as published by the Free Software Foundation; either version 2 00006 // of the License, or (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00016 // 00017 00023 #ifndef COORDINATESYSTEM_H_ 00024 #define COORDINATESYSTEM_H_ 00025 00026 #include <stdint.h> 00027 #include <vector> 00028 00029 #include <omnetpp.h> 00030 00031 class Prox; 00032 class NeighborCache; 00033 class BaseCallMessage; 00034 00035 00036 class AbstractNcsNodeInfo 00037 { 00038 public: 00039 virtual ~AbstractNcsNodeInfo() {}; 00040 virtual bool isValid() = 0; 00041 virtual Prox getDistance(const AbstractNcsNodeInfo& node) const = 0; 00042 virtual bool update(const AbstractNcsNodeInfo& info) = 0; 00043 00044 virtual operator std::vector<double>() const = 0; 00045 }; 00046 00047 class EuclideanNcsNodeInfo : public AbstractNcsNodeInfo 00048 { 00049 public: 00050 EuclideanNcsNodeInfo() { coordinates.resize(dim); }; 00051 virtual ~EuclideanNcsNodeInfo() { }; 00052 00053 uint8_t getDimension() const { return coordinates.size(); }; 00054 static void setDimension(uint8_t dimension) { dim = dimension; }; 00055 00056 double getCoords(uint8_t i) const { 00057 if (i >= coordinates.size()) { 00058 throw cRuntimeError("too high value for dim!"); 00059 } 00060 return coordinates[i]; 00061 }; 00062 00063 const std::vector<double>& getCoords() const { return coordinates; }; 00064 00065 void setCoords(uint8_t i, double value) { 00066 if (i >= coordinates.size()) { 00067 throw cRuntimeError("coordinates too small"); 00068 } 00069 coordinates[i] = value; 00070 }; 00071 00072 protected: 00073 std::vector<double> coordinates; 00074 static uint8_t dim; 00075 }; 00076 00077 class GnpNpsCoordsInfo : public EuclideanNcsNodeInfo 00078 { 00079 public: 00080 GnpNpsCoordsInfo() { npsLayer = -1; }; 00081 00082 bool isValid() { return npsLayer != -1; }; 00083 00084 int8_t getLayer() const { return npsLayer; }; 00085 void setLayer(int8_t layer) { npsLayer = layer; }; 00086 Prox getDistance(const AbstractNcsNodeInfo& abstractInfo) const; 00087 bool update(const AbstractNcsNodeInfo& abstractInfo); 00088 00089 operator std::vector<double>() const; 00090 00091 protected: 00092 int8_t npsLayer; 00093 }; 00094 00095 std::ostream& operator<<(std::ostream& os, const GnpNpsCoordsInfo& info); 00096 00097 class VivaldiCoordsInfo : public EuclideanNcsNodeInfo 00098 { 00099 public: 00100 VivaldiCoordsInfo(bool useHeightVector = false) { 00101 coordErr = 1.0; 00102 heightVector = (useHeightVector ? 0 : -1.0); 00103 }; 00104 00105 bool isValid() { return coordErr >= 0.0 && coordErr < 1.0; }; 00106 00107 double getError() const { return coordErr; }; 00108 void setError(double err) { 00109 coordErr = ((err > 1.0) ? 1.0 : ((err < 0.0) ? 0.0 : coordErr = err)); 00110 }; 00111 00112 double getHeightVector() const { return heightVector; }; 00113 void setHeightVector(double height) { 00114 heightVector = ((height > 0.0) ? height : 0.0); 00115 }; 00116 00117 Prox getDistance(const AbstractNcsNodeInfo& node) const; 00118 bool update(const AbstractNcsNodeInfo& info); 00119 operator std::vector<double>() const ; 00120 00121 protected: 00122 double coordErr; 00123 double heightVector; 00124 }; 00125 00126 std::ostream& operator<<(std::ostream& os, const VivaldiCoordsInfo& info); 00127 00128 class AbstractNcs { 00129 public: 00130 virtual ~AbstractNcs() { }; 00131 00132 virtual void init(NeighborCache* neighorCache) = 0; 00133 00134 virtual bool isAdapting() = 0; 00135 00136 virtual AbstractNcsNodeInfo* getUnvalidNcsInfo() const = 0; 00137 00138 virtual Prox getCoordinateBasedProx(const AbstractNcsNodeInfo& node) const = 0; 00139 virtual void processCoordinates(const simtime_t& rtt, 00140 const AbstractNcsNodeInfo& nodeInfo) { }; 00141 00142 virtual const AbstractNcsNodeInfo& getOwnNcsInfo() const = 0; 00143 virtual AbstractNcsNodeInfo* createNcsInfo(const std::vector<double>& coords) const = 0; 00144 00145 virtual void handleTimerEvent(cMessage* msg) { }; 00146 virtual bool handleRpcCall(BaseCallMessage* msg) { return false; }; 00147 }; 00148 00149 #endif /* COORDINATESYSTEM_H_ */