diff options
Diffstat (limited to 'TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.h')
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.h | 658 |
1 files changed, 0 insertions, 658 deletions
diff --git a/TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.h b/TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.h deleted file mode 100644 index d07f746050b..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.h +++ /dev/null @@ -1,658 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Trader_Utils.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// Client Utils: -// TAO_Policy_Manager -// TAO_Property_Evaluator -// TAO_Property_Evaluator_By_Name -// -// Service Utils: -// TAO_Policies -// TAO_Offer_Filter -// TAO_Offer_Modifier -// TAO_Property_Filter -// TAO_Property_Evaluator -// TAO_Property_Evaluator_By_Name -// -// ======================================================================== - -#ifndef TAO_TRADER_UTILS_H -#define TAO_TRADER_UTILS_H - -#include "Trader.h" - - - // ************************************************************* - // TAO_Property_Evaluator - // ************************************************************* - -class TAO_ORBSVCS_Export TAO_Property_Evaluator -// -// = TITLE -// This class abstracts away the details of obtaining property -// values and property types. Since the procedure for obtaining the -// value or type of a dynamic property is disparate from the method -// for a static property, TAO_Property_Evaluator provides methods -// that will unify the two approaches under a single -// interface. Since dynamic properties aren't necessarily supported -// by a trader, this class accounts for that contingency. The use of -// indexed lookups allows them to occur in constant time on the -// CORBA sequences, but requires that the client know the layout of -// properties ahead of time. -{ -public: - - TAO_Property_Evaluator(const CosTrading::PropertySeq& properties, - CORBA::Boolean supports_dp = 1); - - TAO_Property_Evaluator(CosTrading::Offer& offer, - CORBA::Boolean supports_dp = 1); - // Construct an instance of TAO_Property_Evaluator that operates on - // an <offer> where the support for dynamic properties is dictated - // by <supports_dynamic_properties>. - - int is_dynamic_property(int index); - // Returns 1 if the property at index <index> is dynamic. Returns a - // 0 when the index is out of bounds. - - CORBA::Any* property_value(int index, CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTradingDynamic::DPEvalFailure)); - - // Returns value of the property whose index is <index>. If the - // property at that index is dynamic and the trader supports dynamic - // properties, then the property_value method will obtain the value - // of the dynamic property using the evalDP method on the - // CosTradingDynamic::DynamicPropEval interface, passing on a - // CosTradingDynamic::DPEvalFailure exception on failure. If the - // property index is undefined, the method returns a null pointer. - - CORBA::TypeCode* property_type(int index); - // Returns the type of the property whose index is <index>. If the - // property is dynamic and the trader supports dynamic properties, - // then the method returns the <returned_type> field of the - // CosTradingDynamic::DynamicProp struct associated with the - // property name. If the index is out of bounds, the method returns - // a null pointer (that is, 0). - -protected: - - typedef CosTradingDynamic::DynamicProp DP_Struct; - typedef CosTradingDynamic::DynamicPropEval DP_Eval; - - const CosTrading::PropertySeq& props_; - // The offer from which the TAO_Property_Evaluator extracts property - // information. - - int supports_dp_; -}; - - // ************************************************************* - // TAO_Property_Evaluator_By_Name - // ************************************************************* - -class TAO_Property_Evaluator_By_Name : public TAO_Property_Evaluator -// -// = TITLE -// This class extends the TAO_Property_Evaluator to allow lookups -// based on the property name of interest. Since the property -// information is contained within an integer indexed array, -// lookups may occur in O(n) time, where n is the length of the -// array. To make lookups by name more efficient, -// TAO_Property_Evaluator_By_Name creates a mapping of property -// names to integer indicies, upon which lookups are guaranteed to -// be O(lg n). -{ -public: - - TAO_Property_Evaluator_By_Name (const CosTrading::PropertySeq& properties, - CORBA::Environment& _env, - CORBA::Boolean supports_dp = 1) - TAO_THROW_SPEC ((CosTrading::DuplicatePropertyName, - CosTrading::IllegalPropertyName)); - - TAO_Property_Evaluator_By_Name(CosTrading::Offer& offer, - CORBA::Boolean supports_dp = 1); - // Construct an instance of TAO_Property_Evaluator that operates on - // an <offer> where the support for dynamic properties is dictated - // by <supports_dynamic_properties>. - - int is_dynamic_property(const char* property_name); - // Returns 1 if the property whose name is <property_name> is - // defined and dynamic. If the property is undefined, this method - // will throw a Property_Undefined exception with impunity. - - CORBA::Any* property_value(const char* property_name, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTradingDynamic::DPEvalFailure)); - - // This method is identical to its counterpart in - // TAO_Property_Evaluator, except property_value first discovers the - // index through a string matching lookup. - - CORBA::TypeCode* property_type(const char* property_name); - // This method is identical to its counterpart in - // TAO_Property_Evaluator, exception property_type first discovers - // the index through a string matching lookup. - - const CosTrading::Property* get_property (const char* property_name); - -private: - - typedef ACE_Hash_Map_Manager - < - TAO_String_Hash_Key, - int, - ACE_Null_Mutex - > - Lookup_Table; - // A mapping, upon which lookups will take O(lg n), of property - // names to sequence indices. - - Lookup_Table table_; - // The instance of the above mapping for the offer provided in the - // constructor. -}; - - // ************************************************************* - // TAO_Policies - // ************************************************************* - -class TAO_Policies -// -// = TITLE -// This class ensures that policies submitted to Lookup make sense, -// have the correct value types, and don't exceed the maximums set -// through the Admin Interface. -// -// = DESCRIPTION -// TAO_Policies does an admirable job of reconciling differences -// between the default parameter settings of the Trader and the import -// and other policies set by the client. Unbeknownst to its client -// TAO_Policies hides this arbitration, and records whether the user -// policy was chosen, or the default. This information gets returned -// to the invoker of the query method. -{ -public: - -#define TAO_NUM_POLICIES 11 - - enum POLICY_TYPE - { - EXACT_TYPE_MATCH, - HOP_COUNT, - LINK_FOLLOW_RULE, - MATCH_CARD, - RETURN_CARD, - SEARCH_CARD, - STARTING_TRADER, - USE_DYNAMIC_PROPERTIES, - USE_MODIFIABLE_PROPERTIES, - USE_PROXY_OFFERS, - REQUEST_ID - }; - - static const char * POLICY_NAMES[]; - - TAO_Policies (TAO_Trader_Base& trader, - const CosTrading::PolicySeq& policies, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPolicyName, - CosTrading::DuplicatePolicyName)); - - // BEGIN SPEC - // The "policies" parameter allows the importer to specify how the - // search should be performed as opposed to what sort of services - // should be found in the course of the search. This can be viewed - // as parameterizing the algorithms within the trader - // implementation. The "policies" are a sequence of name-value - // pairs. The names available to an importer depend on the - // implementation of the trader. However, some names are - // standardized where they effect the interpretation of other - // parameters or where they may impact linking and federation of - // traders. ° If a policy name in this parameter does not obey the - // syntactic rules for legal PolicyName's, then an IllegalPolicyName - // exception is raised. ° If the type of the value associated with a - // policy differs from that specified in this specification, then a - // PolicyTypeMismatch exception is raised. ° If subsequent - // processing of a PolicyValue yields any errors (e.g., the - // starting_trader policy value is malformed), then an - // InvalidPolicyValue exception is raised. ° If the same policy name - // is included two or more times in this parameter, then the - // DuplicatePolicyName exception is raised. - // END SPEC - - ~TAO_Policies (void); - - CORBA::ULong search_card (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - - // BEGIN SPEC - // The "search_card" policy indicates to the trader the maximum - // number of offers it should consider when looking for type - // conformance and constraint expression match. The lesser of this - // value and the trader's max_search_card attribute is used by the - // trader. If this policy is not specified, then the value of the - // trader's def_search_card attribute is used. - // END SPEC - - CORBA::ULong match_card (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - - // BEGIN SPEC - // The "match_card" policy indicates to the trader the maximum - // number of matching offers to which the preference specification - // should be applied. The lesser of this value and the trader's - // max_match_card attribute is used by the trader. If this policy is - // not specified, then the value of the trader's def_match_card - // attribute is used. - // END SPEC - - CORBA::ULong return_card (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - - // BEGIN SPEC - // The "return_card" policy indicates to the trader the maximum - // number of matching offers to return as a result of this - // query. The lesser of this value and the trader's max_return_card - // attribute is used by the trader. If this policy is not specified, - // then the value of the trader's def_return_card attribute is - // used. - // END SPEC - - // = Offer consideration policies - - CORBA::Boolean use_modifiable_properties (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - - // BEGIN SPEC - // The "use_modifiable_properties" policy indicates whether the - // trader should consider offers which have modifiable properties - // when constructing the set of offers to which type conformance and - // constraint processing should be applied. If the value of this - // policy is TRUE, then such offers will be included; if FALSE, they - // will not. If this policy is not specified, such offers will be - // included. - // END SPEC - - CORBA::Boolean use_dynamic_properties (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - - // BEGIN SPEC - // The "use_dynamic_properties" policy indicates whether the trader - // should consider offers which have dynamic properties when - // constructing the set of offers to which type conformance and - // constraint processing should be applied. If the value of this - // policy is TRUE, then such offers will be included; if FALSE, they - // will not. If this policy is not specified, such offers will be - // included. - // END SPEC - - CORBA::Boolean use_proxy_offers (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - - // BEGIN SPEC - // The "use_proxy_offers" policy indicates whether the trader should - // consider proxy offers when constructing the set of offers to - // which type conformance and constraint processing should be - // applied. If the value of this policy is TRUE, then such offers - // will be included; if FALSE, they will not. If this policy is not - // specified, such offers will be included. - // END SPEC - - CORBA::Boolean exact_type_match (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - - // BEGIN SPEC - // The "exact_type_match" policy indicates to the trader whether the - // importer's service type must exactly match an offer's service - // type; if not (and by default), then any offer of a type - // conformant to the importer's service type is considered. - // END SPEC - - // = Federated trader policies (not implemented yet) - - CosTrading::TraderName* starting_trader (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue)); - // BEGIN SPEC - // The "starting_trader" policy facilitates the distribution of the - // trading service itself. It allows an importer to scope a search - // by choosing to explicitly navigate the links of the trading - // graph. If the policy is used in a query invocation it is - // recommended that it be the first policy-value pair; this - // facilitates an optimal forwarding of the query operation. A - // "policies" parameter need not include a value for the - // "starting_trader" policy. Where this policy is present, the first - // name component is compared against the name held in each link. If - // no match is found, the InvalidPolicyValue exception is - // raised. Otherwise, the trader invokes query() on the Lookup - // interface held by the named link, but passing the - // "starting_trader" policy with the first component removed. - // END SPEC - - CosTrading::FollowOption link_follow_rule (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - // Determine the link follow policy for this query overall. - - CosTrading::FollowOption link_follow_rule (const char* link_name, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue)); - // Determine the link follow policy for a given <link_name>. - - // BEGIN SPEC - //The "link_follow_rule" policy indicates how the client wishes - //links to be followed in the resolution of its query. See the - //discussion in "Link Follow Behavior" on page 16-16 for details. - // END SPEC - - // This method returns the link_follow_rule for a link whose name is - // <link_name> using the following formula: - // if the importer specified a link_follow_rule policy - // min(trader.max_follow_policy, link.limiting_follow_rule, - // query.link_follow_rule) - // else min(trader.max_follow_policy, link.limiting_follow_rule, - // trader.def_follow_policy) - - CORBA::ULong hop_count (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - - // BEGIN SPEC - // The "hop_count" policy indicates to the trader the maximum number - // of hops across federation links that should be tolerated in the - // resolution of this query. The hop_count at the current trader is - // determined by taking the minimum of the trader's max_hop_count - // attribute and the importer's hop_count policy, if provided, or - // the trader's def_hop_count attribute if it is not. If the - // resulting value is zero, then no federated queries are - // permitted. If it is greater than zero, then it must be - // decremented before passing on to a federated trader. - // END SPEC - - CosTrading::Admin::OctetSeq* request_id (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - // Return the request_id passed to the query method across a link to - // another trader. - - CosTrading::PolicySeq* policies_to_forward (void); - // Policies to forward to the next trader in a directed federated query. - - CosTrading::PolicySeq* - policies_to_pass (CosTrading::FollowOption def_pass_on_follow_rule, - CORBA::ULong offers_returned, - CosTrading::Admin_ptr admin_if); - // Policies to pass on to the next generation of queries. Decrements - // the hop counter,adds a link_follow_rule if none exists, adjusts - // the return_card, and adds the stem_id if none exists. - -private: - - CORBA::ULong ulong_prop (POLICY_TYPE pol, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - // Reconclile a ULong property with its default. - - CORBA::Boolean boolean_prop (POLICY_TYPE pol, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); - // Reconcile a Boolean property with its debault. - - CosTrading::Policy* policies_[TAO_NUM_POLICIES]; - // The policies indexable from the enumerated type. - - TAO_Trader_Base& trader_; - // For the validating identifier names. -}; - - // ************************************************************* - // TAO_Policy_Manager - // ************************************************************* - -class TAO_ORBSVCS_Export TAO_Policy_Manager -// = TITLE -// -// This class is a utility for clients using the CosTrading::Lookup -// interface that helps them build a policy sequence without violating -// syntax rules and having to mess with typecodes. -{ -public: - - TAO_Policy_Manager (int num_policies = 0); - - // = Routines to set policies. - - void search_card (CORBA::ULong scard); - - void match_card (CORBA::ULong mcard); - - void return_card (CORBA::ULong rcard); - - void use_modifiable_properties (CORBA::Boolean mod_props); - - void use_dynamic_properties (CORBA::Boolean dyn_props); - - void use_proxy_offers (CORBA::Boolean prox_offs); - - void starting_trader (CosTrading::TraderName* name); - - void link_follow_rule (CosTrading::FollowOption follow_option); - - void hop_count (CORBA::ULong hop_count); - - void request_id (CosTrading::Admin::OctetSeq* reqiest_id); - - void exact_type_match (CORBA::Boolean exact_type); - - operator const CosTrading::PolicySeq& (void) const; - - const CosTrading::PolicySeq& policy_seq (void) const; - // Return a PolicySeq suitable for passing to the query method of - // the Lookup interface. - -private: - - CosTrading::Policy& fetch_next_policy (TAO_Policies::POLICY_TYPE pol_type); - - int poltable_[TAO_Policies::REQUEST_ID + 1]; - - CosTrading::PolicySeq policies_; - - CORBA::ULong num_policies_; -}; - - - // ************************************************************* - // TAO_Offer_Modifier - // ************************************************************* - -class TAO_Offer_Modifier -// = TITLE -// This class deletes, modifies, and adds properties to a given -// offer according to the rules of the modify method on the Register -// interface. -{ -public: - - TAO_Offer_Modifier (const char* type, - CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct, - CosTrading::Offer& offer); - // Modify an <offer> of type <type>, whose properties are described - // by <type_struct> - - void delete_properties (const CosTrading::PropertyNameSeq& deletes, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Register::UnknownPropertyName, - CosTrading::Register::MandatoryProperty, - CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName)); - // Delete the properties whose names were given to the - // constructor. Ensure we don't delete mandatory properties. - - void merge_properties (const CosTrading::PropertySeq& modifies, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName, - CosTrading::Register::ReadonlyProperty)); - // Copy to the destination the union of the source and destination - // properties. In the case of duplicate properties, update the - // destination with the source's value. - - CosTrading::Offer& affect_change (void); - // Return a reference to the Offer with the changes affected. - -private: - - typedef ACE_Unbounded_Set<TAO_String_Hash_Key> Prop_Names; - - typedef ACE_Hash_Map_Manager - < - TAO_String_Hash_Key, - CosTrading::Property*, - ACE_Null_Mutex - > - Props; - - const char* type_; - // The type of the offer. - - Props props_; - // The map of properties in the offer. - - Prop_Names readonly_, mandatory_; - // The set of readonly and mandatory property names in the offer's - // type. - - CosTrading::Offer& offer_; - // A reference to the offer undergoing change. -}; - - - // ************************************************************* - // TAO_Offer_Filter - // ************************************************************* - -class TAO_Offer_Filter -// = TITLE -// The purpose of this class is to ensure that offers that -// shouldn't be considered by the TAO_Constraint_Interpreter -// aren't. -// -// = DESCRIPTION -// 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. -{ -public: - - typedef CosTradingRepos::ServiceTypeRepository SERVICE_TYPE_REPOS; - - TAO_Offer_Filter (SERVICE_TYPE_REPOS::TypeStruct* type_struct, - TAO_Policies& policies, - CORBA::Environment& _env); - // Glean from the TypeStruct and Policy setting the appropriate way - // to screen unsuitable offers from consideration. - - CORBA::Boolean 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. - - CORBA::Boolean 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. - - void matched_offer (void); - // Signal that the Lookup method has matched an offer; decrement the - // match_card. - - // = Return the limits applied. - CosTrading::PolicyNameSeq* 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 - -private: - - typedef ACE_Unbounded_Set<TAO_String_Hash_Key> Names; - - Names mod_props_; - // The set of the name of modifiable properties. - - Names limits_; - // Cardinality and property limitations applied. - - CORBA::ULong search_card_, match_card_, return_card_; - // Keep track of the cardinalities. - - CORBA::Boolean dp_; - CORBA::Boolean mod_; - // Keep track of property limitations: modifiable or dynamic ones - // may be bad. -}; - - // ************************************************************* - // TAO_Property_Filter - // ************************************************************* - -class TAO_Property_Filter -// = TITLE -// -// The Ace_Property_Filter copies those properties specified in a -// CosTrading::Lookup::SpecifiedProps from a source -// CosTrading::Offer to a destination CosTrading::Offer. -{ -public: - - typedef CosTrading::Lookup::SpecifiedProps SPECIFIED_PROPS; - - TAO_Property_Filter (const SPECIFIED_PROPS& desired_props, - CORBA::Environment& env) - TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName)); - // Verify that the specified properties are correct. - - TAO_Property_Filter (const TAO_Property_Filter& prop_filter); - - void filter_offer (CosTrading::Offer& source, - CosTrading::Offer& destination); - // Copy the desired properties from the source offer to the - // destination offer. - -private: - - typedef ACE_Unbounded_Set< TAO_String_Hash_Key > Prop_Names; - typedef ACE_Unbounded_Queue< CosTrading::Property* > Prop_Queue; - - Prop_Names props_; - CosTrading::Lookup::HowManyProps policy_; -}; - -#endif /* TAO_TRADER_UTILS_H */ |