Offer_Iterators.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Offer_Iterators.h
00006  *
00007  *  $Id: Offer_Iterators.h 77001 2007-02-12 07:54:49Z johnnyw $
00008  *
00009  *  @author Marina Spivak <marina@cs.wustl.edu>
00010  *  @author Seth Widoff <sbw1@cs.wustl.edu>
00011  */
00012 //=============================================================================
00013 
00014 
00015 #ifndef TAO_OFFER_ITERATORS_H
00016 #define TAO_OFFER_ITERATORS_H
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "orbsvcs/Trader/Trader_Utils.h"
00020 
00021 #if defined(_MSC_VER)
00022 #pragma warning(push)
00023 #pragma warning(disable:4250)
00024 #endif /* _MSC_VER */
00025 
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027 
00028   // *************************************************************
00029   // TAO_Offer_Iterator
00030   // *************************************************************
00031 
00032 class TAO_Offer_Iterator
00033   : public virtual POA_CosTrading::OfferIterator
00034 {
00035   // = TITLE
00036   //     This class implements CosTrading::OfferIterator IDL
00037   //     interface.
00038 
00039   // = DESCRIPTION
00040   //     This is an abstract base class  to allow for different
00041   //     implementations of OfferIterator.
00042   // BEGIN SPEC
00043   //   The OfferIterator interface is used to return a set of service
00044   //   offers from the query operation by enabling the service offers
00045   //   to be extracted by successive operations on the OfferIterator
00046   //   interface.
00047   // END SPEC
00048 public:
00049   // = Initialization and termination methods.
00050 
00051   TAO_Offer_Iterator (const TAO_Property_Filter& property_filter);
00052 
00053   virtual ~TAO_Offer_Iterator (void);
00054 
00055   /**
00056    * BEGIN SPEC
00057    * The destroy operation destroys the iterator. No further
00058    * operations can be invoked on an iterator after it has been
00059    * destroyed.
00060    * END SPEC
00061    */
00062   virtual void destroy (void);
00063 
00064   /// Add an offer to the collection of offers the iterator will
00065   /// iterate over.
00066   virtual void add_offer (CosTrading::OfferId offer_id,
00067                           const CosTrading::Offer* offer) = 0;
00068 
00069   virtual CORBA::ULong max_left (void)
00070     = 0;
00071 
00072   // BEGIN SPEC
00073   // The max_left operation returns the number of service offers
00074   // remaining in the iterator. The exception UnknownMaxLeft is raised
00075   // if the iterator cannot determine the remaining number of service
00076   // offers (e.g., if the iterator determines its set of service
00077   // offers through lazy evaluation).
00078   // END SPEC
00079 
00080   /**
00081    * BEGIN SPEC
00082    * The next_n operation returns a set of service offers in the
00083    * output parameter "offers." The operation returns n service offers
00084    * if there are at least n service offers remaining in the
00085    * iterator. If there are fewer than n service offers in the
00086    * iterator, then all remaining service offers are returned. The
00087    * actual number of service offers returned can be determined from
00088    * the length of the "offers" sequence. The next_n operation returns
00089    * TRUE if there are further service offers to be extracted from the
00090    * iterator. It returns FALSE if there are no further service offers
00091    * to be extracted.
00092    * END SPEC
00093    */
00094   virtual CORBA::Boolean next_n (CORBA::ULong n,
00095                                  CosTrading::OfferSeq_out offers)
00096     = 0;
00097  protected:
00098 
00099   TAO_Offer_Iterator& operator=(const TAO_Offer_Iterator&);
00100 
00101   /// The filter through which each returned offer must pass. Used to
00102   /// strip offers of undesirable properties.
00103   TAO_Property_Filter pfilter_;
00104 };
00105 
00106   // *************************************************************
00107   // TAO_Query_Only_Offer_Iterator
00108   // *************************************************************
00109 
00110 class TAO_Query_Only_Offer_Iterator
00111   : public TAO_Offer_Iterator
00112   // = TITLE
00113   //     An implementation of the CosTrading::OfferIterator IDL
00114   //     interface that takes advantage of the fact that the trader is
00115   //     Query Only, and therefore its service offers are not being
00116   //     changed or removed.
00117   //
00118   // = DESCRIPTION
00119   //     The iterator stores pointers to Offers to be iterated over,
00120   //     and later accesses the Offers directly through the pointers.
00121   //
00122 {
00123 public:
00124   // = Initialization and termination methods.
00125 
00126   TAO_Query_Only_Offer_Iterator (const TAO_Property_Filter& pfilter);
00127 
00128   virtual ~TAO_Query_Only_Offer_Iterator (void);
00129 
00130   /// Deposit at maximum n offers into the return sequence and return 1,
00131   /// or return 0 if the iterator is done and no offers are returned.
00132   virtual CORBA::Boolean next_n (CORBA::ULong n,
00133                                  CosTrading::OfferSeq_out offers);
00134 
00135   /// Return the number of items left in the iterator.
00136   virtual CORBA::ULong max_left (void);
00137 
00138   /// Add an offer the iterator should iterate over.
00139   void add_offer (CosTrading::OfferId offer_id,
00140                   const CosTrading::Offer* offer);
00141 
00142 private:
00143 
00144   TAO_Query_Only_Offer_Iterator (const TAO_Query_Only_Offer_Iterator&);
00145   TAO_Query_Only_Offer_Iterator& operator=(const TAO_Query_Only_Offer_Iterator&);
00146 
00147   /// Structure that stores pointers to offers
00148   /// to iterate over.
00149   ACE_Unbounded_Queue <CosTrading::Offer *> offers_;
00150 };
00151 
00152   // *************************************************************
00153   // TAO_Offer_Iterator_Collection
00154   // *************************************************************
00155 
00156 class TAO_Offer_Iterator_Collection :
00157   public virtual POA_CosTrading::OfferIterator
00158 // = TITLE
00159 //   A collection of offer iterator to query in turn.
00160 //
00161 // = DESCRIPTION
00162 //   Since a query could conceivable query several other traders, it
00163 //   needs a way to merge the results into a single set of results
00164 //   suitable for being returned to the user. And since all the query
00165 //   method can return to the user is a sequence and an iterator, and
00166 //   the size of the sequence is constrained, there needs to be some
00167 //   way to collect all the returned offer_iterators into a single
00168 //   offer_iterator. This is that collection. The results of
00169 //   collecting all the iterators in this way is a distributed tree of
00170 //   iterators, which could conceivably become hugely inefficient if
00171 //   the trader graph is deep enough.
00172 {
00173 public:
00174 
00175   // = Constructors.
00176 
00177   TAO_Offer_Iterator_Collection (void);
00178 
00179   virtual ~TAO_Offer_Iterator_Collection (void);
00180 
00181   /// Retrieve n offers from the set of iterators.
00182   virtual CORBA::Boolean next_n (CORBA::ULong n,
00183                                  CosTrading::OfferSeq_out offers);
00184 
00185   /// Destroy the collection of iterators.
00186   virtual void destroy (void);
00187 
00188   /// Determine how many offers are left in the collection.
00189   virtual CORBA::ULong max_left (void);
00190 
00191   /// Add an iterator to the collection.
00192   void add_offer_iterator (CosTrading::OfferIterator_ptr offer_iter);
00193 
00194 private:
00195 
00196   TAO_Offer_Iterator_Collection (const TAO_Offer_Iterator_Collection&);
00197   TAO_Offer_Iterator_Collection& operator= (const TAO_Offer_Iterator_Collection&);
00198 
00199   typedef ACE_Unbounded_Queue <CosTrading::OfferIterator*> Offer_Iters;
00200 
00201   /// The iterator collection.
00202   Offer_Iters iters_;
00203 };
00204 
00205   // *************************************************************
00206   // TAO_Offer_Id_Iterator
00207   // *************************************************************
00208 
00209 class TAO_Offer_Id_Iterator :
00210   public virtual POA_CosTrading::OfferIdIterator
00211 // = TITLE
00212 //   Silly little iterator that contains the overflow of offer ids
00213 //   from the Admin list_offers method.
00214 //
00215 // = DESCRIPTION
00216 //
00217 //   BEGIN SPEC
00218 //   The OfferIdIterator interface is used to return a set of offer
00219 //   identifiers from the list_offers operation and the list_proxies
00220 //   operation in the Admin interface by enabling the offer identifiers
00221 //   to be extracted by successive operations on the OfferIdIterator
00222 //   interface.
00223 //   END SPEC
00224 {
00225  public:
00226 
00227   /// No op constructor
00228   TAO_Offer_Id_Iterator(void);
00229 
00230   ~TAO_Offer_Id_Iterator (void);
00231 
00232   /**
00233    * The max_left operation returns the number of offer identifiers
00234    * remaining in the iterator. The exception UnknownMaxLeft is raised
00235    * if the iterator cannot determine the remaining number of offer
00236    * identifiers (e.g., if the iterator determines its set of offer
00237    * identifiers through lazy evaluation).
00238    */
00239   virtual CORBA::ULong max_left(void);
00240 
00241   /**
00242    * The destroy operation destroys the iterator. No further
00243    * operations can be invoked on an iterator after it has been
00244    * destroyed.
00245    */
00246   virtual void destroy(void);
00247 
00248   /**
00249    * The next_n operation returns a set of offer identifiers in the
00250    * output parameter "ids." The operation returns n offer identifiers
00251    * if there are at least n offer identifiers remaining in the
00252    * iterator. If there are fewer than n offer identifiers in the
00253    * iterator, then all remaining offer identifiers are returned. The
00254    * actual number of offer identifiers returned can be determined
00255    * from the length of the "ids" sequence. The next_n operation
00256    * returns TRUE if there are further offer identifiers to be
00257    * extracted from the iterator. It returns FALSE if there are no
00258    * further offer identifiers to be extracted.
00259    */
00260   virtual CORBA::Boolean next_n(CORBA::ULong _n,
00261                                 CosTrading::OfferIdSeq_out _ids);
00262 
00263   /// Insert a <new_id> into the contents of the iterator.
00264   void insert_id(CosTrading::OfferId new_id);
00265 
00266  private:
00267 
00268   TAO_Offer_Id_Iterator (const TAO_Offer_Id_Iterator&);
00269   TAO_Offer_Id_Iterator& operator= (TAO_Offer_Id_Iterator&);
00270 
00271   TAO_String_Queue ids_;
00272 };
00273 
00274 TAO_END_VERSIONED_NAMESPACE_DECL
00275 
00276 #if defined(_MSC_VER)
00277 #pragma warning(pop)
00278 #endif /* _MSC_VER */
00279 
00280 #include /**/ "ace/post.h"
00281 #endif /* TAO_OFFER_ITERATOR */

Generated on Tue Feb 2 17:49:26 2010 for TAO_CosTrader by  doxygen 1.4.7