Go to the documentation of this file.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 "$Id: UIPMC_Endpoint.cpp 79015 2007-07-24 15:03:04Z vridosh $")
00016
00017
00018 #if !defined (__ACE_INLINE__)
00019 # include "orbsvcs/PortableGroup/UIPMC_Endpoint.inl"
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 host_ (),
00027 port_ (0),
00028 object_addr_ (),
00029 next_ (0)
00030 {
00031 }
00032
00033 TAO_UIPMC_Endpoint::TAO_UIPMC_Endpoint (const ACE_INET_Addr &addr)
00034 : TAO_Endpoint (IOP::TAG_UIPMC),
00035 host_ (),
00036 port_ (0),
00037 object_addr_ (addr),
00038 next_ (0)
00039 {
00040 this->object_addr (addr);
00041 }
00042
00043
00044 TAO_UIPMC_Endpoint::TAO_UIPMC_Endpoint (const CORBA::Octet class_d_address[4],
00045 CORBA::UShort port)
00046 : TAO_Endpoint (IOP::TAG_UIPMC),
00047 port_ (port),
00048 next_ (0)
00049 {
00050 for (int i = 0; i<4; i++)
00051 this->class_d_address_[i] = class_d_address[i];
00052
00053 this->update_object_addr ();
00054 }
00055
00056 TAO_UIPMC_Endpoint::~TAO_UIPMC_Endpoint (void)
00057 {
00058 }
00059
00060 void
00061 TAO_UIPMC_Endpoint::object_addr (const ACE_INET_Addr &addr)
00062 {
00063 this->port_ = addr.get_port_number();
00064 this->host_ = CORBA::string_dup (addr.get_host_addr ());
00065
00066 this->object_addr_.set (addr);
00067 }
00068
00069 const char *
00070 TAO_UIPMC_Endpoint::host (void) const
00071 {
00072 return this->host_.in ();
00073 }
00074
00075 int
00076 TAO_UIPMC_Endpoint::addr_to_string (char *buffer, size_t length)
00077 {
00078 size_t actual_len =
00079 ACE_OS::strlen (this->object_addr_.get_host_addr ())
00080 + sizeof (':')
00081 + 5
00082 + sizeof ('\0');
00083
00084 #if defined (ACE_HAS_IPV6)
00085 if (this->object_addr_.get_type () == AF_INET6)
00086 actual_len += 2;
00087 #endif
00088
00089 if (length < actual_len)
00090 return -1;
00091
00092 #if defined (ACE_HAS_IPV6)
00093 if (this->object_addr_.get_type () == AF_INET6)
00094 ACE_OS::sprintf (buffer, "[%s]:%d",
00095 this->object_addr_.get_host_addr (),
00096 this->port_);
00097 else
00098 #endif
00099 ACE_OS::sprintf (buffer, "%s:%d",
00100 this->object_addr_.get_host_addr (),
00101 this->port_);
00102
00103 return 0;
00104 }
00105
00106 TAO_Endpoint *
00107 TAO_UIPMC_Endpoint::next (void)
00108 {
00109 return this->next_;
00110 }
00111
00112 TAO_Endpoint *
00113 TAO_UIPMC_Endpoint::duplicate (void)
00114 {
00115 TAO_UIPMC_Endpoint *endpoint = 0;
00116
00117 ACE_NEW_RETURN (endpoint,
00118 TAO_UIPMC_Endpoint (this->object_addr_),
00119 0);
00120
00121 return endpoint;
00122 }
00123
00124 CORBA::Boolean
00125 TAO_UIPMC_Endpoint::is_equivalent (const TAO_Endpoint *other_endpoint)
00126 {
00127 const TAO_UIPMC_Endpoint *endpoint =
00128 dynamic_cast<const TAO_UIPMC_Endpoint *> (other_endpoint);
00129
00130 if (endpoint == 0)
00131 return 0;
00132
00133 return
00134 (this->port_ == endpoint->port_
00135 && ACE_OS::strcmp (this->host (), endpoint->host ()) == 0);
00136 }
00137
00138 CORBA::ULong
00139 TAO_UIPMC_Endpoint::hash (void)
00140 {
00141 if (this->hash_val_ != 0)
00142 return this->hash_val_;
00143
00144 {
00145 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00146 guard,
00147 this->addr_lookup_lock_,
00148 this->hash_val_);
00149
00150 if (this->hash_val_ != 0)
00151 return this->hash_val_;
00152
00153 this->hash_val_ = this->object_addr_.hash ();
00154 }
00155
00156 return this->hash_val_;
00157 }
00158
00159 TAO_END_VERSIONED_NAMESPACE_DECL