TAO_Offer_Filter Class Reference

The purpose of this class is to ensure that offers that shouldn't be considered by the TAO_Constraint_Interpreter aren't. More...

#include <Trader_Utils.h>

Collaboration diagram for TAO_Offer_Filter:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_Offer_Filter (TAO_Policies &policies)
void configure_type (CosTradingRepos::ServiceTypeRepository::TypeStruct *type_struct)
CORBA::Boolean ok_to_consider (CosTrading::Offer *offer)
CORBA::Boolean ok_to_consider_more (void)
void matched_offer (void)
CosTrading::PolicyNameSeqlimits_applied (void)
CORBA::ULong search_card_remaining (void) const
 Accessors to retrieve the adjusted cardinalities.
CORBA::ULong match_card_remaining (void) const

Private Member Functions

 TAO_Offer_Filter (const TAO_Offer_Filter &)
TAO_Offer_Filteroperator= (const TAO_Offer_Filter &)

Private Attributes

TAO_String_Set not_mod_props_
 The set of the name of modifiable properties.
TAO_String_Set limits_
 Cardinality and property limitations applied.
CORBA::ULong search_card_
 Keep track of the cardinalities.
CORBA::ULong match_card_
CORBA::ULong return_card_
CORBA::Boolean dp_
CORBA::Boolean mod_

Detailed Description

The purpose of this class is to ensure that offers that shouldn't be considered by the TAO_Constraint_Interpreter aren't.

There two classes of reasons why an offer for a correct type shouldn't be considered: 1) The default parameters of the Trader or policies passed to the Lookup::query method deem it inappropriate to consider offers with modifiable (i.e., not readonly) or dynamic properties. 2) We've exceeded the default or provided cardinality constraints. TAO_Offer_Filter ensures that violation of policies doesn't occur. It's the enforcer.

Definition at line 619 of file Trader_Utils.h.


Constructor & Destructor Documentation

TAO_Offer_Filter::TAO_Offer_Filter ( TAO_Policies policies  ) 

Glean from the TypeStruct and Policy setting the appropriate way to screen unsuitable offers from consideration.

Definition at line 1192 of file Trader_Utils.cpp.

References dp_, TAO_Policies::EXACT_TYPE_MATCH, TAO_Policies::exact_type_match(), ACE_Unbounded_Set_Ex< T, C >::insert(), limits_, TAO_Policies::match_card(), match_card_, mod_, TAO_Policies::POLICY_NAMES, TAO_Policies::return_card(), return_card_, TAO_Policies::search_card(), search_card_, TAO_Policies::use_dynamic_properties(), and TAO_Policies::use_modifiable_properties().

01193 {
01194   search_card_ = policies.search_card ();
01195 
01196   match_card_ = policies.match_card ();
01197 
01198   return_card_ = policies.return_card ();
01199 
01200   dp_ = policies.use_dynamic_properties ();
01201 
01202   mod_ = policies.use_modifiable_properties ();
01203 
01204   CORBA::Boolean exact_type_match =
01205     policies.exact_type_match ();
01206 
01207   if (exact_type_match == 1)
01208     {
01209       CORBA::String_var exact_match
01210         (TAO_Policies::POLICY_NAMES[TAO_Policies::EXACT_TYPE_MATCH]);
01211       this->limits_.insert (exact_match);
01212     }
01213 }

TAO_Offer_Filter::TAO_Offer_Filter ( const TAO_Offer_Filter  )  [private]


Member Function Documentation

void TAO_Offer_Filter::configure_type ( CosTradingRepos::ServiceTypeRepository::TypeStruct type_struct  ) 

Set the offer filter to screen for offers containing properties that aren't marked as readonly in this TypeStruct.

Definition at line 1217 of file Trader_Utils.cpp.

References ACE_Unbounded_Set_Ex< T, C >::insert(), not_mod_props_, CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY_READONLY, CosTradingRepos::ServiceTypeRepository::PROP_READONLY, CosTradingRepos::ServiceTypeRepository::TypeStruct::props, and ACE_Unbounded_Set_Ex< T, C >::reset().

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_all_subtypes(), and TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::query().

01218 {
01219   CosTradingRepos::ServiceTypeRepository::PropStructSeq&
01220     prop_seq = type_struct->props;
01221 
01222   // Take note of non-modifiable properties in the type_struct
01223   this->not_mod_props_.reset ();
01224   for (int i = prop_seq.length () - 1; i >= 0; i--)
01225     {
01226       CosTradingRepos::ServiceTypeRepository::PropertyMode mode = prop_seq[i].mode;
01227       if (mode == CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY_READONLY ||
01228           mode == CosTradingRepos::ServiceTypeRepository::PROP_READONLY)
01229         {
01230           CORBA::String_var prop_name ((const char*) prop_seq[i].name);
01231           this->not_mod_props_.insert (prop_name);
01232         }
01233     }
01234 }

CosTrading::PolicyNameSeq * TAO_Offer_Filter::limits_applied ( void   ) 

BEGIN SPEC If any cardinality or other limits were applied by one or more traders in responding to a particular query, then the "limits_applied" parameter will contain the names of the policies which limited the query. The sequence of names returned in "limits_applied" from any federated or proxy queries must be concatenated onto the names of limits applied locally and returned. END SPEC

Definition at line 1339 of file Trader_Utils.cpp.

References ACE_Unbounded_Set_Ex_Iterator< T, C >::done(), limits_, ACE_Unbounded_Set_Ex< T, C >::size(), size, and CORBA::string_dup().

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::query().

01340 {
01341   int i = 0;
01342   CORBA::ULong size = static_cast<CORBA::ULong> (this->limits_.size ());
01343   CosTrading::PolicyName* temp =
01344     CosTrading::PolicyNameSeq::allocbuf (size);
01345 
01346   for (TAO_String_Set::iterator p_iter (this->limits_.begin());
01347        ! p_iter.done ();
01348        p_iter.advance ())
01349     {
01350       CORBA::String_var* policy_name_ptr = 0;
01351       p_iter.next (policy_name_ptr);
01352       temp[i++] = CORBA::string_dup (policy_name_ptr->in ());
01353     }
01354 
01355   return new CosTrading::PolicyNameSeq (size, size, temp, 1);
01356 }

CORBA::ULong TAO_Offer_Filter::match_card_remaining ( void   )  const

Definition at line 1333 of file Trader_Utils.cpp.

References match_card_.

01334 {
01335   return this->match_card_;
01336 }

void TAO_Offer_Filter::matched_offer ( void   ) 

Signal that the Lookup method has matched an offer; decrement the match_card.

Definition at line 1306 of file Trader_Utils.cpp.

References ACE_Unbounded_Set_Ex< T, C >::insert(), limits_, TAO_Policies::MATCH_CARD, match_card_, TAO_Policies::POLICY_NAMES, and return_card_.

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_one_type().

01307 {
01308   this->match_card_--;
01309   this->return_card_--;
01310 
01311   if (this->match_card_ == 0)
01312     {
01313       CORBA::String_var match_card =
01314         TAO_Policies::POLICY_NAMES[TAO_Policies::MATCH_CARD];
01315       this->limits_.insert (match_card);
01316     }
01317 
01318   if (this->return_card_ == 0)
01319     {
01320       CORBA::String_var return_card =
01321         TAO_Policies::POLICY_NAMES[TAO_Policies::MATCH_CARD];
01322       this->limits_.insert (return_card);
01323     }
01324 }

CORBA::Boolean TAO_Offer_Filter::ok_to_consider ( CosTrading::Offer offer  ) 

Determine whether the poicies contained in the given policy object allow the Lookup interface to consider the offer. That is, if use_modifiable_properties is false, and the offer contains modifiable properties as designated in the type struct, return false. If use_dynamic_properties is false, and the offer contains dynamic properties, then return false. If the lookup interface is safe in considering this offer, return true and subtract from the search card value. When the search card value falls to zero, ok_to_consider always returns false.

Definition at line 1237 of file Trader_Utils.cpp.

References ACE_Unbounded_Set_Ex< T, C >::insert(), TAO_Property_Evaluator::is_dynamic_property(), limits_, TAO_Policies::POLICY_NAMES, CosTrading::Offer::properties, TAO_Policies::SEARCH_CARD, search_card_, TAO_Policies::USE_DYNAMIC_PROPERTIES, and TAO_Policies::USE_MODIFIABLE_PROPERTIES.

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_one_type().

01238 {
01239   CORBA::String_var use_mods =
01240     TAO_Policies::POLICY_NAMES[TAO_Policies::USE_MODIFIABLE_PROPERTIES];
01241   CORBA::String_var use_dyns =
01242     TAO_Policies::POLICY_NAMES[TAO_Policies::USE_DYNAMIC_PROPERTIES];
01243   CORBA::Boolean return_value = 1;
01244   TAO_Property_Evaluator prop_eval (*offer);
01245 
01246   // If we should screen offers, determine if this offer is unworthy
01247   // for consideration.
01248   if (! (this->mod_ && this->dp_))
01249     {
01250       for (int i = offer->properties.length () - 1;
01251            i >= 0 && return_value;
01252            i--)
01253         {
01254           // Winnow away the unwanted offers with modifiable or
01255           // dynamic properties.
01256           if (! this->mod_)
01257             {
01258               // Determine if this property name is found in the set
01259               // of modifiable properties for the type being considered.
01260               CORBA::String_var prop_name ((const char*) offer->properties[i].name);
01261               if (this->not_mod_props_.find (prop_name) == -1)
01262                 {
01263                   this->limits_.insert (use_mods);
01264                   return_value = 0;
01265                 }
01266             }
01267 
01268           if (! this->dp_ && return_value)
01269             {
01270               // Determine if this property is dynamic.
01271               if (prop_eval.is_dynamic_property (i))
01272                 {
01273                   this->limits_.insert (use_dyns);
01274                   return_value = 0;
01275                 }
01276             }
01277 
01278           if (return_value == 0)
01279             break;
01280         }
01281     }
01282 
01283   // If we're good to go, consider this offer considered and decrement
01284   // the search cardinality counter.
01285   if (return_value)
01286     {
01287       this->search_card_--;
01288       if (this->search_card_ == 0)
01289         {
01290           CORBA::String_var search_card =
01291             TAO_Policies::POLICY_NAMES[TAO_Policies::SEARCH_CARD];
01292           this->limits_.insert (search_card);
01293         }
01294     }
01295 
01296   return return_value;
01297 }

CORBA::Boolean TAO_Offer_Filter::ok_to_consider_more ( void   ) 

It's ok to consider more offers when lookup hasn't exceeded the cardinality values for searching and matching offers.

Definition at line 1300 of file Trader_Utils.cpp.

References match_card_, and search_card_.

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_all_subtypes(), and TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_one_type().

01301 {
01302   return this->search_card_ > 0 && this->match_card_ > 0;
01303 }

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

CORBA::ULong TAO_Offer_Filter::search_card_remaining ( void   )  const

Accessors to retrieve the adjusted cardinalities.

Definition at line 1327 of file Trader_Utils.cpp.

References search_card_.

01328 {
01329   return this->search_card_;
01330 }


Member Data Documentation

CORBA::Boolean TAO_Offer_Filter::dp_ [private]

Keep track of property limitations: modifiable or dynamic ones may be bad.

Definition at line 686 of file Trader_Utils.h.

Referenced by TAO_Offer_Filter().

TAO_String_Set TAO_Offer_Filter::limits_ [private]

Cardinality and property limitations applied.

Definition at line 679 of file Trader_Utils.h.

Referenced by limits_applied(), matched_offer(), ok_to_consider(), and TAO_Offer_Filter().

CORBA::ULong TAO_Offer_Filter::match_card_ [private]

Definition at line 682 of file Trader_Utils.h.

Referenced by match_card_remaining(), matched_offer(), ok_to_consider_more(), and TAO_Offer_Filter().

CORBA::Boolean TAO_Offer_Filter::mod_ [private]

Definition at line 687 of file Trader_Utils.h.

Referenced by TAO_Offer_Filter().

TAO_String_Set TAO_Offer_Filter::not_mod_props_ [private]

The set of the name of modifiable properties.

Definition at line 676 of file Trader_Utils.h.

Referenced by configure_type().

CORBA::ULong TAO_Offer_Filter::return_card_ [private]

Definition at line 682 of file Trader_Utils.h.

Referenced by matched_offer(), and TAO_Offer_Filter().

CORBA::ULong TAO_Offer_Filter::search_card_ [private]

Keep track of the cardinalities.

Definition at line 682 of file Trader_Utils.h.

Referenced by ok_to_consider(), ok_to_consider_more(), search_card_remaining(), and TAO_Offer_Filter().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:49:33 2010 for TAO_CosTrader by  doxygen 1.4.7