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.isUnspecified()) {
00033         os << "<unspec>";
00034     } else {
00035         os << n.ip << ":" << n.port << " " << n.key;
00036     }
00037 
00038     return os;
00039 };
00040 
00041 
00042 //default-constructor
00043 NodeHandle::NodeHandle()
00044 {
00045     port = -1;
00046     key = OverlayKey(); // unspecified key, note: OverlayKey::UNSPECIFIED_KEY might not be initialized here
00047 }
00048 
00049 //copy constructor
00050 NodeHandle::NodeHandle( const NodeHandle& handle )
00051 {
00052     key = handle.key;
00053     port = handle.port;
00054     ip = handle.ip;
00055 }
00056 
00057 NodeHandle::NodeHandle( const TransportAddress& ta )
00058 {
00059     this->ip = ta.ip;
00060     this->port = ta.port;
00061     this->key = OverlayKey::UNSPECIFIED_KEY;
00062 }
00063 
00064 //complete constructor
00065 NodeHandle::NodeHandle( const OverlayKey& key,
00066                               const IPvXAddress& ip, int port )
00067 {
00068     this->ip = ip;
00069     this->port = port;
00070     this->key = key;
00071 }
00072 
00073 //public
00074 bool NodeHandle::isUnspecified() const
00075 {
00076     return (ip.isUnspecified() || key.isUnspecified());
00077 }
00078 
00079 //public
00080 NodeHandle& NodeHandle::operator=(const NodeHandle& rhs)
00081 {
00082     this->key = rhs.key;
00083     this->ip = rhs.ip;
00084     this->port = rhs.port;
00085 
00086     return *this;
00087 }
00088 
00089 //public
00090 bool NodeHandle::operator==(const NodeHandle& rhs) const
00091 {
00092     assertUnspecified( rhs );
00093     return ( this->key == rhs.key &&
00094              this->ip == rhs.ip && this->port == rhs.port );
00095 }
00096 
00097 //public
00098 bool NodeHandle::operator!=(const NodeHandle& rhs) const
00099 {
00100     assertUnspecified( rhs );
00101     return !( this->key == rhs.key &&
00102               this->ip == rhs.ip && this->port == rhs.port );
00103 }
00104 
00105 //public
00106 bool NodeHandle::operator<(const NodeHandle &rhs) const
00107 {
00108     assertUnspecified(rhs);
00109     return this->key < rhs.key;
00110 }
00111 
00112 //public
00113 bool NodeHandle::operator>(const NodeHandle &rhs) const
00114 {
00115     assertUnspecified(rhs);
00116     return this->key > rhs.key;
00117 }
00118 
00119 //public
00120 bool NodeHandle::operator<=(const NodeHandle &rhs) const
00121 {
00122     assertUnspecified(rhs);
00123     return this->key <= rhs.key;
00124 }
00125 
00126 //public
00127 bool NodeHandle::operator>=(const NodeHandle &rhs) const
00128 {
00129     assertUnspecified(rhs);
00130     return this->key >= rhs.key;
00131 }
00132 
00133 //public
00134 void NodeHandle::setKey( const OverlayKey& key )
00135 {
00136     this->key = key;
00137 }
00138 
00139 //public
00140 const OverlayKey& NodeHandle::getKey() const
00141 {
00142     return key;
00143 }
00144 
00145 
00146 //private
00147 inline void NodeHandle::assertUnspecified( const NodeHandle& handle ) const
00148 {
00149     if ( this->isUnspecified() || handle.isUnspecified() )
00150         opp_error("NodeHandle: Trying to compare unspecified NodeHandle!");
00151 }
00152 
00153 
00154 void NodeHandle::netPack(cCommBuffer *b)
00155 {
00156     //cMessage::netPack(b);
00157     doPacking(b,this->ip);
00158     doPacking(b,this->key);
00159     doPacking(b,this->port);
00160 }
00161 
00162 void NodeHandle::netUnpack(cCommBuffer *b)
00163 {
00164     //cMessage::netUnpack(b);
00165     doUnpacking(b,this->ip);
00166     doUnpacking(b,this->key);
00167     doUnpacking(b,this->port);
00168 }
00169 
00170 TransportAddress* NodeHandle::dup() const
00171 {
00172     return new NodeHandle(*this);
00173 }

Generated on Wed Mar 25 16:32:49 2009 for OverSim by  doxygen 1.5.5