Root_POA.cpp

Go to the documentation of this file.
00001 // Root_POA.cpp,v 1.31 2006/06/20 07:17:26 jwillemsen Exp
00002 
00003 #include "tao/PortableServer/Root_POA.h"
00004 #include "tao/PortableServer/Regular_POA.h"
00005 
00006 #include "tao/PortableServer/ThreadPolicy.h"
00007 #include "tao/PortableServer/LifespanPolicy.h"
00008 #include "tao/PortableServer/IdAssignmentPolicy.h"
00009 #include "tao/PortableServer/IdUniquenessPolicy.h"
00010 #include "tao/PortableServer/ImplicitActivationPolicy.h"
00011 #include "tao/PortableServer/RequestProcessingPolicy.h"
00012 #include "tao/PortableServer/ServantRetentionPolicy.h"
00013 #include "tao/PortableServer/Active_Object_Map.h"
00014 #include "tao/PortableServer/Default_Acceptor_Filter.h"
00015 #include "tao/PortableServer/ORT_Adapter.h"
00016 #include "tao/PortableServer/ORT_Adapter_Factory.h"
00017 #include "tao/PortableServer/POA_Current_Impl.h"
00018 #include "tao/PortableServer/Servant_Upcall.h"
00019 #include "tao/PortableServer/AdapterActivatorC.h"
00020 #include "tao/PortableServer/Non_Servant_Upcall.h"
00021 #include "tao/PortableServer/POAManager.h"
00022 #include "tao/PortableServer/POAManagerFactory.h"
00023 #include "tao/PortableServer/ServantManagerC.h"
00024 #include "tao/PortableServer/poa_macros.h"
00025 #include "tao/PortableServer/POA_Guard.h"
00026 #include "tao/PortableServer/Creation_Time.h"
00027 #include "tao/PortableServer/RequestProcessingStrategy.h"
00028 #include "tao/PortableServer/LifespanStrategy.h"
00029 #include "tao/PortableServer/IdUniquenessStrategy.h"
00030 #include "tao/PortableServer/IdAssignmentStrategy.h"
00031 #include "tao/PortableServer/ServantRetentionStrategy.h"
00032 #include "tao/PortableServer/ImplicitActivationStrategy.h"
00033 #include "tao/PortableServer/ThreadStrategy.h"
00034 #include "tao/PortableServer/Acceptor_Filter_Factory.h"
00035 
00036 #include "tao/StringSeqC.h"
00037 #include "tao/PortableInterceptorC.h"
00038 #include "tao/PolicyC.h"
00039 #include "tao/ORB_Core.h"
00040 #include "tao/ORB.h"
00041 #include "tao/Server_Strategy_Factory.h"
00042 #include "tao/Acceptor_Registry.h"
00043 #include "tao/Thread_Lane_Resources.h"
00044 #include "tao/Environment.h"
00045 #include "tao/Exception.h"
00046 #include "tao/Stub.h"
00047 #include "tao/Profile.h"
00048 #include "tao/TSS_Resources.h"
00049 #include "tao/IORInterceptor_Adapter.h"
00050 #include "tao/debug.h"
00051 
00052 // auto_ptr class
00053 #include "ace/Auto_Ptr.h"
00054 #include "ace/Dynamic_Service.h"
00055 #include "ace/OS_NS_netdb.h"
00056 #include "ace/OS_NS_string.h"
00057 #include "ace/OS_NS_unistd.h"
00058 #include "ace/Log_Msg.h"
00059 
00060 #if !defined (__ACE_INLINE__)
00061 # include "tao/PortableServer/Root_POA.inl"
00062 #endif /* ! __ACE_INLINE__ */
00063 
00064 ACE_RCSID (PortableServer,
00065            Root_POA,
00066            "Root_POA.cpp,v 1.31 2006/06/20 07:17:26 jwillemsen Exp")
00067 
00068 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00069 
00070 // This is the TAO_Object_key-prefix that is appended to all TAO Object keys.
00071 // It's an array of octets representing ^t^a^o/0 in octal.
00072 CORBA::Octet const
00073 TAO_Root_POA::objectkey_prefix [TAO_Root_POA::TAO_OBJECTKEY_PREFIX_SIZE] = {
00074   024, // octal for ^t
00075   001, // octal for ^a
00076   017, // octal for ^o
00077   000
00078 };
00079 
00080 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00081 
00082 PortableServer::ThreadPolicy_ptr
00083 TAO_Root_POA::create_thread_policy (PortableServer::ThreadPolicyValue value
00084                                     ACE_ENV_ARG_DECL)
00085   ACE_THROW_SPEC ((CORBA::SystemException))
00086 {
00087   TAO::Portable_Server::ThreadPolicy *policy = 0;
00088   ACE_NEW_THROW_EX (policy,
00089                     TAO::Portable_Server::ThreadPolicy (value),
00090                     CORBA::NO_MEMORY ());
00091   ACE_CHECK_RETURN (PortableServer::ThreadPolicy::_nil ());
00092 
00093   return policy;
00094 }
00095 
00096 #endif /* TAO_HAS_MINIMUM_POA == 0 && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO) */
00097 
00098 #if !defined (CORBA_E_MICRO)
00099 
00100 PortableServer::LifespanPolicy_ptr
00101 TAO_Root_POA::create_lifespan_policy (PortableServer::LifespanPolicyValue value
00102                                       ACE_ENV_ARG_DECL)
00103   ACE_THROW_SPEC ((CORBA::SystemException))
00104 {
00105   TAO::Portable_Server::LifespanPolicy *policy = 0;
00106   ACE_NEW_THROW_EX (policy,
00107                     TAO::Portable_Server::LifespanPolicy (value),
00108                     CORBA::NO_MEMORY ());
00109   ACE_CHECK_RETURN (PortableServer::LifespanPolicy::_nil ());
00110 
00111   return policy;
00112 }
00113 
00114 #endif
00115 
00116 #if !defined (CORBA_E_MICRO)
00117 PortableServer::IdUniquenessPolicy_ptr
00118 TAO_Root_POA::create_id_uniqueness_policy (PortableServer::IdUniquenessPolicyValue value
00119                                            ACE_ENV_ARG_DECL)
00120   ACE_THROW_SPEC ((CORBA::SystemException))
00121 {
00122   TAO::Portable_Server::IdUniquenessPolicy *policy = 0;
00123   ACE_NEW_THROW_EX (policy,
00124                     TAO::Portable_Server::IdUniquenessPolicy (value),
00125                     CORBA::NO_MEMORY ());
00126   ACE_CHECK_RETURN (PortableServer::IdUniquenessPolicy::_nil ());
00127 
00128   return policy;
00129 }
00130 #endif
00131 
00132 #if !defined (CORBA_E_MICRO)
00133 PortableServer::IdAssignmentPolicy_ptr
00134 TAO_Root_POA::create_id_assignment_policy (PortableServer::IdAssignmentPolicyValue value
00135                                            ACE_ENV_ARG_DECL)
00136   ACE_THROW_SPEC ((CORBA::SystemException))
00137 {
00138   TAO::Portable_Server::IdAssignmentPolicy *policy = 0;
00139   ACE_NEW_THROW_EX (policy,
00140                     TAO::Portable_Server::IdAssignmentPolicy (value),
00141                     CORBA::NO_MEMORY ());
00142   ACE_CHECK_RETURN (PortableServer::IdAssignmentPolicy::_nil ());
00143 
00144   return policy;
00145 }
00146 #endif
00147 
00148 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00149 
00150 PortableServer::ImplicitActivationPolicy_ptr
00151 TAO_Root_POA::create_implicit_activation_policy (PortableServer::ImplicitActivationPolicyValue value
00152                                                  ACE_ENV_ARG_DECL)
00153   ACE_THROW_SPEC ((CORBA::SystemException))
00154 {
00155   TAO::Portable_Server::ImplicitActivationPolicy *policy = 0;
00156   ACE_NEW_THROW_EX (policy,
00157                     TAO::Portable_Server::ImplicitActivationPolicy (value),
00158                     CORBA::NO_MEMORY ());
00159   ACE_CHECK_RETURN (PortableServer::ImplicitActivationPolicy::_nil ());
00160 
00161   return policy;
00162 }
00163 
00164 PortableServer::ServantRetentionPolicy_ptr
00165 TAO_Root_POA::create_servant_retention_policy (PortableServer::ServantRetentionPolicyValue value
00166                                                ACE_ENV_ARG_DECL)
00167   ACE_THROW_SPEC ((CORBA::SystemException))
00168 {
00169   TAO::Portable_Server::ServantRetentionPolicy *policy = 0;
00170   ACE_NEW_THROW_EX (policy,
00171                     TAO::Portable_Server::ServantRetentionPolicy (value),
00172                     CORBA::NO_MEMORY ());
00173   ACE_CHECK_RETURN (PortableServer::ServantRetentionPolicy::_nil ());
00174 
00175   return policy;
00176 }
00177 
00178 PortableServer::RequestProcessingPolicy_ptr
00179 TAO_Root_POA::create_request_processing_policy (PortableServer::RequestProcessingPolicyValue value
00180                                                 ACE_ENV_ARG_DECL)
00181   ACE_THROW_SPEC ((CORBA::SystemException))
00182 {
00183   TAO::Portable_Server::RequestProcessingPolicy *policy = 0;
00184   ACE_NEW_THROW_EX (policy,
00185                     TAO::Portable_Server::RequestProcessingPolicy (value),
00186                     CORBA::NO_MEMORY ());
00187   ACE_CHECK_RETURN (PortableServer::RequestProcessingPolicy::_nil ());
00188 
00189   return policy;
00190 }
00191 
00192 #endif /* TAO_HAS_MINIMUM_POA == 0 */
00193 
00194 void
00195 TAO_Root_POA::set_obj_ref_factory (
00196   PortableInterceptor::ObjectReferenceFactory *current_factory
00197   ACE_ENV_ARG_DECL)
00198 {
00199   TAO::ORT_Adapter *adapter = this->ORT_adapter (ACE_ENV_SINGLE_ARG_PARAMETER);
00200   ACE_CHECK;
00201 
00202   if (adapter)
00203     {
00204       // Activate a different factory
00205       this->ort_adapter_->set_obj_ref_factory (current_factory
00206                                                ACE_ENV_ARG_PARAMETER);
00207       ACE_CHECK;
00208     }
00209 }
00210 
00211 TAO_Root_POA::TAO_Root_POA (const TAO_Root_POA::String &name,
00212                             PortableServer::POAManager_ptr poa_manager,
00213                             const TAO_POA_Policy_Set &policies,
00214                             TAO_Root_POA *parent,
00215                             ACE_Lock &lock,
00216                             TAO_SYNCH_MUTEX &thread_lock,
00217                             TAO_ORB_Core &orb_core,
00218                             TAO_Object_Adapter *object_adapter
00219                             ACE_ENV_ARG_DECL)
00220   : name_ (name),
00221     poa_manager_ (* (dynamic_cast <TAO_POA_Manager*> (poa_manager))),
00222     poa_manager_factory_ (* (object_adapter->poa_manager_factory_)),
00223     tagged_component_ (),
00224     tagged_component_id_ (),
00225     profile_id_array_ (0),
00226     policies_ (policies),
00227     ort_adapter_ (0),
00228     adapter_state_ (PortableInterceptor::HOLDING),
00229 
00230 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00231 
00232     adapter_activator_ (),
00233 
00234 #endif /* TAO_HAS_MINIMUM_POA == 0 */
00235 
00236     children_ (),
00237     lock_ (lock),
00238     orb_core_ (orb_core),
00239     object_adapter_ (object_adapter),
00240     cleanup_in_progress_ (0),
00241     outstanding_requests_ (0),
00242     outstanding_requests_condition_ (thread_lock),
00243     wait_for_completion_pending_ (0),
00244     waiting_destruction_ (0),
00245     servant_deactivation_condition_ (thread_lock),
00246     filter_factory_ (0),
00247     caller_key_to_object_ (0),
00248     servant_for_key_to_object_ (0)
00249 {
00250   // Parse the policies that are used in the critical path in
00251   // a cache.
00252   this->cached_policies_.update (this->policies_
00253                                  ACE_ENV_ARG_PARAMETER);
00254   ACE_CHECK;
00255 
00256 #if (TAO_HAS_MINIMUM_POA == 1)
00257   // If this is the RootPOA, set the value of the ImplicitActivationPolicy
00258   // to IMPLICIT_ACTIVATION since it is impossible to pass the policy
00259   // as it is not compiled into the library.
00260   //
00261   // If the ImplicitActivationPolicy policy is ever compiled in the
00262   // minimum POA builds, remove this code and remove the guards
00263   // in Object_Adapter.cpp when changing the default policy for the
00264   // RootPOA.
00265   if (ACE_OS::strcmp (this->name_.c_str (),
00266                       TAO_DEFAULT_ROOTPOA_NAME) == 0)
00267     {
00268       this->cached_policies_.implicit_activation
00269         (PortableServer::IMPLICIT_ACTIVATION);
00270     }
00271 #endif /* TAO_HAS_MINIMUM_POA == 1 */
00272 
00273   // Set the active strategies to be used by this POA
00274   this->active_policy_strategies_.update (this->cached_policies_,
00275                                           this
00276                                           ACE_ENV_ARG_PARAMETER);
00277   ACE_CHECK;
00278 
00279   // Set the folded name of this POA.
00280   this->set_folded_name (parent);
00281 
00282   // Register self with manager.
00283   int result = this->poa_manager_.register_poa (this);
00284   if (result != 0)
00285     {
00286       ACE_THROW (CORBA::OBJ_ADAPTER ());
00287     }
00288 
00289   // Add self to Object Adapter class.
00290   result =
00291     this->object_adapter ().bind_poa (this->folded_name_,
00292                                       this,
00293                                       this->system_name_.out ());
00294   if (result != 0)
00295     {
00296       // Remove from POA Manager in case of errors. No checks of
00297       // further errors...
00298       this->poa_manager_.remove_poa (this);
00299 
00300       ACE_THROW (CORBA::OBJ_ADAPTER ());
00301     }
00302 
00303   // Set the id for this POA.
00304   this->set_id (parent);
00305 
00306   // Notify the Lifespan strategy of our startup
00307   ACE_TRY
00308     {
00309       this->active_policy_strategies_.lifespan_strategy()->notify_startup (ACE_ENV_SINGLE_ARG_PARAMETER);
00310       ACE_TRY_CHECK;
00311     }
00312   ACE_CATCHANY
00313     {
00314       this->poa_manager_.remove_poa (this);
00315       this->object_adapter ().unbind_poa (this,
00316                                           this->folded_name_,
00317                                           this->system_name_.in ());
00318       ACE_RE_THROW;
00319     }
00320   ACE_ENDTRY;
00321   ACE_CHECK;
00322 }
00323 
00324 TAO_Root_POA::~TAO_Root_POA (void)
00325 {
00326 }
00327 
00328 void
00329 TAO_Root_POA::complete_destruction_i (ACE_ENV_SINGLE_ARG_DECL)
00330 {
00331   // No longer awaiting destruction.
00332   this->waiting_destruction_ = 0;
00333 
00334   // Remove POA from the POAManager.
00335   int result = this->poa_manager_.remove_poa (this);
00336 
00337   if (result != 0)
00338     ACE_THROW (CORBA::OBJ_ADAPTER ());
00339 
00340   // Remove POA from the Object Adapter.
00341   result = this->object_adapter ().unbind_poa (this,
00342                                                this->folded_name_,
00343                                                this->system_name_.in ());
00344   if (result != 0)
00345     ACE_THROW (CORBA::OBJ_ADAPTER ());
00346 
00347   // Cleanup all strategies
00348   this->active_policy_strategies_.cleanup (ACE_ENV_SINGLE_ARG_PARAMETER);
00349   ACE_CHECK;
00350 
00351   // Forced cleanup.  The new memory management scheme is evil and can
00352   // lead to reference deadlock, i.e., POA holds object A, but POA
00353   // cannot die because object A hold POA.
00354   {
00355     //
00356     // If new things are added to this cleanup code, make sure to move
00357     // the minimum CORBA #define after the declaration of
00358     // <non_servant_upcall>.
00359     //
00360 
00361 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00362 
00363     // ATTENTION: Trick locking here, see class header for details
00364     TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*this);
00365     ACE_UNUSED_ARG (non_servant_upcall);
00366 
00367     this->adapter_activator_ = PortableServer::AdapterActivator::_nil ();
00368 
00369 #endif /* TAO_HAS_MINIMUM_POA == 0 */
00370 
00371   }
00372 
00373   ::CORBA::release (this);
00374 }
00375 
00376 #if ! defined (CORBA_E_MICRO)
00377 PortableServer::POA_ptr
00378 TAO_Root_POA::create_POA_i (const char *adapter_name,
00379                             PortableServer::POAManager_ptr poa_manager,
00380                             const CORBA::PolicyList &policies
00381                             ACE_ENV_ARG_DECL)
00382   ACE_THROW_SPEC ((CORBA::SystemException,
00383                    PortableServer::POA::AdapterAlreadyExists,
00384                    PortableServer::POA::InvalidPolicy))
00385 {
00386   // Initialize a TAO_POA_Policy_Set instance so that it contains the
00387   // default POA policies.
00388   TAO_POA_Policy_Set tao_policies (this->object_adapter ().default_poa_policies ());
00389 
00390   // Merge policies from the ORB level.
00391   this->object_adapter ().validator ().merge_policies (tao_policies.policies ()
00392                                                        ACE_ENV_ARG_PARAMETER);
00393   ACE_CHECK_RETURN (PortableServer::POA::_nil ());
00394 
00395   // Merge in any policies that the user may have specified.
00396   tao_policies.merge_policies (policies
00397                                ACE_ENV_ARG_PARAMETER);
00398   ACE_CHECK_RETURN (PortableServer::POA::_nil ());
00399 
00400   // If any of the policy objects specified are not valid for the ORB
00401   // implementation, if conflicting policy objects are specified, or
00402   // if any of the specified policy objects require prior
00403   // administrative action that has not been performed, an
00404   // InvalidPolicy exception is raised containing the index in the
00405   // policies parameter value of the first offending policy object.
00406   tao_policies.validate_policies (this->object_adapter ().validator (),
00407                                   this->orb_core_
00408                                   ACE_ENV_ARG_PARAMETER);
00409   ACE_CHECK_RETURN (PortableServer::POA::_nil ());
00410 
00411   // If the poa_manager parameter is null, a new POAManager object is
00412   // created and associated with the new POA. Otherwise, the specified
00413   // POAManager object is associated with the new POA. The POAManager
00414   // object can be obtained using the attribute name the_POAManager.
00415 
00416   PortableServer::POAManager_var the_poa_manager;
00417 
00418   if (CORBA::is_nil (poa_manager))
00419     {
00420       PortableServer::POA_var poa = PortableServer::POA::_duplicate (this);
00421       PortableServer::POA_var root_poa;
00422 
00423       // Find the RootPOA by traversing the POA hierarchy until the
00424       // RootPOA is reached.  The RootPOA has no parent.
00425       while (!CORBA::is_nil (poa.in ()))
00426       {
00427         root_poa = poa;
00428         poa = poa->the_parent (ACE_ENV_SINGLE_ARG_PARAMETER);
00429         ACE_CHECK_RETURN (PortableServer::POA::_nil ());
00430       }
00431 
00432       // Get the POAManagerFactory instance owned by RootPOA.
00433       PortableServer::POAManagerFactory_var tao_poa_manager_factory
00434         = root_poa->the_POAManagerFactory ();
00435 
00436       CORBA::PolicyList empty_policies;
00437       // The POAManager name will be generated when the POAManager instance
00438       // is created.
00439       the_poa_manager
00440         = tao_poa_manager_factory->create_POAManager (0,
00441                                                       empty_policies
00442                                                       ACE_ENV_ARG_PARAMETER);
00443       ACE_CHECK_RETURN (PortableServer::POA::_nil ());
00444     }
00445   else
00446     {
00447       the_poa_manager = PortableServer::POAManager::_duplicate (poa_manager);
00448     }
00449 
00450   PortableServer::POA_var poa = this->create_POA_i (adapter_name,
00451                                                     the_poa_manager.in (),
00452                                                     tao_policies
00453                                                     ACE_ENV_ARG_PARAMETER);
00454   ACE_CHECK_RETURN (PortableServer::POA::_nil ());
00455 
00456   return poa._retn ();
00457 }
00458 #endif
00459 
00460 TAO_Root_POA *
00461 TAO_Root_POA::new_POA (const String &name,
00462                        PortableServer::POAManager_ptr poa_manager,
00463                        const TAO_POA_Policy_Set &policies,
00464                        TAO_Root_POA *parent,
00465                        ACE_Lock &lock,
00466                        TAO_SYNCH_MUTEX &thread_lock,
00467                        TAO_ORB_Core &orb_core,
00468                        TAO_Object_Adapter *object_adapter
00469                        ACE_ENV_ARG_DECL)
00470 {
00471   TAO_Regular_POA *poa = 0;
00472 
00473   ACE_NEW_THROW_EX (poa,
00474                     TAO_Regular_POA (name,
00475                              poa_manager,
00476                              policies,
00477                              parent,
00478                              lock,
00479                              thread_lock,
00480                              orb_core,
00481                              object_adapter
00482                              ACE_ENV_ARG_PARAMETER),
00483                     CORBA::NO_MEMORY ());
00484   ACE_CHECK_RETURN (0);
00485 
00486   return poa;
00487 }
00488 
00489 #if ! defined (CORBA_E_MICRO)
00490 PortableServer::POA_ptr
00491 TAO_Root_POA::create_POA_i (const TAO_Root_POA::String &adapter_name,
00492                             PortableServer::POAManager_ptr poa_manager,
00493                             const TAO_POA_Policy_Set &policies
00494                             ACE_ENV_ARG_DECL)
00495   ACE_THROW_SPEC ((CORBA::SystemException,
00496                    PortableServer::POA::AdapterAlreadyExists,
00497                    PortableServer::POA::InvalidPolicy))
00498 {
00499   // This operaton creates a new POA as a child of the target POA. The
00500   // specified name identifies the new POA with respect to other POAs
00501   // with the same parent POA. If the target POA already has a child
00502   // POA with the specified name, the AdapterAlreadyExists exception
00503   // is raised.
00504   int result = this->children_.find (adapter_name);
00505 
00506   // Child was found
00507   if (result != -1)
00508     {
00509       ACE_THROW_RETURN (PortableServer::POA::AdapterAlreadyExists (),
00510                         PortableServer::POA::_nil ());
00511     }
00512 
00513   //
00514   // Child was not found.  Create one.
00515   //
00516 
00517   // The specified policy objects are associated with the POA and used
00518   // to control its behavior. The policy objects are effectively
00519   // copied before this operation returns, so the application is free
00520   // to destroy them while the POA is in use. Policies are not
00521   // inherited from the parent POA.
00522   TAO_Root_POA * poa = this->new_POA (adapter_name,
00523                                       poa_manager,
00524                                       policies,
00525                                       this,
00526                                       this->object_adapter ().lock (),
00527                                       this->object_adapter ().thread_lock (),
00528                                       this->orb_core_,
00529                                       this->object_adapter_
00530                                       ACE_ENV_ARG_PARAMETER);
00531 
00532   // Give ownership of the new map to the POA_var.  Note, that it
00533   // is important for the POA_var to take ownership before
00534   // checking for exception since we may need to delete the new map.
00535   PortableServer::POA_var new_poa = poa;
00536 
00537   // Check for exception in construction of the POA.
00538   ACE_CHECK_RETURN (PortableServer::POA::_nil ());
00539 
00540   // Add to children map
00541   result = this->children_.bind (adapter_name,
00542                                  poa);
00543   if (result != 0)
00544     {
00545       ACE_THROW_RETURN (CORBA::OBJ_ADAPTER (),
00546                         PortableServer::POA::_nil ());
00547     }
00548 
00549   // Increment the reference count on the child POA since the children
00550   // map must retain ownership.  Do so immediately before any other
00551   // operations to prevent memory cleanup problems induced from
00552   // errors below.
00553   poa->_add_ref ();
00554 
00555   // Iterate over the registered IOR interceptors so that they may be
00556   // given the opportunity to add tagged components to the profiles
00557   // for this servant.
00558   poa->establish_components (ACE_ENV_SINGLE_ARG_PARAMETER);
00559   ACE_CHECK_RETURN (PortableServer::POA::_nil ());
00560 
00561   // Note: Creating a POA using a POA manager that is in the active
00562   // state can lead to race conditions if the POA supports preexisting
00563   // objects, because the new POA may receive a request before its
00564   // adapter activator, servant manager, or default servant have been
00565   // initialized. These problems do not occur if the POA is created by
00566   // an adapter activator registered with a parent of the new POA,
00567   // because requests are queued until the adapter activator
00568   // returns. To avoid these problems when a POA must be explicitly
00569   // initialized, the application can initialize the POA by invoking
00570   // find_POA with a TRUE activate parameter.
00571 
00572   // Everything is fine. Don't let the POA_var release the
00573   // implementation.
00574   return new_poa._retn ();
00575 }
00576 #endif
00577 
00578 #if ! defined (CORBA_E_MICRO)
00579 PortableServer::POA_ptr
00580 TAO_Root_POA::find_POA (const char *adapter_name,
00581                         CORBA::Boolean activate_it
00582                         ACE_ENV_ARG_DECL)
00583   ACE_THROW_SPEC ((CORBA::SystemException,
00584                    PortableServer::POA::AdapterNonExistent))
00585 {
00586   // Lock access for the duration of this transaction.
00587   TAO_POA_GUARD_RETURN (0);
00588 
00589   TAO_Root_POA *poa = this->find_POA_i (adapter_name,
00590                                    activate_it
00591                                    ACE_ENV_ARG_PARAMETER);
00592   ACE_CHECK_RETURN (PortableServer::POA::_nil ());
00593 
00594   return PortableServer::POA::_duplicate (poa);
00595 }
00596 #endif
00597 
00598 #if ! defined (CORBA_E_MICRO)
00599 TAO_Root_POA *
00600 TAO_Root_POA::find_POA_i (const ACE_CString &child_name,
00601                      CORBA::Boolean activate_it
00602                      ACE_ENV_ARG_DECL)
00603   ACE_THROW_SPEC ((CORBA::SystemException,
00604                    PortableServer::POA::AdapterNonExistent))
00605 {
00606   TAO_Root_POA *child = 0;
00607   int result = this->children_.find (child_name,
00608                                      child);
00609 
00610 #if (TAO_HAS_MINIMUM_POA == 0)
00611 
00612   if (result != 0)
00613     {
00614       if (activate_it)
00615         {
00616           if (!CORBA::is_nil (this->adapter_activator_.in ()))
00617             {
00618               // Check our state
00619               this->check_state (ACE_ENV_SINGLE_ARG_PARAMETER);
00620               ACE_CHECK_RETURN (0);
00621 
00622               CORBA::Boolean success = false;
00623               ACE_TRY_EX (UnknownAdapter)
00624                 {
00625                   // ATTENTION: Trick locking here, see class header for details
00626                   TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (
00627                     *this);
00628                   ACE_UNUSED_ARG (non_servant_upcall);
00629 
00630                   // When unknown_adapter gives a system exception, the POA
00631                   // should raise OBJ_ADAPTER with standard minor code 1.
00632                   // See 11.3.9.2 of the Corba spec
00633                   success =
00634                     this->adapter_activator_->unknown_adapter (
00635                       this,
00636                       child_name.c_str ()
00637                       ACE_ENV_ARG_PARAMETER);
00638                   ACE_TRY_CHECK_EX (UnknownAdapter);
00639                 }
00640               ACE_CATCH (CORBA::SystemException, ex)
00641                 {
00642                   ACE_TRY_THROW_EX (CORBA::OBJ_ADAPTER (CORBA::OMGVMCID | 1,
00643                                     CORBA::COMPLETED_NO),
00644                                     UnknownAdapter);
00645                 }
00646               ACE_ENDTRY;
00647               ACE_CHECK_RETURN (0);
00648 
00649               if (success)
00650                 {
00651                   result = this->children_.find (child_name,
00652                                                  child);
00653                 }
00654               else
00655                 {
00656                   result = -1;
00657                 }
00658             }
00659           else
00660             {
00661               result = -1;
00662             }
00663         }
00664       else
00665         {
00666           result = -1;
00667         }
00668     }
00669 #else
00670   ACE_UNUSED_ARG (activate_it);
00671 #endif /* TAO_HAS_MINIMUM_POA == 0 */
00672 
00673   if (result == 0)
00674     {
00675       return child;
00676     }
00677   else
00678     {
00679       // Otherwise, the AdapterNonExistent exception is raised.
00680       ACE_THROW_RETURN (PortableServer::POA::AdapterNonExistent (),
00681                         0);
00682     }
00683 }
00684 #endif
00685 
00686 TAO_POA_Manager &
00687 TAO_Root_POA::tao_poa_manager ()
00688 {
00689   return poa_manager_;
00690 }
00691 
00692 #if ! defined (CORBA_E_MICRO)
00693 PortableServer::POA_ptr
00694 TAO_Root_POA::create_POA (const char *adapter_name,
00695                           PortableServer::POAManager_ptr poa_manager,
00696                           const CORBA::PolicyList &policies
00697                           ACE_ENV_ARG_DECL)
00698   ACE_THROW_SPEC ((CORBA::SystemException,
00699                    PortableServer::POA::AdapterAlreadyExists,
00700                    PortableServer::POA::InvalidPolicy))
00701 {
00702   // Lock access for the duration of this transaction.
00703   TAO_POA_GUARD_RETURN (0);
00704 
00705   return this->create_POA_i (adapter_name,
00706                              poa_manager,
00707                              policies
00708                              ACE_ENV_ARG_PARAMETER);
00709 }
00710 #endif
00711 
00712 PortableServer::ObjectId *
00713 TAO_Root_POA::servant_to_id (PortableServer::Servant servant
00714                              ACE_ENV_ARG_DECL)
00715   ACE_THROW_SPEC ((CORBA::SystemException,
00716                    PortableServer::POA::ServantNotActive,
00717                    PortableServer::POA::WrongPolicy))
00718 {
00719   // If we had upgradeable locks, this would initially be a read lock
00720   //
00721   // Lock access for the duration of this transaction.
00722   TAO_POA_GUARD_RETURN (0);
00723 
00724   return this->servant_to_id_i (servant
00725                                 ACE_ENV_ARG_PARAMETER);
00726 }
00727 
00728 PortableServer::ObjectId *
00729 TAO_Root_POA::servant_to_user_id (PortableServer::Servant servant
00730                                   ACE_ENV_ARG_DECL)
00731   ACE_THROW_SPEC ((CORBA::SystemException,
00732                    PortableServer::POA::ServantNotActive,
00733                    PortableServer::POA::WrongPolicy))
00734 {
00735   return this->active_policy_strategies_.servant_retention_strategy()->
00736     servant_to_user_id (servant ACE_ENV_ARG_PARAMETER);
00737 }
00738 
00739 PortableServer::Servant
00740 TAO_Root_POA::reference_to_servant (CORBA::Object_ptr reference
00741                                     ACE_ENV_ARG_DECL)
00742   ACE_THROW_SPEC ((CORBA::SystemException,
00743                    PortableServer::POA::ObjectNotActive,
00744                    PortableServer::POA::WrongAdapter,
00745                    PortableServer::POA::WrongPolicy))
00746 {
00747   // Lock access for the duration of this transaction.
00748   TAO_POA_GUARD_RETURN (0);
00749 
00750   return this->reference_to_servant_i (reference
00751                                        ACE_ENV_ARG_PARAMETER);
00752 }
00753 
00754 CORBA::Object_ptr
00755 TAO_Root_POA::servant_to_reference (PortableServer::Servant servant
00756                                     ACE_ENV_ARG_DECL)
00757   ACE_THROW_SPEC ((CORBA::SystemException,
00758                    PortableServer::POA::ServantNotActive,
00759                    PortableServer::POA::WrongPolicy))
00760 {
00761   TAO_POA_GUARD_RETURN (CORBA::Object::_nil ());
00762 
00763   return this->servant_to_reference_i (servant
00764                                        ACE_ENV_ARG_PARAMETER);
00765 }
00766 
00767 PortableServer::POAList *
00768 TAO_Root_POA::the_children (ACE_ENV_SINGLE_ARG_DECL)
00769   ACE_THROW_SPEC ((CORBA::SystemException))
00770 {
00771   // Lock access for the duration of this transaction.
00772   TAO_POA_GUARD_RETURN (0);
00773 
00774   return this->the_children_i (ACE_ENV_SINGLE_ARG_PARAMETER);
00775 }
00776 
00777 
00778 PortableServer::Servant
00779 TAO_Root_POA::id_to_servant (const PortableServer::ObjectId &oid
00780                              ACE_ENV_ARG_DECL)
00781   ACE_THROW_SPEC ((CORBA::SystemException,
00782                    PortableServer::POA::ObjectNotActive,
00783                    PortableServer::POA::WrongPolicy))
00784 {
00785   // Lock access for the duration of this transaction.
00786   TAO_POA_GUARD_RETURN (0);
00787 
00788   return this->id_to_servant_i (oid
00789                                 ACE_ENV_ARG_PARAMETER);
00790 }
00791 
00792 CORBA::Object_ptr
00793 TAO_Root_POA::id_to_reference (const PortableServer::ObjectId &oid
00794                                ACE_ENV_ARG_DECL)
00795   ACE_THROW_SPEC ((CORBA::SystemException,
00796                    PortableServer::POA::ObjectNotActive,
00797                    PortableServer::POA::WrongPolicy))
00798 {
00799   // Lock access for the duration of this transaction.
00800   TAO_POA_GUARD_RETURN (0);
00801 
00802   return this->id_to_reference_i (oid, true ACE_ENV_ARG_PARAMETER);
00803 }
00804 
00805 
00806 CORBA::Object_ptr
00807 TAO_Root_POA::create_reference_with_id (const PortableServer::ObjectId &id,
00808                                         const char *intf
00809                                         ACE_ENV_ARG_DECL)
00810   ACE_THROW_SPEC ((CORBA::SystemException))
00811 {
00812   // Lock access for the duration of this transaction.
00813   TAO_POA_GUARD_RETURN (CORBA::Object::_nil ());
00814 
00815   return this->create_reference_with_id_i (id,
00816                                            intf,
00817                                            this->server_priority ()
00818                                            ACE_ENV_ARG_PARAMETER);
00819 }
00820 
00821 
00822 void
00823 TAO_Root_POA::destroy (CORBA::Boolean etherealize_objects,
00824                        CORBA::Boolean wait_for_completion
00825                        ACE_ENV_ARG_DECL)
00826   ACE_THROW_SPEC ((CORBA::SystemException))
00827 {
00828   // Lock access for the duration of this transaction.
00829   TAO::Portable_Server::POA_Guard poa_guard (*this ACE_ENV_ARG_PARAMETER, 0);
00830   ACE_CHECK;
00831   ACE_UNUSED_ARG (poa_guard);
00832 
00833   this->destroy_i (etherealize_objects,
00834                    wait_for_completion
00835                    ACE_ENV_ARG_PARAMETER);
00836   ACE_CHECK;
00837 }
00838 
00839 void
00840 TAO_Root_POA::remove_from_parent_i (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00841 {
00842   // The root poa has no parent, so this is a noop
00843 }
00844 
00845 void
00846 TAO_Root_POA::destroy_i (CORBA::Boolean etherealize_objects,
00847                          CORBA::Boolean wait_for_completion
00848                          ACE_ENV_ARG_DECL)
00849   ACE_THROW_SPEC ((CORBA::SystemException))
00850 {
00851   if (this->cleanup_in_progress_)
00852     return;
00853 
00854   // Is the <wait_for_completion> semantics for this thread correct?
00855   TAO_Root_POA::check_for_valid_wait_for_completions (this->orb_core (),
00856                                                       wait_for_completion
00857                                                       ACE_ENV_ARG_PARAMETER);
00858   ACE_CHECK;
00859 
00860   this->cleanup_in_progress_ = 1;
00861 
00862   // Inform the custom servant dispatching strategy to stop the working
00863   // threads when the poa is destroyed.
00864   this->poa_deactivated_hook ();
00865 
00866   // This operation destroys the POA and all descendant POAs. The POA
00867   // so destroyed (that is, the POA with its name) may be re-created
00868   // later in the same process. (This differs from the
00869   // POAManager::deactivate operation that does not allow a
00870   // re-creation of its associated POA in the same process.)
00871 
00872   // Remove POA from the parent
00873   this->remove_from_parent_i (ACE_ENV_SINGLE_ARG_PARAMETER);
00874   ACE_CHECK;
00875 
00876   TAO::ORT_Array array_obj_ref_template (1);
00877 
00878   CORBA::ULong i = 0;
00879 
00880   // Gather all ObjectReferenceTemplates and change all adapter states
00881   // to INACTIVE.
00882   for (CHILDREN::iterator iterator = this->children_.begin ();
00883        iterator != this->children_.end ();
00884        ++iterator)
00885     {
00886       TAO_Root_POA * const child_poa = (*iterator).int_id_;
00887 
00888       TAO::ORT_Adapter * const adapter = child_poa->ORT_adapter_i ();
00889 
00890       // In case no ORT library is linked we get zero.
00891       if (adapter != 0)
00892         {
00893           // Get the ObjectReferenceTemplate for the child POA.
00894           PortableInterceptor::ObjectReferenceTemplate * const ort =
00895             adapter->get_adapter_template ();
00896 
00897           // Add it to the sequence of object reference templates that
00898           // will be destroyed.
00899           array_obj_ref_template.size (1);
00900 
00901           array_obj_ref_template[0] = ort;
00902         }
00903 
00904       child_poa->adapter_state_ =
00905         PortableInterceptor::INACTIVE;
00906 
00907       // Notify the state changes to the IORInterceptors
00908       this->adapter_state_changed (array_obj_ref_template,
00909                                    PortableInterceptor::INACTIVE
00910                                    ACE_ENV_ARG_PARAMETER);
00911       ACE_CHECK;
00912 
00913       if (adapter != 0)
00914         adapter->release (array_obj_ref_template[0]);
00915 
00916       ++i;
00917     }
00918 
00919   // Destroy all child POA's now.
00920   for (CHILDREN::iterator destroy_iterator = this->children_.begin ();
00921        destroy_iterator != this->children_.end ();
00922        ++destroy_iterator)
00923     {
00924       TAO_Root_POA *destroy_child_poa = (*destroy_iterator).int_id_;
00925 
00926       destroy_child_poa->destroy_i (etherealize_objects,
00927                                     wait_for_completion
00928                                     ACE_ENV_ARG_PARAMETER);
00929       ACE_CHECK;
00930     }
00931 
00932   // Notify the lifespan strategy of our shutdown
00933   this->active_policy_strategies_.lifespan_strategy()->notify_shutdown (
00934     ACE_ENV_SINGLE_ARG_PARAMETER);
00935   ACE_CHECK;
00936 
00937 // @todo, is the exception handling above correct, should we just fail when
00938 // the notify above fails
00939 
00940   // When a POA is destroyed, any requests that have started execution
00941   // continue to completion. Any requests that have not started
00942   // execution are processed as if they were newly arrived, that is,
00943   // the POA will attempt to cause recreation of the POA by invoking
00944   // one or more adapter activators as described in Section 3.3.3.
00945   // If the wait_for_completion parameter is TRUE, the destroy
00946   // operation will return only after all requests in process have
00947   // completed and all invocations of etherealize have
00948   // completed. Otherwise, the destroy operation returns after
00949   // destroying the POAs.
00950 
00951   this->deactivate_all_objects_i (etherealize_objects,
00952                                   wait_for_completion
00953                                   ACE_ENV_ARG_PARAMETER);
00954   ACE_CHECK;
00955 
00956   // If there are no outstanding requests and that we are not in a
00957   // non-servant upcall or if we are in a non-servant upcall, make
00958   // sure we are the POA related to the non-servant upcall.
00959   TAO::Portable_Server::Non_Servant_Upcall *non_servant_upcall_in_progress =
00960     this->object_adapter ().non_servant_upcall_in_progress ();
00961   if (this->outstanding_requests_ == 0 &&
00962       (non_servant_upcall_in_progress == 0 ||
00963        &non_servant_upcall_in_progress->poa () != this))
00964     {
00965       TAO::ORT_Array my_array_obj_ref_template;
00966 
00967       TAO::ORT_Adapter * const ort_adapter =
00968         this->ORT_adapter_i ();
00969 
00970       // In case no ORT library is linked we get zero.
00971       if (ort_adapter != 0)
00972         {
00973           // Get the ObjectReferenceTemplate.
00974           PortableInterceptor::ObjectReferenceTemplate * const ort =
00975             ort_adapter->get_adapter_template ();
00976 
00977           // Add it to the sequence of object reference templates, we
00978           // just notify for ourselves that we are now non_existent,
00979           // our childs will do it for themselves.
00980           my_array_obj_ref_template.size (1);
00981           my_array_obj_ref_template[0] = ort;
00982         }
00983 
00984       // According to the ORT spec, after a POA is destroyed, its state
00985       // has to be changed to NON_EXISTENT and all the registered
00986       // interceptors are to be informed. Since, the POA is destroyed
00987       // and is released in the complete_destruction_i method, we are
00988       // trying to keep the poa still around by doing a duplicate of
00989       // it. (a hack).
00990       PortableServer::POA_var poa = PortableServer::POA::_duplicate (this);
00991 
00992       this->complete_destruction_i (ACE_ENV_SINGLE_ARG_PARAMETER);
00993       ACE_CHECK;
00994 
00995       this->adapter_state_ = PortableInterceptor::NON_EXISTENT;
00996 
00997       this->adapter_state_changed (my_array_obj_ref_template,
00998                                    this->adapter_state_
00999                                    ACE_ENV_ARG_PARAMETER);
01000       ACE_CHECK;
01001 
01002       if (ort_adapter != 0)
01003         {
01004           ort_adapter->release (my_array_obj_ref_template[0]);
01005 
01006           TAO::ORT_Adapter_Factory *ort_factory =
01007             this->ORT_adapter_factory ();
01008 
01009           ort_factory->destroy (ort_adapter);
01010 
01011           this->ort_adapter_ = 0;
01012         }
01013     }
01014   else
01015     {
01016       // Mark that we are ready for destruction.
01017       this->waiting_destruction_ = 1;
01018     }
01019 }
01020 
01021 int
01022 TAO_Root_POA::delete_child (const TAO_Root_POA::String &child)
01023 {
01024   int result = 0;
01025 
01026   // If we are not closing down, we must remove this child from our
01027   // collection.
01028   if (!this->cleanup_in_progress_)
01029     result = this->children_.unbind (child);
01030 
01031   // Otherwise, if we are closing down, we are currently iterating
01032   // over our children and there is not need to remove this child from
01033   // our collection.
01034 
01035   return result;
01036 }
01037 
01038 PortableServer::POAList *
01039 TAO_Root_POA::the_children_i (ACE_ENV_SINGLE_ARG_DECL)
01040   ACE_THROW_SPEC ((CORBA::SystemException))
01041 {
01042   PortableServer::POAList_var children;
01043   CORBA::ULong child_current = static_cast <CORBA::ULong>
01044                                            (this->children_.current_size ());
01045   ACE_NEW_THROW_EX (children,
01046                     PortableServer::POAList (child_current),
01047                     CORBA::NO_MEMORY ());
01048   ACE_CHECK_RETURN (0);
01049 
01050   children->length (child_current);
01051 
01052   CORBA::ULong index = 0;
01053   for (CHILDREN::iterator iterator = this->children_.begin ();
01054        iterator != this->children_.end ();
01055        ++iterator, ++index)
01056     {
01057       TAO_Root_POA *child_poa = (*iterator).int_id_;
01058       children[index] = PortableServer::POA::_duplicate (child_poa);
01059     }
01060 
01061   return children._retn ();
01062 }
01063 
01064 PortableInterceptor::AdapterName *
01065 TAO_Root_POA::adapter_name_i (ACE_ENV_SINGLE_ARG_DECL)
01066   ACE_THROW_SPEC ((CORBA::SystemException))
01067 {
01068   // The adapter name is the sequence of names starting from the
01069   // RootPOA to the one whose name is requested.  The name of the
01070   // RootPOA is "RootPOA".
01071 
01072   PortableServer::POA_var poa = PortableServer::POA::_duplicate (this);
01073 
01074   CORBA::ULong len = 0;
01075 
01076   // Find the length of the adapter name sequence by traversing the
01077   // POA hierarchy until the RootPOA is reached.  The RootPOA has no
01078   // parent.
01079   while (!CORBA::is_nil (poa.in ()))
01080     {
01081       poa = poa->the_parent (ACE_ENV_SINGLE_ARG_PARAMETER);
01082       ACE_CHECK_RETURN (0);
01083 
01084       ++len;
01085     }
01086 
01087   // Empty adapter name sequence.
01088   PortableInterceptor::AdapterName *names = 0;
01089   ACE_NEW_THROW_EX (names,
01090                     PortableInterceptor::AdapterName (len),
01091                     CORBA::NO_MEMORY (
01092                       CORBA::SystemException::_tao_minor_code (
01093                         TAO::VMCID,
01094                         ENOMEM),
01095                       CORBA::COMPLETED_NO));
01096   ACE_CHECK_RETURN (0);
01097 
01098   PortableInterceptor::AdapterName_var safe_names (names);
01099 
01100   names->length (len);
01101 
01102   poa = PortableServer::POA::_duplicate (this);
01103 
01104   (*names)[0] = CORBA::string_dup ("RootPOA");
01105 
01106   // Fill in the AdapterName sequence as the POA hierarchy is
01107   // traversed.
01108   CORBA::ULong ilen = len;
01109   for (CORBA::ULong i = 1; i < len; ++i)
01110     {
01111       (*names)[--ilen] = poa->the_name (ACE_ENV_SINGLE_ARG_PARAMETER);
01112       ACE_CHECK_RETURN (0);
01113 
01114       poa = poa->the_parent (ACE_ENV_SINGLE_ARG_PARAMETER);
01115       ACE_CHECK_RETURN (0);
01116 
01117       // If this condition asserts, the POA hierarchy was modified
01118       // (i.e. reduced in size) by another thread!
01119       ACE_ASSERT ((ilen > 0 ? !CORBA::is_nil (poa.in ()) : 1));
01120     }
01121 
01122   return safe_names._retn ();
01123 }
01124 
01125 void
01126 TAO_Root_POA::add_ior_component (TAO_MProfile & mprofile,
01127                                  const IOP::TaggedComponent &component
01128                                  ACE_ENV_ARG_DECL)
01129   ACE_THROW_SPEC ((CORBA::SystemException))
01130 {
01131   // Add the given tagged component to all profiles.
01132   const CORBA::ULong profile_count = mprofile.profile_count ();
01133 
01134   for (CORBA::ULong i = 0; i < profile_count; ++i)
01135     {
01136       TAO_Profile *profile = mprofile.get_profile (i);
01137 
01138       profile->add_tagged_component (component
01139                                      ACE_ENV_ARG_PARAMETER);
01140       ACE_CHECK;
01141     }
01142 }
01143 
01144 void
01145 TAO_Root_POA::add_ior_component_to_profile (
01146     TAO_MProfile & mprofile,
01147     const IOP::TaggedComponent &component,
01148     IOP::ProfileId profile_id
01149     ACE_ENV_ARG_DECL)
01150   ACE_THROW_SPEC ((CORBA::SystemException))
01151 {
01152   // Add the given tagged component to all profiles matching the given
01153   // ProfileId.
01154   bool found_profile = false;
01155 
01156   CORBA::ULong const profile_count = mprofile.profile_count ();
01157 
01158   for (CORBA::ULong i = 0; i < profile_count; ++i)
01159     {
01160       TAO_Profile *profile = mprofile.get_profile (i);
01161 
01162       if (profile->tag () == profile_id)
01163         {
01164           profile->add_tagged_component (component
01165                                          ACE_ENV_ARG_PARAMETER);
01166           ACE_CHECK;
01167 
01168           found_profile = true;
01169         }
01170     }
01171 
01172   // According to the Portable Interceptor specification, we're
01173   // supposed to throw a CORBA::BAD_PARAM exception if no profile
01174   // matched the given ProfileId.
01175   if (found_profile == false)
01176     ACE_THROW (CORBA::BAD_PARAM (CORBA::OMGVMCID | 29,
01177                                  CORBA::COMPLETED_NO));
01178 }
01179 
01180 void
01181 TAO_Root_POA::adapter_state_changed (
01182    const TAO::ORT_Array &array_obj_ref_template,
01183    PortableInterceptor::AdapterState state
01184    ACE_ENV_ARG_DECL)
01185   ACE_THROW_SPEC ((CORBA::SystemException))
01186 {
01187   TAO_IORInterceptor_Adapter *ior_adapter =
01188     this->orb_core_.ior_interceptor_adapter ();
01189 
01190   if (ior_adapter)
01191     {
01192       ior_adapter->adapter_state_changed (array_obj_ref_template,
01193                                           state
01194                                           ACE_ENV_ARG_PARAMETER);
01195       ACE_CHECK;
01196     }
01197 }
01198 
01199 PortableServer::ObjectId *
01200 TAO_Root_POA::activate_object_i (PortableServer::Servant servant,
01201                                  CORBA::Short priority,
01202                                  int &wait_occurred_restart_call
01203                                  ACE_ENV_ARG_DECL)
01204   ACE_THROW_SPEC ((CORBA::SystemException,
01205                    PortableServer::POA::ServantAlreadyActive,
01206                    PortableServer::POA::WrongPolicy))
01207 {
01208   return this->active_policy_strategies_.servant_retention_strategy()->
01209     activate_object (servant,
01210                      priority,
01211                      wait_occurred_restart_call
01212                      ACE_ENV_ARG_PARAMETER);
01213 }
01214 
01215 PortableServer::ObjectId *
01216 TAO_Root_POA::activate_object (PortableServer::Servant servant
01217                                ACE_ENV_ARG_DECL)
01218   ACE_THROW_SPEC ((CORBA::SystemException,
01219                    PortableServer::POA::ServantAlreadyActive,
01220                    PortableServer::POA::WrongPolicy))
01221 {
01222   while (1)
01223     {
01224       int wait_occurred_restart_call = 0;
01225 
01226       // Lock access for the duration of this transaction.
01227       TAO_POA_GUARD_RETURN (0);
01228 
01229       PortableServer::ObjectId *result =
01230         this->activate_object_i (servant,
01231                                  this->server_priority (),
01232                                  wait_occurred_restart_call
01233                                  ACE_ENV_ARG_PARAMETER);
01234       ACE_CHECK_RETURN (0);
01235 
01236       // If we ended up waiting on a condition variable, the POA state
01237       // may have changed while we are waiting.  Therefore, we need to
01238       // restart this call.
01239       if (wait_occurred_restart_call)
01240         continue;
01241       else
01242         return result;
01243     }
01244 }
01245 
01246 #if !defined (CORBA_E_MICRO)
01247 void
01248 TAO_Root_POA::activate_object_with_id (const PortableServer::ObjectId &id,
01249                                        PortableServer::Servant servant
01250                                        ACE_ENV_ARG_DECL)
01251   ACE_THROW_SPEC ((CORBA::SystemException,
01252                    PortableServer::POA::ServantAlreadyActive,
01253                    PortableServer::POA::ObjectAlreadyActive,
01254                    PortableServer::POA::WrongPolicy))
01255 {
01256   while (1)
01257     {
01258       int wait_occurred_restart_call = 0;
01259 
01260       // Lock access for the duration of this transaction.
01261       TAO_POA_GUARD;
01262 
01263       this->activate_object_with_id_i (id,
01264                                        servant,
01265                                        this->server_priority (),
01266                                        wait_occurred_restart_call
01267                                        ACE_ENV_ARG_PARAMETER);
01268       ACE_CHECK;
01269 
01270       // If we ended up waiting on a condition variable, the POA state
01271       // may have changed while we are waiting.  Therefore, we need to
01272       // restart this call.
01273       if (wait_occurred_restart_call)
01274         continue;
01275       else
01276         return;
01277     }
01278 }
01279 #endif
01280 
01281 #if !defined (CORBA_E_MICRO)
01282 void
01283 TAO_Root_POA::activate_object_with_id_i (const PortableServer::ObjectId &id,
01284                                          PortableServer::Servant servant,
01285                                          CORBA::Short priority,
01286                                          int &wait_occurred_restart_call
01287                                          ACE_ENV_ARG_DECL)
01288   ACE_THROW_SPEC ((CORBA::SystemException,
01289                    PortableServer::POA::ServantAlreadyActive,
01290                    PortableServer::POA::ObjectAlreadyActive,
01291                    PortableServer::POA::WrongPolicy))
01292 {
01293   this->active_policy_strategies_.servant_retention_strategy()->
01294     activate_object_with_id (id,
01295                              servant,
01296                              priority,
01297                              wait_occurred_restart_call
01298                              ACE_ENV_ARG_PARAMETER);
01299   ACE_CHECK;
01300 }
01301 #endif
01302 
01303 void
01304 TAO_Root_POA::deactivate_all_objects_i (CORBA::Boolean etherealize_objects,
01305                                         CORBA::Boolean wait_for_completion
01306                                         ACE_ENV_ARG_DECL)
01307   ACE_THROW_SPEC ((CORBA::SystemException,
01308                    PortableServer::POA::WrongPolicy))
01309 {
01310   this->deactivate_all_objects_i (etherealize_objects
01311                                   ACE_ENV_ARG_PARAMETER);
01312   ACE_CHECK;
01313 
01314   this->wait_for_completions (wait_for_completion
01315                               ACE_ENV_ARG_PARAMETER);
01316   ACE_CHECK;
01317 }
01318 
01319 void
01320 TAO_Root_POA::wait_for_completions (CORBA::Boolean wait_for_completion
01321                                     ACE_ENV_ARG_DECL)
01322 {
01323   while (this->object_adapter ().enable_locking_ &&
01324          wait_for_completion &&
01325          this->outstanding_requests_ > 0)
01326     {
01327       this->wait_for_completion_pending_ = 1;
01328 
01329       int result = this->outstanding_requests_condition_.wait ();
01330       if (result == -1)
01331         {
01332           ACE_THROW (CORBA::OBJ_ADAPTER ());
01333         }
01334     }
01335 }
01336 
01337 /* static */
01338 void
01339 TAO_Root_POA::check_for_valid_wait_for_completions (const TAO_ORB_Core &orb_core,
01340                                                     CORBA::Boolean wait_for_completion
01341                                                     ACE_ENV_ARG_DECL)
01342 {
01343   if (wait_for_completion)
01344     {
01345       TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
01346         static_cast <TAO::Portable_Server::POA_Current_Impl *>
01347                     (TAO_TSS_Resources::instance ()->poa_current_impl_);
01348 
01349       while (1)
01350         {
01351           // If wait_for_completion is TRUE and the current thread is
01352           // in an invocation context dispatched from some POA
01353           // belonging to the same ORB as this POA, the BAD_INV_ORDER
01354           // system exception with standard minor code 3 is raised and
01355           // POA destruction does not occur.
01356           if (poa_current_impl != 0)
01357             {
01358               if (&orb_core == &poa_current_impl->orb_core ())
01359                 {
01360                   // CORBA 2.3 specifies which minor code corresponds
01361                   // to this particular problem.
01362                   ACE_THROW (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 3,
01363                                                    CORBA::COMPLETED_NO));
01364                 }
01365             }
01366           else
01367             break;
01368 
01369           poa_current_impl =
01370             poa_current_impl->previous_current_impl_;
01371         }
01372     }
01373 }
01374 
01375 void
01376 TAO_Root_POA::deactivate_all_objects_i (CORBA::Boolean etherealize_objects
01377                                         ACE_ENV_ARG_DECL)
01378   ACE_THROW_SPEC ((CORBA::SystemException,
01379                    PortableServer::POA::WrongPolicy))
01380 {
01381   this->active_policy_strategies_.request_processing_strategy ()->
01382     etherealize_objects (etherealize_objects);
01383 
01384   this->active_policy_strategies_.servant_retention_strategy ()->
01385     deactivate_all_objects (ACE_ENV_SINGLE_ARG_PARAMETER);
01386 }
01387 
01388 void
01389 TAO_Root_POA::deactivate_object (const PortableServer::ObjectId &oid
01390                                  ACE_ENV_ARG_DECL)
01391   ACE_THROW_SPEC ((CORBA::SystemException,
01392                    PortableServer::POA::ObjectNotActive,
01393                    PortableServer::POA::WrongPolicy))
01394 {
01395   // Lock access for the duration of this transaction.
01396   TAO_POA_GUARD;
01397 
01398   this->deactivate_object_i (oid
01399                              ACE_ENV_ARG_PARAMETER);
01400   ACE_CHECK;
01401 }
01402 
01403 
01404 void
01405 TAO_Root_POA::deactivate_object_i (const PortableServer::ObjectId &id
01406                                    ACE_ENV_ARG_DECL)
01407   ACE_THROW_SPEC ((CORBA::SystemException,
01408                    PortableServer::POA::ObjectNotActive,
01409                    PortableServer::POA::WrongPolicy))
01410 {
01411   this->active_policy_strategies_.servant_retention_strategy()->
01412     deactivate_object (id
01413                        ACE_ENV_ARG_PARAMETER);
01414   ACE_CHECK;
01415 }
01416 
01417 CORBA::Boolean
01418 TAO_Root_POA::is_persistent (void) const
01419 {
01420   return active_policy_strategies_.lifespan_strategy()->is_persistent ();
01421 }
01422 
01423 CORBA::Object_ptr
01424 TAO_Root_POA::create_reference (const char *intf
01425                                 ACE_ENV_ARG_DECL)
01426   ACE_THROW_SPEC ((CORBA::SystemException,
01427                    PortableServer::POA::WrongPolicy))
01428 {
01429   // Lock access for the duration of this transaction.
01430   TAO_POA_GUARD_RETURN (CORBA::Object::_nil ());
01431 
01432   return this->create_reference_i (intf,
01433                                    this->server_priority ()
01434                                    ACE_ENV_ARG_PARAMETER);
01435 }
01436 
01437 CORBA::Object_ptr
01438 TAO_Root_POA::create_reference_i (const char *intf,
01439                                   CORBA::Short priority
01440                                   ACE_ENV_ARG_DECL)
01441   ACE_THROW_SPEC ((CORBA::SystemException,
01442                    PortableServer::POA::WrongPolicy))
01443 {
01444   if (!this->has_system_id ())
01445     {
01446       ACE_THROW_RETURN (PortableServer::POA::WrongPolicy (),
01447                         CORBA::Object::_nil ());
01448     }
01449 
01450   return this->active_policy_strategies_.servant_retention_strategy()->
01451     create_reference (intf, priority ACE_ENV_ARG_PARAMETER);
01452 }
01453 
01454 CORBA::Object_ptr
01455 TAO_Root_POA::invoke_key_to_object_helper_i (const char * repository_id,
01456                                              const PortableServer::ObjectId & id
01457                                              ACE_ENV_ARG_DECL)
01458   ACE_THROW_SPEC ((CORBA::SystemException))
01459 {
01460   const PortableInterceptor::ObjectId &user_oid =
01461     reinterpret_cast <const PortableInterceptor::ObjectId &>(id);
01462 
01463   // Ask the ORT to create the object.
01464   if (this->ORT_adapter_i ())
01465     {
01466       // Ask the ORT to create the object.
01467       return this->ort_adapter_->make_object (repository_id,
01468                                               user_oid
01469                                               ACE_ENV_ARG_PARAMETER);
01470     }
01471   else
01472     {
01473       return this->invoke_key_to_object (ACE_ENV_SINGLE_ARG_PARAMETER);
01474     }
01475 }
01476 
01477 CORBA::Object_ptr
01478 TAO_Root_POA::create_reference_with_id_i (const PortableServer::ObjectId &user_id,
01479                                           const char *intf,
01480                                           CORBA::Short priority
01481                                           ACE_ENV_ARG_DECL)
01482   ACE_THROW_SPEC ((CORBA::SystemException))
01483 {
01484   // If the POA has the SYSTEM_ID policy and it detects that the
01485   // Object Id value was not generated by the system or for this POA,
01486   // the create_reference_with_id operation may raise the BAD_PARAM
01487   // system exception. An ORB is not required to detect all such
01488   // invalid Object Id values, but a portable application must not
01489   // invoke this operation on a POA that has the SYSTEM_ID policy with
01490   // an Object Id value that was not previously generated by the
01491   // system for that POA, or, if the POA also has the PERSISTENT
01492   // policy, for a previous instantiation of the same POA.
01493   if (this->has_system_id () &&
01494       !this->is_poa_generated_id (user_id))
01495     {
01496       ACE_THROW_RETURN (CORBA::BAD_PARAM (CORBA::OMGVMCID | 14,
01497                                           CORBA::COMPLETED_NO),
01498                         CORBA::Object::_nil ());
01499     }
01500 
01501   return this->active_policy_strategies_.servant_retention_strategy()->
01502     create_reference_with_id (user_id, intf, priority ACE_ENV_ARG_PARAMETER);
01503 }
01504 
01505 PortableServer::ObjectId *
01506 TAO_Root_POA::servant_to_id_i (PortableServer::Servant servant
01507                                ACE_ENV_ARG_DECL)
01508   ACE_THROW_SPEC ((CORBA::SystemException,
01509                    PortableServer::POA::ServantNotActive,
01510                    PortableServer::POA::WrongPolicy))
01511 {
01512   return this->active_policy_strategies_.request_processing_strategy()->
01513     servant_to_id (servant ACE_ENV_ARG_PARAMETER);
01514 }
01515 
01516 CORBA::Object_ptr
01517 TAO_Root_POA::servant_to_reference_i (PortableServer::Servant servant
01518                                       ACE_ENV_ARG_DECL)
01519   ACE_THROW_SPEC ((CORBA::SystemException,
01520                    PortableServer::POA::ServantNotActive,
01521                    PortableServer::POA::WrongPolicy))
01522 {
01523   return this->active_policy_strategies_.servant_retention_strategy()->
01524     servant_to_reference (servant ACE_ENV_ARG_PARAMETER);
01525 }
01526 
01527 PortableServer::Servant
01528 TAO_Root_POA::reference_to_servant_i (CORBA::Object_ptr reference
01529                                       ACE_ENV_ARG_DECL)
01530   ACE_THROW_SPEC ((CORBA::SystemException,
01531                    PortableServer::POA::ObjectNotActive,
01532                    PortableServer::POA::WrongAdapter,
01533                    PortableServer::POA::WrongPolicy))
01534 {
01535   // Make sure that the reference is valid.
01536   if (CORBA::is_nil (reference))
01537     {
01538       ACE_THROW_RETURN (CORBA::BAD_PARAM (),
01539                         0);
01540     }
01541 
01542   PortableServer::ObjectId system_id;
01543   bool const is_generated =
01544     this->is_poa_generated (reference, system_id ACE_ENV_ARG_PARAMETER);
01545   ACE_CHECK_RETURN (0);
01546 
01547   if (!is_generated)
01548     {
01549       // In case this object reference is not generated by this POA throw
01550       // an exception
01551       ACE_THROW_RETURN (PortableServer::POA::WrongAdapter (),
01552                         0);
01553     }
01554 
01555   PortableServer::Servant servant =
01556     this->active_policy_strategies_.request_processing_strategy()->
01557       system_id_to_servant (system_id ACE_ENV_ARG_PARAMETER);
01558   ACE_CHECK_RETURN (0);
01559 
01560   if (servant != 0)
01561     {
01562       // ATTENTION: Trick locking here, see class header for details
01563       TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*this);
01564       ACE_UNUSED_ARG (non_servant_upcall);
01565 
01566       // The POA invokes _add_ref once on the Servant before returning
01567       // it. If the application uses reference counting, the caller of
01568       // id_to_servant is responsible for invoking _remove_ref once on
01569       // the returned Servant when it is finished with it. A
01570       // conforming caller need not invoke _remove_ref on the returned
01571       // Servant if the type of the Servant uses the default reference
01572       // counting inherited from ServantBase.
01573       servant->_add_ref (ACE_ENV_SINGLE_ARG_PARAMETER);
01574       ACE_CHECK_RETURN (0);
01575     }
01576 
01577   return servant;
01578 }
01579 
01580 bool
01581 TAO_Root_POA::is_poa_generated (CORBA::Object_ptr reference,
01582                                 PortableServer::ObjectId &system_id
01583                                 ACE_ENV_ARG_DECL)
01584 {
01585   TAO::ObjectKey_var key = reference->_key (ACE_ENV_SINGLE_ARG_PARAMETER);
01586   ACE_CHECK_RETURN (false);
01587 
01588   TAO_Object_Adapter::poa_name poa_system_name;
01589   CORBA::Boolean is_root = false;
01590   CORBA::Boolean is_persistent = false;
01591   CORBA::Boolean is_system_id = false;
01592   TAO::Portable_Server::Temporary_Creation_Time poa_creation_time;
01593 
01594   int const result = this->parse_key (key.in (),
01595                                       poa_system_name,
01596                                       system_id,
01597                                       is_root,
01598                                       is_persistent,
01599                                       is_system_id,
01600                                       poa_creation_time);
01601   if (result != 0 ||
01602       !this->root () &&
01603       poa_system_name != this->system_name () ||
01604       is_root != this->root () ||
01605       is_system_id != this->system_id () ||
01606       !this->validate_lifespan (is_persistent, poa_creation_time))
01607     {
01608       // The passed reference is NOT generated by this POA
01609       return false;
01610     }
01611   else
01612     {
01613       // The passed reference is generated by this POA
01614       return true;
01615     }
01616 }
01617 
01618 PortableServer::ObjectId *
01619 TAO_Root_POA::reference_to_id (CORBA::Object_ptr reference
01620                                ACE_ENV_ARG_DECL)
01621   ACE_THROW_SPEC ((CORBA::SystemException,
01622                    PortableServer::POA::WrongAdapter,
01623                    PortableServer::POA::WrongPolicy))
01624 {
01625   // Make sure that the reference is valid.
01626   if (CORBA::is_nil (reference))
01627     {
01628       ACE_THROW_RETURN (CORBA::BAD_PARAM (),
01629                         0);
01630     }
01631 
01632   // The WrongPolicy exception is declared to allow future extensions.
01633 
01634   // This operation is valid only if the reference was created by the
01635   // POA on which the operation is being performed.  If the object
01636   // reference was not created by this POA, the WrongAdapter exception
01637   // is raised.
01638   PortableServer::ObjectId system_id;
01639   bool const is_generated = this->is_poa_generated (reference,
01640                                                     system_id
01641                                                     ACE_ENV_ARG_PARAMETER);
01642   ACE_CHECK_RETURN (0);
01643 
01644   if (!is_generated)
01645     {
01646       ACE_THROW_RETURN (PortableServer::POA::WrongAdapter (),
01647                         0);
01648     }
01649 
01650   // Lock access for the duration of this transaction.
01651   TAO_POA_GUARD_RETURN (0);
01652 
01653   return this->active_policy_strategies_.servant_retention_strategy()->
01654     system_id_to_object_id (system_id ACE_ENV_ARG_PARAMETER);
01655 }
01656 
01657 PortableServer::Servant
01658 TAO_Root_POA::find_servant (const PortableServer::ObjectId &system_id
01659                             ACE_ENV_ARG_DECL)
01660 {
01661   return this->active_policy_strategies_.servant_retention_strategy()->
01662     find_servant (system_id ACE_ENV_ARG_PARAMETER);
01663 }
01664 
01665 int
01666 TAO_Root_POA::unbind_using_user_id (const PortableServer::ObjectId &user_id)
01667 {
01668   return this->active_policy_strategies_.servant_retention_strategy()->
01669     unbind_using_user_id  (user_id);
01670 }
01671 
01672 void
01673 TAO_Root_POA::cleanup_servant (
01674   PortableServer::Servant servant,
01675   const PortableServer::ObjectId &user_id
01676   ACE_ENV_ARG_DECL)
01677 {
01678   this->active_policy_strategies_.request_processing_strategy()->
01679     cleanup_servant (servant, user_id ACE_ENV_ARG_PARAMETER);
01680 }
01681 
01682 PortableServer::Servant
01683 TAO_Root_POA::id_to_servant_i (const PortableServer::ObjectId &id
01684                                ACE_ENV_ARG_DECL)
01685   ACE_THROW_SPEC ((CORBA::SystemException,
01686                    PortableServer::POA::ObjectNotActive,
01687                    PortableServer::POA::WrongPolicy))
01688 {
01689 
01690   PortableServer::Servant servant =
01691     this->active_policy_strategies_.request_processing_strategy()->
01692       id_to_servant (id ACE_ENV_ARG_PARAMETER);
01693   ACE_CHECK_RETURN (0);
01694 
01695   if (servant != 0)
01696     {
01697       // ATTENTION: Trick locking here, see class header for details
01698       TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*this);
01699       ACE_UNUSED_ARG (non_servant_upcall);
01700 
01701       // The POA invokes _add_ref once on the Servant before returning
01702       // it. If the application uses reference counting, the caller of
01703       // id_to_servant is responsible for invoking _remove_ref once on
01704       // the returned Servant when it is finished with it. A
01705       // conforming caller need not invoke _remove_ref on the returned
01706       // Servant if the type of the Servant uses the default reference
01707       // counting inherited from ServantBase.
01708       servant->_add_ref (ACE_ENV_SINGLE_ARG_PARAMETER);
01709       ACE_CHECK_RETURN (0);
01710     }
01711 
01712   return servant;
01713 }
01714 
01715 PortableServer::Servant
01716 TAO_Root_POA::user_id_to_servant_i (const PortableServer::ObjectId &id
01717                                     ACE_ENV_ARG_DECL)
01718   ACE_THROW_SPEC ((CORBA::SystemException,
01719                    PortableServer::POA::ObjectNotActive,
01720                    PortableServer::POA::WrongPolicy))
01721 {
01722   return this->active_policy_strategies_.servant_retention_strategy()->
01723     user_id_to_servant (id ACE_ENV_ARG_PARAMETER);
01724 }
01725 
01726 CORBA::Object_ptr
01727 TAO_Root_POA::id_to_reference_i (const PortableServer::ObjectId &id,
01728                                  bool indirect
01729                                  ACE_ENV_ARG_DECL)
01730   ACE_THROW_SPEC ((CORBA::SystemException,
01731                    PortableServer::POA::ObjectNotActive,
01732                    PortableServer::POA::WrongPolicy))
01733 {
01734   return this->active_policy_strategies_.servant_retention_strategy()->
01735     id_to_reference (id, indirect ACE_ENV_ARG_PARAMETER);
01736 }
01737 
01738 CORBA::OctetSeq *
01739 TAO_Root_POA::id (ACE_ENV_SINGLE_ARG_DECL)
01740   ACE_THROW_SPEC ((CORBA::SystemException))
01741 {
01742   CORBA::OctetSeq *id = 0;
01743   ACE_NEW_THROW_EX (id,
01744                     CORBA::OctetSeq (this->id_),
01745                     CORBA::NO_MEMORY ());
01746   ACE_CHECK_RETURN (0);
01747 
01748   return id;
01749 }
01750 
01751 PortableServer::Servant
01752 TAO_Root_POA::locate_servant_i (const char *operation,
01753                                 const PortableServer::ObjectId &system_id,
01754                                 TAO::Portable_Server::Servant_Upcall &servant_upcall,
01755                                 TAO::Portable_Server::POA_Current_Impl &poa_current_impl,
01756                                 int &wait_occurred_restart_call
01757                                 ACE_ENV_ARG_DECL)
01758 {
01759   return this->active_policy_strategies_.request_processing_strategy()->
01760     locate_servant (operation,
01761                     system_id,
01762                     servant_upcall,
01763                     poa_current_impl,
01764                     wait_occurred_restart_call
01765                     ACE_ENV_ARG_PARAMETER);
01766 }
01767 
01768 /* static */
01769 int
01770 TAO_Root_POA::parse_key (const TAO::ObjectKey &key,
01771                          TAO_Object_Adapter::poa_name &poa_system_name,
01772                          PortableServer::ObjectId &system_id,
01773                          CORBA::Boolean &is_root,
01774                          CORBA::Boolean &is_persistent,
01775                          CORBA::Boolean &is_system_id,
01776                          TAO::Portable_Server::Temporary_Creation_Time &poa_creation_time)
01777 {
01778   // Start at zero.
01779   CORBA::ULong starting_at = 0;
01780 
01781   // Get the object key octets.
01782   const CORBA::Octet *key_data = key.get_buffer ();
01783 
01784   // Skip the object key prefix since we have already checked for this.
01785   starting_at += TAO_OBJECTKEY_PREFIX_SIZE;
01786 
01787   // Check the root indicator.
01788   char root_key_type = key_data[starting_at];
01789   if (root_key_type == TAO_Root_POA::root_key_char ())
01790     {
01791       is_root = true;
01792     }
01793   else if (root_key_type == TAO_Root_POA::non_root_key_char ())
01794     {
01795       is_root = false;
01796     }
01797   else
01798     {
01799       // Incorrect key
01800       return -1;
01801     }
01802 
01803   // Skip past the system id indicator
01804   starting_at += TAO_Root_POA::root_key_type_length ();
01805 
01806   // Check the system id indicator.
01807   char system_id_key_type = key_data[starting_at];
01808   if (system_id_key_type == TAO_Root_POA::system_id_key_char ())
01809     {
01810       is_system_id = true;
01811     }
01812   else if (system_id_key_type == TAO_Root_POA::user_id_key_char ())
01813     {
01814       is_system_id = false;
01815     }
01816   else
01817     {
01818       // Incorrect key
01819       return -1;
01820     }
01821 
01822   // Skip past the system id indicator
01823   starting_at += TAO_Root_POA::system_id_key_type_length ();
01824 
01825   // Check the persistence indicator
01826   char persistent_key_type = key_data[starting_at];
01827   if (persistent_key_type == TAO_Root_POA::persistent_key_char ())
01828     {
01829       is_persistent = true;
01830     }
01831   else if (persistent_key_type == TAO_Root_POA::transient_key_char ())
01832     {
01833       is_persistent = false;
01834     }
01835   else
01836     {
01837       // Incorrect key
01838       return -1;
01839     }
01840 
01841   // Skip past the persistent indicator
01842   starting_at += TAO_Root_POA::persistent_key_type_length ();
01843 
01844 #if (POA_NO_TIMESTAMP == 0)
01845   // Grab the timestamp for transient POAs.
01846   if (!is_persistent)
01847     {
01848       // Take the creation time for the timestamp
01849       poa_creation_time.creation_time (key_data + starting_at);
01850 
01851       // Skip past the timestamp
01852       starting_at += TAO::Portable_Server::Creation_Time::creation_time_length ();
01853     }
01854 #else
01855   ACE_UNUSED_ARG (poa_creation_time);
01856 #endif /* POA_NO_TIMESTAMP */
01857 
01858   // Calculate the size of the POA name.
01859   CORBA::ULong poa_name_size = 0;
01860   if (!is_persistent)
01861     {
01862       // Transient POAs have fixed size.
01863       poa_name_size = TAO_Object_Adapter::transient_poa_name_size ();
01864     }
01865   else if (is_system_id)
01866     {
01867       // System ids have fixed size.
01868       poa_name_size = static_cast <CORBA::ULong>
01869                                   (key.length () - starting_at -
01870                                    TAO_Active_Object_Map::system_id_size ());
01871     }
01872   else
01873     {
01874       // Get the size from the object key.
01875       ACE_OS::memcpy (&poa_name_size,
01876                       key_data + starting_at,
01877                       sizeof (poa_name_size));
01878       poa_name_size = ACE_NTOHL (poa_name_size);
01879 
01880       starting_at += sizeof (poa_name_size);
01881     }
01882 
01883   // Grep the name if there is a name
01884   if (!is_root)
01885     {
01886       poa_system_name.replace (poa_name_size,
01887                                poa_name_size,
01888                                (CORBA::Octet *) key_data + starting_at,
01889                                0);
01890 
01891       starting_at += poa_name_size;
01892     }
01893 
01894   // The rest is the system id.
01895   CORBA::ULong system_id_size = key.length () - starting_at;
01896 
01897   // Reset <system_id>.
01898   system_id.length (system_id_size);
01899   CORBA::Octet * buf = system_id.get_buffer ();
01900   ACE_OS::memcpy (buf, key_data + starting_at, system_id_size);
01901 
01902   // Success
01903   return 0;
01904 }
01905 
01906 TAO::ObjectKey *
01907 TAO_Root_POA::create_object_key (const PortableServer::ObjectId &id)
01908 {
01909   // Calculate the space required for the key.
01910   CORBA::ULong buffer_size =
01911     this->id_.length () +
01912     id.length ();
01913 
01914   // Create the buffer for the key.
01915   CORBA::Octet *buffer = TAO::ObjectKey::allocbuf (buffer_size);
01916 
01917   // First copy the POA id into the key.
01918   ACE_OS::memcpy (&buffer[0],
01919                   this->id_.get_buffer (),
01920                   this->id_.length ());
01921 
01922   // Then copy the object id into the key.
01923   ACE_OS::memcpy (&buffer[this->id_.length ()],
01924                   id.get_buffer (),
01925                   id.length ());
01926 
01927   // Create the key, giving the ownership of the buffer to the
01928   // sequence.
01929   TAO::ObjectKey *key = 0;
01930   ACE_NEW_RETURN (key,
01931                   TAO::ObjectKey (buffer_size,
01932                                   buffer_size,
01933                                   buffer,
01934                                   1),
01935                   0);
01936 
01937   return key;
01938 }
01939 
01940 void
01941 TAO_Root_POA::set_id (TAO_Root_POA *parent)
01942 {
01943   // Calculate the prefix size.
01944   CORBA::ULong prefix_size = 0;
01945   prefix_size += TAO_OBJECTKEY_PREFIX_SIZE;
01946 
01947   // If we are dealing with a persistent POA and user ids are being
01948   // used, then we need to add the POA name length field to the object
01949   // key. Otherwise, the POA name length can be calculated by looking
01950   // at the remainder after extracting other parts of the key.
01951   bool const add_poa_name_length =
01952     this->is_persistent () &&
01953     !this->system_id ();
01954 
01955   // Size required by the POA name.
01956   CORBA::ULong poa_name = 0;
01957 
01958   // Calculate the space required for the POA name.
01959   CORBA::ULong poa_name_length = this->system_name_->length ();
01960   if (parent != 0)
01961     {
01962       poa_name += poa_name_length;
01963     }
01964 
01965   // Check if we need to added the length of the POA name.
01966   if (add_poa_name_length)
01967     {
01968       poa_name += sizeof (poa_name_length);
01969     }
01970 
01971   // Get the space needed for the lifespan length
01972   // byte.
01973   CORBA::ULong const lifespan_key_length =
01974     this->active_policy_strategies_.lifespan_strategy()->key_length ();
01975 
01976   CORBA::ULong const id_assignment_key_length =
01977     this->active_policy_strategies_.id_assignment_strategy()->key_type_length ();
01978 
01979   // Calculate the space required for the POA id.
01980   CORBA::ULong const buffer_size =
01981     prefix_size +
01982     this->root_key_type_length () +
01983     id_assignment_key_length +
01984     lifespan_key_length +
01985     poa_name;
01986 
01987   // Create the buffer for the POA id.
01988   this->id_.length (buffer_size);
01989   CORBA::Octet *buffer = &this->id_[0];
01990 
01991   // Keeps track of where the next infomation goes; start at 0 byte.
01992   CORBA::ULong starting_at = 0;
01993 
01994   // Add the object key prefix.
01995   ACE_OS::memcpy (&buffer[starting_at],
01996                   &objectkey_prefix[0],
01997                   TAO_OBJECTKEY_PREFIX_SIZE);
01998 
01999   starting_at += TAO_OBJECTKEY_PREFIX_SIZE;
02000 
02001   // Copy the root byte.
02002   if (parent != 0)
02003     {
02004       buffer[starting_at] = (CORBA::Octet) TAO_Root_POA::non_root_key_char ();
02005     }
02006   else
02007     {
02008       buffer[starting_at] = (CORBA::Octet) TAO_Root_POA::root_key_char ();
02009     }
02010   starting_at += this->root_key_type_length ();
02011 
02012   // Add the id_assignment part
02013   this->active_policy_strategies_.id_assignment_strategy()->create_key (buffer, starting_at);
02014 
02015   // Add the lifespan part
02016   this->active_policy_strategies_.lifespan_strategy()->create_key (buffer, starting_at);
02017 
02018   // Check if we need to added the length of the POA name.
02019   if (add_poa_name_length)
02020     {
02021       poa_name_length = ACE_HTONL (poa_name_length);
02022       ACE_OS::memcpy (&buffer[starting_at],
02023                       &poa_name_length,
02024                       sizeof (poa_name_length));
02025       starting_at += sizeof (poa_name_length);
02026     }
02027 
02028   // Put the POA name into the key (for non-root POAs).
02029   if (parent != 0)
02030     {
02031       ACE_OS::memcpy (&buffer[starting_at],
02032                       this->system_name_->get_buffer (),
02033                       this->system_name_->length ());
02034       starting_at += this->system_name_->length ();
02035     }
02036 }
02037 
02038 int
02039 TAO_Root_POA::is_poa_generated_id (const PortableServer::ObjectId &id)
02040 {
02041 #if defined (POA_NAME_IN_POA_GENERATED_ID)
02042 
02043   // Grab the buffer
02044   const char *id_buffer = (const char *) id.get_buffer ();
02045 
02046   // Check to see if the POA name is the first part of the id
02047   return
02048     this->name_.length () < id.length () &&
02049     ACE_OS::strncmp (id_buffer,
02050                      this->name_.c_str (),
02051                      this->name_.length ()) == 0;
02052 #else /* POA_NAME_IN_POA_GENERATED_ID */
02053 
02054   ACE_UNUSED_ARG (id);
02055   return 1;
02056 
02057 #endif /* POA_NAME_IN_POA_GENERATED_ID */
02058 }
02059 
02060 void
02061 TAO_Root_POA::set_folded_name (TAO_Root_POA *parent)
02062 {
02063   size_t length = 0;
02064   size_t parent_length = 0;
02065 
02066   if (parent != 0)
02067     {
02068       parent_length = parent->folded_name ().length ();
02069       length += parent_length;
02070     }
02071 
02072   length += this->name_.length ();
02073   length += TAO_Root_POA::name_separator_length ();
02074 
02075   this->folded_name_.length (static_cast <CORBA::ULong> (length));
02076   CORBA::Octet *folded_name_buffer = this->folded_name_.get_buffer ();
02077 
02078   if (parent != 0)
02079     {
02080       ACE_OS::memcpy (folded_name_buffer,
02081                       parent->folded_name ().get_buffer (),
02082                       parent_length);
02083     }
02084 
02085   ACE_OS::memcpy (&folded_name_buffer[parent_length],
02086                   this->name_.c_str (),
02087                   this->name_.length ());
02088 
02089   folded_name_buffer[length - TAO_Root_POA::name_separator_length ()] = TAO_Root_POA::name_separator ();
02090 }
02091 
02092 int
02093 TAO_Root_POA::parse_ir_object_key (const TAO::ObjectKey &object_key,
02094                                    PortableServer::ObjectId &user_id)
02095 {
02096   TAO_Object_Adapter::poa_name poa_system_name;
02097   CORBA::Boolean is_root = false;
02098   CORBA::Boolean is_persistent = false;
02099   CORBA::Boolean is_system_id = false;
02100   TAO::Portable_Server::Temporary_Creation_Time poa_creation_time;
02101 
02102   return TAO_Root_POA::parse_key (object_key,
02103                                   poa_system_name,
02104                                   user_id,
02105                                   is_root,
02106                                   is_persistent,
02107                                   is_system_id,
02108                                   poa_creation_time);
02109 }
02110 
02111 TAO_Object_Adapter &
02112 TAO_Root_POA::object_adapter (void)
02113 {
02114   return *this->object_adapter_;
02115 }
02116 
02117 CORBA::Object_ptr
02118 TAO_Root_POA::invoke_key_to_object (ACE_ENV_SINGLE_ARG_DECL)
02119 {
02120   PortableServer::ObjectId_var &system_id =
02121     *this->key_to_object_params_.system_id_;
02122 
02123   // Create object key.
02124   TAO::ObjectKey_var key =
02125     this->create_object_key (system_id.in ());
02126 
02127   return this->key_to_object (key.in (),
02128                               this->key_to_object_params_.type_id_,
02129                               this->key_to_object_params_.servant_,
02130                               this->key_to_object_params_.collocated_,
02131                               this->key_to_object_params_.priority_,
02132                               this->key_to_object_params_.indirect_
02133                               ACE_ENV_ARG_PARAMETER);
02134 }
02135 
02136 CORBA::Object_ptr
02137 TAO_Root_POA::key_to_object (const TAO::ObjectKey &key,
02138                              const char *type_id,
02139                              TAO_ServantBase *servant,
02140                              CORBA::Boolean collocated,
02141                              CORBA::Short priority,
02142                              bool indirect
02143                              ACE_ENV_ARG_DECL)
02144 {
02145   // Check if the ORB is still running, otherwise throw an exception.
02146   // @@ What if the ORB was destroyed?  In that case we shouldn't even
02147   //    get here!
02148   this->orb_core_.check_shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
02149   ACE_CHECK_RETURN (0);
02150 
02151   //
02152   // ImplRepo related.
02153   //
02154 #if (TAO_HAS_MINIMUM_CORBA == 0)
02155 
02156   CORBA::Object_ptr obj = CORBA::Object::_nil ();
02157 
02158   if (indirect && this->active_policy_strategies_.lifespan_strategy()->use_imr ()
02159          && this->orb_core ().imr_endpoints_in_ior ())
02160     {
02161       // Check to see if we alter the IOR.
02162       CORBA::Object_var imr =
02163         this->orb_core ().implrepo_service ();
02164 
02165       if (CORBA::is_nil (imr.in ())
02166           || !imr->_stubobj ()
02167           || !imr->_stubobj ()->profile_in_use ())
02168         {
02169           if (TAO_debug_level > 1)
02170             {
02171               ACE_DEBUG ((LM_DEBUG,
02172                           "Missing ImR IOR, will not use the ImR\n"));
02173             }
02174           goto orbkey;
02175         }
02176 
02177       CORBA::String_var imr_str =
02178         imr->_stubobj ()->profile_in_use ()->to_string (ACE_ENV_SINGLE_ARG_PARAMETER);
02179       ACE_CHECK_RETURN (obj);
02180 
02181       if (TAO_debug_level > 0)
02182         ACE_DEBUG ((LM_DEBUG,
02183                     "IMR IOR = \n%s\n",
02184                     ACE_TEXT_CHAR_TO_TCHAR (imr_str.in ())));
02185 
02186       // Search for "corbaloc:" alone, without the protocol.  This code
02187       // should be protocol neutral.
02188       const char corbaloc[] = "corbaloc:";
02189       char *pos = ACE_OS::strstr (imr_str.inout (), corbaloc);
02190       pos = ACE_OS::strchr (pos + sizeof (corbaloc), ':');
02191 
02192       pos = ACE_OS::strchr (pos + 1,
02193                             imr->_stubobj ()->profile_in_use ()->object_key_delimiter ());
02194 
02195       if (pos)
02196         pos[1] = 0;  // Crop the string.
02197       else
02198         {
02199           if (TAO_debug_level > 0)
02200             ACE_ERROR ((LM_ERROR,
02201                         "Could not parse ImR IOR, skipping ImRification\n"));
02202           goto orbkey;
02203         }
02204 
02205       ACE_CString ior (imr_str.in ());
02206 
02207       // Add the key.
02208 
02209       CORBA::String_var key_str;
02210       TAO::ObjectKey::encode_sequence_to_string (key_str.inout (), key);
02211 
02212       ior += key_str.in ();
02213 
02214       if (TAO_debug_level > 0)
02215         ACE_DEBUG ((LM_DEBUG,
02216                     "ImR-ified IOR = \n%s\n",
02217                     ACE_TEXT_CHAR_TO_TCHAR (ior.c_str ())));
02218 
02219       obj =
02220         this->orb_core_.orb ()->string_to_object (ior.c_str ()
02221                                                   ACE_ENV_ARG_PARAMETER);
02222       ACE_CHECK_RETURN (obj);
02223 
02224       return obj;
02225     }
02226 
02227 orbkey:
02228 
02229 #else
02230   ACE_UNUSED_ARG (indirect);
02231 #endif /* TAO_HAS_MINIMUM_CORBA */
02232 
02233   TAO_Stub *data =
02234     this->key_to_stub_i (key, type_id, priority ACE_ENV_ARG_PARAMETER);
02235   ACE_CHECK_RETURN (CORBA::Object::_nil ());
02236 
02237   TAO_Stub_Auto_Ptr safe_data (data);
02238 
02239   CORBA::Object_ptr tmp;
02240 
02241   if (this->orb_core_.optimize_collocation_objects ())
02242     {
02243       ACE_NEW_THROW_EX (tmp, CORBA::Object (data,
02244                                             collocated,
02245                                             servant),
02246                         CORBA::INTERNAL ());
02247 
02248       ACE_CHECK_RETURN (CORBA::Object::_nil ());
02249     }
02250   else
02251     {
02252       ACE_NEW_THROW_EX (tmp,
02253                         CORBA::Object (data,
02254                                        collocated),
02255                         CORBA::INTERNAL ());
02256       ACE_CHECK_RETURN (CORBA::Object::_nil ());
02257     }
02258 
02259   data->servant_orb (this->orb_core_.orb ());
02260 
02261   // Transfer ownership to the Object.
02262   (void) safe_data.release ();
02263 
02264   return tmp;
02265 }
02266 
02267 TAO_Stub *
02268 TAO_Root_POA::key_to_stub (const TAO::ObjectKey &key,
02269                            const char *type_id,
02270                            CORBA::Short priority
02271                            ACE_ENV_ARG_DECL)
02272 {
02273   // Check if the ORB is still running, otherwise throw an exception.
02274   // @@ What if the ORB was destroyed?  In that case we shouldn't even
02275   //    get here!
02276   this->orb_core_.check_shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
02277   ACE_CHECK_RETURN (0);
02278 
02279   return this->key_to_stub_i (key, type_id, priority ACE_ENV_ARG_PARAMETER);
02280 }
02281 
02282 TAO_Stub *
02283 TAO_Root_POA::key_to_stub_i (const TAO::ObjectKey &key,
02284                              const char *type_id,
02285                              CORBA::Short priority
02286                              ACE_ENV_ARG_DECL)
02287 {
02288   CORBA::PolicyList_var client_exposed_policies =
02289     this->client_exposed_policies (priority
02290                                    ACE_ENV_ARG_PARAMETER);
02291   ACE_CHECK_RETURN (0);
02292 
02293   if (this->filter_factory_ == 0)
02294     this->filter_factory_
02295       = ACE_Dynamic_Service<TAO_Acceptor_Filter_Factory>::instance ("TAO_Acceptor_Filter_Factory");
02296 
02297   TAO_Acceptor_Filter* filter =
02298     this->filter_factory_->create_object (this->poa_manager_);
02299 
02300   // Give ownership to the auto pointer.
02301   auto_ptr<TAO_Acceptor_Filter> new_filter (filter);
02302 
02303   TAO_Stub *data =
02304     this->create_stub_object (
02305       key,
02306       type_id,
02307       client_exposed_policies._retn (),
02308       filter,
02309       this->orb_core_.lane_resources ().acceptor_registry ()
02310       ACE_ENV_ARG_PARAMETER);
02311   ACE_CHECK_RETURN (0);
02312 
02313   return data;
02314 }
02315 
02316 void
02317 TAO_Root_POA::establish_components (ACE_ENV_SINGLE_ARG_DECL)
02318 {
02319   TAO_IORInterceptor_Adapter *ior_adapter =
02320     this->orb_core_.ior_interceptor_adapter ();
02321 
02322   if (ior_adapter)
02323     {
02324       ior_adapter->establish_components (this ACE_ENV_ARG_PARAMETER);
02325       ACE_CHECK;
02326     }
02327 }
02328 
02329 void
02330 TAO_Root_POA::components_established (PortableInterceptor::IORInfo_ptr info
02331                                       ACE_ENV_ARG_DECL)
02332 {
02333   TAO_IORInterceptor_Adapter *ior_adapter =
02334     this->orb_core_.ior_interceptor_adapter ();
02335 
02336   if (ior_adapter)
02337     {
02338       ior_adapter->components_established (info ACE_ENV_ARG_PARAMETER);
02339       ACE_CHECK;
02340     }
02341 }
02342 
02343 void
02344 TAO_Root_POA::save_ior_component (const IOP::TaggedComponent &component
02345                                   ACE_ENV_ARG_DECL_NOT_USED)
02346 {
02347   const CORBA::ULong old_len = this->tagged_component_.length ();
02348 
02349   this->tagged_component_.length (old_len + 1);
02350   this->tagged_component_[old_len] = component;
02351 }
02352 
02353 void
02354 TAO_Root_POA::
02355 save_ior_component_and_profile_id (const IOP::TaggedComponent &component,
02356                                    IOP::ProfileId profile_id
02357                                    ACE_ENV_ARG_DECL_NOT_USED)
02358 {
02359   // The length of this->tagged_component_id_ is the same as the
02360   // length of the profile_id_array_ since we are trying to make a
02361   // one-to-one link between these two arrays. So, whenever
02362   // this->tagged_component_id_ is increased, we need to increase the
02363   // size of this->profile_id_array_ also.
02364 
02365   CORBA::ULong const old_len = this->tagged_component_id_.length ();
02366 
02367   CORBA::ULong const new_len = old_len + 1;
02368 
02369   this->tagged_component_id_.length (new_len);
02370   this->tagged_component_id_[old_len] = component;
02371 
02372   this->profile_id_array_.size (new_len);
02373   this->profile_id_array_[old_len] = profile_id;
02374 }
02375 
02376 TAO_Stub *
02377 TAO_Root_POA::create_stub_object (const TAO::ObjectKey &object_key,
02378                                   const char *type_id,
02379                                   CORBA::PolicyList *policy_list,
02380                                   TAO_Acceptor_Filter *filter,
02381                                   TAO_Acceptor_Registry &acceptor_registry
02382                                   ACE_ENV_ARG_DECL)
02383 {
02384   int error = 0;
02385 
02386   // Count the number of endpoints.
02387   size_t const profile_count =
02388     acceptor_registry.endpoint_count ();
02389 
02390   // Create a profile container and have acceptor registries populate
02391   // it with profiles as appropriate.
02392   TAO_MProfile mprofile (0);
02393 
02394   // Allocate space for storing the profiles.  There can never be more
02395   // profiles than there are endpoints.  In some cases, there can be
02396   // less profiles than endpoints.
02397   int result =
02398     mprofile.set (static_cast <CORBA::ULong> (profile_count));
02399   if (result == -1)
02400     error = 1;
02401 
02402   if (!error)
02403     {
02404       result =
02405         filter->fill_profile (object_key,
02406                               mprofile,
02407                               acceptor_registry.begin (),
02408                               acceptor_registry.end ());
02409       if (result == -1)
02410         error = 1;
02411     }
02412 
02413   if (!error)
02414     result = filter->encode_endpoints (mprofile);
02415   if (result == -1)
02416     error = 1;
02417 
02418   if (error)
02419     ACE_THROW_RETURN (CORBA::INTERNAL (
02420                         CORBA::SystemException::_tao_minor_code (
02421                           TAO_MPROFILE_CREATION_ERROR,
02422                           0),
02423                         CORBA::COMPLETED_NO),
02424                       0);
02425 
02426   // Make sure we have at least one profile.  <mp> may end up being
02427   // empty if none of the acceptor endpoints have the right priority
02428   // for this object, for example.
02429   if (mprofile.profile_count () == 0)
02430     ACE_THROW_RETURN (CORBA::BAD_PARAM (
02431                         CORBA::SystemException::_tao_minor_code (
02432                           TAO_MPROFILE_CREATION_ERROR,
02433                           0),
02434                         CORBA::COMPLETED_NO),
02435                       0);
02436 
02437   TAO_Stub *stub =
02438     this->orb_core_.create_stub_object (mprofile,
02439                                         type_id,
02440                                         policy_list
02441                                         ACE_ENV_ARG_PARAMETER);
02442   ACE_CHECK_RETURN (0);
02443 
02444   // Add the saved tagged components methods to the profiles.
02445   CORBA::ULong len = this->tagged_component_.length ();
02446   for (CORBA::ULong i = 0; i != len; ++i)
02447     {
02448       this->add_ior_component (mprofile,
02449                                this->tagged_component_[i]
02450                                ACE_ENV_ARG_PARAMETER);
02451       ACE_CHECK_RETURN (0);
02452       }
02453 
02454   len = this->tagged_component_id_.length ();
02455 
02456   for (CORBA::ULong k = 0; k != len; ++k)
02457     {
02458       this->add_ior_component_to_profile (mprofile,
02459                                           this->tagged_component_id_[k],
02460                                           this->profile_id_array_[k]
02461                                           ACE_ENV_ARG_PARAMETER);
02462       ACE_CHECK_RETURN (0);
02463     }
02464 
02465   return stub;
02466 }
02467 
02468 CORBA::PolicyList *
02469 TAO_Root_POA::client_exposed_policies (CORBA::Short /* object_priority */
02470                                        ACE_ENV_ARG_DECL)
02471 {
02472   CORBA::PolicyList *client_exposed_policies = 0;
02473   ACE_NEW_THROW_EX (client_exposed_policies,
02474                     CORBA::PolicyList (),
02475                     CORBA::NO_MEMORY (TAO::VMCID,
02476                                       CORBA::COMPLETED_NO));
02477   ACE_CHECK_RETURN (0);
02478 
02479   CORBA::PolicyList_var policies = client_exposed_policies;
02480 
02481   // Add in all of the client exposed policies.
02482   this->policies_.add_client_exposed_fixed_policies (client_exposed_policies
02483                                                      ACE_ENV_ARG_PARAMETER);
02484   ACE_CHECK_RETURN (0);
02485 
02486   return policies._retn ();
02487 }
02488 
02489 TAO_SERVANT_LOCATION
02490 TAO_Root_POA::locate_servant_i (const PortableServer::ObjectId &system_id,
02491                                 PortableServer::Servant &servant
02492                                 ACE_ENV_ARG_DECL)
02493 {
02494   return this->active_policy_strategies_.request_processing_strategy()->
02495           locate_servant (system_id, servant ACE_ENV_ARG_PARAMETER);
02496 }
02497 
02498 TAO_SERVANT_LOCATION
02499 TAO_Root_POA::servant_present (const PortableServer::ObjectId &system_id,
02500                                PortableServer::Servant &servant
02501                                ACE_ENV_ARG_DECL)
02502 {
02503   return this->active_policy_strategies_.servant_retention_strategy()->
02504           servant_present (system_id, servant ACE_ENV_ARG_PARAMETER);
02505 }
02506 
02507 PortableServer::Servant
02508 TAO_Root_POA::find_servant (
02509         const PortableServer::ObjectId &system_id,
02510         TAO::Portable_Server::Servant_Upcall &servant_upcall,
02511         TAO::Portable_Server::POA_Current_Impl &poa_current_impl
02512         ACE_ENV_ARG_DECL)
02513 {
02514   return this->active_policy_strategies_.servant_retention_strategy()->
02515           find_servant (system_id,
02516                         servant_upcall,
02517                         poa_current_impl
02518                         ACE_ENV_ARG_PARAMETER);
02519 }
02520 
02521 int
02522 TAO_Root_POA::find_servant_priority (
02523          const PortableServer::ObjectId &system_id,
02524          CORBA::Short &priority
02525         ACE_ENV_ARG_DECL)
02526 {
02527   return this->active_policy_strategies_.servant_retention_strategy()->
02528           find_servant_priority (system_id,
02529                                  priority
02530                                  ACE_ENV_ARG_PARAMETER);
02531 }
02532 
02533 TAO::ORT_Adapter_Factory *
02534 TAO_Root_POA::ORT_adapter_factory (void)
02535 {
02536   return ACE_Dynamic_Service<TAO::ORT_Adapter_Factory>::instance
02537     (orb_core_.configuration (),
02538            TAO_Root_POA::ort_adapter_factory_name ());
02539 }
02540 
02541 TAO::ORT_Adapter *
02542 TAO_Root_POA::ORT_adapter_i (void)
02543 {
02544   if (this->ort_adapter_ != 0)
02545     return this->ort_adapter_;
02546 
02547   ACE_DECLARE_NEW_CORBA_ENV;
02548   ACE_TRY
02549     {
02550       TAO::ORT_Adapter_Factory * ort_ap_factory =
02551         this->ORT_adapter_factory ();
02552 
02553       if (!ort_ap_factory)
02554         return 0;
02555 
02556       // Get the full adapter name of this POA, do this before we
02557       // create the adapter so that in case this fails, we just
02558       // return 0 and not a not activated adapter
02559       PortableInterceptor::AdapterName *adapter_name =
02560         this->adapter_name_i (ACE_ENV_SINGLE_ARG_PARAMETER);
02561       ACE_TRY_CHECK;
02562 
02563       this->ort_adapter_ =
02564           ort_ap_factory->create ();
02565 
02566       if (!this->ort_adapter_)
02567         return 0;
02568 
02569       // @todo We have to look at this, we activate it but hold the POA lock,
02570       // in case we are called by ORT_adapter, we shouldn't keep the lock
02571       // here, but then the ort_adapter should be guarded against multiple
02572       // activations.
02573       this->ort_adapter_->activate (this->orb_core_.server_id (),
02574                                     this->orb_core_.orbid (),
02575                                     adapter_name,
02576                                     this
02577                                     ACE_ENV_ARG_PARAMETER);
02578       ACE_TRY_CHECK;
02579     }
02580   ACE_CATCHANY
02581     {
02582       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
02583                            "(%P|%t) Cannot initialize the "
02584                            "object_reference_template_adapter\n");
02585     }
02586   ACE_ENDTRY;
02587   ACE_CHECK_RETURN (0);
02588 
02589   return this->ort_adapter_;
02590 }
02591 
02592 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
02593 
02594 PortableServer::AdapterActivator_ptr
02595 TAO_Root_POA::the_activator (ACE_ENV_SINGLE_ARG_DECL)
02596   ACE_THROW_SPEC ((CORBA::SystemException))
02597 {
02598   // Lock access for the duration of this transaction.
02599   TAO_POA_GUARD_RETURN (PortableServer::AdapterActivator::_nil ());
02600 
02601   return PortableServer::AdapterActivator::_duplicate (this->adapter_activator_.in ());
02602 }
02603 
02604 void
02605 TAO_Root_POA::the_activator (PortableServer::AdapterActivator_ptr adapter_activator
02606                              ACE_ENV_ARG_DECL)
02607   ACE_THROW_SPEC ((CORBA::SystemException))
02608 {
02609   // Lock access for the duration of this transaction.
02610   TAO_POA_GUARD;
02611 
02612   this->adapter_activator_ = PortableServer::AdapterActivator::_duplicate (adapter_activator);
02613 }
02614 
02615 #endif /* TAO_HAS_MINIMUM_POA == 0 && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)*/
02616 
02617 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
02618 
02619 PortableServer::ServantManager_ptr
02620 TAO_Root_POA::get_servant_manager (ACE_ENV_SINGLE_ARG_DECL)
02621   ACE_THROW_SPEC ((CORBA::SystemException,
02622                    PortableServer::POA::WrongPolicy))
02623 {
02624   // Lock access for the duration of this transaction.
02625   TAO_POA_GUARD_RETURN (PortableServer::ServantManager::_nil ());
02626 
02627   return this->active_policy_strategies_.request_processing_strategy()->
02628     get_servant_manager (ACE_ENV_SINGLE_ARG_PARAMETER);
02629 }
02630 
02631 void
02632 TAO_Root_POA::set_servant_manager (PortableServer::ServantManager_ptr imgr
02633                               ACE_ENV_ARG_DECL)
02634   ACE_THROW_SPEC ((CORBA::SystemException,
02635                    PortableServer::POA::WrongPolicy))
02636 {
02637   // Lock access for the duration of this transaction.
02638   TAO_POA_GUARD;
02639 
02640   this->active_policy_strategies_.request_processing_strategy()->
02641     set_servant_manager (imgr ACE_ENV_ARG_PARAMETER);
02642   ACE_CHECK;
02643 }
02644 
02645 PortableServer::Servant
02646 TAO_Root_POA::get_servant_i (ACE_ENV_SINGLE_ARG_DECL)
02647   ACE_THROW_SPEC ((CORBA::SystemException,
02648                    PortableServer::POA::WrongPolicy))
02649 {
02650   return this->active_policy_strategies_.request_processing_strategy()->
02651     get_servant (ACE_ENV_SINGLE_ARG_PARAMETER);
02652 }
02653 
02654 PortableServer::Servant
02655 TAO_Root_POA::get_servant (ACE_ENV_SINGLE_ARG_DECL)
02656   ACE_THROW_SPEC ((CORBA::SystemException,
02657                    PortableServer::POA::NoServant,
02658                    PortableServer::POA::WrongPolicy))
02659 {
02660   // Lock access for the duration of this transaction.
02661   TAO_POA_GUARD_RETURN (0);
02662 
02663   PortableServer::Servant servant =
02664     this->get_servant_i (ACE_ENV_SINGLE_ARG_PARAMETER);
02665   ACE_CHECK_RETURN (0);
02666 
02667   if (servant != 0)
02668     {
02669       // ATTENTION: Trick locking here, see class header for details
02670       TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*this);
02671       ACE_UNUSED_ARG (non_servant_upcall);
02672 
02673       // The POA invokes _add_ref once on the Servant before returning
02674       // it. If the application uses reference counting, the caller of
02675       // get_servant is responsible for invoking _remove_ref once on
02676       // the returned Servant when it is finished with it. A
02677       // conforming caller need not invoke _remove_ref on the returned
02678       // Servant if the type of the Servant uses the default reference
02679       // counting inherited from ServantBase.
02680       servant->_add_ref (ACE_ENV_SINGLE_ARG_PARAMETER);
02681       ACE_CHECK_RETURN (0);
02682 
02683       return servant;
02684     }
02685   else
02686     {
02687       // If no servant has been associated with the POA, the NoServant
02688       // exception is raised.
02689       ACE_THROW_RETURN (PortableServer::POA::NoServant (),
02690                         0);
02691     }
02692 }
02693 
02694 void
02695 TAO_Root_POA::set_servant (PortableServer::Servant servant
02696                            ACE_ENV_ARG_DECL)
02697   ACE_THROW_SPEC ((CORBA::SystemException,
02698                    PortableServer::POA::WrongPolicy))
02699 {
02700   // Lock access for the duration of this transaction.
02701   TAO_POA_GUARD;
02702 
02703   this->active_policy_strategies_.request_processing_strategy()->
02704     set_servant (servant ACE_ENV_ARG_PARAMETER);
02705   ACE_CHECK;
02706 }
02707 
02708 #endif /* TAO_HAS_MINIMUM_POA == 0 && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO) */
02709 
02710 bool
02711 TAO_Root_POA::is_servant_activation_allowed (PortableServer::Servant servant,
02712                                              int &wait_occurred_restart_call)
02713 {
02714   return this->active_policy_strategies_.id_uniqueness_strategy ()->
02715     is_servant_activation_allowed (servant, wait_occurred_restart_call);
02716 }
02717 
02718 bool
02719 TAO_Root_POA::has_system_id (void) const
02720 {
02721   return this->active_policy_strategies_.id_assignment_strategy ()->
02722     has_system_id ();
02723 }
02724 
02725 int
02726 TAO_Root_POA::rebind_using_user_id_and_system_id (
02727   PortableServer::Servant servant,
02728   const PortableServer::ObjectId &user_id,
02729   const PortableServer::ObjectId &system_id,
02730   TAO::Portable_Server::Servant_Upcall &servant_upcall)
02731 {
02732   return this->active_policy_strategies_.servant_retention_strategy ()->
02733     rebind_using_user_id_and_system_id (servant,
02734                                         user_id,
02735                                         system_id,
02736                                         servant_upcall);
02737 }
02738 
02739 CORBA::Boolean
02740 TAO_Root_POA::servant_has_remaining_activations (PortableServer::Servant servant)
02741 {
02742   return this->active_policy_strategies_.servant_retention_strategy ()->
02743     servant_has_remaining_activations (servant);
02744 }
02745 
02746 bool
02747 TAO_Root_POA::allow_implicit_activation (void) const
02748 {
02749   return this->active_policy_strategies_.implicit_activation_strategy ()->
02750     allow_implicit_activation ();
02751 }
02752 
02753 bool
02754 TAO_Root_POA::allow_multiple_activations (void) const
02755 {
02756   return this->active_policy_strategies_.id_uniqueness_strategy ()->
02757     allow_multiple_activations ();
02758 }
02759 
02760 void
02761 TAO_Root_POA::post_invoke_servant_cleanup(
02762   const PortableServer::ObjectId &system_id,
02763   const TAO::Portable_Server::Servant_Upcall &servant_upcall)
02764 {
02765   this->active_policy_strategies_.request_processing_strategy ()->
02766     post_invoke_servant_cleanup (system_id, servant_upcall);
02767 }
02768 
02769 CORBA::Short
02770 TAO_Root_POA::server_priority (void) const
02771 {
02772   return this->cached_policies_.server_priority ();
02773 }
02774 
02775 int
02776 TAO_Root_POA::is_servant_active (
02777   PortableServer::Servant servant,
02778   int &wait_occurred_restart_call)
02779 {
02780   return this->active_policy_strategies_.servant_retention_strategy ()->
02781     is_servant_in_map (servant, wait_occurred_restart_call);
02782 }
02783 
02784 TAO::Portable_Server::Cached_Policies::PriorityModel
02785 TAO_Root_POA::priority_model (void) const
02786 {
02787   return cached_policies_.priority_model ();
02788 }
02789 
02790 #if (TAO_HAS_MINIMUM_POA == 0)
02791 int
02792 TAO_Root_POA::enter ()
02793 {
02794   return this->active_policy_strategies_.thread_strategy ()->enter();
02795 }
02796 #endif /* TAO_HAS_MINIMUM_POA == 0 */
02797 
02798 #if (TAO_HAS_MINIMUM_POA == 0)
02799 int
02800 TAO_Root_POA::exit ()
02801 {
02802   return this->active_policy_strategies_.thread_strategy ()->exit();
02803 }
02804 #endif /* TAO_HAS_MINIMUM_POA == 0 */
02805 
02806 bool
02807 TAO_Root_POA::validate_lifespan (
02808   CORBA::Boolean is_persistent,
02809   const TAO::Portable_Server::Temporary_Creation_Time& creation_time) const
02810 {
02811   return this->active_policy_strategies_.lifespan_strategy()->
02812     validate (is_persistent, creation_time);
02813 }
02814 
02815 CORBA::Boolean
02816 TAO_Root_POA::root (void) const
02817 {
02818   return true;
02819 }
02820 
02821 TAO::ORT_Adapter *
02822 TAO_Root_POA::ORT_adapter (ACE_ENV_SINGLE_ARG_DECL)
02823   ACE_THROW_SPEC ((CORBA::SystemException))
02824 {
02825   if (this->ort_adapter_ != 0)
02826     return this->ort_adapter_;
02827 
02828   // Lock access for the duration of this transaction.
02829   TAO_POA_GUARD_RETURN (0);
02830 
02831   // DCL ..
02832   if (this->ort_adapter_ != 0)
02833     return this->ort_adapter_;
02834 
02835   return this->ORT_adapter_i ();
02836 }
02837 
02838 CORBA::Policy *
02839 TAO_Root_POA::server_protocol (void)
02840 {
02841   return 0;
02842 }
02843 
02844 void
02845 TAO_Root_POA::Key_To_Object_Params::set (PortableServer::ObjectId_var &system_id,
02846                                          const char *type_id,
02847                                          TAO_ServantBase *servant,
02848                                          CORBA::Boolean collocated,
02849                                          CORBA::Short priority,
02850                                          bool indirect)
02851 {
02852   this->system_id_ = &system_id;
02853   this->type_id_ = type_id;
02854   this->servant_ = servant;
02855   this->collocated_ = collocated;
02856   this->priority_ = priority;
02857   this->indirect_ = indirect;
02858 }
02859 
02860 CORBA::ULong
02861 TAO_Root_POA::waiting_servant_deactivation (void) const
02862 {
02863   return this->active_policy_strategies_.servant_retention_strategy ()->
02864           waiting_servant_deactivation ();
02865 }
02866 
02867 void
02868 TAO_Root_POA::ort_adapter_factory_name (const char *name)
02869 {
02870   TAO_POA_Static_Resources::instance ()->ort_adapter_factory_name_ =
02871     name;
02872 }
02873 
02874 CORBA::Policy_ptr
02875 TAO_Root_POA::get_policy (CORBA::PolicyType policy
02876                           ACE_ENV_ARG_DECL)
02877 {
02878   return this->policies_.get_policy (policy ACE_ENV_ARG_PARAMETER);
02879 }
02880 
02881 void
02882 TAO_Root_POA::check_state (ACE_ENV_SINGLE_ARG_DECL)
02883 {
02884   this->active_policy_strategies_.lifespan_strategy ()->
02885     check_state (ACE_ENV_SINGLE_ARG_PARAMETER);
02886 }
02887 
02888 const char *
02889 TAO_Root_POA::ort_adapter_factory_name (void)
02890 {
02891   return TAO_POA_Static_Resources::instance ()->ort_adapter_factory_name_.c_str();
02892 }
02893 
02894 void
02895 TAO_Root_POA::imr_client_adapter_name (const char *name)
02896 {
02897   TAO_POA_Static_Resources::instance ()->imr_client_adapter_name_ = name;
02898 }
02899 
02900 const char *
02901 TAO_Root_POA::imr_client_adapter_name (void)
02902 {
02903   return TAO_POA_Static_Resources::instance ()->imr_client_adapter_name_.c_str();
02904 }
02905 
02906 PortableServer::POAManager_ptr
02907 TAO_Root_POA::the_POAManager (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
02908   ACE_THROW_SPEC ((CORBA::SystemException))
02909 {
02910   return PortableServer::POAManager::_duplicate (&this->poa_manager_);
02911 }
02912 
02913 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
02914 PortableServer::POAManagerFactory_ptr
02915 TAO_Root_POA::the_POAManagerFactory (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
02916   ACE_THROW_SPEC ((CORBA::SystemException))
02917 {
02918   return PortableServer::POAManagerFactory::_duplicate (&this->poa_manager_factory_);
02919 }
02920 #endif
02921 
02922 CORBA::ORB_ptr
02923 TAO_Root_POA::_get_orb (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
02924 {
02925   return CORBA::ORB::_duplicate (this->orb_core_.orb ());
02926 }
02927 
02928 // Initialize instance_ to 0, since this is what we test for in the call
02929 // to instance ().  Note that this does not require a constructor call, so
02930 // it is always initialized by the time that instance () can be called.
02931 TAO_POA_Static_Resources* TAO_POA_Static_Resources::instance_ = 0;
02932 
02933 // Force an instance to be created at module initialization time,
02934 // since we do not want to worry about double checked locking and
02935 // the race condition to initialize the lock.
02936 TAO_POA_Static_Resources* TAO_POA_Static_Resources::initialization_reference_ =
02937   TAO_POA_Static_Resources::instance ();
02938 
02939 TAO_POA_Static_Resources*
02940 TAO_POA_Static_Resources::instance (void)
02941 {
02942   if (TAO_POA_Static_Resources::instance_ == 0)
02943     {
02944       // This new is never freed on purpose.  The data specified by
02945       // it needs to be around for the last shared library that references
02946       // this class.  This could occur in a destructor in a shared library
02947       // that is unloaded after this one.  One solution to avoid this
02948       // harmless memory leak would be to use reference counting.
02949       ACE_NEW_RETURN (TAO_POA_Static_Resources::instance_,
02950                       TAO_POA_Static_Resources (),
02951                       0);
02952     }
02953 
02954   return TAO_POA_Static_Resources::instance_;
02955 }
02956 
02957 TAO_POA_Static_Resources::TAO_POA_Static_Resources (void)
02958   : ort_adapter_factory_name_ ("ORT_Adapter_Factory"),
02959     imr_client_adapter_name_ ("ImR_Client_Adapter")
02960 {
02961 }
02962 
02963 void
02964 TAO_Root_POA::poa_activated_hook ()
02965 {
02966 }
02967 
02968 void
02969 TAO_Root_POA::poa_deactivated_hook ()
02970 {
02971 }
02972 
02973 void
02974 TAO_Root_POA::servant_activated_hook (PortableServer::Servant,
02975                                       const PortableServer::ObjectId&
02976                                       ACE_ENV_ARG_DECL)
02977 {
02978 }
02979 
02980 void
02981 TAO_Root_POA::servant_deactivated_hook (PortableServer::Servant,
02982                                         const PortableServer::ObjectId&
02983                                         ACE_ENV_ARG_DECL)
02984 {
02985 }
02986 
02987 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 12:40:43 2006 for TAO_PortableServer by doxygen 1.3.6