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 Member Functions

 TAO_Policy_Set (TAO_Policy_Scope scope)
 TAO_Policy_Set (const TAO_Policy_Set &rhs)
 Copy constructor.
 ~TAO_Policy_Set (void)
 Destructor.
void copy_from (TAO_Policy_Set *source)
void set_policy_overrides (const CORBA::PolicyList &policies, CORBA::SetOverrideType set_add)
CORBA::PolicyList * get_policy_overrides (const CORBA::PolicyTypeSeq &types)
CORBA::Policy_ptr get_policy (CORBA::PolicyType policy)
 Obtain a single policy.
CORBA::Policy_ptr get_cached_const_policy (TAO_Cached_Policy_Type type) const
 Obtain a cached policy for speedy lookups.
CORBA::Policy_ptr get_cached_policy (TAO_Cached_Policy_Type type)
 Obtain a single cached policy.
void set_policy (const CORBA::Policy_ptr policy)
 Utility method to set a single policy.
CORBA::Policyget_policy_by_index (CORBA::ULong index) const
CORBA::ULong num_policies (void) const

Private Member Functions

TAO_Policy_Setoperator= (const TAO_Policy_Set &)
void cleanup_i (void)
CORBA::Boolean compatible_scope (TAO_Policy_Scope policy_scope) const
 Utility method to determine if a policy's scope is compatible with ours.

Private Attributes

CORBA::PolicyList policy_list_
 Policies set for this Policy_Manager.
CORBA::Policycached_policies_ [TAO_CACHED_POLICY_MAX_CACHED]
 List of caches.
TAO_Policy_Scope scope_
 Scope associated to the Policy Manager Impl.

Detailed Description

The policy manager implementation.

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

Definition at line 39 of file Policy_Set.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL 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 18 of file Policy_Set.cpp.

References TAO_CACHED_POLICY_MAX_CACHED.

00019   : scope_ (scope)
00020 {
00021   for (unsigned int i = 0; i < TAO_CACHED_POLICY_MAX_CACHED; ++i)
00022     this->cached_policies_[i] = 0;
00023 }

TAO_Policy_Set::TAO_Policy_Set ( const TAO_Policy_Set rhs  ) 

Copy constructor.

Definition at line 37 of file Policy_Set.cpp.

References TAO_Objref_Var_T< T >::_retn(), cached_policies_, CORBA::is_nil(), policy_list_, TAO_Objref_Var_T< T >::ptr(), TAO_CACHED_POLICY_MAX_CACHED, TAO_CACHED_POLICY_UNCACHED, and TAO_debug_level.

00038   : scope_ (rhs.scope_)
00039 {
00040   // Initialize the cache.
00041   for (int i = 0; i < TAO_CACHED_POLICY_MAX_CACHED; ++i)
00042     {
00043       this->cached_policies_[i] = 0;
00044     }
00045 
00046   // Copy over the policy list.
00047   this->policy_list_.length (rhs.policy_list_.length ());
00048 
00049   try
00050     {
00051       for (CORBA::ULong i = 0; i < rhs.policy_list_.length (); ++i)
00052         {
00053           CORBA::Policy_ptr policy = rhs.policy_list_[i];
00054 
00055           if (CORBA::is_nil (policy))
00056             {
00057               continue;
00058             }
00059 
00060           CORBA::Policy_var copy =
00061             policy->copy ();
00062 
00063           TAO_Cached_Policy_Type const cached_type =
00064             copy->_tao_cached_type ();
00065 
00066           // Add the "cacheable" policies into the cache.
00067           if (cached_type != TAO_CACHED_POLICY_UNCACHED
00068               && cached_type >= 0)
00069             {
00070               this->cached_policies_[cached_type] = copy.ptr ();
00071             }
00072 
00073           this->policy_list_[i] = copy._retn ();
00074         }
00075 
00076     }
00077   catch (const ::CORBA::Exception& ex)
00078     {
00079       if (TAO_debug_level > 4)
00080         ex._tao_print_exception ("TAO_Policy_Set::TAO_Policy_Set");
00081 
00082       // "Try" to make this recoverable as we must have run out of memory.
00083       this->policy_list_.length (0);
00084     }
00085 }

TAO_Policy_Set::~TAO_Policy_Set ( void   ) 

Destructor.

Definition at line 25 of file Policy_Set.cpp.

References cleanup_i().

00026 {
00027   try
00028     {
00029       this->cleanup_i ();
00030     }
00031   catch (const ::CORBA::Exception&)
00032     {
00033       // Ignore exceptions...
00034     }
00035 }


Member Function Documentation

void TAO_Policy_Set::cleanup_i ( void   )  [private]

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

Definition at line 132 of file Policy_Set.cpp.

References CORBA::Policy::_nil(), policy_list_, and TAO_CACHED_POLICY_MAX_CACHED.

Referenced by copy_from(), set_policy_overrides(), and ~TAO_Policy_Set().

00133 {
00134   CORBA::ULong const len = this->policy_list_.length ();
00135   // Cleanup the policy list.
00136   for (CORBA::ULong i = 0; i < len; ++i)
00137     {
00138       this->policy_list_[i]->destroy ();
00139       this->policy_list_[i] = CORBA::Policy::_nil ();
00140     }
00141 
00142   this->policy_list_.length (0);
00143 
00144   // Cleanup the cache.
00145   for (CORBA::ULong j = 0; j < TAO_CACHED_POLICY_MAX_CACHED; ++j)
00146     {
00147       this->cached_policies_[j] = 0;
00148     }
00149 }

TAO_BEGIN_VERSIONED_NAMESPACE_DECL 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 8 of file Policy_Set.inl.

00009 {
00010   return
00011     ((static_cast<unsigned int> (policy_scope)
00012       & static_cast<unsigned int> (this->scope_)) > 0);
00013 }

void TAO_Policy_Set::copy_from ( TAO_Policy_Set source  ) 

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

Definition at line 88 of file Policy_Set.cpp.

References TAO_Objref_Var_T< T >::_retn(), cached_policies_, cleanup_i(), CORBA::is_nil(), policy_list_, TAO_Objref_Var_T< T >::ptr(), and TAO_CACHED_POLICY_UNCACHED.

00089 {
00090   if (source == 0)
00091     {
00092       return;
00093     }
00094 
00095   this->cleanup_i ();
00096 
00097   for (CORBA::ULong i = 0; i < source->policy_list_.length (); ++i)
00098     {
00099       CORBA::Policy_ptr policy = source->policy_list_[i];
00100 
00101       if (CORBA::is_nil (policy))
00102         {
00103           continue;
00104         }
00105 
00106       if (! this->compatible_scope (policy->_tao_scope()))
00107         {
00108           throw ::CORBA::NO_PERMISSION ();
00109         }
00110 
00111       CORBA::Policy_var copy =
00112         policy->copy ();
00113 
00114       CORBA::ULong const length = this->policy_list_.length ();
00115       this->policy_list_.length (length + 1);
00116 
00117       TAO_Cached_Policy_Type const cached_type =
00118         copy->_tao_cached_type ();
00119 
00120       // Add the "cacheable" policies into the cache.
00121       if (cached_type != TAO_CACHED_POLICY_UNCACHED
00122           && cached_type >= 0)
00123         {
00124           this->cached_policies_[cached_type] = copy.ptr ();
00125         }
00126 
00127       this->policy_list_[length] = copy._retn ();
00128     }
00129 }

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 328 of file Policy_Set.cpp.

References CORBA::Policy::_nil(), cached_policies_, TAO_CACHED_POLICY_MAX_CACHED, and TAO_CACHED_POLICY_UNCACHED.

00329 {
00330   if (type != TAO_CACHED_POLICY_UNCACHED
00331       && type < TAO_CACHED_POLICY_MAX_CACHED)
00332     {
00333       return this->cached_policies_[type];
00334     }
00335 
00336   return CORBA::Policy::_nil ();
00337 }

CORBA::Policy_ptr TAO_Policy_Set::get_cached_policy ( TAO_Cached_Policy_Type  type  ) 

Obtain a single cached policy.

Definition at line 340 of file Policy_Set.cpp.

References CORBA::Policy::_duplicate(), CORBA::Policy::_nil(), TAO_CACHED_POLICY_MAX_CACHED, and TAO_CACHED_POLICY_UNCACHED.

Referenced by TAO_Stub::get_cached_policy(), TAO_Policy_Manager::get_cached_policy(), TAO_Policy_Current_Impl::get_cached_policy(), and TAO_ORB_Core::get_cached_policy().

00341 {
00342   if (type != TAO_CACHED_POLICY_UNCACHED
00343       && type < TAO_CACHED_POLICY_MAX_CACHED)
00344     {
00345       return CORBA::Policy::_duplicate (this->cached_policies_[type]);
00346     }
00347 
00348   return CORBA::Policy::_nil ();
00349 }

CORBA::Policy_ptr TAO_Policy_Set::get_policy ( CORBA::PolicyType  policy  ) 

Obtain a single policy.

Definition at line 307 of file Policy_Set.cpp.

References CORBA::Policy::_duplicate(), CORBA::Policy::_nil(), and policy_list_.

Referenced by TAO_Stub::get_policy(), TAO_Policy_Manager::get_policy(), TAO_Policy_Current_Impl::get_policy(), and TAO_ORB_Core::get_policy().

00308 {
00309   CORBA::ULong const length = this->policy_list_.length ();
00310 
00311   for (CORBA::ULong i = 0; i < length; ++i)
00312     {
00313       const CORBA::ULong current =
00314         this->policy_list_[i]->policy_type ();
00315 
00316       if (current != type)
00317         {
00318           continue;
00319         }
00320 
00321       return CORBA::Policy::_duplicate (this->policy_list_[i]);
00322     }
00323 
00324   return CORBA::Policy::_nil ();
00325 }

ACE_INLINE CORBA::Policy * TAO_Policy_Set::get_policy_by_index ( CORBA::ULong  index  )  const

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

Definition at line 16 of file Policy_Set.inl.

References CORBA::Policy::_duplicate().

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

CORBA::PolicyList * TAO_Policy_Set::get_policy_overrides ( const CORBA::PolicyTypeSeq &  types  ) 

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 257 of file Policy_Set.cpp.

References CORBA::Policy::_duplicate(), ACE_NEW_THROW_EX, and policy_list_.

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

00258 {
00259   CORBA::ULong const slots = types.length ();
00260   CORBA::PolicyList *policy_list_ptr = 0;
00261 
00262   if (slots == 0)
00263     {
00264       // Copy our own policy list.
00265       ACE_NEW_THROW_EX (policy_list_ptr,
00266                         CORBA::PolicyList (this->policy_list_),
00267                         CORBA::NO_MEMORY ());
00268 
00269       return policy_list_ptr;
00270     }
00271 
00272   ACE_NEW_THROW_EX (policy_list_ptr,
00273                     CORBA::PolicyList (slots),
00274                     CORBA::NO_MEMORY ());
00275 
00276   CORBA::PolicyList_var policy_list (policy_list_ptr);
00277   policy_list->length (slots);
00278   CORBA::ULong n = 0;
00279 
00280   for (CORBA::ULong j = 0; j < slots; ++j)
00281     {
00282       CORBA::ULong const slot = types[j];
00283       CORBA::ULong const length = this->policy_list_.length ();
00284 
00285       for (CORBA::ULong i = 0; i < length; ++i)
00286         {
00287           CORBA::ULong const current =
00288             this->policy_list_[i]->policy_type ();
00289 
00290           if (current != slot)
00291             {
00292               continue;
00293             }
00294 
00295           policy_list[n++] =
00296             CORBA::Policy::_duplicate (this->policy_list_[i]);
00297           break;
00298         }
00299     }
00300 
00301   policy_list->length (n);  // Truncate buffer if necessary.
00302 
00303   return policy_list._retn ();
00304 }

ACE_INLINE CORBA::ULong TAO_Policy_Set::num_policies ( void   )  const

Definition at line 22 of file Policy_Set.inl.

References policy_list_.

00023 {
00024   return this->policy_list_.length();
00025 }

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

void TAO_Policy_Set::set_policy ( const CORBA::Policy_ptr  policy  ) 

Utility method to set a single policy.

Definition at line 205 of file Policy_Set.cpp.

References TAO_Objref_Var_T< T >::_retn(), CORBA::Policy::_tao_cached_type(), CORBA::Policy::_tao_scope(), cached_policies_, CORBA::Policy::copy(), policy_list_, CORBA::Policy::policy_type(), TAO_Objref_Var_T< T >::ptr(), and TAO_CACHED_POLICY_UNCACHED.

Referenced by set_policy_overrides().

00206 {
00207   if (! this->compatible_scope (policy->_tao_scope()))
00208     {
00209       throw ::CORBA::NO_PERMISSION ();
00210     }
00211 
00212   CORBA::PolicyType const policy_type = policy->policy_type ();
00213 
00214   CORBA::Policy_var copy = policy->copy ();
00215 
00216   CORBA::ULong j = 0;
00217   CORBA::ULong const length = this->policy_list_.length ();
00218 
00219   while (j != length)
00220     {
00221       CORBA::ULong current =
00222         this->policy_list_[j]->policy_type ();
00223 
00224       if (current == policy_type)
00225         {
00226           this->policy_list_[j]->destroy ();
00227 
00228           this->policy_list_[j] = copy.ptr ();
00229           break;
00230         }
00231 
00232       ++j;
00233     }
00234 
00235   if (j == length)
00236     {
00237       this->policy_list_.length (length + 1);
00238       this->policy_list_[j] = copy.ptr ();
00239     }
00240 
00241   // If this is a policy that gets accessed on the critical path,
00242   // save a pointer to it in the cache.
00243   TAO_Cached_Policy_Type const cached_policy_type =
00244     policy->_tao_cached_type ();
00245 
00246   if (cached_policy_type != TAO_CACHED_POLICY_UNCACHED
00247       && cached_policy_type >= 0)
00248     {
00249       this->cached_policies_[cached_policy_type] = copy.ptr ();
00250     }
00251 
00252   // Transfer ownership to the policy list.
00253   (void) copy._retn ();
00254 }

void TAO_Policy_Set::set_policy_overrides ( const CORBA::PolicyList &  policies,
CORBA::SetOverrideType  set_add 
)

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 153 of file Policy_Set.cpp.

References cleanup_i(), CORBA::is_nil(), set_policy(), and TAO_RT_SERVER_PROTOCOL_POLICY_TYPE.

Referenced by TAO_Policy_Manager::set_policy_overrides().

00155 {
00156   // @@ The spec does not say what to do on this case.
00157   if (set_add != CORBA::SET_OVERRIDE && set_add != CORBA::ADD_OVERRIDE)
00158     {
00159       throw ::CORBA::BAD_PARAM ();
00160     }
00161 
00162   if (set_add == CORBA::SET_OVERRIDE)
00163     {
00164       this->cleanup_i ();
00165     }
00166 
00167   // Flag, indicating whether we have already overridden
00168   // RTCORBA::ServerProtocolPolicy during this call.
00169   bool server_protocol_set = false;
00170 
00171   CORBA::ULong const plen = policies.length ();
00172 
00173   for (CORBA::ULong i = 0; i < plen; ++i)
00174     {
00175       CORBA::Policy_ptr policy = policies[i];
00176 
00177       if (CORBA::is_nil (policy))
00178         {
00179           continue;
00180         }
00181 
00182       CORBA::PolicyType const policy_type = policy->policy_type ();
00183 
00184       if (policy_type == TAO_RT_SERVER_PROTOCOL_POLICY_TYPE)
00185         {
00186           // Only one ServerProtocolPolicy should be included in a
00187           // given PolicyList (section 4.15.2 of RTCORBA 1.0, i.e.,
00188           // ptc/99-05-03).
00189           // User-caused exceptional conditions can leave the Policy
00190           // Manager in an inconsistent state.  It is the
00191           // responsibility of the user to return it to consistent state.
00192           if (server_protocol_set)
00193             {
00194               throw ::CORBA::INV_POLICY ();
00195             }
00196 
00197           server_protocol_set = true;
00198         }
00199 
00200       this->set_policy (policy);
00201     }
00202 }


Member Data Documentation

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

List of caches.

Definition at line 115 of file Policy_Set.h.

Referenced by 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 112 of file Policy_Set.h.

Referenced by cleanup_i(), copy_from(), get_policy(), 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 118 of file Policy_Set.h.


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:39:42 2010 for TAO by  doxygen 1.4.7