00001
00002
00003 #include "tao/Strategies/SHMIOP_Endpoint.h"
00004
00005 #if defined (TAO_HAS_SHMIOP) && (TAO_HAS_SHMIOP != 0)
00006
00007 #include "tao/Strategies/SHMIOP_Connection_Handler.h"
00008 #include "tao/debug.h"
00009 #include "tao/ORB_Constants.h"
00010
00011 #include "ace/OS_NS_stdio.h"
00012
00013
00014 ACE_RCSID (Strategies,
00015 SHMIOP_Endpoint,
00016 "$Id: SHMIOP_Endpoint.cpp 73791 2006-07-27 20:54:56Z wotte $")
00017
00018
00019 #if !defined (__ACE_INLINE__)
00020 # include "tao/Strategies/SHMIOP_Endpoint.inl"
00021 #endif
00022
00023 #include "ace/os_include/os_netdb.h"
00024
00025 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00026
00027 TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const ACE_MEM_Addr &addr,
00028 int use_dotted_decimal_addresses)
00029 : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE)
00030 , host_ ()
00031 , port_ (0)
00032 , object_addr_ (addr.get_remote_addr ())
00033 , object_addr_set_ (0)
00034 , next_ (0)
00035 {
00036 this->set (addr.get_remote_addr (), use_dotted_decimal_addresses);
00037 }
00038
00039 TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const ACE_INET_Addr &addr,
00040 int use_dotted_decimal_addresses)
00041 : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE)
00042 , host_ ()
00043 , port_ (0)
00044 , object_addr_ (addr)
00045 , object_addr_set_ (0)
00046 , next_ (0)
00047 {
00048 this->set (addr, use_dotted_decimal_addresses);
00049 }
00050
00051 TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const char *host,
00052 CORBA::UShort port,
00053 const ACE_INET_Addr &addr,
00054 CORBA::Short priority)
00055 : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE, priority)
00056 , host_ ()
00057 , port_ (port)
00058 , object_addr_ (addr)
00059 , object_addr_set_ (0)
00060 , next_ (0)
00061 {
00062 if (host != 0)
00063 this->host_ = host;
00064 }
00065
00066 TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (void)
00067 : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE)
00068 , host_ ()
00069 , port_ (0)
00070 , object_addr_ ()
00071 , object_addr_set_ (0)
00072 , next_ (0)
00073 {
00074 }
00075
00076 TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const char *host,
00077 CORBA::UShort port,
00078 CORBA::Short priority)
00079 : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE)
00080 , host_ ()
00081 , port_ (port)
00082 , object_addr_ ()
00083 , object_addr_set_ (0)
00084 , next_ (0)
00085 {
00086 if (host != 0)
00087 this->host_ = host;
00088
00089 this->priority (priority);
00090 }
00091
00092 TAO_SHMIOP_Endpoint::~TAO_SHMIOP_Endpoint (void)
00093 {
00094 }
00095
00096 int
00097 TAO_SHMIOP_Endpoint::set (const ACE_INET_Addr &addr,
00098 int use_dotted_decimal_addresses)
00099 {
00100 char tmp_host[MAXHOSTNAMELEN + 1];
00101
00102 if (use_dotted_decimal_addresses
00103 || addr.get_host_name (tmp_host, sizeof (tmp_host)) != 0)
00104 {
00105 if (use_dotted_decimal_addresses == 0 && TAO_debug_level > 5)
00106 {
00107 ACE_DEBUG ((LM_DEBUG,
00108 ACE_TEXT ("TAO (%P|%t) - SHMIOP_Endpoint::set, ")
00109 ACE_TEXT ("- %p cannot determine hostname\n")));
00110 }
00111
00112 const char *tmp = addr.get_host_addr ();
00113 if (tmp == 0)
00114 {
00115 if (TAO_debug_level > 0)
00116 ACE_DEBUG ((LM_DEBUG,
00117 ACE_TEXT ("TAO (%P|%t) - ")
00118 ACE_TEXT ("SHMIOP_Endpoint::set ")
00119 ACE_TEXT ("- %p\n"),
00120 ACE_TEXT ("cannot determine hostname")));
00121 return -1;
00122 }
00123 else
00124 this->host_ = tmp;
00125 }
00126 else
00127 this->host_ = CORBA::string_dup (tmp_host);
00128
00129 this->port_ = addr.get_port_number();
00130
00131 return 0;
00132 }
00133
00134 int
00135 TAO_SHMIOP_Endpoint::addr_to_string (char *buffer, size_t length)
00136 {
00137 size_t actual_len =
00138 ACE_OS::strlen (this->host_.in ())
00139 + sizeof (':')
00140 + ACE_OS::strlen ("65536")
00141 + sizeof ('\0');
00142
00143 if (length < actual_len)
00144 return -1;
00145
00146 ACE_OS::sprintf (buffer, "%s:%d",
00147 this->host_.in (), this->port_);
00148
00149 return 0;
00150 }
00151
00152 const char *
00153 TAO_SHMIOP_Endpoint::host (const char *h)
00154 {
00155 this->host_ = h;
00156
00157 return this->host_.in ();
00158 }
00159
00160 TAO_Endpoint *
00161 TAO_SHMIOP_Endpoint::next (void)
00162 {
00163 return this->next_;
00164 }
00165
00166 TAO_Endpoint *
00167 TAO_SHMIOP_Endpoint::duplicate (void)
00168 {
00169 TAO_SHMIOP_Endpoint *endpoint = 0;
00170 ACE_NEW_RETURN (endpoint,
00171 TAO_SHMIOP_Endpoint (this->host_.in (),
00172 this->port_,
00173 this->object_addr_,
00174 this->priority ()),
00175 0);
00176
00177 return endpoint;
00178 }
00179
00180
00181 CORBA::Boolean
00182 TAO_SHMIOP_Endpoint::is_equivalent (const TAO_Endpoint *other_endpoint)
00183 {
00184 const TAO_SHMIOP_Endpoint *endpoint = dynamic_cast <const TAO_SHMIOP_Endpoint *>
00185 (other_endpoint);
00186
00187 if (endpoint == 0)
00188 return 0;
00189
00190 return
00191 this->port_ == endpoint->port_
00192 && ACE_OS::strcmp (this->host_.in (), endpoint->host_.in ()) == 0;
00193 }
00194
00195 CORBA::ULong
00196 TAO_SHMIOP_Endpoint::hash (void)
00197 {
00198 if (this->hash_val_ != 0)
00199 return this->hash_val_;
00200
00201 {
00202 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00203 guard,
00204 this->addr_lookup_lock_,
00205 this->hash_val_);
00206
00207 if (this->hash_val_ != 0)
00208 return this->hash_val_;
00209
00210 this->hash_val_ =
00211 ACE::hash_pjw (this->host ()) + this->port ();
00212 }
00213
00214 return this->hash_val_;
00215 }
00216
00217 const ACE_INET_Addr &
00218 TAO_SHMIOP_Endpoint::object_addr (void) const
00219 {
00220
00221
00222
00223
00224
00225
00226
00227 if (!this->object_addr_set_)
00228 {
00229
00230
00231 TAO_SHMIOP_Endpoint *endpoint =
00232 const_cast <TAO_SHMIOP_Endpoint *>(this);
00233
00234 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00235 guard,
00236 endpoint->addr_lookup_lock_,
00237 this->object_addr_ );
00238
00239 if (!this->object_addr_set_)
00240 {
00241 if (endpoint->object_addr_.set (this->port_,
00242 this->host_.in ()) == -1)
00243 {
00244
00245
00246
00247
00248
00249
00250
00251
00252 endpoint->object_addr_.set_type (-1);
00253 }
00254 else
00255 {
00256 endpoint->object_addr_set_ = 1;
00257 }
00258 }
00259 }
00260
00261 return this->object_addr_;
00262 }
00263
00264 TAO_END_VERSIONED_NAMESPACE_DECL
00265
00266 #endif