00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Offer_Iterators.h 00006 * 00007 * Offer_Iterators.h,v 1.25 2006/03/14 06:14:35 jtc Exp 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 (ACE_ENV_SINGLE_ARG_DECL) 00063 ACE_THROW_SPEC ((CORBA::SystemException)); 00064 00065 /// Add an offer to the collection of offers the iterator will 00066 /// iterate over. 00067 virtual void add_offer (CosTrading::OfferId offer_id, 00068 const CosTrading::Offer* offer) = 0; 00069 00070 virtual CORBA::ULong max_left (ACE_ENV_SINGLE_ARG_DECL) 00071 ACE_THROW_SPEC ((CORBA::SystemException, 00072 CosTrading::UnknownMaxLeft)) = 0; 00073 00074 // BEGIN SPEC 00075 // The max_left operation returns the number of service offers 00076 // remaining in the iterator. The exception UnknownMaxLeft is raised 00077 // if the iterator cannot determine the remaining number of service 00078 // offers (e.g., if the iterator determines its set of service 00079 // offers through lazy evaluation). 00080 // END SPEC 00081 00082 /** 00083 * BEGIN SPEC 00084 * The next_n operation returns a set of service offers in the 00085 * output parameter "offers." The operation returns n service offers 00086 * if there are at least n service offers remaining in the 00087 * iterator. If there are fewer than n service offers in the 00088 * iterator, then all remaining service offers are returned. The 00089 * actual number of service offers returned can be determined from 00090 * the length of the "offers" sequence. The next_n operation returns 00091 * TRUE if there are further service offers to be extracted from the 00092 * iterator. It returns FALSE if there are no further service offers 00093 * to be extracted. 00094 * END SPEC 00095 */ 00096 virtual CORBA::Boolean next_n (CORBA::ULong n, 00097 CosTrading::OfferSeq_out offers 00098 ACE_ENV_ARG_DECL) 00099 ACE_THROW_SPEC ((CORBA::SystemException)) = 0; 00100 protected: 00101 00102 TAO_Offer_Iterator& operator=(const TAO_Offer_Iterator&); 00103 00104 /// The filter through which each returned offer must pass. Used to 00105 /// strip offers of undesirable properties. 00106 TAO_Property_Filter pfilter_; 00107 }; 00108 00109 // ************************************************************* 00110 // TAO_Query_Only_Offer_Iterator 00111 // ************************************************************* 00112 00113 class TAO_Query_Only_Offer_Iterator 00114 : public TAO_Offer_Iterator 00115 // = TITLE 00116 // An implementation of the CosTrading::OfferIterator IDL 00117 // interface that takes advantage of the fact that the trader is 00118 // Query Only, and therefore its service offers are not being 00119 // changed or removed. 00120 // 00121 // = DESCRIPTION 00122 // The iterator stores pointers to Offers to be iterated over, 00123 // and later accesses the Offers directly through the pointers. 00124 // 00125 { 00126 public: 00127 // = Initialization and termination methods. 00128 00129 TAO_Query_Only_Offer_Iterator (const TAO_Property_Filter& pfilter); 00130 00131 virtual ~TAO_Query_Only_Offer_Iterator (void); 00132 00133 /// Deposit at maximum n offers into the return sequence and return 1, 00134 /// or return 0 if the iterator is done and no offers are returned. 00135 virtual CORBA::Boolean next_n (CORBA::ULong n, 00136 CosTrading::OfferSeq_out offers 00137 ACE_ENV_ARG_DECL) 00138 ACE_THROW_SPEC ((CORBA::SystemException)); 00139 00140 /// Return the number of items left in the iterator. 00141 virtual CORBA::ULong max_left (ACE_ENV_SINGLE_ARG_DECL) 00142 ACE_THROW_SPEC ((CORBA::SystemException, 00143 CosTrading::UnknownMaxLeft)); 00144 00145 /// Add an offer the iterator should iterate over. 00146 void add_offer (CosTrading::OfferId offer_id, 00147 const CosTrading::Offer* offer); 00148 00149 private: 00150 00151 TAO_Query_Only_Offer_Iterator (const TAO_Query_Only_Offer_Iterator&); 00152 TAO_Query_Only_Offer_Iterator& operator=(const TAO_Query_Only_Offer_Iterator&); 00153 00154 /// Structure that stores pointers to offers 00155 /// to iterate over. 00156 ACE_Unbounded_Queue <CosTrading::Offer *> offers_; 00157 }; 00158 00159 // ************************************************************* 00160 // TAO_Offer_Iterator_Collection 00161 // ************************************************************* 00162 00163 class TAO_Offer_Iterator_Collection : 00164 public virtual POA_CosTrading::OfferIterator 00165 // = TITLE 00166 // A collection of offer iterator to query in turn. 00167 // 00168 // = DESCRIPTION 00169 // Since a query could conceivable query several other traders, it 00170 // needs a way to merge the results into a single set of results 00171 // suitable for being returned to the user. And since all the query 00172 // method can return to the user is a sequence and an iterator, and 00173 // the size of the sequence is constrained, there needs to be some 00174 // way to collect all the returned offer_iterators into a single 00175 // offer_iterator. This is that collection. The results of 00176 // collecting all the iterators in this way is a distributed tree of 00177 // iterators, which could conceivably become hugely inefficient if 00178 // the trader graph is deep enough. 00179 { 00180 public: 00181 00182 // = Constructors. 00183 00184 TAO_Offer_Iterator_Collection (void); 00185 00186 virtual ~TAO_Offer_Iterator_Collection (void); 00187 00188 /// Retrieve n offers from the set of iterators. 00189 virtual CORBA::Boolean next_n (CORBA::ULong n, 00190 CosTrading::OfferSeq_out offers 00191 ACE_ENV_ARG_DECL) 00192 ACE_THROW_SPEC ((CORBA::SystemException)); 00193 00194 /// Destroy the collection of iterators. 00195 virtual void destroy (ACE_ENV_SINGLE_ARG_DECL) 00196 ACE_THROW_SPEC ((CORBA::SystemException)); 00197 00198 /// Determine how many offers are left in the collection. 00199 virtual CORBA::ULong max_left (ACE_ENV_SINGLE_ARG_DECL) 00200 ACE_THROW_SPEC ((CORBA::SystemException, 00201 CosTrading::UnknownMaxLeft)); 00202 00203 /// Add an iterator to the collection. 00204 void add_offer_iterator (CosTrading::OfferIterator_ptr offer_iter); 00205 00206 private: 00207 00208 TAO_Offer_Iterator_Collection (const TAO_Offer_Iterator_Collection&); 00209 TAO_Offer_Iterator_Collection& operator= (const TAO_Offer_Iterator_Collection&); 00210 00211 typedef ACE_Unbounded_Queue <CosTrading::OfferIterator*> Offer_Iters; 00212 00213 /// The iterator collection. 00214 Offer_Iters iters_; 00215 }; 00216 00217 // ************************************************************* 00218 // TAO_Offer_Id_Iterator 00219 // ************************************************************* 00220 00221 class TAO_Offer_Id_Iterator : 00222 public virtual POA_CosTrading::OfferIdIterator 00223 // = TITLE 00224 // Silly little iterator that contains the overflow of offer ids 00225 // from the Admin list_offers method. 00226 // 00227 // = DESCRIPTION 00228 // 00229 // BEGIN SPEC 00230 // The OfferIdIterator interface is used to return a set of offer 00231 // identifiers from the list_offers operation and the list_proxies 00232 // operation in the Admin interface by enabling the offer identifiers 00233 // to be extracted by successive operations on the OfferIdIterator 00234 // interface. 00235 // END SPEC 00236 { 00237 public: 00238 00239 /// No op constructor 00240 TAO_Offer_Id_Iterator(void); 00241 00242 ~TAO_Offer_Id_Iterator (void); 00243 00244 /** 00245 * The max_left operation returns the number of offer identifiers 00246 * remaining in the iterator. The exception UnknownMaxLeft is raised 00247 * if the iterator cannot determine the remaining number of offer 00248 * identifiers (e.g., if the iterator determines its set of offer 00249 * identifiers through lazy evaluation). 00250 */ 00251 virtual CORBA::ULong max_left(ACE_ENV_SINGLE_ARG_DECL) 00252 ACE_THROW_SPEC ((CORBA::SystemException, 00253 CosTrading::UnknownMaxLeft)); 00254 00255 /** 00256 * The destroy operation destroys the iterator. No further 00257 * operations can be invoked on an iterator after it has been 00258 * destroyed. 00259 */ 00260 virtual void destroy(ACE_ENV_SINGLE_ARG_DECL) 00261 ACE_THROW_SPEC ((CORBA::SystemException)); 00262 00263 /** 00264 * The next_n operation returns a set of offer identifiers in the 00265 * output parameter "ids." The operation returns n offer identifiers 00266 * if there are at least n offer identifiers remaining in the 00267 * iterator. If there are fewer than n offer identifiers in the 00268 * iterator, then all remaining offer identifiers are returned. The 00269 * actual number of offer identifiers returned can be determined 00270 * from the length of the "ids" sequence. The next_n operation 00271 * returns TRUE if there are further offer identifiers to be 00272 * extracted from the iterator. It returns FALSE if there are no 00273 * further offer identifiers to be extracted. 00274 */ 00275 virtual CORBA::Boolean next_n(CORBA::ULong _n, 00276 CosTrading::OfferIdSeq_out _ids 00277 ACE_ENV_ARG_DECL) 00278 ACE_THROW_SPEC ((CORBA::SystemException)); 00279 00280 /// Insert a <new_id> into the contents of the iterator. 00281 void insert_id(CosTrading::OfferId new_id); 00282 00283 private: 00284 00285 TAO_Offer_Id_Iterator (const TAO_Offer_Id_Iterator&); 00286 TAO_Offer_Id_Iterator& operator= (TAO_Offer_Id_Iterator&); 00287 00288 TAO_String_Queue ids_; 00289 }; 00290 00291 TAO_END_VERSIONED_NAMESPACE_DECL 00292 00293 #if defined(_MSC_VER) 00294 #pragma warning(pop) 00295 #endif /* _MSC_VER */ 00296 00297 #include /**/ "ace/post.h" 00298 #endif /* TAO_OFFER_ITERATOR */