00001 
00002 
00003 #include "tao/PortableServer/POAManager.h"
00004 #include "tao/PortableServer/POAManagerFactory.h"
00005 #include "tao/PortableServer/Root_POA.h"
00006 #include "tao/PortableServer/poa_macros.h"
00007 #include "tao/Server_Strategy_Factory.h"
00008 #include "tao/ORB_Core.h"
00009 #include "tao/IORInterceptor_Adapter.h"
00010 
00011 #if !defined (__ACE_INLINE__)
00012 # include "tao/PortableServer/POAManager.i"
00013 #endif 
00014 
00015 ACE_RCSID (PortableServer,
00016            POAManager,
00017            "POAManager.cpp,v 1.22 2006/06/20 06:30:34 jwillemsen Exp")
00018 
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 TAO_POA_Manager::TAO_POA_Manager (
00022   TAO_Object_Adapter &object_adapter,
00023   const char * id,
00024   const ::CORBA::PolicyList &policies,
00025   PortableServer::POAManagerFactory_ptr poa_manager_factory)
00026   : state_ (PortableServer::POAManager::HOLDING),
00027     lock_ (object_adapter.lock ()),
00028     poa_collection_ (),
00029     object_adapter_ (object_adapter),
00030     id_ (id == 0 ? this->generate_manager_id () : CORBA::string_dup (id)),
00031 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00032     poa_manager_factory_ (* dynamic_cast <TAO_POAManager_Factory*> (poa_manager_factory)),
00033 #endif
00034     policies_ (policies)
00035 {
00036 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00037   poa_manager_factory_._add_ref ();
00038 #endif
00039 }
00040 
00041 TAO_POA_Manager::~TAO_POA_Manager (void)
00042 {
00043 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00044   poa_manager_factory_._remove_ref ();
00045 #endif
00046 }
00047 
00048 char *
00049 TAO_POA_Manager::get_id (ACE_ENV_SINGLE_ARG_DECL)
00050   ACE_THROW_SPEC ((CORBA::SystemException))
00051 {
00052   return CORBA::string_dup (this->id_.in ());
00053 }
00054 
00055 void
00056 TAO_POA_Manager::activate_i (ACE_ENV_SINGLE_ARG_DECL)
00057   ACE_THROW_SPEC ((CORBA::SystemException,
00058                    PortableServer::POAManager::AdapterInactive))
00059 {
00060   
00061   
00062   
00063   
00064 
00065   if (this->state_ == PortableServer::POAManager::INACTIVE)
00066     {
00067       ACE_THROW (PortableServer::POAManager::AdapterInactive ());
00068     }
00069   else
00070     {
00071       this->state_ = PortableServer::POAManager::ACTIVE;
00072       
00073       
00074 
00075       for (POA_COLLECTION::iterator iterator = this->poa_collection_.begin ();
00076        iterator != this->poa_collection_.end ();
00077        ++iterator)
00078         {
00079           (*iterator)->poa_activated_hook ();
00080         }
00081     }
00082 
00083   this->adapter_manager_state_changed (this->state_
00084                                        ACE_ENV_ARG_PARAMETER);
00085   ACE_CHECK;
00086 }
00087 
00088 void
00089 TAO_POA_Manager::deactivate_i (CORBA::Boolean etherealize_objects,
00090                                CORBA::Boolean wait_for_completion
00091                                ACE_ENV_ARG_DECL)
00092   ACE_THROW_SPEC ((CORBA::SystemException,
00093                    PortableServer::POAManager::AdapterInactive))
00094 {
00095   
00096   TAO_Root_POA::check_for_valid_wait_for_completions (this->object_adapter_.orb_core (),
00097                                                       wait_for_completion
00098                                                       ACE_ENV_ARG_PARAMETER);
00099   ACE_CHECK;
00100 
00101   
00102   
00103   
00104   
00105   
00106 
00107   if (this->state_ == PortableServer::POAManager::INACTIVE)
00108     {
00109       ACE_THROW (PortableServer::POAManager::AdapterInactive ());
00110     }
00111   else
00112     {
00113       this->state_ = PortableServer::POAManager::INACTIVE;
00114     }
00115 
00116   
00117   
00118   
00119   
00120   
00121   
00122   
00123   
00124   
00125   
00126 
00127   
00128   
00129   
00130   
00131   
00132   
00133   
00134   
00135   
00136   
00137   
00138   
00139   
00140   
00141 
00142   for (POA_COLLECTION::iterator iterator = this->poa_collection_.begin ();
00143        iterator != this->poa_collection_.end ();
00144        ++iterator)
00145     {
00146       TAO_Root_POA *poa = *iterator;
00147       
00148       
00149       poa->poa_deactivated_hook ();
00150 
00151       poa->deactivate_all_objects_i (etherealize_objects,
00152                                      wait_for_completion
00153                                      ACE_ENV_ARG_PARAMETER);
00154       ACE_CHECK;
00155     }
00156 
00157   
00158   
00159   
00160   
00161   
00162 
00163   this->adapter_manager_state_changed (this->state_
00164                                        ACE_ENV_ARG_PARAMETER);
00165   ACE_CHECK;
00166 }
00167 
00168 void
00169 TAO_POA_Manager::adapter_manager_state_changed (PortableServer::POAManager::State state
00170                                                 ACE_ENV_ARG_DECL)
00171   ACE_THROW_SPEC ((CORBA::SystemException))
00172 {
00173   PortableInterceptor::AdapterState adapter_state =
00174     static_cast<PortableInterceptor::AdapterState> (state);
00175 
00176   TAO_IORInterceptor_Adapter *ior_adapter =
00177     this->object_adapter_.orb_core ().ior_interceptor_adapter ();
00178 
00179   if (ior_adapter)
00180     {
00181       ior_adapter->adapter_manager_state_changed (this->id_.in (),
00182                                                   adapter_state
00183                                                   ACE_ENV_ARG_PARAMETER);
00184       ACE_CHECK;
00185     }
00186 }
00187 
00188 #if (TAO_HAS_MINIMUM_POA == 0)
00189 
00190 void
00191 TAO_POA_Manager::hold_requests_i (CORBA::Boolean wait_for_completion
00192                                   ACE_ENV_ARG_DECL)
00193   ACE_THROW_SPEC ((CORBA::SystemException,
00194                    PortableServer::POAManager::AdapterInactive))
00195 {
00196   
00197   TAO_Root_POA::check_for_valid_wait_for_completions (this->object_adapter_.orb_core (),
00198                                                       wait_for_completion
00199                                                       ACE_ENV_ARG_PARAMETER);
00200   ACE_CHECK;
00201 
00202   
00203   
00204   
00205   
00206   
00207   
00208   
00209 
00210   if (this->state_ == PortableServer::POAManager::INACTIVE)
00211     {
00212       ACE_THROW (PortableServer::POAManager::AdapterInactive ());
00213     }
00214   else
00215     {
00216       this->state_ = PortableServer::POAManager::HOLDING;
00217     }
00218 
00219   
00220   
00221   
00222   
00223   
00224   
00225   
00226   
00227   
00228   
00229   
00230   
00231 
00232   if (wait_for_completion)
00233     {
00234       for (POA_COLLECTION::iterator iterator = this->poa_collection_.begin ();
00235            iterator != this->poa_collection_.end ();
00236            ++iterator)
00237         {
00238           TAO_Root_POA *poa = *iterator;
00239           poa->wait_for_completions (wait_for_completion
00240                                      ACE_ENV_ARG_PARAMETER);
00241           ACE_CHECK;
00242         }
00243     }
00244 
00245   this->adapter_manager_state_changed (this->state_
00246                                        ACE_ENV_ARG_PARAMETER);
00247   ACE_CHECK;
00248 }
00249 
00250 void
00251 TAO_POA_Manager::discard_requests_i (CORBA::Boolean wait_for_completion
00252                                      ACE_ENV_ARG_DECL)
00253   ACE_THROW_SPEC ((CORBA::SystemException,
00254                    PortableServer::POAManager::AdapterInactive))
00255 {
00256   
00257   TAO_Root_POA::check_for_valid_wait_for_completions (this->object_adapter_.orb_core (),
00258                                                       wait_for_completion
00259                                                       ACE_ENV_ARG_PARAMETER);
00260   ACE_CHECK;
00261 
00262   
00263   
00264   
00265   
00266   
00267   
00268   
00269   
00270 
00271   if (this->state_ == PortableServer::POAManager::INACTIVE)
00272     {
00273       ACE_THROW (PortableServer::POAManager::AdapterInactive ());
00274     }
00275   else
00276     {
00277       this->state_ = PortableServer::POAManager::DISCARDING;
00278     }
00279 
00280   
00281   
00282   
00283   
00284   
00285   
00286   
00287   
00288   
00289   
00290   
00291   
00292   
00293 
00294   if (wait_for_completion)
00295     {
00296       for (POA_COLLECTION::iterator iterator = this->poa_collection_.begin ();
00297            iterator != this->poa_collection_.end ();
00298            ++iterator)
00299         {
00300           TAO_Root_POA *poa = *iterator;
00301           poa->wait_for_completions (wait_for_completion
00302                                      ACE_ENV_ARG_PARAMETER);
00303           ACE_CHECK;
00304         }
00305     }
00306 
00307   this->adapter_manager_state_changed (this->state_
00308                                        ACE_ENV_ARG_PARAMETER);
00309 }
00310 
00311 #endif 
00312 
00313 int
00314 TAO_POA_Manager::remove_poa (TAO_Root_POA *poa)
00315 {
00316   int const result = this->poa_collection_.remove (poa);
00317 
00318   if (result == 0)
00319     {
00320       if (this->poa_collection_.is_empty ())
00321         {
00322 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00323           this->poa_manager_factory_.remove_poamanager (this);
00324 #endif
00325         }
00326     }
00327 
00328   return result;
00329 }
00330 
00331 int
00332 TAO_POA_Manager::register_poa (TAO_Root_POA *poa)
00333 {
00334   return this->poa_collection_.insert (poa);
00335 }
00336 
00337 void
00338 TAO_POA_Manager::check_state (ACE_ENV_SINGLE_ARG_DECL)
00339 {
00340   if (state_ == PortableServer::POAManager::ACTIVE)
00341     {
00342       
00343       
00344       
00345       return;
00346     }
00347 
00348   if (state_ == PortableServer::POAManager::DISCARDING)
00349     {
00350       
00351       
00352       
00353       
00354       
00355       
00356       
00357       
00358       ACE_THROW (
00359         CORBA::TRANSIENT (
00360           CORBA::SystemException::_tao_minor_code (
00361             TAO_POA_DISCARDING,
00362             1),
00363           CORBA::COMPLETED_NO));
00364     }
00365 
00366   if (state_ == PortableServer::POAManager::HOLDING)
00367     {
00368       
00369       
00370       
00371       
00372       
00373       
00374       
00375       
00376 
00377       
00378       
00379       ACE_THROW (CORBA::TRANSIENT (
00380         CORBA::SystemException::_tao_minor_code (
00381           TAO_POA_HOLDING,
00382           1),
00383         CORBA::COMPLETED_NO));
00384     }
00385 
00386   if (state_ == PortableServer::POAManager::INACTIVE)
00387     {
00388       
00389       
00390       
00391       
00392       
00393       
00394       
00395       
00396       
00397       
00398       
00399       ACE_THROW (CORBA::OBJ_ADAPTER (
00400         CORBA::SystemException::_tao_minor_code (
00401           TAO_POA_INACTIVE,
00402           1),
00403         CORBA::COMPLETED_NO));
00404     }
00405 }
00406 
00407 CORBA::ORB_ptr
00408 TAO_POA_Manager::_get_orb (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00409 {
00410   return CORBA::ORB::_duplicate (this->object_adapter_.orb_core ().orb ());
00411 }
00412 
00413 TAO_END_VERSIONED_NAMESPACE_DECL