Connector_Registry.cpp

Go to the documentation of this file.
00001 // Connector_Registry.cpp,v 1.59 2006/06/19 19:46:40 jwillemsen Exp
00002 
00003 #include "tao/Connector_Registry.h"
00004 #include "tao/ORB_Core.h"
00005 #include "tao/Profile.h"
00006 #include "tao/Transport_Connector.h"
00007 #include "tao/Protocol_Factory.h"
00008 #include "tao/debug.h"
00009 #include "tao/ORB_Constants.h"
00010 #include "tao/CDR.h"
00011 #include "tao/SystemException.h"
00012 #include "ace/Auto_Ptr.h"
00013 
00014 #if !defined(__ACE_INLINE__)
00015 #include "tao/Connector_Registry.i"
00016 #endif /* __ACE_INLINE__ */
00017 
00018 
00019 ACE_RCSID (tao,
00020            Connector_Registry,
00021            "Connector_Registry.cpp,v 1.59 2006/06/19 19:46:40 jwillemsen Exp")
00022 
00023 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 TAO_Connector_Registry::TAO_Connector_Registry (void)
00026   : connectors_ (0),
00027     size_ (0)
00028 {
00029 }
00030 
00031 TAO_Connector_Registry::~TAO_Connector_Registry (void)
00032 {
00033   this->close_all ();
00034 
00035   delete [] this->connectors_;
00036 }
00037 
00038 TAO_Connector *
00039 TAO_Connector_Registry::get_connector (CORBA::ULong tag) const
00040 {
00041   const TAO_ConnectorSetIterator end = this->end ();
00042 
00043   for (TAO_ConnectorSetIterator connector = this->begin ();
00044        connector != end;
00045        ++connector)
00046     {
00047       if ((*connector)->tag () == tag)
00048         return *connector;
00049     }
00050 
00051   return 0;
00052 }
00053 
00054 int
00055 TAO_Connector_Registry::open (TAO_ORB_Core *orb_core)
00056 {
00057   TAO_ProtocolFactorySet * const pfs =
00058     orb_core->protocol_factories ();
00059 
00060   // The array containing the TAO_Connectors will never contain more
00061   // than the number of loaded protocols in the ORB core.
00062   if (this->connectors_ == 0)
00063     ACE_NEW_RETURN (this->connectors_,
00064                     TAO_Connector *[pfs->size ()],
00065                     -1);
00066 
00067   // Open one connector for each loaded protocol!
00068   const TAO_ProtocolFactorySetItor end = pfs->end ();
00069 
00070   for (TAO_ProtocolFactorySetItor factory = pfs->begin ();
00071        factory != end;
00072        ++factory)
00073     {
00074       auto_ptr <TAO_Connector> connector (
00075         (*factory)->factory ()->make_connector ());
00076 
00077       if (connector.get ())
00078         {
00079          if (connector->open (orb_core) != 0)
00080            {
00081              ACE_ERROR_RETURN ((LM_ERROR,
00082                                 ACE_TEXT ("TAO (%P|%t) unable to open connector for ")
00083                                 ACE_TEXT ("<%s>.\n"),
00084                                 ACE_TEXT_CHAR_TO_TCHAR((*factory)->protocol_name ().c_str ())),
00085                                -1);
00086            }
00087 
00088          this->connectors_[this->size_++] =
00089            connector.release ();
00090         }
00091       else
00092         return -1;
00093     }
00094 
00095   return 0;
00096 }
00097 
00098 int
00099 TAO_Connector_Registry::close_all (void)
00100 {
00101   const TAO_ConnectorSetIterator end = this->end ();
00102 
00103   for (TAO_ConnectorSetIterator i = this->begin ();
00104        i != end;
00105        ++i)
00106     {
00107       if (*i == 0)
00108         continue;
00109 
00110       (*i)->close ();
00111 
00112       delete *i;
00113     }
00114 
00115   this->size_ = 0;
00116 
00117   return 0;
00118 }
00119 
00120 int
00121 TAO_Connector_Registry::make_mprofile (const char *ior,
00122                                        TAO_MProfile &mprofile
00123                                        ACE_ENV_ARG_DECL)
00124 {
00125   if (!ior)
00126     // Failure: Null IOR string pointer
00127     ACE_THROW_RETURN (CORBA::INV_OBJREF (
00128       CORBA::SystemException::_tao_minor_code (
00129         0,
00130         EINVAL),
00131       CORBA::COMPLETED_NO),
00132       -1);
00133 
00134   const TAO_ConnectorSetIterator first_connector = this->begin ();
00135   const TAO_ConnectorSetIterator last_connector = this->end ();
00136 
00137   for (TAO_ConnectorSetIterator connector = first_connector;
00138        connector != last_connector;
00139        ++connector)
00140     {
00141       if (*connector)
00142         {
00143           const int mp_result =
00144             (*connector)->make_mprofile (ior,
00145                                          mprofile
00146                                          ACE_ENV_ARG_PARAMETER);
00147           ACE_CHECK_RETURN (mp_result);
00148 
00149           if (mp_result == 0)
00150             return 0;  // Success
00151         }
00152       else
00153         // Failure: Null pointer to connector in connector registry.
00154         ACE_THROW_RETURN (CORBA::INV_OBJREF (
00155           CORBA::SystemException::_tao_minor_code (
00156             0,
00157             EINVAL),
00158           CORBA::COMPLETED_NO),
00159           -1);
00160     }
00161 
00162   // Failure: None of the connectors were able to parse the URL style
00163   // IOR into an MProfile.
00164   ACE_THROW_RETURN (CORBA::INV_OBJREF (
00165    CORBA::SystemException::_tao_minor_code (
00166       TAO_CONNECTOR_REGISTRY_NO_USABLE_PROTOCOL,
00167       0),
00168    CORBA::COMPLETED_NO),
00169    -1);
00170 }
00171 
00172 TAO_Profile *
00173 TAO_Connector_Registry::create_profile (TAO_InputCDR &cdr)
00174 {
00175   CORBA::ULong tag = 0;
00176 
00177   // If there is an error we abort.
00178   if ((cdr >> tag) == 0)
00179     return 0;
00180 
00181   TAO_Connector *connector =
00182     this->get_connector (tag);
00183 
00184   if (connector == 0)
00185     {
00186       if (TAO_debug_level > 0)
00187         {
00188           ACE_DEBUG ((LM_DEBUG,
00189                       ACE_TEXT ("TAO (%P|%t) Unknown profile tag 0x%x\n"),
00190                       tag));
00191         }
00192 
00193       TAO_ORB_Core *orb_core = cdr.orb_core ();
00194       if (orb_core == 0)
00195         {
00196           orb_core = TAO_ORB_Core_instance ();
00197           if (TAO_debug_level > 0)
00198             {
00199               ACE_DEBUG ((LM_WARNING,
00200                           ACE_TEXT ("TAO (%P|%t) - TAO_Connector_Registry")
00201                           ACE_TEXT ("::create_profile: ")
00202                           ACE_TEXT ("WARNING: extracting object from ")
00203                           ACE_TEXT ("default ORB_Core\n")));
00204             }
00205         }
00206 
00207 
00208       TAO_Profile *pfile = 0;
00209       ACE_NEW_RETURN (pfile,
00210                       TAO_Unknown_Profile (tag,
00211                                            orb_core),
00212                       0);
00213       if (pfile->decode (cdr) == -1)
00214         {
00215           pfile->_decr_refcnt ();
00216           pfile = 0;
00217         }
00218 
00219       return pfile;
00220     }
00221 
00222   // OK, we've got a known profile.  It's going to be encapsulated
00223   // ProfileData.  Create a new decoding stream and context for it,
00224   // and skip the data in the parent stream
00225 
00226   // ProfileData is encoded as a sequence of octet. So first get the
00227   // length of the sequence.
00228   CORBA::ULong encap_len = 0;
00229   if ((cdr >> encap_len) == 0)
00230     return 0;
00231 
00232   // Create the decoding stream from the encapsulation in the buffer,
00233   // and skip the encapsulation.
00234   TAO_InputCDR str (cdr, encap_len);
00235 
00236   if (str.good_bit () == 0
00237       || cdr.skip_bytes (encap_len) == 0)
00238     return 0;
00239 
00240   return connector->create_profile (str);
00241 }
00242 
00243 char
00244 TAO_Connector_Registry::object_key_delimiter (const char *ior)
00245 {
00246   if (!ior)
00247     {
00248       errno = EINVAL;
00249       return 0; // Failure: Null IOR string pointer
00250     }
00251 
00252   const TAO_ConnectorSetIterator first_connector = this->begin ();
00253   const TAO_ConnectorSetIterator last_connector =  this->end ();
00254 
00255   for (TAO_ConnectorSetIterator connector = first_connector;
00256        connector != last_connector;
00257        ++connector)
00258     {
00259       if (*connector)
00260         {
00261           if ((*connector)->check_prefix (ior) == 0)
00262             return (*connector)->object_key_delimiter ();
00263         }
00264     }
00265 
00266   // Failure: None of the connectors were able to match their protocol
00267   // against the provided string.
00268   return 0;
00269 }
00270 
00271 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 11:54:09 2006 for TAO by doxygen 1.3.6