ORBInitInfo.cpp

Go to the documentation of this file.
00001 // ORBInitInfo.cpp,v 1.11 2006/04/19 09:22:56 jwillemsen Exp
00002 
00003 #include "tao/PI/ORBInitInfo.h"
00004 #include "tao/ORB_Core.h"
00005 #include "tao/ORB.h"
00006 #include "tao/SystemException.h"
00007 #include "tao/Object_Loader.h"
00008 #include "tao/PolicyFactory_Registry_Adapter.h"
00009 
00010 #include "ace/Dynamic_Service.h"
00011 #include "ace/Service_Config.h"
00012 
00013 #if TAO_HAS_INTERCEPTORS == 1
00014 #include "tao/PI/PICurrent.h"
00015 #endif  /* TAO_HAS_INTERCEPTORS == 1 */
00016 
00017 ACE_RCSID (TAO,
00018            ORBInitInfo,
00019            "ORBInitInfo.cpp,v 1.11 2006/04/19 09:22:56 jwillemsen Exp")
00020 
00021 #if !defined (__ACE_INLINE__)
00022 #include "tao/PI/ORBInitInfo.inl"
00023 #endif /* defined INLINE */
00024 
00025 #include "ace/OS_NS_string.h"
00026 
00027 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00028 
00029 // Traits specializations for TAO_ORBInitInfo.
00030 
00031 TAO_ORBInitInfo_ptr
00032 TAO::Objref_Traits<TAO_ORBInitInfo>::duplicate (
00033     TAO_ORBInitInfo_ptr p
00034   )
00035 {
00036   return TAO_ORBInitInfo::_duplicate (p);
00037 }
00038 
00039 void
00040 TAO::Objref_Traits<TAO_ORBInitInfo>::release (
00041     TAO_ORBInitInfo_ptr p
00042   )
00043 {
00044   ::CORBA::release (p);
00045 }
00046 
00047 TAO_ORBInitInfo_ptr
00048 TAO::Objref_Traits<TAO_ORBInitInfo>::nil (void)
00049 {
00050   return TAO_ORBInitInfo::_nil ();
00051 }
00052 
00053 CORBA::Boolean
00054 TAO::Objref_Traits<TAO_ORBInitInfo>::marshal (
00055     TAO_ORBInitInfo_ptr p,
00056     TAO_OutputCDR & cdr
00057   )
00058 {
00059   return p->marshal (cdr);
00060 }
00061 
00062 TAO_ORBInitInfo::TAO_ORBInitInfo (TAO_ORB_Core *orb_core,
00063                                   int argc,
00064                                   char *argv[],
00065                                   PortableInterceptor::SlotId slotid)
00066   : orb_core_ (orb_core),
00067     argc_ (argc),
00068     argv_ (argv),
00069     codec_factory_ (),
00070     slot_count_ (slotid)
00071 {
00072 }
00073 
00074 TAO_ORBInitInfo::~TAO_ORBInitInfo (void)
00075 {
00076 }
00077 
00078 CORBA::StringSeq *
00079 TAO_ORBInitInfo::arguments (ACE_ENV_SINGLE_ARG_DECL)
00080   ACE_THROW_SPEC ((CORBA::SystemException))
00081 {
00082   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00083   ACE_CHECK_RETURN (0);
00084 
00085   // In accordance with the C++ mapping for sequences, it is up to the
00086   // caller to deallocate storage for returned sequences.
00087 
00088   CORBA::StringSeq *args = 0;
00089   ACE_NEW_THROW_EX (args,
00090                     CORBA::StringSeq,
00091                     CORBA::NO_MEMORY (
00092                       CORBA::SystemException::_tao_minor_code (
00093                         0,
00094                         ENOMEM),
00095                       CORBA::COMPLETED_NO));
00096   ACE_CHECK_RETURN (0);
00097 
00098   CORBA::StringSeq_var safe_args (args);
00099 
00100   // Copy the argument vector to the string sequence.
00101 
00102   args->length (this->argc_);   // Not a problem if argc is zero.
00103   for (int i = 0; i < this->argc_; ++i)
00104     (*args)[i] = CORBA::string_dup (this->argv_[i]);
00105 
00106   return safe_args._retn ();
00107 }
00108 
00109 char *
00110 TAO_ORBInitInfo::orb_id (ACE_ENV_SINGLE_ARG_DECL)
00111   ACE_THROW_SPEC ((CORBA::SystemException))
00112 {
00113   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00114   ACE_CHECK_RETURN (0);
00115 
00116   // In accordance with the C++ mapping for strings, return a copy.
00117 
00118   return CORBA::string_dup (this->orb_core_->orbid ());
00119 }
00120 
00121 IOP::CodecFactory_ptr
00122 TAO_ORBInitInfo::codec_factory (ACE_ENV_SINGLE_ARG_DECL)
00123   ACE_THROW_SPEC ((CORBA::SystemException))
00124 {
00125   if (CORBA::is_nil (this->codec_factory_.in ()))
00126     {
00127       TAO_Object_Loader *loader =
00128         ACE_Dynamic_Service<TAO_Object_Loader>::instance ("CodecFactory_Loader");
00129 
00130       if (loader == 0)
00131         {
00132           ACE_Service_Config::process_directive (
00133             ACE_DYNAMIC_SERVICE_DIRECTIVE("CodecFactory",
00134                                           "TAO_CodecFactory",
00135                                           "_make_TAO_CodecFactory_Loader",
00136                                           ""));
00137           loader =
00138             ACE_Dynamic_Service<TAO_Object_Loader>::instance ("CodecFactory_Loader");
00139         }
00140 
00141       if (loader != 0)
00142         {
00143           CORBA::Object_var cf =
00144             loader->create_object (this->orb_core_->orb (), 0, 0 ACE_ENV_ARG_PARAMETER);
00145           ACE_CHECK_RETURN (IOP::CodecFactory::_nil ());
00146 
00147           this->codec_factory_ = IOP::CodecFactory::_narrow (cf.in ());
00148         }
00149     }
00150 
00151   return IOP::CodecFactory::_duplicate (this->codec_factory_.in ());
00152 }
00153 
00154 void
00155 TAO_ORBInitInfo::register_initial_reference (
00156     const char * id,
00157     CORBA::Object_ptr obj
00158     ACE_ENV_ARG_DECL)
00159   ACE_THROW_SPEC ((CORBA::SystemException,
00160                    PortableInterceptor::ORBInitInfo::InvalidName))
00161 {
00162   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00163   ACE_CHECK;
00164 
00165   if (id == 0 || ACE_OS::strlen (id) == 0)
00166     ACE_THROW (PortableInterceptor::ORBInitInfo::InvalidName ());
00167   ACE_CHECK;
00168 
00169   if (CORBA::is_nil (obj))
00170     ACE_THROW (CORBA::BAD_PARAM (CORBA::OMGVMCID | 27,
00171                                  CORBA::COMPLETED_NO));
00172   ACE_CHECK;
00173 
00174   TAO_Object_Ref_Table &table = this->orb_core_->object_ref_table ();
00175 
00176   if (table.register_initial_reference (id, obj) == -1)
00177     ACE_THROW (PortableInterceptor::ORBInitInfo::InvalidName ());
00178 }
00179 
00180 CORBA::Object_ptr
00181 TAO_ORBInitInfo::resolve_initial_references (
00182     const char * id
00183     ACE_ENV_ARG_DECL)
00184   ACE_THROW_SPEC ((CORBA::SystemException,
00185                    PortableInterceptor::ORBInitInfo::InvalidName))
00186 {
00187   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00188   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00189 
00190   if (id == 0 || ACE_OS::strlen (id) == 0)
00191     ACE_THROW_RETURN (PortableInterceptor::ORBInitInfo::InvalidName (),
00192                       CORBA::Object::_nil ());
00193 
00194   // The ORB is practically fully initialized by the time this point
00195   // is reached so just use the ORB's resolve_initial_references()
00196   // mechanism.
00197   return
00198     this->orb_core_->orb ()->resolve_initial_references (id
00199                                                          ACE_ENV_ARG_PARAMETER);
00200 }
00201 
00202 void
00203 TAO_ORBInitInfo::add_client_request_interceptor (
00204     PortableInterceptor::ClientRequestInterceptor_ptr interceptor
00205     ACE_ENV_ARG_DECL)
00206   ACE_THROW_SPEC ((CORBA::SystemException,
00207                    PortableInterceptor::ORBInitInfo::DuplicateName))
00208 {
00209 # if TAO_HAS_INTERCEPTORS == 1
00210   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00211   ACE_CHECK;
00212 
00213   this->orb_core_->add_interceptor (interceptor ACE_ENV_ARG_PARAMETER);
00214   ACE_CHECK;
00215 #else
00216   ACE_UNUSED_ARG (interceptor);
00217   ACE_THROW (CORBA::NO_IMPLEMENT (
00218                CORBA::SystemException::_tao_minor_code (
00219                  0,
00220                  ENOTSUP),
00221                CORBA::COMPLETED_NO));
00222 #endif  /* TAO_HAS_INTERCEPTORS == 1 */
00223 }
00224 
00225 void
00226 TAO_ORBInitInfo::add_server_request_interceptor (
00227     PortableInterceptor::ServerRequestInterceptor_ptr interceptor
00228     ACE_ENV_ARG_DECL)
00229   ACE_THROW_SPEC ((CORBA::SystemException,
00230                    PortableInterceptor::ORBInitInfo::DuplicateName))
00231 {
00232 # if TAO_HAS_INTERCEPTORS == 1
00233   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00234   ACE_CHECK;
00235 
00236   this->orb_core_->add_interceptor (interceptor ACE_ENV_ARG_PARAMETER);
00237   ACE_CHECK;
00238 
00239 #else
00240   ACE_UNUSED_ARG (interceptor);
00241   ACE_THROW (CORBA::NO_IMPLEMENT (
00242                CORBA::SystemException::_tao_minor_code (
00243                  0,
00244                  ENOTSUP),
00245                CORBA::COMPLETED_NO));
00246 #endif  /* TAO_HAS_INTERCEPTORS == 1 */
00247 }
00248 
00249 void
00250 TAO_ORBInitInfo::add_ior_interceptor (
00251     PortableInterceptor::IORInterceptor_ptr interceptor
00252     ACE_ENV_ARG_DECL)
00253   ACE_THROW_SPEC ((CORBA::SystemException,
00254                    PortableInterceptor::ORBInitInfo::DuplicateName))
00255 {
00256   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00257   ACE_CHECK;
00258 
00259   this->orb_core_->add_interceptor (interceptor
00260                                      ACE_ENV_ARG_PARAMETER);
00261 }
00262 
00263 void
00264 TAO_ORBInitInfo::add_client_request_interceptor_with_policy (
00265     PortableInterceptor::ClientRequestInterceptor_ptr interceptor,
00266     const CORBA::PolicyList& policies
00267     ACE_ENV_ARG_DECL)
00268   ACE_THROW_SPEC ((CORBA::SystemException,
00269                    PortableInterceptor::ORBInitInfo::DuplicateName,
00270                    CORBA::PolicyError))
00271 {
00272 # if TAO_HAS_INTERCEPTORS == 1
00273   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00274   ACE_CHECK;
00275 
00276   this->orb_core_->add_interceptor (interceptor,
00277                                     policies
00278                                     ACE_ENV_ARG_PARAMETER);
00279 #else
00280   ACE_UNUSED_ARG (interceptor);
00281   ACE_UNUSED_ARG (policies);
00282   ACE_THROW (CORBA::NO_IMPLEMENT (
00283                CORBA::SystemException::_tao_minor_code (
00284                  0,
00285                  ENOTSUP),
00286                CORBA::COMPLETED_NO));
00287 #endif  /* TAO_HAS_INTERCEPTORS == 1 */
00288 }
00289 
00290 void
00291 TAO_ORBInitInfo::add_server_request_interceptor_with_policy (
00292     PortableInterceptor::ServerRequestInterceptor_ptr interceptor,
00293     const CORBA::PolicyList& policies
00294     ACE_ENV_ARG_DECL)
00295   ACE_THROW_SPEC ((CORBA::SystemException,
00296                    PortableInterceptor::ORBInitInfo::DuplicateName,
00297                    CORBA::PolicyError))
00298 {
00299 # if TAO_HAS_INTERCEPTORS == 1
00300   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00301   ACE_CHECK;
00302 
00303   this->orb_core_->add_interceptor (interceptor,
00304                                     policies
00305                                     ACE_ENV_ARG_PARAMETER);
00306 
00307 #else
00308   ACE_UNUSED_ARG (interceptor);
00309   ACE_UNUSED_ARG (policies);
00310   ACE_THROW (CORBA::NO_IMPLEMENT (
00311                CORBA::SystemException::_tao_minor_code (
00312                  0,
00313                  ENOTSUP),
00314                CORBA::COMPLETED_NO));
00315 #endif  /* TAO_HAS_INTERCEPTORS == 1 */
00316 }
00317 
00318 void
00319 TAO_ORBInitInfo::add_ior_interceptor_with_policy (
00320     PortableInterceptor::IORInterceptor_ptr interceptor,
00321     const CORBA::PolicyList& policies
00322     ACE_ENV_ARG_DECL)
00323   ACE_THROW_SPEC ((CORBA::SystemException,
00324                    PortableInterceptor::ORBInitInfo::DuplicateName,
00325                    CORBA::PolicyError))
00326 {
00327   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00328   ACE_CHECK;
00329 
00330   // Since there are currently no PI Policies that pertain to
00331   // IOR Interceptors, we will always raise the NO_IMPLEMENT
00332   // CORBA System Exception here to indicate that this method
00333   // is currently not implemented/supported.
00334   ACE_UNUSED_ARG (interceptor);
00335   ACE_UNUSED_ARG (policies);
00336   ACE_THROW (CORBA::NO_IMPLEMENT (
00337                CORBA::SystemException::_tao_minor_code (
00338                  0,
00339                  ENOTSUP),
00340                CORBA::COMPLETED_NO));
00341 }
00342 
00343 PortableInterceptor::SlotId
00344 TAO_ORBInitInfo::allocate_slot_id (ACE_ENV_SINGLE_ARG_DECL)
00345   ACE_THROW_SPEC ((CORBA::SystemException))
00346 {
00347   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00348   ACE_CHECK_RETURN (0);
00349 
00350 #if TAO_HAS_INTERCEPTORS == 1
00351   // No need to acquire a lock.  This only gets called during ORB
00352   // initialization.  ORB initialization is already atomic.
00353   return this->slot_count_++;
00354 #else
00355   ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (
00356                       CORBA::SystemException::_tao_minor_code (
00357                         0,
00358                         ENOTSUP),
00359                       CORBA::COMPLETED_NO),
00360                     0);
00361 #endif  /* TAO_HAS_INTERCEPTORS == 1 */
00362 }
00363 
00364 void
00365 TAO_ORBInitInfo::register_policy_factory (
00366     CORBA::PolicyType type,
00367     PortableInterceptor::PolicyFactory_ptr policy_factory
00368     ACE_ENV_ARG_DECL)
00369   ACE_THROW_SPEC ((CORBA::SystemException))
00370 {
00371   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00372   ACE_CHECK;
00373 
00374   TAO::PolicyFactory_Registry_Adapter *registry =
00375     this->orb_core_->policy_factory_registry ();
00376 
00377   if (registry == 0)
00378     {
00379       ACE_THROW (CORBA::INTERNAL ());
00380     }
00381 
00382   registry->register_policy_factory (type,
00383                                      policy_factory
00384                                       ACE_ENV_ARG_PARAMETER);
00385 }
00386 
00387 size_t
00388 TAO_ORBInitInfo::allocate_tss_slot_id (ACE_CLEANUP_FUNC cleanup
00389                                        ACE_ENV_ARG_DECL)
00390   ACE_THROW_SPEC ((CORBA::SystemException))
00391 {
00392   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00393   ACE_CHECK_RETURN (0);
00394 
00395   size_t slot_id = 0;
00396 
00397   const int result = this->orb_core_->add_tss_cleanup_func (cleanup,
00398                                                             slot_id);
00399 
00400   if (result != 0)
00401     ACE_THROW_RETURN (CORBA::INTERNAL (
00402                         CORBA::SystemException::_tao_minor_code (
00403                           0,
00404                           errno),
00405                         CORBA::COMPLETED_NO),
00406                       0);
00407 
00408   return slot_id;
00409 }
00410 
00411 void
00412 TAO_ORBInitInfo::check_validity (ACE_ENV_SINGLE_ARG_DECL)
00413 {
00414   if (this->orb_core_ == 0)
00415     {
00416       // As defined by the Portable Interceptor specification, throw a
00417       // CORBA::OBJECT_NOT_EXIST exception after CORBA::ORB_init() has
00418       // completed.  CORBA::ORB_init() sets the ORB core pointer in
00419       // this instance to zero when it is done initializing the ORB,
00420       // which is why we base "existence" on the validity of the ORB
00421       // core pointer.
00422       ACE_THROW (CORBA::OBJECT_NOT_EXIST (0,
00423                                           CORBA::COMPLETED_NO));
00424     }
00425 }
00426 
00427 CORBA::ORB_ptr
00428 TAO_ORBInitInfo::_get_orb (ACE_ENV_SINGLE_ARG_DECL)
00429 {
00430   this->check_validity (ACE_ENV_SINGLE_ARG_PARAMETER);
00431   ACE_CHECK_RETURN (CORBA::ORB::_nil ());
00432 
00433   return CORBA::ORB::_duplicate (this->orb_core_->orb ());
00434 }
00435 
00436 TAO_ORBInitInfo_ptr TAO_ORBInitInfo::_narrow (
00437     CORBA::Object_ptr _tao_objref
00438     ACE_ENV_ARG_DECL_NOT_USED
00439   )
00440 {
00441   if (CORBA::is_nil (_tao_objref))
00442     {
00443       return TAO_ORBInitInfo::_nil ();
00444     }
00445 
00446   TAO_ORBInitInfo_ptr proxy =
00447     dynamic_cast<TAO_ORBInitInfo_ptr> (_tao_objref);
00448 
00449   return TAO_ORBInitInfo::_duplicate (proxy);
00450 }
00451 
00452 TAO_ORBInitInfo_ptr
00453 TAO_ORBInitInfo::_duplicate (TAO_ORBInitInfo_ptr obj)
00454 {
00455   if (!CORBA::is_nil (obj))
00456     {
00457       obj->_add_ref ();
00458     }
00459 
00460   return obj;
00461 }
00462 
00463 const char* TAO_ORBInitInfo::_interface_repository_id (void) const
00464 {
00465   return "IDL:TAO_ORBInitInfo:1.0";
00466 }
00467 
00468 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 12:51:39 2006 for TAO_PI by doxygen 1.3.6