COIOP_Connector.cpp

Go to the documentation of this file.
00001 // This may look like C, but it's really -*- C++ -*-
00002 // $Id: COIOP_Connector.cpp 78931 2007-07-18 09:59:36Z johnnyw $
00003 
00004 #include "tao/Strategies/COIOP_Connector.h"
00005 
00006 #if defined (TAO_HAS_COIOP) && (TAO_HAS_COIOP != 0)
00007 
00008 #include "ace/Connector.h"
00009 #include "tao/debug.h"
00010 #include "tao/ORB_Core.h"
00011 #include "tao/SystemException.h"
00012 #include "ace/OS_NS_strings.h"
00013 #include "ace/OS_NS_string.h"
00014 
00015 #include "tao/Strategies/COIOP_Profile.h"
00016 
00017 
00018 ACE_RCSID (Strategies,
00019            COIOP_Connector,
00020            "$Id: COIOP_Connector.cpp 78931 2007-07-18 09:59:36Z johnnyw $")
00021 
00022 
00023 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 TAO_COIOP_Connector::TAO_COIOP_Connector (void)
00026   : TAO_Connector (TAO_TAG_COIOP_PROFILE)
00027 {
00028 }
00029 
00030 TAO_COIOP_Connector::~TAO_COIOP_Connector (void)
00031 {
00032 }
00033 
00034 int
00035 TAO_COIOP_Connector::open (TAO_ORB_Core *orb_core)
00036 {
00037   this->orb_core (orb_core);
00038 
00039   // Create our connect strategy
00040   if (this->create_connect_strategy () == -1)
00041     return -1;
00042 
00043   return 0;
00044 }
00045 
00046 int
00047 TAO_COIOP_Connector::close (void)
00048 {
00049   return 0;
00050 }
00051 
00052 int
00053 TAO_COIOP_Connector::set_validate_endpoint (TAO_Endpoint *endpoint)
00054 {
00055   TAO_COIOP_Endpoint *COIOP_endpoint =
00056     this->remote_endpoint (endpoint);
00057 
00058   if (COIOP_endpoint == 0)
00059     return -1;
00060 
00061   return 0;
00062 }
00063 
00064 TAO_Transport *
00065 TAO_COIOP_Connector::make_connection (TAO::Profile_Transport_Resolver *,
00066                                       TAO_Transport_Descriptor_Interface &,
00067                                       ACE_Time_Value * /*max_wait_time*/)
00068 {
00069   // No remote connection possible with COIOP
00070   return 0;
00071 }
00072 
00073 TAO_Profile *
00074 TAO_COIOP_Connector::create_profile (TAO_InputCDR& cdr)
00075 {
00076   TAO_Profile *pfile = 0;
00077   ACE_NEW_RETURN (pfile,
00078                   TAO_COIOP_Profile (this->orb_core ()),
00079                   0);
00080 
00081   int const r = pfile->decode (cdr);
00082   if (r == -1)
00083     {
00084       pfile->_decr_refcnt ();
00085       pfile = 0;
00086     }
00087 
00088   return pfile;
00089 }
00090 
00091 TAO_Profile *
00092 TAO_COIOP_Connector::make_profile (void)
00093 {
00094   // The endpoint should be of the form:
00095   //    N.n@uuid/object_key
00096   // or:
00097   //    uuid/object_key
00098 
00099   TAO_Profile *profile = 0;
00100   ACE_NEW_THROW_EX (profile,
00101                     TAO_COIOP_Profile (this->orb_core ()),
00102                     CORBA::NO_MEMORY (
00103                       CORBA::SystemException::_tao_minor_code (
00104                         TAO::VMCID,
00105                         ENOMEM),
00106                       CORBA::COMPLETED_NO));
00107 
00108   return profile;
00109 }
00110 
00111 int
00112 TAO_COIOP_Connector::check_prefix (const char *endpoint)
00113 {
00114   // Check for a valid string
00115   if (!endpoint || !*endpoint)
00116     return -1;  // Failure
00117 
00118   const char *protocol[] = { "COIOP", "COIOPloc" };
00119 
00120   size_t const slot = ACE_OS::strchr (endpoint, ':') - endpoint;
00121 
00122   size_t const len0 = ACE_OS::strlen (protocol[0]);
00123   size_t const len1 = ACE_OS::strlen (protocol[1]);
00124 
00125   // Check for the proper prefix in the IOR.  If the proper prefix
00126   // isn't in the IOR then it is not an IOR we can use.
00127   if (slot == len0
00128       && ACE_OS::strncasecmp (endpoint, protocol[0], len0) == 0)
00129     return 0;
00130   else if (slot == len1
00131            && ACE_OS::strncasecmp (endpoint, protocol[1], len1) == 0)
00132     return 0;
00133 
00134   return -1;
00135   // Failure: not an COIOP IOR
00136   // DO NOT throw an exception here.
00137 }
00138 
00139 char
00140 TAO_COIOP_Connector::object_key_delimiter (void) const
00141 {
00142   return TAO_COIOP_Profile::object_key_delimiter_;
00143 }
00144 
00145 TAO_COIOP_Endpoint *
00146 TAO_COIOP_Connector::remote_endpoint (TAO_Endpoint *endpoint)
00147 {
00148   if (endpoint->tag () != TAO_TAG_COIOP_PROFILE)
00149     return 0;
00150 
00151   TAO_COIOP_Endpoint *COIOP_endpoint =
00152     dynamic_cast<TAO_COIOP_Endpoint *> (endpoint );
00153 
00154   return COIOP_endpoint;
00155 }
00156 
00157 int
00158 TAO_COIOP_Connector::cancel_svc_handler (
00159   TAO_Connection_Handler * /* svc_handler */)
00160 {
00161   return 0;
00162 }
00163 
00164 TAO_END_VERSIONED_NAMESPACE_DECL
00165 
00166 #endif /* TAO_HAS_COIOP && TAO_HAS_COIOP != 0 */

Generated on Sun Jan 27 15:59:45 2008 for TAO_Strategies by doxygen 1.3.6