ORBInitializer_Registry_Impl.cpp

Go to the documentation of this file.
00001 #include "tao/PI/ORBInitializer_Registry_Impl.h"
00002 #include "tao/PI/ORBInitInfo.h"
00003 #include "tao/PI/PICurrent.h"
00004 #include "tao/PI/PI_ORBInitializer.h"
00005 #include "tao/PI/ClientRequestInterceptor_Factory_Impl.h"
00006 #include "tao/PI/PICurrent_Loader.h"
00007 #include "tao/PI/PolicyFactory_Loader.h"
00008 
00009 #include "tao/ORB_Core.h"
00010 #include "tao/ORB_Constants.h"
00011 
00012 #include "ace/Static_Object_Lock.h"
00013 #include "ace/Recursive_Thread_Mutex.h"
00014 #include "ace/Log_Msg.h"
00015 #include "ace/CORBA_macros.h"
00016 
00017 ACE_RCSID (PI,
00018            ORBInitializer_Registry,
00019            "$Id: ORBInitializer_Registry_Impl.cpp 78935 2007-07-18 12:40:46Z johnnyw $")
00020 
00021 
00022 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 TAO::ORBInitializer_Registry::ORBInitializer_Registry (void)
00025   : lock_ (),
00026     initializers_ ()
00027 {
00028 }
00029 
00030 int
00031 TAO::ORBInitializer_Registry::init (int, ACE_TCHAR *[])
00032 {
00033 #if !defined (TAO_AS_STATIC_LIBS) && (TAO_HAS_INTERCEPTORS == 1)
00034   ACE_Service_Config::process_directive
00035     (ace_svc_desc_TAO_ClientRequestInterceptor_Adapter_Factory_Impl);
00036 
00037   ACE_Service_Config::process_directive
00038     (ace_svc_desc_TAO_PICurrent_Loader);
00039 
00040   PortableInterceptor::ORBInitializer_ptr temp_orb_initializer =
00041     PortableInterceptor::ORBInitializer::_nil ();
00042 
00043   PortableInterceptor::ORBInitializer_var orb_initializer;
00044 
00045   try
00046     {
00047       /// Register the PI ORBInitializer.
00048 
00049       ACE_NEW_THROW_EX (temp_orb_initializer,
00050                         TAO_PI_ORBInitializer,
00051                         CORBA::NO_MEMORY (
00052                           CORBA::SystemException::_tao_minor_code (
00053                             TAO::VMCID,
00054                             ENOMEM),
00055                           CORBA::COMPLETED_NO));
00056 
00057       orb_initializer = temp_orb_initializer;
00058 
00059       this->register_orb_initializer (orb_initializer.in ());
00060     }
00061   catch (const ::CORBA::Exception& ex)
00062     {
00063       if (TAO_debug_level > 0)
00064         {
00065           ex._tao_print_exception ("(%P|%t) Caught exception:");
00066         }
00067       return -1;
00068     }
00069 #endif /* !TAO_AS_STATIC_LIBS  && TAO_HAS_INTERCEPTORS == 1 */
00070   return 0;
00071 }
00072 
00073 int
00074 TAO::ORBInitializer_Registry::fini (void)
00075 {
00076   ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
00077                     guard,
00078                     this->lock_,
00079                     -1);
00080 
00081   // Release all initializers in the array
00082   size_t const initializer_count (this->initializers_.size ());
00083   for (size_t i = 0; i < initializer_count; ++i)
00084     {
00085       this->initializers_[i] = PortableInterceptor::ORBInitializer::_nil();
00086     }
00087 
00088   return 0;
00089 }
00090 
00091 void
00092 TAO::ORBInitializer_Registry::register_orb_initializer (
00093   PortableInterceptor::ORBInitializer_ptr init)
00094 {
00095   if (!CORBA::is_nil (init))
00096     {
00097       ACE_GUARD (TAO_SYNCH_RECURSIVE_MUTEX,
00098                  guard,
00099                  this->lock_);
00100 
00101       // Increase the length of the ORBInitializer array by one.
00102       size_t const cur_len = this->initializers_.size ();
00103       size_t const new_len = cur_len + 1;
00104       if (this->initializers_.size (new_len) != 0)
00105         throw ::CORBA::INTERNAL ();
00106 
00107       // Add the given ORBInitializer to the sequence.
00108       this->initializers_[cur_len] =
00109         PortableInterceptor::ORBInitializer::_duplicate (init);
00110     }
00111   else
00112     throw ::CORBA::INV_OBJREF (
00113                  CORBA::SystemException::_tao_minor_code (
00114                    0,
00115                    EINVAL),
00116                  CORBA::COMPLETED_NO);
00117 }
00118 
00119 size_t
00120 TAO::ORBInitializer_Registry::pre_init (
00121   TAO_ORB_Core *orb_core,
00122   int argc,
00123   char *argv[],
00124   PortableInterceptor::SlotId &slotid)
00125 {
00126   ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
00127                     guard,
00128                     this->lock_,
00129                     0);
00130 
00131   size_t const initializer_count (this->initializers_.size ());
00132 
00133   if (initializer_count > 0)
00134     {
00135       TAO_ORBInitInfo * orb_init_info_temp = 0;
00136 
00137       ACE_NEW_THROW_EX (orb_init_info_temp,
00138                         TAO_ORBInitInfo (orb_core,
00139                                          argc,
00140                                          argv,
00141                                          slotid),
00142                         CORBA::NO_MEMORY (
00143                           CORBA::SystemException::_tao_minor_code (
00144                             0,
00145                             ENOMEM),
00146                           CORBA::COMPLETED_NO));
00147 
00148       TAO_ORBInitInfo_var orb_init_info_ = orb_init_info_temp;
00149 
00150       for (size_t i = 0; i < initializer_count; ++i)
00151         {
00152           this->initializers_[i]->pre_init (orb_init_info_.in ());
00153         }
00154 
00155       slotid = orb_init_info_temp->slot_count ();
00156 
00157       // Invalidate the ORBInitInfo instance to prevent future
00158       // modifications to the ORB.  This behavior complies with the
00159       // PortableInterceptor specification.
00160       orb_init_info_temp->invalidate ();
00161     }
00162 
00163   return initializer_count;
00164 }
00165 
00166 void
00167 TAO::ORBInitializer_Registry::post_init (
00168   size_t pre_init_count,
00169   TAO_ORB_Core *orb_core,
00170   int argc,
00171   char *argv[],
00172   PortableInterceptor::SlotId slotid)
00173 {
00174   if (pre_init_count > 0)
00175     {
00176       ACE_GUARD (TAO_SYNCH_RECURSIVE_MUTEX,
00177                  guard,
00178                  this->lock_);
00179 
00180       TAO_ORBInitInfo * orb_init_info_temp = 0;
00181 
00182       ACE_NEW_THROW_EX (orb_init_info_temp,
00183                         TAO_ORBInitInfo (orb_core,
00184                                          argc,
00185                                          argv,
00186                                          slotid),
00187                         CORBA::NO_MEMORY (
00188                           CORBA::SystemException::_tao_minor_code (
00189                             0,
00190                             ENOMEM),
00191                           CORBA::COMPLETED_NO));
00192 
00193       TAO_ORBInitInfo_var orb_init_info_ = orb_init_info_temp;
00194 
00195       for (size_t i = 0; i < pre_init_count; ++i)
00196         {
00197           this->initializers_[i]->post_init (orb_init_info_.in ());
00198         }
00199 
00200 #if TAO_HAS_INTERCEPTORS == 1
00201       CORBA::Object_ptr picurrent_ptr = orb_core->pi_current ();
00202       PortableInterceptor::SlotId slot_count = orb_init_info_->slot_count ();
00203 
00204       if (CORBA::is_nil (picurrent_ptr) && slot_count != 0)
00205         {
00206           // Force instantiation of the PICurrent object. If we do not do it
00207           // now, the slot count will be lost.
00208           CORBA::Object_var tmp = orb_core->resolve_picurrent ();
00209           picurrent_ptr = orb_core->pi_current ();
00210         }
00211 
00212       if (!CORBA::is_nil (picurrent_ptr))
00213         {
00214           TAO::PICurrent *pi = dynamic_cast <TAO::PICurrent*> (picurrent_ptr);
00215 
00216           if (pi)
00217             {
00218               pi->initialize (slot_count);
00219             }
00220         }
00221 #endif /* TAO_HAS_INTERCEPTORS == 1 */
00222 
00223       // Invalidate the ORBInitInfo instance to prevent future
00224       // modifications to the ORB.  This behavior complies with the
00225       // PortableInterceptor specification.
00226       orb_init_info_temp->invalidate ();
00227     }
00228 }
00229 
00230 TAO_END_VERSIONED_NAMESPACE_DECL
00231 
00232 ACE_STATIC_SVC_DEFINE (ORBInitializer_Registry,
00233                        ACE_TEXT ("ORBInitializer_Registry"),
00234                        ACE_SVC_OBJ_T,
00235                        &ACE_SVC_NAME (ORBInitializer_Registry),
00236                        ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00237                        0)
00238 
00239 ACE_FACTORY_NAMESPACE_DEFINE (TAO_PI, ORBInitializer_Registry, TAO::ORBInitializer_Registry)

Generated on Tue Feb 2 17:42:01 2010 for TAO_PI by  doxygen 1.4.7