BrooseHandle.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 
00024 #include <omnetpp.h>
00025 
00026 #include <IPAddress.h>
00027 
00028 #include "BrooseHandle.h"
00029 
00030 std::ostream& operator<<(std::ostream& os, const BrooseHandle& n)
00031 {
00032     if (n.isUnspecified()) {
00033         os << "<unspec>";
00034     } else {
00035         os << n.getAddress() << ":" << n.getPort() << " " << n.getKey() << " last-seen: " << n.lastSeen
00036            << " failedResponses: " << n.failedResponses << " rtt: " << n.rtt;
00037     }
00038 
00039     return os;
00040 };
00041 
00042 BrooseHandle::BrooseHandle()
00043 {
00044     //
00045     // Default-constructor.
00046     //
00047     port = -1;
00048     key = OverlayKey::UNSPECIFIED_KEY;
00049     failedResponses = 0;
00050     rtt = -1;
00051     lastSeen = -1;
00052 }
00053 
00054 BrooseHandle::BrooseHandle(OverlayKey initKey, IPvXAddress initIP, int initPort)
00055 {
00056     //
00057     // Constructor. Initializes the node handle with the passed arguments.
00058     //
00059     ip = initIP;
00060     port = initPort;
00061     key = initKey;
00062     failedResponses = 0;
00063     rtt = -1;
00064     lastSeen = -1;
00065 }
00066 
00067 BrooseHandle::BrooseHandle(const NodeHandle& node)
00068 {
00069     //
00070     // Constructor. Initializes the node handle with the passed arguments.
00071     //
00072     ip = node.getAddress();
00073     port = node.getPort();
00074     key = node.getKey();
00075     failedResponses = 0;
00076     rtt = -1;
00077     lastSeen = -1;
00078 }
00079 
00080 
00081 BrooseHandle::BrooseHandle(const TransportAddress& node, const OverlayKey& destKey)
00082 {
00083     //
00084     // Constructor. Initializes the node handle with the passed arguments.
00085     //
00086     ip = node.getAddress();
00087     port = node.getPort();
00088     key = destKey;
00089     rtt = -1;
00090     lastSeen = -1;
00091 }
00092 
00093 BrooseHandle& BrooseHandle::operator=(const BrooseHandle& rhs)
00094 {
00095 
00096     this->key = rhs.getKey();
00097     this->ip = rhs.getAddress();
00098     this->port = rhs.getPort();
00099     this->failedResponses = rhs.failedResponses;
00100     this->rtt = rhs.rtt;
00101     this->lastSeen = rhs.lastSeen;
00102     return *this;
00103 }
00104 
00105 bool BrooseHandle::operator==(const BrooseHandle& rhs) const
00106 {
00107     if(this->isUnspecified() || rhs.isUnspecified())
00108         opp_error("BrooseHandle: Trying to compare unspecified nodeHandle!");
00109 
00110     if( this->key != rhs.getKey() )
00111         return false;
00112     if( this->ip != rhs.getAddress() )
00113         return false;
00114     if( this->port != rhs.getPort() )
00115         return false;
00116     return true;
00117 }
00118 
00119 bool BrooseHandle::operator!=(const BrooseHandle& rhs) const
00120 {
00121     if(this->isUnspecified() || rhs.isUnspecified())
00122         opp_error("BrooseHandle: Trying to compare unspecified nodeHandle!");
00123 
00124     if ( this->key == rhs.getKey() &&
00125          this->ip == rhs.getAddress() && this->port == rhs.getPort())
00126         return false;
00127     return true;
00128 }
00129 
Generated on Wed May 26 16:21:13 2010 for OverSim by  doxygen 1.6.3