00001
00002
00003 #include "orbsvcs/PortableGroup/UIPMC_Endpoint.h"
00004 #include "orbsvcs/PortableGroup/UIPMC_Profile.h"
00005
00006 #include "tao/debug.h"
00007 #include "ace/Guard_T.h"
00008 #include "tao/ORB_Constants.h"
00009 #include "ace/OS_NS_stdio.h"
00010 #include "ace/OS_NS_string.h"
00011 #include "ace/OS_Memory.h"
00012
00013 ACE_RCSID (tao,
00014 UIPMC_Endpoint,
00015 "UIPMC_Endpoint.cpp,v 1.13 2006/05/23 16:09:34 mitza Exp")
00016
00017
00018 #if !defined (__ACE_INLINE__)
00019 # include "orbsvcs/PortableGroup/UIPMC_Endpoint.i"
00020 #endif
00021
00022 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00023
00024 TAO_UIPMC_Endpoint::TAO_UIPMC_Endpoint (void)
00025 : TAO_Endpoint (IOP::TAG_UIPMC),
00026 object_addr_ (),
00027 next_ (0)
00028 {
00029 }
00030
00031
00032 TAO_UIPMC_Endpoint::TAO_UIPMC_Endpoint (const ACE_INET_Addr &addr)
00033 : TAO_Endpoint (IOP::TAG_UIPMC),
00034 object_addr_ (addr),
00035 next_ (0)
00036 {
00037 this->object_addr (addr);
00038 }
00039
00040 TAO_UIPMC_Endpoint::TAO_UIPMC_Endpoint (const CORBA::Octet class_d_address[4],
00041 CORBA::UShort port)
00042 : TAO_Endpoint (IOP::TAG_UIPMC),
00043 port_ (port),
00044 next_ (0)
00045 {
00046 for (int i = 0; i<4; i++)
00047 this->class_d_address_[i] = class_d_address[i];
00048
00049 this->update_object_addr ();
00050 }
00051
00052
00053 TAO_UIPMC_Endpoint::~TAO_UIPMC_Endpoint (void)
00054 {
00055
00056 }
00057
00058 void
00059 TAO_UIPMC_Endpoint::object_addr (const ACE_INET_Addr &addr)
00060 {
00061 this->port_ = addr.get_port_number();
00062 this->uint_ip_addr (addr.get_ip_address ());
00063
00064 this->object_addr_.set (addr);
00065 }
00066
00067 const char *
00068 TAO_UIPMC_Endpoint::get_host_addr (void) const
00069 {
00070 return this->object_addr_.get_host_addr ();
00071 }
00072
00073
00074 int
00075 TAO_UIPMC_Endpoint::addr_to_string (char *buffer, size_t length)
00076 {
00077 size_t actual_len =
00078 15
00079 + sizeof (':')
00080 + 5
00081 + sizeof ('\0');
00082
00083 if (length < actual_len)
00084 return -1;
00085
00086 ACE_OS::sprintf (buffer, "%d.%d.%d.%d:%d",
00087 this->class_d_address_[0],
00088 this->class_d_address_[1],
00089 this->class_d_address_[2],
00090 this->class_d_address_[3],
00091 this->port_);
00092
00093 return 0;
00094 }
00095
00096 TAO_Endpoint *
00097 TAO_UIPMC_Endpoint::next (void)
00098 {
00099 return this->next_;
00100 }
00101
00102 TAO_Endpoint *
00103 TAO_UIPMC_Endpoint::duplicate (void)
00104 {
00105 TAO_UIPMC_Endpoint *endpoint = 0;
00106
00107 ACE_NEW_RETURN (endpoint,
00108 TAO_UIPMC_Endpoint (this->object_addr_),
00109 0);
00110
00111 return endpoint;
00112 }
00113
00114 CORBA::Boolean
00115 TAO_UIPMC_Endpoint::is_equivalent (const TAO_Endpoint *other_endpoint)
00116 {
00117 TAO_Endpoint *endpt = const_cast<TAO_Endpoint *> (other_endpoint);
00118
00119 TAO_UIPMC_Endpoint *endpoint = dynamic_cast<TAO_UIPMC_Endpoint *> (endpt);
00120 if (endpoint == 0)
00121 return 0;
00122
00123 return
00124 this->port_ == endpoint->port_
00125 && ACE_OS::memcmp (this->class_d_address_, endpoint->class_d_address_, 4) == 0;
00126 }
00127
00128 CORBA::ULong
00129 TAO_UIPMC_Endpoint::hash (void)
00130 {
00131 if (this->hash_val_ != 0)
00132 return this->hash_val_;
00133
00134 {
00135 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00136 guard,
00137 this->addr_lookup_lock_,
00138 this->hash_val_);
00139
00140 if (this->hash_val_ != 0)
00141 return this->hash_val_;
00142
00143 this->hash_val_ =
00144 this->uint_ip_addr () + this->port_;
00145 }
00146
00147 return this->hash_val_;
00148 }
00149
00150 TAO_END_VERSIONED_NAMESPACE_DECL