Trader_Utils.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Trader_Utils.h
00006  *
00007  *  Trader_Utils.h,v 1.38 2006/04/25 11:35:29 jwillemsen Exp
00008  *
00009  *  @author Seth Widoff <sbw1@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_TRADER_UTILS_H
00015 #define TAO_TRADER_UTILS_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "orbsvcs/Trader/Trader.h"
00020 
00021 #if defined(_MSC_VER)
00022 #pragma warning(push)
00023 #pragma warning(disable:4250)
00024 #endif /* _MSC_VER */
00025 
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027 
00028 /**
00029  * @class TAO_Property_Evaluator
00030  *
00031  * @brief This class abstracts away the details of obtaining property
00032  * values and property types. Since the procedure for obtaining the
00033  * value or type of a dynamic property is disparate from the method
00034  * for a static property, TAO_Property_Evaluator provides methods
00035  * that will unify the two approaches under a single
00036  * interface. Since dynamic properties aren't necessarily supported
00037  * by a trader, this class accounts for that contingency. The use of
00038  * indexed lookups allows them to occur in constant time on the
00039  * CORBA sequences, but requires that the client know the layout of
00040  * properties ahead of time.
00041  */
00042 class TAO_Trading_Serv_Export TAO_Property_Evaluator
00043 {
00044 public:
00045 
00046   TAO_Property_Evaluator(const CosTrading::PropertySeq& properties,
00047                          CORBA::Boolean supports_dp = 1);
00048 
00049   /**
00050    * Construct an instance of TAO_Property_Evaluator that operates on
00051    * an <offer> where the support for dynamic properties is dictated
00052    * by <supports_dynamic_properties>.
00053    */
00054   TAO_Property_Evaluator(CosTrading::Offer& offer,
00055                          CORBA::Boolean supports_dp = 1);
00056 
00057   /// Clean up dynamic properties.
00058   virtual ~TAO_Property_Evaluator (void);
00059 
00060   /// Returns 1 if the property at index <index> is dynamic. Returns a
00061   /// 0 when the index is out of bounds.
00062   int is_dynamic_property(int index);
00063 
00064   /**
00065         * Returns value of the property whose index is <index>. If the
00066         * property at that index is dynamic and the trader supports dynamic
00067         * properties, then the property_value method will obtain the value
00068         * of the dynamic property using the evalDP method on the
00069         * CosTradingDynamic::DynamicPropEval interface, passing on a
00070         * CosTradingDynamic::DPEvalFailure exception on failure. If the
00071         * property index is undefined, the method returns a null pointer.
00072         */
00073   CORBA::Any* property_value(int index ACE_ENV_ARG_DECL)
00074     ACE_THROW_SPEC ((CosTradingDynamic::DPEvalFailure));
00075 
00076 
00077   /**
00078    * Returns the type of the property whose index is <index>. If the
00079    * property is dynamic and the trader supports dynamic properties,
00080    * then the method returns the <returned_type> field of the
00081    * CosTradingDynamic::DynamicProp struct associated with the
00082    * property name. If the index is out of bounds, the method returns
00083    * a null pointer (that is, 0).
00084    */
00085   CORBA::TypeCode_ptr property_type (int index);
00086 
00087 protected:
00088 
00089   typedef CosTradingDynamic::DynamicProp DP_Struct;
00090   typedef CosTradingDynamic::DynamicPropEval DP_Eval;
00091 
00092   /// The offer from which the TAO_Property_Evaluator extracts property
00093   /// information.
00094   const CosTrading::PropertySeq& props_;
00095 
00096   int supports_dp_;
00097 
00098   /**
00099    * In order for the client to treat the results of property_value
00100    * uniformly, we need to collect the dynamically allocated anys
00101    * retrieved from dynamic properties and free them upon deletion. If
00102    * we didn't do this, then the property_value method would leak or
00103    * cause seg faults, since the client wouldn't be able to tell
00104    * whether or not the return value should be freed.
00105    */
00106   CORBA::Any** dp_cache_;
00107 
00108 private:
00109 
00110   TAO_Property_Evaluator (const TAO_Property_Evaluator&);
00111   TAO_Property_Evaluator& operator= (const TAO_Property_Evaluator&);
00112 };
00113 
00114 /**
00115  * @class TAO_Property_Evaluator_By_Name
00116  *
00117  * @brief This class extends the TAO_Property_Evaluator to allow lookups
00118  * based on the property name of interest. Since the property
00119  * information is contained within an integer indexed array,
00120  * lookups may occur in O(n) time, where n is the length of the
00121  * array. To make lookups by name more efficient,
00122  * TAO_Property_Evaluator_By_Name creates a mapping of property
00123  * names to integer indicies, upon which lookups are guaranteed to
00124  * be O(lg n).
00125  */
00126 class TAO_Trading_Serv_Export TAO_Property_Evaluator_By_Name : public TAO_Property_Evaluator
00127 {
00128 public:
00129 
00130   TAO_Property_Evaluator_By_Name (const CosTrading::PropertySeq& properties
00131                                   ACE_ENV_ARG_DECL ,
00132                                   CORBA::Boolean supports_dp = 1)
00133     ACE_THROW_SPEC ((CosTrading::DuplicatePropertyName,
00134                      CosTrading::IllegalPropertyName));
00135 
00136   /**
00137    * Construct an instance of TAO_Property_Evaluator that operates on
00138    * an <offer> where the support for dynamic properties is dictated
00139    * by <supports_dynamic_properties>.
00140    */
00141   TAO_Property_Evaluator_By_Name(CosTrading::Offer& offer,
00142                                  CORBA::Boolean supports_dp = 1);
00143 
00144   /**
00145    * Returns 1 if the property whose name is <property_name> is
00146    * defined and dynamic. If the property is undefined, this method
00147    * will throw a Property_Undefined exception with impunity.
00148    */
00149   int is_dynamic_property(const char* property_name);
00150 
00151   /**
00152         * This method is identical to its counterpart in
00153         * TAO_Property_Evaluator, except property_value first discovers the
00154         * index through a string matching lookup.
00155         */
00156   CORBA::Any* property_value(const char* property_name
00157                              ACE_ENV_ARG_DECL)
00158     ACE_THROW_SPEC ((CosTradingDynamic::DPEvalFailure));
00159 
00160   /**
00161    * This method is identical to its counterpart in
00162    * TAO_Property_Evaluator, exception property_type first discovers
00163    * the index through a string matching lookup.
00164    */
00165   CORBA::TypeCode_ptr property_type(const char* property_name);
00166 
00167   const CosTrading::Property* get_property (const char* property_name);
00168 
00169 private:
00170 
00171   TAO_Property_Evaluator_By_Name (const TAO_Property_Evaluator_By_Name&);
00172   TAO_Property_Evaluator_By_Name& operator= (const TAO_Property_Evaluator_By_Name&);
00173 
00174   /// The instance of the above mapping for the offer provided in the
00175   /// constructor.
00176   TAO_Lookup_Table table_;
00177 };
00178 
00179 /**
00180  * @class TAO_Dynamic_Property
00181  *
00182  * @brief Little helper class that you can extend to have your dynamic
00183  * property handler construct CosTradingDynamic::DynamicProp structs.
00184  */
00185 class TAO_Trading_Serv_Export TAO_Dynamic_Property
00186   : public virtual POA_CosTradingDynamic::DynamicPropEval
00187 {
00188 public:
00189 
00190   TAO_Dynamic_Property (void) {}
00191   virtual ~TAO_Dynamic_Property (void);
00192 
00193   void destroy (void);
00194 
00195   /// Dynamic property evaluation call-back method.
00196   virtual CORBA::Any* evalDP(const char* name,
00197                              CORBA::TypeCode_ptr returned_type,
00198                              const CORBA::Any& extra_info
00199                              ACE_ENV_ARG_DECL)
00200     ACE_THROW_SPEC ((CORBA::SystemException,
00201                      CosTradingDynamic::DPEvalFailure)) = 0;
00202 
00203   /// Method to construct a dynamic property structure suitable for
00204   /// exporting in a CosTrading::PropertyStruct to the Trading Service.
00205   CosTradingDynamic::DynamicProp*
00206   construct_dynamic_prop (const char* name,
00207                           CORBA::TypeCode_ptr returned_type,
00208                           const CORBA::Any& extra_info);
00209 
00210 private:
00211 
00212   CosTradingDynamic::DynamicPropEval_var prop_;
00213 };
00214 
00215 /**
00216  * @class TAO_Policies
00217  *
00218  * @brief This class ensures that policies submitted to Lookup make sense,
00219  * have the correct value types, and don't exceed the maximums set
00220  * through the Admin Interface.
00221  *
00222  * TAO_Policies does an admirable job of reconciling differences
00223  * between the default parameter settings of the Trader and the import
00224  * and other policies set by the client. Unbeknownst to its client
00225  * TAO_Policies hides this arbitration, and records whether the user
00226  * policy was chosen, or the default. This information gets returned
00227  * to the invoker of the query method.
00228  */
00229 class TAO_Policies
00230 {
00231 public:
00232 
00233 #define TAO_NUM_POLICIES  11
00234 
00235   /**
00236         * This enum represents the relative order that properties are
00237         * passed from one trader to another. Hence, as recommended by the
00238         * spec, the starting_trader policies will be the first element in
00239         * the polcy sequence if it's set for a query.
00240         */
00241   enum POLICY_TYPE
00242   {
00243     STARTING_TRADER,
00244     EXACT_TYPE_MATCH,
00245     HOP_COUNT,
00246     LINK_FOLLOW_RULE,
00247     MATCH_CARD,
00248     RETURN_CARD,
00249     SEARCH_CARD,
00250     USE_DYNAMIC_PROPERTIES,
00251     USE_MODIFIABLE_PROPERTIES,
00252     USE_PROXY_OFFERS,
00253     REQUEST_ID
00254   };
00255 
00256   static const char * POLICY_NAMES[];
00257 
00258   TAO_Policies (TAO_Trader_Base& trader,
00259                 const CosTrading::PolicySeq& policies
00260                 ACE_ENV_ARG_DECL)
00261     ACE_THROW_SPEC ((CosTrading::Lookup::IllegalPolicyName,
00262                      CosTrading::DuplicatePolicyName));
00263 
00264   // BEGIN SPEC
00265   // The "policies" parameter allows the importer to specify how the
00266   // search should be performed as opposed to what sort of services
00267   // should be found in the course of the search. This can be viewed
00268   // as parameterizing the algorithms within the trader
00269   // implementation. The "policies" are a sequence of name-value
00270   // pairs. The names available to an importer depend on the
00271   // implementation of the trader. However, some names are
00272   // standardized where they effect the interpretation of other
00273   // parameters or where they may impact linking and federation of
00274   // traders. ° If a policy name in this parameter does not obey the
00275   // syntactic rules for legal PolicyName's, then an IllegalPolicyName
00276   // exception is raised. ° If the type of the value associated with a
00277   // policy differs from that specified in this specification, then a
00278   // PolicyTypeMismatch exception is raised. ° If subsequent
00279   // processing of a PolicyValue yields any errors (e.g., the
00280   // starting_trader policy value is malformed), then an
00281   // InvalidPolicyValue exception is raised. ° If the same policy name
00282   // is included two or more times in this parameter, then the
00283   // DuplicatePolicyName exception is raised.
00284   // END SPEC
00285 
00286   ~TAO_Policies (void);
00287 
00288   CORBA::ULong search_card (ACE_ENV_SINGLE_ARG_DECL) const
00289     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00290 
00291   // BEGIN SPEC
00292   // The "search_card" policy indicates to the trader the maximum
00293   // number of offers it should consider when looking for type
00294   // conformance and constraint expression match. The lesser of this
00295   // value and the trader's max_search_card attribute is used by the
00296   // trader. If this policy is not specified, then the value of the
00297   // trader's def_search_card attribute is used.
00298   // END SPEC
00299 
00300   CORBA::ULong match_card (ACE_ENV_SINGLE_ARG_DECL) const
00301     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00302 
00303   // BEGIN SPEC
00304   // The "match_card" policy indicates to the trader the maximum
00305   // number of matching offers to which the preference specification
00306   // should be applied. The lesser of this value and the trader's
00307   // max_match_card attribute is used by the trader. If this policy is
00308   // not specified, then the value of the trader's def_match_card
00309   // attribute is used.
00310   // END SPEC
00311 
00312   CORBA::ULong return_card (ACE_ENV_SINGLE_ARG_DECL) const
00313     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00314 
00315   // BEGIN SPEC
00316   // The "return_card" policy indicates to the trader the maximum
00317   // number of matching offers to return as a result of this
00318   // query. The lesser of this value and the trader's max_return_card
00319   // attribute is used by the trader. If this policy is not specified,
00320   // then the value of the trader's def_return_card attribute is
00321   // used.
00322   // END SPEC
00323 
00324   // = Offer consideration policies
00325 
00326   CORBA::Boolean use_modifiable_properties (ACE_ENV_SINGLE_ARG_DECL) const
00327     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00328 
00329   // BEGIN SPEC
00330   // The "use_modifiable_properties" policy indicates whether the
00331   // trader should consider offers which have modifiable properties
00332   // when constructing the set of offers to which type conformance and
00333   // constraint processing should be applied. If the value of this
00334   // policy is TRUE, then such offers will be included; if FALSE, they
00335   // will not. If this policy is not specified, such offers will be
00336   // included.
00337   // END SPEC
00338 
00339   CORBA::Boolean use_dynamic_properties (ACE_ENV_SINGLE_ARG_DECL) const
00340     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00341 
00342   // BEGIN SPEC
00343   // The "use_dynamic_properties" policy indicates whether the trader
00344   // should consider offers which have dynamic properties when
00345   // constructing the set of offers to which type conformance and
00346   // constraint processing should be applied. If the value of this
00347   // policy is TRUE, then such offers will be included; if FALSE, they
00348   // will not. If this policy is not specified, such offers will be
00349   // included.
00350   // END SPEC
00351 
00352   CORBA::Boolean use_proxy_offers (ACE_ENV_SINGLE_ARG_DECL) const
00353     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00354 
00355   // BEGIN SPEC
00356   // The "use_proxy_offers" policy indicates whether the trader should
00357   // consider proxy offers when constructing the set of offers to
00358   // which type conformance and constraint processing should be
00359   // applied. If the value of this policy is TRUE, then such offers
00360   // will be included; if FALSE, they will not. If this policy is not
00361   // specified, such offers will be included.
00362   // END SPEC
00363 
00364   CORBA::Boolean exact_type_match (ACE_ENV_SINGLE_ARG_DECL) const
00365     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00366 
00367   // BEGIN SPEC
00368   // The "exact_type_match" policy indicates to the trader whether the
00369   // importer's service type must exactly match an offer's service
00370   // type; if not (and by default), then any offer of a type
00371   // conformant to the importer's service type is considered.
00372   // END SPEC
00373 
00374   // = Federated trader policies (not implemented yet)
00375 
00376   /**
00377    * BEGIN SPEC
00378    * The "starting_trader" policy facilitates the distribution of the
00379    * trading service itself. It allows an importer to scope a search
00380    * by choosing to explicitly navigate the links of the trading
00381    * graph. If the policy is used in a query invocation it is
00382    * recommended that it be the first policy-value pair; this
00383    * facilitates an optimal forwarding of the query operation. A
00384    * "policies" parameter need not include a value for the
00385    * "starting_trader" policy. Where this policy is present, the first
00386    * name component is compared against the name held in each link. If
00387    * no match is found, the InvalidPolicyValue exception is
00388    * raised. Otherwise, the trader invokes query() on the Lookup
00389    * interface held by the named link, but passing the
00390    * "starting_trader" policy with the first component removed.
00391    * END SPEC
00392    */
00393   CosTrading::TraderName* starting_trader (ACE_ENV_SINGLE_ARG_DECL) const
00394     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch,
00395                      CosTrading::Lookup::InvalidPolicyValue));
00396 
00397   /// Determine the link follow policy for this query overall.
00398   CosTrading::FollowOption link_follow_rule (ACE_ENV_SINGLE_ARG_DECL) const
00399     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00400 
00401   // BEGIN SPEC
00402   //The "link_follow_rule" policy indicates how the client wishes
00403   //links to be followed in the resolution of its query. See the
00404   //discussion in "Link Follow Behavior" on page 16-16 for details.
00405   // END SPEC
00406 
00407 
00408   /**
00409    * Determine the link follow policy for a given <link_name>.
00410    * This method returns the link_follow_rule for a link whose name is
00411    * <link_name> using the following formula:
00412    * if the importer specified a link_follow_rule policy
00413    *      min(trader.max_follow_policy, link.limiting_follow_rule,
00414    *          query.link_follow_rule)
00415    * else min(trader.max_follow_policy, link.limiting_follow_rule,
00416    *          trader.def_follow_policy)
00417    */
00418   CosTrading::FollowOption link_follow_rule (const CosTrading::Link::LinkInfo& link_info
00419                                              ACE_ENV_ARG_DECL) const
00420     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch,
00421                      CosTrading::Lookup::InvalidPolicyValue,
00422                      CosTrading::Link::IllegalLinkName,
00423                      CosTrading::Link::UnknownLinkName));
00424 
00425   CORBA::ULong hop_count (ACE_ENV_SINGLE_ARG_DECL) const
00426     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00427 
00428   // BEGIN SPEC
00429   // The "hop_count" policy indicates to the trader the maximum number
00430   // of hops across federation links that should be tolerated in the
00431   // resolution of this query. The hop_count at the current trader is
00432   // determined by taking the minimum of the trader's max_hop_count
00433   // attribute and the importer's hop_count policy, if provided, or
00434   // the trader's def_hop_count attribute if it is not. If the
00435   // resulting value is zero, then no federated queries are
00436   // permitted. If it is greater than zero, then it must be
00437   // decremented before passing on to a federated trader.
00438   // END SPEC
00439 
00440   /// Return the request_id passed to the query method across a link to
00441   /// another trader.
00442   CosTrading::Admin::OctetSeq* request_id (ACE_ENV_SINGLE_ARG_DECL) const
00443     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00444 
00445   /// Policies to forward to the next trader in a federated query.
00446   void copy_to_pass (CosTrading::PolicySeq& policy_seq,
00447                      const CosTrading::Admin::OctetSeq& request_id
00448                      ACE_ENV_ARG_DECL) const;
00449 
00450   /// Policies to forward to the next trader in a directed query.
00451   void copy_to_forward (CosTrading::PolicySeq& policy_seq,
00452                         const CosTrading::TraderName& name) const;
00453 
00454   /**
00455    * Determine the link follow policy to pass down the link with <link_name>.
00456    * This method returns the link_follow_rule for a link whose name is
00457    * <link_name> using the following formula:
00458    * If the importer specified a link_follow_rule, policy
00459    *      pass on min(query.link_follow_rule, link.limiting_follow_rule,
00460    *                  trader.max_follow_policy)
00461    * else pass on min(link.def_pass_on_follow_rule,
00462    *                  trader.max_follow_policy)
00463    */
00464   void copy_in_follow_option (CosTrading::PolicySeq& policy_seq,
00465                               const CosTrading::Link::LinkInfo& link_info
00466                               ACE_ENV_ARG_DECL) const
00467     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch,
00468                      CosTrading::Lookup::InvalidPolicyValue));
00469 
00470 private:
00471 
00472   /// Reconclile a ULong property with its default.
00473   CORBA::ULong ulong_prop (POLICY_TYPE pol
00474                            ACE_ENV_ARG_DECL) const
00475     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00476 
00477   /// Reconcile a Boolean property with its debault.
00478   CORBA::Boolean boolean_prop (POLICY_TYPE pol
00479                                ACE_ENV_ARG_DECL) const
00480     ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch));
00481 
00482   TAO_Policies (const TAO_Policies&);
00483   TAO_Policies& operator= (const TAO_Policies&);
00484 
00485   /// The policies indexable from the enumerated type.
00486   CosTrading::Policy* policies_[TAO_NUM_POLICIES];
00487 
00488   /// For the validating identifier names.
00489   TAO_Trader_Base& trader_;
00490 };
00491 
00492 /**
00493  * @class TAO_Policy_Creator
00494  *
00495  * @brief This class is a utility for clients using the CosTrading::Lookup
00496  * interface that helps them build a policy sequence without violating
00497  * syntax rules and having to mess with typecodes.
00498  */
00499 class TAO_Trading_Serv_Export TAO_Policy_Creator
00500 {
00501 public:
00502 
00503   TAO_Policy_Creator (int num_policies = 0);
00504 
00505   // = Routines to set policies.
00506 
00507   /// Set the maximum number of offers searched for the query.
00508   void search_card (CORBA::ULong scard);
00509 
00510   /// Set the maximum number of offers searched for the query.
00511   void match_card (CORBA::ULong mcard);
00512 
00513   /// Set the maximum number of offers rerturned for the query.
00514   void return_card (CORBA::ULong rcard);
00515 
00516   // A note about cardinalities: The spec implies that these
00517   // cardinalities apply to the global office space, that is, all
00518   // offers on all linked traders. However, there's no mechanism for
00519   // one trader to return to the calling trader the number of offers
00520   // searched or matched. Thus, these cardinalities are applied on a
00521   // per-trader basis.
00522 
00523   /// Consider offers with modifiable properties.
00524   void use_modifiable_properties (CORBA::Boolean mod_props);
00525 
00526   /// Consider offers with dynamic properties.
00527   void use_dynamic_properties (CORBA::Boolean dyn_props);
00528 
00529   /// Consider proxy offers (NOT SUPPORTED).
00530   void use_proxy_offers (CORBA::Boolean prox_offs);
00531 
00532   /// Designate a trader at which to begin the query.
00533   void starting_trader (const CosTrading::TraderName& name); // Copy
00534   void starting_trader (CosTrading::TraderName* name); // Own
00535 
00536   /// Specify under what conditions a federated query is appropriate.
00537   void link_follow_rule (CosTrading::FollowOption follow_option);
00538 
00539   /// Limit the breadth of a federated query.
00540   void hop_count (CORBA::ULong hop_count);
00541 
00542   /// Set the identifier for this query (clients shouldn't use this).
00543   void request_id (const CosTrading::Admin::OctetSeq& request_id);
00544 
00545   /// Search only the designated type --- not it's subtypes.
00546   void exact_type_match (CORBA::Boolean exact_type);
00547 
00548   /// Return the constructed policy sequence.
00549   operator const CosTrading::PolicySeq& (void) const;
00550 
00551   /// Return a PolicySeq suitable for passing to the query method of
00552   /// the Lookup interface.
00553   const CosTrading::PolicySeq& policy_seq (void) const;
00554 
00555 private:
00556 
00557   TAO_Policy_Creator (const TAO_Policy_Creator&);
00558   TAO_Policy_Creator& operator= (const TAO_Policy_Creator&);
00559 
00560   /// Method to prepare the next slot in the policies_ sequence for
00561   /// policy insertion.
00562   CosTrading::Policy& fetch_next_policy (TAO_Policies::POLICY_TYPE pol_type);
00563 
00564   /// Table mapping policy enum value to the index in the policies sequence.
00565   int poltable_[TAO_Policies::REQUEST_ID + 1];
00566 
00567   /// The sequence being prepared for submittal to the query method.
00568   CosTrading::PolicySeq policies_;
00569 
00570   /// The number of policies so far in the sequence.
00571   CORBA::ULong num_policies_;
00572 };
00573 
00574 /**
00575  * @class TAO_Offer_Modifier
00576  *
00577  * @brief This class deletes, modifies, and adds properties to a given
00578  * offer according to the rules of the modify method on the Register
00579  * interface.
00580  */
00581 class TAO_Offer_Modifier
00582 {
00583 public:
00584 
00585   /// Modify an <offer> of type <type>, whose properties are described
00586   /// by <type_struct>
00587   TAO_Offer_Modifier (const char* type,
00588                       const CosTradingRepos::ServiceTypeRepository::TypeStruct& type_struct,
00589                       CosTrading::Offer* offer);
00590 
00591   ~TAO_Offer_Modifier (void);
00592 
00593   /// Delete the properties whose names were given to the
00594   /// constructor. Ensure we don't delete mandatory properties.
00595   void delete_properties (const CosTrading::PropertyNameSeq& deletes
00596                           ACE_ENV_ARG_DECL)
00597     ACE_THROW_SPEC ((CosTrading::Register::UnknownPropertyName,
00598                      CosTrading::Register::MandatoryProperty,
00599                      CosTrading::IllegalPropertyName,
00600                      CosTrading::DuplicatePropertyName));
00601 
00602   /**
00603    * Copy to the destination the union of the source and destination
00604    * properties. In the case of duplicate properties, update the
00605    * destination with the source's value. This class claims the memory
00606    * in the modifies sequence.
00607    */
00608   void merge_properties (const CosTrading::PropertySeq& modifies
00609                          ACE_ENV_ARG_DECL)
00610     ACE_THROW_SPEC ((CosTrading::IllegalPropertyName,
00611                      CosTrading::DuplicatePropertyName,
00612                      CosTrading::PropertyTypeMismatch,
00613                      CosTrading::ReadonlyDynamicProperty,
00614                      CosTrading::Register::ReadonlyProperty));
00615 
00616   /// Return a reference to the Offer with the changes affected.
00617   void affect_change (const CosTrading::PropertySeq& modifies);
00618 
00619 private:
00620 
00621   TAO_Offer_Modifier (const TAO_Offer_Modifier&);
00622   TAO_Offer_Modifier& operator= (const TAO_Offer_Modifier&);
00623 
00624   typedef ACE_Hash_Map_Manager_Ex <CORBA::String_var,
00625                                    CosTrading::Property *,
00626                                    ACE_Hash<CORBA::String_var>,
00627                                    ACE_Equal_To<CORBA::String_var>,
00628                                    ACE_Null_Mutex>
00629           Property_Table;
00630 
00631   /// The type of the offer.
00632   const char *type_;
00633 
00634   /// The map of properties in the offer.
00635   Property_Table props_;
00636 
00637   /// Table of property types.
00638   TAO_Typecode_Table prop_types_;
00639 
00640   /// The set of readonly and mandatory property names in the offer's
00641   /// type.
00642   TAO_String_Set readonly_;
00643   TAO_String_Set mandatory_;
00644 
00645   /// A reference to the offer undergoing change.
00646   CosTrading::Offer* offer_;
00647 };
00648 
00649 /**
00650  * @class TAO_Offer_Filter
00651  *
00652  * @brief The purpose of this class is to ensure that offers that
00653  * shouldn't be considered by the TAO_Constraint_Interpreter
00654  * aren't.
00655  *
00656  * There two classes of reasons why an offer for a correct
00657  * type shouldn't be considered: 1) The default parameters of the
00658  * Trader or policies passed to the Lookup::query method deem it
00659  * inappropriate to consider offers with modifiable (i.e., not
00660  * readonly) or dynamic properties. 2) We've exceeded the
00661  * default or provided cardinality constraints. TAO_Offer_Filter
00662  * ensures that violation of policies doesn't occur. It's the
00663  * enforcer.
00664  */
00665 class TAO_Offer_Filter
00666 {
00667 public:
00668 
00669   /// Glean from the TypeStruct and Policy setting the appropriate way
00670   /// to screen unsuitable offers from consideration.
00671   TAO_Offer_Filter (TAO_Policies& policies
00672                     ACE_ENV_ARG_DECL);
00673 
00674   /// Set the offer filter to screen for offers containing properties
00675   /// that aren't marked as readonly in this TypeStruct.
00676   void configure_type (CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct);
00677 
00678   /**
00679    * Determine whether the poicies contained in the given policy
00680    * object allow the Lookup interface to consider the offer. That is,
00681    * if use_modifiable_properties is false, and the offer contains
00682    * modifiable properties as designated in the type struct, return
00683    * false. If use_dynamic_properties is false, and the offer contains
00684    * dynamic properties, then return false. If the lookup interface is
00685    * safe in considering this offer, return true and subtract from the
00686    * search card value. When the search card value falls to zero,
00687    * ok_to_consider always returns false.
00688    */
00689   CORBA::Boolean ok_to_consider (CosTrading::Offer* offer);
00690 
00691   /// It's ok to consider more offers when lookup hasn't exceeded the
00692   /// cardinality values for searching and matching offers.
00693   CORBA::Boolean ok_to_consider_more (void);
00694 
00695   /// Signal that the Lookup method has matched an offer; decrement the
00696   /// match_card.
00697   void matched_offer (void);
00698 
00699   // = Return the limits applied.
00700   /**
00701    * BEGIN SPEC
00702    * If any cardinality or other limits were applied by one or more
00703    * traders in responding to a particular query, then the
00704    * "limits_applied" parameter will contain the names of the policies
00705    * which limited the query. The sequence of names returned in
00706    * "limits_applied" from any federated or proxy queries must be
00707    * concatenated onto the names of limits applied locally and
00708    * returned.
00709    * END SPEC
00710    */
00711   CosTrading::PolicyNameSeq* limits_applied (void);
00712 
00713   /// Accessors to retrieve the adjusted cardinalities.
00714   CORBA::ULong search_card_remaining (void) const;
00715   CORBA::ULong match_card_remaining (void) const;
00716 
00717 private:
00718 
00719   TAO_Offer_Filter (const TAO_Offer_Filter&);
00720   TAO_Offer_Filter& operator= (const TAO_Offer_Filter&);
00721 
00722   /// The set of the name of modifiable properties.
00723   TAO_String_Set not_mod_props_;
00724 
00725   /// Cardinality and property limitations applied.
00726   TAO_String_Set limits_;
00727 
00728   /// Keep track of the cardinalities.
00729   CORBA::ULong search_card_, match_card_, return_card_;
00730 
00731   /// Keep track of property limitations: modifiable or dynamic ones
00732   /// may be bad.
00733   CORBA::Boolean dp_;
00734   CORBA::Boolean mod_;
00735 };
00736 
00737 /**
00738  * @class TAO_Property_Filter
00739  *
00740  * @brief The Ace_Property_Filter copies those properties specified in a
00741  * CosTrading::Lookup::SpecifiedProps from a source
00742  * CosTrading::Offer to a destination CosTrading::Offer.
00743  */
00744 class TAO_Property_Filter
00745 {
00746 public:
00747 
00748   typedef CosTrading::Lookup::SpecifiedProps SPECIFIED_PROPS;
00749 
00750   /// An accomplice to g++'s insane lust for copy constructors.
00751   TAO_Property_Filter (void) : policy_ (CosTrading::Lookup::all) {}
00752 
00753   /// Verify that the specified properties are correct.
00754   TAO_Property_Filter (const SPECIFIED_PROPS& desired_props
00755                        ACE_ENV_ARG_DECL)
00756     ACE_THROW_SPEC ((CosTrading::IllegalPropertyName,
00757                      CosTrading::DuplicatePropertyName));
00758 
00759   TAO_Property_Filter (const TAO_Property_Filter& prop_filter);
00760   TAO_Property_Filter& operator= (const TAO_Property_Filter& prop_filter);
00761 
00762   /// Copy the desired properties from the source offer to the
00763   /// destination offer.
00764   void filter_offer (CosTrading::Offer* source,
00765                      CosTrading::Offer& destination);
00766 
00767 private:
00768 
00769   typedef ACE_Unbounded_Queue< CosTrading::Property* > Prop_Queue;
00770 
00771   TAO_String_Set props_;
00772   CosTrading::Lookup::HowManyProps policy_;
00773 };
00774 
00775 TAO_END_VERSIONED_NAMESPACE_DECL
00776 
00777 #if defined(_MSC_VER)
00778 #pragma warning(pop)
00779 #endif /* _MSC_VER */
00780 
00781 #include /**/ "ace/post.h"
00782 
00783 #endif /* TAO_TRADER_UTILS_H */

Generated on Thu Nov 9 13:59:59 2006 for TAO_CosTrader by doxygen 1.3.6