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