00001
00002
00003
00004 #include "tao/Strategies/DIOP_Connector.h"
00005
00006 #if defined (TAO_HAS_DIOP) && (TAO_HAS_DIOP != 0)
00007
00008 #include "ace/Connector.h"
00009
00010 #include "tao/debug.h"
00011 #include "tao/ORB_Core.h"
00012 #include "tao/Environment.h"
00013 #include "tao/Base_Transport_Property.h"
00014 #include "tao/Protocols_Hooks.h"
00015 #include "ace/OS_NS_strings.h"
00016 #include "ace/OS_NS_string.h"
00017
00018 #include "tao/Strategies/DIOP_Profile.h"
00019
00020
00021 ACE_RCSID (Strategies,
00022 DIOP_Connector,
00023 "DIOP_Connector.cpp,v 1.30 2006/05/24 09:12:03 jwillemsen Exp")
00024
00025
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027
00028 TAO_DIOP_Connector::TAO_DIOP_Connector (CORBA::Boolean flag)
00029 : TAO_Connector (TAO_TAG_DIOP_PROFILE),
00030 lite_flag_ (flag)
00031 {
00032 }
00033
00034 TAO_DIOP_Connector::~TAO_DIOP_Connector (void)
00035 {
00036 }
00037
00038 int
00039 TAO_DIOP_Connector::open (TAO_ORB_Core *orb_core)
00040 {
00041 this->orb_core (orb_core);
00042
00043
00044 if (this->create_connect_strategy () == -1)
00045 return -1;
00046
00047
00048
00049 return 0;
00050 }
00051
00052 int
00053 TAO_DIOP_Connector::close (void)
00054 {
00055
00056 SvcHandlerIterator iter (svc_handler_table_);
00057
00058 while (!iter.done ())
00059 {
00060 (*iter).int_id_->remove_reference ();
00061 iter++;
00062 }
00063
00064
00065 return 0;
00066 }
00067
00068 int
00069 TAO_DIOP_Connector::set_validate_endpoint (TAO_Endpoint *endpoint)
00070 {
00071 TAO_DIOP_Endpoint *diop_endpoint =
00072 this->remote_endpoint (endpoint);
00073
00074 if (diop_endpoint == 0)
00075 return -1;
00076
00077 const ACE_INET_Addr &remote_address =
00078 diop_endpoint->object_addr ();
00079
00080
00081
00082
00083 if (remote_address.get_type () != AF_INET)
00084 {
00085 if (TAO_debug_level > 0)
00086 {
00087 ACE_DEBUG ((LM_DEBUG,
00088 ACE_TEXT ("TAO (%P|%t) DIOP connection failed.\n")
00089 ACE_TEXT ("TAO (%P|%t) This is most likely ")
00090 ACE_TEXT ("due to a hostname lookup ")
00091 ACE_TEXT ("failure.\n")));
00092 }
00093
00094 return -1;
00095 }
00096
00097 return 0;
00098 }
00099
00100 TAO_Transport *
00101 TAO_DIOP_Connector::make_connection (TAO::Profile_Transport_Resolver *,
00102 TAO_Transport_Descriptor_Interface &desc,
00103 ACE_Time_Value * )
00104 {
00105 TAO_DIOP_Endpoint *diop_endpoint =
00106 this->remote_endpoint (desc.endpoint ());
00107
00108 if (diop_endpoint == 0)
00109 return 0;
00110
00111 const ACE_INET_Addr &remote_address =
00112 diop_endpoint->object_addr ();
00113
00114 TAO_DIOP_Connection_Handler *svc_handler = 0;
00115
00116 if (svc_handler_table_.find (remote_address, svc_handler) == -1)
00117 {
00118 TAO_DIOP_Connection_Handler *svc_handler_i = 0;
00119 ACE_NEW_RETURN (svc_handler_i,
00120 TAO_DIOP_Connection_Handler (this->orb_core (),
00121 this->lite_flag_),
00122 0);
00123
00124 svc_handler_i->local_addr (ACE_sap_any_cast (ACE_INET_Addr &));
00125 svc_handler_i->addr (remote_address);
00126
00127 svc_handler_i->open (0);
00128
00129 svc_handler_table_.bind (remote_address,
00130 svc_handler_i);
00131 svc_handler = svc_handler_i;
00132
00133 if (TAO_debug_level > 2)
00134 ACE_DEBUG ((LM_DEBUG,
00135 ACE_TEXT ("(%P|%t) DIOP_Connector::connect - ")
00136 ACE_TEXT ("new connection on HANDLE %d\n"),
00137 svc_handler->get_handle ()));
00138 }
00139
00140
00141 svc_handler->add_reference ();
00142 TAO_Transport *transport =
00143 svc_handler->transport ();
00144
00145 return transport;
00146 }
00147
00148 TAO_Profile *
00149 TAO_DIOP_Connector::create_profile (TAO_InputCDR& cdr)
00150 {
00151 TAO_Profile *pfile = 0;
00152 ACE_NEW_RETURN (pfile,
00153 TAO_DIOP_Profile (this->orb_core ()),
00154 0);
00155
00156 int const r = pfile->decode (cdr);
00157 if (r == -1)
00158 {
00159 pfile->_decr_refcnt ();
00160 pfile = 0;
00161 }
00162
00163 return pfile;
00164 }
00165
00166 TAO_Profile *
00167 TAO_DIOP_Connector::make_profile (ACE_ENV_SINGLE_ARG_DECL)
00168 {
00169
00170
00171
00172
00173
00174 TAO_Profile *profile = 0;
00175 ACE_NEW_THROW_EX (profile,
00176 TAO_DIOP_Profile (this->orb_core ()),
00177 CORBA::NO_MEMORY (
00178 CORBA::SystemException::_tao_minor_code (
00179 TAO::VMCID,
00180 ENOMEM),
00181 CORBA::COMPLETED_NO));
00182 ACE_CHECK_RETURN (0);
00183
00184 return profile;
00185 }
00186
00187 int
00188 TAO_DIOP_Connector::check_prefix (const char *endpoint)
00189 {
00190
00191 if (!endpoint || !*endpoint)
00192 return -1;
00193
00194 const char *protocol[] = { "diop", "dioploc" };
00195
00196 size_t const slot = ACE_OS::strchr (endpoint, ':') - endpoint;
00197
00198 size_t const len0 = ACE_OS::strlen (protocol[0]);
00199 size_t const len1 = ACE_OS::strlen (protocol[1]);
00200
00201
00202
00203 if (slot == len0
00204 && ACE_OS::strncasecmp (endpoint, protocol[0], len0) == 0)
00205 return 0;
00206 else if (slot == len1
00207 && ACE_OS::strncasecmp (endpoint, protocol[1], len1) == 0)
00208 return 0;
00209
00210 return -1;
00211
00212
00213 }
00214
00215 char
00216 TAO_DIOP_Connector::object_key_delimiter (void) const
00217 {
00218 return TAO_DIOP_Profile::object_key_delimiter_;
00219 }
00220
00221 TAO_DIOP_Endpoint *
00222 TAO_DIOP_Connector::remote_endpoint (TAO_Endpoint *endpoint)
00223 {
00224 if (endpoint->tag () != TAO_TAG_DIOP_PROFILE)
00225 return 0;
00226
00227 TAO_DIOP_Endpoint *diop_endpoint =
00228 dynamic_cast<TAO_DIOP_Endpoint *> (endpoint );
00229
00230 return diop_endpoint;
00231 }
00232
00233 int
00234 TAO_DIOP_Connector::cancel_svc_handler (
00235 TAO_Connection_Handler * )
00236 {
00237 return 0;
00238 }
00239
00240 TAO_END_VERSIONED_NAMESPACE_DECL
00241
00242 #endif