NodeHandle.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00025 #include "NodeHandle.h"
00026 
00027 // predefined node handle
00028 const NodeHandle NodeHandle::UNSPECIFIED_NODE;
00029 
00030 std::ostream& operator<<(std::ostream& os, const NodeHandle& n)
00031 {
00032     if (n.ip.isUnspecified()) {
00033         os << "<addr unspec> ";
00034     } else {
00035         os << n.ip << ":" << n.port << " ";
00036     }
00037 
00038     if (n.key.isUnspecified()) {
00039         os << "<key unspec>";
00040     } else {
00041         os << n.key;
00042     }
00043 
00044     return os;
00045 };
00046 
00047 
00048 //default-constructor
00049 NodeHandle::NodeHandle()
00050 {
00051     port = -1;
00052     key = OverlayKey(); // unspecified key, note: OverlayKey::UNSPECIFIED_KEY might not be initialized here
00053 }
00054 
00055 //copy constructor
00056 NodeHandle::NodeHandle( const NodeHandle& handle )
00057 {
00058     key = handle.key;
00059     port = handle.port;
00060     ip = handle.ip;
00061 }
00062 
00063 NodeHandle::NodeHandle( const TransportAddress& ta )
00064 {
00065     this->setAddress(ta.getAddress());
00066     this->setPort(ta.getPort());
00067     this->setKey(OverlayKey::UNSPECIFIED_KEY);
00068 }
00069 
00070 //complete constructor
00071 NodeHandle::NodeHandle( const OverlayKey& key,
00072                               const IPvXAddress& ip, int port )
00073 {
00074     this->setAddress(ip);
00075     this->setPort(port);
00076     this->setKey(key);
00077 }
00078 
00079 NodeHandle::NodeHandle( const OverlayKey& key, const TransportAddress& ta )
00080 {
00081     this->setAddress(ta.getAddress());
00082     this->setPort(ta.getPort());
00083     this->setKey(key);
00084 }
00085 
00086 //public
00087 bool NodeHandle::isUnspecified() const
00088 {
00089     return (ip.isUnspecified() || key.isUnspecified());
00090 }
00091 
00092 //public
00093 NodeHandle& NodeHandle::operator=(const NodeHandle& rhs)
00094 {
00095     this->key = rhs.key;
00096     this->ip = rhs.ip;
00097     this->port = rhs.port;
00098 
00099     return *this;
00100 }
00101 
00102 //public
00103 bool NodeHandle::operator==(const NodeHandle& rhs) const
00104 {
00105     assertUnspecified( rhs );
00106     return ( this->key == rhs.key &&
00107              this->ip == rhs.ip && this->port == rhs.port );
00108 }
00109 
00110 //public
00111 bool NodeHandle::operator!=(const NodeHandle& rhs) const
00112 {
00113     assertUnspecified( rhs );
00114     return !( this->key == rhs.key &&
00115               this->ip == rhs.ip && this->port == rhs.port );
00116 }
00117 
00118 //public
00119 bool NodeHandle::operator<(const NodeHandle &rhs) const
00120 {
00121     assertUnspecified(rhs);
00122     return this->key < rhs.key;
00123 }
00124 
00125 //public
00126 bool NodeHandle::operator>(const NodeHandle &rhs) const
00127 {
00128     assertUnspecified(rhs);
00129     return this->key > rhs.key;
00130 }
00131 
00132 //public
00133 bool NodeHandle::operator<=(const NodeHandle &rhs) const
00134 {
00135     assertUnspecified(rhs);
00136     return this->key <= rhs.key;
00137 }
00138 
00139 //public
00140 bool NodeHandle::operator>=(const NodeHandle &rhs) const
00141 {
00142     assertUnspecified(rhs);
00143     return this->key >= rhs.key;
00144 }
00145 
00146 //public
00147 void NodeHandle::setKey( const OverlayKey& key )
00148 {
00149     this->key = key;
00150 }
00151 
00152 //public
00153 const OverlayKey& NodeHandle::getKey() const
00154 {
00155     return key;
00156 }
00157 
00158 
00159 //private
00160 inline void NodeHandle::assertUnspecified( const NodeHandle& handle ) const
00161 {
00162     if ( this->isUnspecified() || handle.isUnspecified() )
00163         opp_error("NodeHandle: Trying to compare unspecified NodeHandle!");
00164 }
00165 
00166 
00167 void NodeHandle::netPack(cCommBuffer *b)
00168 {
00169     //cMessage::netPack(b);
00170     doPacking(b,this->ip);
00171     doPacking(b,this->key);
00172     doPacking(b,this->port);
00173 }
00174 
00175 void NodeHandle::netUnpack(cCommBuffer *b)
00176 {
00177     //cMessage::netUnpack(b);
00178     doUnpacking(b,this->ip);
00179     doUnpacking(b,this->key);
00180     doUnpacking(b,this->port);
00181 }
00182 
00183 TransportAddress* NodeHandle::dup() const
00184 {
00185     return new NodeHandle(*this);
00186 }

Generated on Tue Sep 8 17:26:53 2009 for OverSim by  doxygen 1.5.8