The policy manager implementation. More...
#include <Policy_Set.h>
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::Policy * | get_policy_by_index (CORBA::ULong index) const |
CORBA::ULong | num_policies (void) const |
Private Member Functions | |
TAO_Policy_Set & | operator= (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::Policy * | cached_policies_ [TAO_CACHED_POLICY_MAX_CACHED] |
List of caches. | |
TAO_Policy_Scope | scope_ |
Scope associated to the Policy Manager Impl. |
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.
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.
: scope_ (scope) { for (unsigned int i = 0; i < TAO_CACHED_POLICY_MAX_CACHED; ++i) this->cached_policies_[i] = 0; }
TAO_Policy_Set::TAO_Policy_Set | ( | const TAO_Policy_Set & | rhs | ) |
Copy constructor.
Definition at line 37 of file Policy_Set.cpp.
: scope_ (rhs.scope_) { // Initialize the cache. for (int i = 0; i < TAO_CACHED_POLICY_MAX_CACHED; ++i) { this->cached_policies_[i] = 0; } // Copy over the policy list. this->policy_list_.length (rhs.policy_list_.length ()); try { for (CORBA::ULong i = 0; i < rhs.policy_list_.length (); ++i) { CORBA::Policy_ptr policy = rhs.policy_list_[i]; if (CORBA::is_nil (policy)) { continue; } CORBA::Policy_var copy = policy->copy (); TAO_Cached_Policy_Type const cached_type = copy->_tao_cached_type (); // Add the "cacheable" policies into the cache. if (cached_type != TAO_CACHED_POLICY_UNCACHED && cached_type >= 0) { this->cached_policies_[cached_type] = copy.ptr (); } this->policy_list_[i] = copy._retn (); } } catch (const ::CORBA::Exception& ex) { if (TAO_debug_level > 4) ex._tao_print_exception ("TAO_Policy_Set::TAO_Policy_Set"); // "Try" to make this recoverable as we must have run out of memory. this->policy_list_.length (0); } }
TAO_Policy_Set::~TAO_Policy_Set | ( | void | ) |
Destructor.
Definition at line 25 of file Policy_Set.cpp.
{ try { this->cleanup_i (); } catch (const ::CORBA::Exception&) { // Ignore exceptions... } }
void TAO_Policy_Set::cleanup_i | ( | void | ) | [private] |
Remove and destroy all the policy objects owned by this policy manager.
Definition at line 127 of file Policy_Set.cpp.
{ CORBA::ULong const len = this->policy_list_.length (); // Cleanup the policy list. for (CORBA::ULong i = 0; i < len; ++i) { this->policy_list_[i]->destroy (); this->policy_list_[i] = CORBA::Policy::_nil (); } this->policy_list_.length (0); // Cleanup the cache. for (CORBA::ULong j = 0; j < TAO_CACHED_POLICY_MAX_CACHED; ++j) { this->cached_policies_[j] = 0; } }
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.
{ return ((static_cast<unsigned int> (policy_scope) & static_cast<unsigned int> (this->scope_)) > 0); }
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 84 of file Policy_Set.cpp.
{ if (source == 0) { return; } this->cleanup_i (); for (CORBA::ULong i = 0; i < source->policy_list_.length (); ++i) { CORBA::Policy_ptr policy = source->policy_list_[i]; if (CORBA::is_nil (policy)) { continue; } if (! this->compatible_scope (policy->_tao_scope())) { throw ::CORBA::NO_PERMISSION (); } CORBA::Policy_var copy = policy->copy (); CORBA::ULong const length = this->policy_list_.length (); this->policy_list_.length (length + 1); TAO_Cached_Policy_Type const cached_type = copy->_tao_cached_type (); // Add the "cacheable" policies into the cache. if (cached_type != TAO_CACHED_POLICY_UNCACHED && cached_type >= 0) { this->cached_policies_[cached_type] = copy.ptr (); } this->policy_list_[length] = copy._retn (); } }
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 320 of file Policy_Set.cpp.
{ if (type != TAO_CACHED_POLICY_UNCACHED && type < TAO_CACHED_POLICY_MAX_CACHED) { return this->cached_policies_[type]; } return CORBA::Policy::_nil (); }
CORBA::Policy_ptr TAO_Policy_Set::get_cached_policy | ( | TAO_Cached_Policy_Type | type | ) |
Obtain a single cached policy.
Definition at line 331 of file Policy_Set.cpp.
{ if (type != TAO_CACHED_POLICY_UNCACHED && type < TAO_CACHED_POLICY_MAX_CACHED) { return CORBA::Policy::_duplicate (this->cached_policies_[type]); } return CORBA::Policy::_nil (); }
CORBA::Policy_ptr TAO_Policy_Set::get_policy | ( | CORBA::PolicyType | policy | ) |
Obtain a single policy.
Definition at line 302 of file Policy_Set.cpp.
{ CORBA::ULong const length = this->policy_list_.length (); for (CORBA::ULong i = 0; i < length; ++i) { CORBA::PolicyType const current = this->policy_list_[i]->policy_type (); if (current == type) { return CORBA::Policy::_duplicate (this->policy_list_[i]); } } return CORBA::Policy::_nil (); }
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.
{ return CORBA::Policy::_duplicate (this->policy_list_[index]); }
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 252 of file Policy_Set.cpp.
{ CORBA::ULong const slots = types.length (); CORBA::PolicyList *policy_list_ptr = 0; if (slots == 0) { // Copy our own policy list. ACE_NEW_THROW_EX (policy_list_ptr, CORBA::PolicyList (this->policy_list_), CORBA::NO_MEMORY ()); return policy_list_ptr; } ACE_NEW_THROW_EX (policy_list_ptr, CORBA::PolicyList (slots), CORBA::NO_MEMORY ()); CORBA::PolicyList_var policy_list (policy_list_ptr); policy_list->length (slots); CORBA::ULong n = 0; for (CORBA::ULong j = 0; j < slots; ++j) { CORBA::ULong const slot = types[j]; CORBA::ULong const length = this->policy_list_.length (); for (CORBA::ULong i = 0; i < length; ++i) { CORBA::ULong const current = this->policy_list_[i]->policy_type (); if (current != slot) { continue; } policy_list[n++] = CORBA::Policy::_duplicate (this->policy_list_[i]); break; } } policy_list->length (n); // Truncate buffer if necessary. return policy_list._retn (); }
CORBA::ULong TAO_Policy_Set::num_policies | ( | void | ) | const |
Definition at line 22 of file Policy_Set.inl.
{ return this->policy_list_.length(); }
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 200 of file Policy_Set.cpp.
{ if (! this->compatible_scope (policy->_tao_scope())) { throw ::CORBA::NO_PERMISSION (); } CORBA::PolicyType const policy_type = policy->policy_type (); CORBA::Policy_var copy = policy->copy (); CORBA::ULong j = 0; CORBA::ULong const length = this->policy_list_.length (); while (j != length) { CORBA::ULong const current = this->policy_list_[j]->policy_type (); if (current == policy_type) { this->policy_list_[j]->destroy (); this->policy_list_[j] = copy.ptr (); break; } ++j; } if (j == length) { this->policy_list_.length (length + 1); this->policy_list_[j] = copy.ptr (); } // If this is a policy that gets accessed on the critical path, // save a pointer to it in the cache. TAO_Cached_Policy_Type const cached_policy_type = policy->_tao_cached_type (); if (cached_policy_type != TAO_CACHED_POLICY_UNCACHED && cached_policy_type >= 0) { this->cached_policies_[cached_policy_type] = copy.ptr (); } // Transfer ownership to the policy list. (void) copy._retn (); }
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 148 of file Policy_Set.cpp.
{ // @@ The spec does not say what to do on this case. if (set_add != CORBA::SET_OVERRIDE && set_add != CORBA::ADD_OVERRIDE) { throw ::CORBA::BAD_PARAM (); } if (set_add == CORBA::SET_OVERRIDE) { this->cleanup_i (); } // Flag, indicating whether we have already overridden // RTCORBA::ServerProtocolPolicy during this call. bool server_protocol_set = false; CORBA::ULong const plen = policies.length (); for (CORBA::ULong i = 0; i < plen; ++i) { CORBA::Policy_ptr policy = policies[i]; if (CORBA::is_nil (policy)) { continue; } CORBA::PolicyType const policy_type = policy->policy_type (); if (policy_type == TAO_RT_SERVER_PROTOCOL_POLICY_TYPE) { // Only one ServerProtocolPolicy should be included in a // given PolicyList (section 4.15.2 of RTCORBA 1.0, i.e., // ptc/99-05-03). // User-caused exceptional conditions can leave the Policy // Manager in an inconsistent state. It is the // responsibility of the user to return it to consistent state. if (server_protocol_set) { throw ::CORBA::INV_POLICY (); } server_protocol_set = true; } this->set_policy (policy); } }
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.
CORBA::PolicyList TAO_Policy_Set::policy_list_ [private] |
Policies set for this Policy_Manager.
Definition at line 112 of file Policy_Set.h.
TAO_Policy_Scope TAO_Policy_Set::scope_ [private] |
Scope associated to the Policy Manager Impl.
Definition at line 118 of file Policy_Set.h.