ORBInitInfo.cpp

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

Generated on Sun Jan 27 13:29:59 2008 for TAO_PI by doxygen 1.3.6