diff options
author | sbw1 <sbw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-06-23 01:29:30 +0000 |
---|---|---|
committer | sbw1 <sbw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-06-23 01:29:30 +0000 |
commit | b0fe6b842134b5b7c7e1b9d924182fc18e0cfa13 (patch) | |
tree | a9c8b79da456071e722ac1f9cb2dee4f7ff54a55 | |
parent | 19f4420651377b3733882c382163659e07638396 (diff) | |
download | ATCD-b0fe6b842134b5b7c7e1b9d924182fc18e0cfa13.tar.gz |
Compressed the Trading Service into a fewer number of files by having
related classes share a file.
64 files changed, 6639 insertions, 7100 deletions
diff --git a/TAO/orbsvcs/orbsvcs/Trader/Admin.cpp b/TAO/orbsvcs/orbsvcs/Trader/Admin.cpp deleted file mode 100644 index c8e5b409263..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Admin.cpp +++ /dev/null @@ -1,328 +0,0 @@ -/* -*- C++ -*- */ - -// ============================================================================ -// $Id$ -// -// = LIBRARY -// Admin -// -// = FILENAME -// Admin.cpp -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ============================================================================ - -#if !defined (TAO_ADMIN_C) -#define TAO_ADMIN_C - -#include "Admin.h" - -template <class TRADER> -const char* TAO_Admin<TRADER>::NAME = "Trader: Admin"; - -template <class TRADER> -TAO_Admin<TRADER>::TAO_Admin (TRADER &trader) - : trader_ (trader), - TAO_Trader_Components <POA_CosTrading::Admin> (trader.trading_components ()), - TAO_Import_Attributes <POA_CosTrading::Admin> (trader.import_attributes ()), - TAO_Support_Attributes <POA_CosTrading::Admin> (trader.support_attributes ()), - TAO_Link_Attributes <POA_CosTrading::Admin> (trader.link_attributes ()), - sequence_number_ (0) -{ - // Because a servant is uniquely identified by a POA name and an - // ObjectID number, the concatenation of the two prefixed before a - // sequence number will ensure the request_id_stem space between - // traders will not overlap. The sequence number space will be four - // octets. - CORBA::Environment _env; - PortableServer::POA_var poa = this->_default_POA (_env); - PortableServer::ObjectId_var id = poa->servant_to_id (this, _env); - CORBA::String_var poa_name = poa->the_name (_env); - int name_length = ACE_OS::strlen (poa_name.in ()), - id_length = id->length (), - total_length = name_length + id_length + sizeof (CORBA::ULong); - - this->stem_id_.length (total_length); - // @@ Commented it out until a fix is found - - for (int i = total_length - 1, j = name_length - 1; j >= 0; i--, j--) - //this->stem_id_[i] = (CORBA::Octet) poa_name[j]; - ; - - - for (j = id_length - 1; j >= 0; j--, i--) - this->stem_id_[i] = id[j]; -} - -template <class TRADER> -TAO_Admin<TRADER>::~TAO_Admin (void) -{ -} - -template <class TRADER> CosTrading::Admin::OctetSeq * -TAO_Admin<TRADER>::request_id_stem (CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - // Add one to the sequence_number and concatenate it to the unique - // prefix. The sequence number is four octets long. - for (int i = sizeof (CORBA::ULong) - 1; i >= 0; i--) - this->stem_id_[i] = (this->sequence_number_ >> (8*i)) & 0xff; - - // Increment the sequence number and return a copy of the stem_id. - this->sequence_number_++; - return new CosTrading::Admin::OctetSeq (this->stem_id_); -} - -template <class TRADER> CORBA::ULong -TAO_Admin<TRADER>::set_def_search_card (CORBA::ULong value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::ULong return_value = - this->trader_.import_attributes ().def_search_card (); - - this->trader_.import_attributes ().def_search_card (value); - return return_value; -} - -template <class TRADER> CORBA::ULong -TAO_Admin<TRADER>::set_max_search_card (CORBA::ULong value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::ULong return_value = - this->trader_.import_attributes ().max_search_card (); - - this->trader_.import_attributes ().max_search_card (value); - return return_value; -} - -template <class TRADER> CORBA::ULong -TAO_Admin<TRADER>::set_def_match_card (CORBA::ULong value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::ULong return_value = - this->trader_.import_attributes ().def_match_card (); - - this->trader_.import_attributes ().def_match_card (value); - return return_value; -} - -template <class TRADER> CORBA::ULong -TAO_Admin<TRADER>::set_max_match_card (CORBA::ULong value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::ULong return_value = - this->trader_.import_attributes ().max_match_card (); - - this->trader_.import_attributes ().max_match_card (value); - return return_value; -} - -template <class TRADER> CORBA::ULong -TAO_Admin<TRADER>::set_def_return_card (CORBA::ULong value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::ULong return_value = - this->trader_.import_attributes ().def_return_card (); - - this->trader_.import_attributes ().def_return_card (value); - return return_value; -} - -template <class TRADER> CORBA::ULong -TAO_Admin<TRADER>::set_max_return_card (CORBA::ULong value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::ULong return_value = - this->trader_.import_attributes ().max_return_card (); - - this->trader_.import_attributes ().max_return_card (value); - return return_value; -} - -template <class TRADER> CORBA::ULong -TAO_Admin<TRADER>::set_max_list (CORBA::ULong value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::ULong return_value = - this->trader_.import_attributes ().max_list (); - - this->trader_.import_attributes ().max_list (value); - return return_value; -} - -template <class TRADER> CORBA::Boolean -TAO_Admin<TRADER>:: -set_supports_modifiable_properties (CORBA::Boolean value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::Boolean return_value = - this->trader_.support_attributes ().supports_modifiable_properties (); - - this->trader_.support_attributes ().supports_modifiable_properties (value); - return return_value; -} - -template <class TRADER> CORBA::Boolean -TAO_Admin<TRADER>:: -set_supports_dynamic_properties (CORBA::Boolean value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::Boolean return_value = - this->trader_.support_attributes ().supports_dynamic_properties (); - - this->trader_.support_attributes ().supports_dynamic_properties (value); - return return_value; -} - -template <class TRADER> CORBA::Boolean -TAO_Admin<TRADER>::set_supports_proxy_offers (CORBA::Boolean value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::Boolean return_value = - this->trader_.support_attributes ().supports_proxy_offers (); - - this->trader_.support_attributes ().supports_proxy_offers (value); - return return_value; -} - -template <class TRADER> CORBA::ULong -TAO_Admin<TRADER>::set_def_hop_count (CORBA::ULong value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::ULong return_value = - this->trader_.import_attributes ().def_hop_count (); - - this->trader_.import_attributes ().def_hop_count (value); - return return_value; -} - -template <class TRADER> CORBA::ULong -TAO_Admin<TRADER>::set_max_hop_count (CORBA::ULong value, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::ULong return_value = - this->trader_.import_attributes ().max_hop_count (); - - this->trader_.import_attributes ().max_hop_count (value); - return return_value; -} - -template <class TRADER> CosTrading::FollowOption -TAO_Admin<TRADER>::set_def_follow_policy (CosTrading::FollowOption policy, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CosTrading::FollowOption return_value = - this->trader_.import_attributes ().def_follow_policy (); - - this->trader_.import_attributes ().def_follow_policy (policy); - return return_value; -} - -template <class TRADER> CosTrading::FollowOption -TAO_Admin<TRADER>::set_max_follow_policy (CosTrading::FollowOption policy, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CosTrading::FollowOption return_value = - this->trader_.import_attributes ().max_follow_policy (); - - this->trader_.import_attributes ().max_follow_policy (policy); - return return_value; -} - -template <class TRADER> CosTrading::FollowOption -TAO_Admin<TRADER>:: -set_max_link_follow_policy (CosTrading::FollowOption policy, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CosTrading::FollowOption return_value = - this->trader_.link_attributes ().max_link_follow_policy (); - - this->trader_.link_attributes ().max_link_follow_policy (policy); - return return_value; -} - -template <class TRADER> CosTrading::TypeRepository_ptr -TAO_Admin<TRADER>:: -set_type_repos (CosTrading::TypeRepository_ptr repository, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CosTrading::TypeRepository_ptr return_value = - this->trader_.support_attributes ().type_repos (); - - this->trader_.support_attributes ().type_repos (repository); - return return_value; -} - -template <class TRADER> CosTrading::Admin::OctetSeq* -TAO_Admin<TRADER>::set_request_id_stem (const CosTrading::Admin::OctetSeq& stem, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - return 0; -} - -template <class TRADER> void -TAO_Admin<TRADER>::list_offers (CORBA::ULong how_many, - CosTrading::OfferIdSeq_out ids, - CosTrading::OfferIdIterator_out id_itr, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException,) - CosTrading::NotImplemented) -{ - // This method only applies when the register interface is implemented - if (CORBA::is_nil(this->trader_.trading_components().register_if())) - TAO_THROW (CosTrading::NotImplemented()); - - TRADER::Service_Type_Map& type_map = this->trader_.service_type_map(); - - CosTrading::OfferIdIterator_ptr oi = - type_map.retrieve_all_offer_ids ()->_this (_env); - TAO_CHECK_ENV_RETURN_VOID (_env); - - id_itr = CosTrading::OfferIdIterator::_nil (); - if (how_many > 0) - { - if (oi->next_n (how_many, ids, _env) == CORBA::B_FALSE) - { - // No more items left in the iterator. - oi->destroy (_env); - oi = CosTrading::OfferIdIterator::_nil (); - } - else - id_itr = oi; - } - else - ids = new CosTrading::OfferIdSeq(0); -} - -template <class TRADER> void -TAO_Admin<TRADER>::list_proxies (CORBA::ULong how_many, - CosTrading::OfferIdSeq_out ids, - CosTrading::OfferIdIterator_out id_itr, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::NotImplemented)) -{ - TAO_THROW (CosTrading::NotImplemented ()); -} - -#endif /* TAO_ADMIN_C */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Admin.h b/TAO/orbsvcs/orbsvcs/Trader/Admin.h deleted file mode 100644 index 363bc428b8d..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Admin.h +++ /dev/null @@ -1,194 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Admin.h -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// Irfan Pyarali <irfan@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_ADMIN_H -#define TAO_ADMIN_H - -#include "Attributes_T.h" - -template <class TRADER> -class TAO_Admin : - public TAO_Trader_Components <POA_CosTrading::Admin>, - public TAO_Support_Attributes <POA_CosTrading::Admin>, - public TAO_Import_Attributes <POA_CosTrading::Admin>, - public TAO_Link_Attributes <POA_CosTrading::Admin> -// -// = TITLE -// This class implements CosTrading::Admin IDL interface. -// -// = DESCRIPTION (FROM SPEC) -// -// The admin interface enables the values of the trader attributes to -// be read and written. All attributes are defined as readonly in -// either SupportAttributes, ImportAttributes, LinkAttributes, or -// Admin. To set the trader "attribute" to a new value, -// set_<attribute_name> operations are defined in Admin. Each of these -// set operations returns the previous value of the attribute as its -// function value. If the admin interface operation -// set_support_proxy_offers is invoked with a value set to FALSE in a -// trader which supports the proxy interface, the -// set_support_proxy_offer value does not affect the function of -// operations in the proxy interface. However, in this case, it does -// have the effect of making any proxy offers exported via the proxy -// interface for that trader unavailable to satisfy queries on that -// trader's lookup interface. -{ -public: - - TAO_Admin (TRADER &trader); - - ~TAO_Admin (void); - - // = Importing Parameters (used by the Lookup Interface) - - virtual CORBA::ULong set_def_search_card (CORBA::ULong value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - virtual CORBA::ULong set_max_search_card (CORBA::ULong value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - // search card is the cardinality of the offers searched for - // constraint compliance. - - - virtual CORBA::ULong set_def_match_card (CORBA::ULong value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - virtual CORBA::ULong set_max_match_card (CORBA::ULong value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - // match card is the cardinality of offers found compliant with the - // constraints. - - virtual CORBA::ULong set_def_return_card (CORBA::ULong value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - virtual CORBA::ULong set_max_return_card (CORBA::ULong value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - // return card is the cardinality of the offers returned from - // Lookup. - - virtual CORBA::ULong set_max_list (CORBA::ULong value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - virtual CORBA::Boolean - set_supports_modifiable_properties (CORBA::Boolean value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - virtual CORBA::Boolean - set_supports_dynamic_properties (CORBA::Boolean value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - virtual CORBA::Boolean - set_supports_proxy_offers (CORBA::Boolean value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - // Types of offers available for consideration. Ween out those - // offers with modifiable properties - - // = Link Interface parameters - - virtual CORBA::ULong set_def_hop_count (CORBA::ULong value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - virtual CORBA::ULong set_max_hop_count (CORBA::ULong value, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - - virtual CosTrading::FollowOption - set_def_follow_policy (CosTrading::FollowOption policy, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - virtual CosTrading::FollowOption - set_max_follow_policy (CosTrading::FollowOption policy, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - virtual CosTrading::FollowOption - set_max_link_follow_policy (CosTrading::FollowOption policy, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - - // = Set Type Repository - - virtual CosTrading::TypeRepository_ptr - set_type_repos (CosTrading::TypeRepository_ptr repository, - CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException)); - - virtual CosTrading::Admin::OctetSeq* - request_id_stem (CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException)); - - virtual CosTrading::Admin::OctetSeq* - set_request_id_stem (const CosTrading::Admin::OctetSeq& stem, - CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException)); - - virtual void list_offers (CORBA::ULong how_many, - CosTrading::OfferIdSeq_out ids, - CosTrading::OfferIdIterator_out id_itr, - CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::NotImplemented)); - - - // BEGIN SPEC - // The list_offers operation allows the administrator of a trader to - // perform housekeeping by obtaining a handle on each of the offers - // within a trader (e.g., for garbage collection etc.). Only the - // identifiers of ordinary offers are returned, identifiers of proxy - // offers are not returned via this operation. If the trader does - // not support the Register interface, the NotImplemented exception - // is raised. The returned identifiers are passed back in one of two - // ways (or a combination of both). ° The "ids" return result - // conveys a list of offer identifiers and the "id_itr" is a - // reference to an interface at which additional offer identities - // can be obtained. ° The "how_many" parameter states how many - // identifiers are to be returned via the "ids" result; any - // remaining are available via the iterator interface. If the - // "how_many" exceeds the number of offers held in the trader, then - // the "id_itr" is nil. - // END SPEC - - virtual void list_proxies (CORBA::ULong how_many, - CosTrading::OfferIdSeq_out ids, - CosTrading::OfferIdIterator_out id_itr, - CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::NotImplemented)); - - - static const char* NAME; - -private: - - TRADER &trader_; - - CosTrading::Admin::OctetSeq stem_id_; - // Unique prefix to create a sequence number space. - - CORBA::ULong sequence_number_; - // Current sequence number. -}; - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Admin.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#endif /* TAO_ADMIN_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Attributes.h b/TAO/orbsvcs/orbsvcs/Trader/Attributes.h index 14d21466ffa..87368294eb4 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Attributes.h +++ b/TAO/orbsvcs/orbsvcs/Trader/Attributes.h @@ -21,6 +21,10 @@ #include "orbsvcs/CosTradingS.h" +#if defined(_MSC_VER) +#pragma warning (disable:4250) +#endif /* _MSC_VER */ + class TAO_Lockable // = DESCRIPTION // Class used to remove the circular dependencies between the diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint.cpp b/TAO/orbsvcs/orbsvcs/Trader/Constraint.cpp deleted file mode 100644 index bd384d9984e..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Constraint.cpp -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - - -#include "Constraint.h" - -char* TAO_Lex_String_Input::string_ = 0; -char* TAO_Lex_String_Input::current_ = 0; -char* TAO_Lex_String_Input::end_ = 0; - -// Routine to have Lex read its input from the constraint string. - -int -TAO_Lex_String_Input::copy_into(char* buf, int max_size) -{ - int chars_left = TAO_Lex_String_Input::end_ - TAO_Lex_String_Input::current_; - int n = (max_size > chars_left) ? chars_left : max_size; - - - if (n > 0) - { - memcpy(buf, TAO_Lex_String_Input::current_, n); - TAO_Lex_String_Input::current_ += n; - } - - return n; -} - -void -TAO_Lex_String_Input::reset(char* input_string) -{ - TAO_Lex_String_Input::string_ = input_string; - TAO_Lex_String_Input::current_ = input_string; - TAO_Lex_String_Input::end_ = input_string + - ACE_OS::strlen(TAO_Lex_String_Input::string_); -} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint.h b/TAO/orbsvcs/orbsvcs/Trader/Constraint.h deleted file mode 100644 index ec0008d195b..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Constraint.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_CONSTRAINT_H -#define TAO_CONSTRAINT_H - -#include "Constraint_Nodes.h" - -// Functions we need for parsing. -extern int yyparse(void); -extern void yyrestart(FILE*); -extern int yylex(void); - -// Have yylex read from the constraint string, not from stdin. -#undef YY_INPUT -#define YY_INPUT(b, r, ms) (r = TAO_Lex_String_Input::copy_into(b, ms)) - -#undef yyerror -#define yyerror(x) - -class TAO_Lex_String_Input -// = TITLE -// Stupid hack to have Lex read from a string and not from -// stdin. Essentially, the interpreter needs to call yylex() until -// EOF, and call TAO_Lex_String_Input::reset() with the new string, -// prior to calling yyparse. -{ -public: - - static void reset(char* input_string); - // Reset the lex input. - - static int copy_into(char* buf, int max_size); - // Method lex will call to read from the input string. - -private: - - static char* string_; - static char* current_; - static char* end_; - // Pointers to keep track of the input string. -}; - -// The union used by lex and yacc to build the Abstract Syntax Tree. -typedef union -{ - TAO_Constraint* constraint_; -} YYSTYPE; - -extern YYSTYPE yylval; -extern YYSTYPE yyval; - -#endif /* CONSTRAINT_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.h b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.h deleted file mode 100644 index e0eb3062bb2..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.h +++ /dev/null @@ -1,171 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ======================================================================== -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Constraint_Evaluator.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_CONSTRAINT_EVALUATOR_H -#define TAO_CONSTRAINT_EVALUATOR_H - -#include "Property_Evaluator.h" -#include "Constraint_Visitor.h" -#include "Constraint_Nodes.h" - -class TAO_Constraint_Evaluator : public TAO_Constraint_Visitor -// -// = TITLE -// TAO_Constraint_Evaluator traverse a constraint expression tree, -// and determines whether an offer fits the constraints -// represented by the tree -// -// = DESCRIPTION -// Using the Visitor pattern, the TAO_Constraint_Evaluator has each -// node of the expression tree call back to it with the method -// designated for its type. In that method, the visitor will -// evaluate its operands and perform the operation designated by -// that node's type, and return the result. Note: the -// EvaluationVisitor assumes the tree is semantically correct, -// that is, the validate method on SemanticValidatorVisitor return -// true. The only possible evaluation time error is a divide by a -// property whose value is zero. -{ -public: - - TAO_Constraint_Evaluator(CosTrading::Offer* offer, - CORBA::Boolean supports_dynamic_properties = 1); - - CORBA::Boolean evaluate_constraint(TAO_Constraint* root); - // Evaluate returns 1 if the offer satisfies the constraints - // represented by the the expression tree rooted at <root>, 0 if it - // doesn't. If an error occurs during process, the constraint - // automatically fails. - - int evaluate_preference(TAO_Constraint* root, - TAO_Literal_Constraint& result); - // The result of the preference evaluation is stored in result. The - // method returns 0 upon success, -1 upon failure. - - // = Visitor Methods - - virtual int visit_constraint(TAO_Unary_Constraint* constraint); - - virtual int visit_with(TAO_Unary_Constraint* unary_with); - virtual int visit_min(TAO_Unary_Constraint* unary_min); - virtual int visit_max(TAO_Unary_Constraint* unary_max); - virtual int visit_first(TAO_Noop_Constraint* noop_first); - virtual int visit_random(TAO_Noop_Constraint* noop_random); - - virtual int visit_and(TAO_Binary_Constraint* boolean_and); - // Takes the logical and of the results of both operands. Note that - // in the case where the left operand returns zero, the result is - // immediately known. - - virtual int visit_or(TAO_Binary_Constraint* boolean_or); - // Takes the logical or of the results of both operands. Note that - // in the case where the left operand returns one, the result is - // immediately known. - - virtual int visit_not(TAO_Unary_Constraint* unary_not); - // Logically negates the value of the operand. - - virtual int visit_exist(TAO_Unary_Constraint* unary_exist); - // The property exists if its name is bound to a value in the - // <props_> map. - - virtual int visit_unary_minus(TAO_Unary_Constraint* unary_minus); - // Mathematically negates the return value the operand. - - virtual int visit_add(TAO_Binary_Constraint* boolean_add); - // Add the results of evaluating the left and right operands. - - virtual int visit_sub(TAO_Binary_Constraint* boolean_sub); - // Subtract the results of evaluating the left and right operands. - - virtual int visit_mult(TAO_Binary_Constraint* boolean_mult); - // Multiply the results of evaluating the left and right operands. - - virtual int visit_div(TAO_Binary_Constraint* boolean_div); - // Divide the results of evaluating the left and right operands. - - virtual int visit_twiddle(TAO_Binary_Constraint* binary_twiddle); - // Determines if the right operand is a substring of the left. - - virtual int visit_in(TAO_Binary_Constraint* binary_in); - // Determines if the sequence represented by the right operand - // contains the left operand. - - // = Compare the results of evaluating left and right operands. - virtual int visit_less_than(TAO_Binary_Constraint* boolean_lt); - virtual int visit_less_than_equal(TAO_Binary_Constraint* boolean_lte); - virtual int visit_greater_than(TAO_Binary_Constraint* boolean_gt); - virtual int visit_greater_than_equal(TAO_Binary_Constraint* boolean_gte); - virtual int visit_equal(TAO_Binary_Constraint* boolean_eq); - virtual int visit_not_equal(TAO_Binary_Constraint* boolean_neq); - - virtual int visit_literal(TAO_Literal_Constraint* literal); - // Copy the value of the literal into the result container. - - virtual int visit_property(TAO_Property_Constraint* literal); - // Copy the value of the property into the result container. - -private: - - class Operand_Queue : - public ACE_Unbounded_Queue <TAO_Literal_Constraint> - { - public: - - Operand_Queue (void); - - TAO_Literal_Constraint& get_left_operand (void); - - TAO_Literal_Constraint& get_right_operand (void); - - TAO_Literal_Constraint& get_operand (void); - - void dequeue_operand (void); - }; - - typedef ACE_Hash_Map_Manager - < - TAO_String_Hash_Key, - int, - ACE_Null_Mutex - > - Property_Map; - - void do_the_op (int operation); - int visit_bin_op (TAO_Binary_Constraint* op, int operation); - - CORBA::Boolean sequence_does_contain(CORBA::Any* sequence, - TAO_Literal_Constraint& element); - // Determine if sequence contains <element>, a literal of the same - // simple type as <sequence_type>. Return 1 in this eventuality. - - TAO_Literal_Constraint& left_operand(void); - TAO_Literal_Constraint& right_operand(void); - - Property_Map props_; - // The map of property names to their values for a property. - - TAO_Property_Evaluator prop_eval_; - // Utility with which to evaluate the properties of an offer, be - // they dyanmic or static. - - Operand_Queue queue_; - // The result of a non_boolean operation. -}; - -CORBA::Boolean TAO_find_string (TAO_Sequences::StringSeq& sequence, const char* element); - -#endif /* CONSTRAINT_EVALUATOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Interpreter.cpp b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Interpreter.cpp index 4077030341f..0e953941a94 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Interpreter.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Interpreter.cpp @@ -14,10 +14,66 @@ // // ======================================================================== - +#include "ace/OS.h" #include "Constraint_Interpreter.h" -#include <ctype.h> -#include <stdio.h> + + // ************************************************************* + // TAO_Interpreter + // ************************************************************* + +TAO_Interpreter::~TAO_Interpreter (void) +{ + delete root_; +} + +int +TAO_Interpreter::build_tree(const char* constraints) +{ + TAO_Lex_String_Input::reset((char*)constraints); + int return_value = 0; + + yyval.constraint_ = 0; + return_value = ::yyparse(); + + if (return_value == 0 && yyval.constraint_ != 0) + this->root_ = yyval.constraint_; + else + { + while (yylex() > 0) + ; + this->root_ = 0; + } + + return return_value; +} + + +int +TAO_Interpreter::is_empty_string(const char* str) +{ + int return_value = 0; + + if (str != 0) + { + int i = 0; + while (str[i] != '\0') + { + if (str[i] != ' ') + break; + + i++; + } + + if (str[i] == '\0') + return_value = 1; + } + + return return_value; +} + + // ************************************************************* + // TAO_Constraint_Interpreter + // ************************************************************* TAO_Constraint_Interpreter:: TAO_Constraint_Interpreter(CosTradingRepos::ServiceTypeRepository::TypeStruct* ts, @@ -75,3 +131,187 @@ TAO_Constraint_Interpreter::evaluate(TAO_Constraint_Evaluator& evaluator) return evaluator.evaluate_constraint (this->root_); } + // ************************************************************* + // TAO_Preference_Interpreter + // ************************************************************* + +const CORBA::Double TRADER_MAX_DOUBLE = 1.79769313486231570e+308; + +TAO_Preference_Interpreter:: +TAO_Preference_Interpreter(CosTradingRepos::ServiceTypeRepository::TypeStruct* ts, + const char* preference, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPreference)) + : TAO_Interpreter () +{ + TAO_Constraint_Validator type_checker(ts); + + if (TAO_Interpreter::is_empty_string(preference)) + this->root_ = new TAO_Noop_Constraint(TAO_FIRST); + else + { + if (this->build_tree (preference) != 0) + TAO_THROW (CosTrading::Lookup::IllegalPreference (preference)); + + if (type_checker.validate (this->root_) == -1) + TAO_THROW (CosTrading::Lookup::IllegalPreference (preference)); + } +} + +TAO_Preference_Interpreter:: +TAO_Preference_Interpreter(TAO_Constraint_Validator& validator, + const char* preference, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPreference)) + : TAO_Interpreter () +{ + if (TAO_Interpreter::is_empty_string(preference)) + this->root_ = new TAO_Noop_Constraint(TAO_FIRST); + else + { + if (this->build_tree (preference) != 0) + TAO_THROW (CosTrading::Lookup::IllegalPreference (preference)); + + if (validator.validate (this->root_) == -1) + TAO_THROW (CosTrading::Lookup::IllegalPreference (preference)); + } +} + +TAO_Preference_Interpreter::~TAO_Preference_Interpreter() +{ +} + +void +TAO_Preference_Interpreter:: +order_offer (CosTrading::OfferId offer_id, + CosTrading::Offer* offer) +{ + TAO_Constraint_Evaluator evaluator(offer); + this->order_offer (offer_id, offer, evaluator); +} + +void +TAO_Preference_Interpreter:: +order_offer (CosTrading::OfferId offer_id, + CosTrading::Offer* offer, + TAO_Constraint_Evaluator& evaluator) +{ + if (this->root_ != 0) + { + Preference_Info pref_info; + TAO_Expression_Type expr_type = this->root_->expr_type (); + + pref_info.offer_ = offer; + pref_info.offer_id_ = offer_id; + pref_info.evaluated_ = CORBA::B_TRUE; + + if (evaluator.evaluate_preference (this->root_, pref_info.value_) == 0) + { + // If the evaluation succeeds, insert the node into the + // correct place in the queue. + TAO_Expression_Type expr_type = this->root_->expr_type (); + + if (expr_type == TAO_FIRST) + this->offers_.enqueue_tail (pref_info); + else + this->offers_.enqueue_head (pref_info); + + if (expr_type == TAO_MIN || expr_type == TAO_MAX) + { + Ordered_Offers::ITERATOR offer_iter (this->offers_); + + // Push the new item down the list until the min/max + // criterion is satisfied. Observe the evaluation + // failed / evaluation suceeded partion in the list. + offer_iter.advance (); + for (int i = 1; + ! offer_iter.done (); + offer_iter.advance (), i++) + { + Preference_Info* current_offer; + offer_iter.next (current_offer); + + // Maintain the sorted order in the first partition. + if (current_offer->evaluated_ == CORBA::B_TRUE && + ((expr_type == TAO_MIN && + pref_info.value_ > current_offer->value_) || + (expr_type == TAO_MAX && + pref_info.value_ < current_offer->value_))) + { + this->offers_.set (*current_offer, i - 1); + this->offers_.set (pref_info, i); + } + else + break; + } + } + } + else + { + // If the evaluation fails, just tack the sucker onto the + // end of the queue. + pref_info.evaluated_ = CORBA::B_FALSE; + this->offers_.enqueue_tail (pref_info); + } + } +} + +int +TAO_Preference_Interpreter:: +remove_offer (CosTrading::OfferId& offer_id, + CosTrading::Offer*& offer) +{ + int return_value = -1; + Preference_Info pref_info; + + return_value = this->offers_.dequeue_head (pref_info); + + if (return_value == 0) + { + offer = pref_info.offer_; + offer_id = pref_info.offer_id_; + } + + return return_value; +} + +int +TAO_Preference_Interpreter::num_offers(void) +{ + return this->offers_.size(); +} + + // ************************************************************* + // Ugly Lex/Yacc Stuff + // ************************************************************* + +char* TAO_Lex_String_Input::string_ = 0; +char* TAO_Lex_String_Input::current_ = 0; +char* TAO_Lex_String_Input::end_ = 0; + +// Routine to have Lex read its input from the constraint string. + +int +TAO_Lex_String_Input::copy_into(char* buf, int max_size) +{ + int chars_left = TAO_Lex_String_Input::end_ - TAO_Lex_String_Input::current_; + int n = (max_size > chars_left) ? chars_left : max_size; + + + if (n > 0) + { + memcpy(buf, TAO_Lex_String_Input::current_, n); + TAO_Lex_String_Input::current_ += n; + } + + return n; +} + +void +TAO_Lex_String_Input::reset(char* input_string) +{ + TAO_Lex_String_Input::string_ = input_string; + TAO_Lex_String_Input::current_ = input_string; + TAO_Lex_String_Input::end_ = input_string + + ACE_OS::strlen(TAO_Lex_String_Input::string_); +} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Interpreter.h b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Interpreter.h index 9a988cb1177..1f29ae295ab 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Interpreter.h +++ b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Interpreter.h @@ -17,9 +17,39 @@ #ifndef TAO_CONSTRAINT_INTERPRETER_H #define TAO_CONSTRAINT_INTERPRETER_H -#include "Interpreter.h" -#include "Constraint_Validator.h" -#include "Constraint_Evaluator.h" +#include "Constraint_Nodes.h" +#include "Constraint_Visitors.h" + + // ************************************************************* + // TAO_Interpreter + // ************************************************************* + +class TAO_Interpreter +// = TITLE +// TAO_Interpreter is the superclass for all interpreters. It's +// build tree method invoke the yacc parser to parse a constraint +// or preference string. +{ +protected: + + TAO_Interpreter (void) : root_ (0) {} + + ~TAO_Interpreter (void); + + int build_tree (const char* preferences); + // Using the Yacc generated parser, construct an expression + // tree representing <constraints> from the tokens returned by it. + + static int is_empty_string (const char* str); + + TAO_Constraint* root_; + // The root of the expression tree, not equal to null if build_tree + // successfully builds a tree from the constraints. +}; + + // ************************************************************* + // TAO_Constraint_Interpreter + // ************************************************************* class TAO_Constraint_Interpreter : public TAO_Interpreter // @@ -65,4 +95,121 @@ public: // tree was constructed. This method is thread safe (hopefully). }; + // ************************************************************* + // TAO_Preference_Interpreter + // ************************************************************* + +class TAO_Preference_Interpreter : public TAO_Interpreter +// = TITLE +// The TAO_Preference_Interpreter will, given a valid preference +// string and offers, will order the offers based on the offers' +// compliance with the preferences. +// +// = DESCRIPTION +// Each time the order_offer method is invoked, the +// TAO_Preference_Interpreter stores the offer reference in the +// order dictated by its evaluation of the preference string. After +// the TAO_Preference_Interpreter client has finished ordering all +// the offers, it will extract the offers in order using the +// remove_offer method. +{ +public: + + TAO_Preference_Interpreter(CosTradingRepos::ServiceTypeRepository::TypeStruct* ts, + const char* preference, + CORBA::Environment& env) + TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPreference)); + + TAO_Preference_Interpreter(TAO_Constraint_Validator& validator, + const char* preference, + CORBA::Environment& env) + TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPreference)); + + // Parse the preference string, determining first if it's + // valid. Throw an IllegalPreference exception if the preference + // doesn't conform to the BNF grammar for preferences. + + ~TAO_Preference_Interpreter(void); + // Destructor + + void order_offer (CosTrading::OfferId offer_id, + CosTrading::Offer* offer); + + void order_offer (CosTrading::OfferId offer_id, + CosTrading::Offer* offer, + TAO_Constraint_Evaluator& evaluator); + // Evaluate the offer, and order it internally based on the results + // of the evaluation. + + int remove_offer (CosTrading::OfferId& offer_id, + CosTrading::Offer*& offer); + // Remove the next offer. The offer returned will be the next in the + // ordering determined by the preference string. + + int num_offers(void); + // Return the number of offers remaining in the ordering. + +private: + + struct Preference_Info + { + CORBA::Boolean evaluated_; + TAO_Literal_Constraint value_; + CosTrading::OfferId offer_id_; + CosTrading::Offer* offer_; + }; + + typedef ACE_Unbounded_Queue<Preference_Info> Ordered_Offers; + + Ordered_Offers offers_; +}; + + // ************************************************************* + // Ugly Lex/Yacc Stuff + // ************************************************************* + +// Functions we need for parsing. +extern int yyparse(void); +extern void yyrestart(FILE*); +extern int yylex(void); + +// Have yylex read from the constraint string, not from stdin. +#undef YY_INPUT +#define YY_INPUT(b, r, ms) (r = TAO_Lex_String_Input::copy_into(b, ms)) + +#undef yyerror +#define yyerror(x) + +class TAO_Lex_String_Input +// = TITLE +// Stupid hack to have Lex read from a string and not from +// stdin. Essentially, the interpreter needs to call yylex() until +// EOF, and call TAO_Lex_String_Input::reset() with the new string, +// prior to calling yyparse. +{ +public: + + static void reset(char* input_string); + // Reset the lex input. + + static int copy_into(char* buf, int max_size); + // Method lex will call to read from the input string. + +private: + + static char* string_; + static char* current_; + static char* end_; + // Pointers to keep track of the input string. +}; + +// The union used by lex and yacc to build the Abstract Syntax Tree. +typedef union +{ + TAO_Constraint* constraint_; +} YYSTYPE; + +extern YYSTYPE yylval; +extern YYSTYPE yyval; + #endif /* TAO_CONSTRAINT_INTERPRETER_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Nodes.cpp b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Nodes.cpp index a0427fa405f..f07307c2f36 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Nodes.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Nodes.cpp @@ -16,38 +16,39 @@ #include "Constraint_Nodes.h" +#include "Constraint_Visitors.h" const CORBA::Long MAX_SIGNED_INTEGER = (~(CORBA::Long)0) >> 1; const CORBA::Long MIN_SIGNED_INTEGER = ~(MAX_SIGNED_INTEGER); const CORBA::ULong MAX_UNSIGNED_INTEGER = (~(CORBA::ULong)0); int -TAO_Noop_Constraint::accept(TAO_Constraint_Visitor* visitor) +TAO_Noop_Constraint::accept (TAO_Constraint_Visitor* visitor) { int return_value = -1; - switch(this->type_) + switch (this->type_) { case TAO_FIRST: - return_value = visitor->visit_first(this); + return_value = visitor->visit_first (this); break; case TAO_RANDOM: - return_value = visitor->visit_random(this); + return_value = visitor->visit_random (this); } return return_value; } TAO_Binary_Constraint:: -TAO_Binary_Constraint(TAO_Expression_Type op_type, +TAO_Binary_Constraint (TAO_Expression_Type op_type, TAO_Constraint* left, TAO_Constraint* right) - : op_ (op_type), + : op_ (op_type), left_ (left), right_ (right) { } -TAO_Binary_Constraint::~TAO_Binary_Constraint() +TAO_Binary_Constraint::~TAO_Binary_Constraint () { delete left_; delete right_; @@ -78,7 +79,7 @@ static int (*dispatch_table[]) (TAO_Constraint_Visitor*, // Simulate the fun of actual double dispatching. int -TAO_Binary_Constraint::accept(TAO_Constraint_Visitor* visitor) +TAO_Binary_Constraint::accept (TAO_Constraint_Visitor* visitor) { int offset = this->op_ - TAO_GT, return_value = -1; @@ -91,7 +92,7 @@ TAO_Binary_Constraint::accept(TAO_Constraint_Visitor* visitor) int TAO_Binary_Constraint:: -visit_or(TAO_Constraint_Visitor* visitor, +visit_or (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { return visitor->visit_or(expr); @@ -99,7 +100,7 @@ visit_or(TAO_Constraint_Visitor* visitor, int TAO_Binary_Constraint:: -visit_and(TAO_Constraint_Visitor* visitor, +visit_and (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { return visitor->visit_and(expr); @@ -107,129 +108,129 @@ visit_and(TAO_Constraint_Visitor* visitor, int TAO_Binary_Constraint:: -visit_less_than(TAO_Constraint_Visitor* visitor, +visit_less_than (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_less_than(expr); + return visitor->visit_less_than (expr); } int TAO_Binary_Constraint:: -visit_less_than_equal(TAO_Constraint_Visitor* visitor, +visit_less_than_equal (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_less_than_equal(expr); + return visitor->visit_less_than_equal (expr); } int TAO_Binary_Constraint:: -visit_greater_than(TAO_Constraint_Visitor* visitor, +visit_greater_than (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_greater_than(expr); + return visitor->visit_greater_than (expr); } int TAO_Binary_Constraint:: -visit_greater_than_equal(TAO_Constraint_Visitor* visitor, +visit_greater_than_equal (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_greater_than_equal(expr); + return visitor->visit_greater_than_equal (expr); } int TAO_Binary_Constraint:: -visit_equal(TAO_Constraint_Visitor* visitor, +visit_equal (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_equal(expr); + return visitor->visit_equal (expr); } int TAO_Binary_Constraint:: -visit_not_equal(TAO_Constraint_Visitor* visitor, +visit_not_equal (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_not_equal(expr); + return visitor->visit_not_equal (expr); } int TAO_Binary_Constraint:: -visit_add(TAO_Constraint_Visitor* visitor, +visit_add (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_add(expr); + return visitor->visit_add (expr); } int TAO_Binary_Constraint:: -visit_sub(TAO_Constraint_Visitor* visitor, +visit_sub (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_sub(expr); + return visitor->visit_sub (expr); } int TAO_Binary_Constraint:: -visit_mult(TAO_Constraint_Visitor* visitor, +visit_mult (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_mult(expr); + return visitor->visit_mult (expr); } int TAO_Binary_Constraint:: -visit_div(TAO_Constraint_Visitor* visitor, +visit_div (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_div(expr); + return visitor->visit_div (expr); } int TAO_Binary_Constraint:: -visit_twiddle(TAO_Constraint_Visitor* visitor, +visit_twiddle (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_twiddle(expr); + return visitor->visit_twiddle (expr); } int TAO_Binary_Constraint:: -visit_in(TAO_Constraint_Visitor* visitor, +visit_in (TAO_Constraint_Visitor* visitor, TAO_Binary_Constraint* expr) { - return visitor->visit_in(expr); + return visitor->visit_in (expr); } TAO_Constraint* -TAO_Binary_Constraint::left_operand() +TAO_Binary_Constraint::left_operand (void) const { return this->left_; } TAO_Constraint* -TAO_Binary_Constraint::right_operand() +TAO_Binary_Constraint::right_operand (void) const { return this->right_; } TAO_Unary_Constraint:: -TAO_Unary_Constraint(TAO_Expression_Type op_type, +TAO_Unary_Constraint (TAO_Expression_Type op_type, TAO_Constraint* operand) : op_ (op_type), operand_ (operand) { } -TAO_Unary_Constraint::~TAO_Unary_Constraint() +TAO_Unary_Constraint::~TAO_Unary_Constraint (void) { delete operand_; } int -TAO_Unary_Constraint::accept(TAO_Constraint_Visitor* visitor) +TAO_Unary_Constraint::accept (TAO_Constraint_Visitor* visitor) { // Since there are only three unary operators, there's no need for a // dispatch table. @@ -237,25 +238,25 @@ TAO_Unary_Constraint::accept(TAO_Constraint_Visitor* visitor) switch (this->op_) { case TAO_CONSTRAINT: - return_value = visitor->visit_constraint(this); + return_value = visitor->visit_constraint (this); break; case TAO_WITH: - return_value = visitor->visit_with(this); + return_value = visitor->visit_with (this); break; case TAO_MIN: - return_value = visitor->visit_min(this); + return_value = visitor->visit_min (this); break; case TAO_MAX: - return_value = visitor->visit_max(this); + return_value = visitor->visit_max (this); break; case TAO_NOT: - return_value = visitor->visit_not(this); + return_value = visitor->visit_not (this); break; case TAO_UMINUS: - return_value = visitor->visit_unary_minus(this); + return_value = visitor->visit_unary_minus (this); break; case TAO_EXIST: - return_value = visitor->visit_exist(this); + return_value = visitor->visit_exist (this); break; } @@ -263,30 +264,30 @@ TAO_Unary_Constraint::accept(TAO_Constraint_Visitor* visitor) } TAO_Constraint* -TAO_Unary_Constraint::operand() +TAO_Unary_Constraint::operand (void) { return this->operand_; } TAO_Property_Constraint:: -TAO_Property_Constraint(const char* name) - : name_ (ACE_OS::strdup (name)) +TAO_Property_Constraint (const char* name) + : name_ (CORBA::string_dup (name)) { } -TAO_Property_Constraint::~TAO_Property_Constraint() +TAO_Property_Constraint::~TAO_Property_Constraint (void) { - delete this->name_; + CORBA::string_free (this->name_); } int TAO_Property_Constraint::accept(TAO_Constraint_Visitor* visitor) { - return visitor->visit_property(this); + return visitor->visit_property (this); } const char* -TAO_Property_Constraint::name() const +TAO_Property_Constraint::name (void) const { return name_; } @@ -299,7 +300,7 @@ TAO_Literal_Constraint (const TAO_Literal_Constraint& lit) TAO_Literal_Constraint:: -TAO_Literal_Constraint(CORBA::Any* any) +TAO_Literal_Constraint (CORBA::Any* any) : type_ (TAO_Literal_Constraint::comparable_type (any->type ())) { CORBA::Environment env; @@ -351,7 +352,7 @@ TAO_Literal_Constraint(CORBA::Any* any) { char * s; any_ref >>= s; - this->op_.str_ = ACE_OS::strdup(s); + this->op_.str_ = CORBA::string_dup (s); } break; case TAO_SEQUENCE: @@ -359,44 +360,44 @@ TAO_Literal_Constraint(CORBA::Any* any) } } -TAO_Literal_Constraint::TAO_Literal_Constraint(CORBA::ULong uinteger) +TAO_Literal_Constraint::TAO_Literal_Constraint (CORBA::ULong uinteger) : type_ (TAO_UNSIGNED) { this->op_.uinteger_ = uinteger; } -TAO_Literal_Constraint::TAO_Literal_Constraint(CORBA::Long integer) +TAO_Literal_Constraint::TAO_Literal_Constraint (CORBA::Long integer) : type_ (TAO_SIGNED) { this->op_.integer_ = integer; } -TAO_Literal_Constraint::TAO_Literal_Constraint(CORBA::Boolean boolean) +TAO_Literal_Constraint::TAO_Literal_Constraint (CORBA::Boolean boolean) : type_ (TAO_BOOLEAN) { this->op_.bool_ = boolean; } -TAO_Literal_Constraint::TAO_Literal_Constraint(CORBA::Double doub) +TAO_Literal_Constraint::TAO_Literal_Constraint (CORBA::Double doub) : type_ (TAO_DOUBLE) { this->op_.double_ = doub; } -TAO_Literal_Constraint::TAO_Literal_Constraint(const char* str) +TAO_Literal_Constraint::TAO_Literal_Constraint (const char* str) : type_ (TAO_STRING) { - this->op_.str_ = ACE_OS::strdup(str); + this->op_.str_ = CORBA::string_dup (str); } -TAO_Literal_Constraint::~TAO_Literal_Constraint(void) +TAO_Literal_Constraint::~TAO_Literal_Constraint (void) { if (this->type_ == TAO_STRING) - free (this->op_.str_); + CORBA::string_free (this->op_.str_); } int -TAO_Literal_Constraint::accept(TAO_Constraint_Visitor* visitor) +TAO_Literal_Constraint::accept (TAO_Constraint_Visitor* visitor) { return visitor->visit_literal(this); } @@ -407,12 +408,12 @@ TAO_Literal_Constraint::operator= (const TAO_Literal_Constraint& co) this->copy (co); } -TAO_Literal_Constraint::operator CORBA::Boolean(void) const +TAO_Literal_Constraint::operator CORBA::Boolean (void) const { return (this->type_ == TAO_BOOLEAN) ? this->op_.bool_ : CORBA::B_FALSE; } -TAO_Literal_Constraint::operator CORBA::ULong(void) const +TAO_Literal_Constraint::operator CORBA::ULong (void) const { CORBA::ULong return_value = (CORBA::ULong)0; @@ -432,7 +433,7 @@ TAO_Literal_Constraint::operator CORBA::ULong(void) const return return_value; } -TAO_Literal_Constraint::operator CORBA::Long(void) const +TAO_Literal_Constraint::operator CORBA::Long (void) const { CORBA::Long return_value = (CORBA::Long)0; @@ -455,7 +456,7 @@ TAO_Literal_Constraint::operator CORBA::Long(void) const return return_value; } -TAO_Literal_Constraint::operator CORBA::Double(void) const +TAO_Literal_Constraint::operator CORBA::Double (void) const { CORBA::Double return_value = (CORBA::Double)0.0; @@ -878,8 +879,8 @@ operator- (const TAO_Literal_Constraint& operand) } TAO_Expression_Type -TAO_Literal_Constraint::widest_type(const TAO_Literal_Constraint& left, - const TAO_Literal_Constraint& right) +TAO_Literal_Constraint::widest_type (const TAO_Literal_Constraint& left, + const TAO_Literal_Constraint& right) { TAO_Expression_Type left_type = left.expr_type(), right_type = right.expr_type(), @@ -901,7 +902,7 @@ TAO_Literal_Constraint::copy (const TAO_Literal_Constraint& lit) { this->type_ = lit.type_; if (this->type_ == TAO_STRING) - this->op_.str_ = ACE_OS::strdup(lit.op_.str_); + this->op_.str_ = CORBA::string_dup (lit.op_.str_); else if (this->type_ == TAO_DOUBLE) this->op_.double_ = lit.op_.double_; else if (this->type_ == TAO_UNSIGNED) diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Nodes.h b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Nodes.h index 29544b3ddd6..c24404cfe3a 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Nodes.h +++ b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Nodes.h @@ -17,7 +17,7 @@ #ifndef TAO_CONSTRAINT_NODES_H #define TAO_CONSTRAINT_NODES_H -#include "Constraint_Visitor.h" +//#include "Constraint_Visitors.h" #include "Constraint_Tokens.h" #include "orbsvcs/CosTradingC.h" @@ -27,6 +27,7 @@ #pragma warning (disable:4250) #endif /* _MSC_VER */ +class TAO_Constraint_Visitor; typedef unsigned short TAO_Expression_Type; class TAO_Constraint @@ -44,27 +45,27 @@ class TAO_Constraint { public: - virtual int accept(TAO_Constraint_Visitor* visitor) = 0; + virtual int accept (TAO_Constraint_Visitor* visitor) = 0; // Implementing the pattern of double dispatching, each subclass of // TAO_Constraint will call back on an InterpreterVisitor the // method to handle a node of its ExpressionType. - virtual TAO_Expression_Type expr_type(void) const = 0; + virtual TAO_Expression_Type expr_type (void) const = 0; // Return the expression type represented by this node. - virtual ~TAO_Constraint(void) {} + virtual ~TAO_Constraint (void) {} }; class TAO_Noop_Constraint : public TAO_Constraint { public: - TAO_Noop_Constraint(TAO_Expression_Type type) + TAO_Noop_Constraint (TAO_Expression_Type type) : type_ (type) {} - virtual int accept(TAO_Constraint_Visitor* visitor); + virtual int accept (TAO_Constraint_Visitor* visitor); - virtual TAO_Expression_Type expr_type(void) const + virtual TAO_Expression_Type expr_type (void) const { return this->type_; } private: @@ -80,41 +81,41 @@ class TAO_Binary_Constraint : public TAO_Constraint { public: - TAO_Binary_Constraint(TAO_Expression_Type op_type, - TAO_Constraint* left, - TAO_Constraint* right); + TAO_Binary_Constraint (TAO_Expression_Type op_type, + TAO_Constraint* left, + TAO_Constraint* right); - virtual int accept(TAO_Constraint_Visitor* visitor); + virtual int accept (TAO_Constraint_Visitor* visitor); - virtual ~TAO_Binary_Constraint(void); + virtual ~TAO_Binary_Constraint (void); - virtual TAO_Expression_Type expr_type(void) const + virtual TAO_Expression_Type expr_type (void) const { return this->op_; } - TAO_Constraint* left_operand(void); + TAO_Constraint* left_operand (void) const; // Return the left operand of the binary expression - TAO_Constraint* right_operand(void); + TAO_Constraint* right_operand (void) const; // Return the right operand of the binary expression // Allow double dispatching without creating an inundation of // classes by using a dispatch table of static method pointers to // invoke the correct visitor method as efficiently as a virtual // method invocation. - static int visit_or(TAO_Constraint_Visitor*, TAO_Binary_Constraint*); - static int visit_and(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_less_than(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_less_than_equal(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_greater_than(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_greater_than_equal(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_equal(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_not_equal(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_add(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_sub(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_mult(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_div(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_twiddle(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); - static int visit_in(TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_or (TAO_Constraint_Visitor*, TAO_Binary_Constraint*); + static int visit_and (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_less_than (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_less_than_equal (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_greater_than (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_greater_than_equal (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_equal (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_not_equal (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_add (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_sub (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_mult (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_div (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_twiddle (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); + static int visit_in (TAO_Constraint_Visitor* , TAO_Binary_Constraint*); private: @@ -134,17 +135,17 @@ class TAO_Unary_Constraint : public TAO_Constraint { public: - TAO_Unary_Constraint(TAO_Expression_Type op_type, + TAO_Unary_Constraint (TAO_Expression_Type op_type, TAO_Constraint* operand); - virtual ~TAO_Unary_Constraint(void); + virtual ~TAO_Unary_Constraint (void); - virtual int accept(TAO_Constraint_Visitor* visitor); + virtual int accept (TAO_Constraint_Visitor* visitor); - virtual TAO_Expression_Type expr_type(void) const + virtual TAO_Expression_Type expr_type (void) const { return this->op_; } - TAO_Constraint* operand(void); + TAO_Constraint* operand (void); private: @@ -163,16 +164,16 @@ class TAO_Property_Constraint : public TAO_Constraint { public: - TAO_Property_Constraint(const char* name); + TAO_Property_Constraint (const char* name); - virtual ~TAO_Property_Constraint(void); + virtual ~TAO_Property_Constraint (void); - virtual int accept(TAO_Constraint_Visitor* visitor); + virtual int accept (TAO_Constraint_Visitor* visitor); - virtual TAO_Expression_Type expr_type(void) const + virtual TAO_Expression_Type expr_type (void) const { return TAO_IDENT; } - const char* name(void) const; + const char* name (void) const; // Returns the name of the property. private: @@ -189,39 +190,39 @@ class TAO_Literal_Constraint : public TAO_Constraint { public: - TAO_Literal_Constraint(void) + TAO_Literal_Constraint (void) : type_ (TAO_UNKNOWN) {} // = Constructors for each of the various types of literals. - TAO_Literal_Constraint(CORBA::Any* any); + TAO_Literal_Constraint (CORBA::Any* any); - TAO_Literal_Constraint(CORBA::ULong uinteger); + TAO_Literal_Constraint (CORBA::ULong uinteger); - TAO_Literal_Constraint(CORBA::Long integer); + TAO_Literal_Constraint (CORBA::Long integer); - TAO_Literal_Constraint(CORBA::Boolean boolean); + TAO_Literal_Constraint (CORBA::Boolean boolean); - TAO_Literal_Constraint(CORBA::Double doub); + TAO_Literal_Constraint (CORBA::Double doub); - TAO_Literal_Constraint(const char* str); + TAO_Literal_Constraint (const char* str); TAO_Literal_Constraint (const TAO_Literal_Constraint& lit); ~TAO_Literal_Constraint(void); - virtual int accept(TAO_Constraint_Visitor* visitor); + virtual int accept (TAO_Constraint_Visitor* visitor); - virtual TAO_Expression_Type expr_type(void) const + virtual TAO_Expression_Type expr_type (void) const { return type_; } void operator= (const TAO_Literal_Constraint& co); // Conversion routines. - operator CORBA::Boolean(void) const; - operator CORBA::ULong(void) const; - operator CORBA::Long(void) const; - operator CORBA::Double(void) const; + operator CORBA::Boolean (void) const; + operator CORBA::ULong (void) const; + operator CORBA::Long (void) const; + operator CORBA::Double (void) const; operator const char* (void) const; operator const CORBA::Any* (void) const; diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Validator.cpp b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Validator.cpp deleted file mode 100644 index 24a9099b39d..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Validator.cpp +++ /dev/null @@ -1,468 +0,0 @@ -// Constraint_Validator.cpp - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Constraint_Validator.cpp -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#include "Constraint_Validator.h" - -TAO_Constraint_Validator:: -TAO_Constraint_Validator -(CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct) -{ - CosTradingRepos::ServiceTypeRepository::PropStructSeq& prop_seq = - type_struct->props; - int length = prop_seq.length(); - - // Create a map of the service type properties to their types. - for (int i = 0; i < length; i++) - { - CORBA::TypeCode_var corba_type = prop_seq[i].value_type; - TAO_String_Hash_Key prop_name_str = (const char*) prop_seq[i].name; - this->type_map_.bind (prop_name_str, corba_type.ptr ()); - } -} - -int -TAO_Constraint_Validator::validate (TAO_Constraint* root) -{ - return root->accept(this); -} - -int -TAO_Constraint_Validator::visit_constraint(TAO_Unary_Constraint* constraint) -{ - int return_value = -1; - TAO_Expression_Type type; - TAO_Constraint* operand = constraint->operand(); - this->extract_type(operand, type); - - if (this->expr_returns_boolean (type)) - return_value = operand->accept (this); - - return return_value; -} - -int -TAO_Constraint_Validator::visit_first(TAO_Noop_Constraint* noop) -{ - return 0; -} - -int -TAO_Constraint_Validator::visit_random(TAO_Noop_Constraint* noop) -{ - return 0; -} - -int -TAO_Constraint_Validator::visit_with(TAO_Unary_Constraint* unary_with) -{ - return this->visit_constraint(unary_with); -} - -int -TAO_Constraint_Validator::visit_min(TAO_Unary_Constraint* unary_min) -{ - return this->visit_unary_minus(unary_min); -} - -int -TAO_Constraint_Validator::visit_max(TAO_Unary_Constraint* unary_max) -{ - return this->visit_unary_minus(unary_max); -} - -int -TAO_Constraint_Validator:: -visit_and(TAO_Binary_Constraint* boolean_and) -{ - int return_value = -1; - TAO_Constraint* left = boolean_and->left_operand(), - *right = boolean_and->right_operand(); - TAO_Expression_Type left_type, right_type; - this->extract_type(left, left_type); - this->extract_type(right, right_type); - - // Can only "and" expressions that return a boolean value - if (this->expr_returns_boolean(left_type) && - this->expr_returns_boolean(right_type)) - { - if (left->accept(this) == 0 && - right->accept(this) == 0) - return_value = 0; - } - - return return_value; -} - -int -TAO_Constraint_Validator:: -visit_or(TAO_Binary_Constraint* boolean_or) -{ - // The types for or are the same as those for and. - return this->visit_and(boolean_or); -} - -int -TAO_Constraint_Validator:: -visit_not(TAO_Unary_Constraint* unary_not) -{ - int return_value = -1; - // Not can only negate an expression that returns a boolean. - TAO_Expression_Type type; - TAO_Constraint* operand = unary_not->operand(); - this->extract_type(operand, type); - - if (this->expr_returns_boolean(type)) - return_value = operand->accept(this); - - return return_value; -} - -int -TAO_Constraint_Validator:: -visit_exist(TAO_Unary_Constraint* unary_exist) -{ - // Exist simply requires that its operand be a property name - // included in the service type. - int return_value = -1; - TAO_Constraint* operand = unary_exist->operand(); - TAO_Expression_Type type = operand->expr_type(); - - if (type == TAO_IDENT) - return_value = operand->accept(this); - - return return_value; -} - -int -TAO_Constraint_Validator:: -visit_unary_minus(TAO_Unary_Constraint* unary_minus) -{ - // Unary minus can only negate a numeric operand. - int return_value = -1; - TAO_Expression_Type type; - TAO_Constraint* operand = unary_minus->operand(); - this->extract_type(operand, type); - - if (this->expr_returns_number(type)) - return_value = operand->accept(this); - - return return_value; -} - -int -TAO_Constraint_Validator:: -visit_add(TAO_Binary_Constraint* boolean_add) -{ - // All the mathematical operators require numeric operands. - int return_value = -1; - TAO_Constraint* left = boolean_add->left_operand(), - *right = boolean_add->right_operand(); - TAO_Expression_Type left_type, right_type; - this->extract_type(left, left_type); - this->extract_type(right, right_type); - - if (this->expr_returns_number(left_type) && - this->expr_returns_number(right_type)) - { - if (left->accept(this) == 0 && - right->accept(this) == 0) - return_value = 0; - } - - return return_value; -} - -int -TAO_Constraint_Validator:: -visit_sub(TAO_Binary_Constraint* boolean_sub) -{ - return this->visit_add(boolean_sub); -} - -int -TAO_Constraint_Validator:: -visit_mult(TAO_Binary_Constraint* boolean_mult) -{ - return this->visit_add(boolean_mult); -} - -int -TAO_Constraint_Validator:: -visit_div(TAO_Binary_Constraint* boolean_div) -{ - // Div not only requires that both of its operands be numeric, but - // also the the demoninator not be zero. However, since the - // denominator can be an expression who's value can only be - // determined while evaulating the constraint expression, this - // method detects only when the demoniator is a literal whose value - // is zero. - int return_value = -1; - TAO_Constraint* left = boolean_div->left_operand(), - *right = boolean_div->right_operand(); - TAO_Expression_Type left_type, right_type; - this->extract_type(left, left_type); - this->extract_type(right, right_type); - - if (this->expr_returns_number(left_type) && - this->expr_returns_number(right_type)) - { - // Prevent division by zero, a no no. - int right_isnt_zero = 1; - switch(right->expr_type()) - { - case TAO_UNSIGNED: - right_isnt_zero = - ((CORBA::ULong) (*((TAO_Literal_Constraint*) right)) != 0); - break; - case TAO_SIGNED: - right_isnt_zero = - ((CORBA::Long) (*((TAO_Literal_Constraint*) right)) != 0); - break; - case TAO_DOUBLE: - right_isnt_zero = - ((CORBA::Double) (*((TAO_Literal_Constraint*) right)) != 0.0); - break; - } - - if (right_isnt_zero) - { - if (left->accept(this) == 0 && - right->accept(this) == 0) - return_value = 0; - } - } - - return return_value; -} - -int -TAO_Constraint_Validator:: -visit_twiddle(TAO_Binary_Constraint* binary_twiddle) -{ - // Twiddle requires that both of its operand be strings. - int return_value = -1; - TAO_Constraint* left = binary_twiddle->left_operand(), - *right = binary_twiddle->right_operand(); - TAO_Expression_Type left_type, right_type; - this->extract_type(left, left_type); - this->extract_type(right, right_type); - - if (this->expr_returns_string(left_type) && - this->expr_returns_string(right_type)) - { - if (left->accept(this) == 0 && - right->accept(this) == 0) - return_value = 0; - } - - return return_value; -} - -int -TAO_Constraint_Validator:: -visit_in (TAO_Binary_Constraint* binary_in) -{ - // In requires that the right operand be a sequence of a simple type - // and that its left operand be an expression that evaluates to a - // value of the same simple type. - int return_value = -1; - TAO_Constraint* left = binary_in->left_operand(), - *right = binary_in->right_operand(); - TAO_Expression_Type left_type, right_type; - CORBA::TypeCode* prop_type = this->extract_type(right, right_type); - this->extract_type(left, left_type); - - if (right_type == TAO_SEQUENCE) - { - int types_match = 0; - CORBA::Environment env; - - if (this->expr_returns_number (left_type)) - { - types_match = - prop_type->equal (TAO_Sequences::_tc_ShortSeq, env) || - prop_type->equal (TAO_Sequences::_tc_UShortSeq, env) || - prop_type->equal (TAO_Sequences::_tc_LongSeq, env) || - prop_type->equal (TAO_Sequences::_tc_ULongSeq, env) || - prop_type->equal (TAO_Sequences::_tc_DoubleSeq, env) || - prop_type->equal (TAO_Sequences::_tc_FloatSeq, env); - } - else if (this->expr_returns_boolean (left_type)) - types_match = prop_type->equal (TAO_Sequences::_tc_BooleanSeq, env); - else if (this->expr_returns_string (left_type)) - types_match = prop_type->equal (TAO_Sequences::_tc_StringSeq, env); - - if (types_match) - return_value = left->accept(this); - } - - return return_value; -} - -int -TAO_Constraint_Validator:: -visit_less_than(TAO_Binary_Constraint* boolean_lt) -{ - // Comparison operations require that both operands be of the same - // simple type. - int return_value = -1; - TAO_Constraint* left = boolean_lt->left_operand(), - *right = boolean_lt->right_operand(); - TAO_Expression_Type left_type, right_type; - this->extract_type(left, left_type); - this->extract_type(right, right_type); - - if ((this->expr_returns_number(left_type) && - this->expr_returns_number(right_type)) || - (this->expr_returns_string(left_type) && - this->expr_returns_string(right_type))) - { - if (left->accept(this) == 0 && - right->accept(this) == 0) - return_value = 0; - } - - return return_value; -} - -int -TAO_Constraint_Validator:: -visit_less_than_equal(TAO_Binary_Constraint* boolean_lte) -{ - return this->visit_less_than(boolean_lte); -} - -int -TAO_Constraint_Validator:: -visit_greater_than(TAO_Binary_Constraint* boolean_gt) -{ - return this->visit_less_than(boolean_gt); -} - -int -TAO_Constraint_Validator:: -visit_greater_than_equal(TAO_Binary_Constraint* boolean_gte) -{ - return this->visit_less_than(boolean_gte); -} - -int -TAO_Constraint_Validator:: -visit_equal(TAO_Binary_Constraint* boolean_eq) -{ - int return_value = -1; - TAO_Constraint* left = boolean_eq->left_operand(), - *right = boolean_eq->right_operand(); - TAO_Expression_Type left_type, right_type; - this->extract_type(left, left_type); - this->extract_type(right, right_type); - - if ((this->expr_returns_number(left_type) && - this->expr_returns_number(right_type)) || - (this->expr_returns_string(left_type) && - this->expr_returns_string(right_type)) || - (this->expr_returns_boolean(left_type) && - this->expr_returns_boolean(right_type))) - { - if (left->accept(this) == 0 && - right->accept(this) == 0) - return_value = 0; - } - - return return_value; -} - -int -TAO_Constraint_Validator:: -visit_not_equal(TAO_Binary_Constraint* boolean_neq) -{ - return this->visit_equal(boolean_neq); -} - -int -TAO_Constraint_Validator:: -visit_literal(TAO_Literal_Constraint* literal) -{ - return 0; -} - -int -TAO_Constraint_Validator:: -visit_property(TAO_Property_Constraint* literal) -{ - return 0; -} - -CORBA::TypeCode* -TAO_Constraint_Validator::extract_type (TAO_Constraint* expr, - TAO_Expression_Type& type) -{ - CORBA::TypeCode* return_value = 0; - - type = expr->expr_type(); - if (type == TAO_IDENT) - { - TAO_Property_Constraint* prop = (TAO_Property_Constraint*) expr; - TAO_String_Hash_Key prop_name (prop->name()); - - if (this->type_map_.find (prop_name, return_value) == 0) - type = TAO_Literal_Constraint::comparable_type (return_value); - } - - return return_value; -} - -int -TAO_Constraint_Validator::expr_returns_boolean(TAO_Expression_Type expr_type) -{ - // If the expression is a boolean operations, a boolean literal, or - // a boolean property, return 1. - int return_value = 0; - - if (expr_type <= TAO_BOOLEAN) - return_value = 1; - - return return_value; -} - - -int -TAO_Constraint_Validator::expr_returns_number(TAO_Expression_Type expr_type) -{ - // If the expression is a number operation, a numeric literal, or a - // numeric property, return 1. - int return_value = 0; - - if ((expr_type >= TAO_PLUS && expr_type <= TAO_NUMBER) || - (expr_type >= TAO_UNSIGNED && expr_type <= TAO_DOUBLE)) - return_value = 1; - - return return_value; -} - -int -TAO_Constraint_Validator::expr_returns_string(TAO_Expression_Type expr_type) -{ - // If the expression is an operation with a string return value, a - // string literal, or a property whose type is string, return 1. - int return_value = 0; - - if (expr_type == TAO_STRING) - return_value = 1; - - return return_value; -} - diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Validator.h b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Validator.h deleted file mode 100644 index 9191487cf5f..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Validator.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Constraint_Validator.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_CONSTRAINT_VALIDATOR_H -#define TAO_CONSTRAINT_VALIDATOR_H - -#include "Trader.h" -#include "Constraint_Nodes.h" - -class TAO_Constraint_Validator : public TAO_Constraint_Visitor - // - // = TITLE - // TAO_Constraint_Validator ensures that in an expression tree - // passed to it, the operands of each operation match the - // correct types. - // - // = DESCRIPTION - // TAO_Constraint_Validator uses the visitor pattern to - // traverse all the nodes in an expression tree, checking each - // for operands of the proper type. The algorithm for type - // checking is as follows: ensure that operand expression(s) - // return the correct types using exprReturns* methods, and their - // types. If they (or it) return the correct types, call accept - // on the operands until all return true, or one returns false, - // at which point we can back out of the traversal. -{ -public: - - TAO_Constraint_Validator - (CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct); - // The constructor creates a map of property names to their values - // from the Type Description retrieved from the - // ServiceTypeRepository. The ServiceTypeRepository throws - // exceptions when it's displeased with the type name provided to - // it. The map allows O(lg n) associative access, rather than the - // O(n) sequential lookup from the CORBA data structures. - - int validate(TAO_Constraint* root); - // Validate returns 1 if the expression tree whose root is <root> - // makes semantic sense, in that the operands for each operation - // comply with each other and the types accepted by the operator. - - // = Visitor Methods - - virtual int visit_constraint(TAO_Unary_Constraint* constraint); - - virtual int visit_with(TAO_Unary_Constraint* unary_with); - virtual int visit_min(TAO_Unary_Constraint* unary_min); - virtual int visit_max(TAO_Unary_Constraint* unary_max); - virtual int visit_first(TAO_Noop_Constraint* noop_first); - virtual int visit_random(TAO_Noop_Constraint* noop_random); - - virtual int visit_and(TAO_Binary_Constraint* boolean_and); - virtual int visit_or(TAO_Binary_Constraint* boolean_or); - // The two operands must return a boolean value. - - virtual int visit_not(TAO_Unary_Constraint* unary_not); - // The operand must return a boolean value. - - virtual int visit_exist(TAO_Unary_Constraint* unary_exist); - // The operand must return a valid (i.e., present in the service - // type description) property name. - - virtual int visit_unary_minus(TAO_Unary_Constraint* unary_minus); - // The operand must return a number to be negated. - - virtual int visit_add(TAO_Binary_Constraint* boolean_add); - virtual int visit_sub(TAO_Binary_Constraint* boolean_sub); - virtual int visit_mult(TAO_Binary_Constraint* boolean_mult); - virtual int visit_div(TAO_Binary_Constraint* boolean_div); - // Both operands must return numeric results. - - virtual int visit_twiddle(TAO_Binary_Constraint* binary_twiddle); - // Both operands must return strings. - - virtual int visit_in(TAO_Binary_Constraint* binary_in); - // The right operand must be a sequence of the same simple type as - // the left operand. - - virtual int visit_less_than(TAO_Binary_Constraint* boolean_lt); - virtual int visit_less_than_equal(TAO_Binary_Constraint* boolean_lte); - virtual int visit_greater_than(TAO_Binary_Constraint* boolean_gt); - virtual int visit_greater_than_equal(TAO_Binary_Constraint* boolean_gte); - virtual int visit_equal(TAO_Binary_Constraint* boolean_eq); - virtual int visit_not_equal(TAO_Binary_Constraint* boolean_neq); - // The left and right operands must both be of the same simple type. - - virtual int visit_literal(TAO_Literal_Constraint* literal); - virtual int visit_property(TAO_Property_Constraint* literal); - // The property must be defined in the service type description. - -private: - - typedef ACE_Hash_Map_Manager - < - TAO_String_Hash_Key, - CORBA::TypeCode_ptr, - ACE_Null_Mutex - > - Property_Type_Map; - - Property_Type_Map type_map_; - // A map gleaned from the ServiceTypeStruct, which correlates - // property names with their types. - - CORBA::TypeCode* extract_type(TAO_Constraint* expr_type, - TAO_Expression_Type& type); - - int expr_returns_boolean(TAO_Expression_Type expr_type); - // expr_returns_boolean returns 1 if <expr_type>, when evaluated, will - // return a boolean. - - int expr_returns_number(TAO_Expression_Type expr_type); - // expr_returns_boolean returns 1 if <expr_type>, when evaluated, will - // return a number. - - int expr_returns_string(TAO_Expression_Type expr_type); - // expr_returns_boolean returns 1 if <expr_type>, when evaluated, will - // return a string. -}; - -#endif /* TAO_CONSTRAINT_VALIDATOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Visitor.h b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Visitor.h deleted file mode 100644 index 255b483b490..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Visitor.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Constraint_Visitor.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_CONSTRAINT_VISITOR_H -#define TAO_CONSTRAINT_VISITOR_H - -class TAO_Binary_Constraint; -class TAO_Unary_Constraint; -class TAO_Property_Constraint; -class TAO_Literal_Constraint; -class TAO_Noop_Constraint; - -class TAO_Constraint_Visitor -// -// = TITLE -// This is the base class for all visitors who wish to preform -// some operation from the state of the expression tree. Using -// double dispatching, subclasses of Constraint expression call -// back to the InterpreterVisitor subclass from the accept method. -// -// = DESCRIPTION -// Traversal of the expression tree uses the "Visitor" pattern. To -// "visit" a node, a client invokes the "accept" method on a -// subclass of ConstraintExpression, which, in turn, invokes the -// appropriate method on the visitor passed to it, based on its -// own type. So, the Constraint_Visitor has a method to deal with -// each possible type of node in an expression tree; one for each -// operator in the grammar. -{ -public: - - virtual int visit_constraint(TAO_Unary_Constraint* constraint) = 0; - - virtual int visit_with(TAO_Unary_Constraint* unary_with) = 0; - virtual int visit_min(TAO_Unary_Constraint* unary_min) = 0; - virtual int visit_max(TAO_Unary_Constraint* unary_max) = 0; - virtual int visit_first(TAO_Noop_Constraint* noop_first) = 0; - virtual int visit_random(TAO_Noop_Constraint* noop_random) = 0; - - virtual int visit_and(TAO_Binary_Constraint* boolean_and) = 0; - virtual int visit_or(TAO_Binary_Constraint* boolean_or) = 0; - virtual int visit_not(TAO_Unary_Constraint* unary_not) = 0; - - virtual int visit_exist(TAO_Unary_Constraint* unary_exist) = 0; - virtual int visit_unary_minus(TAO_Unary_Constraint* unary_minus) = 0; - - virtual int visit_add(TAO_Binary_Constraint* boolean_add) = 0; - virtual int visit_sub(TAO_Binary_Constraint* boolean_sub) = 0; - virtual int visit_mult(TAO_Binary_Constraint* boolean_mult) = 0; - virtual int visit_div(TAO_Binary_Constraint* boolean_div) = 0; - - virtual int visit_twiddle(TAO_Binary_Constraint* binary_twiddle) = 0; - virtual int visit_in(TAO_Binary_Constraint* binary_in) = 0; - - virtual int visit_less_than(TAO_Binary_Constraint* boolean_lt) = 0; - virtual int visit_less_than_equal(TAO_Binary_Constraint* boolean_lte) = 0; - virtual int visit_greater_than(TAO_Binary_Constraint* boolean_gt) = 0; - virtual int visit_greater_than_equal(TAO_Binary_Constraint* boolean_gte) = 0; - virtual int visit_equal(TAO_Binary_Constraint* boolean_eq) = 0; - virtual int visit_not_equal(TAO_Binary_Constraint* boolean_neq) = 0; - - virtual int visit_literal(TAO_Literal_Constraint* literal) = 0; - virtual int visit_property(TAO_Property_Constraint* literal) = 0; -}; - -#endif /* CONSTRAINT_VISITOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.cpp b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Visitors.cpp index c8d7381aace..a6ae436e5af 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Visitors.cpp @@ -1,4 +1,4 @@ -// Constraint_Evaluator.cpp +// Constraint_Visitors.cpp // $Id$ // ======================================================================== @@ -7,16 +7,21 @@ // orbsvcs // // = FILENAME -// Constraint_Evaluator.cpp +// Constraint_Visitors.cpp // // = AUTHOR // Seth Widoff <sbw1@cs.wustl.edu> // // ======================================================================== -#include "Constraint_Evaluator.h" +#include "Constraint_Visitors.h" +#include "Constraint_Nodes.h" #include "Trader_T.h" + // ************************************************************* + // TAO_Constraint_Evaluator + // ************************************************************* + TAO_Constraint_Evaluator::Operand_Queue::Operand_Queue (void) { } @@ -161,7 +166,7 @@ TAO_Constraint_Evaluator::visit_first(TAO_Noop_Constraint* noop_first) int TAO_Constraint_Evaluator:: -visit_and(TAO_Binary_Constraint* boolean_and) +visit_and (TAO_Binary_Constraint* boolean_and) { int return_value = -1; CORBA::Boolean result = (CORBA::Boolean) 0; @@ -624,3 +629,457 @@ sequence_does_contain(CORBA::Any* sequence, return return_value; } + + // ************************************************************* + // TAO_Constraint_Evaluator + // ************************************************************* + +TAO_Constraint_Validator:: +TAO_Constraint_Validator +(CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct) +{ + CosTradingRepos::ServiceTypeRepository::PropStructSeq& prop_seq = + type_struct->props; + int length = prop_seq.length(); + + // Create a map of the service type properties to their types. + for (int i = 0; i < length; i++) + { + CORBA::TypeCode_var corba_type = prop_seq[i].value_type; + TAO_String_Hash_Key prop_name_str = (const char*) prop_seq[i].name; + this->type_map_.bind (prop_name_str, corba_type.ptr ()); + } +} + +int +TAO_Constraint_Validator::validate (TAO_Constraint* root) +{ + return root->accept(this); +} + +int +TAO_Constraint_Validator::visit_constraint(TAO_Unary_Constraint* constraint) +{ + int return_value = -1; + TAO_Expression_Type type; + TAO_Constraint* operand = constraint->operand(); + this->extract_type(operand, type); + + if (this->expr_returns_boolean (type)) + return_value = operand->accept (this); + + return return_value; +} + +int +TAO_Constraint_Validator::visit_first(TAO_Noop_Constraint* noop) +{ + return 0; +} + +int +TAO_Constraint_Validator::visit_random(TAO_Noop_Constraint* noop) +{ + return 0; +} + +int +TAO_Constraint_Validator::visit_with(TAO_Unary_Constraint* unary_with) +{ + return this->visit_constraint(unary_with); +} + +int +TAO_Constraint_Validator::visit_min(TAO_Unary_Constraint* unary_min) +{ + return this->visit_unary_minus(unary_min); +} + +int +TAO_Constraint_Validator::visit_max(TAO_Unary_Constraint* unary_max) +{ + return this->visit_unary_minus(unary_max); +} + +int +TAO_Constraint_Validator:: +visit_and(TAO_Binary_Constraint* boolean_and) +{ + int return_value = -1; + TAO_Constraint* left = boolean_and->left_operand(), + *right = boolean_and->right_operand(); + TAO_Expression_Type left_type, right_type; + this->extract_type(left, left_type); + this->extract_type(right, right_type); + + // Can only "and" expressions that return a boolean value + if (this->expr_returns_boolean(left_type) && + this->expr_returns_boolean(right_type)) + { + if (left->accept(this) == 0 && + right->accept(this) == 0) + return_value = 0; + } + + return return_value; +} + +int +TAO_Constraint_Validator:: +visit_or(TAO_Binary_Constraint* boolean_or) +{ + // The types for or are the same as those for and. + return this->visit_and(boolean_or); +} + +int +TAO_Constraint_Validator:: +visit_not(TAO_Unary_Constraint* unary_not) +{ + int return_value = -1; + // Not can only negate an expression that returns a boolean. + TAO_Expression_Type type; + TAO_Constraint* operand = unary_not->operand(); + this->extract_type(operand, type); + + if (this->expr_returns_boolean(type)) + return_value = operand->accept(this); + + return return_value; +} + +int +TAO_Constraint_Validator:: +visit_exist(TAO_Unary_Constraint* unary_exist) +{ + // Exist simply requires that its operand be a property name + // included in the service type. + int return_value = -1; + TAO_Constraint* operand = unary_exist->operand(); + TAO_Expression_Type type = operand->expr_type(); + + if (type == TAO_IDENT) + return_value = operand->accept(this); + + return return_value; +} + +int +TAO_Constraint_Validator:: +visit_unary_minus(TAO_Unary_Constraint* unary_minus) +{ + // Unary minus can only negate a numeric operand. + int return_value = -1; + TAO_Expression_Type type; + TAO_Constraint* operand = unary_minus->operand(); + this->extract_type(operand, type); + + if (this->expr_returns_number(type)) + return_value = operand->accept(this); + + return return_value; +} + +int +TAO_Constraint_Validator:: +visit_add(TAO_Binary_Constraint* boolean_add) +{ + // All the mathematical operators require numeric operands. + int return_value = -1; + TAO_Constraint* left = boolean_add->left_operand(), + *right = boolean_add->right_operand(); + TAO_Expression_Type left_type, right_type; + this->extract_type(left, left_type); + this->extract_type(right, right_type); + + if (this->expr_returns_number(left_type) && + this->expr_returns_number(right_type)) + { + if (left->accept(this) == 0 && + right->accept(this) == 0) + return_value = 0; + } + + return return_value; +} + +int +TAO_Constraint_Validator:: +visit_sub(TAO_Binary_Constraint* boolean_sub) +{ + return this->visit_add(boolean_sub); +} + +int +TAO_Constraint_Validator:: +visit_mult(TAO_Binary_Constraint* boolean_mult) +{ + return this->visit_add(boolean_mult); +} + +int +TAO_Constraint_Validator:: +visit_div(TAO_Binary_Constraint* boolean_div) +{ + // Div not only requires that both of its operands be numeric, but + // also the the demoninator not be zero. However, since the + // denominator can be an expression who's value can only be + // determined while evaulating the constraint expression, this + // method detects only when the demoniator is a literal whose value + // is zero. + int return_value = -1; + TAO_Constraint* left = boolean_div->left_operand(), + *right = boolean_div->right_operand(); + TAO_Expression_Type left_type, right_type; + this->extract_type(left, left_type); + this->extract_type(right, right_type); + + if (this->expr_returns_number(left_type) && + this->expr_returns_number(right_type)) + { + // Prevent division by zero, a no no. + int right_isnt_zero = 1; + switch(right->expr_type()) + { + case TAO_UNSIGNED: + right_isnt_zero = + ((CORBA::ULong) (*((TAO_Literal_Constraint*) right)) != 0); + break; + case TAO_SIGNED: + right_isnt_zero = + ((CORBA::Long) (*((TAO_Literal_Constraint*) right)) != 0); + break; + case TAO_DOUBLE: + right_isnt_zero = + ((CORBA::Double) (*((TAO_Literal_Constraint*) right)) != 0.0); + break; + } + + if (right_isnt_zero) + { + if (left->accept(this) == 0 && + right->accept(this) == 0) + return_value = 0; + } + } + + return return_value; +} + +int +TAO_Constraint_Validator:: +visit_twiddle(TAO_Binary_Constraint* binary_twiddle) +{ + // Twiddle requires that both of its operand be strings. + int return_value = -1; + TAO_Constraint* left = binary_twiddle->left_operand(), + *right = binary_twiddle->right_operand(); + TAO_Expression_Type left_type, right_type; + this->extract_type(left, left_type); + this->extract_type(right, right_type); + + if (this->expr_returns_string(left_type) && + this->expr_returns_string(right_type)) + { + if (left->accept(this) == 0 && + right->accept(this) == 0) + return_value = 0; + } + + return return_value; +} + +int +TAO_Constraint_Validator:: +visit_in (TAO_Binary_Constraint* binary_in) +{ + // In requires that the right operand be a sequence of a simple type + // and that its left operand be an expression that evaluates to a + // value of the same simple type. + int return_value = -1; + TAO_Constraint* left = binary_in->left_operand(), + *right = binary_in->right_operand(); + TAO_Expression_Type left_type, right_type; + CORBA::TypeCode* prop_type = this->extract_type(right, right_type); + this->extract_type(left, left_type); + + if (right_type == TAO_SEQUENCE) + { + int types_match = 0; + CORBA::Environment env; + + if (this->expr_returns_number (left_type)) + { + types_match = + prop_type->equal (TAO_Sequences::_tc_ShortSeq, env) || + prop_type->equal (TAO_Sequences::_tc_UShortSeq, env) || + prop_type->equal (TAO_Sequences::_tc_LongSeq, env) || + prop_type->equal (TAO_Sequences::_tc_ULongSeq, env) || + prop_type->equal (TAO_Sequences::_tc_DoubleSeq, env) || + prop_type->equal (TAO_Sequences::_tc_FloatSeq, env); + } + else if (this->expr_returns_boolean (left_type)) + types_match = prop_type->equal (TAO_Sequences::_tc_BooleanSeq, env); + else if (this->expr_returns_string (left_type)) + types_match = prop_type->equal (TAO_Sequences::_tc_StringSeq, env); + + if (types_match) + return_value = left->accept(this); + } + + return return_value; +} + +int +TAO_Constraint_Validator:: +visit_less_than(TAO_Binary_Constraint* boolean_lt) +{ + // Comparison operations require that both operands be of the same + // simple type. + int return_value = -1; + TAO_Constraint* left = boolean_lt->left_operand(), + *right = boolean_lt->right_operand(); + TAO_Expression_Type left_type, right_type; + this->extract_type(left, left_type); + this->extract_type(right, right_type); + + if ((this->expr_returns_number(left_type) && + this->expr_returns_number(right_type)) || + (this->expr_returns_string(left_type) && + this->expr_returns_string(right_type))) + { + if (left->accept(this) == 0 && + right->accept(this) == 0) + return_value = 0; + } + + return return_value; +} + +int +TAO_Constraint_Validator:: +visit_less_than_equal(TAO_Binary_Constraint* boolean_lte) +{ + return this->visit_less_than(boolean_lte); +} + +int +TAO_Constraint_Validator:: +visit_greater_than(TAO_Binary_Constraint* boolean_gt) +{ + return this->visit_less_than(boolean_gt); +} + +int +TAO_Constraint_Validator:: +visit_greater_than_equal(TAO_Binary_Constraint* boolean_gte) +{ + return this->visit_less_than(boolean_gte); +} + +int +TAO_Constraint_Validator:: +visit_equal(TAO_Binary_Constraint* boolean_eq) +{ + int return_value = -1; + TAO_Constraint* left = boolean_eq->left_operand(), + *right = boolean_eq->right_operand(); + TAO_Expression_Type left_type, right_type; + this->extract_type(left, left_type); + this->extract_type(right, right_type); + + if ((this->expr_returns_number(left_type) && + this->expr_returns_number(right_type)) || + (this->expr_returns_string(left_type) && + this->expr_returns_string(right_type)) || + (this->expr_returns_boolean(left_type) && + this->expr_returns_boolean(right_type))) + { + if (left->accept(this) == 0 && + right->accept(this) == 0) + return_value = 0; + } + + return return_value; +} + +int +TAO_Constraint_Validator:: +visit_not_equal(TAO_Binary_Constraint* boolean_neq) +{ + return this->visit_equal(boolean_neq); +} + +int +TAO_Constraint_Validator:: +visit_literal(TAO_Literal_Constraint* literal) +{ + return 0; +} + +int +TAO_Constraint_Validator:: +visit_property(TAO_Property_Constraint* literal) +{ + return 0; +} + +CORBA::TypeCode* +TAO_Constraint_Validator::extract_type (TAO_Constraint* expr, + TAO_Expression_Type& type) +{ + CORBA::TypeCode* return_value = 0; + + type = expr->expr_type(); + if (type == TAO_IDENT) + { + TAO_Property_Constraint* prop = (TAO_Property_Constraint*) expr; + TAO_String_Hash_Key prop_name (prop->name()); + + if (this->type_map_.find (prop_name, return_value) == 0) + type = TAO_Literal_Constraint::comparable_type (return_value); + } + + return return_value; +} + +int +TAO_Constraint_Validator::expr_returns_boolean(TAO_Expression_Type expr_type) +{ + // If the expression is a boolean operations, a boolean literal, or + // a boolean property, return 1. + int return_value = 0; + + if (expr_type <= TAO_BOOLEAN) + return_value = 1; + + return return_value; +} + + +int +TAO_Constraint_Validator::expr_returns_number(TAO_Expression_Type expr_type) +{ + // If the expression is a number operation, a numeric literal, or a + // numeric property, return 1. + int return_value = 0; + + if ((expr_type >= TAO_PLUS && expr_type <= TAO_NUMBER) || + (expr_type >= TAO_UNSIGNED && expr_type <= TAO_DOUBLE)) + return_value = 1; + + return return_value; +} + +int +TAO_Constraint_Validator::expr_returns_string(TAO_Expression_Type expr_type) +{ + // If the expression is an operation with a string return value, a + // string literal, or a property whose type is string, return 1. + int return_value = 0; + + if (expr_type == TAO_STRING) + return_value = 1; + + return return_value; +} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Visitors.h b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Visitors.h new file mode 100644 index 00000000000..7f55b832eb4 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Visitors.h @@ -0,0 +1,357 @@ +/* -*- C++ -*- */ + +// ======================================================================== +// $Id$ +// +// = LIBRARY +// orbsvcs +// +// = FILENAME +// Constraint_Visitor.h +// +// = AUTHOR +// Seth Widoff <sbw1@cs.wustl.edu> +// +// ======================================================================== + +#ifndef TAO_CONSTRAINT_VISITOR_H +#define TAO_CONSTRAINT_VISITOR_H + +#include "Trader.h" +#include "Trader_Utils.h" + + // ************************************************************* + // TAO_Constraint_Visitor + // ************************************************************* + +class TAO_Constraint; +class TAO_Unary_Constraint; +class TAO_Binary_Constraint; +class TAO_Literal_Constraint; +class TAO_Property_Constraint; +class TAO_Noop_Constraint; + +class TAO_Constraint_Visitor +// +// = TITLE +// This is the base class for all visitors who wish to preform +// some operation from the state of the expression tree. Using +// double dispatching, subclasses of Constraint expression call +// back to the InterpreterVisitor subclass from the accept method. +// +// = DESCRIPTION +// Traversal of the expression tree uses the "Visitor" pattern. To +// "visit" a node, a client invokes the "accept" method on a +// subclass of ConstraintExpression, which, in turn, invokes the +// appropriate method on the visitor passed to it, based on its +// own type. So, the Constraint_Visitor has a method to deal with +// each possible type of node in an expression tree; one for each +// operator in the grammar. +{ +public: + + virtual int visit_constraint(TAO_Unary_Constraint* constraint) = 0; + + virtual int visit_with(TAO_Unary_Constraint* unary_with) = 0; + virtual int visit_min(TAO_Unary_Constraint* unary_min) = 0; + virtual int visit_max(TAO_Unary_Constraint* unary_max) = 0; + virtual int visit_first(TAO_Noop_Constraint* noop_first) = 0; + virtual int visit_random(TAO_Noop_Constraint* noop_random) = 0; + + virtual int visit_and(TAO_Binary_Constraint* boolean_and) = 0; + virtual int visit_or(TAO_Binary_Constraint* boolean_or) = 0; + virtual int visit_not(TAO_Unary_Constraint* unary_not) = 0; + + virtual int visit_exist(TAO_Unary_Constraint* unary_exist) = 0; + virtual int visit_unary_minus(TAO_Unary_Constraint* unary_minus) = 0; + + virtual int visit_add(TAO_Binary_Constraint* boolean_add) = 0; + virtual int visit_sub(TAO_Binary_Constraint* boolean_sub) = 0; + virtual int visit_mult(TAO_Binary_Constraint* boolean_mult) = 0; + virtual int visit_div(TAO_Binary_Constraint* boolean_div) = 0; + + virtual int visit_twiddle(TAO_Binary_Constraint* binary_twiddle) = 0; + virtual int visit_in(TAO_Binary_Constraint* binary_in) = 0; + + virtual int visit_less_than(TAO_Binary_Constraint* boolean_lt) = 0; + virtual int visit_less_than_equal(TAO_Binary_Constraint* boolean_lte) = 0; + virtual int visit_greater_than(TAO_Binary_Constraint* boolean_gt) = 0; + virtual int visit_greater_than_equal(TAO_Binary_Constraint* boolean_gte) = 0; + virtual int visit_equal(TAO_Binary_Constraint* boolean_eq) = 0; + virtual int visit_not_equal(TAO_Binary_Constraint* boolean_neq) = 0; + + virtual int visit_literal(TAO_Literal_Constraint* literal) = 0; + virtual int visit_property(TAO_Property_Constraint* literal) = 0; +}; + +#include "Constraint_Nodes.h" + + // ************************************************************* + // TAO_Constraint_Evaluator + // ************************************************************* + + +class TAO_Constraint_Evaluator : public TAO_Constraint_Visitor +// +// = TITLE +// TAO_Constraint_Evaluator traverse a constraint expression tree, +// and determines whether an offer fits the constraints +// represented by the tree +// +// = DESCRIPTION +// Using the Visitor pattern, the TAO_Constraint_Evaluator has each +// node of the expression tree call back to it with the method +// designated for its type. In that method, the visitor will +// evaluate its operands and perform the operation designated by +// that node's type, and return the result. Note: the +// EvaluationVisitor assumes the tree is semantically correct, +// that is, the validate method on SemanticValidatorVisitor return +// true. The only possible evaluation time error is a divide by a +// property whose value is zero. +{ +public: + + TAO_Constraint_Evaluator(CosTrading::Offer* offer, + CORBA::Boolean supports_dynamic_properties = 1); + + CORBA::Boolean evaluate_constraint(TAO_Constraint* root); + // Evaluate returns 1 if the offer satisfies the constraints + // represented by the the expression tree rooted at <root>, 0 if it + // doesn't. If an error occurs during process, the constraint + // automatically fails. + + int evaluate_preference(TAO_Constraint* root, + TAO_Literal_Constraint& result); + // The result of the preference evaluation is stored in result. The + // method returns 0 upon success, -1 upon failure. + + // = Visitor Methods + + virtual int visit_constraint(TAO_Unary_Constraint* constraint); + + virtual int visit_with(TAO_Unary_Constraint* unary_with); + virtual int visit_min(TAO_Unary_Constraint* unary_min); + virtual int visit_max(TAO_Unary_Constraint* unary_max); + virtual int visit_first(TAO_Noop_Constraint* noop_first); + virtual int visit_random(TAO_Noop_Constraint* noop_random); + + virtual int visit_and(TAO_Binary_Constraint* boolean_and); + // Takes the logical and of the results of both operands. Note that + // in the case where the left operand returns zero, the result is + // immediately known. + + virtual int visit_or(TAO_Binary_Constraint* boolean_or); + // Takes the logical or of the results of both operands. Note that + // in the case where the left operand returns one, the result is + // immediately known. + + virtual int visit_not(TAO_Unary_Constraint* unary_not); + // Logically negates the value of the operand. + + virtual int visit_exist(TAO_Unary_Constraint* unary_exist); + // The property exists if its name is bound to a value in the + // <props_> map. + + virtual int visit_unary_minus(TAO_Unary_Constraint* unary_minus); + // Mathematically negates the return value the operand. + + virtual int visit_add(TAO_Binary_Constraint* boolean_add); + // Add the results of evaluating the left and right operands. + + virtual int visit_sub(TAO_Binary_Constraint* boolean_sub); + // Subtract the results of evaluating the left and right operands. + + virtual int visit_mult(TAO_Binary_Constraint* boolean_mult); + // Multiply the results of evaluating the left and right operands. + + virtual int visit_div(TAO_Binary_Constraint* boolean_div); + // Divide the results of evaluating the left and right operands. + + virtual int visit_twiddle(TAO_Binary_Constraint* binary_twiddle); + // Determines if the right operand is a substring of the left. + + virtual int visit_in(TAO_Binary_Constraint* binary_in); + // Determines if the sequence represented by the right operand + // contains the left operand. + + // = Compare the results of evaluating left and right operands. + virtual int visit_less_than(TAO_Binary_Constraint* boolean_lt); + virtual int visit_less_than_equal(TAO_Binary_Constraint* boolean_lte); + virtual int visit_greater_than(TAO_Binary_Constraint* boolean_gt); + virtual int visit_greater_than_equal(TAO_Binary_Constraint* boolean_gte); + virtual int visit_equal(TAO_Binary_Constraint* boolean_eq); + virtual int visit_not_equal(TAO_Binary_Constraint* boolean_neq); + + virtual int visit_literal(TAO_Literal_Constraint* literal); + // Copy the value of the literal into the result container. + + virtual int visit_property(TAO_Property_Constraint* literal); + // Copy the value of the property into the result container. + +private: + + class Operand_Queue : + public ACE_Unbounded_Queue <TAO_Literal_Constraint> + { + public: + + Operand_Queue (void); + + TAO_Literal_Constraint& get_left_operand (void); + + TAO_Literal_Constraint& get_right_operand (void); + + TAO_Literal_Constraint& get_operand (void); + + void dequeue_operand (void); + }; + + typedef ACE_Hash_Map_Manager + < + TAO_String_Hash_Key, + int, + ACE_Null_Mutex + > + Property_Map; + + void do_the_op (int operation); + int visit_bin_op (TAO_Binary_Constraint* op, int operation); + + CORBA::Boolean sequence_does_contain(CORBA::Any* sequence, + TAO_Literal_Constraint& element); + // Determine if sequence contains <element>, a literal of the same + // simple type as <sequence_type>. Return 1 in this eventuality. + + TAO_Literal_Constraint& left_operand(void); + TAO_Literal_Constraint& right_operand(void); + + Property_Map props_; + // The map of property names to their values for a property. + + TAO_Property_Evaluator prop_eval_; + // Utility with which to evaluate the properties of an offer, be + // they dyanmic or static. + + Operand_Queue queue_; + // The result of a non_boolean operation. +}; + +CORBA::Boolean TAO_find_string (TAO_Sequences::StringSeq& sequence, const char* element); + + // ************************************************************* + // TAO_Constraint_Validator + // ************************************************************* + +class TAO_Constraint_Validator : public TAO_Constraint_Visitor + // + // = TITLE + // TAO_Constraint_Validator ensures that in an expression tree + // passed to it, the operands of each operation match the + // correct types. + // + // = DESCRIPTION + // TAO_Constraint_Validator uses the visitor pattern to + // traverse all the nodes in an expression tree, checking each + // for operands of the proper type. The algorithm for type + // checking is as follows: ensure that operand expression(s) + // return the correct types using exprReturns* methods, and their + // types. If they (or it) return the correct types, call accept + // on the operands until all return true, or one returns false, + // at which point we can back out of the traversal. +{ +public: + + TAO_Constraint_Validator + (CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct); + // The constructor creates a map of property names to their values + // from the Type Description retrieved from the + // ServiceTypeRepository. The ServiceTypeRepository throws + // exceptions when it's displeased with the type name provided to + // it. The map allows O(lg n) associative access, rather than the + // O(n) sequential lookup from the CORBA data structures. + + int validate(TAO_Constraint* root); + // Validate returns 1 if the expression tree whose root is <root> + // makes semantic sense, in that the operands for each operation + // comply with each other and the types accepted by the operator. + + // = Visitor Methods + + virtual int visit_constraint(TAO_Unary_Constraint* constraint); + + virtual int visit_with(TAO_Unary_Constraint* unary_with); + virtual int visit_min(TAO_Unary_Constraint* unary_min); + virtual int visit_max(TAO_Unary_Constraint* unary_max); + virtual int visit_first(TAO_Noop_Constraint* noop_first); + virtual int visit_random(TAO_Noop_Constraint* noop_random); + + virtual int visit_and(TAO_Binary_Constraint* boolean_and); + virtual int visit_or(TAO_Binary_Constraint* boolean_or); + // The two operands must return a boolean value. + + virtual int visit_not(TAO_Unary_Constraint* unary_not); + // The operand must return a boolean value. + + virtual int visit_exist(TAO_Unary_Constraint* unary_exist); + // The operand must return a valid (i.e., present in the service + // type description) property name. + + virtual int visit_unary_minus(TAO_Unary_Constraint* unary_minus); + // The operand must return a number to be negated. + + virtual int visit_add(TAO_Binary_Constraint* boolean_add); + virtual int visit_sub(TAO_Binary_Constraint* boolean_sub); + virtual int visit_mult(TAO_Binary_Constraint* boolean_mult); + virtual int visit_div(TAO_Binary_Constraint* boolean_div); + // Both operands must return numeric results. + + virtual int visit_twiddle(TAO_Binary_Constraint* binary_twiddle); + // Both operands must return strings. + + virtual int visit_in(TAO_Binary_Constraint* binary_in); + // The right operand must be a sequence of the same simple type as + // the left operand. + + virtual int visit_less_than(TAO_Binary_Constraint* boolean_lt); + virtual int visit_less_than_equal(TAO_Binary_Constraint* boolean_lte); + virtual int visit_greater_than(TAO_Binary_Constraint* boolean_gt); + virtual int visit_greater_than_equal(TAO_Binary_Constraint* boolean_gte); + virtual int visit_equal(TAO_Binary_Constraint* boolean_eq); + virtual int visit_not_equal(TAO_Binary_Constraint* boolean_neq); + // The left and right operands must both be of the same simple type. + + virtual int visit_literal(TAO_Literal_Constraint* literal); + virtual int visit_property(TAO_Property_Constraint* literal); + // The property must be defined in the service type description. + +private: + + typedef ACE_Hash_Map_Manager + < + TAO_String_Hash_Key, + CORBA::TypeCode_ptr, + ACE_Null_Mutex + > + Property_Type_Map; + + Property_Type_Map type_map_; + // A map gleaned from the ServiceTypeStruct, which correlates + // property names with their types. + + CORBA::TypeCode* extract_type(TAO_Constraint* expr_type, + TAO_Expression_Type& type); + + int expr_returns_boolean(TAO_Expression_Type expr_type); + // expr_returns_boolean returns 1 if <expr_type>, when evaluated, will + // return a boolean. + + int expr_returns_number(TAO_Expression_Type expr_type); + // expr_returns_boolean returns 1 if <expr_type>, when evaluated, will + // return a number. + + int expr_returns_string(TAO_Expression_Type expr_type); + // expr_returns_boolean returns 1 if <expr_type>, when evaluated, will + // return a string. +}; + +#endif /* CONSTRAINT_VISITORS_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_l.cpp b/TAO/orbsvcs/orbsvcs/Trader/Constraint_l.cpp index bbad8cd58ce..4c139e3dbca 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_l.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Constraint_l.cpp @@ -36,15 +36,6 @@ #endif /* __STDC__ */ #endif /* ! __cplusplus */ -#ifdef __TURBOC__ - #pragma warn -rch - #pragma warn -use -#include <io.h> -#include <stdlib.h> -#define YY_USE_CONST -#define YY_USE_PROTOS -#endif - #ifdef YY_USE_CONST #define yyconst const #else @@ -427,7 +418,7 @@ char *yytext; // // ======================================================================== -#include "Constraint.h" +#include "Constraint_Interpreter.h" #include "Constraint_Nodes.h" #include "Constraint_Tokens.h" @@ -436,7 +427,7 @@ static TAO_Literal_Constraint* extract_string(const char*); #define TAO_YY_LEX_DEBUG #ifdef TAO_CONSTRAINT_DEBUG -#define TAO_YY_LEX_DEBUG TAO_OS::fprintf(stderr, "%s\n", yytext) +#define TAO_YY_LEX_DEBUG ACE_OS::fprintf(stderr, "%s\n", yytext) #endif /* TAO_CONSTRAINT_DEBUG */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_y.cpp b/TAO/orbsvcs/orbsvcs/Trader/Constraint_y.cpp index db03a65df31..08778372140 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_y.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Constraint_y.cpp @@ -14,7 +14,8 @@ // // ======================================================================== -#include "Constraint.h" +#include "ace/OS.h" +#include "Constraint_Interpreter.h" #include "Constraint_Nodes.h" //#define YYDEBUG 1 @@ -53,14 +54,6 @@ # define TAO_FIRST 289 # define TAO_RANDOM 290 -#ifdef __STDC__ -#include <stdlib.h> -#include <string.h> -#else -#include <malloc.h> -#include <memory.h> -#endif - #ifdef __cplusplus #ifndef yyerror diff --git a/TAO/orbsvcs/orbsvcs/Trader/Interpreter.cpp b/TAO/orbsvcs/orbsvcs/Trader/Interpreter.cpp deleted file mode 100644 index 07afac4ce3f..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Interpreter.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// $Id$ - -#include "Interpreter.h" - -TAO_Interpreter::~TAO_Interpreter (void) -{ - delete root_; -} - -int -TAO_Interpreter::build_tree(const char* constraints) -{ - TAO_Lex_String_Input::reset((char*)constraints); - int return_value = 0; - - yyval.constraint_ = 0; - return_value = ::yyparse(); - - if (return_value == 0 && yyval.constraint_ != 0) - this->root_ = yyval.constraint_; - else - { - while (yylex() > 0) - ; - this->root_ = 0; - } - - return return_value; -} - - -int -TAO_Interpreter::is_empty_string(const char* str) -{ - int return_value = 0; - - if (str != 0) - { - int i = 0; - while (str[i] != '\0') - { - if (str[i] != ' ') - break; - - i++; - } - - if (str[i] == '\0') - return_value = 1; - } - - return return_value; -} - diff --git a/TAO/orbsvcs/orbsvcs/Trader/Interpreter.h b/TAO/orbsvcs/orbsvcs/Trader/Interpreter.h deleted file mode 100644 index 08dee14637a..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Interpreter.h +++ /dev/null @@ -1,45 +0,0 @@ -// ============================================================================ -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Interpreter.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ============================================================================ - - -#ifndef TAO_INTERPRETER_H -#define TAO_INTERPRETER_H - -#include "Constraint.h" -#include "Constraint_Nodes.h" - -class TAO_Interpreter -// = TITLE -// TAO_Interpreter is the superclass for all interpreters. It's -// build tree method invoke the yacc parser to parse a constraint -// or preference string. -{ -protected: - - TAO_Interpreter (void) : root_ (0) {} - - ~TAO_Interpreter (void); - - int build_tree (const char* preferences); - // Using the Yacc generated parser, construct an expression - // tree representing <constraints> from the tokens returned by it. - - static int is_empty_string (const char* str); - - TAO_Constraint* root_; - // The root of the expression tree, not equal to null if build_tree - // successfully builds a tree from the constraints. -}; - -#endif /* TAO_Interpreter */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Link.cpp b/TAO/orbsvcs/orbsvcs/Trader/Link.cpp deleted file mode 100644 index e61b340a696..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Link.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Link.cpp -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#if !defined (TAO_LINK_C) -#define TAO_LINK_C - -#include "Link.h" -#include "Locking.h" -#include "Trader.h" - -template <class TRADER, class MAP_LOCK_TYPE> -TAO_Link<TRADER,MAP_LOCK_TYPE>::TAO_Link (TRADER &trader) - : trader_ (trader), - TAO_Trader_Components <POA_CosTrading::Link> (trader.trading_components ()), - TAO_Link_Attributes <POA_CosTrading::Link> (trader.link_attributes ()), - TAO_Support_Attributes <POA_CosTrading::Link> (trader.support_attributes ()) -{ -} - -template <class TRADER, class MAP_LOCK_TYPE> -TAO_Link<TRADER,MAP_LOCK_TYPE>::~TAO_Link (void) -{ -} - -template <class TRADER, class MAP_LOCK_TYPE> void -TAO_Link<TRADER, MAP_LOCK_TYPE>:: -add_link (const char *name, - CosTrading::Lookup_ptr target, - CosTrading::FollowOption def_pass_on_follow_rule, - CosTrading::FollowOption limiting_follow_rule, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Link::IllegalLinkName, - CosTrading::Link::DuplicateLinkName, - CosTrading::InvalidLookupRef, - CosTrading::Link::DefaultFollowTooPermissive, - CosTrading::Link::LimitingFollowTooPermissive)) -{ - // Ensure the link name is valid. - if (! TAO_Trader_Base::is_valid_identifier_name (name)) - TAO_THROW (CosTrading::Link::IllegalLinkName (name)); - - // Ensure this isn't a duplicate link name. - TAO_String_Hash_Key link_name (name); - if (this->links_.find (link_name) == -1) - TAO_THROW (CosTrading::Link::DuplicateLinkName (name)); - - // Ensure the lookup_ptr isn't nil. - if (target == CosTrading::Lookup::_nil()) - TAO_THROW (CosTrading::InvalidLookupRef (target)); - - // Ensure that the default link behavior isn't stronger than the - // limiting link behavior. - if (def_pass_on_follow_rule > limiting_follow_rule) - TAO_THROW (CosTrading::Link::DefaultFollowTooPermissive - (def_pass_on_follow_rule, limiting_follow_rule)); - - // Ensure that the limiting link behavior for this link doesn't - // exceed the maximum allowed for a link. - if (limiting_follow_rule < this->max_link_follow_policy (_env)) - TAO_THROW (CosTrading::Link::LimitingFollowTooPermissive - (limiting_follow_rule, this->max_link_follow_policy (_env))); - - // Create a link info structure for this link of the federation. - CosTrading::Link::LinkInfo link_info; - link_info.target = target; - link_info.target_reg = target->register_if (_env); - link_info.def_pass_on_follow_rule = def_pass_on_follow_rule; - link_info.limiting_follow_rule = limiting_follow_rule; - TAO_CHECK_ENV_RETURN_VOID (_env); - - // Insert this link into the collection of links. - this->links_.bind (link_name, link_info); -} - -template <class TRADER, class MAP_LOCK_TYPE> void -TAO_Link<TRADER,MAP_LOCK_TYPE>::remove_link (const char *name, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Link::IllegalLinkName, - CosTrading::Link::UnknownLinkName)) -{ - // Ensure the link name is valid. - if (! TAO_Trader_Base::is_valid_identifier_name (name)) - TAO_THROW (CosTrading::Link::IllegalLinkName (name)); - - // Ensure this isn't a duplicate link name. - TAO_String_Hash_Key link_name (name); - if (this->links_.find (link_name) == -1) - TAO_THROW (CosTrading::Link::UnknownLinkName (name)); - - // Erase the link state from the map. - this->links_.unbind (link_name); -} - -template <class TRADER, class MAP_LOCK_TYPE> CosTrading::Link::LinkInfo * -TAO_Link<TRADER,MAP_LOCK_TYPE>::describe_link (const char *name, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::SystemException, - CosTrading::Link::IllegalLinkName, - CosTrading::Link::UnknownLinkName)) -{ - // Ensure the link name is valid. - if (! TAO_Trader_Base::is_valid_identifier_name (name)) - TAO_THROW_RETURN (CosTrading::Link::IllegalLinkName (name), 0); - - // Ensure this isn't a duplicate link name. - Links::ENTRY* link_entry; - TAO_String_Hash_Key link_name (name); - if (this->links_.find (link_name, link_entry) == -1) - TAO_THROW_RETURN (CosTrading::Link::UnknownLinkName (name), 0); - - // return the link infor for this link name. - return &(link_entry->int_id_); -} - -template <class TRADER, class MAP_LOCK_TYPE> CosTrading::LinkNameSeq* -TAO_Link<TRADER,MAP_LOCK_TYPE>::list_links (CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - // Allocate space for the link names. - CORBA::ULong size = this->links_.current_size (), i = 0; - CosTrading::LinkName* link_seq = - CosTrading::LinkNameSeq::allocbuf (size); - - // Copy the link names into the buffer. - for (Links::iterator links_iter (this->links_); - ! links_iter.done (); - links_iter++) - link_seq[i++] = CORBA::string_dup ((*links_iter).ext_id_.in ()); - - // Return a sequence of the buf names. - return new CosTrading::LinkNameSeq (i, i, link_seq, CORBA::B_TRUE); -} - -template <class TRADER, class MAP_LOCK_TYPE> void -TAO_Link<TRADER,MAP_LOCK_TYPE>:: -modify_link (const char *name, - CosTrading::FollowOption def_pass_on_follow_rule, - CosTrading::FollowOption limiting_follow_rule, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Link::IllegalLinkName, - CosTrading::Link::UnknownLinkName, - CosTrading::Link::DefaultFollowTooPermissive, - CosTrading::Link::LimitingFollowTooPermissive)) -{ - // Ensure the link name is valid. - if (! TAO_Trader_Base::is_valid_identifier_name (name)) - TAO_THROW (CosTrading::Link::IllegalLinkName (name)); - - // Ensure this isn't a duplicate link name. - Links::ENTRY* link_entry = 0; - TAO_String_Hash_Key link_name (name); - if (this->links_.find (link_name, link_entry) == -1) - TAO_THROW (CosTrading::Link::UnknownLinkName (name)); - - // Ensure that the default link behavior isn't stronger than the - // limiting link behavior. - if (def_pass_on_follow_rule > limiting_follow_rule) - TAO_THROW (CosTrading::Link::DefaultFollowTooPermissive - (def_pass_on_follow_rule, limiting_follow_rule)); - - // Ensure that the limiting link behavior for this link doesn't - // exceed the maximum allowed for a link. - if (limiting_follow_rule < this->max_link_follow_policy (_env)) - TAO_THROW (CosTrading::Link::LimitingFollowTooPermissive - (limiting_follow_rule, this->max_link_follow_policy (_env))); - - // Adjust the link settings - CosTrading::Link::LinkInfo& link_info = link_entry->int_id_; - link_info.def_pass_on_follow_rule = def_pass_on_follow_rule; - link_info.limiting_follow_rule = limiting_follow_rule; -} - -#endif /* TAO_LINK_C */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Link.h b/TAO/orbsvcs/orbsvcs/Trader/Link.h deleted file mode 100644 index 329e96567e8..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Link.h +++ /dev/null @@ -1,198 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Link.h -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu>, -// Irfan Pyarali <irfan@cs.wustl.edu>, -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_LINK_H -#define TAO_LINK_H - -#include "Attributes_T.h" -#include "Trader.h" - -template <class TRADER, class MAP_LOCK_TYPE> -class TAO_Link : - public TAO_Trader_Components <POA_CosTrading::Link>, - public TAO_Support_Attributes <POA_CosTrading::Link>, - public TAO_Link_Attributes <POA_CosTrading::Link> -{ -public: - - TAO_Link (TRADER &trader); - - ~TAO_Link (void); - - virtual void add_link (const char *name, - CosTrading::Lookup_ptr target, - CosTrading::FollowOption def_pass_on_follow_rule, - CosTrading::FollowOption limiting_follow_rule, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Link::IllegalLinkName, - CosTrading::Link::DuplicateLinkName, - CosTrading::InvalidLookupRef, - CosTrading::Link::DefaultFollowTooPermissive, - CosTrading::Link::LimitingFollowTooPermissive)); - // BEGIN SPEC - // The add_link operation allows a trader subsequently to use the - // service of another trader in the performance of its own trading - // service operations. - - // The "name" parameter is used in subsequent link management - // operations to identify the intended link. If the parameter is not - // legally formed, then the IllegalLinkName exception is raised. An - // exception of DuplicateLinkName is raised if the link name already - // exists. The link name is also used as a component in a sequence - // of name components in naming a trader for resolving or forwarding - // operations. The sequence of context relative link names provides - // a path to a trader. - - // The "target" parameter identifies the Lookup interface at which - // the trading service provided by the target trader can be - // accessed. Should the Lookup interface parameter be nil, then an - // exception of InvalidLookupRef is raised. The target interface is - // used to obtain the associated Register interface, which will be - // subsequently returned as part of a describe_link operation and - // invoked as part of a resolve operation. - - // The "def_pass_on_follow_rule" parameter specifies the default - // link behavior for the link if no link behavior is specified on an - // importer's query request. If the "def_pass_on_follow_rule" - // exceeds the "limiting_follow_rule" specified in the next - // parameter, then a DefaultFollowTooPermissive exception is - // raised. - - // The "limiting_follow_rule" parameter specifies the most - // permissive link follow behavior that the link is willing to - // tolerate. The exception LimitingFollowTooPermissive is raised if - // this parameter exceeds the trader's attribute of - // "max_link_follow_policy" at the time of the link's creation. Note - // it is possible for a link's "limiting_follow_rule" to exceed the - // trader's "max_link_follow_policy" later in the life of a link, as - // it is possible that the trader could set its - // "max_link_follow_policy" to a more restrictive value after the - // creation of the link. - // END SPEC - - virtual void remove_link (const char *name, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Link::IllegalLinkName, - CosTrading::Link::UnknownLinkName)); - - // BEGIN SPEC - // The remove_link operation removes all knowledge of the target - // trader. The target trader cannot be used subsequently to resolve, - // forward, or propagate trading operations from this trader. - - // The "name" parameter identifies the link to be removed. The - // exception IllegalLinkName is raised if the link is formed poorly - // and the UnknownLinkName exception is raised if the named link is - // not in the trader. - // END SPEC - - virtual CosTrading::Link::LinkInfo* describe_link (const char *name, - CORBA::Environment&) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Link::IllegalLinkName, - CosTrading::Link::UnknownLinkName)); - - // BEGIN SPEC - // The describe_link operation returns information on a link held in - // the trader. - - // The "name" parameter identifies the link whose description is - // required. For a malformed link name, the exception - // IllegalLinkName is raised. An UnknownLinkName exception is raised - // if the named link is not found in the trader. - - // The operation returns a LinkInfo structure comprising: ° the - // Lookup interface of the target trading service, ° the Register - // interface of the target trading service, and ° the default, as - // well as the limiting follow behavior of the named link. - - // If the target service does not support the Register interface, - // then that field of the LinkInfo structure is nil. Given the - // description of the Register::resolve() operation in "Resolve - // Operation" on page 16-45, most implementations will opt for - // determining the Register interface when add_link is called and - // storing that information statically with the rest of the link - // state. - // END SPEC - - virtual CosTrading::LinkNameSeq* list_links (CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)); - - // BEGIN SPEC - // The list_links operation returns a list of the names of all - // trading links within the trader. The names can be used - // subsequently for other management operations, such as - // describe_link or remove_link. - // END SPEC - - virtual void modify_link (const char *name, - CosTrading::FollowOption def_pass_on_follow_rule, - CosTrading::FollowOption limiting_follow_rule, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Link::IllegalLinkName, - CosTrading::Link::UnknownLinkName, - CosTrading::Link::DefaultFollowTooPermissive, - CosTrading::Link::LimitingFollowTooPermissive)); - - // BEGIN SPEC - // The modify_link operation is used to change the existing link - // follow behaviors of an identified link. The Lookup interface - // reference of the target trader and the name of the link cannot be - // changed. - - // The "name" parameter identifies the link whose follow behaviors - // are to be changed. A poorly formed "name" raises the - // IllegalLinkName exception. An UnknownLinkName exception is raised - // if the link name is not known to the trader. - - // The "def_pass_on_follow_rule" parameter specifies the new default - // link behavior for this link. If the "def_pass_on_follow_rule" - // exceeds the "limiting_follow_rule" specified in the next - // parameter, then a DefaultFollowTooPermissive exception is - // raised. - - // The "limiting_follow_rule" parameter specifies the new limit for - // the follow behavior of this link. The exception - // LimitingFollowTooPermissive is raised if the value exceeds the - // current "max_link_follow_policy" of the trader. - // END SPEC - -private: - - typedef ACE_Hash_Map_Manager - < - TAO_String_Hash_Key, - CosTrading::Link::LinkInfo, - MAP_LOCK_TYPE - > - Links; - - Links links_; - // The collection of link connecting this trader to others in the - // federation. - - TRADER &trader_; -}; - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Link.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#endif /* TAO_LINK_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Lookup.cpp b/TAO/orbsvcs/orbsvcs/Trader/Lookup.cpp deleted file mode 100644 index d6c8f69cb7d..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Lookup.cpp +++ /dev/null @@ -1,752 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Lookup.cpp -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#if !defined (TAO_LOOKUP_C) -#define TAO_LOOKUP_C - -#include "Lookup.h" - -#include "Query_Only_Offer_Iterator.h" -#include "Register_Offer_Iterator.h" -#include "Offer_Iterator_Collection.h" - -template <class TRADER> -TAO_Lookup<TRADER>::TAO_Lookup (TRADER &trader) - : trader_ (trader), - TAO_Trader_Components<POA_CosTrading::Lookup> (trader.trading_components ()), - TAO_Support_Attributes<POA_CosTrading::Lookup> (trader.support_attributes ()), - TAO_Import_Attributes<POA_CosTrading::Lookup> (trader.import_attributes ()) -{ -} - -template <class TRADER> -TAO_Lookup<TRADER>::~TAO_Lookup (void) -{ -} - -template <class TRADER> void -TAO_Lookup<TRADER>:: -query (const char *type, - const char *constraint, - const char *preferences, - const CosTrading::PolicySeq &in_policies, - const CosTrading::Lookup::SpecifiedProps &desired_props, - CORBA::ULong how_many, - CosTrading::OfferSeq_out returned_offers, - CosTrading::OfferIterator_out returned_offer_iterator, - CosTrading::PolicyNameSeq_out returned_limits_applied, - CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::IllegalConstraint, - CosTrading::Lookup::IllegalPreference, - CosTrading::Lookup::IllegalPolicyName, - CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue, - CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName, - CosTrading::DuplicatePolicyName)) -{ - // Initializing out parameters - returned_offers = new CosTrading::OfferSeq; - returned_offer_iterator = CosTrading::OfferIterator::_nil (); - returned_limits_applied = new CosTrading::PolicyNameSeq; - - // Get service type map - Service_Type_Map& service_type_map = this->trader_.service_type_map (); - - TAO_Policies policies (this->trader_, in_policies, env); - TAO_CHECK_ENV_RETURN_VOID (env); - - // If the importer has specified a starting trader, foward the - // query. - CosTrading::TraderName* trader_name = policies.starting_trader (env); - TAO_CHECK_ENV_RETURN_VOID (env); - - if (trader_name != 0) - { - CosTrading::TraderName_var starting_trader (trader_name); - this->forward_query (starting_trader.in (), - type, - constraint, - preferences, - policies, - desired_props, - how_many, - returned_offers, - returned_offer_iterator, - returned_limits_applied, - env); - return; - } - - // If a federated query returns to us, ignore it to prevent - // redundant results. - if (this->duplicate_stem_id (policies, env)) - return; - - // If the type is invalid or unknown, let us know now. - const TAO_Support_Attributes_Impl& support_attrs = - this->trader_.support_attributes (); - CosTrading::TypeRepository_ptr type_repos = - support_attrs.type_repos (); - CosTradingRepos::ServiceTypeRepository_ptr rep = - CosTradingRepos::ServiceTypeRepository::_narrow (type_repos, env); - TAO_CHECK_ENV_RETURN_VOID (env); - - // If type is not found, there is nothing to consider - return. - // Else we found the service type....proceed with lookup. - // We will store the matched offers in here. - Offer_Queue ordered_offers; - - // Perform the lookup, placing the ordered results in ordered_offers. - this->perform_lookup (type, - constraint, - preferences, - service_type_map, - rep, - policies, - ordered_offers, - returned_limits_applied, - env); - TAO_CHECK_ENV_RETURN_VOID (env); - - // Fill the return sequence and iterator with the bountiful results. - CORBA::ULong offers_returned = - this->fill_receptacles (type, - ordered_offers, - how_many, - desired_props, - returned_offers, - returned_offer_iterator, - env); - TAO_CHECK_ENV_RETURN_VOID (env); - - // Determine if we should perform a federated query, and if so - // construct a sequence of links to follow. - CosTrading::LinkNameSeq* links = 0; - CORBA::Boolean should_follow = - this->retrieve_links (policies, - offers_returned, - CosTrading::LinkNameSeq_out (links), - env); - TAO_CHECK_ENV_RETURN_VOID (env); - - if (should_follow && links != 0) - { - // Perform the sequence of fedrated queries. - CosTrading::LinkNameSeq_var links_to_follow (links); - this->federated_query (*links, - type, - constraint, - preferences, - policies, - desired_props, - how_many - returned_offers->length (), - returned_offers, - returned_offer_iterator, - returned_limits_applied, - env); - } - TAO_CHECK_ENV_RETURN_VOID (env); -} - -template <class TRADER> void -TAO_Lookup<TRADER>:: -perform_lookup (const char* type, - const char* constraint, - const char* preferences, - Service_Type_Map& service_type_map, - CosTradingRepos::ServiceTypeRepository_ptr rep, - TAO_Policies& policies, - Offer_Queue& ordered_offers, - CosTrading::PolicyNameSeq_out returned_limits_applied, - CORBA::Environment& env) - TAO_THROW_SPEC ((CosTrading::IllegalConstraint, - CosTrading::Lookup::IllegalPreference, - CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType)) -{ - // TAO_Offer_Filter -- ensures that we don't consider offers with - // modifiable or dynamic properties if the Trader doesn't support - // them, or the importer has turned them off using policies. - // TAO_Constraint_Validator -- validates the constraint with the - // property types in the supplied type. - // TAO_Constraint_Interpreter -- parses the constraint string, and - // determines whether an offer meets those constraints. - // TAO_Preference_Interpreter -- parses the preference string and - // orders offers according to those constraints. - CosTradingRepos::ServiceTypeRepository::TypeStruct_var - type_struct (rep->fully_describe_type (type, env)); - TAO_CHECK_ENV_RETURN_VOID (env); - TAO_Offer_Filter offer_filter (type_struct.ptr (), policies, env); - TAO_CHECK_ENV_RETURN_VOID (env); - TAO_Constraint_Validator validator (type_struct.ptr ()); - TAO_Constraint_Interpreter constr_inter (validator, constraint, env); - TAO_CHECK_ENV_RETURN_VOID (env); - TAO_Preference_Interpreter pref_inter (validator, preferences, env); - TAO_CHECK_ENV_RETURN_VOID (env); - CORBA::ULong return_card = policies.return_card (env); - TAO_CHECK_ENV_RETURN_VOID (env); - - // Try to find the map of offers of desired service type. - this->lookup_one_type (type, - service_type_map, - constr_inter, - pref_inter, - offer_filter); - - // If the importer hasn't demanded an exact match search, we search - // all the subtypes of the supplied type. NOTE: Only the properties - // belonging to the provided type are considered on - // subtypes. Additional properties on the subtype are generally - // ignored. This is as it should be, consistent with the notions of - // type inheritence. - if (! policies.exact_type_match (env)) - { - TAO_CHECK_ENV_RETURN_VOID (env); - this->lookup_all_subtypes (type, - type_struct->incarnation, - service_type_map, - rep, - constr_inter, - pref_inter, - offer_filter); - } - TAO_CHECK_ENV_RETURN_VOID (env); - - // Pull the matched offers out of the pref_inter in order, and stick - // them in a queue. The offers in the queue will be emptied into - // the return sequence and iterator for later purusal by the - // importer. Only prepare for the importer no more offers than the - // return cardinality default or policy allows. - CORBA::ULong num_offers = pref_inter.num_offers (); - for (CORBA::ULong i = 0; i < num_offers && i < return_card; i++) - { - CosTrading::Offer* offer; - CosTrading::OfferId offer_id; - if (pref_inter.remove_offer (offer_id, offer) == 0) - { - Offer_Info offer_info; - offer_info.offer_id_ = offer_id; - offer_info.offer_ptr_ = offer; - ordered_offers.enqueue_tail (offer_info); - } - else - break; - } - - // Take note of the limits applied in this query. - returned_limits_applied = offer_filter.limits_applied (); -} - -template <class TRADER> void -TAO_Lookup<TRADER>:: -lookup_one_type (const char* type, - Service_Type_Map& service_type_map, - TAO_Constraint_Interpreter& constr_inter, - TAO_Preference_Interpreter& pref_inter, - TAO_Offer_Filter& offer_filter) -{ - ACE_DEBUG ((LM_DEBUG, "TAO_Lookup: Performing query for %s\n", type)); - - // Retrieve an iterator over the offers for a given type. - Service_Type_Map::offer_iterator offer_iter (type, service_type_map); - - while (offer_filter.ok_to_consider_more () && - offer_iter.has_more_offers ()) - { - // For each offer in the iterator, attempt to match it with - // the constraints passed to the Query method. If it matches - // the constraint, use the TAO_Preference_Interpreter to - // order the matched offers with respect to the preference - // string passed to the method. All the while the offer - // iterator ensures we don't exceed the match cardinality - // constraints. - CosTrading::Offer* offer = offer_iter.get_offer (); - - TAO_Constraint_Evaluator evaluator (offer); - if (offer_filter.ok_to_consider (offer) && - constr_inter.evaluate (evaluator)) - { - // Shove the offer and its id into the preference - // ordering object, pref_inter. - CosTrading::OfferId offer_id = offer_iter.get_id (); - pref_inter.order_offer (offer_id, offer, evaluator); - offer_filter.matched_offer (); - } - - offer_iter.next_offer (); - } -} - -template <class TRADER> void -TAO_Lookup<TRADER>:: -lookup_all_subtypes (const char* type, - CosTradingRepos::ServiceTypeRepository::IncarnationNumber& inc_num, - Service_Type_Map& service_type_map, - CosTradingRepos::ServiceTypeRepository_ptr rep, - TAO_Constraint_Interpreter& constr_inter, - TAO_Preference_Interpreter& pref_inter, - TAO_Offer_Filter& offer_filter) -{ - // BEGIN SPEC - // The trader may return a service offer of a subtype of the "type" - // requested. Sub-typing of service types is discussed in "Service - // Types" on page 16-4. A service subtype can be described by the - // properties of its supertypes. This ensures that a well-formed query - // for the "type" is also a well-formed query with respect to any - // subtypes. However, if the importer specifies the policy of - // exact_type_match = TRUE, then only offers with the exact (no - // subtype) service type requested are returned. - // END SPEC - - CosTradingRepos::ServiceTypeRepository::SpecifiedServiceTypes sst; - CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq_var all_types; - - // Optimization: Since a subtype can't have a higher incarnation - // number than a supertype, we don't need to consider those - // types with lower incarnation numbers. - sst._d (CosTradingRepos::ServiceTypeRepository::since); - sst.incarnation (inc_num); - - // TAO_TRY - // { - CORBA::Environment env; - all_types = rep->list_types (sst, env); - // TAO_CHECK_ENV; - // } - // TAO_CATCHANY { return; } - // TAO_ENDTRY; - - // Scan all types inserted after the super types. If the transitive - // closure of a type's super type relation includes the super type - // being considered, then perform a search on that type. - CORBA::ULong num_types = all_types->length (); - for (CORBA::ULong i = 0; - i < num_types && offer_filter.ok_to_consider_more (); - i++) - { - CosTradingRepos::ServiceTypeRepository::TypeStruct_var type_struct; - - TAO_TRY - { - // Obtain a description of the prospective type. - type_struct = rep->fully_describe_type (all_types[i], TAO_TRY_ENV); - TAO_CHECK_ENV; - } - TAO_CATCHANY - { - break; - } - TAO_ENDTRY; - - CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq& - super_types = type_struct->super_types; - CORBA::ULong num_super_types = super_types.length (); - - for (CORBA::ULong j = 0; j < num_super_types; j++) - { - if (ACE_OS::strcmp (type_struct->super_types[j], type) == 0) - { - // Egads, a subtype! - this->lookup_one_type (all_types[i], - service_type_map, - constr_inter, - pref_inter, - offer_filter); - break; - } - } - } -} - - -template <class TRADER> int -TAO_Lookup<TRADER>:: -fill_receptacles (const char* type, - Offer_Queue& ordered_offers, - CORBA::ULong how_many, - const CosTrading::Lookup::SpecifiedProps& desired_props, - CosTrading::OfferSeq*& offers, - CosTrading::OfferIterator_ptr& offer_itr, - CORBA::Environment& env) - TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName)) -{ - // BEGIN SPEC - // The returned offers are passed back in one of two ways (or a - // combination of both). ° The "offers" return result conveys a list - // of offers and the "offer_itr" is a reference to an interface at - // which offers can be obtained. ° The "how_many" parameter states - // how many offers are to be returned via the "offers" result, any - // remaining offers are available via the iterator interface. If the - // "how_many" exceeds the number of offers to be returned, then the - // "offer_itr" will be nil. - // END SPEC - - // Ordered offers iterator. - Offer_Queue::ITERATOR ordered_offers_iterator (ordered_offers); - TAO_Property_Filter prop_filter (desired_props, env); - TAO_CHECK_ENV_RETURN (env, 0); - - // RETURNING: Calculate how many offers go into the sequence - // Calculate how many go into the iterator - CORBA::ULong size = ordered_offers.size (); - CORBA::ULong offers_in_sequence = (how_many < size) ? how_many : size; - CORBA::ULong offers_in_iterator = size - offers_in_sequence; - CORBA::ULong total_offers = offers_in_sequence + offers_in_iterator; - - offers->length (offers_in_sequence); - - // Add to the sequence, filtering out the undesired properties. - for (CORBA::ULong i = 0; - i < offers_in_sequence; - ordered_offers_iterator.advance (), i++) - { - Offer_Info* offer_info_ptr = 0; - ordered_offers_iterator.next (offer_info_ptr); - CosTrading::Offer& source = *offer_info_ptr->offer_ptr_; - CosTrading::Offer& destination = (*offers)[i]; - prop_filter.filter_offer (source, destination); - - CORBA::string_free (offer_info_ptr->offer_id_); - } - - // Any remaining offers go into iterator - if (offers_in_iterator > 0) - { - // Create an iterator implementation - TAO_Offer_Iterator *oi = - this->create_offer_iterator (type, prop_filter); - offer_itr = oi->_this (env); - TAO_CHECK_ENV_RETURN (env,total_offers - offers_in_iterator); - - // Add to the iterator - for (i = 0; - i < offers_in_iterator; - ordered_offers_iterator.advance (), i++) - { - Offer_Info* offer_info_ptr = 0; - ordered_offers_iterator.next (offer_info_ptr); - oi->add_offer (offer_info_ptr->offer_id_, - offer_info_ptr->offer_ptr_); - } - } - - return total_offers; -} - -template <class TRADER> -TAO_Offer_Iterator * -TAO_Lookup<TRADER>:: -create_offer_iterator (const char *type, - const TAO_Property_Filter& pfilter) -{ - // This is the factory method that creates the appropriate type of - // offer iterator. If there's no Register interface, then we can - // just stick the offers directly into an iterator, since these - // offers will never be removed from the Trader. If there's a - // Register interface, then there's a chance that by the time the - // importer calls the next_n method on the iterator that the offer - // will have been withdrawn. So the Register_Offer_Iterator retains only - // the offer ids, and will recognize when an offer id no longer - // identifies an offer in the trader. - - // We pass the property filter to the iterators, so when the iterators - // return the offers, they can remove the undesirable properties - // from those offers. - TAO_Offer_Iterator* iterator = 0; - - if (CORBA::is_nil (this->trader_.trading_components ().register_if ())) - iterator = new TAO_Query_Only_Offer_Iterator (pfilter); - else - { - iterator = - new TAO_Register_Offer_Iterator<TRADER> (this->trader_, pfilter); - } - - return iterator; -} - -template <class TRADER> CORBA::Boolean -TAO_Lookup<TRADER>::duplicate_stem_id (TAO_Policies& policies, - CORBA::Environment& _env) -{ - // Determine whether the stem_id passed to this query is one we've - // already seen. If this is the case, then we shouldn't pursue this - // query any further. - CORBA::Boolean return_value = CORBA::B_FALSE; - CosTrading::Admin::OctetSeq_var request_id = policies.request_id (_env); - TAO_CHECK_ENV_RETURN (_env, return_value); - - // If the stem_id was provided and is a duplicate, return true. - if ((request_id.ptr () != 0) && - this->request_ids_.insert (request_id) == 1) - return_value = CORBA::B_TRUE; - - return return_value; -} - -template <class TRADER> CORBA::Boolean -TAO_Lookup<TRADER>::retrieve_links (TAO_Policies& policies, - CORBA::ULong offers_returned, - CosTrading::LinkNameSeq_out links, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Lookup::PolicyTypeMismatch)) -{ - CORBA::Boolean should_follow = CORBA::B_FALSE; - CosTrading::FollowOption follow_rule = policies.link_follow_rule (_env); - TAO_CHECK_ENV_RETURN (_env, should_follow); - - // Determine whether or not a federated query is warranted. A query - // is waranted if the follow_rule governing this query is 'always' - // or if_no_local and the local query returned nothing. - if ((follow_rule == CosTrading::always || - (follow_rule == CosTrading::if_no_local && offers_returned == 0)) - && policies.hop_count (_env) > 0) - should_follow = CORBA::B_TRUE; - - if (should_follow) - { - // Grab the names of all the links in the trader, and push - // the suitable ones onto <valid_links>. - CosTrading::Link_ptr link_interface - = this->trader_.trading_components ().link_if (); - ACE_Unbounded_Queue<CosTrading::LinkName> valid_links; - CosTrading::LinkNameSeq_var link_path = - link_interface->list_links (_env); - TAO_CHECK_ENV_RETURN (_env, should_follow); - - // Determine which of the links registered with the Link - // interface are suitable to follow. - for (int i = link_path->length () - 1; i >= 0; i--) - { - CosTrading::FollowOption link_rule = - policies.link_follow_rule ((const char*) link_path[i], _env); - if (link_rule == CosTrading::always || - (link_rule == CosTrading::if_no_local && - offers_returned == 0)) - valid_links.enqueue_tail ((char *)((const char*) link_path[i])); - } - - // Collect those valid links into a sequence suitable for - // passing into the federated_query method. - CosTrading::LinkName link_name = 0, - *link_buf = CosTrading::LinkNameSeq::allocbuf (valid_links.size ()); - - if (link_buf != 0) - { - for (i = valid_links.size () - 1; i >= 0; i--) - { - valid_links.dequeue_head (link_name); - link_buf[i] = CORBA::string_dup (link_name); - } - - ACE_NEW_RETURN (links, - CosTrading::LinkNameSeq (valid_links.size (), - valid_links.size (), - link_buf, - CORBA::B_TRUE), - 0); - } - } - - return should_follow; -} - - -template <class TRADER> void -TAO_Lookup<TRADER>:: -federated_query (const CosTrading::LinkNameSeq& links, - const char *type, - const char *constr, - const char *pref, - TAO_Policies& policies, - const CosTrading::Lookup::SpecifiedProps& desired_props, - CORBA::ULong how_many, - CosTrading::OfferSeq_out offers, - CosTrading::OfferIterator_out offer_iter, - CosTrading::PolicyNameSeq_out limits, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::IllegalConstraint, - CosTrading::Lookup::IllegalPreference, - CosTrading::Lookup::IllegalPolicyName, - CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue, - CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName, - CosTrading::DuplicatePolicyName)) -{ - // The general idea here is this: We've assembled a number of links - // to follow, and we'll query each of them in turn. When we've - // assembled <return_card> number of offers, we've hit the ceiling - // and we back out. On each query we adjust the policies for the new - // trader by reducing the return_card, hop_count, etc..., and merge - // the results from the new query with the results from the previous - // queries. - - // We'll need the link and admin interfaces for this part of the - // federated query. - CORBA::ULong total_returned = 0, - return_card = policies.return_card (_env); - CosTrading::Link_ptr link_interface - = this->trader_.trading_components ().link_if (); - CosTrading::Admin_ptr admin_interface - = this->trader_.trading_components ().admin_if (); - - // Begin collecting all the various offer_iterators into a - // collection. The end result is a distributed tree of offer - // iterators, which if traversed in its entirety is probably hugely - // inefficient, but oh well, I can't think of a better solution. - TAO_Offer_Iterator_Collection* offer_iter_collection; - ACE_NEW (offer_iter_collection, TAO_Offer_Iterator_Collection); - - offer_iter_collection->add_offer_iterator (offer_iter); - total_returned = offers->length () + - offer_iter_collection->max_left (_env); - - for (int i = links.length () - 1; i >= 0; i--) - { - CosTrading::OfferSeq* out_offers = 0; - CosTrading::OfferIterator* out_offer_iter = 0; - CosTrading::PolicyNameSeq* out_limits = 0; - CosTrading::OfferSeq_var out_offers_var (out_offers); - CosTrading::OfferIterator_var out_offer_iter_var (out_offer_iter); - CosTrading::PolicyNameSeq_var out_limits_var (out_limits); - - TAO_TRY - { - // Obtain information about the link we're traversing. - CosTrading::Link::LinkInfo_var link_info = - link_interface->describe_link (links[i], TAO_TRY_ENV); - TAO_CHECK_ENV; - - // Prepare a set of policies to pass to the next trader. - CosTrading::PolicySeq_var new_pols = - policies.policies_to_pass (link_info->def_pass_on_follow_rule, - total_returned, - admin_interface); - - // Perform the federated query. - link_info->target-> - query (type, - constr, - pref, - new_pols.in (), - desired_props, - how_many - offers->length (), - CosTrading::OfferSeq_out (out_offers), - CosTrading::OfferIterator_out (out_offer_iter), - CosTrading::PolicyNameSeq_out (out_limits), - _env); - TAO_CHECK_ENV; - - // Merge the results. - CORBA::ULong offset = offers->length (); - offers->length (out_offers->length () + offset); - offer_iter_collection->add_offer_iterator (out_offer_iter); - for (int j = out_offers->length () - 1; j >= 0; j--) - offers[j + offset] = out_offers_var[j]; - - // Concatenate the limits applied. - offset = limits->length (); - offers->length (out_limits->length () + offset); - for (j = out_limits->length () - 1; j >= 0; j--) - limits[j + offset] = out_limits_var[j]; - - // If we've obtained all the offers we need, let's blow this - // joint. - if (total_returned >= return_card) - break; - } - TAO_CATCHANY - { - break; - } - TAO_ENDTRY; - } - - // Return the collection of offer iterators. - offer_iter = offer_iter_collection->_this (_env); -} - -template <class TRADER> void -TAO_Lookup<TRADER>:: -forward_query (const CosTrading::TraderName& starting_trader, - const char *type, - const char *constr, - const char *pref, - TAO_Policies& policies, - const CosTrading::Lookup::SpecifiedProps& desired_props, - CORBA::ULong how_many, - CosTrading::OfferSeq_out offers, - CosTrading::OfferIterator_out offer_itr, - CosTrading::PolicyNameSeq_out limits_applied, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::IllegalConstraint, - CosTrading::Lookup::IllegalPreference, - CosTrading::Lookup::IllegalPolicyName, - CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue, - CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName, - CosTrading::DuplicatePolicyName)) -{ - // Forward this query to the next link in the starting_trader sequence. - CosTrading::Link_ptr link_interface - = this->trader_.trading_components ().link_if (); - - TAO_TRY - { - CosTrading::Link::LinkInfo_var link_info = - link_interface->describe_link (starting_trader[0], TAO_TRY_ENV); - TAO_CHECK_ENV; - - CosTrading::PolicySeq_var in_policies = policies.policies_to_forward (); - - // Perform forwarding query. - link_info->target->query (type, - constr, - pref, - in_policies.in (), - desired_props, - how_many, - offers, - offer_itr, - limits_applied, - _env); - TAO_CHECK_ENV_RETURN_VOID (_env); - } - TAO_CATCHANY - { - TAO_THROW (CosTrading::Lookup::InvalidPolicyValue ()); - } - TAO_ENDTRY; -} - -#endif /* TAO_LOOKUP_C */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Lookup.h b/TAO/orbsvcs/orbsvcs/Trader/Lookup.h deleted file mode 100644 index e9854f5dba6..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Lookup.h +++ /dev/null @@ -1,309 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Lookup.h -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// Irfan Pyarali <irfan@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_LOOKUP_H -#define TAO_LOOKUP_H - -#include "Policies.h" -#include "Attributes_T.h" -#include "Offer_Filter.h" -#include "Offer_Iterator.h" -#include "Constraint_Interpreter.h" -#include "Preference_Interpreter.h" - -#include "ace/Containers.h" - -template<class TRADER> -class TAO_Lookup : - public TAO_Trader_Components<POA_CosTrading::Lookup>, - public TAO_Support_Attributes<POA_CosTrading::Lookup>, - public TAO_Import_Attributes<POA_CosTrading::Lookup> - // - // = TITLE - // This class implements CosTrading::Lookup IDL interface. -{ -public: - - TAO_Lookup (TRADER &trader); - - ~TAO_Lookup (void); - - virtual void - query (const char *type, - const char *constr, - const char *pref, - const CosTrading::PolicySeq& policies, - const CosTrading::Lookup::SpecifiedProps& desired_props, - CORBA::ULong how_many, - CosTrading::OfferSeq_out offers, - CosTrading::OfferIterator_out offer_itr, - CosTrading::PolicyNameSeq_out limits_applied, - CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::IllegalConstraint, - CosTrading::Lookup::IllegalPreference, - CosTrading::Lookup::IllegalPolicyName, - CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue, - CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName, - CosTrading::DuplicatePolicyName)); - - // BEGIN SPEC - // The query operation is the means by which an object can obtain - // references to other objects that provide services meeting its - // requirements. - - // The "type" parameter conveys the required service type. It is key - // to the central purpose of trading: to perform an introduction for - // future type safe interactions between importer and exporter. By - // stating a service type, the importer implies the desired interface - // type and a domain of discourse for talking about properties of the - // service. - - // The trader may return a service offer of a subtype of the "type" - // requested. Sub-typing of service types is discussed in "Service - // Types" on page 16-4. A service subtype can be described by the - // properties of its supertypes. This ensures that a well-formed - // query for the "type" is also a well-formed query with respect to - // any subtypes. However, if the importer specifies the policy of - // exact_type_match = TRUE, then only offers with the exact (no - // subtype) service type requested are returned. - - // The constraint "constr" is the means by which the importer states - // those requirements of a service that are not captured in the - // signature of the interface. These requirements deal with the - // computational behavior of the desired service, non-functional - // aspects, and non-computational aspects (such as the organization - // owning the objects that provide the service). An importer is - // always guaranteed that any returned offer satisfies the matching - // constraint at the time of import. If the "constr" does not obey - // the syntax rules for a legal constraint expression, then an - // IllegalConstraint exception is raised. - - // The "pref" parameter is also used to order those offers that - // match the "constr" so that the offers returned by the trader are - // in the order of greatest interest to the importer. If "pref" does - // not obey the syntax rules for a legal preference expression, then - // an IllegalPreference exception is raised. - - // 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. - - // The "desired_props" parameter defines the set of properties - // describing returned offers that are to be returned with the - // object reference. There are three possibilities, the importer - // wants one of the properties, all of the properties (but without - // having to name them), or some properties (the names of which are - // provided). - - // The desired_props parameter does not affect whether or not a - // service offer is returned. To avoid "missing" desired properties, - // the importer should specify "exists prop_name" in the - // constraint. - - // The returned offers are passed back in one of two ways (or a - // combination of both). °The "offers" return result conveys a list - // of offers and the "offer_itr" is a reference to an interface at - // which offers can be obtained. The "how_many" parameter states - // how many offers are to be returned via the "offers" result, any - // remaining offers are available via the iterator interface. If the - // "how_many" exceeds the number of offers to be returned, then the - // "offer_itr" will be nil. - - // 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 TRADER::Service_Type_Map Service_Type_Map; - - struct Offer_Info - { - CosTrading::OfferId offer_id_; - CosTrading::Offer* offer_ptr_; - }; - - typedef ACE_Unbounded_Queue<Offer_Info> Offer_Queue; - - TAO_Offer_Iterator* - create_offer_iterator (const char *type, - const TAO_Property_Filter& filter); - // Factory method for creating an appropriate Offer Iterator based - // on the presence of the Register Interface. - - void perform_lookup (const char* type, - const char* constraint, - const char* preferences, - Service_Type_Map& service_type_map, - CosTradingRepos::ServiceTypeRepository_ptr rep, - TAO_Policies& policies, - Offer_Queue& ordered_offers, - CosTrading::PolicyNameSeq_out returned_limits_applied, - CORBA::Environment& env) - TAO_THROW_SPEC ((CosTrading::IllegalConstraint, - CosTrading::Lookup::IllegalPreference, - CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType)); - // This method has three phases. The first phase passes the - // offer_map through the constraint interpreter, winnowing away - // those offers that don't match the validated constraint. The - // second phase orders the offers using the specified - // preferences. The last phase places the ordered offers into a list - // for returning. At each phase, the cardinality policies specified - // in the policies structure determine the number of offers - // submitted to each phase. - - void lookup_all_subtypes (const char* type, - CosTradingRepos::ServiceTypeRepository::IncarnationNumber& inc_num, - Service_Type_Map& service_type_map, - CosTradingRepos::ServiceTypeRepository_ptr rep, - TAO_Constraint_Interpreter& constr_inter, - TAO_Preference_Interpreter& pref_inter, - TAO_Offer_Filter& offer_filter); - // Traverse the type hierarchy to pull the matching offers from all - // subtypes of the root type. - - void lookup_one_type (const char* type, - Service_Type_Map& service_type_map, - TAO_Constraint_Interpreter& constr_inter, - TAO_Preference_Interpreter& pref_inter, - TAO_Offer_Filter& offer_filter); - // Check if offers of a type fit the constraints and order them - // according to the preferences submitted. - - int fill_receptacles (const char* type, - Offer_Queue& ordered_offers, - CORBA::ULong how_many, - const CosTrading::Lookup::SpecifiedProps& desired_props, - CosTrading::OfferSeq*& offers, - CosTrading::OfferIterator_ptr& offer_itr, - CORBA::Environment& env) - TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName)); - // This method takes the list of ordered offers and places a number - // of them in the sequence of returned offers and the rest into thr - // iterator. In addition, fill_receptacles uses the - // TAO_Property_Filter to ensure the returned offers contain the - // properties specified in the desired_props in parameter. - - void forward_query (const CosTrading::TraderName& starting_trader, - const char *type, - const char *constr, - const char *pref, - TAO_Policies& policies, - const CosTrading::Lookup::SpecifiedProps& desired_props, - CORBA::ULong how_many, - CosTrading::OfferSeq_out offers, - CosTrading::OfferIterator_out offer_itr, - CosTrading::PolicyNameSeq_out limits_applied, - CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::IllegalConstraint, - CosTrading::Lookup::IllegalPreference, - CosTrading::Lookup::IllegalPolicyName, - CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue, - CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName, - CosTrading::DuplicatePolicyName)); - // If a starting_trader policy was specfied, foward the query to the - // next link in the sequence. - - CORBA::Boolean duplicate_stem_id (TAO_Policies& policies, - CORBA::Environment& _env); - // Determine if the stem id provided to the query is one we've - // already seen. - - CORBA::Boolean retrieve_links (TAO_Policies& policies, - CORBA::ULong offer_returned, - CosTrading::LinkNameSeq_out links, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Lookup::PolicyTypeMismatch)); - // Assemble a sequence of links that the federate_query method - // should follow. Use the starting_trader policy, if one's provided, - // otherwise use the Link interface to determine which of the - // registered links should be followed in this query. - - void federated_query (const CosTrading::LinkNameSeq& links, - const char *type, - const char *constr, - const char *pref, - TAO_Policies& policies, - const CosTrading::Lookup::SpecifiedProps& desired_props, - CORBA::ULong how_many, - CosTrading::OfferSeq_out offers, - CosTrading::OfferIterator_out offer_itr, - CosTrading::PolicyNameSeq_out limits_applied, - CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::IllegalConstraint, - CosTrading::Lookup::IllegalPreference, - CosTrading::Lookup::IllegalPolicyName, - CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue, - CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName, - CosTrading::DuplicatePolicyName)); - // Perform and pass on a query over a set of links. Merge the - // results of the federated queries into a single set of results - // suitable for returning to the user. - - TRADER &trader_; - // A reference to the trader for obtaining offer maps. - - typedef ACE_Unbounded_Set - < - CosTrading::Admin::OctetSeq_var - > - Request_Ids; - - Request_Ids request_ids_; - // A list of recent request_id_stems - - // TAO_Register_Offer_Iterator<TRADER> msvc_dummy_; -}; - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Lookup.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#endif /* TAO_LOOKUP_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Service_Type_Map.cpp b/TAO/orbsvcs/orbsvcs/Trader/Offer_Database.cpp index 307edfa60a7..024a98e67fa 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Service_Type_Map.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Offer_Database.cpp @@ -1,17 +1,17 @@ // $Id$ -#ifndef TAO_SERVICE_TYPE_MAP_C -#define TAO_SERVICE_TYPE_MAP_C +#ifndef TAO_OFFER_DATABASE_C +#define TAO_OFFER_DATABASE_C -#include "Service_Type_Map.h" -#include "Offer_Id_Iterator.h" +#include "Offer_Database.h" +#include "Offer_Iterators.h" template <class LOCK_TYPE> -TAO_Service_Type_Map<LOCK_TYPE>::TAO_Service_Type_Map (void) +TAO_Offer_Database<LOCK_TYPE>::TAO_Offer_Database (void) { } template <class LOCK_TYPE> -TAO_Service_Type_Map<LOCK_TYPE>::~TAO_Service_Type_Map (void) +TAO_Offer_Database<LOCK_TYPE>::~TAO_Offer_Database (void) { ACE_WRITE_GUARD (LOCK_TYPE, ace_mon, this->db_lock_); @@ -27,7 +27,7 @@ TAO_Service_Type_Map<LOCK_TYPE>::~TAO_Service_Type_Map (void) } template <class LOCK_TYPE> CosTrading::OfferId -TAO_Service_Type_Map<LOCK_TYPE>:: +TAO_Offer_Database<LOCK_TYPE>:: insert_offer (const char* type, const CosTrading::Offer& offer) { @@ -66,7 +66,7 @@ insert_offer (const char* type, } template <class LOCK_TYPE> int -TAO_Service_Type_Map<LOCK_TYPE>:: +TAO_Offer_Database<LOCK_TYPE>:: remove_offer (const char* type, CORBA::ULong id) { if (this->db_lock_.acquire_read ()) @@ -87,7 +87,7 @@ remove_offer (const char* type, CORBA::ULong id) } template <class LOCK_TYPE> int -TAO_Service_Type_Map<LOCK_TYPE>:: +TAO_Offer_Database<LOCK_TYPE>:: remove_offer (const CosTrading::OfferId offer_id, CORBA::Environment& _env) TAO_THROW_SPEC ((CosTrading::IllegalOfferId, @@ -106,7 +106,7 @@ remove_offer (const CosTrading::OfferId offer_id, } template <class LOCK_TYPE> CosTrading::Offer* -TAO_Service_Type_Map<LOCK_TYPE>:: +TAO_Offer_Database<LOCK_TYPE>:: lookup_offer (const CosTrading::OfferId offer_id, char*& type_name, CORBA::Environment& _env) @@ -126,7 +126,7 @@ lookup_offer (const CosTrading::OfferId offer_id, template <class LOCK_TYPE> CosTrading::Offer* -TAO_Service_Type_Map<LOCK_TYPE>:: +TAO_Offer_Database<LOCK_TYPE>:: lookup_offer (const CosTrading::OfferId offer_id, CORBA::Environment& _env) TAO_THROW_SPEC ((CosTrading::IllegalOfferId, @@ -146,7 +146,7 @@ lookup_offer (const CosTrading::OfferId offer_id, } template <class LOCK_TYPE> CosTrading::Offer* -TAO_Service_Type_Map<LOCK_TYPE>:: +TAO_Offer_Database<LOCK_TYPE>:: lookup_offer (const char* type, CORBA::ULong id) { ACE_READ_GUARD_RETURN (LOCK_TYPE, ace_mon, this->db_lock_, 0); @@ -170,10 +170,10 @@ lookup_offer (const char* type, CORBA::ULong id) } template <class LOCK_TYPE> TAO_Offer_Id_Iterator* -TAO_Service_Type_Map<LOCK_TYPE>::retrieve_all_offer_ids (void) +TAO_Offer_Database<LOCK_TYPE>::retrieve_all_offer_ids (void) { // Fill an TAO_Offer_Id_Iterator with the offer_ids of all offers - // exported to the TAO_Service_Type_Map. Iterates through the entire + // exported to the TAO_Offer_Database. Iterates through the entire // map, cramming offer_id strings into a newly constructed // TAO_Offer_Id_Iterator. TAO_Offer_Id_Iterator* id_iterator = new TAO_Offer_Id_Iterator (); @@ -204,7 +204,7 @@ TAO_Service_Type_Map<LOCK_TYPE>::retrieve_all_offer_ids (void) } template <class LOCK_TYPE> void -TAO_Service_Type_Map<LOCK_TYPE>:: +TAO_Offer_Database<LOCK_TYPE>:: parse_offer_id (const CosTrading::OfferId offer_id, char*&service_type, CORBA::ULong& id, @@ -228,7 +228,7 @@ parse_offer_id (const CosTrading::OfferId offer_id, } template <class LOCK_TYPE> CosTrading::OfferId -TAO_Service_Type_Map<LOCK_TYPE>:: +TAO_Offer_Database<LOCK_TYPE>:: generate_offer_id (const char *service_type_name, CORBA::ULong id) { // holds final id string. @@ -249,7 +249,7 @@ generate_offer_id (const char *service_type_name, CORBA::ULong id) template <class LOCK_TYPE> TAO_Service_Offer_Iterator<LOCK_TYPE>:: TAO_Service_Offer_Iterator (const char* type, - TAO_Service_Type_Map<LOCK_TYPE>& offer_database) + TAO_Offer_Database<LOCK_TYPE>& offer_database) : stm_ (offer_database), entry_ (0), offer_iter_ (0), @@ -260,7 +260,7 @@ TAO_Service_Offer_Iterator (const char* type, if (this->stm_.db_lock_.acquire_read () == -1) ; - Service_Type_Map::Offer_Database::ENTRY* db_entry; + Offer_Database::Offer_Database::ENTRY* db_entry; if (this->stm_.offer_db_.find (service_type, db_entry) == -1) return; else @@ -270,7 +270,7 @@ TAO_Service_Offer_Iterator (const char* type, ; ACE_NEW (offer_iter_, - Service_Type_Map::Offer_Map::iterator (*this->entry_->offer_map_)); + Offer_Database::Offer_Map::iterator (*this->entry_->offer_map_)); } } @@ -293,7 +293,7 @@ template <class LOCK_TYPE> CosTrading::OfferId TAO_Service_Offer_Iterator<LOCK_TYPE>::get_id (void) { return (this->offer_iter_ != 0) - ? TAO_Service_Type_Map<LOCK_TYPE>::generate_offer_id (this->type_, (**this->offer_iter_).ext_id_) + ? TAO_Offer_Database<LOCK_TYPE>::generate_offer_id (this->type_, (**this->offer_iter_).ext_id_) : 0; } @@ -336,5 +336,5 @@ hash (const CORBA::ULong &ext_id) } */ -#endif /* TAO_SERVICE_TYPE_MAP_C */ +#endif /* TAO_OFFER_DATABASE_C */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Service_Type_Map.h b/TAO/orbsvcs/orbsvcs/Trader/Offer_Database.h index 968ae3e89f9..78da84170e0 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Service_Type_Map.h +++ b/TAO/orbsvcs/orbsvcs/Trader/Offer_Database.h @@ -7,27 +7,26 @@ // orbsvcs // // = FILENAME -// Service_Type_Map.h +// Offer_Database.h // // = AUTHOR // Seth Widoff <sbw1@cs.wustl.edu> // // ======================================================================== -#ifndef TAO_SERVICE_TYPE_MAP_H -#define TAO_SERVICE_TYPE_MAP_H +#ifndef TAO_OFFER_DATABASE_H +#define TAO_OFFER_DATABASE_H #include "Trader.h" -#include "ace/Map_Manager.h" class TAO_Offer_Id_Iterator; template <class LOCK_TYPE> class TAO_Service_Offer_Iterator; template <class LOCK_TYPE> -class TAO_Service_Type_Map +class TAO_Offer_Database // = DESCRIPTION -// The TAO_Service_Type_Map encapsulates the mapping of service +// The TAO_Offer_Database encapsulates the mapping of service // types to those offers exported with that service types. The // underlying structure is a map of maps. The first maps maps the // service type name to a map of exported offers. The second map @@ -36,14 +35,14 @@ class TAO_Service_Type_Map // exported offer. In fact, when the register export interface // returns a CosTrading::OfferId, it's returning no more than a // simple string concatenation of these two values. In addition to -// all these wonderful things, the TAO_Service_Type_Map has built-in +// all these wonderful things, the TAO_Offer_Database has built-in // locking, one reader/writer-style lock for modifying the top-level // map and a reader/writer-style for each of the offer // maps. Needless to say the locks are acquired when the -// TAO_Service_Type_Map performs operations on the structures they +// TAO_Offer_Database performs operations on the structures they // guard. // -// NOTE: TAO_Service_Type_Map needs to be parameterized by a +// NOTE: TAO_Offer_Database needs to be parameterized by a // READER/WRITER LOCK, a RECURSIVE MUTEX, or a NULL MUTEX, not a // simple binary mutex! Mutexes will cause deadlock when you try to // contruct an iterator (which acquires a read lock on the map under @@ -55,10 +54,10 @@ public: // Traits typedef TAO_Service_Offer_Iterator<LOCK_TYPE> offer_iterator; - TAO_Service_Type_Map (void); + TAO_Offer_Database (void); // No arg constructor. - ~TAO_Service_Type_Map (void); + ~TAO_Offer_Database (void); CosTrading::OfferId insert_offer (const char* type, const CosTrading::Offer& offer); @@ -90,11 +89,12 @@ public: // Return an iterator that will traverse and return all the offer // ids in the service type map. + private: + // = Disallow these operations. - ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Service_Type_Map<LOCK_TYPE> &)) - ACE_UNIMPLEMENTED_FUNC (TAO_Service_Type_Map (const TAO_Service_Type_Map<LOCK_TYPE> &)) - -private: + ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Offer_Database<LOCK_TYPE> &)) + ACE_UNIMPLEMENTED_FUNC (TAO_Offer_Database (const TAO_Offer_Database<LOCK_TYPE> &)) + class Hashable_ULong { @@ -187,10 +187,10 @@ class TAO_Service_Offer_Iterator { public: - typedef TAO_Service_Type_Map<LOCK_TYPE> Service_Type_Map; + typedef TAO_Offer_Database<LOCK_TYPE> Offer_Database; TAO_Service_Offer_Iterator (const char* type, - TAO_Service_Type_Map<LOCK_TYPE>& offer_database); + TAO_Offer_Database<LOCK_TYPE>& offer_database); ~TAO_Service_Offer_Iterator (void); // Release all the locks acquired. @@ -210,18 +210,18 @@ class TAO_Service_Offer_Iterator private: // Protected constructor. - TAO_Service_Type_Map<LOCK_TYPE>& stm_; + TAO_Offer_Database<LOCK_TYPE>& stm_; - TAO_Service_Type_Map<LOCK_TYPE>::Offer_Map_Entry* entry_; + TAO_Offer_Database<LOCK_TYPE>::Offer_Map_Entry* entry_; - TAO_Service_Type_Map<LOCK_TYPE>::Offer_Map::iterator* offer_iter_; + TAO_Offer_Database<LOCK_TYPE>::Offer_Map::iterator* offer_iter_; const char* type_; }; #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Service_Type_Map.cpp" +#include "Offer_Database.cpp" #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ #endif /* TAO_SERVICE_TYPE_MAP_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Filter.cpp b/TAO/orbsvcs/orbsvcs/Trader/Offer_Filter.cpp deleted file mode 100644 index 1a323792227..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Offer_Filter.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// $Id$ - -#include "Offer_Filter.h" - -TAO_Offer_Filter:: -TAO_Offer_Filter (SERVICE_TYPE_REPOS::TypeStruct* type_struct, - TAO_Policies& policies, - CORBA::Environment& _env) - : search_card_ (policies.search_card (_env)), - match_card_ (policies.match_card (_env)), - return_card_ (policies.return_card (_env)), - dp_ (policies.use_dynamic_properties (_env)), - mod_ (policies.use_modifiable_properties (_env)) -{ - SERVICE_TYPE_REPOS::PropStructSeq& prop_seq = type_struct->props; - - // Take note of modifiable properties in the type_struct - for (int i = prop_seq.length () - 1; i >= 0; i--) - { - SERVICE_TYPE_REPOS::PropertyMode mode = prop_seq[i].mode; - if (mode != SERVICE_TYPE_REPOS::PROP_MANDATORY_READONLY || - mode != SERVICE_TYPE_REPOS::PROP_READONLY) - { - TAO_String_Hash_Key prop_name ((const char*) prop_seq[i].name); - this->mod_props_.insert (prop_name); - } - } - - if (policies.exact_type_match (_env) == CORBA::B_TRUE) - { - TAO_String_Hash_Key exact_match - (TAO_Policies::POLICY_NAMES[TAO_Policies::EXACT_TYPE_MATCH]); - this->limits_.insert (exact_match); - } - -} - -CORBA::Boolean -TAO_Offer_Filter::ok_to_consider (CosTrading::Offer* offer) -{ - TAO_String_Hash_Key use_mods = - TAO_Policies::POLICY_NAMES[TAO_Policies::USE_MODIFIABLE_PROPERTIES]; - TAO_String_Hash_Key use_dyns = - TAO_Policies::POLICY_NAMES[TAO_Policies::USE_DYNAMIC_PROPERTIES]; - CORBA::Boolean return_value = CORBA::B_TRUE; - TAO_Property_Evaluator prop_eval (*offer); - - // If we should screen offers, determine if this offer is unworthy - // for consideration. - if (! (this->mod_ && this->dp_)) - { - for (int i = offer->properties.length () - 1; - i >= 0 && return_value; - i--) - { - // Winnow away the unwanted offers with modifiable or - // dynamic properties. - if (! this->mod_) - { - // Determine if this property name is found in the set - // of modifiable properties for the type being considered. - TAO_String_Hash_Key prop_name ((const char*) offer->properties[i].name); - if (this->mod_props_.find (prop_name) == 0) - { - this->limits_.insert (use_mods); - return_value = 0; - } - } - - if (! this->dp_ && return_value) - { - // Determine if this property is dynamic. - if (prop_eval.is_dynamic_property (i)) - { - this->limits_.insert (use_dyns); - return_value = 0; - } - } - - if (return_value == 0) - break; - } - } - - // If we're good to go, consider this offer considered and decrement - // the search cardinality counter. - if (return_value) - { - this->search_card_--; - if (this->search_card_ == 0) - { - TAO_String_Hash_Key search_card = - TAO_Policies::POLICY_NAMES[TAO_Policies::SEARCH_CARD]; - this->limits_.insert (search_card); - } - } - - return return_value; -} - -CORBA::Boolean -TAO_Offer_Filter::ok_to_consider_more (void) -{ - return this->search_card_ > 0 && this->match_card_ > 0; -} - -void -TAO_Offer_Filter::matched_offer (void) -{ - this->match_card_--; - this->return_card_--; - - if (this->match_card_ == 0) - { - TAO_String_Hash_Key match_card = - TAO_Policies::POLICY_NAMES[TAO_Policies::MATCH_CARD]; - this->limits_.insert (match_card); - } - - if (this->return_card_ == 0) - { - TAO_String_Hash_Key return_card = - TAO_Policies::POLICY_NAMES[TAO_Policies::MATCH_CARD]; - this->limits_.insert (return_card); - } -} - -CosTrading::PolicyNameSeq* -TAO_Offer_Filter::limits_applied (void) -{ - int i = 0; - CORBA::ULong size = this->limits_.size (); - CosTrading::PolicyName* temp = - CosTrading::PolicyNameSeq::allocbuf (size); - - for (Names::iterator p_iter (this->limits_.begin()); - ! p_iter.done (); - p_iter.advance ()) - { - TAO_String_Hash_Key* policy_name_ptr = 0; - p_iter.next (policy_name_ptr); - temp[i++] = CORBA::string_dup ((const char*) *policy_name_ptr); - } - - return new CosTrading::PolicyNameSeq (i, i, temp, 1); -} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Filter.h b/TAO/orbsvcs/orbsvcs/Trader/Offer_Filter.h deleted file mode 100644 index a8425e974f5..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Offer_Filter.h +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Offer_Filter.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_OFFER_FILTER_H -#define TAO_OFFER_FILTER_H - -#include "Policies.h" -#include "Property_Evaluator.h" - -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. -}; - -#endif /* TAO_OFFER_FILTER_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Id_Iterator.cpp b/TAO/orbsvcs/orbsvcs/Trader/Offer_Id_Iterator.cpp deleted file mode 100644 index fdbdb5fbcb2..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Offer_Id_Iterator.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// ============================================================================ -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Offer_Id_terator.cpp -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ============================================================================ - -#include "Offer_Id_Iterator.h" - -TAO_Offer_Id_Iterator::TAO_Offer_Id_Iterator (void) -{ -} - -TAO_Offer_Id_Iterator::~TAO_Offer_Id_Iterator (void) -{ - int items_left = this->ids_.size (), - return_value = 0; - - do - { - CosTrading::OfferId offer_id = 0; - - return_value = this->ids_.dequeue_head (offer_id); - if (return_value == 0) - CORBA::string_free (offer_id); - } - while (return_value == 0); -} - -CORBA::ULong -TAO_Offer_Id_Iterator::max_left (CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::UnknownMaxLeft)) -{ - return this->ids_.size (); -} - -void -TAO_Offer_Id_Iterator::destroy (CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - // Remove self from POA - // - // Note that there is no real error checking here as we can't do - // much about errors here anyway - // - - TAO_TRY - { - PortableServer::POA_var poa = this->_default_POA (TAO_TRY_ENV); - TAO_CHECK_ENV; - - PortableServer::ObjectId_var id = poa->servant_to_id (this, TAO_TRY_ENV); - TAO_CHECK_ENV; - - poa->deactivate_object (id.in (), TAO_TRY_ENV); - } - TAO_CATCHANY - { - } - TAO_ENDTRY; - - delete this; -} - -CORBA::Boolean -TAO_Offer_Id_Iterator::next_n (CORBA::ULong n, - CosTrading::OfferIdSeq_out _ids, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - // Calculate the number of Ids to be returned in this. - int items_left = this->ids_.size(), - difference = items_left - n, - returnable_items = (difference >= 0) ? n : items_left; - CORBA::Boolean return_value = (CORBA::Boolean) (difference > 0); - - if (returnable_items == 0) - { - ACE_NEW_RETURN (_ids, CosTrading::OfferIdSeq, return_value); - } - else - { - // Allocate space for the returned OfferIds. - CosTrading::OfferId* id_buf = - CosTrading::OfferIdSeq::allocbuf (returnable_items); - - if (id_buf != 0) - { - // Copy in those ids! - for (int i = 0; i < returnable_items; i++) - { - CosTrading::OfferId offer_id = 0; - - this->ids_.dequeue_head (offer_id); - id_buf[i] = offer_id; - } - - // Place them into an OfferIdSeq. - ACE_NEW_RETURN (_ids, - CosTrading::OfferIdSeq (returnable_items, - returnable_items, - id_buf, - 1), - return_value); - } - else - ACE_NEW_RETURN (_ids, CosTrading::OfferIdSeq, return_value); - } - - // Return true only if there are items left to be returned in - // subsequent calls. - return return_value; -} - -void -TAO_Offer_Id_Iterator::insert_id (CosTrading::OfferId new_id) -{ - this->ids_.enqueue_tail (new_id); -} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Id_Iterator.h b/TAO/orbsvcs/orbsvcs/Trader/Offer_Id_Iterator.h deleted file mode 100644 index 63520656362..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Offer_Id_Iterator.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Offer_Id_terator.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================= - -#ifndef TAO_OFFER_ID_ITERATOR_H -#define TAO_OFFER_ID_ITERATOR_H - -#include "orbsvcs/CosTradingS.h" - -#if defined(_MSC_VER) -#pragma warning (disable:4250) -#endif /* _MSC_VER */ - -class TAO_Offer_Id_Iterator : public POA_CosTrading::OfferIdIterator -// = TITLE -// Silly little iterator that contains the overflow of offer ids -// from the Admin list_offers method. -// -// = DESCRIPTION -// -// BEGIN SPEC -// The OfferIdIterator interface is used to return a set of offer -// identifiers from the list_offers operation and the list_proxies -// operation in the Admin interface by enabling the offer identifiers -// to be extracted by successive operations on the OfferIdIterator -// interface. -// END SPEC -{ - public: - - TAO_Offer_Id_Iterator(void); - // No op constructor - - ~TAO_Offer_Id_Iterator (void); - - virtual CORBA::ULong max_left(CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::UnknownMaxLeft)); - // The max_left operation returns the number of offer identifiers - // remaining in the iterator. The exception UnknownMaxLeft is raised - // if the iterator cannot determine the remaining number of offer - // identifiers (e.g., if the iterator determines its set of offer - // identifiers through lazy evaluation). - - virtual void destroy(CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException)); - // The destroy operation destroys the iterator. No further - // operations can be invoked on an iterator after it has been - // destroyed. - - virtual CORBA::Boolean next_n(CORBA::ULong _n, - CosTrading::OfferIdSeq_out _ids, - CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException)); - // The next_n operation returns a set of offer identifiers in the - // output parameter "ids." The operation returns n offer identifiers - // if there are at least n offer identifiers remaining in the - // iterator. If there are fewer than n offer identifiers in the - // iterator, then all remaining offer identifiers are returned. The - // actual number of offer identifiers returned can be determined - // from the length of the "ids" sequence. The next_n operation - // returns TRUE if there are further offer identifiers to be - // extracted from the iterator. It returns FALSE if there are no - // further offer identifiers to be extracted. - - void insert_id(CosTrading::OfferId new_id); - // Insert a <new_id> into the contents of the iterator. - - private: - - typedef ACE_Unbounded_Queue - < - CosTrading::OfferId - > - Offer_Id_Queue; - - - Offer_Id_Queue ids_; -}; - -#endif /* TAO_OFFER_ID_ITERATOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator.cpp b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator.cpp deleted file mode 100644 index 9acdabd4619..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Offer_Iterator.cpp -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#include "Offer_Iterator.h" - - -TAO_Offer_Iterator::TAO_Offer_Iterator (const TAO_Property_Filter& pfilter) - : pfilter_ (pfilter) -{ -} - -TAO_Offer_Iterator::~TAO_Offer_Iterator (void) -{ -} - -void -TAO_Offer_Iterator::destroy (CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - // Remove self from POA - // - // Note that there is no real error checking here as we can't do - // much about errors here anyway - // - - TAO_TRY - { - PortableServer::POA_var poa = this->_default_POA (TAO_TRY_ENV); - TAO_CHECK_ENV; - PortableServer::ObjectId_var id = poa->servant_to_id (this, TAO_TRY_ENV); - TAO_CHECK_ENV; - - poa->deactivate_object (id.in (), TAO_TRY_ENV); - } - TAO_CATCHANY - { - } - TAO_ENDTRY; - - delete this; -} - - - diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator.h b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator.h deleted file mode 100644 index 5ae9e659ed9..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- C++ -*- */ - -// ============================================================================ -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Offer_Iterator.h -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ============================================================================ - -#ifndef TAO_OFFER_ITERATOR_H -#define TAO_OFFER_ITERATOR_H - -#include "Property_Filter.h" - -class TAO_Offer_Iterator : - public POA_CosTrading::OfferIterator - // = TITLE - // This class implements CosTrading::OfferIterator IDL - // interface. - - // = DESCRIPTION - // This is an abstract base class to allow for different - // implementations of OfferIterator. - // BEGIN SPEC - // The OfferIterator interface is used to return a set of service - // offers from the query operation by enabling the service offers - // to be extracted by successive operations on the OfferIterator - // interface. - // END SPEC -{ -public: - // = Initialization and termination methods. - - TAO_Offer_Iterator (const TAO_Property_Filter& property_filter); - - virtual ~TAO_Offer_Iterator (void); - - virtual void destroy (CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)); - // BEGIN SPEC - // The destroy operation destroys the iterator. No further - // operations can be invoked on an iterator after it has been - // destroyed. - // END SPEC - - virtual void add_offer (CosTrading::OfferId offer_id, - const CosTrading::Offer* offer) = 0; - // Add an offer to the collection of offers the iterator will - // iterate over. - - virtual CORBA::ULong max_left (CORBA::Environment &env) = 0 - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::UnknownMaxLeft)); - - // BEGIN SPEC - // The max_left operation returns the number of service offers - // remaining in the iterator. The exception UnknownMaxLeft is raised - // if the iterator cannot determine the remaining number of service - // offers (e.g., if the iterator determines its set of service - // offers through lazy evaluation). - // END SPEC - - virtual CORBA::Boolean next_n (CORBA::ULong n, - CosTrading::OfferSeq_out offers, - CORBA::Environment &env) = 0 - TAO_THROW_SPEC ((CORBA::SystemException)); - // BEGIN SPEC - // The next_n operation returns a set of service offers in the - // output parameter "offers." The operation returns n service offers - // if there are at least n service offers remaining in the - // iterator. If there are fewer than n service offers in the - // iterator, then all remaining service offers are returned. The - // actual number of service offers returned can be determined from - // the length of the "offers" sequence. The next_n operation returns - // TRUE if there are further service offers to be extracted from the - // iterator. It returns FALSE if there are no further service offers - // to be extracted. - // END SPEC - protected: - - TAO_Property_Filter pfilter_; -}; - -#endif /* TAO_OFFER_ITERATOR */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator_Collection.cpp b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator_Collection.cpp deleted file mode 100644 index b8306876f3d..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator_Collection.cpp +++ /dev/null @@ -1,137 +0,0 @@ -// $Id$ - -#include "Offer_Iterator_Collection.h" - -TAO_Offer_Iterator_Collection::TAO_Offer_Iterator_Collection (void) - : total_left_ (0) -{ -} - -void -TAO_Offer_Iterator_Collection:: -add_offer_iterator (CosTrading::OfferIterator* offer_iter) -{ - Iter_Info iter_info; - - if (offer_iter != CosTrading::OfferIterator::_nil ()) - { - TAO_TRY - { - iter_info.iter_ = offer_iter; - iter_info.num_left_ = offer_iter->max_left (TAO_TRY_ENV); - TAO_CHECK_ENV; - } - TAO_CATCHANY - { - // I don't know what to do here if the offer_iterator throws - // an UnknownMaxLeft exception. - } - TAO_ENDTRY; - - this->total_left_ += iter_info.num_left_; - this->iters_.enqueue_tail (iter_info); - } -} - -CORBA::Boolean -TAO_Offer_Iterator_Collection::next_n (CORBA::ULong n, - CosTrading::OfferSeq_out offers, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::ULong offers_left = n; - CORBA::Boolean return_value = CORBA::B_TRUE; - CosTrading::OfferSeq_var out_offers; - - ACE_NEW_RETURN (offers, CosTrading::OfferSeq, return_value); - while (offers_left > 0 && ! this->iters_.is_empty ()) - { - Iter_Info iter_info; - this->iters_.dequeue_head (iter_info); - - // Determine how many offers we should retrieve from this - // iterator. - CORBA::ULong offers_to_retrieve = - (offers_left > iter_info.num_left_) - ? iter_info.num_left_ - : offers_left; - - // Retrieve the set of offers. - iter_info.iter_->next_n - (offers_to_retrieve, - CosTrading::OfferSeq_out (out_offers.out ()), - env); - - // Merge it with the passed set. - CORBA::ULong offset = offers->length (); - offers->length (out_offers->length () + offset); - for (int j = out_offers->length () - 1; j >= 0; j--) - offers[j + offset] = out_offers[j]; - - // Adjust the offer counters. - offers_left -= offers_to_retrieve; - iter_info.num_left_ -= offers_to_retrieve; - this->total_left_ -= offers_to_retrieve; - - // If we've exhausted this iterator, destroy it. - if (iter_info.num_left_ == 0) - iter_info.iter_->destroy (env); - else - this->iters_.enqueue_head (iter_info); - } - - // Determine if we have anything left to offer. - if (this->iters_.is_empty ()) - return_value = CORBA::B_FALSE; - - return return_value; -} - -void -TAO_Offer_Iterator_Collection::destroy (CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - // Destroy all iterators in the collection. - for (Offer_Iters::ITERATOR iters_iter (this->iters_); - ! iters_iter.done (); - iters_iter.advance ()) - { - Iter_Info* iter_info = 0; - - iters_iter.next (iter_info); - iter_info->iter_->destroy (_env); - } - - this->total_left_ = 0; - - // Remove self from POA - // - // Note that there is no real error checking here as we can't do - // much about errors here anyway - // - - TAO_TRY - { - PortableServer::POA_var poa = this->_default_POA (TAO_TRY_ENV); - TAO_CHECK_ENV; - PortableServer::ObjectId_var id = - poa->servant_to_id (this, TAO_TRY_ENV); - TAO_CHECK_ENV; - - poa->deactivate_object (id.in (), TAO_TRY_ENV); - } - TAO_CATCHANY - { - } - TAO_ENDTRY; - - delete this; -} - -CORBA::ULong -TAO_Offer_Iterator_Collection::max_left (CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::UnknownMaxLeft)) -{ - return this->total_left_; -} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator_Collection.h b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator_Collection.h deleted file mode 100644 index a94efca7235..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterator_Collection.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Offer_Iterator_Collection.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_OFFER_ITERATOR_COLLECTION_H -#define TAO_OFFER_ITERATOR_COLLECTION_H - -#include "orbsvcs/CosTradingS.h" - -#if defined(_MSC_VER) -#pragma warning (disable:4250) -#endif /* _MSC_VER */ - -class TAO_Offer_Iterator_Collection : public POA_CosTrading::OfferIterator -// = TITLE -// A collection of offer iterator to query in turn. -// -// = DESCRIPTION -// Since a query could conceivable query several other traders, it -// needs a way to merge the results into a single set of results -// suitable for being returned to the user. And since all the query -// method can return to the user is a sequence and an iterator, and -// the size of the sequence is constrained, there needs to be some -// way to collect all the returned offer_iterators into a single -// offer_iterator. This is that collection. The results of -// collecting all the iterators in this way is a distributed tree of -// iterators, which could conceivably become hugely inefficient if -// the trader graph is deep enough. -{ -public: - - // = Constructors. - - TAO_Offer_Iterator_Collection (void); - - virtual ~TAO_Offer_Iterator_Collection (void) {} - - virtual CORBA::Boolean next_n (CORBA::ULong n, - CosTrading::OfferSeq_out offers, - CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException)); - // Retrieve n offers from the set of iterators. - - virtual void destroy (CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)); - // Destroy the collection of iterators. - - virtual CORBA::ULong max_left (CORBA::Environment &env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::UnknownMaxLeft)); - // Determine how many offers are left in the collection. - - void add_offer_iterator (CosTrading::OfferIterator* offer_iter); - // Add an iterator to the collection. - -private: - - struct Iter_Info - { - CosTrading::OfferIterator_var iter_; - // Object reference for this iterator in the collection. - - CORBA::ULong num_left_; - // Cached value of the number of elements left in this iterator. - }; - - typedef ACE_Unbounded_Queue <Iter_Info> Offer_Iters; - - Offer_Iters iters_; - // The iterator collection. - - CORBA::ULong total_left_; - // Cached value of the number of offers left in the collection. -}; - -#endif /* TAO_OFFER_ITERATOR_COLLECTION_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterators.cpp b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterators.cpp new file mode 100644 index 00000000000..09994c9df66 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterators.cpp @@ -0,0 +1,368 @@ +/* -*- C++ -*- */ + +// ======================================================================== +// $Id$ +// +// = LIBRARY +// orbsvcs +// +// = FILENAME +// Offer_Iterators.cpp +// +// = AUTHOR +// Marina Spivak <marina@cs.wustl.edu> +// Seth Widoff <sbw1@cs.wustl.edu> +// +// ======================================================================== + +#include "Offer_Iterators.h" + + // ************************************************************* + // TAO_Offer_Iterator + // ************************************************************* + +TAO_Offer_Iterator::TAO_Offer_Iterator (const TAO_Property_Filter& pfilter) + : pfilter_ (pfilter) +{ +} + +TAO_Offer_Iterator::~TAO_Offer_Iterator (void) +{ +} + +void +TAO_Offer_Iterator::destroy (CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + // Remove self from POA + // + // Note that there is no real error checking here as we can't do + // much about errors here anyway + // + + TAO_TRY + { + PortableServer::POA_var poa = this->_default_POA (TAO_TRY_ENV); + TAO_CHECK_ENV; + PortableServer::ObjectId_var id = poa->servant_to_id (this, TAO_TRY_ENV); + TAO_CHECK_ENV; + + poa->deactivate_object (id.in (), TAO_TRY_ENV); + } + TAO_CATCHANY + { + } + TAO_ENDTRY; + + delete this; +} + + // ************************************************************* + // TAO_Query_Only_Offer_Iterator + // ************************************************************* + +TAO_Query_Only_Offer_Iterator:: +TAO_Query_Only_Offer_Iterator(const TAO_Property_Filter& pfilter) + : TAO_Offer_Iterator (pfilter) +{ +} + +TAO_Query_Only_Offer_Iterator::~TAO_Query_Only_Offer_Iterator(void) +{ +} + +void +TAO_Query_Only_Offer_Iterator::add_offer (CosTrading::OfferId offer_id, + const CosTrading::Offer* offer) +{ + this->offers_.enqueue_tail ((CosTrading::Offer*) offer); + CORBA::string_free (offer_id); +} + +CORBA::ULong +TAO_Query_Only_Offer_Iterator::max_left (CORBA::Environment& _env) + TAO_THROW_SPEC((CORBA::SystemException, + CosTrading::UnknownMaxLeft)) +{ + return this->offers_.size (); +} + +CORBA::Boolean +TAO_Query_Only_Offer_Iterator::next_n (CORBA::ULong n, + CosTrading::OfferSeq_out offers, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + offers = new CosTrading::OfferSeq; + + CORBA::ULong sequence_size = this->offers_.size (); + CORBA::ULong offers_in_sequence = (n < sequence_size) ? n : sequence_size; + offers->length (offers_in_sequence); + + // populate the sequence. + for (CORBA::ULong i = 0; i < offers_in_sequence; i++) + { + CosTrading::Offer *source = 0; + CosTrading::Offer& destination = (*offers)[i]; + + this->offers_.dequeue_head (source); + this->pfilter_.filter_offer (*source, destination); + } + + return offers_in_sequence != 0; +} + + // ************************************************************* + // TAO_Offer_Iterator_Collection + // ************************************************************* + +TAO_Offer_Iterator_Collection::TAO_Offer_Iterator_Collection (void) + : total_left_ (0) +{ +} + +void +TAO_Offer_Iterator_Collection:: +add_offer_iterator (CosTrading::OfferIterator* offer_iter) +{ + Iter_Info iter_info; + + if (offer_iter != CosTrading::OfferIterator::_nil ()) + { + TAO_TRY + { + iter_info.iter_ = offer_iter; + iter_info.num_left_ = offer_iter->max_left (TAO_TRY_ENV); + TAO_CHECK_ENV; + } + TAO_CATCHANY + { + // I don't know what to do here if the offer_iterator throws + // an UnknownMaxLeft exception. + } + TAO_ENDTRY; + + this->total_left_ += iter_info.num_left_; + this->iters_.enqueue_tail (iter_info); + } +} + +CORBA::Boolean +TAO_Offer_Iterator_Collection::next_n (CORBA::ULong n, + CosTrading::OfferSeq_out offers, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::ULong offers_left = n; + CORBA::Boolean return_value = CORBA::B_TRUE; + CosTrading::OfferSeq_var out_offers; + + ACE_NEW_RETURN (offers, CosTrading::OfferSeq, return_value); + while (offers_left > 0 && ! this->iters_.is_empty ()) + { + Iter_Info iter_info; + this->iters_.dequeue_head (iter_info); + + // Determine how many offers we should retrieve from this + // iterator. + CORBA::ULong offers_to_retrieve = + (offers_left > iter_info.num_left_) + ? iter_info.num_left_ + : offers_left; + + // Retrieve the set of offers. + iter_info.iter_->next_n + (offers_to_retrieve, + CosTrading::OfferSeq_out (out_offers.out ()), + env); + + // Merge it with the passed set. + CORBA::ULong offset = offers->length (); + offers->length (out_offers->length () + offset); + for (int j = out_offers->length () - 1; j >= 0; j--) + offers[j + offset] = out_offers[j]; + + // Adjust the offer counters. + offers_left -= offers_to_retrieve; + iter_info.num_left_ -= offers_to_retrieve; + this->total_left_ -= offers_to_retrieve; + + // If we've exhausted this iterator, destroy it. + if (iter_info.num_left_ == 0) + iter_info.iter_->destroy (env); + else + this->iters_.enqueue_head (iter_info); + } + + // Determine if we have anything left to offer. + if (this->iters_.is_empty ()) + return_value = CORBA::B_FALSE; + + return return_value; +} + +void +TAO_Offer_Iterator_Collection::destroy (CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + // Destroy all iterators in the collection. + for (Offer_Iters::ITERATOR iters_iter (this->iters_); + ! iters_iter.done (); + iters_iter.advance ()) + { + Iter_Info* iter_info = 0; + + iters_iter.next (iter_info); + iter_info->iter_->destroy (_env); + } + + this->total_left_ = 0; + + // Remove self from POA + // + // Note that there is no real error checking here as we can't do + // much about errors here anyway + // + + TAO_TRY + { + PortableServer::POA_var poa = this->_default_POA (TAO_TRY_ENV); + TAO_CHECK_ENV; + PortableServer::ObjectId_var id = + poa->servant_to_id (this, TAO_TRY_ENV); + TAO_CHECK_ENV; + + poa->deactivate_object (id.in (), TAO_TRY_ENV); + } + TAO_CATCHANY + { + } + TAO_ENDTRY; + + delete this; +} + +CORBA::ULong +TAO_Offer_Iterator_Collection::max_left (CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::UnknownMaxLeft)) +{ + return this->total_left_; +} + + // ************************************************************* + // TAO_Offer_Id_Iterator + // ************************************************************* + + +TAO_Offer_Id_Iterator::TAO_Offer_Id_Iterator (void) +{ +} + +TAO_Offer_Id_Iterator::~TAO_Offer_Id_Iterator (void) +{ + int items_left = this->ids_.size (), + return_value = 0; + + do + { + CosTrading::OfferId offer_id = 0; + + return_value = this->ids_.dequeue_head (offer_id); + if (return_value == 0) + CORBA::string_free (offer_id); + } + while (return_value == 0); +} + +CORBA::ULong +TAO_Offer_Id_Iterator::max_left (CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::UnknownMaxLeft)) +{ + return this->ids_.size (); +} + +void +TAO_Offer_Id_Iterator::destroy (CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + // Remove self from POA + // + // Note that there is no real error checking here as we can't do + // much about errors here anyway + // + + TAO_TRY + { + PortableServer::POA_var poa = this->_default_POA (TAO_TRY_ENV); + TAO_CHECK_ENV; + + PortableServer::ObjectId_var id = poa->servant_to_id (this, TAO_TRY_ENV); + TAO_CHECK_ENV; + + poa->deactivate_object (id.in (), TAO_TRY_ENV); + } + TAO_CATCHANY + { + } + TAO_ENDTRY; + + delete this; +} + +CORBA::Boolean +TAO_Offer_Id_Iterator::next_n (CORBA::ULong n, + CosTrading::OfferIdSeq_out _ids, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + // Calculate the number of Ids to be returned in this. + int items_left = this->ids_.size(), + difference = items_left - n, + returnable_items = (difference >= 0) ? n : items_left; + CORBA::Boolean return_value = (CORBA::Boolean) (difference > 0); + + if (returnable_items == 0) + { + ACE_NEW_RETURN (_ids, CosTrading::OfferIdSeq, return_value); + } + else + { + // Allocate space for the returned OfferIds. + CosTrading::OfferId* id_buf = + CosTrading::OfferIdSeq::allocbuf (returnable_items); + + if (id_buf != 0) + { + // Copy in those ids! + for (int i = 0; i < returnable_items; i++) + { + CosTrading::OfferId offer_id = 0; + + this->ids_.dequeue_head (offer_id); + id_buf[i] = offer_id; + } + + // Place them into an OfferIdSeq. + ACE_NEW_RETURN (_ids, + CosTrading::OfferIdSeq (returnable_items, + returnable_items, + id_buf, + 1), + return_value); + } + else + ACE_NEW_RETURN (_ids, CosTrading::OfferIdSeq, return_value); + } + + // Return true only if there are items left to be returned in + // subsequent calls. + return return_value; +} + +void +TAO_Offer_Id_Iterator::insert_id (CosTrading::OfferId new_id) +{ + this->ids_.enqueue_tail (new_id); +} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterators.h b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterators.h new file mode 100644 index 00000000000..34049865dee --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterators.h @@ -0,0 +1,280 @@ +/* -*- C++ -*- */ + +// ============================================================================ +// $Id$ +// +// = LIBRARY +// orbsvcs +// +// = FILENAME +// Offer_Iterators.h +// +// = AUTHOR +// Marina Spivak <marina@cs.wustl.edu> +// Seth Widoff <sbw1@cs.wustl.edu> +// +// ============================================================================ + +#ifndef TAO_OFFER_ITERATORS_H +#define TAO_OFFER_ITERATORS_H + +#include "Trader_Utils.h" + + // ************************************************************* + // TAO_Offer_Iterator + // ************************************************************* + +class TAO_Offer_Iterator : + public POA_CosTrading::OfferIterator + // = TITLE + // This class implements CosTrading::OfferIterator IDL + // interface. + + // = DESCRIPTION + // This is an abstract base class to allow for different + // implementations of OfferIterator. + // BEGIN SPEC + // The OfferIterator interface is used to return a set of service + // offers from the query operation by enabling the service offers + // to be extracted by successive operations on the OfferIterator + // interface. + // END SPEC +{ +public: + // = Initialization and termination methods. + + TAO_Offer_Iterator (const TAO_Property_Filter& property_filter); + + virtual ~TAO_Offer_Iterator (void); + + virtual void destroy (CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)); + // BEGIN SPEC + // The destroy operation destroys the iterator. No further + // operations can be invoked on an iterator after it has been + // destroyed. + // END SPEC + + virtual void add_offer (CosTrading::OfferId offer_id, + const CosTrading::Offer* offer) = 0; + // Add an offer to the collection of offers the iterator will + // iterate over. + + virtual CORBA::ULong max_left (CORBA::Environment &env) = 0 + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::UnknownMaxLeft)); + + // BEGIN SPEC + // The max_left operation returns the number of service offers + // remaining in the iterator. The exception UnknownMaxLeft is raised + // if the iterator cannot determine the remaining number of service + // offers (e.g., if the iterator determines its set of service + // offers through lazy evaluation). + // END SPEC + + virtual CORBA::Boolean next_n (CORBA::ULong n, + CosTrading::OfferSeq_out offers, + CORBA::Environment &env) = 0 + TAO_THROW_SPEC ((CORBA::SystemException)); + // BEGIN SPEC + // The next_n operation returns a set of service offers in the + // output parameter "offers." The operation returns n service offers + // if there are at least n service offers remaining in the + // iterator. If there are fewer than n service offers in the + // iterator, then all remaining service offers are returned. The + // actual number of service offers returned can be determined from + // the length of the "offers" sequence. The next_n operation returns + // TRUE if there are further service offers to be extracted from the + // iterator. It returns FALSE if there are no further service offers + // to be extracted. + // END SPEC + protected: + + TAO_Property_Filter pfilter_; +}; + + // ************************************************************* + // TAO_Query_Only_Offer_Iterator + // ************************************************************* + +class TAO_Query_Only_Offer_Iterator + : public TAO_Offer_Iterator + // = TITLE + // An implementation of the CosTrading::OfferIterator IDL + // interface that takes advantage of the fact that the trader is + // Query Only, and therefore its service offers are not being + // changed or removed. + // + // = DESCRIPTION + // The iterator stores pointers to Offers to be iterated over, + // and later accesses the Offers directly through the pointers. + // +{ +public: + // = Initialization and termination methods. + + TAO_Query_Only_Offer_Iterator (const TAO_Property_Filter& pfilter); + + virtual ~TAO_Query_Only_Offer_Iterator (void); + + virtual CORBA::Boolean next_n (CORBA::ULong n, + CosTrading::OfferSeq_out offers, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)); + // Deposit at maximum n offers into the return sequence and return 1, + // or return 0 if the iterator is done and no offers are returned. + + virtual CORBA::ULong max_left (CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::UnknownMaxLeft)); + // Return the number of items left in the iterator. + + void add_offer (CosTrading::OfferId offer_id, + const CosTrading::Offer* offer); + // Add an offer the iterator should iterate over. + +private: + + ACE_Unbounded_Queue <CosTrading::Offer *> offers_; + // Structure that stores pointers to offers + // to iterate over. +}; + + // ************************************************************* + // TAO_Offer_Iterator_Collection + // ************************************************************* + +class TAO_Offer_Iterator_Collection : public POA_CosTrading::OfferIterator +// = TITLE +// A collection of offer iterator to query in turn. +// +// = DESCRIPTION +// Since a query could conceivable query several other traders, it +// needs a way to merge the results into a single set of results +// suitable for being returned to the user. And since all the query +// method can return to the user is a sequence and an iterator, and +// the size of the sequence is constrained, there needs to be some +// way to collect all the returned offer_iterators into a single +// offer_iterator. This is that collection. The results of +// collecting all the iterators in this way is a distributed tree of +// iterators, which could conceivably become hugely inefficient if +// the trader graph is deep enough. +{ +public: + + // = Constructors. + + TAO_Offer_Iterator_Collection (void); + + virtual ~TAO_Offer_Iterator_Collection (void) {} + + virtual CORBA::Boolean next_n (CORBA::ULong n, + CosTrading::OfferSeq_out offers, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + // Retrieve n offers from the set of iterators. + + virtual void destroy (CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)); + // Destroy the collection of iterators. + + virtual CORBA::ULong max_left (CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::UnknownMaxLeft)); + // Determine how many offers are left in the collection. + + void add_offer_iterator (CosTrading::OfferIterator* offer_iter); + // Add an iterator to the collection. + +private: + + struct Iter_Info + { + CosTrading::OfferIterator_var iter_; + // Object reference for this iterator in the collection. + + CORBA::ULong num_left_; + // Cached value of the number of elements left in this iterator. + }; + + typedef ACE_Unbounded_Queue <Iter_Info> Offer_Iters; + + Offer_Iters iters_; + // The iterator collection. + + CORBA::ULong total_left_; + // Cached value of the number of offers left in the collection. +}; + + // ************************************************************* + // TAO_Offer_Id_Iterator + // ************************************************************* + +class TAO_Offer_Id_Iterator : public POA_CosTrading::OfferIdIterator +// = TITLE +// Silly little iterator that contains the overflow of offer ids +// from the Admin list_offers method. +// +// = DESCRIPTION +// +// BEGIN SPEC +// The OfferIdIterator interface is used to return a set of offer +// identifiers from the list_offers operation and the list_proxies +// operation in the Admin interface by enabling the offer identifiers +// to be extracted by successive operations on the OfferIdIterator +// interface. +// END SPEC +{ + public: + + TAO_Offer_Id_Iterator(void); + // No op constructor + + ~TAO_Offer_Id_Iterator (void); + + virtual CORBA::ULong max_left(CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::UnknownMaxLeft)); + // The max_left operation returns the number of offer identifiers + // remaining in the iterator. The exception UnknownMaxLeft is raised + // if the iterator cannot determine the remaining number of offer + // identifiers (e.g., if the iterator determines its set of offer + // identifiers through lazy evaluation). + + virtual void destroy(CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException)); + // The destroy operation destroys the iterator. No further + // operations can be invoked on an iterator after it has been + // destroyed. + + virtual CORBA::Boolean next_n(CORBA::ULong _n, + CosTrading::OfferIdSeq_out _ids, + CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException)); + // The next_n operation returns a set of offer identifiers in the + // output parameter "ids." The operation returns n offer identifiers + // if there are at least n offer identifiers remaining in the + // iterator. If there are fewer than n offer identifiers in the + // iterator, then all remaining offer identifiers are returned. The + // actual number of offer identifiers returned can be determined + // from the length of the "ids" sequence. The next_n operation + // returns TRUE if there are further offer identifiers to be + // extracted from the iterator. It returns FALSE if there are no + // further offer identifiers to be extracted. + + void insert_id(CosTrading::OfferId new_id); + // Insert a <new_id> into the contents of the iterator. + + private: + + typedef ACE_Unbounded_Queue + < + CosTrading::OfferId + > + Offer_Id_Queue; + + + Offer_Id_Queue ids_; +}; + +#endif /* TAO_OFFER_ITERATOR */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Register_Offer_Iterator.cpp b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterators_T.cpp index a8f1ee84628..8cafb670300 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Register_Offer_Iterator.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterators_T.cpp @@ -7,7 +7,7 @@ // orbsvcs // // = FILENAME -// Register_Offer_Iterator.cpp +// Offer_Iterators_T.cpp // // = AUTHOR // Marina Spivak <marina@cs.wustl.edu> @@ -15,10 +15,10 @@ // Irfan Pyarali <irfan@cs.wustl.edu> // ============================================================================ -#if !defined (TAO_REGISTER_OFFER_ITERATOR_C) -#define TAO_REGISTER_OFFER_ITERATOR_C +#if !defined (TAO_OFFER_ITERATORS_T_C) +#define TAO_OFFER_ITERATORS_T_C -#include "Register_Offer_Iterator.h" +#include "Offer_Iterators_T.h" template <class TRADER> TAO_Register_Offer_Iterator<TRADER>:: @@ -68,8 +68,8 @@ TAO_Register_Offer_Iterator<TRADER>::next_n (CORBA::ULong n, CORBA::ULong ret_offers = 0; // Get service type map (monitor object). - TRADER::Service_Type_Map &service_type_map = - this->trader_.service_type_map (); + TRADER::Offer_Database &offer_database = + this->trader_.offer_database (); CORBA::ULong max_possible_offers_in_sequence = (n < this->offer_ids_.size ()) ? n : this->offer_ids_.size (); @@ -90,7 +90,7 @@ TAO_Register_Offer_Iterator<TRADER>::next_n (CORBA::ULong n, { CosTrading::OfferId_var offerid_var (id); CosTrading::Offer* offer = - service_type_map.lookup_offer (id, TAO_TRY_ENV); + offer_database.lookup_offer (id, TAO_TRY_ENV); TAO_CHECK_ENV; if (offer != 0) diff --git a/TAO/orbsvcs/orbsvcs/Trader/Register_Offer_Iterator.h b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterators_T.h index 0f16a7287e9..f978e34ccda 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Register_Offer_Iterator.h +++ b/TAO/orbsvcs/orbsvcs/Trader/Offer_Iterators_T.h @@ -7,7 +7,7 @@ // orbsvcs // // = FILENAME -// Register_Offer_Iterator.h +// Offer_Iterators_T.h // // = AUTHOR // Marina Spivak <marina@cs.wustl.edu> @@ -18,7 +18,7 @@ #ifndef TAO_REGISTER_OFFER_ITERATOR_H #define TAO_REGISTER_OFFER_ITERATOR_H -#include "Offer_Iterator.h" +#include "Offer_Iterators.h" template <class TRADER> class TAO_Register_Offer_Iterator : public TAO_Offer_Iterator @@ -73,7 +73,7 @@ private: #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Register_Offer_Iterator.cpp" +#include "Offer_Iterators_T.cpp" #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ #endif /* TAO_REGISTER_OFFER_ITERATOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Modifier.cpp b/TAO/orbsvcs/orbsvcs/Trader/Offer_Modifier.cpp deleted file mode 100644 index d1821138a87..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Offer_Modifier.cpp +++ /dev/null @@ -1,143 +0,0 @@ -// $Id$ - -#include "Offer_Modifier.h" - -TAO_Offer_Modifier:: -TAO_Offer_Modifier (const char* type_name, - CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct, - CosTrading::Offer& offer) - : offer_ (offer), - type_ (type_name) -{ - CosTrading::PropertySeq& prop_seq = this->offer_.properties; - CosTradingRepos::ServiceTypeRepository::PropStructSeq& - pstructs = type_struct->props; - int pstructs_length = pstructs.length (), - props_length = prop_seq.length (); - - // Separate the type defined properties into mandatory and readonly - for (int i = 0; i < pstructs_length; i++) - { - if (pstructs[i].mode == - CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY) - { - TAO_String_Hash_Key prop_name ((const char *) pstructs[i].name); - this->mandatory_.insert (prop_name); - } - else if (pstructs[i].mode == - CosTradingRepos::ServiceTypeRepository::PROP_READONLY) - { - TAO_String_Hash_Key prop_name ((const char *) pstructs[i].name); - this->readonly_.insert (prop_name); - } - } - - // Insert the properties of the offer into a map. - for (i = 0; i < props_length; i++) - { - TAO_String_Hash_Key prop_name = (const char*) prop_seq[i].name; - this->props_.bind (prop_name, &prop_seq[i]); - } -} - -void -TAO_Offer_Modifier:: -delete_properties (const CosTrading::PropertyNameSeq& deletes, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Register::UnknownPropertyName, - CosTrading::Register::MandatoryProperty, - CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName)) -{ - Prop_Names delete_me; - // Validate that the listed property names can be deleted - for (int i = 0, length = deletes.length (); i < length; i++) - { - const char* dname = (const char *) deletes[i]; - if (! TAO_Trader_Base::is_valid_identifier_name (dname)) - TAO_THROW (CosTrading::IllegalPropertyName (dname)); - else - { - TAO_String_Hash_Key prop_name (dname); - if (this->mandatory_.find (prop_name) == 0) - TAO_THROW (CosTrading::Register::MandatoryProperty (this->type_, dname)); - else if (delete_me.insert (prop_name) == 1) - TAO_THROW (CosTrading::DuplicatePropertyName (dname)); - else if (this->props_.find (prop_name) == 0) - TAO_THROW (CosTrading::Register::UnknownPropertyName (dname)); - } - } - - // Delete those properties from the offer. - for (i = 0; i < length; i++) - { - TAO_String_Hash_Key prop_name = (const char *) deletes[i]; - this->props_.unbind (prop_name); - } -} - -void -TAO_Offer_Modifier:: -merge_properties (const CosTrading::PropertySeq& modifies, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName, - CosTrading::Register::ReadonlyProperty)) -{ - Prop_Names modify_me; - // Ensure that the proposed changes aren't to readonly properties or - // otherwise invalid. - for (int i = 0, length = modifies.length (); i < length; i++) - { - const char* mname =(const char *) modifies[i].name; - if (! TAO_Trader_Base::is_valid_identifier_name (mname)) - TAO_THROW (CosTrading::IllegalPropertyName (mname)); - else - { - TAO_String_Hash_Key prop_name (mname); - if (this->readonly_.find (prop_name) == 0 && - this->props_.find (prop_name) == 0) - TAO_THROW (CosTrading::Register::ReadonlyProperty (this->type_, mname)); - else if (modify_me.insert (prop_name) == 1) - TAO_THROW (CosTrading::DuplicatePropertyName (mname)); - } - } - - for (i = 0; i < length; i++) - { - // Add a property to the destination if it doesn't already exist. - Props::ENTRY* existing_entry = 0; - TAO_String_Hash_Key prop_name ((const char*) modifies[i].name); - - if (this->props_.bind (prop_name, - (CosTrading::Property *) &modifies[i], - existing_entry) == 1) - { - // Modify a property if it already exists in the destination. - CosTrading::Property* prop = existing_entry->int_id_; - prop->value = modifies[i].value; - } - } -} - -CosTrading::Offer& -TAO_Offer_Modifier::affect_change (void) -{ - int elem = 0; - CosTrading::PropertySeq prop_seq; - - // Create a new property list reflecting the deletes, modifies, and - // add operations performed, and place this property list in the - // offer. - prop_seq.length (this->props_.current_size ()); - for (Props::iterator props_iter (this->props_); - ! props_iter.done (); - props_iter++, elem++) - { - prop_seq[elem] = *(*props_iter).int_id_; - } - - this->offer_.properties = prop_seq; - return this->offer_; -} - diff --git a/TAO/orbsvcs/orbsvcs/Trader/Offer_Modifier.h b/TAO/orbsvcs/orbsvcs/Trader/Offer_Modifier.h deleted file mode 100644 index ef0c7a3cf74..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Offer_Modifier.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Offer_Modifier -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef ACE_OFFER_MODIFIER_H -#define ACE_OFFER_MODIFIER_H - -#include "Trader.h" -#include "ace/Containers.h" - -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. -}; - -#endif /* TAO_OFFER_MODIFIER_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Policies.cpp b/TAO/orbsvcs/orbsvcs/Trader/Policies.cpp deleted file mode 100644 index 8fd299deb0b..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Policies.cpp +++ /dev/null @@ -1,501 +0,0 @@ -// $Id$ - -#include "Policies.h" - -const char* TAO_Policies::POLICY_NAMES[] = -{ - "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" -}; - -TAO_Policies::TAO_Policies (TAO_Trader_Base& trader, - const CosTrading::PolicySeq& policies, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPolicyName, - CosTrading::DuplicatePolicyName)) - : trader_ (trader) -{ - for (int i = 0; i < TAO_NUM_POLICIES; i++) - this->policies_[i] = 0; - - for (CORBA::ULong j = 0; j < policies.length (); j++) - { - const char* pol_name = (const char*) policies[j].name; - size_t length = (pol_name == 0) ? 0 : ACE_OS::strlen (pol_name), - index = -1; - - if (length < ACE_OS::strlen (POLICY_NAMES[HOP_COUNT])) - TAO_THROW (CosTrading::Lookup::IllegalPolicyName (pol_name)); - - switch (pol_name[0]) - { - case 'e': - index = EXACT_TYPE_MATCH; - break; - case 'h': - index = HOP_COUNT; - break; - case 'l': - index = LINK_FOLLOW_RULE; - break; - case 'm': - index = MATCH_CARD; - break; - case 'r': - if (pol_name[2] == 't') - index = RETURN_CARD; - else if (pol_name[2] == 'q') - index = REQUEST_ID; - break; - case 's': - if (pol_name[1] == 't') - index == STARTING_TRADER; - else if (pol_name[1] == 'e') - index = SEARCH_CARD; - break; - case 'u': - if (pol_name[4] == 'd') - index = USE_DYNAMIC_PROPERTIES; - if (pol_name[4] == 'm') - index = USE_MODIFIABLE_PROPERTIES; - if (pol_name[4] == 'p') - index = USE_PROXY_OFFERS; - } - - // Match the name of the policy, and insert its value into the - // vector. - if (index == -1 || ::strcmp (POLICY_NAMES[index], pol_name) != 0) - TAO_THROW (CosTrading::Lookup::IllegalPolicyName (pol_name)); - else - { - if (this->policies_[index] != 0) - TAO_THROW (CosTrading::DuplicatePolicyName (pol_name)); - else - this->policies_[index] = (CosTrading::Policy *) &(policies[j]); - } - } -} - -TAO_Policies::~TAO_Policies (void) -{ -} - -CORBA::ULong -TAO_Policies::ulong_prop (POLICY_TYPE pol, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - CORBA::ULong return_value = 0, max_value; - TAO_Import_Attributes_Impl& import_attrs = - this->trader_.import_attributes (); - - // Discover the default values for each of the possible cardinality - // policies. - switch (pol) - { - case SEARCH_CARD: - return_value = import_attrs.def_search_card (); - max_value = import_attrs.max_search_card (); - break; - case MATCH_CARD: - return_value = import_attrs.def_match_card (); - max_value = import_attrs.max_match_card (); - break; - case RETURN_CARD: - return_value = import_attrs.def_return_card (); - max_value = import_attrs.max_return_card (); - break; - case HOP_COUNT: - return_value = import_attrs.def_hop_count (); - max_value = import_attrs.max_hop_count (); - break; - } - - if (this->policies_[pol] != 0) - { - // Extract the desired policy value. - CosTrading::Policy* policy = this->policies_[pol]; - CosTrading::PolicyValue& value = policy->value; - CORBA::TypeCode* type = value.type (); - - if (!type->equal (CORBA::_tc_ulong, _env)) - TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), - return_value); - else - value >>= return_value; - - if (max_value < return_value) - return_value = max_value; - } - - return return_value; -} - -CORBA::ULong -TAO_Policies::search_card (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - return this->ulong_prop (SEARCH_CARD, _env); -} - -CORBA::ULong -TAO_Policies::match_card (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - return this->ulong_prop (MATCH_CARD, _env); -} - -CORBA::ULong -TAO_Policies::return_card (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - return this->ulong_prop (RETURN_CARD, _env); -} - -CORBA::Boolean -TAO_Policies::boolean_prop (POLICY_TYPE pol, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - CORBA::Boolean def_value = CORBA::B_TRUE, - return_value = CORBA::B_TRUE; - TAO_Support_Attributes_Impl& support_attrs = - this->trader_.support_attributes (); - - switch (pol) - { - case USE_MODIFIABLE_PROPERTIES: - def_value = support_attrs.supports_modifiable_properties (); - break; - case USE_DYNAMIC_PROPERTIES: - def_value = support_attrs.supports_dynamic_properties (); - break; - case USE_PROXY_OFFERS: - def_value = support_attrs.supports_proxy_offers (); - break; - case EXACT_TYPE_MATCH: - def_value = CORBA::B_FALSE; - break; - } - - if (this->policies_[pol] != 0) - { - CosTrading::Policy* policy = this->policies_[pol]; - CosTrading::PolicyValue& value = policy->value; - CORBA::TypeCode* type = value.type (); - - if (!type->equal (CORBA::_tc_boolean, _env)) - TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), - return_value); - else - value >>= CORBA::Any::to_boolean (return_value); - - if (def_value == CORBA::B_FALSE && - pol != EXACT_TYPE_MATCH) - return_value = CORBA::B_FALSE; - } - else - return_value = def_value; - - return return_value; -} - - -CORBA::Boolean -TAO_Policies::use_modifiable_properties (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - return this->boolean_prop (USE_MODIFIABLE_PROPERTIES, _env); -} - -CORBA::Boolean -TAO_Policies::use_dynamic_properties (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - return this->boolean_prop (USE_DYNAMIC_PROPERTIES, _env); -} - -CORBA::Boolean -TAO_Policies::use_proxy_offers (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - return this->boolean_prop (USE_PROXY_OFFERS, _env); -} - -CORBA::Boolean -TAO_Policies::exact_type_match (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - return this->boolean_prop (EXACT_TYPE_MATCH, _env); -} - - -CosTrading::TraderName* -TAO_Policies::starting_trader (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue)) -{ - CosTrading::TraderName* trader_name = 0; - - if (this->policies_[STARTING_TRADER] != 0) - { - CosTrading::Policy* policy = this->policies_[STARTING_TRADER]; - CosTrading::PolicyValue& value = policy->value; - CORBA::TypeCode* type = value.type (); - - if (!type->equal (CosTrading::_tc_TraderName, _env)) - TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), - trader_name); - else - { - // ACE_NEW_RETURN (trader_name, CosTrading::TraderName, 0); - value >>= trader_name; - } - } - - return trader_name; -} - -CosTrading::FollowOption -TAO_Policies::link_follow_rule (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - CosTrading::FollowOption return_value = - this->trader_.import_attributes ().def_follow_policy (); - - if (this->policies_[LINK_FOLLOW_RULE] != 0) - { - CosTrading::FollowOption max_follow_policy = - this->trader_.import_attributes ().max_follow_policy (); - - CosTrading::Policy* policy = this->policies_[LINK_FOLLOW_RULE]; - CosTrading::PolicyValue& value = policy->value; - CORBA::TypeCode* type = value.type (); - - // Extract the link follow rule - if (!type->equal (CosTrading::_tc_FollowOption, _env)) - TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), - return_value); - else - value >>= return_value; - - if (return_value > max_follow_policy) - return_value = max_follow_policy; - } - - return return_value; -} - -CosTrading::FollowOption -TAO_Policies::link_follow_rule (const char* link_name, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch, - CosTrading::Lookup::InvalidPolicyValue, - CosTrading::Link::IllegalLinkName, - CosTrading::Link::UnknownLinkName)) -{ - CosTrading::FollowOption return_value = CosTrading::local_only; - CosTrading::Link_var link - (this->trader_.trading_components ().link_if ()); - - if (link.in() != CosTrading::Link::_nil ()) - { - CosTrading::Link::LinkInfo_var - link_info (link->describe_link (link_name, _env)); - TAO_CHECK_ENV_RETURN (_env, return_value); - CosTrading::FollowOption trader_max_follow_policy = - this->trader_.import_attributes ().max_follow_policy (); - - if (this->policies_[LINK_FOLLOW_RULE] != 0) - { - CosTrading::FollowOption query_link_follow_rule; - CosTrading::FollowOption link_limiting_follow_rule = - link_info->limiting_follow_rule; - CosTrading::Policy* policy = this->policies_[LINK_FOLLOW_RULE]; - CosTrading::PolicyValue& value = policy->value; - CORBA::TypeCode* type = value.type (); - - // Extract the link follow rule - if (!type->equal (CosTrading::_tc_FollowOption, _env)) - TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), - return_value); - else - value >>= query_link_follow_rule; - - return_value = (query_link_follow_rule < trader_max_follow_policy) - ? query_link_follow_rule : trader_max_follow_policy; - return_value = (return_value < link_limiting_follow_rule) - ? return_value : link_limiting_follow_rule; - } - else - { - CosTrading::FollowOption link_def_follow_rule = - this->trader_.import_attributes ().max_follow_policy (); - - return_value = (link_def_follow_rule < trader_max_follow_policy) - ? link_def_follow_rule : trader_max_follow_policy; - } - } - - return return_value; -} - -CORBA::ULong -TAO_Policies::hop_count (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - return this->ulong_prop (HOP_COUNT, _env); -} - -CosTrading::Admin::OctetSeq* -TAO_Policies::request_id (CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) -{ - CosTrading::Admin::OctetSeq* request_id = 0; - - if (this->policies_[REQUEST_ID] != 0) - { - CosTrading::Policy* policy = this->policies_[REQUEST_ID]; - CosTrading::PolicyValue& value = policy->value; - CORBA::TypeCode* type = value.type (); - - if (!type->equal (CosTrading::Admin::_tc_OctetSeq, _env)) - TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), - request_id); - else - { - //ACE_NEW_RETURN (request_id, CosTrading::Admin::OctetSeq, 0); - value >>= request_id; - } - } - - return request_id; -} - -CosTrading::PolicySeq* -TAO_Policies::policies_to_forward (void) -{ - // Create a new policy sequence, shortening the starting trader - // policy by one link. - - CORBA::ULong counter = 0; - CosTrading::Policy* policy_buffer = - CosTrading::PolicySeq::allocbuf (REQUEST_ID + 1); - - if (policy_buffer == 0) - return 0; - - for (int i = EXACT_TYPE_MATCH; i <= REQUEST_ID; i++) - { - CosTrading::Policy& new_policy = policy_buffer[counter]; - - if (this->policies_[i] != 0) - { - // Copy in the existing policies. - new_policy.name = this->policies_[i]->name; - - if (i == STARTING_TRADER) - { - TAO_TRY - { - // Eliminate the first link of the trader name. - CosTrading::TraderName* trader_name = - this->starting_trader (TAO_TRY_ENV); - TAO_CHECK_ENV; - - CORBA::ULong length = trader_name->length (); - - for (CORBA::ULong j = 1; j < length; j++) - trader_name[j - 1] = trader_name[j]; - trader_name->length (length - 1); - - new_policy.value <<= *trader_name; - counter++; - } - TAO_CATCHANY {} - TAO_ENDTRY; - } - else - { - new_policy.value = this->policies_[i]->value; - counter++; - } - } - } - - // Create the new sequence - return new CosTrading::PolicySeq (REQUEST_ID + 1, counter, - policy_buffer, CORBA::B_TRUE); -} - -CosTrading::PolicySeq* -TAO_Policies:: -policies_to_pass (CosTrading::FollowOption def_pass_on_follow_rule, - CORBA::ULong offers_returned, - CosTrading::Admin_ptr admin_if) -{ - // Create a new policy sequence to pass to a federated - // query. Decrement the hop count, add a stem id if none exists, and - // add a follow rule if none exists. Also adjust the return_card to - // account for previous queries. - CORBA::Environment env; - CORBA::ULong counter = 0; - CosTrading::Policy* policy_buffer = - CosTrading::PolicySeq::allocbuf (REQUEST_ID + 1); - - if (policy_buffer == 0) - return 0; - - for (int i = EXACT_TYPE_MATCH; i <= REQUEST_ID; i++) - { - CosTrading::Policy& new_policy = policy_buffer[counter]; - - if (this->policies_[i] != 0) - { - // Add an existing query. - new_policy.name = this->policies_[i]->name; - new_policy.value = this->policies_[i]->value; - } - else - { - if (i == LINK_FOLLOW_RULE) - { - // Add a link follow rule if one didn't exist. - new_policy.name = POLICY_NAMES[i]; - new_policy.value <<= def_pass_on_follow_rule; - } - else if (i == REQUEST_ID) - { - // Add the request id if one didn't exist. - new_policy.name = POLICY_NAMES[i]; - new_policy.value <<= *(admin_if->request_id_stem (env)); - } - } - - if (i == HOP_COUNT) - { - // Decrement the hop count. - new_policy.name = POLICY_NAMES[i]; - new_policy.value <<= this->hop_count (env) - 1; - } - else if (i == RETURN_CARD) - { - // Adjust the return card. - new_policy.name = POLICY_NAMES[i]; - new_policy.value <<= this->return_card (env) - offers_returned; - } - } - - // Create the new sequence. - return new CosTrading::PolicySeq (REQUEST_ID + 1, counter, - policy_buffer, CORBA::B_TRUE); -} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Policies.h b/TAO/orbsvcs/orbsvcs/Trader/Policies.h deleted file mode 100644 index 3f2b87e860c..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Policies.h +++ /dev/null @@ -1,270 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Policies.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================= - -#ifndef TAO_POLICIES_H -#define TAO_POLICIES_H - -#include "Trader.h" - -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. -}; - - -#endif /* TAO_POLICIES_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Policy_Manager.cpp b/TAO/orbsvcs/orbsvcs/Trader/Policy_Manager.cpp deleted file mode 100644 index 1c5f2495f4a..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Policy_Manager.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// $Id$ - -#include "Policy_Manager.h" - -TAO_Policy_Manager::TAO_Policy_Manager (int num_policies) - : policies_ (num_policies), - num_policies_ (0) -{ - for (int i = 0; i < TAO_Policies::REQUEST_ID + 1; i++) - this->poltable_[i] = -1; -} - -void -TAO_Policy_Manager::search_card (CORBA::ULong scard) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::SEARCH_CARD); - policy.value <<= scard; -} - -void -TAO_Policy_Manager::match_card (CORBA::ULong mcard) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::MATCH_CARD); - policy.value <<= mcard; -} - -void -TAO_Policy_Manager::return_card (CORBA::ULong rcard) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::RETURN_CARD); - policy.value <<= rcard; -} - -void -TAO_Policy_Manager::use_modifiable_properties (CORBA::Boolean mod_props) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::USE_MODIFIABLE_PROPERTIES); - policy.value <<= CORBA::Any::from_boolean (mod_props); -} - -void -TAO_Policy_Manager::use_dynamic_properties (CORBA::Boolean dyn_props) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::USE_DYNAMIC_PROPERTIES); - policy.value <<= CORBA::Any::from_boolean (dyn_props); -} - -void -TAO_Policy_Manager::use_proxy_offers (CORBA::Boolean prox_offs) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::USE_PROXY_OFFERS); - policy.value <<= CORBA::Any::from_boolean (prox_offs); -} - -void -TAO_Policy_Manager::starting_trader (CosTrading::TraderName* name) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::STARTING_TRADER); - policy.value <<= *name; -} - -void -TAO_Policy_Manager:: -link_follow_rule (CosTrading::FollowOption follow_option) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::LINK_FOLLOW_RULE); - policy.value <<= follow_option; -} - -void -TAO_Policy_Manager::hop_count (CORBA::ULong hop_count) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::HOP_COUNT); - policy.value <<= hop_count; -} - -void -TAO_Policy_Manager::exact_type_match (CORBA::Boolean exact_type) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::EXACT_TYPE_MATCH); - policy.value <<= CORBA::Any::from_boolean (exact_type); -} - -void -TAO_Policy_Manager::request_id (CosTrading::Admin::OctetSeq* request_id) -{ - CosTrading::Policy& policy = - this->fetch_next_policy (TAO_Policies::REQUEST_ID); - policy.value <<= *request_id; -} - -TAO_Policy_Manager::operator const CosTrading::PolicySeq& (void) const -{ - return this->policies_; -} - -const CosTrading::PolicySeq& -TAO_Policy_Manager::policy_seq (void) const -{ - return this->policies_; -} - -CosTrading::Policy& -TAO_Policy_Manager::fetch_next_policy (TAO_Policies::POLICY_TYPE pol_type) -{ - CORBA::ULong index = 0; - - if (this->poltable_[pol_type] == -1) - { - CORBA::ULong length = this->policies_.length (); - this->num_policies_++; - - if (length < this->num_policies_) - this->policies_.length (this->num_policies_); - - index = this->num_policies_ - 1; - this->policies_[index].name = TAO_Policies::POLICY_NAMES[pol_type]; - this->poltable_[pol_type] = index; - } - else - index = this->poltable_[pol_type]; - - return this->policies_[index]; -} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Policy_Manager.h b/TAO/orbsvcs/orbsvcs/Trader/Policy_Manager.h deleted file mode 100644 index ed2318381ca..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Policy_Manager.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// ACE_Policies.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================= - -#ifndef TAO_POLICY_MANAGER_H -#define TAO_POLICY_MANAGER_H - -#include "Policies.h" - -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_; -}; - -#endif /* TAO_POLICY_MANAGER_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Preference_Interpreter.cpp b/TAO/orbsvcs/orbsvcs/Trader/Preference_Interpreter.cpp deleted file mode 100644 index de0a723387e..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Preference_Interpreter.cpp +++ /dev/null @@ -1,164 +0,0 @@ -// Preference_Interpreter.cpp - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Preference_Interpreter.cpp -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#include "Preference_Interpreter.h" -#include <stdio.h> - -const CORBA::Double TRADER_MAX_DOUBLE = 1.79769313486231570e+308; - -TAO_Preference_Interpreter:: -TAO_Preference_Interpreter(CosTradingRepos::ServiceTypeRepository::TypeStruct* ts, - const char* preference, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPreference)) - : TAO_Interpreter () -{ - TAO_Constraint_Validator type_checker(ts); - - if (TAO_Interpreter::is_empty_string(preference)) - this->root_ = new TAO_Noop_Constraint(TAO_FIRST); - else - { - if (this->build_tree (preference) != 0) - TAO_THROW (CosTrading::Lookup::IllegalPreference (preference)); - - if (type_checker.validate (this->root_) == -1) - TAO_THROW (CosTrading::Lookup::IllegalPreference (preference)); - } -} - -TAO_Preference_Interpreter:: -TAO_Preference_Interpreter(TAO_Constraint_Validator& validator, - const char* preference, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPreference)) - : TAO_Interpreter () -{ - if (TAO_Interpreter::is_empty_string(preference)) - this->root_ = new TAO_Noop_Constraint(TAO_FIRST); - else - { - if (this->build_tree (preference) != 0) - TAO_THROW (CosTrading::Lookup::IllegalPreference (preference)); - - if (validator.validate (this->root_) == -1) - TAO_THROW (CosTrading::Lookup::IllegalPreference (preference)); - } -} - -TAO_Preference_Interpreter::~TAO_Preference_Interpreter() -{ -} - -void -TAO_Preference_Interpreter:: -order_offer (CosTrading::OfferId offer_id, - CosTrading::Offer* offer) -{ - TAO_Constraint_Evaluator evaluator(offer); - this->order_offer (offer_id, offer, evaluator); -} - -void -TAO_Preference_Interpreter:: -order_offer (CosTrading::OfferId offer_id, - CosTrading::Offer* offer, - TAO_Constraint_Evaluator& evaluator) -{ - if (this->root_ != 0) - { - Preference_Info pref_info; - TAO_Expression_Type expr_type = this->root_->expr_type (); - - pref_info.offer_ = offer; - pref_info.offer_id_ = offer_id; - pref_info.evaluated_ = CORBA::B_TRUE; - - if (evaluator.evaluate_preference (this->root_, pref_info.value_) == 0) - { - // If the evaluation succeeds, insert the node into the - // correct place in the queue. - TAO_Expression_Type expr_type = this->root_->expr_type (); - - if (expr_type == TAO_FIRST) - this->offers_.enqueue_tail (pref_info); - else - this->offers_.enqueue_head (pref_info); - - if (expr_type == TAO_MIN || expr_type == TAO_MAX) - { - Ordered_Offers::ITERATOR offer_iter (this->offers_); - - // Push the new item down the list until the min/max - // criterion is satisfied. Observe the evaluation - // failed / evaluation suceeded partion in the list. - offer_iter.advance (); - for (int i = 1; - ! offer_iter.done (); - offer_iter.advance (), i++) - { - Preference_Info* current_offer; - offer_iter.next (current_offer); - - // Maintain the sorted order in the first partition. - if (current_offer->evaluated_ == CORBA::B_TRUE && - ((expr_type == TAO_MIN && - pref_info.value_ > current_offer->value_) || - (expr_type == TAO_MAX && - pref_info.value_ < current_offer->value_))) - { - this->offers_.set (*current_offer, i - 1); - this->offers_.set (pref_info, i); - } - else - break; - } - } - } - else - { - // If the evaluation fails, just tack the sucker onto the - // end of the queue. - pref_info.evaluated_ = CORBA::B_FALSE; - this->offers_.enqueue_tail (pref_info); - } - } -} - -int -TAO_Preference_Interpreter:: -remove_offer (CosTrading::OfferId& offer_id, - CosTrading::Offer*& offer) -{ - int return_value = -1; - Preference_Info pref_info; - - return_value = this->offers_.dequeue_head (pref_info); - - if (return_value == 0) - { - offer = pref_info.offer_; - offer_id = pref_info.offer_id_; - } - - return return_value; -} - -int -TAO_Preference_Interpreter::num_offers(void) -{ - return this->offers_.size(); -} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Preference_Interpreter.h b/TAO/orbsvcs/orbsvcs/Trader/Preference_Interpreter.h deleted file mode 100644 index c9a24c16908..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Preference_Interpreter.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Preference_Interpreter.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_PREFERENCE_INTERPRETER_H -#define TAO_PREFERENCE_INTERPRETER_H - -#include "Interpreter.h" -#include "Constraint_Evaluator.h" -#include "Constraint_Validator.h" - -class TAO_Preference_Interpreter : public TAO_Interpreter -// = TITLE -// The TAO_Preference_Interpreter will, given a valid preference -// string and offers, will order the offers based on the offers' -// compliance with the preferences. -// -// = DESCRIPTION -// Each time the order_offer method is invoked, the -// TAO_Preference_Interpreter stores the offer reference in the -// order dictated by its evaluation of the preference string. After -// the TAO_Preference_Interpreter client has finished ordering all -// the offers, it will extract the offers in order using the -// remove_offer method. -{ -public: - - TAO_Preference_Interpreter(CosTradingRepos::ServiceTypeRepository::TypeStruct* ts, - const char* preference, - CORBA::Environment& env) - TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPreference)); - - TAO_Preference_Interpreter(TAO_Constraint_Validator& validator, - const char* preference, - CORBA::Environment& env) - TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPreference)); - - // Parse the preference string, determining first if it's - // valid. Throw an IllegalPreference exception if the preference - // doesn't conform to the BNF grammar for preferences. - - ~TAO_Preference_Interpreter(void); - // Destructor - - void order_offer (CosTrading::OfferId offer_id, - CosTrading::Offer* offer); - - void order_offer (CosTrading::OfferId offer_id, - CosTrading::Offer* offer, - TAO_Constraint_Evaluator& evaluator); - // Evaluate the offer, and order it internally based on the results - // of the evaluation. - - int remove_offer (CosTrading::OfferId& offer_id, - CosTrading::Offer*& offer); - // Remove the next offer. The offer returned will be the next in the - // ordering determined by the preference string. - - int num_offers(void); - // Return the number of offers remaining in the ordering. - -private: - - struct Preference_Info - { - CORBA::Boolean evaluated_; - TAO_Literal_Constraint value_; - CosTrading::OfferId offer_id_; - CosTrading::Offer* offer_; - }; - - typedef ACE_Unbounded_Queue<Preference_Info> Ordered_Offers; - - Ordered_Offers offers_; -}; - -#endif /* TAO_PREFERENCE_INTERPRETER_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.cpp b/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.cpp deleted file mode 100644 index dc7161574e5..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.cpp +++ /dev/null @@ -1,223 +0,0 @@ -// File: Property_Evaluator.cpp -// $Id$ - -#include "Trader.h" -#include "Property_Evaluator.h" - -// Constructor - -TAO_Property_Evaluator:: -TAO_Property_Evaluator(const CosTrading::PropertySeq& props, - CORBA::Boolean supports_dp) - : props_ (props), - supports_dp_ (supports_dp) -{ -} - - -TAO_Property_Evaluator:: -TAO_Property_Evaluator(CosTrading::Offer& offer, - CORBA::Boolean supports_dp) - : props_ (offer.properties), - supports_dp_ (supports_dp) -{ -} - -int -TAO_Property_Evaluator::is_dynamic_property (int index) -{ - CORBA::Environment env; - int return_value = 0, - num_properties = this->props_.length(); - - // Ensure index is in bounds. - if (index >= 0 && index < num_properties) - { - // Obtain the value of the property at index <index>. - const CORBA::Any& value = this->props_[index].value; - CORBA::TypeCode* type = value.type (); - - if (type->equal (CosTradingDynamic::_tc_DynamicProp, env)) - return_value = 1; - } - - return return_value; -} - - -CORBA::Any* -TAO_Property_Evaluator::property_value(int index, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTradingDynamic::DPEvalFailure)) -{ - CORBA::Any* prop_val = 0; - - if (! this->is_dynamic_property(index)) - prop_val = (CORBA::Any *) &(this->props_[index].value); - else if (this->supports_dp_) - { - // Property is defined at this point. - DP_Eval* dp_eval; - CosTradingDynamic::DynamicProp* dp_struct; - const CORBA::String_var name = this->props_[index].name; - const CORBA::Any& value = this->props_[index].value; - - // Extract the DP_Struct. - value >>= dp_struct; - -#if defined TAO_HAS_DYNAMIC_PROPERTY_BUG - CORBA::ORB_ptr orb = TAO_ORB_Core_instance ()->orb (); - CORBA::Object_ptr obj = orb->string_to_object (dp_struct->eval_if, _env); - TAO_CHECK_ENV_RETURN (_env, 0); - dp_eval = CosTradingDynamic::DynamicPropEval::_narrow (obj, _env); - TAO_CHECK_ENV_RETURN (_env, 0); -#else - dp_eval = dp_struct->eval_if; -#endif /* TAO_HAS_DYNAMIC_PROPERTY_BUG */ - - if (CORBA::is_nil (dp_eval)) - TAO_THROW_RETURN (CosTradingDynamic::DPEvalFailure (), prop_val); - else - { - CORBA::TypeCode* type = dp_struct->returned_type; - CORBA::Any& info = dp_struct->extra_info; - - TAO_TRY - { - // Retrieve the value of the dynamic property. - prop_val = dp_eval->evalDP(name, type, info, TAO_TRY_ENV); - TAO_CHECK_ENV; - } - TAO_CATCH (CORBA::SystemException, excp) - { - TAO_THROW_RETURN - (CosTradingDynamic::DPEvalFailure (name, type, info), - prop_val); - } - TAO_ENDTRY; - } - } - - return prop_val; -} - -CORBA::TypeCode* -TAO_Property_Evaluator::property_type(int index) -{ - CORBA::TypeCode* prop_type = CORBA::TypeCode::_nil(); - - // Determine if property is both defined and dynamic. - if (this->is_dynamic_property (index)) - { - // Extract type information from the DP_Struct. - const CORBA::Any& value = this->props_[index].value; - CosTradingDynamic::DynamicProp* dp_struct; - value >>= dp_struct; - - // Grab a pointer to the returned_type description - prop_type = CORBA::TypeCode::_duplicate(dp_struct->returned_type); - } - else - // TypeCode is self-evident at this point. - prop_type = this->props_[index].value.type(); - - return prop_type; -} - -TAO_Property_Evaluator_By_Name:: -TAO_Property_Evaluator_By_Name (const CosTrading::PropertySeq& properties, - CORBA::Environment& _env, - CORBA::Boolean supports_dp) - TAO_THROW_SPEC ((CosTrading::DuplicatePropertyName, - CosTrading::IllegalPropertyName)) - : TAO_Property_Evaluator (properties, supports_dp) -{ - int length = this->props_.length(); - - for (int i = 0; i < length; i++) - { - const CosTrading::Property& prop = this->props_[i]; - - if (! TAO_Trader_Base::is_valid_identifier_name (prop.name)) - TAO_THROW (CosTrading::IllegalPropertyName (prop.name)); - - TAO_String_Hash_Key prop_name = prop.name; - if (this->table_.bind (prop_name, i)) - TAO_THROW (CosTrading::DuplicatePropertyName (prop.name)); - } -} - -TAO_Property_Evaluator_By_Name:: -TAO_Property_Evaluator_By_Name(CosTrading::Offer& offer, - CORBA::Boolean supports_dp) - : TAO_Property_Evaluator(offer, supports_dp) -{ - int length = this->props_.length(); - - for (int i = 0; i < length; i++) - { - TAO_String_Hash_Key prop_name = (const char*) this->props_[i].name; - this->table_.bind (prop_name, i); - } -} - -int -TAO_Property_Evaluator_By_Name:: -is_dynamic_property(const char* property_name) -{ - int predicate = 0, index = 0; - TAO_String_Hash_Key prop_name (property_name); - - // If the property name is in the map, delegate evaluation to our - // superclass. Otherwise, throw an exception. - if (this->table_.find (prop_name, index) == 0) - predicate = this->TAO_Property_Evaluator::is_dynamic_property(index); - - return predicate; -} - -CORBA::Any* -TAO_Property_Evaluator_By_Name::property_value (const char* property_name, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTradingDynamic::DPEvalFailure)) -{ - int index = 0; - CORBA::Any* prop_value = 0; - TAO_String_Hash_Key prop_name (property_name); - - // If the property name is in the map, delegate evaluation to our - // superclass. Otherwise, throw an exception. - if (this->table_.find (prop_name, index) == 0) - prop_value = this->TAO_Property_Evaluator::property_value (index, _env); - - return prop_value; -} - -CORBA::TypeCode* -TAO_Property_Evaluator_By_Name::property_type (const char* property_name) -{ - int index = 0; - TAO_String_Hash_Key prop_name (property_name); - CORBA::TypeCode* prop_type = CORBA::TypeCode::_nil(); - - // If the property name is in the map, delegate evaluation to our - // superclass. Otherwise, throw an exception. - if (this->table_.find (prop_name, index) == 0) - prop_type = this->TAO_Property_Evaluator::property_type (index); - - return prop_type; -} - -const CosTrading::Property* -TAO_Property_Evaluator_By_Name::get_property (const char* property_name) -{ - int index = 0; - CosTrading::Property* property = 0; - TAO_String_Hash_Key prop_name (property_name); - - if (this->table_.find (prop_name, index) == 0) - property = (CosTrading::Property *) &this->props_[index]; - - return property; -} - diff --git a/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.h b/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.h deleted file mode 100644 index f95fa7acdda..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.h +++ /dev/null @@ -1,145 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Property_Evaluator.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_PROPERTY_EVALUATOR_H -#define TAO_PROPERTY_EVALUATOR_H - -#include "Trader.h" - -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_; -}; - -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. -}; - -#endif /* TAO_PROPERTY_EVALUATOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Property_Filter.cpp b/TAO/orbsvcs/orbsvcs/Trader/Property_Filter.cpp deleted file mode 100644 index a2221e579ca..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Property_Filter.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// $Id$ - -#include "Property_Filter.h" - -TAO_Property_Filter:: -TAO_Property_Filter (const SPECIFIED_PROPS& desired_props, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, - CosTrading::DuplicatePropertyName)) - : policy_ (desired_props._d ()) -{ - if (this->policy_ == CosTrading::Lookup::some) - { - ACE_DEBUG ((LM_DEBUG, "Filter: policy == some\n")); - const CosTrading::PropertyNameSeq& - prop_seq = desired_props.prop_names (); - int length = prop_seq.length (); - - for (int i = 0; i < length; i++) - { - const char* pname = prop_seq[i]; - - // Check for errors or duplicates - if (TAO_Trader_Base::is_valid_identifier_name (pname)) - { - // Insert returns a pair whose second element is a flag - // indicating whether a collision occured. - TAO_String_Hash_Key prop_name (pname); - if (this->props_.insert (prop_name) == 1) - { - ACE_DEBUG ((LM_DEBUG, "Filter: Inserted %s\n", pname)); - TAO_THROW (CosTrading::DuplicatePropertyName (pname)); - } - } - else - TAO_THROW (CosTrading::IllegalPropertyName (pname)); - } - } -} - -TAO_Property_Filter:: -TAO_Property_Filter (const TAO_Property_Filter& prop_filter) - : props_ (prop_filter.props_), - policy_ (prop_filter.policy_) -{ -} - -void -TAO_Property_Filter::filter_offer (CosTrading::Offer& source, - CosTrading::Offer& destination) -{ - Prop_Queue prop_queue; - CosTrading::PropertySeq& s_props = source.properties; - CosTrading::PropertySeq& d_props = destination.properties; - int length = s_props.length (), elem = 0; - - destination.reference = source.reference->_duplicate (source.reference); - if (this->policy_ != CosTrading::Lookup::none) - { - for (int i = 0; i < length; i++) - { - if (this->policy_ == CosTrading::Lookup::all) - prop_queue.enqueue_tail (&s_props[i]); - else - { - TAO_String_Hash_Key prop_name ((const char*) s_props[i].name); - - // Save those property that match. - if (this->props_.find (prop_name) == 0) - prop_queue.enqueue_tail (&s_props[i]); - } - } - - // Shove the matched properties into the destination property - // sequence. - length = prop_queue.size (); - d_props.length (prop_queue.size ()); - for (Prop_Queue::ITERATOR prop_iter (prop_queue); - ! prop_iter.done (); - prop_iter.advance (), elem++) - { - CosTrading::Property** prop_ptr = 0; - - prop_iter.next (prop_ptr); - d_props[elem] = **prop_ptr; - } - } -} - -int -TAO_Property_Filter::verify_property_name (const char* name) -{ - int return_value = -1, - length = ACE_OS::strlen (name); - - if (length >= 1 && isalpha (name[0])) - { - for (int i = 0; i < length; i++) - { - if (! (isalnum (name[i]) || name[i] == '_')) - break; - } - - return_value = 0; - } - - return return_value; -} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Property_Filter.h b/TAO/orbsvcs/orbsvcs/Trader/Property_Filter.h deleted file mode 100644 index 577a51d3f7d..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Property_Filter.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Property_Filter.h -// -// = AUTHOR -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================= - -#ifndef TAO_PROPERTY_FILTER_H -#define TAO_PROPERTY_FILTER_H - -#include "Trader.h" - -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; - - int verify_property_name (const char* name); - - Prop_Names props_; - CosTrading::Lookup::HowManyProps policy_; -}; - -#endif /* TAO_PROPERTY_FILTER_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Proxy.cpp b/TAO/orbsvcs/orbsvcs/Trader/Proxy.cpp deleted file mode 100644 index 0e9e17a82ef..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Proxy.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- C++ -*- */ - -// ============================================================================ -// $Id$ -// -// = LIBRARY -// Trading -// -// = FILENAME -// Proxy.cpp -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ============================================================================ - -#if !defined (TAO_PROXY_C) -#define TAO_PROXY_C - -#include "Proxy.h" - -template <class TRADER> -TAO_Proxy<TRADER>::TAO_Proxy (TRADER &trader) - : trader_ (trader), - TAO_Trader_Components <POA_CosTrading::Proxy> (trader.trading_components ()), - TAO_Support_Attributes <POA_CosTrading::Proxy> (trader.support_attributes ()) -{ -} - -template <class TRADER> -TAO_Proxy<TRADER>::~TAO_Proxy (void) -{ -} - -template <class TRADER> CosTrading::OfferId -TAO_Proxy<TRADER>::export_proxy (CosTrading::Lookup_ptr target, - const char *type, - const CosTrading::PropertySeq& properties, - CORBA::Boolean if_match_all, - const char * recipe, - const CosTrading::PolicySeq& policies_to_pass_on, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::InvalidLookupRef, - CosTrading::IllegalPropertyName, - CosTrading::PropertyTypeMismatch, - CosTrading::ReadonlyDynamicProperty, - CosTrading::MissingMandatoryProperty, - CosTrading::Proxy::IllegalRecipe, - CosTrading::DuplicatePropertyName, - CosTrading::DuplicatePolicyName)) -{ - TAO_THROW_RETURN (CORBA::UNKNOWN (CORBA::COMPLETED_NO), 0); -} - -template <class TRADER> void -TAO_Proxy<TRADER>::withdraw_proxy (const char *id, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalOfferId, - CosTrading::UnknownOfferId, - CosTrading::Proxy::NotProxyOfferId)) -{ - TAO_THROW (CORBA::UNKNOWN (CORBA::COMPLETED_NO)); -} - -template <class TRADER> CosTrading::Proxy::ProxyInfo * -TAO_Proxy<TRADER>::describe_proxy (const char *id, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalOfferId, - CosTrading::UnknownOfferId, - CosTrading::Proxy::NotProxyOfferId)) -{ - TAO_THROW_RETURN (CORBA::UNKNOWN (CORBA::COMPLETED_NO), 0); -} - -template <class TRADER> void -TAO_Proxy<TRADER>::list_proxies (CORBA::ULong how_many, - CosTrading::OfferIdSeq*& ids, - CosTrading::OfferIdIterator_ptr& id_itr, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::NotImplemented)) -{ - TAO_THROW (CORBA::UNKNOWN (CORBA::COMPLETED_NO)); -} - - -#endif /* TAO_PROXY_C */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Proxy.h b/TAO/orbsvcs/orbsvcs/Trader/Proxy.h deleted file mode 100644 index ab92b2affb6..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Proxy.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- C++ -*- */ - -// ======================================================================== -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Proxy.h -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Irfan Pyarali <irfan@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ======================================================================== - -#ifndef TAO_PROXY_H -#define TAO_PROXY_H - -#include "Attributes_T.h" - -template <class TRADER> -class TAO_Proxy : - public TAO_Trader_Components <POA_CosTrading::Proxy>, - public TAO_Support_Attributes <POA_CosTrading::Proxy> -{ -public: - - TAO_Proxy (TRADER &trader); - - ~TAO_Proxy (void); - - virtual CosTrading::OfferId - export_proxy (CosTrading::Lookup_ptr target, - const char *type, - const CosTrading::PropertySeq& properties, - CORBA::Boolean if_match_all, - const char * recipe, - const CosTrading::PolicySeq& policies_to_pass_on, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::InvalidLookupRef, - CosTrading::IllegalPropertyName, - CosTrading::PropertyTypeMismatch, - CosTrading::ReadonlyDynamicProperty, - CosTrading::MissingMandatoryProperty, - CosTrading::Proxy::IllegalRecipe, - CosTrading::DuplicatePropertyName, - CosTrading::DuplicatePolicyName)); - - virtual void withdraw_proxy (const char *id, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalOfferId, - CosTrading::UnknownOfferId, - CosTrading::Proxy::NotProxyOfferId)); - - virtual CosTrading::Proxy::ProxyInfo * - describe_proxy (const char *id, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalOfferId, - CosTrading::UnknownOfferId, - CosTrading::Proxy::NotProxyOfferId)); - - // = CosTrading::TraderComponents methods. - - virtual void list_proxies (CORBA::ULong how_many, - CosTrading::OfferIdSeq*& ids, - CosTrading::OfferIdIterator_ptr& id_itr, - CORBA::Environment& env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::NotImplemented)); - -private: - TRADER &trader_; -}; - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Proxy.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#endif /* TAO_PROXY_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Query_Only_Offer_Iterator.cpp b/TAO/orbsvcs/orbsvcs/Trader/Query_Only_Offer_Iterator.cpp deleted file mode 100644 index 69f0c61cc47..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Query_Only_Offer_Iterator.cpp +++ /dev/null @@ -1,71 +0,0 @@ - /* -*- C++ -*- */ - -// ============================================================================ -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Query_Only_Offer_Iterator.cpp -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ============================================================================ - -#include "Query_Only_Offer_Iterator.h" - -TAO_Query_Only_Offer_Iterator:: -TAO_Query_Only_Offer_Iterator(const TAO_Property_Filter& pfilter) - : TAO_Offer_Iterator (pfilter) -{ -} - -TAO_Query_Only_Offer_Iterator::~TAO_Query_Only_Offer_Iterator(void) -{ -} - -void -TAO_Query_Only_Offer_Iterator::add_offer (CosTrading::OfferId offer_id, - const CosTrading::Offer* offer) -{ - this->offers_.enqueue_tail ((CosTrading::Offer*) offer); - CORBA::string_free (offer_id); -} - -CORBA::ULong -TAO_Query_Only_Offer_Iterator::max_left (CORBA::Environment& _env) - TAO_THROW_SPEC((CORBA::SystemException, - CosTrading::UnknownMaxLeft)) -{ - return this->offers_.size (); -} - -CORBA::Boolean -TAO_Query_Only_Offer_Iterator::next_n (CORBA::ULong n, - CosTrading::OfferSeq_out offers, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)) -{ - offers = new CosTrading::OfferSeq; - - CORBA::ULong sequence_size = this->offers_.size (); - CORBA::ULong offers_in_sequence = (n < sequence_size) ? n : sequence_size; - offers->length (offers_in_sequence); - - // populate the sequence. - for (CORBA::ULong i = 0; i < offers_in_sequence; i++) - { - CosTrading::Offer *source = 0; - CosTrading::Offer& destination = (*offers)[i]; - - this->offers_.dequeue_head (source); - this->pfilter_.filter_offer (*source, destination); - } - - return offers_in_sequence != 0; -} - - diff --git a/TAO/orbsvcs/orbsvcs/Trader/Query_Only_Offer_Iterator.h b/TAO/orbsvcs/orbsvcs/Trader/Query_Only_Offer_Iterator.h deleted file mode 100644 index 318217e2cdd..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Query_Only_Offer_Iterator.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- C++ -*- */ - -// ============================================================================ -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Query_Only_Offer_Iterator.h -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ============================================================================ - -#ifndef TAO_QUERY_ONLY_OFFER_ITERATOR_H -#define TAO_QUERY_ONLY_OFFER_ITERATOR_H - -#include "ace/Containers.h" -#include "Offer_Iterator.h" - -class TAO_Query_Only_Offer_Iterator - : public TAO_Offer_Iterator - // = TITLE - // An implementation of the CosTrading::OfferIterator IDL - // interface that takes advantage of the fact that the trader is - // Query Only, and therefore its service offers are not being - // changed or removed. - // - // = DESCRIPTION - // The iterator stores pointers to Offers to be iterated over, - // and later accesses the Offers directly through the pointers. - // -{ -public: - // = Initialization and termination methods. - - TAO_Query_Only_Offer_Iterator (const TAO_Property_Filter& pfilter); - - virtual ~TAO_Query_Only_Offer_Iterator (void); - - virtual CORBA::Boolean next_n (CORBA::ULong n, - CosTrading::OfferSeq_out offers, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException)); - // Deposit at maximum n offers into the return sequence and return 1, - // or return 0 if the iterator is done and no offers are returned. - - virtual CORBA::ULong max_left (CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::UnknownMaxLeft)); - // Return the number of items left in the iterator. - - void add_offer (CosTrading::OfferId offer_id, - const CosTrading::Offer* offer); - // Add an offer the iterator should iterate over. - -private: - - ACE_Unbounded_Queue <CosTrading::Offer *> offers_; - // Structure that stores pointers to offers - // to iterate over. -}; - - -#endif /* TAO_QUERY_ONLY_OFFER_ITERATOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Register.cpp b/TAO/orbsvcs/orbsvcs/Trader/Register.cpp deleted file mode 100644 index e6fc845dc01..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Register.cpp +++ /dev/null @@ -1,367 +0,0 @@ -/* -*- C++ -*- */ - -// ============================================================================ -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Register.cpp -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ============================================================================ - -#if !defined (TAO_REGISTER_C) -#define TAO_REGISTER_C - -#include "Trader.h" -#include "Register.h" -#include "Property_Evaluator.h" - -#include "ace/Containers.h" - -template <class TRADER> -TAO_Register<TRADER>::TAO_Register (TRADER &trader) - : trader_ (trader), - TAO_Trader_Components<POA_CosTrading::Register> (trader.trading_components ()), - TAO_Support_Attributes<POA_CosTrading::Register> (trader.support_attributes ()) -{ -} - -template <class TRADER> -TAO_Register<TRADER>::~TAO_Register (void) -{ -} - -template <class TRADER> CosTrading::OfferId -TAO_Register<TRADER>::export (CORBA::Object_ptr reference, - const char *type, - const CosTrading::PropertySeq &properties, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Register::InvalidObjectRef, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::Register::InterfaceTypeMismatch, - CosTrading::IllegalPropertyName, - CosTrading::PropertyTypeMismatch, - CosTrading::ReadonlyDynamicProperty, - CosTrading::MissingMandatoryProperty, - CosTrading::DuplicatePropertyName)) -{ - // For robustness purposes -- - if (CORBA::is_nil (reference)) - TAO_THROW_RETURN (CosTrading::Register::InvalidObjectRef (), 0); - - // Get service type map - Service_Type_Map &service_type_map = this->trader_.service_type_map (); - - CosTrading::Offer offer; - TAO_Support_Attributes_Impl& support_attrs = - this->trader_.support_attributes (); - CosTrading::TypeRepository_ptr type_repos = - support_attrs.type_repos (); - CosTradingRepos::ServiceTypeRepository_ptr rep = - CosTradingRepos::ServiceTypeRepository::_narrow (type_repos, _env); - TAO_CHECK_ENV_RETURN (_env, 0); - - // Yank our friend, the type struct, and confirm that the given - // properties match the type definition. - CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct = - rep->fully_describe_type (type, _env); - TAO_CHECK_ENV_RETURN (_env, 0); - - // Oops the type is masked, we shouldn't let exporters know the type - // exists. - if (type_struct->masked) - TAO_THROW_RETURN (CosTrading::UnknownServiceType (type), 0); - - // TAO-specific way to determine if an object is derived from or is - // an interface type. - if (! reference->_is_a (type_struct->if_name, _env)) - TAO_THROW_RETURN (CosTrading::Register:: - InterfaceTypeMismatch (type, reference), 0); - - // Validate that the properties defined for this offer are correct - // to their types and strength. - this->validate_properties (type, type_struct, - (CosTrading::PropertySeq&) properties, _env); - TAO_CHECK_ENV_RETURN (_env, 0); - - offer.reference = reference->_duplicate (reference); - offer.properties = properties; - - // Insert the offer into the underlying type map. - CosTrading::OfferId id = service_type_map.insert_offer (type, offer); - - if (id == 0) - { - // Add type, if it's already been added in that split second - // since we've released the lock, nothing bad will happen. - id = service_type_map.insert_offer (type, offer); - } - - return id; -} - -template <class TRADER> void -TAO_Register<TRADER>::withdraw (const char *id, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalOfferId, - CosTrading::UnknownOfferId, - CosTrading::Register::ProxyOfferId)) -{ - // Get service type map. - Service_Type_Map &service_type_map = this->trader_.service_type_map (); - service_type_map.remove_offer ((CosTrading::OfferId) id, _env); -} - -template <class TRADER> CosTrading::Register::OfferInfo * -TAO_Register<TRADER>::describe (const char *id, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalOfferId, - CosTrading::UnknownOfferId, - CosTrading::Register::ProxyOfferId)) -{ - // Get service type map. - char* type = 0; - Service_Type_Map &service_type_map = this->trader_.service_type_map (); - - // Perform a lookup to find the offer. - CosTrading::Offer* offer = - service_type_map.lookup_offer ((CosTrading::OfferId) id, type, _env); - TAO_CHECK_ENV_RETURN (_env, (CosTrading::Register::OfferInfo *) 0); - - CosTrading::Register::OfferInfo *offer_info = - new CosTrading::Register::OfferInfo (); - - offer_info->reference = offer->reference->_duplicate (offer->reference); - offer_info->type = CORBA::string_dup (type); - offer_info->properties = offer->properties; - - return offer_info; -} - -template <class TRADER> void -TAO_Register<TRADER>::modify (const char *id, - const CosTrading::PropertyNameSeq& del_list, - const CosTrading::PropertySeq& modify_list, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::NotImplemented, - CosTrading::IllegalOfferId, - CosTrading::UnknownOfferId, - CosTrading::Register::ProxyOfferId, - CosTrading::IllegalPropertyName, - CosTrading::Register::UnknownPropertyName, - CosTrading::PropertyTypeMismatch, - CosTrading::ReadonlyDynamicProperty, - CosTrading::Register::MandatoryProperty, - CosTrading::Register::ReadonlyProperty, - CosTrading::DuplicatePropertyName)) -{ - // Throw an exception if the trader is not configured - // to support properties modification. - if (! this->supports_modifiable_properties (_env)) - TAO_THROW (CosTrading::NotImplemented ()); - - char* type = 0; - TAO_Support_Attributes_Impl& support_attrs = - this->trader_.support_attributes (); - CosTrading::TypeRepository_ptr type_repos = support_attrs.type_repos (); - CosTradingRepos::ServiceTypeRepository_ptr rep = - CosTradingRepos::ServiceTypeRepository::_narrow (type_repos, _env); - TAO_CHECK_ENV_RETURN_VOID (_env); - Service_Type_Map &service_type_map = this->trader_.service_type_map (); - - CosTrading::Offer* offer = - service_type_map.lookup_offer ((CosTrading::OfferId) id, type, _env); - TAO_CHECK_ENV_RETURN_VOID (_env); - - if (offer != 0) - { - // Yank our friend, the type struct. - CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct = rep->describe_type (type, _env); - TAO_CHECK_ENV_RETURN_VOID (_env); - TAO_Offer_Modifier offer_mod (type, type_struct, *offer); - - // Delete, add, and change properties of the offer. - this->validate_properties (type, type_struct, - (CosTrading::PropertySeq) modify_list, _env); - TAO_CHECK_ENV_RETURN_VOID (_env); - offer_mod.delete_properties (del_list, _env); - TAO_CHECK_ENV_RETURN_VOID (_env); - offer_mod.merge_properties (modify_list, _env); - TAO_CHECK_ENV_RETURN_VOID (_env); - - // Alter our reference to the offer. - offer_mod.affect_change (); - } -} - -template <class TRADER> void -TAO_Register<TRADER>::withdraw_using_constraint (const char *type, - const char *constr, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::IllegalConstraint, - CosTrading::Register::NoMatchingOffers)) -{ - int num_removed = 0; - TAO_Support_Attributes_Impl& - support_attrs = this->trader_.support_attributes (); - CosTrading::TypeRepository_ptr type_repos = support_attrs.type_repos (); - CosTradingRepos::ServiceTypeRepository_ptr rep = - CosTradingRepos::ServiceTypeRepository::_narrow (type_repos, _env); - Service_Type_Map &service_type_map = this->trader_.service_type_map (); - CORBA::Boolean dp_support = support_attrs.supports_dynamic_properties (); - ACE_Unbounded_Queue<CosTrading::OfferId_var> ids; - - // Retrieve the type struct - CosTradingRepos::ServiceTypeRepository::TypeStruct* - type_struct = rep->describe_type (type, _env); - TAO_CHECK_ENV_RETURN_VOID (_env); - - // Try to find the map of offers of desired service type. - Service_Type_Map::offer_iterator offer_iter (type, service_type_map); - TAO_Constraint_Validator validator (type_struct); - TAO_Constraint_Interpreter constr_inter (validator, constr, _env); - TAO_CHECK_ENV_RETURN_VOID (_env); - - while (offer_iter.has_more_offers ()) - { - CosTrading::Offer* offer = offer_iter.get_offer (); - // Add offer if it matches the constraints - - TAO_Constraint_Evaluator evaluator (offer, dp_support); - if (constr_inter.evaluate (evaluator)) - ids.enqueue_tail (offer_iter.get_id ()); - - offer_iter.next_offer (); - } - - if (ids.size () == 0) - TAO_THROW (CosTrading::Register::NoMatchingOffers (constr)); - else - { - while (! ids.is_empty ()) - { - CosTrading::OfferId_var offer_id; - - ids.dequeue_head (offer_id); - service_type_map.remove_offer (offer_id, _env); - } - } -} - -template <class TRADER> CosTrading::Register_ptr -TAO_Register<TRADER>::resolve (const CosTrading::TraderName &name, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Register::IllegalTraderName, - CosTrading::Register::UnknownTraderName, - CosTrading::Register::RegisterNotSupported)) -{ - // Determine if the first link is a legal link name. - if (! TAO_Trader_Base::is_valid_identifier_name (name[0])) - TAO_THROW_RETURN (CosTrading::Register::IllegalTraderName (name), - CosTrading::Register::_nil ()); - - // Grab a reference to the link interface, and get a link description. - CosTrading::Link_var link (this->link_if (_env)); - TAO_CHECK_ENV_RETURN (_env, CosTrading::Register::_nil ()); - CosTrading::Link::LinkInfo_var link_info; - - TAO_TRY - { - // Ensure that the link to the next trader exists. - link_info = link->describe_link (name[0], TAO_TRY_ENV); - TAO_CHECK_ENV; - } - TAO_CATCHANY - { - TAO_THROW_RETURN (CosTrading::Register::UnknownTraderName (name), - CosTrading::Register::_nil ()); - } - TAO_ENDTRY; - - // Ensure that the register pointer isn't nil. - if (link_info->target_reg.in() == CosTrading::Register::_nil ()) - TAO_THROW_RETURN (CosTrading::Register::RegisterNotSupported (name), - CosTrading::Register::_nil ()); - - CosTrading::Register_ptr return_value = link_info->target_reg; - - if (name.length () > 1) - { - // Create a new Trader Name with the first link removed. - CosTrading::TraderName trader_name (name.length () - 1); - for (int i = trader_name.length () - 1; i >= 0; i--) - trader_name[i] = name[i + 1]; - - return_value = link_info->target_reg->resolve (trader_name, _env); - TAO_CHECK_ENV_RETURN (_env, CosTrading::Register::_nil ()); - } - - return return_value; -} - -template <class TRADER> void -TAO_Register<TRADER>:: -validate_properties (const char* type, - CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct, - CosTrading::PropertySeq& properties, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, - CosTrading::PropertyTypeMismatch, - CosTrading::ReadonlyDynamicProperty, - CosTrading::MissingMandatoryProperty, - CosTrading::DuplicatePropertyName)) -{ - typedef CosTradingRepos::ServiceTypeRepository SERVICE_TYPE_REPOS; - - int length = properties.length (); - SERVICE_TYPE_REPOS::PropStructSeq& prop_types = type_struct->props; - TAO_Property_Evaluator_By_Name prop_eval (properties, _env); - TAO_CHECK_ENV_RETURN_VOID (_env); - - // Perform property validation - length = prop_types.length (); - for (int i = 0; i < length; i++) - { - SERVICE_TYPE_REPOS::PropStruct& prop_struct = prop_types[i]; - const char* prop_name = prop_struct.name; - - // Obtain the type of the exported property. - CORBA::TypeCode* prop_type = prop_eval.property_type (prop_name); - - if (prop_type == CORBA::TypeCode::_nil ()) - { - // Offer cannot have a missing mandatory property. - if (prop_types[i].mode == SERVICE_TYPE_REPOS::PROP_MANDATORY) - TAO_THROW (CosTrading::MissingMandatoryProperty (type, prop_name)); - } - else - { - if (! prop_type->equal (prop_struct.value_type, _env)) - { - // Offer cannot redefine the type of an property. - const CosTrading::Property* prop = prop_eval.get_property (prop_name); - TAO_THROW (CosTrading::PropertyTypeMismatch (type, *prop)); - } - else if (prop_struct.mode == SERVICE_TYPE_REPOS::PROP_READONLY && - prop_eval.is_dynamic_property (prop_name)) - TAO_THROW (CosTrading::ReadonlyDynamicProperty (type, prop_name)); - } - } -} - -#endif /* TAO_REGISTER_C */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Register.h b/TAO/orbsvcs/orbsvcs/Trader/Register.h deleted file mode 100644 index 1c4e8b2791f..00000000000 --- a/TAO/orbsvcs/orbsvcs/Trader/Register.h +++ /dev/null @@ -1,310 +0,0 @@ -/* -*- C++ -*- */ - -// ============================================================================ -// $Id$ -// -// = LIBRARY -// orbsvcs -// -// = FILENAME -// Register.h -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// Seth Widoff <sbw1@cs.wustl.edu> -// -// ============================================================================ -#ifndef ACE_REGISTER_H -#define ACE_REGISTER_H - -#include "Attributes_T.h" -#include "Offer_Modifier.h" - -template <class TRADER> -class TAO_Register : - public TAO_Trader_Components<POA_CosTrading::Register>, - public TAO_Support_Attributes<POA_CosTrading::Register> - // - // = TITLE - // This class implements CosTrading::Register IDL interface. -{ -public: - - TAO_Register (TRADER &trader); - - virtual ~TAO_Register (void); - - virtual CosTrading::OfferId export (CORBA::Object_ptr reference, - const char *type, - const CosTrading::PropertySeq& properties, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Register::InvalidObjectRef, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::Register::InterfaceTypeMismatch, - CosTrading::IllegalPropertyName, - CosTrading::PropertyTypeMismatch, - CosTrading::ReadonlyDynamicProperty, - CosTrading::MissingMandatoryProperty, - CosTrading::DuplicatePropertyName)); - - // BEGIN SPEC - // The export operation is the means by which a service is - // advertised, via a trader, to a community of potential - // importers. The OfferId returned is the handle with which the - // exporter can identify the exported offer when attempting to - // access it via other operations. The OfferId is only meaningful in - // the context of the trader that generated it. - - // The "reference" parameter is the information that enables a client - // to interact with a remote server. If a trader implementation chooses - // to consider certain types of object references (e.g., a nil object - // reference) to be unexportable, then it may return the InvalidObjectRef - // exception in such cases. - - // The "type" parameter - // identifies the service type, which contains the interface type of - // the "reference" and a set of named property types that may be - // used in further describing this offer (i.e., it restricts what is - // acceptable in the properties parameter). ° - - // If the string - // representation of the "type" does not obey the rules for - // identifiers, then an IllegalServiceType exception is raised. ° If - // the "type" is correct syntactically but a trader is able to - // unambiguously determine that it is not a recognized service type, - // then an UnknownServiceType exception is raised. ° - - // If the trader - // can determine that the interface type of the "reference" - // parameter is not a subtype of the interface type specified in - // "type," then an InterfaceTypeMismatch exception is raised. The - // "properties" parameter is a list of named values that conform to - // the property value types defined for those names. They describe - // the service being offered. This description typically covers - // behavioral, non-functional, and non-computational aspects of the - // service. ° - - // If any of the property names do not obey the syntax - // rules for PropertyNames, then an IllegalPropertyName exception is - // raised. ° - - // If the type of any of the property values is not the - // same as the declared type (declared in the service type), then a - // PropertyTypeMismatch exception is raised. - - // ° If an attempt is made to assign a dynamic property value to a - // readonly property, then the ReadonlyDynamicProperty exception is - // raised. ° If the "properties" parameter omits any property - // declared in the service type with a mode of mandatory, then a - // MissingMandatoryProperty exception is raised. ° If two or more - // properties with the same property name are included in this - // parameter, the DuplicatePropertyName exception is raised. - // END SPEC - - virtual void withdraw (const char *id, CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalOfferId, - CosTrading::UnknownOfferId, - CosTrading::Register::ProxyOfferId)); - - // BEGIN SPEC - // The withdraw operation removes the service offer from the trader - // (i.e., after withdraw the offer can no longer be returned as the - // result of a query). The offer is identified by the "id" parameter - // which was originally returned by export. ° If the string - // representation of "id" does not obey the rules for offer - // identifiers, then an IllegalOfferId exception is raised. ° If the - // "id" is legal but there is no offer within the trader with that - // "id," then an UnknownOfferId exception is raised. ° If the "id" - // identifies a proxy offer rather than an ordinary offer, then a - // ProxyOfferId exception is raised. - // END SPEC - - virtual CosTrading::Register::OfferInfo* - describe (const char * id, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalOfferId, - CosTrading::UnknownOfferId, - CosTrading::Register::ProxyOfferId)); - - // BEGIN SPEC - // The describe operation returns the information about an offered - // service that is held by the trader. It comprises the "reference" - // of the offered service, the "type" of the service offer, and the - // "properties" that describe this offer of service. The offer is - // identified by the "id" parameter which was originally returned by - // export. ° If the string representation of "id" does not obey the - // rules for object identifiers, then an IllegalOfferId exception is - // raised. ° If the "id" is legal but there is no offer within the - // trader with that "id," then an UnknownOfferId exception is - // raised. ° If the "id" identifies a proxy offer rather than an - // ordinary offer, then a ProxyOfferId exception is raised. - // END SPEC - - virtual void modify (const char * id, - const CosTrading::PropertyNameSeq& del_list, - const CosTrading::PropertySeq& modify_list, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::NotImplemented, - CosTrading::IllegalOfferId, - CosTrading::UnknownOfferId, - CosTrading::Register::ProxyOfferId, - CosTrading::IllegalPropertyName, - CosTrading::Register::UnknownPropertyName, - CosTrading::PropertyTypeMismatch, - CosTrading::ReadonlyDynamicProperty, - CosTrading::Register::MandatoryProperty, - CosTrading::Register::ReadonlyProperty, - CosTrading::DuplicatePropertyName)); - - // BEGIN SPEC - // The modify operation is used to change the description of a - // service as held within a service offer. The object reference and - // the service type associated with the offer cannot be - // changed. This operation may: ° add new (non-mandatory) properties - // to describe an offer, ° change the values of some existing (not - // readonly) properties, or ° delete existing (neither mandatory nor - // readonly) properties. - - // The modify operation either succeeds completely or it fails - // completely. The offer is identified by the "id" parameter which - // was originally returned by export. ° If the string representation - // of "id" does not obey the rules for offer identifiers, then an - // IllegalOfferId exception is raised. ° If the "id" is legal but - // there is no offer within the trader with that "id," then an - // UnknownOfferId exception is raised. ° If the "id" identifies a - // proxy offer rather than an ordinary offer, then a ProxyOfferId - // exception is raised. - - // The "del_list" parameter gives the names of the properties that - // are no longer to be recorded for the identified offer. Future - // query and describe operations will not see these properties. ° If - // any of the names within the "del_list" do not obey the rules for - // PropertyName's, then an IllegalPropertyName exception is - // raised. ° If a "name" is legal but there is no property for the - // offer with that "name," then an UnknownPropertyName exception is - // raised. ° If the list includes a property that has a mandatory - // mode, then the MandatoryProperty exception is raised. ° If the - // same property name is included two or more times in this - // parameter, the DuplicatePropertyName exception is raised. - - // The "modify_list" parameter gives the names and values of - // properties to be changed. If the property is not in the offer, - // then the modify operation adds it. The modified (or added) - // property values are returned in future query and describe - // operations in place of the original values. ° If any of the names - // within the "modify_list" do not obey the rules for - // PropertyName's, then an IllegalPropertyName exception is - // raised. ° If the list includes a property that has a readonly - // mode, then the ReadonlyProperty exception is raised unless that - // readonly property is not currently recorded for the offer. The - // ReadonlyDynamicProperty exception is raised if an attempt is made - // to assign a dynamic property value to a readonly property. ° If - // the value of any modified property is of a type that is not the - // same as the type expected, then the PropertyTypeMismatch - // exception is raised. ° If two or more properties with the same - // property name are included in this argument, the - // DuplicatePropertyName exception is raised. - - // The NotImplemented exception shall be raised if and only if the - // supports_modifiable_properties attribute yields FALSE. - // END SPEC - - virtual void withdraw_using_constraint (const char *type, - const char *constr, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::IllegalServiceType, - CosTrading::UnknownServiceType, - CosTrading::IllegalConstraint, - CosTrading::Register::NoMatchingOffers)); - - // BEGIN SPEC - // The withdraw_using_constraint operation withdraws a set of offers - // from within a single trader. This set is identified in the same - // way that a query operation identifies a set of offers to be - // returned to an importer. - - // The "type" parameter conveys the required service type. Each - // offer of the specified type will have the constraint expression - // applied to it. If it matches the constraint expression, then the - // offer will be withdrawn.° If "type" does not obey the rules for - // service types, then an IllegalServiceType exception is raised. ° - // If the "type" is correct syntactically but is not recognized as a - // service type by the trader, then an UnknownServiceType exception - // is raised. - - // The constraint "constr" is the means by which the client - // restricts the set of offers to those that are intended for - // withdrawal. ° If "constr" does not obey the syntax rules for a - // constraint then an IllegalConstraint exception is raised. ° If - // the constraint fails to match with any offer of the specified - // service type, then a NoMatchingOffers exception is raised. - // END SPEC - - virtual CosTrading::Register_ptr - resolve (const CosTrading::TraderName &name, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CORBA::SystemException, - CosTrading::Register::IllegalTraderName, - CosTrading::Register::UnknownTraderName, - CosTrading::Register::RegisterNotSupported)); - - // BEGIN SPEC - // This operation is used to resolve a context relative name for - // another trader. In particular, it is used when exporting to a - // trader that is known by a name rather than by an object - // reference. The client provides the name, which will be a sequence - // of name components. ° If the content of the parameter cannot - // yield legal syntax for the first component, then the - // IllegalTraderName exception is raised. Otherwise, the first name - // component is compared against the name held in each link. ° If no - // match is found, or the trader does not support links, the - // UnknownTraderName exception is raised. Otherwise, the trader - // obtains the register_if held as part of the matched link. ° If - // the Register interface is not nil, then the trader binds to the - // Register interface and invokes resolve but passes the TraderName - // with the first component removed; if it is nil, then the - // RegisterNotSupported exception is raised. When a trader is able - // to match the first name component leaving no residual name, that - // trader returns the reference for the Register interface for that - // linked trader. In unwinding the recursion, intermediate traders - // return the Register interface reference to their client (another - // trader). - // END SPEC - - protected: - - typedef TRADER::Service_Type_Map Service_Type_Map; - - void validate_properties (const char* type, - CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct, - CosTrading::PropertySeq& properties, - CORBA::Environment& _env) - TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, - CosTrading::PropertyTypeMismatch, - CosTrading::ReadonlyDynamicProperty, - CosTrading::MissingMandatoryProperty, - CosTrading::DuplicatePropertyName)); - - // Type is a known service type. - - CORBA::Boolean find_property (CosTrading::PropertySeq &properties, - const char *property_name, - CORBA::ULong &position); - - private: - - TRADER &trader_; -}; - - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Register.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#endif /* ACE_REGISTER_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Trader.cpp b/TAO/orbsvcs/orbsvcs/Trader/Trader.cpp index bd9df0d9f2d..8f3282d2527 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Trader.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Trader.cpp @@ -16,10 +16,6 @@ #include "Trader.h" -#if defined(_MSC_VER) -//#pragma warning(disable:4250) -#endif /* _MSC_VER */ - TAO_Trader_Base::TAO_Trader_Base (void) : trading_components_ (*this), import_attributes_ (*this), @@ -233,6 +229,3 @@ TAO_Trader_Factory::create_MT_linked_trader (void) */ #endif /* ACE_HAS_THREADS */ -#if defined(_MSC_VER) -//#pragma warning(default:4250) -#endif /* _MSC_VER */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Trader_Interfaces.cpp b/TAO/orbsvcs/orbsvcs/Trader/Trader_Interfaces.cpp new file mode 100644 index 00000000000..7a3db67285e --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Trader/Trader_Interfaces.cpp @@ -0,0 +1,1645 @@ +/* -*- C++ -*- */ + +// ======================================================================== +// $Id$ +// +// = LIBRARY +// orbsvcs +// +// = FILENAME +// Trader_Interfaces.cpp +// +// = AUTHOR +// Marina Spivak <marina@cs.wustl.edu> +// Seth Widoff <sbw1@cs.wustl.edu> +// +// ======================================================================== + +#if !defined (TAO_TRADER_INTERFACES_C) +#define TAO_TRADER_INTERFACES_C + +#include "Trader_Interfaces.h" + + // ************************************************************* + // TAO_Lookup + // ************************************************************* + +template <class TRADER> +TAO_Lookup<TRADER>::TAO_Lookup (TRADER &trader) + : trader_ (trader), + TAO_Trader_Components<POA_CosTrading::Lookup> (trader.trading_components ()), + TAO_Support_Attributes<POA_CosTrading::Lookup> (trader.support_attributes ()), + TAO_Import_Attributes<POA_CosTrading::Lookup> (trader.import_attributes ()) +{ +} + +template <class TRADER> +TAO_Lookup<TRADER>::~TAO_Lookup (void) +{ +} + +template <class TRADER> void +TAO_Lookup<TRADER>:: +query (const char *type, + const char *constraint, + const char *preferences, + const CosTrading::PolicySeq &in_policies, + const CosTrading::Lookup::SpecifiedProps &desired_props, + CORBA::ULong how_many, + CosTrading::OfferSeq_out returned_offers, + CosTrading::OfferIterator_out returned_offer_iterator, + CosTrading::PolicyNameSeq_out returned_limits_applied, + CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::IllegalConstraint, + CosTrading::Lookup::IllegalPreference, + CosTrading::Lookup::IllegalPolicyName, + CosTrading::Lookup::PolicyTypeMismatch, + CosTrading::Lookup::InvalidPolicyValue, + CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName, + CosTrading::DuplicatePolicyName)) +{ + // Initializing out parameters + returned_offers = new CosTrading::OfferSeq; + returned_offer_iterator = CosTrading::OfferIterator::_nil (); + returned_limits_applied = new CosTrading::PolicyNameSeq; + + // Get service type map + Offer_Database& offer_database = this->trader_.offer_database (); + + TAO_Policies policies (this->trader_, in_policies, env); + TAO_CHECK_ENV_RETURN_VOID (env); + + // If the importer has specified a starting trader, foward the + // query. + CosTrading::TraderName* trader_name = policies.starting_trader (env); + TAO_CHECK_ENV_RETURN_VOID (env); + + if (trader_name != 0) + { + CosTrading::TraderName_var starting_trader (trader_name); + this->forward_query (starting_trader.in (), + type, + constraint, + preferences, + policies, + desired_props, + how_many, + returned_offers, + returned_offer_iterator, + returned_limits_applied, + env); + return; + } + + // If a federated query returns to us, ignore it to prevent + // redundant results. + if (this->duplicate_stem_id (policies, env)) + return; + + // If the type is invalid or unknown, let us know now. + const TAO_Support_Attributes_Impl& support_attrs = + this->trader_.support_attributes (); + CosTrading::TypeRepository_ptr type_repos = + support_attrs.type_repos (); + CosTradingRepos::ServiceTypeRepository_ptr rep = + CosTradingRepos::ServiceTypeRepository::_narrow (type_repos, env); + TAO_CHECK_ENV_RETURN_VOID (env); + + // If type is not found, there is nothing to consider - return. + // Else we found the service type....proceed with lookup. + // We will store the matched offers in here. + Offer_Queue ordered_offers; + + // Perform the lookup, placing the ordered results in ordered_offers. + this->perform_lookup (type, + constraint, + preferences, + offer_database, + rep, + policies, + ordered_offers, + returned_limits_applied, + env); + TAO_CHECK_ENV_RETURN_VOID (env); + + // Fill the return sequence and iterator with the bountiful results. + CORBA::ULong offers_returned = + this->fill_receptacles (type, + ordered_offers, + how_many, + desired_props, + returned_offers, + returned_offer_iterator, + env); + TAO_CHECK_ENV_RETURN_VOID (env); + + // Determine if we should perform a federated query, and if so + // construct a sequence of links to follow. + CosTrading::LinkNameSeq* links = 0; + CORBA::Boolean should_follow = + this->retrieve_links (policies, + offers_returned, + CosTrading::LinkNameSeq_out (links), + env); + TAO_CHECK_ENV_RETURN_VOID (env); + + if (should_follow && links != 0) + { + // Perform the sequence of fedrated queries. + CosTrading::LinkNameSeq_var links_to_follow (links); + this->federated_query (*links, + type, + constraint, + preferences, + policies, + desired_props, + how_many - returned_offers->length (), + returned_offers, + returned_offer_iterator, + returned_limits_applied, + env); + } + TAO_CHECK_ENV_RETURN_VOID (env); +} + +template <class TRADER> void +TAO_Lookup<TRADER>:: +perform_lookup (const char* type, + const char* constraint, + const char* preferences, + Offer_Database& offer_database, + CosTradingRepos::ServiceTypeRepository_ptr rep, + TAO_Policies& policies, + Offer_Queue& ordered_offers, + CosTrading::PolicyNameSeq_out returned_limits_applied, + CORBA::Environment& env) + TAO_THROW_SPEC ((CosTrading::IllegalConstraint, + CosTrading::Lookup::IllegalPreference, + CosTrading::Lookup::PolicyTypeMismatch, + CosTrading::Lookup::InvalidPolicyValue, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType)) +{ + // TAO_Offer_Filter -- ensures that we don't consider offers with + // modifiable or dynamic properties if the Trader doesn't support + // them, or the importer has turned them off using policies. + // TAO_Constraint_Validator -- validates the constraint with the + // property types in the supplied type. + // TAO_Constraint_Interpreter -- parses the constraint string, and + // determines whether an offer meets those constraints. + // TAO_Preference_Interpreter -- parses the preference string and + // orders offers according to those constraints. + CosTradingRepos::ServiceTypeRepository::TypeStruct_var + type_struct (rep->fully_describe_type (type, env)); + TAO_CHECK_ENV_RETURN_VOID (env); + TAO_Offer_Filter offer_filter (type_struct.ptr (), policies, env); + TAO_CHECK_ENV_RETURN_VOID (env); + TAO_Constraint_Validator validator (type_struct.ptr ()); + TAO_Constraint_Interpreter constr_inter (validator, constraint, env); + TAO_CHECK_ENV_RETURN_VOID (env); + TAO_Preference_Interpreter pref_inter (validator, preferences, env); + TAO_CHECK_ENV_RETURN_VOID (env); + CORBA::ULong return_card = policies.return_card (env); + TAO_CHECK_ENV_RETURN_VOID (env); + + // Try to find the map of offers of desired service type. + this->lookup_one_type (type, + offer_database, + constr_inter, + pref_inter, + offer_filter); + + // If the importer hasn't demanded an exact match search, we search + // all the subtypes of the supplied type. NOTE: Only the properties + // belonging to the provided type are considered on + // subtypes. Additional properties on the subtype are generally + // ignored. This is as it should be, consistent with the notions of + // type inheritence. + if (! policies.exact_type_match (env)) + { + TAO_CHECK_ENV_RETURN_VOID (env); + this->lookup_all_subtypes (type, + type_struct->incarnation, + offer_database, + rep, + constr_inter, + pref_inter, + offer_filter); + } + TAO_CHECK_ENV_RETURN_VOID (env); + + // Pull the matched offers out of the pref_inter in order, and stick + // them in a queue. The offers in the queue will be emptied into + // the return sequence and iterator for later purusal by the + // importer. Only prepare for the importer no more offers than the + // return cardinality default or policy allows. + CORBA::ULong num_offers = pref_inter.num_offers (); + for (CORBA::ULong i = 0; i < num_offers && i < return_card; i++) + { + CosTrading::Offer* offer; + CosTrading::OfferId offer_id; + if (pref_inter.remove_offer (offer_id, offer) == 0) + { + Offer_Info offer_info; + offer_info.offer_id_ = offer_id; + offer_info.offer_ptr_ = offer; + ordered_offers.enqueue_tail (offer_info); + } + else + break; + } + + // Take note of the limits applied in this query. + returned_limits_applied = offer_filter.limits_applied (); +} + +template <class TRADER> void +TAO_Lookup<TRADER>:: +lookup_one_type (const char* type, + Offer_Database& offer_database, + TAO_Constraint_Interpreter& constr_inter, + TAO_Preference_Interpreter& pref_inter, + TAO_Offer_Filter& offer_filter) +{ + ACE_DEBUG ((LM_DEBUG, "TAO_Lookup: Performing query for %s\n", type)); + + // Retrieve an iterator over the offers for a given type. + Offer_Database::offer_iterator offer_iter (type, offer_database); + + while (offer_filter.ok_to_consider_more () && + offer_iter.has_more_offers ()) + { + // For each offer in the iterator, attempt to match it with + // the constraints passed to the Query method. If it matches + // the constraint, use the TAO_Preference_Interpreter to + // order the matched offers with respect to the preference + // string passed to the method. All the while the offer + // iterator ensures we don't exceed the match cardinality + // constraints. + CosTrading::Offer* offer = offer_iter.get_offer (); + + TAO_Constraint_Evaluator evaluator (offer); + if (offer_filter.ok_to_consider (offer) && + constr_inter.evaluate (evaluator)) + { + // Shove the offer and its id into the preference + // ordering object, pref_inter. + CosTrading::OfferId offer_id = offer_iter.get_id (); + pref_inter.order_offer (offer_id, offer, evaluator); + offer_filter.matched_offer (); + } + + offer_iter.next_offer (); + } +} + +template <class TRADER> void +TAO_Lookup<TRADER>:: +lookup_all_subtypes (const char* type, + CosTradingRepos::ServiceTypeRepository::IncarnationNumber& inc_num, + Offer_Database& offer_database, + CosTradingRepos::ServiceTypeRepository_ptr rep, + TAO_Constraint_Interpreter& constr_inter, + TAO_Preference_Interpreter& pref_inter, + TAO_Offer_Filter& offer_filter) +{ + // BEGIN SPEC + // The trader may return a service offer of a subtype of the "type" + // requested. Sub-typing of service types is discussed in "Service + // Types" on page 16-4. A service subtype can be described by the + // properties of its supertypes. This ensures that a well-formed query + // for the "type" is also a well-formed query with respect to any + // subtypes. However, if the importer specifies the policy of + // exact_type_match = TRUE, then only offers with the exact (no + // subtype) service type requested are returned. + // END SPEC + + CosTradingRepos::ServiceTypeRepository::SpecifiedServiceTypes sst; + CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq_var all_types; + + // Optimization: Since a subtype can't have a higher incarnation + // number than a supertype, we don't need to consider those + // types with lower incarnation numbers. + sst._d (CosTradingRepos::ServiceTypeRepository::since); + sst.incarnation (inc_num); + + // TAO_TRY + // { + CORBA::Environment env; + all_types = rep->list_types (sst, env); + // TAO_CHECK_ENV; + // } + // TAO_CATCHANY { return; } + // TAO_ENDTRY; + + // Scan all types inserted after the super types. If the transitive + // closure of a type's super type relation includes the super type + // being considered, then perform a search on that type. + CORBA::ULong num_types = all_types->length (); + for (CORBA::ULong i = 0; + i < num_types && offer_filter.ok_to_consider_more (); + i++) + { + CosTradingRepos::ServiceTypeRepository::TypeStruct_var type_struct; + + TAO_TRY + { + // Obtain a description of the prospective type. + type_struct = rep->fully_describe_type (all_types[i], TAO_TRY_ENV); + TAO_CHECK_ENV; + } + TAO_CATCHANY + { + break; + } + TAO_ENDTRY; + + CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq& + super_types = type_struct->super_types; + CORBA::ULong num_super_types = super_types.length (); + + for (CORBA::ULong j = 0; j < num_super_types; j++) + { + if (ACE_OS::strcmp (type_struct->super_types[j], type) == 0) + { + // Egads, a subtype! + this->lookup_one_type (all_types[i], + offer_database, + constr_inter, + pref_inter, + offer_filter); + break; + } + } + } +} + + +template <class TRADER> int +TAO_Lookup<TRADER>:: +fill_receptacles (const char* type, + Offer_Queue& ordered_offers, + CORBA::ULong how_many, + const CosTrading::Lookup::SpecifiedProps& desired_props, + CosTrading::OfferSeq*& offers, + CosTrading::OfferIterator_ptr& offer_itr, + CORBA::Environment& env) + TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName)) +{ + // BEGIN SPEC + // The returned offers are passed back in one of two ways (or a + // combination of both). ° The "offers" return result conveys a list + // of offers and the "offer_itr" is a reference to an interface at + // which offers can be obtained. ° The "how_many" parameter states + // how many offers are to be returned via the "offers" result, any + // remaining offers are available via the iterator interface. If the + // "how_many" exceeds the number of offers to be returned, then the + // "offer_itr" will be nil. + // END SPEC + + // Ordered offers iterator. + Offer_Queue::ITERATOR ordered_offers_iterator (ordered_offers); + TAO_Property_Filter prop_filter (desired_props, env); + TAO_CHECK_ENV_RETURN (env, 0); + + // RETURNING: Calculate how many offers go into the sequence + // Calculate how many go into the iterator + CORBA::ULong size = ordered_offers.size (); + CORBA::ULong offers_in_sequence = (how_many < size) ? how_many : size; + CORBA::ULong offers_in_iterator = size - offers_in_sequence; + CORBA::ULong total_offers = offers_in_sequence + offers_in_iterator; + + offers->length (offers_in_sequence); + + // Add to the sequence, filtering out the undesired properties. + for (CORBA::ULong i = 0; + i < offers_in_sequence; + ordered_offers_iterator.advance (), i++) + { + Offer_Info* offer_info_ptr = 0; + ordered_offers_iterator.next (offer_info_ptr); + CosTrading::Offer& source = *offer_info_ptr->offer_ptr_; + CosTrading::Offer& destination = (*offers)[i]; + prop_filter.filter_offer (source, destination); + + CORBA::string_free (offer_info_ptr->offer_id_); + } + + // Any remaining offers go into iterator + if (offers_in_iterator > 0) + { + // Create an iterator implementation + TAO_Offer_Iterator *oi = + this->create_offer_iterator (type, prop_filter); + offer_itr = oi->_this (env); + TAO_CHECK_ENV_RETURN (env,total_offers - offers_in_iterator); + + // Add to the iterator + for (i = 0; + i < offers_in_iterator; + ordered_offers_iterator.advance (), i++) + { + Offer_Info* offer_info_ptr = 0; + ordered_offers_iterator.next (offer_info_ptr); + oi->add_offer (offer_info_ptr->offer_id_, + offer_info_ptr->offer_ptr_); + } + } + + return total_offers; +} + +template <class TRADER> +TAO_Offer_Iterator * +TAO_Lookup<TRADER>:: +create_offer_iterator (const char *type, + const TAO_Property_Filter& pfilter) +{ + // This is the factory method that creates the appropriate type of + // offer iterator. If there's no Register interface, then we can + // just stick the offers directly into an iterator, since these + // offers will never be removed from the Trader. If there's a + // Register interface, then there's a chance that by the time the + // importer calls the next_n method on the iterator that the offer + // will have been withdrawn. So the Register_Offer_Iterator retains only + // the offer ids, and will recognize when an offer id no longer + // identifies an offer in the trader. + + // We pass the property filter to the iterators, so when the iterators + // return the offers, they can remove the undesirable properties + // from those offers. + TAO_Offer_Iterator* iterator = 0; + + if (CORBA::is_nil (this->trader_.trading_components ().register_if ())) + iterator = new TAO_Query_Only_Offer_Iterator (pfilter); + else + { + iterator = + new TAO_Register_Offer_Iterator<TRADER> (this->trader_, pfilter); + } + + return iterator; +} + +template <class TRADER> CORBA::Boolean +TAO_Lookup<TRADER>::duplicate_stem_id (TAO_Policies& policies, + CORBA::Environment& _env) +{ + // Determine whether the stem_id passed to this query is one we've + // already seen. If this is the case, then we shouldn't pursue this + // query any further. + CORBA::Boolean return_value = CORBA::B_FALSE; + CosTrading::Admin::OctetSeq_var request_id = policies.request_id (_env); + TAO_CHECK_ENV_RETURN (_env, return_value); + + // If the stem_id was provided and is a duplicate, return true. + if ((request_id.ptr () != 0) && + this->request_ids_.insert (request_id) == 1) + return_value = CORBA::B_TRUE; + + return return_value; +} + +template <class TRADER> CORBA::Boolean +TAO_Lookup<TRADER>::retrieve_links (TAO_Policies& policies, + CORBA::ULong offers_returned, + CosTrading::LinkNameSeq_out links, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Lookup::PolicyTypeMismatch)) +{ + CORBA::Boolean should_follow = CORBA::B_FALSE; + CosTrading::FollowOption follow_rule = policies.link_follow_rule (_env); + TAO_CHECK_ENV_RETURN (_env, should_follow); + + // Determine whether or not a federated query is warranted. A query + // is waranted if the follow_rule governing this query is 'always' + // or if_no_local and the local query returned nothing. + if ((follow_rule == CosTrading::always || + (follow_rule == CosTrading::if_no_local && offers_returned == 0)) + && policies.hop_count (_env) > 0) + should_follow = CORBA::B_TRUE; + + if (should_follow) + { + // Grab the names of all the links in the trader, and push + // the suitable ones onto <valid_links>. + CosTrading::Link_ptr link_interface + = this->trader_.trading_components ().link_if (); + ACE_Unbounded_Queue<CosTrading::LinkName> valid_links; + CosTrading::LinkNameSeq_var link_path = + link_interface->list_links (_env); + TAO_CHECK_ENV_RETURN (_env, should_follow); + + // Determine which of the links registered with the Link + // interface are suitable to follow. + for (int i = link_path->length () - 1; i >= 0; i--) + { + CosTrading::FollowOption link_rule = + policies.link_follow_rule ((const char*) link_path[i], _env); + if (link_rule == CosTrading::always || + (link_rule == CosTrading::if_no_local && + offers_returned == 0)) + valid_links.enqueue_tail ((char *)((const char*) link_path[i])); + } + + // Collect those valid links into a sequence suitable for + // passing into the federated_query method. + CosTrading::LinkName link_name = 0, + *link_buf = CosTrading::LinkNameSeq::allocbuf (valid_links.size ()); + + if (link_buf != 0) + { + for (i = valid_links.size () - 1; i >= 0; i--) + { + valid_links.dequeue_head (link_name); + link_buf[i] = CORBA::string_dup (link_name); + } + + ACE_NEW_RETURN (links, + CosTrading::LinkNameSeq (valid_links.size (), + valid_links.size (), + link_buf, + CORBA::B_TRUE), + 0); + } + } + + return should_follow; +} + + +template <class TRADER> void +TAO_Lookup<TRADER>:: +federated_query (const CosTrading::LinkNameSeq& links, + const char *type, + const char *constr, + const char *pref, + TAO_Policies& policies, + const CosTrading::Lookup::SpecifiedProps& desired_props, + CORBA::ULong how_many, + CosTrading::OfferSeq_out offers, + CosTrading::OfferIterator_out offer_iter, + CosTrading::PolicyNameSeq_out limits, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::IllegalConstraint, + CosTrading::Lookup::IllegalPreference, + CosTrading::Lookup::IllegalPolicyName, + CosTrading::Lookup::PolicyTypeMismatch, + CosTrading::Lookup::InvalidPolicyValue, + CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName, + CosTrading::DuplicatePolicyName)) +{ + // The general idea here is this: We've assembled a number of links + // to follow, and we'll query each of them in turn. When we've + // assembled <return_card> number of offers, we've hit the ceiling + // and we back out. On each query we adjust the policies for the new + // trader by reducing the return_card, hop_count, etc..., and merge + // the results from the new query with the results from the previous + // queries. + + // We'll need the link and admin interfaces for this part of the + // federated query. + CORBA::ULong total_returned = 0, + return_card = policies.return_card (_env); + CosTrading::Link_ptr link_interface + = this->trader_.trading_components ().link_if (); + CosTrading::Admin_ptr admin_interface + = this->trader_.trading_components ().admin_if (); + + // Begin collecting all the various offer_iterators into a + // collection. The end result is a distributed tree of offer + // iterators, which if traversed in its entirety is probably hugely + // inefficient, but oh well, I can't think of a better solution. + TAO_Offer_Iterator_Collection* offer_iter_collection; + ACE_NEW (offer_iter_collection, TAO_Offer_Iterator_Collection); + + offer_iter_collection->add_offer_iterator (offer_iter); + total_returned = offers->length () + + offer_iter_collection->max_left (_env); + + for (int i = links.length () - 1; i >= 0; i--) + { + CosTrading::OfferSeq* out_offers = 0; + CosTrading::OfferIterator* out_offer_iter = 0; + CosTrading::PolicyNameSeq* out_limits = 0; + CosTrading::OfferSeq_var out_offers_var (out_offers); + CosTrading::OfferIterator_var out_offer_iter_var (out_offer_iter); + CosTrading::PolicyNameSeq_var out_limits_var (out_limits); + + TAO_TRY + { + // Obtain information about the link we're traversing. + CosTrading::Link::LinkInfo_var link_info = + link_interface->describe_link (links[i], TAO_TRY_ENV); + TAO_CHECK_ENV; + + // Prepare a set of policies to pass to the next trader. + CosTrading::PolicySeq_var new_pols = + policies.policies_to_pass (link_info->def_pass_on_follow_rule, + total_returned, + admin_interface); + + // Perform the federated query. + link_info->target-> + query (type, + constr, + pref, + new_pols.in (), + desired_props, + how_many - offers->length (), + CosTrading::OfferSeq_out (out_offers), + CosTrading::OfferIterator_out (out_offer_iter), + CosTrading::PolicyNameSeq_out (out_limits), + _env); + TAO_CHECK_ENV; + + // Merge the results. + CORBA::ULong offset = offers->length (); + offers->length (out_offers->length () + offset); + offer_iter_collection->add_offer_iterator (out_offer_iter); + for (int j = out_offers->length () - 1; j >= 0; j--) + offers[j + offset] = out_offers_var[j]; + + // Concatenate the limits applied. + offset = limits->length (); + offers->length (out_limits->length () + offset); + for (j = out_limits->length () - 1; j >= 0; j--) + limits[j + offset] = out_limits_var[j]; + + // If we've obtained all the offers we need, let's blow this + // joint. + if (total_returned >= return_card) + break; + } + TAO_CATCHANY + { + break; + } + TAO_ENDTRY; + } + + // Return the collection of offer iterators. + offer_iter = offer_iter_collection->_this (_env); +} + +template <class TRADER> void +TAO_Lookup<TRADER>:: +forward_query (const CosTrading::TraderName& starting_trader, + const char *type, + const char *constr, + const char *pref, + TAO_Policies& policies, + const CosTrading::Lookup::SpecifiedProps& desired_props, + CORBA::ULong how_many, + CosTrading::OfferSeq_out offers, + CosTrading::OfferIterator_out offer_itr, + CosTrading::PolicyNameSeq_out limits_applied, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::IllegalConstraint, + CosTrading::Lookup::IllegalPreference, + CosTrading::Lookup::IllegalPolicyName, + CosTrading::Lookup::PolicyTypeMismatch, + CosTrading::Lookup::InvalidPolicyValue, + CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName, + CosTrading::DuplicatePolicyName)) +{ + // Forward this query to the next link in the starting_trader sequence. + CosTrading::Link_ptr link_interface + = this->trader_.trading_components ().link_if (); + + TAO_TRY + { + CosTrading::Link::LinkInfo_var link_info = + link_interface->describe_link (starting_trader[0], TAO_TRY_ENV); + TAO_CHECK_ENV; + + CosTrading::PolicySeq_var in_policies = policies.policies_to_forward (); + + // Perform forwarding query. + link_info->target->query (type, + constr, + pref, + in_policies.in (), + desired_props, + how_many, + offers, + offer_itr, + limits_applied, + _env); + TAO_CHECK_ENV_RETURN_VOID (_env); + } + TAO_CATCHANY + { + TAO_THROW (CosTrading::Lookup::InvalidPolicyValue ()); + } + TAO_ENDTRY; +} + + // ************************************************************* + // TAO_Register + // ************************************************************* + +template <class TRADER> +TAO_Register<TRADER>::TAO_Register (TRADER &trader) + : trader_ (trader), + TAO_Trader_Components<POA_CosTrading::Register> (trader.trading_components ()), + TAO_Support_Attributes<POA_CosTrading::Register> (trader.support_attributes ()) +{ +} + +template <class TRADER> +TAO_Register<TRADER>::~TAO_Register (void) +{ +} + +template <class TRADER> CosTrading::OfferId +TAO_Register<TRADER>::export (CORBA::Object_ptr reference, + const char *type, + const CosTrading::PropertySeq &properties, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Register::InvalidObjectRef, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::Register::InterfaceTypeMismatch, + CosTrading::IllegalPropertyName, + CosTrading::PropertyTypeMismatch, + CosTrading::ReadonlyDynamicProperty, + CosTrading::MissingMandatoryProperty, + CosTrading::DuplicatePropertyName)) +{ + // For robustness purposes -- + if (CORBA::is_nil (reference)) + TAO_THROW_RETURN (CosTrading::Register::InvalidObjectRef (), 0); + + // Get service type map + Offer_Database &offer_database = this->trader_.offer_database (); + + CosTrading::Offer offer; + TAO_Support_Attributes_Impl& support_attrs = + this->trader_.support_attributes (); + CosTrading::TypeRepository_ptr type_repos = + support_attrs.type_repos (); + CosTradingRepos::ServiceTypeRepository_ptr rep = + CosTradingRepos::ServiceTypeRepository::_narrow (type_repos, _env); + TAO_CHECK_ENV_RETURN (_env, 0); + + // Yank our friend, the type struct, and confirm that the given + // properties match the type definition. + CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct = + rep->fully_describe_type (type, _env); + TAO_CHECK_ENV_RETURN (_env, 0); + + // Oops the type is masked, we shouldn't let exporters know the type + // exists. + if (type_struct->masked) + TAO_THROW_RETURN (CosTrading::UnknownServiceType (type), 0); + + // TAO-specific way to determine if an object is derived from or is + // an interface type. + if (! reference->_is_a (type_struct->if_name, _env)) + TAO_THROW_RETURN (CosTrading::Register:: + InterfaceTypeMismatch (type, reference), 0); + + // Validate that the properties defined for this offer are correct + // to their types and strength. + this->validate_properties (type, type_struct, + (CosTrading::PropertySeq&) properties, _env); + TAO_CHECK_ENV_RETURN (_env, 0); + + offer.reference = reference->_duplicate (reference); + offer.properties = properties; + + // Insert the offer into the underlying type map. + CosTrading::OfferId id = offer_database.insert_offer (type, offer); + + if (id == 0) + { + // Add type, if it's already been added in that split second + // since we've released the lock, nothing bad will happen. + id = offer_database.insert_offer (type, offer); + } + + return id; +} + +template <class TRADER> void +TAO_Register<TRADER>::withdraw (const char *id, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalOfferId, + CosTrading::UnknownOfferId, + CosTrading::Register::ProxyOfferId)) +{ + // Get service type map. + Offer_Database &offer_database = this->trader_.offer_database (); + offer_database.remove_offer ((CosTrading::OfferId) id, _env); +} + +template <class TRADER> CosTrading::Register::OfferInfo * +TAO_Register<TRADER>::describe (const char *id, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalOfferId, + CosTrading::UnknownOfferId, + CosTrading::Register::ProxyOfferId)) +{ + // Get service type map. + char* type = 0; + Offer_Database &offer_database = this->trader_.offer_database (); + + // Perform a lookup to find the offer. + CosTrading::Offer* offer = + offer_database.lookup_offer ((CosTrading::OfferId) id, type, _env); + TAO_CHECK_ENV_RETURN (_env, (CosTrading::Register::OfferInfo *) 0); + + CosTrading::Register::OfferInfo *offer_info = + new CosTrading::Register::OfferInfo (); + + offer_info->reference = offer->reference->_duplicate (offer->reference); + offer_info->type = CORBA::string_dup (type); + offer_info->properties = offer->properties; + + return offer_info; +} + +template <class TRADER> void +TAO_Register<TRADER>::modify (const char *id, + const CosTrading::PropertyNameSeq& del_list, + const CosTrading::PropertySeq& modify_list, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::NotImplemented, + CosTrading::IllegalOfferId, + CosTrading::UnknownOfferId, + CosTrading::Register::ProxyOfferId, + CosTrading::IllegalPropertyName, + CosTrading::Register::UnknownPropertyName, + CosTrading::PropertyTypeMismatch, + CosTrading::ReadonlyDynamicProperty, + CosTrading::Register::MandatoryProperty, + CosTrading::Register::ReadonlyProperty, + CosTrading::DuplicatePropertyName)) +{ + // Throw an exception if the trader is not configured + // to support properties modification. + if (! this->supports_modifiable_properties (_env)) + TAO_THROW (CosTrading::NotImplemented ()); + + char* type = 0; + TAO_Support_Attributes_Impl& support_attrs = + this->trader_.support_attributes (); + CosTrading::TypeRepository_ptr type_repos = support_attrs.type_repos (); + CosTradingRepos::ServiceTypeRepository_ptr rep = + CosTradingRepos::ServiceTypeRepository::_narrow (type_repos, _env); + TAO_CHECK_ENV_RETURN_VOID (_env); + Offer_Database &offer_database = this->trader_.offer_database (); + + CosTrading::Offer* offer = + offer_database.lookup_offer ((CosTrading::OfferId) id, type, _env); + TAO_CHECK_ENV_RETURN_VOID (_env); + + if (offer != 0) + { + // Yank our friend, the type struct. + CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct = rep->describe_type (type, _env); + TAO_CHECK_ENV_RETURN_VOID (_env); + TAO_Offer_Modifier offer_mod (type, type_struct, *offer); + + // Delete, add, and change properties of the offer. + this->validate_properties (type, type_struct, + (CosTrading::PropertySeq) modify_list, _env); + TAO_CHECK_ENV_RETURN_VOID (_env); + offer_mod.delete_properties (del_list, _env); + TAO_CHECK_ENV_RETURN_VOID (_env); + offer_mod.merge_properties (modify_list, _env); + TAO_CHECK_ENV_RETURN_VOID (_env); + + // Alter our reference to the offer. + offer_mod.affect_change (); + } +} + +template <class TRADER> void +TAO_Register<TRADER>::withdraw_using_constraint (const char *type, + const char *constr, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::IllegalConstraint, + CosTrading::Register::NoMatchingOffers)) +{ + int num_removed = 0; + TAO_Support_Attributes_Impl& + support_attrs = this->trader_.support_attributes (); + CosTrading::TypeRepository_ptr type_repos = support_attrs.type_repos (); + CosTradingRepos::ServiceTypeRepository_ptr rep = + CosTradingRepos::ServiceTypeRepository::_narrow (type_repos, _env); + Offer_Database &offer_database = this->trader_.offer_database (); + CORBA::Boolean dp_support = support_attrs.supports_dynamic_properties (); + ACE_Unbounded_Queue<CosTrading::OfferId_var> ids; + + // Retrieve the type struct + CosTradingRepos::ServiceTypeRepository::TypeStruct* + type_struct = rep->describe_type (type, _env); + TAO_CHECK_ENV_RETURN_VOID (_env); + + // Try to find the map of offers of desired service type. + Offer_Database::offer_iterator offer_iter (type, offer_database); + TAO_Constraint_Validator validator (type_struct); + TAO_Constraint_Interpreter constr_inter (validator, constr, _env); + TAO_CHECK_ENV_RETURN_VOID (_env); + + while (offer_iter.has_more_offers ()) + { + CosTrading::Offer* offer = offer_iter.get_offer (); + // Add offer if it matches the constraints + + TAO_Constraint_Evaluator evaluator (offer, dp_support); + if (constr_inter.evaluate (evaluator)) + ids.enqueue_tail (offer_iter.get_id ()); + + offer_iter.next_offer (); + } + + if (ids.size () == 0) + TAO_THROW (CosTrading::Register::NoMatchingOffers (constr)); + else + { + while (! ids.is_empty ()) + { + CosTrading::OfferId_var offer_id; + + ids.dequeue_head (offer_id); + offer_database.remove_offer (offer_id, _env); + } + } +} + +template <class TRADER> CosTrading::Register_ptr +TAO_Register<TRADER>::resolve (const CosTrading::TraderName &name, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Register::IllegalTraderName, + CosTrading::Register::UnknownTraderName, + CosTrading::Register::RegisterNotSupported)) +{ + // Determine if the first link is a legal link name. + if (! TAO_Trader_Base::is_valid_identifier_name (name[0])) + TAO_THROW_RETURN (CosTrading::Register::IllegalTraderName (name), + CosTrading::Register::_nil ()); + + // Grab a reference to the link interface, and get a link description. + CosTrading::Link_var link (this->link_if (_env)); + TAO_CHECK_ENV_RETURN (_env, CosTrading::Register::_nil ()); + CosTrading::Link::LinkInfo_var link_info; + + TAO_TRY + { + // Ensure that the link to the next trader exists. + link_info = link->describe_link (name[0], TAO_TRY_ENV); + TAO_CHECK_ENV; + } + TAO_CATCHANY + { + TAO_THROW_RETURN (CosTrading::Register::UnknownTraderName (name), + CosTrading::Register::_nil ()); + } + TAO_ENDTRY; + + // Ensure that the register pointer isn't nil. + if (link_info->target_reg.in() == CosTrading::Register::_nil ()) + TAO_THROW_RETURN (CosTrading::Register::RegisterNotSupported (name), + CosTrading::Register::_nil ()); + + CosTrading::Register_ptr return_value = link_info->target_reg; + + if (name.length () > 1) + { + // Create a new Trader Name with the first link removed. + CosTrading::TraderName trader_name (name.length () - 1); + for (int i = trader_name.length () - 1; i >= 0; i--) + trader_name[i] = name[i + 1]; + + return_value = link_info->target_reg->resolve (trader_name, _env); + TAO_CHECK_ENV_RETURN (_env, CosTrading::Register::_nil ()); + } + + return return_value; +} + +template <class TRADER> void +TAO_Register<TRADER>:: +validate_properties (const char* type, + CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct, + CosTrading::PropertySeq& properties, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, + CosTrading::PropertyTypeMismatch, + CosTrading::ReadonlyDynamicProperty, + CosTrading::MissingMandatoryProperty, + CosTrading::DuplicatePropertyName)) +{ + typedef CosTradingRepos::ServiceTypeRepository SERVICE_TYPE_REPOS; + + int length = properties.length (); + SERVICE_TYPE_REPOS::PropStructSeq& prop_types = type_struct->props; + TAO_Property_Evaluator_By_Name prop_eval (properties, _env); + TAO_CHECK_ENV_RETURN_VOID (_env); + + // Perform property validation + length = prop_types.length (); + for (int i = 0; i < length; i++) + { + SERVICE_TYPE_REPOS::PropStruct& prop_struct = prop_types[i]; + const char* prop_name = prop_struct.name; + + // Obtain the type of the exported property. + CORBA::TypeCode* prop_type = prop_eval.property_type (prop_name); + + if (prop_type == CORBA::TypeCode::_nil ()) + { + // Offer cannot have a missing mandatory property. + if (prop_types[i].mode == SERVICE_TYPE_REPOS::PROP_MANDATORY) + TAO_THROW (CosTrading::MissingMandatoryProperty (type, prop_name)); + } + else + { + if (! prop_type->equal (prop_struct.value_type, _env)) + { + // Offer cannot redefine the type of an property. + const CosTrading::Property* prop = prop_eval.get_property (prop_name); + TAO_THROW (CosTrading::PropertyTypeMismatch (type, *prop)); + } + else if (prop_struct.mode == SERVICE_TYPE_REPOS::PROP_READONLY && + prop_eval.is_dynamic_property (prop_name)) + TAO_THROW (CosTrading::ReadonlyDynamicProperty (type, prop_name)); + } + } +} + + // ************************************************************* + // TAO_Admin + // ************************************************************* + +template <class TRADER> +TAO_Admin<TRADER>::TAO_Admin (TRADER &trader) + : trader_ (trader), + TAO_Trader_Components <POA_CosTrading::Admin> (trader.trading_components ()), + TAO_Import_Attributes <POA_CosTrading::Admin> (trader.import_attributes ()), + TAO_Support_Attributes <POA_CosTrading::Admin> (trader.support_attributes ()), + TAO_Link_Attributes <POA_CosTrading::Admin> (trader.link_attributes ()), + sequence_number_ (0) +{ + // Because a servant is uniquely identified by a POA name and an + // ObjectID number, the concatenation of the two prefixed before a + // sequence number will ensure the request_id_stem space between + // traders will not overlap. The sequence number space will be four + // octets. + CORBA::Environment _env; + PortableServer::POA_var poa = this->_default_POA (_env); + PortableServer::ObjectId_var id = poa->servant_to_id (this, _env); + CORBA::String_var poa_name = poa->the_name (_env); + int name_length = ACE_OS::strlen (poa_name.in ()), + id_length = id->length (), + total_length = name_length + id_length + sizeof (CORBA::ULong); + + this->stem_id_.length (total_length); + // @@ Commented it out until a fix is found + + for (int i = total_length - 1, j = name_length - 1; j >= 0; i--, j--) + //this->stem_id_[i] = (CORBA::Octet) poa_name[j]; + ; + + + for (j = id_length - 1; j >= 0; j--, i--) + this->stem_id_[i] = id[j]; +} + +template <class TRADER> +TAO_Admin<TRADER>::~TAO_Admin (void) +{ +} + +template <class TRADER> CosTrading::Admin::OctetSeq * +TAO_Admin<TRADER>::request_id_stem (CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + // Add one to the sequence_number and concatenate it to the unique + // prefix. The sequence number is four octets long. + for (int i = sizeof (CORBA::ULong) - 1; i >= 0; i--) + this->stem_id_[i] = (this->sequence_number_ >> (8*i)) & 0xff; + + // Increment the sequence number and return a copy of the stem_id. + this->sequence_number_++; + return new CosTrading::Admin::OctetSeq (this->stem_id_); +} + +template <class TRADER> CORBA::ULong +TAO_Admin<TRADER>::set_def_search_card (CORBA::ULong value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::ULong return_value = + this->trader_.import_attributes ().def_search_card (); + + this->trader_.import_attributes ().def_search_card (value); + return return_value; +} + +template <class TRADER> CORBA::ULong +TAO_Admin<TRADER>::set_max_search_card (CORBA::ULong value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::ULong return_value = + this->trader_.import_attributes ().max_search_card (); + + this->trader_.import_attributes ().max_search_card (value); + return return_value; +} + +template <class TRADER> CORBA::ULong +TAO_Admin<TRADER>::set_def_match_card (CORBA::ULong value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::ULong return_value = + this->trader_.import_attributes ().def_match_card (); + + this->trader_.import_attributes ().def_match_card (value); + return return_value; +} + +template <class TRADER> CORBA::ULong +TAO_Admin<TRADER>::set_max_match_card (CORBA::ULong value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::ULong return_value = + this->trader_.import_attributes ().max_match_card (); + + this->trader_.import_attributes ().max_match_card (value); + return return_value; +} + +template <class TRADER> CORBA::ULong +TAO_Admin<TRADER>::set_def_return_card (CORBA::ULong value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::ULong return_value = + this->trader_.import_attributes ().def_return_card (); + + this->trader_.import_attributes ().def_return_card (value); + return return_value; +} + +template <class TRADER> CORBA::ULong +TAO_Admin<TRADER>::set_max_return_card (CORBA::ULong value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::ULong return_value = + this->trader_.import_attributes ().max_return_card (); + + this->trader_.import_attributes ().max_return_card (value); + return return_value; +} + +template <class TRADER> CORBA::ULong +TAO_Admin<TRADER>::set_max_list (CORBA::ULong value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::ULong return_value = + this->trader_.import_attributes ().max_list (); + + this->trader_.import_attributes ().max_list (value); + return return_value; +} + +template <class TRADER> CORBA::Boolean +TAO_Admin<TRADER>:: +set_supports_modifiable_properties (CORBA::Boolean value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::Boolean return_value = + this->trader_.support_attributes ().supports_modifiable_properties (); + + this->trader_.support_attributes ().supports_modifiable_properties (value); + return return_value; +} + +template <class TRADER> CORBA::Boolean +TAO_Admin<TRADER>:: +set_supports_dynamic_properties (CORBA::Boolean value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::Boolean return_value = + this->trader_.support_attributes ().supports_dynamic_properties (); + + this->trader_.support_attributes ().supports_dynamic_properties (value); + return return_value; +} + +template <class TRADER> CORBA::Boolean +TAO_Admin<TRADER>::set_supports_proxy_offers (CORBA::Boolean value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::Boolean return_value = + this->trader_.support_attributes ().supports_proxy_offers (); + + this->trader_.support_attributes ().supports_proxy_offers (value); + return return_value; +} + +template <class TRADER> CORBA::ULong +TAO_Admin<TRADER>::set_def_hop_count (CORBA::ULong value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::ULong return_value = + this->trader_.import_attributes ().def_hop_count (); + + this->trader_.import_attributes ().def_hop_count (value); + return return_value; +} + +template <class TRADER> CORBA::ULong +TAO_Admin<TRADER>::set_max_hop_count (CORBA::ULong value, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::ULong return_value = + this->trader_.import_attributes ().max_hop_count (); + + this->trader_.import_attributes ().max_hop_count (value); + return return_value; +} + +template <class TRADER> CosTrading::FollowOption +TAO_Admin<TRADER>::set_def_follow_policy (CosTrading::FollowOption policy, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CosTrading::FollowOption return_value = + this->trader_.import_attributes ().def_follow_policy (); + + this->trader_.import_attributes ().def_follow_policy (policy); + return return_value; +} + +template <class TRADER> CosTrading::FollowOption +TAO_Admin<TRADER>::set_max_follow_policy (CosTrading::FollowOption policy, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CosTrading::FollowOption return_value = + this->trader_.import_attributes ().max_follow_policy (); + + this->trader_.import_attributes ().max_follow_policy (policy); + return return_value; +} + +template <class TRADER> CosTrading::FollowOption +TAO_Admin<TRADER>:: +set_max_link_follow_policy (CosTrading::FollowOption policy, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CosTrading::FollowOption return_value = + this->trader_.link_attributes ().max_link_follow_policy (); + + this->trader_.link_attributes ().max_link_follow_policy (policy); + return return_value; +} + +template <class TRADER> CosTrading::TypeRepository_ptr +TAO_Admin<TRADER>:: +set_type_repos (CosTrading::TypeRepository_ptr repository, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + CosTrading::TypeRepository_ptr return_value = + this->trader_.support_attributes ().type_repos (); + + this->trader_.support_attributes ().type_repos (repository); + return return_value; +} + +template <class TRADER> CosTrading::Admin::OctetSeq* +TAO_Admin<TRADER>::set_request_id_stem (const CosTrading::Admin::OctetSeq& stem, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + return 0; +} + +template <class TRADER> void +TAO_Admin<TRADER>::list_offers (CORBA::ULong how_many, + CosTrading::OfferIdSeq_out ids, + CosTrading::OfferIdIterator_out id_itr, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException,) + CosTrading::NotImplemented) +{ + // This method only applies when the register interface is implemented + if (CORBA::is_nil(this->trader_.trading_components().register_if())) + TAO_THROW (CosTrading::NotImplemented()); + + TRADER::Offer_Database& type_map = this->trader_.offer_database (); + + CosTrading::OfferIdIterator_ptr oi = + type_map.retrieve_all_offer_ids ()->_this (_env); + TAO_CHECK_ENV_RETURN_VOID (_env); + + id_itr = CosTrading::OfferIdIterator::_nil (); + if (how_many > 0) + { + if (oi->next_n (how_many, ids, _env) == CORBA::B_FALSE) + { + // No more items left in the iterator. + oi->destroy (_env); + oi = CosTrading::OfferIdIterator::_nil (); + } + else + id_itr = oi; + } + else + ids = new CosTrading::OfferIdSeq(0); +} + +template <class TRADER> void +TAO_Admin<TRADER>::list_proxies (CORBA::ULong how_many, + CosTrading::OfferIdSeq_out ids, + CosTrading::OfferIdIterator_out id_itr, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::NotImplemented)) +{ + TAO_THROW (CosTrading::NotImplemented ()); +} + + // ************************************************************* + // TAO_Link + // ************************************************************* + + +template <class TRADER, class MAP_LOCK_TYPE> +TAO_Link<TRADER,MAP_LOCK_TYPE>::TAO_Link (TRADER &trader) + : trader_ (trader), + TAO_Trader_Components <POA_CosTrading::Link> (trader.trading_components ()), + TAO_Link_Attributes <POA_CosTrading::Link> (trader.link_attributes ()), + TAO_Support_Attributes <POA_CosTrading::Link> (trader.support_attributes ()) +{ +} + +template <class TRADER, class MAP_LOCK_TYPE> +TAO_Link<TRADER,MAP_LOCK_TYPE>::~TAO_Link (void) +{ +} + +template <class TRADER, class MAP_LOCK_TYPE> void +TAO_Link<TRADER, MAP_LOCK_TYPE>:: +add_link (const char *name, + CosTrading::Lookup_ptr target, + CosTrading::FollowOption def_pass_on_follow_rule, + CosTrading::FollowOption limiting_follow_rule, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Link::IllegalLinkName, + CosTrading::Link::DuplicateLinkName, + CosTrading::InvalidLookupRef, + CosTrading::Link::DefaultFollowTooPermissive, + CosTrading::Link::LimitingFollowTooPermissive)) +{ + // Ensure the link name is valid. + if (! TAO_Trader_Base::is_valid_identifier_name (name)) + TAO_THROW (CosTrading::Link::IllegalLinkName (name)); + + // Ensure this isn't a duplicate link name. + TAO_String_Hash_Key link_name (name); + if (this->links_.find (link_name) == -1) + TAO_THROW (CosTrading::Link::DuplicateLinkName (name)); + + // Ensure the lookup_ptr isn't nil. + if (target == CosTrading::Lookup::_nil()) + TAO_THROW (CosTrading::InvalidLookupRef (target)); + + // Ensure that the default link behavior isn't stronger than the + // limiting link behavior. + if (def_pass_on_follow_rule > limiting_follow_rule) + TAO_THROW (CosTrading::Link::DefaultFollowTooPermissive + (def_pass_on_follow_rule, limiting_follow_rule)); + + // Ensure that the limiting link behavior for this link doesn't + // exceed the maximum allowed for a link. + if (limiting_follow_rule < this->max_link_follow_policy (_env)) + TAO_THROW (CosTrading::Link::LimitingFollowTooPermissive + (limiting_follow_rule, this->max_link_follow_policy (_env))); + + // Create a link info structure for this link of the federation. + CosTrading::Link::LinkInfo link_info; + link_info.target = target; + link_info.target_reg = target->register_if (_env); + link_info.def_pass_on_follow_rule = def_pass_on_follow_rule; + link_info.limiting_follow_rule = limiting_follow_rule; + TAO_CHECK_ENV_RETURN_VOID (_env); + + // Insert this link into the collection of links. + this->links_.bind (link_name, link_info); +} + +template <class TRADER, class MAP_LOCK_TYPE> void +TAO_Link<TRADER,MAP_LOCK_TYPE>::remove_link (const char *name, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Link::IllegalLinkName, + CosTrading::Link::UnknownLinkName)) +{ + // Ensure the link name is valid. + if (! TAO_Trader_Base::is_valid_identifier_name (name)) + TAO_THROW (CosTrading::Link::IllegalLinkName (name)); + + // Ensure this isn't a duplicate link name. + TAO_String_Hash_Key link_name (name); + if (this->links_.find (link_name) == -1) + TAO_THROW (CosTrading::Link::UnknownLinkName (name)); + + // Erase the link state from the map. + this->links_.unbind (link_name); +} + +template <class TRADER, class MAP_LOCK_TYPE> CosTrading::Link::LinkInfo * +TAO_Link<TRADER,MAP_LOCK_TYPE>::describe_link (const char *name, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::SystemException, + CosTrading::Link::IllegalLinkName, + CosTrading::Link::UnknownLinkName)) +{ + // Ensure the link name is valid. + if (! TAO_Trader_Base::is_valid_identifier_name (name)) + TAO_THROW_RETURN (CosTrading::Link::IllegalLinkName (name), 0); + + // Ensure this isn't a duplicate link name. + Links::ENTRY* link_entry; + TAO_String_Hash_Key link_name (name); + if (this->links_.find (link_name, link_entry) == -1) + TAO_THROW_RETURN (CosTrading::Link::UnknownLinkName (name), 0); + + // return the link infor for this link name. + return &(link_entry->int_id_); +} + +template <class TRADER, class MAP_LOCK_TYPE> CosTrading::LinkNameSeq* +TAO_Link<TRADER,MAP_LOCK_TYPE>::list_links (CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)) +{ + // Allocate space for the link names. + CORBA::ULong size = this->links_.current_size (), i = 0; + CosTrading::LinkName* link_seq = + CosTrading::LinkNameSeq::allocbuf (size); + + // Copy the link names into the buffer. + for (Links::iterator links_iter (this->links_); + ! links_iter.done (); + links_iter++) + link_seq[i++] = CORBA::string_dup ((*links_iter).ext_id_.in ()); + + // Return a sequence of the buf names. + return new CosTrading::LinkNameSeq (i, i, link_seq, CORBA::B_TRUE); +} + +template <class TRADER, class MAP_LOCK_TYPE> void +TAO_Link<TRADER,MAP_LOCK_TYPE>:: +modify_link (const char *name, + CosTrading::FollowOption def_pass_on_follow_rule, + CosTrading::FollowOption limiting_follow_rule, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Link::IllegalLinkName, + CosTrading::Link::UnknownLinkName, + CosTrading::Link::DefaultFollowTooPermissive, + CosTrading::Link::LimitingFollowTooPermissive)) +{ + // Ensure the link name is valid. + if (! TAO_Trader_Base::is_valid_identifier_name (name)) + TAO_THROW (CosTrading::Link::IllegalLinkName (name)); + + // Ensure this isn't a duplicate link name. + Links::ENTRY* link_entry = 0; + TAO_String_Hash_Key link_name (name); + if (this->links_.find (link_name, link_entry) == -1) + TAO_THROW (CosTrading::Link::UnknownLinkName (name)); + + // Ensure that the default link behavior isn't stronger than the + // limiting link behavior. + if (def_pass_on_follow_rule > limiting_follow_rule) + TAO_THROW (CosTrading::Link::DefaultFollowTooPermissive + (def_pass_on_follow_rule, limiting_follow_rule)); + + // Ensure that the limiting link behavior for this link doesn't + // exceed the maximum allowed for a link. + if (limiting_follow_rule < this->max_link_follow_policy (_env)) + TAO_THROW (CosTrading::Link::LimitingFollowTooPermissive + (limiting_follow_rule, this->max_link_follow_policy (_env))); + + // Adjust the link settings + CosTrading::Link::LinkInfo& link_info = link_entry->int_id_; + link_info.def_pass_on_follow_rule = def_pass_on_follow_rule; + link_info.limiting_follow_rule = limiting_follow_rule; +} + + // ************************************************************* + // TAO_Proxy + // ************************************************************* + +template <class TRADER> +TAO_Proxy<TRADER>::TAO_Proxy (TRADER &trader) + : trader_ (trader), + TAO_Trader_Components <POA_CosTrading::Proxy> (trader.trading_components ()), + TAO_Support_Attributes <POA_CosTrading::Proxy> (trader.support_attributes ()) +{ +} + +template <class TRADER> +TAO_Proxy<TRADER>::~TAO_Proxy (void) +{ +} + +template <class TRADER> CosTrading::OfferId +TAO_Proxy<TRADER>::export_proxy (CosTrading::Lookup_ptr target, + const char *type, + const CosTrading::PropertySeq& properties, + CORBA::Boolean if_match_all, + const char * recipe, + const CosTrading::PolicySeq& policies_to_pass_on, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::InvalidLookupRef, + CosTrading::IllegalPropertyName, + CosTrading::PropertyTypeMismatch, + CosTrading::ReadonlyDynamicProperty, + CosTrading::MissingMandatoryProperty, + CosTrading::Proxy::IllegalRecipe, + CosTrading::DuplicatePropertyName, + CosTrading::DuplicatePolicyName)) +{ + TAO_THROW_RETURN (CORBA::UNKNOWN (CORBA::COMPLETED_NO), 0); +} + +template <class TRADER> void +TAO_Proxy<TRADER>::withdraw_proxy (const char *id, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalOfferId, + CosTrading::UnknownOfferId, + CosTrading::Proxy::NotProxyOfferId)) +{ + TAO_THROW (CORBA::UNKNOWN (CORBA::COMPLETED_NO)); +} + +template <class TRADER> CosTrading::Proxy::ProxyInfo * +TAO_Proxy<TRADER>::describe_proxy (const char *id, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalOfferId, + CosTrading::UnknownOfferId, + CosTrading::Proxy::NotProxyOfferId)) +{ + TAO_THROW_RETURN (CORBA::UNKNOWN (CORBA::COMPLETED_NO), 0); +} + +template <class TRADER> void +TAO_Proxy<TRADER>::list_proxies (CORBA::ULong how_many, + CosTrading::OfferIdSeq*& ids, + CosTrading::OfferIdIterator_ptr& id_itr, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::NotImplemented)) +{ + TAO_THROW (CORBA::UNKNOWN (CORBA::COMPLETED_NO)); +} + +#endif /* TAO_TRADER_INTERFACES_C */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Trader_Interfaces.h b/TAO/orbsvcs/orbsvcs/Trader/Trader_Interfaces.h new file mode 100644 index 00000000000..405ab862bbe --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Trader/Trader_Interfaces.h @@ -0,0 +1,1022 @@ +/* -*- C++ -*- */ + +// ======================================================================== +// $Id$ +// +// = LIBRARY +// orbsvcs +// +// = FILENAME +// Trader_Interfaces.h +// +// = AUTHOR +// Marina Spivak <marina@cs.wustl.edu> +// Seth Widoff <sbw1@cs.wustl.edu> +// Irfan Pyarali <irfan@cs.wustl.edu> +// +// ======================================================================== + +#ifndef TAO_TRADER_INTERFACES_H +#define TAO_TRADER_INTERFACES_H + +#include "Attributes_T.h" +#include "Trader_Utils.h" +#include "Offer_Iterators_T.h" +#include "Constraint_Interpreter.h" + + // ************************************************************* + // TAO_Lookup + // ************************************************************* + +template<class TRADER> +class TAO_Lookup : + public TAO_Trader_Components<POA_CosTrading::Lookup>, + public TAO_Support_Attributes<POA_CosTrading::Lookup>, + public TAO_Import_Attributes<POA_CosTrading::Lookup> + // + // = TITLE + // This class implements CosTrading::Lookup IDL interface. +{ +public: + + TAO_Lookup (TRADER &trader); + + ~TAO_Lookup (void); + + virtual void + query (const char *type, + const char *constr, + const char *pref, + const CosTrading::PolicySeq& policies, + const CosTrading::Lookup::SpecifiedProps& desired_props, + CORBA::ULong how_many, + CosTrading::OfferSeq_out offers, + CosTrading::OfferIterator_out offer_itr, + CosTrading::PolicyNameSeq_out limits_applied, + CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::IllegalConstraint, + CosTrading::Lookup::IllegalPreference, + CosTrading::Lookup::IllegalPolicyName, + CosTrading::Lookup::PolicyTypeMismatch, + CosTrading::Lookup::InvalidPolicyValue, + CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName, + CosTrading::DuplicatePolicyName)); + + // BEGIN SPEC + // The query operation is the means by which an object can obtain + // references to other objects that provide services meeting its + // requirements. + + // The "type" parameter conveys the required service type. It is key + // to the central purpose of trading: to perform an introduction for + // future type safe interactions between importer and exporter. By + // stating a service type, the importer implies the desired interface + // type and a domain of discourse for talking about properties of the + // service. + + // The trader may return a service offer of a subtype of the "type" + // requested. Sub-typing of service types is discussed in "Service + // Types" on page 16-4. A service subtype can be described by the + // properties of its supertypes. This ensures that a well-formed + // query for the "type" is also a well-formed query with respect to + // any subtypes. However, if the importer specifies the policy of + // exact_type_match = TRUE, then only offers with the exact (no + // subtype) service type requested are returned. + + // The constraint "constr" is the means by which the importer states + // those requirements of a service that are not captured in the + // signature of the interface. These requirements deal with the + // computational behavior of the desired service, non-functional + // aspects, and non-computational aspects (such as the organization + // owning the objects that provide the service). An importer is + // always guaranteed that any returned offer satisfies the matching + // constraint at the time of import. If the "constr" does not obey + // the syntax rules for a legal constraint expression, then an + // IllegalConstraint exception is raised. + + // The "pref" parameter is also used to order those offers that + // match the "constr" so that the offers returned by the trader are + // in the order of greatest interest to the importer. If "pref" does + // not obey the syntax rules for a legal preference expression, then + // an IllegalPreference exception is raised. + + // 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. + + // The "desired_props" parameter defines the set of properties + // describing returned offers that are to be returned with the + // object reference. There are three possibilities, the importer + // wants one of the properties, all of the properties (but without + // having to name them), or some properties (the names of which are + // provided). + + // The desired_props parameter does not affect whether or not a + // service offer is returned. To avoid "missing" desired properties, + // the importer should specify "exists prop_name" in the + // constraint. + + // The returned offers are passed back in one of two ways (or a + // combination of both). °The "offers" return result conveys a list + // of offers and the "offer_itr" is a reference to an interface at + // which offers can be obtained. The "how_many" parameter states + // how many offers are to be returned via the "offers" result, any + // remaining offers are available via the iterator interface. If the + // "how_many" exceeds the number of offers to be returned, then the + // "offer_itr" will be nil. + + // 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 TRADER::Offer_Database Offer_Database; + + struct Offer_Info + { + CosTrading::OfferId offer_id_; + CosTrading::Offer* offer_ptr_; + }; + + typedef ACE_Unbounded_Queue<Offer_Info> Offer_Queue; + + TAO_Offer_Iterator* + create_offer_iterator (const char *type, + const TAO_Property_Filter& filter); + // Factory method for creating an appropriate Offer Iterator based + // on the presence of the Register Interface. + + void perform_lookup (const char* type, + const char* constraint, + const char* preferences, + Offer_Database& offer_database, + CosTradingRepos::ServiceTypeRepository_ptr rep, + TAO_Policies& policies, + Offer_Queue& ordered_offers, + CosTrading::PolicyNameSeq_out returned_limits_applied, + CORBA::Environment& env) + TAO_THROW_SPEC ((CosTrading::IllegalConstraint, + CosTrading::Lookup::IllegalPreference, + CosTrading::Lookup::PolicyTypeMismatch, + CosTrading::Lookup::InvalidPolicyValue, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType)); + // This method has three phases. The first phase passes the + // offer_map through the constraint interpreter, winnowing away + // those offers that don't match the validated constraint. The + // second phase orders the offers using the specified + // preferences. The last phase places the ordered offers into a list + // for returning. At each phase, the cardinality policies specified + // in the policies structure determine the number of offers + // submitted to each phase. + + void lookup_all_subtypes (const char* type, + CosTradingRepos::ServiceTypeRepository::IncarnationNumber& inc_num, + Offer_Database& offer_database, + CosTradingRepos::ServiceTypeRepository_ptr rep, + TAO_Constraint_Interpreter& constr_inter, + TAO_Preference_Interpreter& pref_inter, + TAO_Offer_Filter& offer_filter); + // Traverse the type hierarchy to pull the matching offers from all + // subtypes of the root type. + + void lookup_one_type (const char* type, + Offer_Database& offer_database, + TAO_Constraint_Interpreter& constr_inter, + TAO_Preference_Interpreter& pref_inter, + TAO_Offer_Filter& offer_filter); + // Check if offers of a type fit the constraints and order them + // according to the preferences submitted. + + int fill_receptacles (const char* type, + Offer_Queue& ordered_offers, + CORBA::ULong how_many, + const CosTrading::Lookup::SpecifiedProps& desired_props, + CosTrading::OfferSeq*& offers, + CosTrading::OfferIterator_ptr& offer_itr, + CORBA::Environment& env) + TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName)); + // This method takes the list of ordered offers and places a number + // of them in the sequence of returned offers and the rest into thr + // iterator. In addition, fill_receptacles uses the + // TAO_Property_Filter to ensure the returned offers contain the + // properties specified in the desired_props in parameter. + + void forward_query (const CosTrading::TraderName& starting_trader, + const char *type, + const char *constr, + const char *pref, + TAO_Policies& policies, + const CosTrading::Lookup::SpecifiedProps& desired_props, + CORBA::ULong how_many, + CosTrading::OfferSeq_out offers, + CosTrading::OfferIterator_out offer_itr, + CosTrading::PolicyNameSeq_out limits_applied, + CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::IllegalConstraint, + CosTrading::Lookup::IllegalPreference, + CosTrading::Lookup::IllegalPolicyName, + CosTrading::Lookup::PolicyTypeMismatch, + CosTrading::Lookup::InvalidPolicyValue, + CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName, + CosTrading::DuplicatePolicyName)); + // If a starting_trader policy was specfied, foward the query to the + // next link in the sequence. + + CORBA::Boolean duplicate_stem_id (TAO_Policies& policies, + CORBA::Environment& _env); + // Determine if the stem id provided to the query is one we've + // already seen. + + CORBA::Boolean retrieve_links (TAO_Policies& policies, + CORBA::ULong offer_returned, + CosTrading::LinkNameSeq_out links, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Lookup::PolicyTypeMismatch)); + // Assemble a sequence of links that the federate_query method + // should follow. Use the starting_trader policy, if one's provided, + // otherwise use the Link interface to determine which of the + // registered links should be followed in this query. + + void federated_query (const CosTrading::LinkNameSeq& links, + const char *type, + const char *constr, + const char *pref, + TAO_Policies& policies, + const CosTrading::Lookup::SpecifiedProps& desired_props, + CORBA::ULong how_many, + CosTrading::OfferSeq_out offers, + CosTrading::OfferIterator_out offer_itr, + CosTrading::PolicyNameSeq_out limits_applied, + CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::IllegalConstraint, + CosTrading::Lookup::IllegalPreference, + CosTrading::Lookup::IllegalPolicyName, + CosTrading::Lookup::PolicyTypeMismatch, + CosTrading::Lookup::InvalidPolicyValue, + CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName, + CosTrading::DuplicatePolicyName)); + // Perform and pass on a query over a set of links. Merge the + // results of the federated queries into a single set of results + // suitable for returning to the user. + + // = Disallow these operations. + ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Lookup<TRADER> &)) + ACE_UNIMPLEMENTED_FUNC (TAO_Lookup (const TAO_Lookup<TRADER> &)) + + TRADER &trader_; + // A reference to the trader for obtaining offer maps. + + typedef ACE_Unbounded_Set + < + CosTrading::Admin::OctetSeq_var + > + Request_Ids; + + Request_Ids request_ids_; + // A list of recent request_id_stems + + // TAO_Register_Offer_Iterator<TRADER> msvc_dummy_; +}; + + + // ************************************************************* + // TAO_Register + // ************************************************************* + +template <class TRADER> +class TAO_Register : + public TAO_Trader_Components<POA_CosTrading::Register>, + public TAO_Support_Attributes<POA_CosTrading::Register> + // + // = TITLE + // This class implements CosTrading::Register IDL interface. +{ +public: + + TAO_Register (TRADER &trader); + + virtual ~TAO_Register (void); + + virtual CosTrading::OfferId export (CORBA::Object_ptr reference, + const char *type, + const CosTrading::PropertySeq& properties, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Register::InvalidObjectRef, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::Register::InterfaceTypeMismatch, + CosTrading::IllegalPropertyName, + CosTrading::PropertyTypeMismatch, + CosTrading::ReadonlyDynamicProperty, + CosTrading::MissingMandatoryProperty, + CosTrading::DuplicatePropertyName)); + + // BEGIN SPEC + // The export operation is the means by which a service is + // advertised, via a trader, to a community of potential + // importers. The OfferId returned is the handle with which the + // exporter can identify the exported offer when attempting to + // access it via other operations. The OfferId is only meaningful in + // the context of the trader that generated it. + + // The "reference" parameter is the information that enables a client + // to interact with a remote server. If a trader implementation chooses + // to consider certain types of object references (e.g., a nil object + // reference) to be unexportable, then it may return the InvalidObjectRef + // exception in such cases. + + // The "type" parameter + // identifies the service type, which contains the interface type of + // the "reference" and a set of named property types that may be + // used in further describing this offer (i.e., it restricts what is + // acceptable in the properties parameter). ° + + // If the string + // representation of the "type" does not obey the rules for + // identifiers, then an IllegalServiceType exception is raised. ° If + // the "type" is correct syntactically but a trader is able to + // unambiguously determine that it is not a recognized service type, + // then an UnknownServiceType exception is raised. ° + + // If the trader + // can determine that the interface type of the "reference" + // parameter is not a subtype of the interface type specified in + // "type," then an InterfaceTypeMismatch exception is raised. The + // "properties" parameter is a list of named values that conform to + // the property value types defined for those names. They describe + // the service being offered. This description typically covers + // behavioral, non-functional, and non-computational aspects of the + // service. ° + + // If any of the property names do not obey the syntax + // rules for PropertyNames, then an IllegalPropertyName exception is + // raised. ° + + // If the type of any of the property values is not the + // same as the declared type (declared in the service type), then a + // PropertyTypeMismatch exception is raised. + + // ° If an attempt is made to assign a dynamic property value to a + // readonly property, then the ReadonlyDynamicProperty exception is + // raised. ° If the "properties" parameter omits any property + // declared in the service type with a mode of mandatory, then a + // MissingMandatoryProperty exception is raised. ° If two or more + // properties with the same property name are included in this + // parameter, the DuplicatePropertyName exception is raised. + // END SPEC + + virtual void withdraw (const char *id, CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalOfferId, + CosTrading::UnknownOfferId, + CosTrading::Register::ProxyOfferId)); + + // BEGIN SPEC + // The withdraw operation removes the service offer from the trader + // (i.e., after withdraw the offer can no longer be returned as the + // result of a query). The offer is identified by the "id" parameter + // which was originally returned by export. ° If the string + // representation of "id" does not obey the rules for offer + // identifiers, then an IllegalOfferId exception is raised. ° If the + // "id" is legal but there is no offer within the trader with that + // "id," then an UnknownOfferId exception is raised. ° If the "id" + // identifies a proxy offer rather than an ordinary offer, then a + // ProxyOfferId exception is raised. + // END SPEC + + virtual CosTrading::Register::OfferInfo* + describe (const char * id, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalOfferId, + CosTrading::UnknownOfferId, + CosTrading::Register::ProxyOfferId)); + + // BEGIN SPEC + // The describe operation returns the information about an offered + // service that is held by the trader. It comprises the "reference" + // of the offered service, the "type" of the service offer, and the + // "properties" that describe this offer of service. The offer is + // identified by the "id" parameter which was originally returned by + // export. ° If the string representation of "id" does not obey the + // rules for object identifiers, then an IllegalOfferId exception is + // raised. ° If the "id" is legal but there is no offer within the + // trader with that "id," then an UnknownOfferId exception is + // raised. ° If the "id" identifies a proxy offer rather than an + // ordinary offer, then a ProxyOfferId exception is raised. + // END SPEC + + virtual void modify (const char * id, + const CosTrading::PropertyNameSeq& del_list, + const CosTrading::PropertySeq& modify_list, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::NotImplemented, + CosTrading::IllegalOfferId, + CosTrading::UnknownOfferId, + CosTrading::Register::ProxyOfferId, + CosTrading::IllegalPropertyName, + CosTrading::Register::UnknownPropertyName, + CosTrading::PropertyTypeMismatch, + CosTrading::ReadonlyDynamicProperty, + CosTrading::Register::MandatoryProperty, + CosTrading::Register::ReadonlyProperty, + CosTrading::DuplicatePropertyName)); + + // BEGIN SPEC + // The modify operation is used to change the description of a + // service as held within a service offer. The object reference and + // the service type associated with the offer cannot be + // changed. This operation may: ° add new (non-mandatory) properties + // to describe an offer, ° change the values of some existing (not + // readonly) properties, or ° delete existing (neither mandatory nor + // readonly) properties. + + // The modify operation either succeeds completely or it fails + // completely. The offer is identified by the "id" parameter which + // was originally returned by export. ° If the string representation + // of "id" does not obey the rules for offer identifiers, then an + // IllegalOfferId exception is raised. ° If the "id" is legal but + // there is no offer within the trader with that "id," then an + // UnknownOfferId exception is raised. ° If the "id" identifies a + // proxy offer rather than an ordinary offer, then a ProxyOfferId + // exception is raised. + + // The "del_list" parameter gives the names of the properties that + // are no longer to be recorded for the identified offer. Future + // query and describe operations will not see these properties. ° If + // any of the names within the "del_list" do not obey the rules for + // PropertyName's, then an IllegalPropertyName exception is + // raised. ° If a "name" is legal but there is no property for the + // offer with that "name," then an UnknownPropertyName exception is + // raised. ° If the list includes a property that has a mandatory + // mode, then the MandatoryProperty exception is raised. ° If the + // same property name is included two or more times in this + // parameter, the DuplicatePropertyName exception is raised. + + // The "modify_list" parameter gives the names and values of + // properties to be changed. If the property is not in the offer, + // then the modify operation adds it. The modified (or added) + // property values are returned in future query and describe + // operations in place of the original values. ° If any of the names + // within the "modify_list" do not obey the rules for + // PropertyName's, then an IllegalPropertyName exception is + // raised. ° If the list includes a property that has a readonly + // mode, then the ReadonlyProperty exception is raised unless that + // readonly property is not currently recorded for the offer. The + // ReadonlyDynamicProperty exception is raised if an attempt is made + // to assign a dynamic property value to a readonly property. ° If + // the value of any modified property is of a type that is not the + // same as the type expected, then the PropertyTypeMismatch + // exception is raised. ° If two or more properties with the same + // property name are included in this argument, the + // DuplicatePropertyName exception is raised. + + // The NotImplemented exception shall be raised if and only if the + // supports_modifiable_properties attribute yields FALSE. + // END SPEC + + virtual void withdraw_using_constraint (const char *type, + const char *constr, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::IllegalConstraint, + CosTrading::Register::NoMatchingOffers)); + + // BEGIN SPEC + // The withdraw_using_constraint operation withdraws a set of offers + // from within a single trader. This set is identified in the same + // way that a query operation identifies a set of offers to be + // returned to an importer. + + // The "type" parameter conveys the required service type. Each + // offer of the specified type will have the constraint expression + // applied to it. If it matches the constraint expression, then the + // offer will be withdrawn.° If "type" does not obey the rules for + // service types, then an IllegalServiceType exception is raised. ° + // If the "type" is correct syntactically but is not recognized as a + // service type by the trader, then an UnknownServiceType exception + // is raised. + + // The constraint "constr" is the means by which the client + // restricts the set of offers to those that are intended for + // withdrawal. ° If "constr" does not obey the syntax rules for a + // constraint then an IllegalConstraint exception is raised. ° If + // the constraint fails to match with any offer of the specified + // service type, then a NoMatchingOffers exception is raised. + // END SPEC + + virtual CosTrading::Register_ptr + resolve (const CosTrading::TraderName &name, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Register::IllegalTraderName, + CosTrading::Register::UnknownTraderName, + CosTrading::Register::RegisterNotSupported)); + + // BEGIN SPEC + // This operation is used to resolve a context relative name for + // another trader. In particular, it is used when exporting to a + // trader that is known by a name rather than by an object + // reference. The client provides the name, which will be a sequence + // of name components. ° If the content of the parameter cannot + // yield legal syntax for the first component, then the + // IllegalTraderName exception is raised. Otherwise, the first name + // component is compared against the name held in each link. ° If no + // match is found, or the trader does not support links, the + // UnknownTraderName exception is raised. Otherwise, the trader + // obtains the register_if held as part of the matched link. ° If + // the Register interface is not nil, then the trader binds to the + // Register interface and invokes resolve but passes the TraderName + // with the first component removed; if it is nil, then the + // RegisterNotSupported exception is raised. When a trader is able + // to match the first name component leaving no residual name, that + // trader returns the reference for the Register interface for that + // linked trader. In unwinding the recursion, intermediate traders + // return the Register interface reference to their client (another + // trader). + // END SPEC + + protected: + + typedef TRADER::Offer_Database Offer_Database; + + void validate_properties (const char* type, + CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct, + CosTrading::PropertySeq& properties, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, + CosTrading::PropertyTypeMismatch, + CosTrading::ReadonlyDynamicProperty, + CosTrading::MissingMandatoryProperty, + CosTrading::DuplicatePropertyName)); + + // = Disallow these operations. + ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Register<TRADER> &)) + ACE_UNIMPLEMENTED_FUNC (TAO_Register (const TAO_Register<TRADER> &)) + + // Type is a known service type. + + CORBA::Boolean find_property (CosTrading::PropertySeq &properties, + const char *property_name, + CORBA::ULong &position); + + private: + + TRADER &trader_; +}; + + // ************************************************************* + // TAO_Admin + // ************************************************************* + +template <class TRADER> +class TAO_Admin : + public TAO_Trader_Components <POA_CosTrading::Admin>, + public TAO_Support_Attributes <POA_CosTrading::Admin>, + public TAO_Import_Attributes <POA_CosTrading::Admin>, + public TAO_Link_Attributes <POA_CosTrading::Admin> +// +// = TITLE +// This class implements CosTrading::Admin IDL interface. +// +// = DESCRIPTION (FROM SPEC) +// +// The admin interface enables the values of the trader attributes to +// be read and written. All attributes are defined as readonly in +// either SupportAttributes, ImportAttributes, LinkAttributes, or +// Admin. To set the trader "attribute" to a new value, +// set_<attribute_name> operations are defined in Admin. Each of these +// set operations returns the previous value of the attribute as its +// function value. If the admin interface operation +// set_support_proxy_offers is invoked with a value set to FALSE in a +// trader which supports the proxy interface, the +// set_support_proxy_offer value does not affect the function of +// operations in the proxy interface. However, in this case, it does +// have the effect of making any proxy offers exported via the proxy +// interface for that trader unavailable to satisfy queries on that +// trader's lookup interface. +{ +public: + + TAO_Admin (TRADER &trader); + + ~TAO_Admin (void); + + // = Importing Parameters (used by the Lookup Interface) + + virtual CORBA::ULong set_def_search_card (CORBA::ULong value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + virtual CORBA::ULong set_max_search_card (CORBA::ULong value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + // search card is the cardinality of the offers searched for + // constraint compliance. + + + virtual CORBA::ULong set_def_match_card (CORBA::ULong value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + virtual CORBA::ULong set_max_match_card (CORBA::ULong value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + // match card is the cardinality of offers found compliant with the + // constraints. + + virtual CORBA::ULong set_def_return_card (CORBA::ULong value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + virtual CORBA::ULong set_max_return_card (CORBA::ULong value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + // return card is the cardinality of the offers returned from + // Lookup. + + virtual CORBA::ULong set_max_list (CORBA::ULong value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + virtual CORBA::Boolean + set_supports_modifiable_properties (CORBA::Boolean value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + virtual CORBA::Boolean + set_supports_dynamic_properties (CORBA::Boolean value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + virtual CORBA::Boolean + set_supports_proxy_offers (CORBA::Boolean value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + // Types of offers available for consideration. Ween out those + // offers with modifiable properties + + // = Link Interface parameters + + virtual CORBA::ULong set_def_hop_count (CORBA::ULong value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + virtual CORBA::ULong set_max_hop_count (CORBA::ULong value, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + + virtual CosTrading::FollowOption + set_def_follow_policy (CosTrading::FollowOption policy, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + virtual CosTrading::FollowOption + set_max_follow_policy (CosTrading::FollowOption policy, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + virtual CosTrading::FollowOption + set_max_link_follow_policy (CosTrading::FollowOption policy, + CORBA::Environment &env) + TAO_THROW_SPEC ((CORBA::SystemException)); + + // = Set Type Repository + + virtual CosTrading::TypeRepository_ptr + set_type_repos (CosTrading::TypeRepository_ptr repository, + CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException)); + + virtual CosTrading::Admin::OctetSeq* + request_id_stem (CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException)); + + virtual CosTrading::Admin::OctetSeq* + set_request_id_stem (const CosTrading::Admin::OctetSeq& stem, + CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException)); + + virtual void list_offers (CORBA::ULong how_many, + CosTrading::OfferIdSeq_out ids, + CosTrading::OfferIdIterator_out id_itr, + CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::NotImplemented)); + + + // BEGIN SPEC + // The list_offers operation allows the administrator of a trader to + // perform housekeeping by obtaining a handle on each of the offers + // within a trader (e.g., for garbage collection etc.). Only the + // identifiers of ordinary offers are returned, identifiers of proxy + // offers are not returned via this operation. If the trader does + // not support the Register interface, the NotImplemented exception + // is raised. The returned identifiers are passed back in one of two + // ways (or a combination of both). ° The "ids" return result + // conveys a list of offer identifiers and the "id_itr" is a + // reference to an interface at which additional offer identities + // can be obtained. ° The "how_many" parameter states how many + // identifiers are to be returned via the "ids" result; any + // remaining are available via the iterator interface. If the + // "how_many" exceeds the number of offers held in the trader, then + // the "id_itr" is nil. + // END SPEC + + virtual void list_proxies (CORBA::ULong how_many, + CosTrading::OfferIdSeq_out ids, + CosTrading::OfferIdIterator_out id_itr, + CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::NotImplemented)); + +private: + + // = Disallow these operations. + ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Admin<TRADER> &)) + ACE_UNIMPLEMENTED_FUNC (TAO_Admin (const TAO_Admin<TRADER> &)) + + TRADER &trader_; + + CosTrading::Admin::OctetSeq stem_id_; + // Unique prefix to create a sequence number space. + + CORBA::ULong sequence_number_; + // Current sequence number. +}; + + // ************************************************************* + // TAO_Link + // ************************************************************* + +template <class TRADER, class MAP_TRADER> +class TAO_Link : + public TAO_Trader_Components <POA_CosTrading::Link>, + public TAO_Support_Attributes <POA_CosTrading::Link>, + public TAO_Link_Attributes <POA_CosTrading::Link> +{ +public: + + TAO_Link (TRADER &trader); + + ~TAO_Link (void); + + virtual void add_link (const char *name, + CosTrading::Lookup_ptr target, + CosTrading::FollowOption def_pass_on_follow_rule, + CosTrading::FollowOption limiting_follow_rule, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Link::IllegalLinkName, + CosTrading::Link::DuplicateLinkName, + CosTrading::InvalidLookupRef, + CosTrading::Link::DefaultFollowTooPermissive, + CosTrading::Link::LimitingFollowTooPermissive)); + // BEGIN SPEC + // The add_link operation allows a trader subsequently to use the + // service of another trader in the performance of its own trading + // service operations. + + // The "name" parameter is used in subsequent link management + // operations to identify the intended link. If the parameter is not + // legally formed, then the IllegalLinkName exception is raised. An + // exception of DuplicateLinkName is raised if the link name already + // exists. The link name is also used as a component in a sequence + // of name components in naming a trader for resolving or forwarding + // operations. The sequence of context relative link names provides + // a path to a trader. + + // The "target" parameter identifies the Lookup interface at which + // the trading service provided by the target trader can be + // accessed. Should the Lookup interface parameter be nil, then an + // exception of InvalidLookupRef is raised. The target interface is + // used to obtain the associated Register interface, which will be + // subsequently returned as part of a describe_link operation and + // invoked as part of a resolve operation. + + // The "def_pass_on_follow_rule" parameter specifies the default + // link behavior for the link if no link behavior is specified on an + // importer's query request. If the "def_pass_on_follow_rule" + // exceeds the "limiting_follow_rule" specified in the next + // parameter, then a DefaultFollowTooPermissive exception is + // raised. + + // The "limiting_follow_rule" parameter specifies the most + // permissive link follow behavior that the link is willing to + // tolerate. The exception LimitingFollowTooPermissive is raised if + // this parameter exceeds the trader's attribute of + // "max_link_follow_policy" at the time of the link's creation. Note + // it is possible for a link's "limiting_follow_rule" to exceed the + // trader's "max_link_follow_policy" later in the life of a link, as + // it is possible that the trader could set its + // "max_link_follow_policy" to a more restrictive value after the + // creation of the link. + // END SPEC + + virtual void remove_link (const char *name, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Link::IllegalLinkName, + CosTrading::Link::UnknownLinkName)); + + // BEGIN SPEC + // The remove_link operation removes all knowledge of the target + // trader. The target trader cannot be used subsequently to resolve, + // forward, or propagate trading operations from this trader. + + // The "name" parameter identifies the link to be removed. The + // exception IllegalLinkName is raised if the link is formed poorly + // and the UnknownLinkName exception is raised if the named link is + // not in the trader. + // END SPEC + + virtual CosTrading::Link::LinkInfo* describe_link (const char *name, + CORBA::Environment&) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::Link::IllegalLinkName, + CosTrading::Link::UnknownLinkName)); + + // BEGIN SPEC + // The describe_link operation returns information on a link held in + // the trader. + + // The "name" parameter identifies the link whose description is + // required. For a malformed link name, the exception + // IllegalLinkName is raised. An UnknownLinkName exception is raised + // if the named link is not found in the trader. + + // The operation returns a LinkInfo structure comprising: ° the + // Lookup interface of the target trading service, ° the Register + // interface of the target trading service, and ° the default, as + // well as the limiting follow behavior of the named link. + + // If the target service does not support the Register interface, + // then that field of the LinkInfo structure is nil. Given the + // description of the Register::resolve() operation in "Resolve + // Operation" on page 16-45, most implementations will opt for + // determining the Register interface when add_link is called and + // storing that information statically with the rest of the link + // state. + // END SPEC + + virtual CosTrading::LinkNameSeq* list_links (CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException)); + + // BEGIN SPEC + // The list_links operation returns a list of the names of all + // trading links within the trader. The names can be used + // subsequently for other management operations, such as + // describe_link or remove_link. + // END SPEC + + virtual void modify_link (const char *name, + CosTrading::FollowOption def_pass_on_follow_rule, + CosTrading::FollowOption limiting_follow_rule, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Link::IllegalLinkName, + CosTrading::Link::UnknownLinkName, + CosTrading::Link::DefaultFollowTooPermissive, + CosTrading::Link::LimitingFollowTooPermissive)); + + // BEGIN SPEC + // The modify_link operation is used to change the existing link + // follow behaviors of an identified link. The Lookup interface + // reference of the target trader and the name of the link cannot be + // changed. + + // The "name" parameter identifies the link whose follow behaviors + // are to be changed. A poorly formed "name" raises the + // IllegalLinkName exception. An UnknownLinkName exception is raised + // if the link name is not known to the trader. + + // The "def_pass_on_follow_rule" parameter specifies the new default + // link behavior for this link. If the "def_pass_on_follow_rule" + // exceeds the "limiting_follow_rule" specified in the next + // parameter, then a DefaultFollowTooPermissive exception is + // raised. + + // The "limiting_follow_rule" parameter specifies the new limit for + // the follow behavior of this link. The exception + // LimitingFollowTooPermissive is raised if the value exceeds the + // current "max_link_follow_policy" of the trader. + // END SPEC + +private: + + // = Disallow these operations. + ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Link<TRADER, MAP_TRADER> &)) + ACE_UNIMPLEMENTED_FUNC (TAO_Link (const TAO_Link<TRADER, MAP_TRADER> &)) + + + typedef ACE_Hash_Map_Manager + < + TAO_String_Hash_Key, + CosTrading::Link::LinkInfo, + MAP_TRADER + > + Links; + + Links links_; + // The collection of link connecting this trader to others in the + // federation. + + TRADER &trader_; +}; + + // ************************************************************* + // TAO_Proxy + // ************************************************************* + +template <class TRADER> +class TAO_Proxy : + public TAO_Trader_Components <POA_CosTrading::Proxy>, + public TAO_Support_Attributes <POA_CosTrading::Proxy> +{ +public: + + TAO_Proxy (TRADER &trader); + + ~TAO_Proxy (void); + + virtual CosTrading::OfferId + export_proxy (CosTrading::Lookup_ptr target, + const char *type, + const CosTrading::PropertySeq& properties, + CORBA::Boolean if_match_all, + const char * recipe, + const CosTrading::PolicySeq& policies_to_pass_on, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalServiceType, + CosTrading::UnknownServiceType, + CosTrading::InvalidLookupRef, + CosTrading::IllegalPropertyName, + CosTrading::PropertyTypeMismatch, + CosTrading::ReadonlyDynamicProperty, + CosTrading::MissingMandatoryProperty, + CosTrading::Proxy::IllegalRecipe, + CosTrading::DuplicatePropertyName, + CosTrading::DuplicatePolicyName)); + + virtual void withdraw_proxy (const char *id, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalOfferId, + CosTrading::UnknownOfferId, + CosTrading::Proxy::NotProxyOfferId)); + + virtual CosTrading::Proxy::ProxyInfo * + describe_proxy (const char *id, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::IllegalOfferId, + CosTrading::UnknownOfferId, + CosTrading::Proxy::NotProxyOfferId)); + + // = CosTrading::TraderComponents methods. + + virtual void list_proxies (CORBA::ULong how_many, + CosTrading::OfferIdSeq*& ids, + CosTrading::OfferIdIterator_ptr& id_itr, + CORBA::Environment& env) + TAO_THROW_SPEC ((CORBA::SystemException, + CosTrading::NotImplemented)); + +private: + + // = Disallow these operations. + ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Proxy<TRADER> &)) + ACE_UNIMPLEMENTED_FUNC (TAO_Proxy (const TAO_Proxy<TRADER> &)) + + + TRADER &trader_; +}; + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "Trader_Interfaces.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#endif /* TAO_TRADER_INTERFACES_H */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/Trader_T.cpp b/TAO/orbsvcs/orbsvcs/Trader/Trader_T.cpp index 545f3f2eca5..6b423b2ce57 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Trader_T.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Trader_T.cpp @@ -19,16 +19,7 @@ #define TAO_TRADER_C #include "Trader_T.h" - -#if defined(_MSC_VER) -#pragma warning (disable:4250) -#endif /* _MSC_VER */ - -#include "Lookup.h" -#include "Register.h" -#include "Link.h" -#include "Proxy.h" -#include "Admin.h" +#include "Trader_Interfaces.h" template <class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE> TAO_Trader<TRADER_LOCK_TYPE, MAP_LOCK_TYPE>:: @@ -105,10 +96,10 @@ TAO_Trader<TRADER_LOCK_TYPE, MAP_LOCK_TYPE>::~TAO_Trader (void) } template <class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE> -TAO_Trader<TRADER_LOCK_TYPE, MAP_LOCK_TYPE>::Service_Type_Map& -TAO_Trader<TRADER_LOCK_TYPE, MAP_LOCK_TYPE>::service_type_map (void) +TAO_Trader<TRADER_LOCK_TYPE, MAP_LOCK_TYPE>::Offer_Database& +TAO_Trader<TRADER_LOCK_TYPE, MAP_LOCK_TYPE>::offer_database (void) { - return this->service_type_map_; + return this->offer_database_; } template <class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE> ACE_Lock & diff --git a/TAO/orbsvcs/orbsvcs/Trader/Trader_T.h b/TAO/orbsvcs/orbsvcs/Trader/Trader_T.h index c3964a08654..a47ba9c73a0 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Trader_T.h +++ b/TAO/orbsvcs/orbsvcs/Trader/Trader_T.h @@ -19,9 +19,8 @@ #ifndef TAO_TRADER_H #define TAO_TRADER_H -// ACE includes #include "Trader.h" -#include "Service_Type_Map.h" +#include "Offer_Database.h" template <class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE> class TAO_Trader : public TAO_Trader_Base @@ -56,7 +55,7 @@ public: // The desired combination of interfaces to be passed to the // TAO_Trader constructor. - typedef TAO_Service_Type_Map<MAP_LOCK_TYPE> Service_Type_Map; + typedef TAO_Offer_Database<MAP_LOCK_TYPE> Offer_Database; TAO_Trader (Trader_Components components = LOOKUP); // Constructor which based on its arguments will create @@ -67,17 +66,17 @@ public: ~TAO_Trader (void); // destructor. - Service_Type_Map& service_type_map (void); + Offer_Database& offer_database (void); // Accessor for the structure with all the service offers. ACE_Lock &lock (void); // returns the trader -protected: - +protected: + typedef TAO_Trader<TRADER_LOCK_TYPE, MAP_LOCK_TYPE> TRADER_SELF; - Service_Type_Map service_type_map_; + Offer_Database offer_database_; // A monitor (i.e. an STL map + a lock) serving as a storage for // all the service offers of a trader. // Structure: a map (actually a monitor) of service type names to @@ -90,6 +89,13 @@ protected: enum { LOOKUP_IF, REGISTER_IF, ADMIN_IF, PROXY_IF, LINK_IF }; PortableServer::ServantBase* ifs_[5]; + + private: + + // = Disallow these operations. + ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Trader<LOCK_TYPE> &)) + ACE_UNIMPLEMENTED_FUNC (TAO_Trader (const TAO_Trader<LOCK_TYPE> &)) + }; template <class SEQ, class OPERAND_TYPE> diff --git a/TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.cpp b/TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.cpp new file mode 100644 index 00000000000..40a085d42f9 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.cpp @@ -0,0 +1,1247 @@ +// File: Trader_Utils.cpp +// $Id$ + +#include "Trader_Utils.h" + + // ************************************************************* + // TAO_Policy_Manager + // ************************************************************* + +TAO_Policy_Manager::TAO_Policy_Manager (int num_policies) + : policies_ (num_policies), + num_policies_ (0) +{ + for (int i = 0; i < TAO_Policies::REQUEST_ID + 1; i++) + this->poltable_[i] = -1; +} + +void +TAO_Policy_Manager::search_card (CORBA::ULong scard) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::SEARCH_CARD); + policy.value <<= scard; +} + +void +TAO_Policy_Manager::match_card (CORBA::ULong mcard) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::MATCH_CARD); + policy.value <<= mcard; +} + +void +TAO_Policy_Manager::return_card (CORBA::ULong rcard) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::RETURN_CARD); + policy.value <<= rcard; +} + +void +TAO_Policy_Manager::use_modifiable_properties (CORBA::Boolean mod_props) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::USE_MODIFIABLE_PROPERTIES); + policy.value <<= CORBA::Any::from_boolean (mod_props); +} + +void +TAO_Policy_Manager::use_dynamic_properties (CORBA::Boolean dyn_props) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::USE_DYNAMIC_PROPERTIES); + policy.value <<= CORBA::Any::from_boolean (dyn_props); +} + +void +TAO_Policy_Manager::use_proxy_offers (CORBA::Boolean prox_offs) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::USE_PROXY_OFFERS); + policy.value <<= CORBA::Any::from_boolean (prox_offs); +} + +void +TAO_Policy_Manager::starting_trader (CosTrading::TraderName* name) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::STARTING_TRADER); + policy.value <<= *name; +} + +void +TAO_Policy_Manager:: +link_follow_rule (CosTrading::FollowOption follow_option) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::LINK_FOLLOW_RULE); + policy.value <<= follow_option; +} + +void +TAO_Policy_Manager::hop_count (CORBA::ULong hop_count) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::HOP_COUNT); + policy.value <<= hop_count; +} + +void +TAO_Policy_Manager::exact_type_match (CORBA::Boolean exact_type) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::EXACT_TYPE_MATCH); + policy.value <<= CORBA::Any::from_boolean (exact_type); +} + +void +TAO_Policy_Manager::request_id (CosTrading::Admin::OctetSeq* request_id) +{ + CosTrading::Policy& policy = + this->fetch_next_policy (TAO_Policies::REQUEST_ID); + policy.value <<= *request_id; +} + +TAO_Policy_Manager::operator const CosTrading::PolicySeq& (void) const +{ + return this->policies_; +} + +const CosTrading::PolicySeq& +TAO_Policy_Manager::policy_seq (void) const +{ + return this->policies_; +} + +CosTrading::Policy& +TAO_Policy_Manager::fetch_next_policy (TAO_Policies::POLICY_TYPE pol_type) +{ + CORBA::ULong index = 0; + + if (this->poltable_[pol_type] == -1) + { + CORBA::ULong length = this->policies_.length (); + this->num_policies_++; + + if (length < this->num_policies_) + this->policies_.length (this->num_policies_); + + index = this->num_policies_ - 1; + this->policies_[index].name = TAO_Policies::POLICY_NAMES[pol_type]; + this->poltable_[pol_type] = index; + } + else + index = this->poltable_[pol_type]; + + return this->policies_[index]; +} + + + // ************************************************************* + // TAO_Property_Evaluator + // ************************************************************* + +// Constructor + +TAO_Property_Evaluator:: +TAO_Property_Evaluator(const CosTrading::PropertySeq& props, + CORBA::Boolean supports_dp) + : props_ (props), + supports_dp_ (supports_dp) +{ +} + + +TAO_Property_Evaluator:: +TAO_Property_Evaluator(CosTrading::Offer& offer, + CORBA::Boolean supports_dp) + : props_ (offer.properties), + supports_dp_ (supports_dp) +{ +} + +int +TAO_Property_Evaluator::is_dynamic_property (int index) +{ + CORBA::Environment env; + int return_value = 0, + num_properties = this->props_.length(); + + // Ensure index is in bounds. + if (index >= 0 && index < num_properties) + { + // Obtain the value of the property at index <index>. + const CORBA::Any& value = this->props_[index].value; + CORBA::TypeCode* type = value.type (); + + if (type->equal (CosTradingDynamic::_tc_DynamicProp, env)) + return_value = 1; + } + + return return_value; +} + + +CORBA::Any* +TAO_Property_Evaluator::property_value(int index, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTradingDynamic::DPEvalFailure)) +{ + CORBA::Any* prop_val = 0; + + if (! this->is_dynamic_property(index)) + prop_val = (CORBA::Any *) &(this->props_[index].value); + else if (this->supports_dp_) + { + // Property is defined at this point. + DP_Eval* dp_eval; + CosTradingDynamic::DynamicProp* dp_struct; + const CORBA::String_var name = this->props_[index].name; + const CORBA::Any& value = this->props_[index].value; + + // Extract the DP_Struct. + value >>= dp_struct; + +#if defined TAO_HAS_DYNAMIC_PROPERTY_BUG + CORBA::ORB_ptr orb = TAO_ORB_Core_instance ()->orb (); + CORBA::Object_ptr obj = orb->string_to_object (dp_struct->eval_if, _env); + TAO_CHECK_ENV_RETURN (_env, 0); + dp_eval = CosTradingDynamic::DynamicPropEval::_narrow (obj, _env); + TAO_CHECK_ENV_RETURN (_env, 0); +#else + dp_eval = dp_struct->eval_if; +#endif /* TAO_HAS_DYNAMIC_PROPERTY_BUG */ + + if (CORBA::is_nil (dp_eval)) + TAO_THROW_RETURN (CosTradingDynamic::DPEvalFailure (), prop_val); + else + { + CORBA::TypeCode* type = dp_struct->returned_type; + CORBA::Any& info = dp_struct->extra_info; + + TAO_TRY + { + // Retrieve the value of the dynamic property. + prop_val = dp_eval->evalDP(name, type, info, TAO_TRY_ENV); + TAO_CHECK_ENV; + } + TAO_CATCH (CORBA::SystemException, excp) + { + TAO_THROW_RETURN + (CosTradingDynamic::DPEvalFailure (name, type, info), + prop_val); + } + TAO_ENDTRY; + } + } + + return prop_val; +} + +CORBA::TypeCode* +TAO_Property_Evaluator::property_type(int index) +{ + CORBA::TypeCode* prop_type = CORBA::TypeCode::_nil(); + + // Determine if property is both defined and dynamic. + if (this->is_dynamic_property (index)) + { + // Extract type information from the DP_Struct. + const CORBA::Any& value = this->props_[index].value; + CosTradingDynamic::DynamicProp* dp_struct; + value >>= dp_struct; + + // Grab a pointer to the returned_type description + prop_type = CORBA::TypeCode::_duplicate(dp_struct->returned_type); + } + else + // TypeCode is self-evident at this point. + prop_type = this->props_[index].value.type(); + + return prop_type; +} + + // ************************************************************* + // TAO_Property_Evaluator_By_Name + // ************************************************************* + +TAO_Property_Evaluator_By_Name:: +TAO_Property_Evaluator_By_Name (const CosTrading::PropertySeq& properties, + CORBA::Environment& _env, + CORBA::Boolean supports_dp) + TAO_THROW_SPEC ((CosTrading::DuplicatePropertyName, + CosTrading::IllegalPropertyName)) + : TAO_Property_Evaluator (properties, supports_dp) +{ + int length = this->props_.length(); + + for (int i = 0; i < length; i++) + { + const CosTrading::Property& prop = this->props_[i]; + + if (! TAO_Trader_Base::is_valid_identifier_name (prop.name)) + TAO_THROW (CosTrading::IllegalPropertyName (prop.name)); + + TAO_String_Hash_Key prop_name = prop.name; + if (this->table_.bind (prop_name, i)) + TAO_THROW (CosTrading::DuplicatePropertyName (prop.name)); + } +} + +TAO_Property_Evaluator_By_Name:: +TAO_Property_Evaluator_By_Name(CosTrading::Offer& offer, + CORBA::Boolean supports_dp) + : TAO_Property_Evaluator(offer, supports_dp) +{ + int length = this->props_.length(); + + for (int i = 0; i < length; i++) + { + TAO_String_Hash_Key prop_name = (const char*) this->props_[i].name; + this->table_.bind (prop_name, i); + } +} + +int +TAO_Property_Evaluator_By_Name:: +is_dynamic_property(const char* property_name) +{ + int predicate = 0, index = 0; + TAO_String_Hash_Key prop_name (property_name); + + // If the property name is in the map, delegate evaluation to our + // superclass. Otherwise, throw an exception. + if (this->table_.find (prop_name, index) == 0) + predicate = this->TAO_Property_Evaluator::is_dynamic_property(index); + + return predicate; +} + +CORBA::Any* +TAO_Property_Evaluator_By_Name::property_value (const char* property_name, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTradingDynamic::DPEvalFailure)) +{ + int index = 0; + CORBA::Any* prop_value = 0; + TAO_String_Hash_Key prop_name (property_name); + + // If the property name is in the map, delegate evaluation to our + // superclass. Otherwise, throw an exception. + if (this->table_.find (prop_name, index) == 0) + prop_value = this->TAO_Property_Evaluator::property_value (index, _env); + + return prop_value; +} + +CORBA::TypeCode* +TAO_Property_Evaluator_By_Name::property_type (const char* property_name) +{ + int index = 0; + TAO_String_Hash_Key prop_name (property_name); + CORBA::TypeCode* prop_type = CORBA::TypeCode::_nil(); + + // If the property name is in the map, delegate evaluation to our + // superclass. Otherwise, throw an exception. + if (this->table_.find (prop_name, index) == 0) + prop_type = this->TAO_Property_Evaluator::property_type (index); + + return prop_type; +} + +const CosTrading::Property* +TAO_Property_Evaluator_By_Name::get_property (const char* property_name) +{ + int index = 0; + CosTrading::Property* property = 0; + TAO_String_Hash_Key prop_name (property_name); + + if (this->table_.find (prop_name, index) == 0) + property = (CosTrading::Property *) &this->props_[index]; + + return property; +} + + // ************************************************************* + // TAO_Policies + // ************************************************************* + +const char* TAO_Policies::POLICY_NAMES[] = +{ + "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" +}; + +TAO_Policies::TAO_Policies (TAO_Trader_Base& trader, + const CosTrading::PolicySeq& policies, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPolicyName, + CosTrading::DuplicatePolicyName)) + : trader_ (trader) +{ + for (int i = 0; i < TAO_NUM_POLICIES; i++) + this->policies_[i] = 0; + + for (CORBA::ULong j = 0; j < policies.length (); j++) + { + const char* pol_name = (const char*) policies[j].name; + size_t length = (pol_name == 0) ? 0 : ACE_OS::strlen (pol_name), + index = -1; + + if (length < ACE_OS::strlen (POLICY_NAMES[HOP_COUNT])) + TAO_THROW (CosTrading::Lookup::IllegalPolicyName (pol_name)); + + switch (pol_name[0]) + { + case 'e': + index = EXACT_TYPE_MATCH; + break; + case 'h': + index = HOP_COUNT; + break; + case 'l': + index = LINK_FOLLOW_RULE; + break; + case 'm': + index = MATCH_CARD; + break; + case 'r': + if (pol_name[2] == 't') + index = RETURN_CARD; + else if (pol_name[2] == 'q') + index = REQUEST_ID; + break; + case 's': + if (pol_name[1] == 't') + index == STARTING_TRADER; + else if (pol_name[1] == 'e') + index = SEARCH_CARD; + break; + case 'u': + if (pol_name[4] == 'd') + index = USE_DYNAMIC_PROPERTIES; + if (pol_name[4] == 'm') + index = USE_MODIFIABLE_PROPERTIES; + if (pol_name[4] == 'p') + index = USE_PROXY_OFFERS; + } + + // Match the name of the policy, and insert its value into the + // vector. + if (index == -1 || ::strcmp (POLICY_NAMES[index], pol_name) != 0) + TAO_THROW (CosTrading::Lookup::IllegalPolicyName (pol_name)); + else + { + if (this->policies_[index] != 0) + TAO_THROW (CosTrading::DuplicatePolicyName (pol_name)); + else + this->policies_[index] = (CosTrading::Policy *) &(policies[j]); + } + } +} + +TAO_Policies::~TAO_Policies (void) +{ +} + +CORBA::ULong +TAO_Policies::ulong_prop (POLICY_TYPE pol, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + CORBA::ULong return_value = 0, max_value; + TAO_Import_Attributes_Impl& import_attrs = + this->trader_.import_attributes (); + + // Discover the default values for each of the possible cardinality + // policies. + switch (pol) + { + case SEARCH_CARD: + return_value = import_attrs.def_search_card (); + max_value = import_attrs.max_search_card (); + break; + case MATCH_CARD: + return_value = import_attrs.def_match_card (); + max_value = import_attrs.max_match_card (); + break; + case RETURN_CARD: + return_value = import_attrs.def_return_card (); + max_value = import_attrs.max_return_card (); + break; + case HOP_COUNT: + return_value = import_attrs.def_hop_count (); + max_value = import_attrs.max_hop_count (); + break; + } + + if (this->policies_[pol] != 0) + { + // Extract the desired policy value. + CosTrading::Policy* policy = this->policies_[pol]; + CosTrading::PolicyValue& value = policy->value; + CORBA::TypeCode* type = value.type (); + + if (!type->equal (CORBA::_tc_ulong, _env)) + TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), + return_value); + else + value >>= return_value; + + if (max_value < return_value) + return_value = max_value; + } + + return return_value; +} + +CORBA::ULong +TAO_Policies::search_card (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + return this->ulong_prop (SEARCH_CARD, _env); +} + +CORBA::ULong +TAO_Policies::match_card (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + return this->ulong_prop (MATCH_CARD, _env); +} + +CORBA::ULong +TAO_Policies::return_card (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + return this->ulong_prop (RETURN_CARD, _env); +} + +CORBA::Boolean +TAO_Policies::boolean_prop (POLICY_TYPE pol, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + CORBA::Boolean def_value = CORBA::B_TRUE, + return_value = CORBA::B_TRUE; + TAO_Support_Attributes_Impl& support_attrs = + this->trader_.support_attributes (); + + switch (pol) + { + case USE_MODIFIABLE_PROPERTIES: + def_value = support_attrs.supports_modifiable_properties (); + break; + case USE_DYNAMIC_PROPERTIES: + def_value = support_attrs.supports_dynamic_properties (); + break; + case USE_PROXY_OFFERS: + def_value = support_attrs.supports_proxy_offers (); + break; + case EXACT_TYPE_MATCH: + def_value = CORBA::B_FALSE; + break; + } + + if (this->policies_[pol] != 0) + { + CosTrading::Policy* policy = this->policies_[pol]; + CosTrading::PolicyValue& value = policy->value; + CORBA::TypeCode* type = value.type (); + + if (!type->equal (CORBA::_tc_boolean, _env)) + TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), + return_value); + else + value >>= CORBA::Any::to_boolean (return_value); + + if (def_value == CORBA::B_FALSE && + pol != EXACT_TYPE_MATCH) + return_value = CORBA::B_FALSE; + } + else + return_value = def_value; + + return return_value; +} + + +CORBA::Boolean +TAO_Policies::use_modifiable_properties (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + return this->boolean_prop (USE_MODIFIABLE_PROPERTIES, _env); +} + +CORBA::Boolean +TAO_Policies::use_dynamic_properties (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + return this->boolean_prop (USE_DYNAMIC_PROPERTIES, _env); +} + +CORBA::Boolean +TAO_Policies::use_proxy_offers (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + return this->boolean_prop (USE_PROXY_OFFERS, _env); +} + +CORBA::Boolean +TAO_Policies::exact_type_match (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + return this->boolean_prop (EXACT_TYPE_MATCH, _env); +} + + +CosTrading::TraderName* +TAO_Policies::starting_trader (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch, + CosTrading::Lookup::InvalidPolicyValue)) +{ + CosTrading::TraderName* trader_name = 0; + + if (this->policies_[STARTING_TRADER] != 0) + { + CosTrading::Policy* policy = this->policies_[STARTING_TRADER]; + CosTrading::PolicyValue& value = policy->value; + CORBA::TypeCode* type = value.type (); + + if (!type->equal (CosTrading::_tc_TraderName, _env)) + TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), + trader_name); + else + { + // ACE_NEW_RETURN (trader_name, CosTrading::TraderName, 0); + value >>= trader_name; + } + } + + return trader_name; +} + +CosTrading::FollowOption +TAO_Policies::link_follow_rule (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + CosTrading::FollowOption return_value = + this->trader_.import_attributes ().def_follow_policy (); + + if (this->policies_[LINK_FOLLOW_RULE] != 0) + { + CosTrading::FollowOption max_follow_policy = + this->trader_.import_attributes ().max_follow_policy (); + + CosTrading::Policy* policy = this->policies_[LINK_FOLLOW_RULE]; + CosTrading::PolicyValue& value = policy->value; + CORBA::TypeCode* type = value.type (); + + // Extract the link follow rule + if (!type->equal (CosTrading::_tc_FollowOption, _env)) + TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), + return_value); + else + value >>= return_value; + + if (return_value > max_follow_policy) + return_value = max_follow_policy; + } + + return return_value; +} + +CosTrading::FollowOption +TAO_Policies::link_follow_rule (const char* link_name, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch, + CosTrading::Lookup::InvalidPolicyValue, + CosTrading::Link::IllegalLinkName, + CosTrading::Link::UnknownLinkName)) +{ + CosTrading::FollowOption return_value = CosTrading::local_only; + CosTrading::Link_var link + (this->trader_.trading_components ().link_if ()); + + if (link.in() != CosTrading::Link::_nil ()) + { + CosTrading::Link::LinkInfo_var + link_info (link->describe_link (link_name, _env)); + TAO_CHECK_ENV_RETURN (_env, return_value); + CosTrading::FollowOption trader_max_follow_policy = + this->trader_.import_attributes ().max_follow_policy (); + + if (this->policies_[LINK_FOLLOW_RULE] != 0) + { + CosTrading::FollowOption query_link_follow_rule; + CosTrading::FollowOption link_limiting_follow_rule = + link_info->limiting_follow_rule; + CosTrading::Policy* policy = this->policies_[LINK_FOLLOW_RULE]; + CosTrading::PolicyValue& value = policy->value; + CORBA::TypeCode* type = value.type (); + + // Extract the link follow rule + if (!type->equal (CosTrading::_tc_FollowOption, _env)) + TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), + return_value); + else + value >>= query_link_follow_rule; + + return_value = (query_link_follow_rule < trader_max_follow_policy) + ? query_link_follow_rule : trader_max_follow_policy; + return_value = (return_value < link_limiting_follow_rule) + ? return_value : link_limiting_follow_rule; + } + else + { + CosTrading::FollowOption link_def_follow_rule = + this->trader_.import_attributes ().max_follow_policy (); + + return_value = (link_def_follow_rule < trader_max_follow_policy) + ? link_def_follow_rule : trader_max_follow_policy; + } + } + + return return_value; +} + +CORBA::ULong +TAO_Policies::hop_count (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + return this->ulong_prop (HOP_COUNT, _env); +} + +CosTrading::Admin::OctetSeq* +TAO_Policies::request_id (CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)) +{ + CosTrading::Admin::OctetSeq* request_id = 0; + + if (this->policies_[REQUEST_ID] != 0) + { + CosTrading::Policy* policy = this->policies_[REQUEST_ID]; + CosTrading::PolicyValue& value = policy->value; + CORBA::TypeCode* type = value.type (); + + if (!type->equal (CosTrading::Admin::_tc_OctetSeq, _env)) + TAO_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy), + request_id); + else + { + //ACE_NEW_RETURN (request_id, CosTrading::Admin::OctetSeq, 0); + value >>= request_id; + } + } + + return request_id; +} + +CosTrading::PolicySeq* +TAO_Policies::policies_to_forward (void) +{ + // Create a new policy sequence, shortening the starting trader + // policy by one link. + + CORBA::ULong counter = 0; + CosTrading::Policy* policy_buffer = + CosTrading::PolicySeq::allocbuf (REQUEST_ID + 1); + + if (policy_buffer == 0) + return 0; + + for (int i = EXACT_TYPE_MATCH; i <= REQUEST_ID; i++) + { + CosTrading::Policy& new_policy = policy_buffer[counter]; + + if (this->policies_[i] != 0) + { + // Copy in the existing policies. + new_policy.name = this->policies_[i]->name; + + if (i == STARTING_TRADER) + { + TAO_TRY + { + // Eliminate the first link of the trader name. + CosTrading::TraderName* trader_name = + this->starting_trader (TAO_TRY_ENV); + TAO_CHECK_ENV; + + CORBA::ULong length = trader_name->length (); + + for (CORBA::ULong j = 1; j < length; j++) + trader_name[j - 1] = trader_name[j]; + trader_name->length (length - 1); + + new_policy.value <<= *trader_name; + counter++; + } + TAO_CATCHANY {} + TAO_ENDTRY; + } + else + { + new_policy.value = this->policies_[i]->value; + counter++; + } + } + } + + // Create the new sequence + return new CosTrading::PolicySeq (REQUEST_ID + 1, counter, + policy_buffer, CORBA::B_TRUE); +} + +CosTrading::PolicySeq* +TAO_Policies:: +policies_to_pass (CosTrading::FollowOption def_pass_on_follow_rule, + CORBA::ULong offers_returned, + CosTrading::Admin_ptr admin_if) +{ + // Create a new policy sequence to pass to a federated + // query. Decrement the hop count, add a stem id if none exists, and + // add a follow rule if none exists. Also adjust the return_card to + // account for previous queries. + CORBA::Environment env; + CORBA::ULong counter = 0; + CosTrading::Policy* policy_buffer = + CosTrading::PolicySeq::allocbuf (REQUEST_ID + 1); + + if (policy_buffer == 0) + return 0; + + for (int i = EXACT_TYPE_MATCH; i <= REQUEST_ID; i++) + { + CosTrading::Policy& new_policy = policy_buffer[counter]; + + if (this->policies_[i] != 0) + { + // Add an existing query. + new_policy.name = this->policies_[i]->name; + new_policy.value = this->policies_[i]->value; + } + else + { + if (i == LINK_FOLLOW_RULE) + { + // Add a link follow rule if one didn't exist. + new_policy.name = POLICY_NAMES[i]; + new_policy.value <<= def_pass_on_follow_rule; + } + else if (i == REQUEST_ID) + { + // Add the request id if one didn't exist. + new_policy.name = POLICY_NAMES[i]; + new_policy.value <<= *(admin_if->request_id_stem (env)); + } + } + + if (i == HOP_COUNT) + { + // Decrement the hop count. + new_policy.name = POLICY_NAMES[i]; + new_policy.value <<= this->hop_count (env) - 1; + } + else if (i == RETURN_CARD) + { + // Adjust the return card. + new_policy.name = POLICY_NAMES[i]; + new_policy.value <<= this->return_card (env) - offers_returned; + } + } + + // Create the new sequence. + return new CosTrading::PolicySeq (REQUEST_ID + 1, counter, + policy_buffer, CORBA::B_TRUE); +} + + + // ************************************************************* + // TAO_Offer_Modifier + // ************************************************************* + +TAO_Offer_Modifier:: +TAO_Offer_Modifier (const char* type_name, + CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct, + CosTrading::Offer& offer) + : offer_ (offer), + type_ (type_name) +{ + CosTrading::PropertySeq& prop_seq = this->offer_.properties; + CosTradingRepos::ServiceTypeRepository::PropStructSeq& + pstructs = type_struct->props; + int pstructs_length = pstructs.length (), + props_length = prop_seq.length (); + + // Separate the type defined properties into mandatory and readonly + for (int i = 0; i < pstructs_length; i++) + { + if (pstructs[i].mode == + CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY) + { + TAO_String_Hash_Key prop_name ((const char *) pstructs[i].name); + this->mandatory_.insert (prop_name); + } + else if (pstructs[i].mode == + CosTradingRepos::ServiceTypeRepository::PROP_READONLY) + { + TAO_String_Hash_Key prop_name ((const char *) pstructs[i].name); + this->readonly_.insert (prop_name); + } + } + + // Insert the properties of the offer into a map. + for (i = 0; i < props_length; i++) + { + TAO_String_Hash_Key prop_name = (const char*) prop_seq[i].name; + this->props_.bind (prop_name, &prop_seq[i]); + } +} + +void +TAO_Offer_Modifier:: +delete_properties (const CosTrading::PropertyNameSeq& deletes, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::Register::UnknownPropertyName, + CosTrading::Register::MandatoryProperty, + CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName)) +{ + Prop_Names delete_me; + // Validate that the listed property names can be deleted + for (int i = 0, length = deletes.length (); i < length; i++) + { + const char* dname = (const char *) deletes[i]; + if (! TAO_Trader_Base::is_valid_identifier_name (dname)) + TAO_THROW (CosTrading::IllegalPropertyName (dname)); + else + { + TAO_String_Hash_Key prop_name (dname); + if (this->mandatory_.find (prop_name) == 0) + TAO_THROW (CosTrading::Register::MandatoryProperty (this->type_, dname)); + else if (delete_me.insert (prop_name) == 1) + TAO_THROW (CosTrading::DuplicatePropertyName (dname)); + else if (this->props_.find (prop_name) == 0) + TAO_THROW (CosTrading::Register::UnknownPropertyName (dname)); + } + } + + // Delete those properties from the offer. + for (i = 0; i < length; i++) + { + TAO_String_Hash_Key prop_name = (const char *) deletes[i]; + this->props_.unbind (prop_name); + } +} + +void +TAO_Offer_Modifier:: +merge_properties (const CosTrading::PropertySeq& modifies, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName, + CosTrading::Register::ReadonlyProperty)) +{ + Prop_Names modify_me; + // Ensure that the proposed changes aren't to readonly properties or + // otherwise invalid. + for (int i = 0, length = modifies.length (); i < length; i++) + { + const char* mname =(const char *) modifies[i].name; + if (! TAO_Trader_Base::is_valid_identifier_name (mname)) + TAO_THROW (CosTrading::IllegalPropertyName (mname)); + else + { + TAO_String_Hash_Key prop_name (mname); + if (this->readonly_.find (prop_name) == 0 && + this->props_.find (prop_name) == 0) + TAO_THROW (CosTrading::Register::ReadonlyProperty (this->type_, mname)); + else if (modify_me.insert (prop_name) == 1) + TAO_THROW (CosTrading::DuplicatePropertyName (mname)); + } + } + + for (i = 0; i < length; i++) + { + // Add a property to the destination if it doesn't already exist. + Props::ENTRY* existing_entry = 0; + TAO_String_Hash_Key prop_name ((const char*) modifies[i].name); + + if (this->props_.bind (prop_name, + (CosTrading::Property *) &modifies[i], + existing_entry) == 1) + { + // Modify a property if it already exists in the destination. + CosTrading::Property* prop = existing_entry->int_id_; + prop->value = modifies[i].value; + } + } +} + +CosTrading::Offer& +TAO_Offer_Modifier::affect_change (void) +{ + int elem = 0; + CosTrading::PropertySeq prop_seq; + + // Create a new property list reflecting the deletes, modifies, and + // add operations performed, and place this property list in the + // offer. + prop_seq.length (this->props_.current_size ()); + for (Props::iterator props_iter (this->props_); + ! props_iter.done (); + props_iter++, elem++) + { + prop_seq[elem] = *(*props_iter).int_id_; + } + + this->offer_.properties = prop_seq; + return this->offer_; +} + + // ************************************************************* + // TAO_Offer_Filter + // ************************************************************* + +TAO_Offer_Filter:: +TAO_Offer_Filter (SERVICE_TYPE_REPOS::TypeStruct* type_struct, + TAO_Policies& policies, + CORBA::Environment& _env) + : search_card_ (policies.search_card (_env)), + match_card_ (policies.match_card (_env)), + return_card_ (policies.return_card (_env)), + dp_ (policies.use_dynamic_properties (_env)), + mod_ (policies.use_modifiable_properties (_env)) +{ + SERVICE_TYPE_REPOS::PropStructSeq& prop_seq = type_struct->props; + + // Take note of modifiable properties in the type_struct + for (int i = prop_seq.length () - 1; i >= 0; i--) + { + SERVICE_TYPE_REPOS::PropertyMode mode = prop_seq[i].mode; + if (mode != SERVICE_TYPE_REPOS::PROP_MANDATORY_READONLY || + mode != SERVICE_TYPE_REPOS::PROP_READONLY) + { + TAO_String_Hash_Key prop_name ((const char*) prop_seq[i].name); + this->mod_props_.insert (prop_name); + } + } + + if (policies.exact_type_match (_env) == CORBA::B_TRUE) + { + TAO_String_Hash_Key exact_match + (TAO_Policies::POLICY_NAMES[TAO_Policies::EXACT_TYPE_MATCH]); + this->limits_.insert (exact_match); + } + +} + +CORBA::Boolean +TAO_Offer_Filter::ok_to_consider (CosTrading::Offer* offer) +{ + TAO_String_Hash_Key use_mods = + TAO_Policies::POLICY_NAMES[TAO_Policies::USE_MODIFIABLE_PROPERTIES]; + TAO_String_Hash_Key use_dyns = + TAO_Policies::POLICY_NAMES[TAO_Policies::USE_DYNAMIC_PROPERTIES]; + CORBA::Boolean return_value = CORBA::B_TRUE; + TAO_Property_Evaluator prop_eval (*offer); + + // If we should screen offers, determine if this offer is unworthy + // for consideration. + if (! (this->mod_ && this->dp_)) + { + for (int i = offer->properties.length () - 1; + i >= 0 && return_value; + i--) + { + // Winnow away the unwanted offers with modifiable or + // dynamic properties. + if (! this->mod_) + { + // Determine if this property name is found in the set + // of modifiable properties for the type being considered. + TAO_String_Hash_Key prop_name ((const char*) offer->properties[i].name); + if (this->mod_props_.find (prop_name) == 0) + { + this->limits_.insert (use_mods); + return_value = 0; + } + } + + if (! this->dp_ && return_value) + { + // Determine if this property is dynamic. + if (prop_eval.is_dynamic_property (i)) + { + this->limits_.insert (use_dyns); + return_value = 0; + } + } + + if (return_value == 0) + break; + } + } + + // If we're good to go, consider this offer considered and decrement + // the search cardinality counter. + if (return_value) + { + this->search_card_--; + if (this->search_card_ == 0) + { + TAO_String_Hash_Key search_card = + TAO_Policies::POLICY_NAMES[TAO_Policies::SEARCH_CARD]; + this->limits_.insert (search_card); + } + } + + return return_value; +} + +CORBA::Boolean +TAO_Offer_Filter::ok_to_consider_more (void) +{ + return this->search_card_ > 0 && this->match_card_ > 0; +} + +void +TAO_Offer_Filter::matched_offer (void) +{ + this->match_card_--; + this->return_card_--; + + if (this->match_card_ == 0) + { + TAO_String_Hash_Key match_card = + TAO_Policies::POLICY_NAMES[TAO_Policies::MATCH_CARD]; + this->limits_.insert (match_card); + } + + if (this->return_card_ == 0) + { + TAO_String_Hash_Key return_card = + TAO_Policies::POLICY_NAMES[TAO_Policies::MATCH_CARD]; + this->limits_.insert (return_card); + } +} + +CosTrading::PolicyNameSeq* +TAO_Offer_Filter::limits_applied (void) +{ + int i = 0; + CORBA::ULong size = this->limits_.size (); + CosTrading::PolicyName* temp = + CosTrading::PolicyNameSeq::allocbuf (size); + + for (Names::iterator p_iter (this->limits_.begin()); + ! p_iter.done (); + p_iter.advance ()) + { + TAO_String_Hash_Key* policy_name_ptr = 0; + p_iter.next (policy_name_ptr); + temp[i++] = CORBA::string_dup ((const char*) *policy_name_ptr); + } + + return new CosTrading::PolicyNameSeq (i, i, temp, 1); +} + + // ************************************************************* + // TAO_Property_Filter + // ************************************************************* + +TAO_Property_Filter:: +TAO_Property_Filter (const SPECIFIED_PROPS& desired_props, + CORBA::Environment& _env) + TAO_THROW_SPEC ((CosTrading::IllegalPropertyName, + CosTrading::DuplicatePropertyName)) + : policy_ (desired_props._d ()) +{ + if (this->policy_ == CosTrading::Lookup::some) + { + ACE_DEBUG ((LM_DEBUG, "Filter: policy == some\n")); + const CosTrading::PropertyNameSeq& + prop_seq = desired_props.prop_names (); + int length = prop_seq.length (); + + for (int i = 0; i < length; i++) + { + const char* pname = prop_seq[i]; + + // Check for errors or duplicates + if (TAO_Trader_Base::is_valid_identifier_name (pname)) + { + // Insert returns a pair whose second element is a flag + // indicating whether a collision occured. + TAO_String_Hash_Key prop_name (pname); + if (this->props_.insert (prop_name) == 1) + { + ACE_DEBUG ((LM_DEBUG, "Filter: Inserted %s\n", pname)); + TAO_THROW (CosTrading::DuplicatePropertyName (pname)); + } + } + else + TAO_THROW (CosTrading::IllegalPropertyName (pname)); + } + } +} + +TAO_Property_Filter:: +TAO_Property_Filter (const TAO_Property_Filter& prop_filter) + : props_ (prop_filter.props_), + policy_ (prop_filter.policy_) +{ +} + +void +TAO_Property_Filter::filter_offer (CosTrading::Offer& source, + CosTrading::Offer& destination) +{ + Prop_Queue prop_queue; + CosTrading::PropertySeq& s_props = source.properties; + CosTrading::PropertySeq& d_props = destination.properties; + int length = s_props.length (), elem = 0; + + destination.reference = source.reference->_duplicate (source.reference); + if (this->policy_ != CosTrading::Lookup::none) + { + for (int i = 0; i < length; i++) + { + if (this->policy_ == CosTrading::Lookup::all) + prop_queue.enqueue_tail (&s_props[i]); + else + { + TAO_String_Hash_Key prop_name ((const char*) s_props[i].name); + + // Save those property that match. + if (this->props_.find (prop_name) == 0) + prop_queue.enqueue_tail (&s_props[i]); + } + } + + // Shove the matched properties into the destination property + // sequence. + length = prop_queue.size (); + d_props.length (prop_queue.size ()); + for (Prop_Queue::ITERATOR prop_iter (prop_queue); + ! prop_iter.done (); + prop_iter.advance (), elem++) + { + CosTrading::Property** prop_ptr = 0; + + prop_iter.next (prop_ptr); + d_props[elem] = **prop_ptr; + } + } +} diff --git a/TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.h b/TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.h new file mode 100644 index 00000000000..d07f746050b --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Trader/Trader_Utils.h @@ -0,0 +1,658 @@ +/* -*- 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 */ diff --git a/TAO/orbsvcs/orbsvcs/Trader/constraint.l b/TAO/orbsvcs/orbsvcs/Trader/constraint.l index 76ab1b2cb6c..ccb3c2f4bce 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/constraint.l +++ b/TAO/orbsvcs/orbsvcs/Trader/constraint.l @@ -13,7 +13,8 @@ // // ======================================================================== -#include "Constraint.h" +#include "ace/OS.h" +#include "Constraint_Interpreter.h" #include "Constraint_Nodes.h" #include "Constraint_Tokens.h" diff --git a/TAO/orbsvcs/orbsvcs/Trader/constraint.y b/TAO/orbsvcs/orbsvcs/Trader/constraint.y index b6ead834a7e..1e5ab5c81cf 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/constraint.y +++ b/TAO/orbsvcs/orbsvcs/Trader/constraint.y @@ -13,7 +13,8 @@ // // ======================================================================== -#include "Constraint.h" +#include "ace/OS.h" +#include "Constraint_Interpreter.h" #include "Constraint_Nodes.h" //#define YYDEBUG 1 |