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