Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

TAO_Policy_Set Class Reference

The policy manager implementation. More...

#include <Policy_Set.h>

Collaboration diagram for TAO_Policy_Set:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Policy_Set (TAO_Policy_Scope scope)
 TAO_Policy_Set (const TAO_Policy_Set &rhs)
 ~TAO_Policy_Set (void)
 Destructor. More...

void copy_from (TAO_Policy_Set *source ACE_ENV_ARG_DECL)
 Copy the state from <source>, it uses the copy() operator to obtain independent copies of all the policies. More...

void set_policy_overrides (const CORBA::PolicyList &policies, CORBA::SetOverrideType set_add ACE_ENV_ARG_DECL_WITH_DEFAULTS)
CORBA::PolicyListget_policy_overrides (const CORBA::PolicyTypeSeq &types ACE_ENV_ARG_DECL_WITH_DEFAULTS)
 Get the values (if any) for the policies in <types>, if <types> is an empty list the method returns *all* the current policies. More...

CORBA::Policy_ptr get_policy (CORBA::PolicyType policy ACE_ENV_ARG_DECL_WITH_DEFAULTS)
 Obtain a single policy. More...

CORBA::Policy_ptr get_cached_const_policy (TAO_Cached_Policy_Type type) const
 Obtain a cached policy for speedy lookups. This method just returns a const reference to the policy to avoid obtaining a lock to increment the reference count. As such, it can only be used for single threaded cases or cases where the policies cannot be removed such as at the object and thread level scopes. This method is most likely not appropriate for accessing policies at the ORB level scope in any situation. More...

CORBA::Policy_ptr get_cached_policy (TAO_Cached_Policy_Type type)
 Obtain a single cached policy. More...

void set_policy (const CORBA::Policy_ptr policy ACE_ENV_ARG_DECL)
 Utility method to set a single policy. More...

CORBA::Policyget_policy_by_index (CORBA::ULong index)
 Returns the policy at the specified index. CORBA::Policy::_nil () is returned if the policy doesn't exist. More...

CORBA::ULong num_policies (void) const

Private Methods

TAO_Policy_Set operator= (const TAO_Policy_Set &)
void cleanup_i (ACE_ENV_SINGLE_ARG_DECL)
 Remove and destroy all the policy objects owned by this policy manager. More...

CORBA::Boolean compatible_scope (TAO_Policy_Scope policy_scope) const
 Utility method to determine if a policy's scope is compatible with ours. More...


Private Attributes

CORBA::PolicyList policy_list_
 Policies set for this Policy_Manager. More...

CORBA::Policycached_policies_ [TAO_CACHED_POLICY_MAX_CACHED]
 List of caches. More...

TAO_Policy_Scope scope_
 Scope associated to the Policy Manager Impl. More...


Detailed Description

The policy manager implementation.

This class is used to implement both the CORBA::PolicyManager and the CORBA::PolicyCurrent interfaces.

Definition at line 37 of file Policy_Set.h.


Constructor & Destructor Documentation

ACE_INLINE TAO_Policy_Set::TAO_Policy_Set TAO_Policy_Scope    scope
 

Creates a TAO_Policy_Set that has a given scope. The scope is used to determinate whether or not a given policy can be set for the given Policy Manager Implementation.

Definition at line 4 of file Policy_Set.i.

References cached_policies_, TAO_CACHED_POLICY_MAX_CACHED, and TAO_Policy_Scope.

00005   : scope_ (scope)
00006 {
00007   for (int i = 0; i < TAO_CACHED_POLICY_MAX_CACHED; i++)
00008     this->cached_policies_[i] = 0;
00009 }

TAO_Policy_Set::TAO_Policy_Set const TAO_Policy_Set &    rhs
 

Definition at line 29 of file Policy_Set.cpp.

References CORBA::Policy_var::_retn, ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_CHECK, ACE_ENDTRY, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_PRINT_EXCEPTION, ACE_TRY_CHECK, ACE_TRY_NEW_ENV, cached_policies_, CORBA::is_nil, TAO_Unbounded_Base_Sequence::length, policy_list_, CORBA::Policy_var::ptr, TAO_CACHED_POLICY_MAX_CACHED, and TAO_CACHED_POLICY_UNCACHED.

00030   :
00031     scope_ (rhs.scope_)
00032 {
00033   // Initialize the cache.
00034   for (int i = 0; i < TAO_CACHED_POLICY_MAX_CACHED; i++)
00035     this->cached_policies_[i] = 0;
00036 
00037   // Copy over the policy list.
00038   this->policy_list_.length (rhs.policy_list_.length ());
00039 
00040   ACE_TRY_NEW_ENV
00041     {
00042       for (CORBA::ULong i = 0;
00043            i < rhs.policy_list_.length ();
00044            ++i)
00045         {
00046           CORBA::Policy_ptr policy = rhs.policy_list_[i];
00047           if (CORBA::is_nil (policy))
00048             continue;
00049 
00050           CORBA::Policy_var copy = policy->copy (ACE_ENV_SINGLE_ARG_PARAMETER);
00051           ACE_CHECK;
00052 
00053           // Add the "cacheable" policies into the cache.
00054           if (copy->_tao_cached_type () != TAO_CACHED_POLICY_UNCACHED)
00055             this->cached_policies_[copy->_tao_cached_type ()] = copy.ptr ();
00056 
00057           this->policy_list_[i] = copy._retn ();
00058         }
00059       ACE_TRY_CHECK;
00060     }
00061   ACE_CATCHANY
00062     {
00063       if (TAO_debug_level > 4)
00064         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00065                              "TAO_Policy_Set::TAO_Policy_Set");
00066 
00067       // "Try" to make this recoverable as we must have run out of memory.
00068       this->policy_list_.length (0);
00069     }
00070   ACE_ENDTRY;
00071 }

TAO_Policy_Set::~TAO_Policy_Set void   
 

Destructor.

Definition at line 14 of file Policy_Set.cpp.

References ACE_CATCHANY, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_TRY, ACE_TRY_CHECK, and cleanup_i.

00015 {
00016   ACE_DECLARE_NEW_CORBA_ENV;
00017   ACE_TRY
00018     {
00019       this->cleanup_i (ACE_ENV_SINGLE_ARG_PARAMETER);
00020       ACE_TRY_CHECK;
00021     }
00022   ACE_CATCHANY
00023     {
00024       // Ignore exceptions...
00025     }
00026   ACE_ENDTRY;
00027 }


Member Function Documentation

void TAO_Policy_Set::cleanup_i ACE_ENV_SINGLE_ARG_DECL    [private]
 

Remove and destroy all the policy objects owned by this policy manager.

Definition at line 109 of file Policy_Set.cpp.

References CORBA::Policy::_nil, ACE_CHECK, ACE_ENV_SINGLE_ARG_DECL, ACE_ENV_SINGLE_ARG_PARAMETER, cached_policies_, TAO_Unbounded_Base_Sequence::length, policy_list_, and TAO_CACHED_POLICY_MAX_CACHED.

Referenced by copy_from, set_policy_overrides, and ~TAO_Policy_Set.

00110 {
00111   CORBA::ULong i;
00112 
00113   // Cleanup the policy list.
00114   for (i = 0;
00115        i < this->policy_list_.length ();
00116        ++i)
00117     {
00118       this->policy_list_[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00119       ACE_CHECK;
00120       this->policy_list_[i] = CORBA::Policy::_nil ();
00121     }
00122   this->policy_list_.length (0);
00123 
00124   // Cleanup the cache.
00125   for (i = 0; i < TAO_CACHED_POLICY_MAX_CACHED; i++)
00126     this->cached_policies_[i] = 0;
00127 }

ACE_INLINE CORBA::Boolean TAO_Policy_Set::compatible_scope TAO_Policy_Scope    policy_scope const [private]
 

Utility method to determine if a policy's scope is compatible with ours.

Definition at line 12 of file Policy_Set.i.

References scope_, and TAO_Policy_Scope.

Referenced by copy_from, and set_policy.

00013 {
00014   return ((unsigned int) policy_scope & (unsigned int) this->scope_);
00015 }

void TAO_Policy_Set::copy_from TAO_Policy_Set *source    ACE_ENV_ARG_DECL
 

Copy the state from <source>, it uses the copy() operator to obtain independent copies of all the policies.

Definition at line 74 of file Policy_Set.cpp.

References CORBA::Policy_var::_retn, ACE_CHECK, ACE_ENV_ARG_DECL, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_THROW, cached_policies_, cleanup_i, compatible_scope, CORBA::is_nil, TAO_Unbounded_Base_Sequence::length, policy_list_, CORBA::Policy_var::ptr, and TAO_CACHED_POLICY_UNCACHED.

00076 {
00077   if (source == 0)
00078     return;
00079 
00080   this->cleanup_i (ACE_ENV_SINGLE_ARG_PARAMETER);
00081   ACE_CHECK;
00082 
00083   for (CORBA::ULong i = 0;
00084        i < source->policy_list_.length ();
00085        ++i)
00086     {
00087       CORBA::Policy_ptr policy = source->policy_list_[i];
00088       if (CORBA::is_nil (policy))
00089         continue;
00090 
00091       if (! this->compatible_scope (policy->_tao_scope()))
00092         ACE_THROW (CORBA::NO_PERMISSION ());
00093 
00094       CORBA::Policy_var copy = policy->copy (ACE_ENV_SINGLE_ARG_PARAMETER);
00095       ACE_CHECK;
00096 
00097       CORBA::ULong length = this->policy_list_.length ();
00098       this->policy_list_.length (length + 1);
00099 
00100       // Add the "cacheable" policies into the cache.
00101       if (copy->_tao_cached_type () != TAO_CACHED_POLICY_UNCACHED)
00102         this->cached_policies_[copy->_tao_cached_type ()] = copy.ptr ();
00103 
00104       this->policy_list_[length] = copy._retn ();
00105     }
00106 }

CORBA::Policy_ptr TAO_Policy_Set::get_cached_const_policy TAO_Cached_Policy_Type    type const
 

Obtain a cached policy for speedy lookups. This method just returns a const reference to the policy to avoid obtaining a lock to increment the reference count. As such, it can only be used for single threaded cases or cases where the policies cannot be removed such as at the object and thread level scopes. This method is most likely not appropriate for accessing policies at the ORB level scope in any situation.

Definition at line 310 of file Policy_Set.cpp.

References CORBA::Policy::_nil, cached_policies_, TAO_CACHED_POLICY_MAX_CACHED, TAO_Cached_Policy_Type, and TAO_CACHED_POLICY_UNCACHED.

00311 {
00312   if (type != TAO_CACHED_POLICY_UNCACHED && type < TAO_CACHED_POLICY_MAX_CACHED)
00313     return this->cached_policies_[type];
00314 
00315   return CORBA::Policy::_nil ();
00316 }

CORBA::Policy_ptr TAO_Policy_Set::get_cached_policy TAO_Cached_Policy_Type    type
 

Obtain a single cached policy.

Definition at line 319 of file Policy_Set.cpp.

References CORBA::Policy::_duplicate, CORBA::Policy::_nil, TAO_CACHED_POLICY_MAX_CACHED, TAO_Cached_Policy_Type, and TAO_CACHED_POLICY_UNCACHED.

Referenced by TAO_Stub::buffering_constraint, TAO_Stub::connection_timeout, TAO_Policy_Current_Impl::get_cached_policy, TAO_Policy_Manager::get_cached_policy, TAO_ORB_Core::get_cached_policy, TAO_Stub::relative_roundtrip_timeout, TAO_ORB_Core::stubless_connection_timeout, TAO_ORB_Core::stubless_relative_roundtrip_timeout, TAO_ORB_Core::stubless_sync_scope, and TAO_Stub::sync_scope.

00320 {
00321   if (type != TAO_CACHED_POLICY_UNCACHED && type < TAO_CACHED_POLICY_MAX_CACHED)
00322     return CORBA::Policy::_duplicate (this->cached_policies_[type]);
00323 
00324   return CORBA::Policy::_nil ();
00325 }

CORBA::Policy_ptr TAO_Policy_Set::get_policy CORBA::PolicyType policy    ACE_ENV_ARG_DECL_WITH_DEFAULTS
 

Obtain a single policy.

Referenced by TAO_Stub::get_client_policy, TAO_Policy_Current_Impl::get_policy, and TAO_Policy_Manager::get_policy.

ACE_INLINE CORBA::Policy * TAO_Policy_Set::get_policy_by_index CORBA::ULong    index
 

Returns the policy at the specified index. CORBA::Policy::_nil () is returned if the policy doesn't exist.

Definition at line 18 of file Policy_Set.i.

References CORBA::Policy::_duplicate.

00019 {
00020   return CORBA::Policy::_duplicate (this->policy_list_[index]);
00021 }

CORBA::PolicyList * TAO_Policy_Set::get_policy_overrides const CORBA::PolicyTypeSeq &types    ACE_ENV_ARG_DECL_WITH_DEFAULTS
 

Get the values (if any) for the policies in <types>, if <types> is an empty list the method returns *all* the current policies.

Definition at line 231 of file Policy_Set.cpp.

References CORBA::Policy::_duplicate, CORBA::PolicyList_var::_retn, ACE_CHECK_RETURN, ACE_ENV_ARG_DECL, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_NEW_THROW_EX, TAO_Unbounded_Base_Sequence::length, and policy_list_.

Referenced by TAO_Stub::get_policy_overrides, and TAO_Policy_Current_Impl::get_policy_overrides.

00234 {
00235   CORBA::ULong types_length = types.length ();
00236 
00237   CORBA::ULong slots = types_length;
00238   CORBA::PolicyList *policy_list_ptr;
00239 
00240   if (slots == 0)
00241     {
00242       slots = this->policy_list_.length ();
00243       ACE_NEW_THROW_EX (policy_list_ptr,
00244                         CORBA::PolicyList (slots),
00245                         CORBA::NO_MEMORY ());
00246       ACE_CHECK_RETURN (0);
00247       *policy_list_ptr = this->policy_list_;
00248       return policy_list_ptr;
00249     }
00250 
00251   ACE_NEW_THROW_EX (policy_list_ptr,
00252                     CORBA::PolicyList (slots),
00253                     CORBA::NO_MEMORY ());
00254   ACE_CHECK_RETURN (0);
00255 
00256   CORBA::PolicyList_var policy_list (policy_list_ptr);
00257 
00258   policy_list->length (slots);
00259 
00260   CORBA::ULong n = 0;
00261 
00262   for (CORBA::ULong j = 0; j < types.length ();  ++j)
00263     {
00264       CORBA::ULong slot = types[j];
00265 
00266       CORBA::ULong length = this->policy_list_.length ();
00267       for (CORBA::ULong i = 0;
00268            i != length;
00269            ++i)
00270         {
00271           CORBA::ULong current =
00272             this->policy_list_[i]->policy_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00273           ACE_CHECK_RETURN (0);
00274 
00275           if (current != slot)
00276             continue;
00277 
00278           policy_list[n++] =
00279             CORBA::Policy::_duplicate (this->policy_list_[i].in ());
00280           break;
00281         }
00282     }
00283   policy_list->length (n);
00284   return policy_list._retn ();
00285 }

ACE_INLINE CORBA::ULong TAO_Policy_Set::num_policies void    const
 

Definition at line 24 of file Policy_Set.i.

References TAO_Unbounded_Base_Sequence::length, and policy_list_.

00025 {
00026   return this->policy_list_.length();
00027 }

TAO_Policy_Set TAO_Policy_Set::operator= const TAO_Policy_Set &    [private]
 

void TAO_Policy_Set::set_policy const CORBA::Policy_ptr policy    ACE_ENV_ARG_DECL
 

Utility method to set a single policy.

Definition at line 184 of file Policy_Set.cpp.

References CORBA::Policy_var::_retn, ACE_CHECK, ACE_ENV_ARG_DECL, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_THROW, cached_policies_, compatible_scope, TAO_Unbounded_Base_Sequence::length, policy_list_, CORBA::Policy_var::ptr, TAO_Cached_Policy_Type, and TAO_CACHED_POLICY_UNCACHED.

Referenced by set_policy_overrides.

00186 {
00187   if (! this->compatible_scope (policy->_tao_scope()))
00188     ACE_THROW (CORBA::NO_PERMISSION ());
00189 
00190   CORBA::PolicyType policy_type = policy->policy_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00191   ACE_CHECK;
00192 
00193   CORBA::Policy_var copy = policy->copy (ACE_ENV_SINGLE_ARG_PARAMETER);
00194   ACE_CHECK;
00195 
00196 
00197   CORBA::ULong j = 0;
00198   CORBA::ULong length = this->policy_list_.length ();
00199   while (j != length)
00200     {
00201       CORBA::ULong current =
00202         this->policy_list_[j]->policy_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00203       ACE_CHECK;
00204 
00205       if (current == policy_type)
00206         {
00207           this->policy_list_[j]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00208           ACE_CHECK;
00209           this->policy_list_[j] = copy.ptr ();
00210           break;
00211         }
00212       ++j;
00213     }
00214   if (j == length)
00215     {
00216       this->policy_list_.length (length + 1);
00217       this->policy_list_[j] = copy.ptr ();
00218     }
00219 
00220   // If this is a policy that gets accessed on the critical path,
00221   // save a pointer to it in the cache.
00222   TAO_Cached_Policy_Type cached_policy_type = policy->_tao_cached_type ();
00223   if (cached_policy_type != TAO_CACHED_POLICY_UNCACHED)
00224     this->cached_policies_[cached_policy_type] = copy.ptr ();
00225 
00226   // Transfer ownership to the policy list.
00227   (void) copy._retn ();
00228 }

void TAO_Policy_Set::set_policy_overrides const CORBA::PolicyList   policies,
CORBA::SetOverrideType set_add    ACE_ENV_ARG_DECL_WITH_DEFAULTS
 

Modify the list of policies to include <policies>. If <set_add> is CORBA::SET_OVERRIDE then we replace all the old policies. If it is CORBA::ADD_OVERRIDE we simply add the policies in <policies>. No attempt is made to validate the policies for consistency.

Definition at line 131 of file Policy_Set.cpp.

References CORBA::Policy::_duplicate, ACE_CHECK, ACE_ENV_ARG_DECL, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_THROW, cleanup_i, CORBA::Policy_var::in, CORBA::is_nil, TAO_Unbounded_Base_Sequence::length, set_policy, and TAO_RT_SERVER_PROTOCOL_POLICY_TYPE.

Referenced by TAO_Policy_Current_Impl::set_policy_overrides.

00135 {
00136   // @@ The spec does not say what to do on this case.
00137   if (set_add != CORBA::SET_OVERRIDE
00138       && set_add != CORBA::ADD_OVERRIDE)
00139     ACE_THROW (CORBA::BAD_PARAM ());
00140 
00141   if (set_add == CORBA::SET_OVERRIDE)
00142     {
00143       this->cleanup_i (ACE_ENV_SINGLE_ARG_PARAMETER);
00144       ACE_CHECK;
00145     }
00146 
00147   // Flag, indicating whether we have already overridden
00148   // RTCORBA::ServerProtocolPolicy during this call.
00149   int server_protocol_set = 0;
00150 
00151   for (CORBA::ULong i = 0; i < policies.length ();  ++i)
00152     {
00153       // Because MSVC 5 has a bug, we had to replace
00154       // a simple CORBA::Policy_var policy = policies[i];
00155       // with the following.
00156       CORBA::Policy_ptr temp = policies[i];
00157       CORBA::Policy_var policy = CORBA::Policy::_duplicate (temp);
00158 
00159       if (CORBA::is_nil (policy.in ()))
00160         continue;
00161 
00162       CORBA::PolicyType policy_type = policy->policy_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00163       ACE_CHECK;
00164 
00165       if (policy_type == TAO_RT_SERVER_PROTOCOL_POLICY_TYPE)
00166         {
00167           // Only one ServerProtocolPolicy should be included in a
00168           // given PolicyList (section 4.15.2 of RTCORBA 1.0, i.e.,
00169           // ptc/99-05-03).
00170           // User-caused exceptional conditions can leave the Policy
00171           // Manager in an inconsistent state.  It is the
00172           // responsibility of the user to return it to consistent state.
00173           if (server_protocol_set != 0)
00174             ACE_THROW (CORBA::INV_POLICY ());
00175           server_protocol_set = 1;
00176         }
00177 
00178       this->set_policy (policy.in () ACE_ENV_ARG_PARAMETER);
00179       ACE_CHECK;
00180     }
00181 }


Member Data Documentation

CORBA::Policy* TAO_Policy_Set::cached_policies_[TAO_CACHED_POLICY_MAX_CACHED] [private]
 

List of caches.

Definition at line 118 of file Policy_Set.h.

Referenced by cleanup_i, copy_from, get_cached_const_policy, set_policy, and TAO_Policy_Set.

CORBA::PolicyList TAO_Policy_Set::policy_list_ [private]
 

Policies set for this Policy_Manager.

Definition at line 115 of file Policy_Set.h.

Referenced by cleanup_i, copy_from, get_policy_overrides, num_policies, set_policy, and TAO_Policy_Set.

TAO_Policy_Scope TAO_Policy_Set::scope_ [private]
 

Scope associated to the Policy Manager Impl.

Definition at line 121 of file Policy_Set.h.

Referenced by compatible_scope.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 15:36:18 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002