Trader.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  * @file Trader.h
00006  *
00007  * Trader.h,v 1.62 2006/04/25 11:35:29 jwillemsen Exp
00008  *
00009  * @author Marina Spivak <marina@cs.wustl.edu>
00010  * @author Seth Widoff <sbw1@cs.wustl.edu>
00011  * @author Irfan Pyarali <irfan@cs.wustl.edu>
00012  */
00013 //=============================================================================
00014 
00015 
00016 #ifndef TAO_TRADER_BASE_H
00017 #define TAO_TRADER_BASE_H
00018 #include /**/ "ace/pre.h"
00019 
00020 #include "orbsvcs/Trader/Interpreter_Utils.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 #include "ace/Containers.h"
00027 
00028 #include "orbsvcs/CosTradingS.h"
00029 #include "orbsvcs/CosTradingReposS.h"
00030 #include "orbsvcs/CosTradingDynamicS.h"
00031 #include "orbsvcs/Trader/trading_serv_export.h"
00032 
00033 #if defined(_MSC_VER)
00034 #pragma warning(push)
00035 #pragma warning (disable:4250)
00036 #endif /* _MSC_VER */
00037 
00038 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00039 
00040 // Forward Declaration.
00041 class TAO_Trader_Base;
00042 
00043   // *************************************************************
00044   // TAO_Trader_Factory
00045   // *************************************************************
00046 
00047 /**
00048  * @class TAO_Trader_Factory
00049  *
00050  * @brief Uses command line arguments to construct a trader instance with
00051  * the correct interface support, locking, and policy settings.
00052  */
00053 class TAO_Trading_Serv_Export TAO_Trader_Factory
00054 {
00055 public:
00056 
00057   typedef TAO_Trader_Base TAO_TRADER;
00058 
00059   /**
00060    * Creates an instance of the trader according to parameters whose
00061    * default values can be overrided with the following command line
00062    * arguments:
00063    *
00064    * -TSthreadsafe, default is not thread-safe
00065    * -TSconformance {query, simple, stand-alone, linked}, default is linked
00066    * -TSsupports_dynamic_properties {true, false}, default is true
00067    * -TSsupports_modifiable_propertise {true, false}, default is true
00068    * -TSdef_search_card {integer}, default is 20
00069    * -TSmax_search_card {integer}, default is 50
00070    * -TSdef_match_card {integer}, default is 20
00071    * -TSmax_match_card {integer}, default is 50
00072    * -TSdef_return_card {integer}, default is 20
00073    * -TSmax_return_card {integer}, default is 50
00074    * -TSdef_hop_count {integer}, default is 5,
00075    * -TSmax_hop_count {integer}, default is 10
00076    * -TSdef_follow_policy {always,if_no_local,local_only}, default is if_no_local,
00077    * -TSmax_follow_policy {always,if_no_local,local_only}, default is always
00078    */
00079   static TAO_TRADER* create_trader (int& argc, ACE_TCHAR** argv);
00080 
00081 protected:
00082 
00083   TAO_Trader_Factory (int& argc, ACE_TCHAR** argv);
00084 
00085 private:
00086 
00087   enum Conformance { TAO_TRADER_QUERY,
00088                      TAO_TRADER_SIMPLE,
00089                      TAO_TRADER_STANDALONE,
00090                      TAO_TRADER_LINKED };
00091 
00092   TAO_TRADER* manufacture_trader (void);
00093 
00094   void parse_args (int& argc, ACE_TCHAR** argv);
00095 
00096   TAO_Trader_Factory& operator= (const TAO_Trader_Factory&);
00097   TAO_Trader_Factory (const TAO_Trader_Factory&);
00098 
00099   // = Command line configurable parameters.
00100 
00101   Conformance conformance_;
00102   CORBA::Boolean threadsafe_;
00103   CORBA::Boolean supports_dynamic_properties_;
00104   CORBA::Boolean supports_modifiable_properties_;
00105   CORBA::ULong def_search_card_;
00106   CORBA::ULong max_search_card_;
00107   CORBA::ULong def_match_card_;
00108   CORBA::ULong max_match_card_;
00109   CORBA::ULong def_return_card_;
00110   CORBA::ULong max_return_card_;
00111   CORBA::ULong def_hop_count_;
00112   CORBA::ULong max_hop_count_;
00113   CosTrading::FollowOption def_follow_policy_;
00114   CosTrading::FollowOption max_follow_policy_;
00115 };
00116 
00117   // *************************************************************
00118   // Attribute Classes
00119   // *************************************************************
00120 
00121 /**
00122  * @class TAO_Lockable
00123  *
00124  * Class used to remove the circular dependencies between the
00125  * Attribute classes and the Trader class.
00126  */
00127 #if defined (__BORLANDC__) && (__BORLANDC__ <= 0x582)
00128 // Work around Borland unresolved symbol errors concerning the
00129 // out-of-line virtual destructor.  The virtual destructor should
00130 // not be inlined, nor should we have to export TAO_Lockable from the
00131 // DSO/DLL.  *sigh*
00132 class TAO_Trading_Serv_Export TAO_Lockable
00133 #else
00134 class TAO_Lockable
00135 #endif  /* __BORLANDC__ < 0x581 */
00136 {
00137 public:
00138   virtual ~TAO_Lockable (void);
00139 
00140   virtual ACE_Lock& lock (void) = 0;
00141 };
00142 
00143 
00144 /**
00145  * @class TAO_Support_Attributes_i
00146  *
00147  * @brief This class stores, allows access to and modification of
00148  * trader's support attributes.
00149  *
00150  * Contains a reference to the trader from which it is
00151  * used so it can use trader's lock.
00152  */
00153 class TAO_Trading_Serv_Export TAO_Support_Attributes_i
00154 {
00155 public:
00156   // = Initialization and termination methods.
00157   TAO_Support_Attributes_i (TAO_Lockable &locker);
00158   ~TAO_Support_Attributes_i ();
00159 
00160   // = Accessor methods.
00161   CORBA::Boolean supports_modifiable_properties (void) const;
00162   void supports_modifiable_properties (CORBA::Boolean);
00163 
00164   CORBA::Boolean supports_dynamic_properties (void) const;
00165   void supports_dynamic_properties (CORBA::Boolean);
00166 
00167   CORBA::Boolean supports_proxy_offers (void) const;
00168   void supports_proxy_offers (CORBA::Boolean);
00169 
00170   CosTrading::TypeRepository_ptr type_repos (void) const;
00171   void type_repos (CosTrading::TypeRepository_ptr);
00172 
00173   CosTradingRepos::ServiceTypeRepository_ptr service_type_repos (void) const;
00174 
00175 private:
00176 
00177   /// A reference to the trader (needed for obtaining the lock.)
00178   TAO_Lockable &locker_;
00179 
00180   /// Indicator of whether the trader supports property modification.
00181   CORBA::Boolean supports_modifiable_properties_;
00182 
00183   /// Indicator of whether the trader supports dynamic properties.
00184   CORBA::Boolean supports_dynamic_properties_;
00185 
00186   /// Indicator of whether the trader supports proxy offers.
00187   CORBA::Boolean supports_proxy_offers_;
00188 
00189   /// A reference to the TypeRepostitory used by the trader.
00190   CORBA::Object_var type_repos_;
00191 
00192   /// Already narrowed reference to the ServiceTypeRepository.
00193   CosTradingRepos::ServiceTypeRepository_var service_type_repos_;
00194 };
00195 
00196 /**
00197  * @class TAO_Link_Attributes_i
00198  *
00199  * @brief This class stores, allows access to and modification of
00200  * trader's link attributes.
00201  *
00202  * Contains a reference to the trader from which it is
00203  * used so it can use trader's lock.
00204  */
00205 class TAO_Trading_Serv_Export TAO_Link_Attributes_i
00206 {
00207 public:
00208   // = Initialization and termination methods.
00209 
00210   TAO_Link_Attributes_i (TAO_Lockable &locker);
00211   ~TAO_Link_Attributes_i ();
00212 
00213   // = Accessor methods.
00214 
00215   CosTrading::FollowOption max_link_follow_policy (void) const;
00216   void  max_link_follow_policy (CosTrading::FollowOption);
00217 
00218 private:
00219 
00220   /// A reference to the trader (needed for obtaining the lock.)
00221   TAO_Lockable &locker_;
00222 
00223   ///
00224   CosTrading::FollowOption max_link_follow_policy_;
00225 };
00226 
00227 /**
00228  * @class TAO_Import_Attributes_i
00229  *
00230  * @brief This class stores, allows access to and modification of
00231  * trader's import attributes.
00232  *
00233  * Contains a reference to the trader from which it is
00234  * used so it can use trader's lock.
00235  */
00236 class TAO_Trading_Serv_Export TAO_Import_Attributes_i
00237 {
00238 public:
00239   // = Initialization and termination methods.
00240 
00241   TAO_Import_Attributes_i (TAO_Lockable &locker);
00242 
00243   ~TAO_Import_Attributes_i (void);
00244 
00245   // = Accessor methods.
00246 
00247   CORBA::ULong def_search_card (void) const;
00248   void def_search_card (CORBA::ULong);
00249 
00250   CORBA::ULong max_search_card (void) const;
00251   void max_search_card (CORBA::ULong);
00252 
00253   CORBA::ULong def_match_card (void) const;
00254   void def_match_card (CORBA::ULong);
00255 
00256   CORBA::ULong max_match_card (void) const;
00257   void max_match_card (CORBA::ULong);
00258 
00259   CORBA::ULong def_return_card (void) const;
00260   void def_return_card (CORBA::ULong);
00261 
00262   CORBA::ULong max_return_card (void) const;
00263   void max_return_card (CORBA::ULong);
00264 
00265   CORBA::ULong max_list (void) const;
00266   void max_list (CORBA::ULong);
00267 
00268   CORBA::ULong def_hop_count (void) const;
00269   void def_hop_count (CORBA::ULong);
00270 
00271   CORBA::ULong max_hop_count (void) const;
00272   void max_hop_count (CORBA::ULong);
00273 
00274   CosTrading::FollowOption def_follow_policy (void) const;
00275   void def_follow_policy (CosTrading::FollowOption);
00276 
00277   CosTrading::FollowOption max_follow_policy (void) const;
00278   void max_follow_policy (CosTrading::FollowOption);
00279 
00280 private:
00281 
00282   TAO_Lockable &locker_;
00283 
00284   /// Upper bound of offers to be searched if <search_card>
00285   /// is not specified.
00286   CORBA::ULong def_search_card_;
00287 
00288   /// Maximum upper bound of offers to be searched.
00289   CORBA::ULong max_search_card_;
00290 
00291   /// Upper bound of matched offers to be ordered if
00292   /// <match_card> is not specified).
00293   CORBA::ULong def_match_card_;
00294 
00295   /// Maximum upper bound of matched offers to be ordered.
00296   CORBA::ULong max_match_card_;
00297 
00298   /// Upper bound of ordered offers to be returned if
00299   /// <returned_card> is not specified.
00300   CORBA::ULong def_return_card_;
00301 
00302   /// Maximum upper bound of ordered offers to be returned.
00303   CORBA::ULong max_return_card_;
00304 
00305   /// Upper bound of depth
00306   CORBA::ULong max_list_;
00307 
00308   /// Upper bound of depth of links to be traversed if <hop_count> is
00309   /// not specified.
00310   CORBA::ULong def_hop_count_;
00311 
00312   /// Maximum upper bound of depth of links to be traversed.
00313   CORBA::ULong max_hop_count_;
00314 
00315   /// Default link follow policy for a particular trader.
00316   CosTrading::FollowOption def_follow_policy_;
00317 
00318   /// Limiting link follow policy for all links of the trader -
00319   /// overrides both link and importer policies.
00320   CosTrading::FollowOption max_follow_policy_;
00321 };
00322 
00323 /**
00324  * @class TAO_Trading_Components_i
00325  *
00326  * @brief Set/get methods for references to various
00327  * interfaces of the trader.
00328  *
00329  * Note, this class is for use in local address space only and is NOT a
00330  * direct implementation of IDL methods. (Implementation of
00331  * IDL methods in CosTrading::Trader_Components would need
00332  * add a _duplicate call for each get method).
00333  */
00334 class TAO_Trading_Serv_Export TAO_Trading_Components_i
00335 {
00336 public:
00337 
00338   // = Initialization and termination methods.
00339   TAO_Trading_Components_i (TAO_Lockable &locker);
00340   ~TAO_Trading_Components_i (void);
00341 
00342   // = CosTrading::TraderComponents methods.
00343 
00344   /// Returns an object reference to the Lookup interface of the trader.
00345   /// Returns nil if the trader does not support Lookup interface.
00346   CosTrading::Lookup_ptr lookup_if (void) const;
00347 
00348   /// Set the reference to the Lookup interface.
00349   void lookup_if (CosTrading::Lookup_ptr);
00350 
00351   /// Returns object reference for the Register interface of the trader.
00352   /// Returns nil if the trader does not support Register interface.
00353   CosTrading::Register_ptr register_if (void) const;
00354 
00355   /// Set the reference to the Register interface of the trader.
00356   void register_if (CosTrading::Register_ptr);
00357 
00358   /// Returns object reference for the Link interface of the trader.
00359   /// Returns nil if the trader does not support Link interface.
00360   CosTrading::Link_ptr link_if (void) const;
00361 
00362   /// Set the reference to the Link interface of the trader.
00363   void link_if (CosTrading::Link_ptr);
00364 
00365   /// Returns object reference to the Proxy interface of the trader.
00366   /// Returns nil if the trader does not support Proxy interface.
00367   CosTrading::Proxy_ptr proxy_if (void) const;
00368 
00369   /// Set the reference to the Proxy interface of the trader.
00370   void proxy_if (CosTrading::Proxy_ptr);
00371 
00372   /// Returns object reference for the Admin interface of the trader.
00373   /// Returns nil if the trader does not support Admin interface.
00374   CosTrading::Admin_ptr admin_if (void) const;
00375 
00376   /// Set the reference to the Admin interface of the trader.
00377   void admin_if (CosTrading::Admin_ptr);
00378 
00379 private:
00380 
00381   TAO_Lockable &locker_;
00382 
00383   CosTrading::Lookup_var lookup_;
00384   CosTrading::Register_var register_;
00385   CosTrading::Link_var link_;
00386   CosTrading::Proxy_var proxy_;
00387   CosTrading::Admin_var admin_;
00388 };
00389 
00390   // *************************************************************
00391   // TAO_Trader_Base
00392   // *************************************************************
00393 
00394 /**
00395  * @class TAO_Trader_Base
00396  *
00397  * @brief TAO_Trader inherits from this "helper" class.
00398  * The sole purpose of this class is to factor some of TAO_Trader's
00399  * data members out, so that they would not have to be templatized
00400  * and be be aware of the type of lock they use.
00401  *
00402  * TAO_Trader is a template class.  And while we want
00403  * <import_attributes_>, <trader_components_>, and
00404  * <support_attributes> use a lock contained in TAO_Trader, we do not
00405  * want all these classes to be templatized.  TAO_Trader_Base class solves
00406  * this problem.
00407  */
00408 class TAO_Trading_Serv_Export TAO_Trader_Base : public TAO_Lockable
00409 {
00410 public:
00411 
00412   enum Trader_Components
00413   {
00414     LOOKUP = 0x001,
00415     REGISTER = 0x002,
00416     LINK = 0x004,
00417     PROXY = 0x008,
00418     ADMIN = 0x010
00419   };
00420 
00421   virtual ~TAO_Trader_Base (void);
00422 
00423   // = Accessors for objects that manage trader's configuration.
00424 
00425   TAO_Trading_Components_i &trading_components (void);
00426 
00427   const TAO_Trading_Components_i &trading_components (void) const;
00428 
00429   TAO_Import_Attributes_i &import_attributes (void);
00430 
00431   const TAO_Import_Attributes_i &import_attributes (void) const;
00432 
00433   TAO_Support_Attributes_i &support_attributes (void);
00434 
00435   const TAO_Support_Attributes_i &support_attributes (void) const;
00436 
00437   TAO_Link_Attributes_i &link_attributes (void);
00438 
00439   const TAO_Link_Attributes_i &link_attributes (void) const;
00440 
00441   // = Accessor for trader's lock.
00442 
00443   /**
00444    * Determine whether the identifier is a valid one (i.e., if the
00445    * first character is a letter, and the subsequent ones letter,
00446    * numbers, or underscores.)
00447    *
00448    * IDL identifier scoping and escaping rules apply.
00449    */
00450   static CORBA::Boolean is_valid_identifier_name (const char* ident);
00451 
00452   /**
00453    * Determine whether the identifier is a valid one (i.e., if the
00454    * first character is a letter, and the subsequent ones letter,
00455    * numbers, or underscores.)
00456    */
00457   static CORBA::Boolean is_valid_property_name (const char* ident);
00458 
00459   /**
00460    * Determine whether the link name is a valid one
00461    * currently defined the same as property name.
00462    */
00463   static CORBA::Boolean is_valid_link_name (const char* ident)
00464   {
00465     return is_valid_property_name (ident);
00466   }
00467 
00468 protected:
00469   // = Objects determining current configuration of a trader.
00470 
00471   /// Stores and allows lookup of trader's components.
00472   TAO_Trading_Components_i trading_components_;
00473 
00474   /// Stores and allows access/modification of trader's import attributes.
00475   TAO_Import_Attributes_i import_attributes_;
00476 
00477   /// Stores and allows access/modification of trader's support attributes.
00478   TAO_Support_Attributes_i support_attributes_;
00479 
00480   /// Stores and allows access/modification of trader's link attributes.
00481   TAO_Link_Attributes_i link_attributes_;
00482 
00483  protected:
00484 
00485   /// Implemented.
00486   TAO_Trader_Base (void);
00487 
00488  private:
00489 
00490   /// Unimplemented.
00491   TAO_Trader_Base (const TAO_Trader_Base& TAO_Trader_Base);
00492   TAO_Trader_Base& operator= (const TAO_Trader_Base&);
00493 };
00494 
00495 
00496 // Helpful typedefs
00497 // Should probably be private to TAO_Offer_Database, but g++ has a
00498 // hard time with it like that when compiling TAO_Service_Offer_Iterator.
00499 typedef ACE_Hash_Map_Manager_Ex<CORBA::ULong, CosTrading::Offer*, ACE_Hash<CORBA::ULong>, ACE_Equal_To<CORBA::ULong>, ACE_Null_Mutex> TAO_Offer_Map;
00500 
00501 typedef ACE_Unbounded_Set<CORBA::String_var> TAO_String_Set;
00502 typedef ACE_Unbounded_Queue<char*> TAO_String_Queue;
00503 
00504 // = Helpful operators.
00505 
00506 bool
00507 operator> (const CosTradingRepos::ServiceTypeRepository::IncarnationNumber &l,
00508            const CosTradingRepos::ServiceTypeRepository::IncarnationNumber &r);
00509 
00510 bool
00511 operator< (const CosTradingRepos::ServiceTypeRepository::IncarnationNumber &l,
00512            const CosTradingRepos::ServiceTypeRepository::IncarnationNumber &r);
00513 
00514 bool
00515 operator== (const CosTrading::Admin::OctetSeq& left,
00516             const CosTrading::Admin::OctetSeq& right);
00517 
00518 TAO_END_VERSIONED_NAMESPACE_DECL
00519 
00520 #if defined(_MSC_VER)
00521 #pragma warning(pop)
00522 #endif /* _MSC_VER */
00523 
00524 #include /**/ "ace/post.h"
00525 #endif /* TAO_TRADER_BASE_H */

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