00001 // Offer_Iterators_T.cpp,v 1.24 2006/03/14 06:14:35 jtc Exp 00002 00003 #ifndef TAO_OFFER_ITERATORS_T_CPP 00004 #define TAO_OFFER_ITERATORS_T_CPP 00005 00006 #include "orbsvcs/Trader/Offer_Iterators_T.h" 00007 00008 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00009 00010 template <class MAP_LOCK_TYPE> 00011 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE>:: 00012 TAO_Register_Offer_Iterator (TAO_Offer_Database<MAP_LOCK_TYPE> &db, 00013 const TAO_Property_Filter& pfilter) 00014 : TAO_Offer_Iterator (pfilter), 00015 db_ (db) 00016 { 00017 } 00018 00019 template <class MAP_LOCK_TYPE> 00020 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE>:: 00021 ~TAO_Register_Offer_Iterator (void) 00022 { 00023 while (! this->offer_ids_.is_empty ()) 00024 { 00025 CosTrading::OfferId offer_id = 0; 00026 this->offer_ids_.dequeue_head (offer_id); 00027 00028 CORBA::string_free (offer_id); 00029 } 00030 } 00031 00032 template <class MAP_LOCK_TYPE> void 00033 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE>:: 00034 add_offer (CosTrading::OfferId id, 00035 const CosTrading::Offer* /* offer */) 00036 { 00037 this->offer_ids_.enqueue_tail (id); 00038 } 00039 00040 template <class MAP_LOCK_TYPE> CORBA::ULong 00041 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE>:: 00042 max_left (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) 00043 ACE_THROW_SPEC ((CORBA::SystemException, 00044 CosTrading::UnknownMaxLeft)) 00045 { 00046 return static_cast<CORBA::ULong> (this->offer_ids_.size ()); 00047 } 00048 00049 template <class MAP_LOCK_TYPE> CORBA::Boolean 00050 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE>:: 00051 next_n (CORBA::ULong n, 00052 CosTrading::OfferSeq_out offers 00053 ACE_ENV_ARG_DECL) 00054 ACE_THROW_SPEC ((CORBA::SystemException)) 00055 { 00056 CORBA::ULong ret_offers = 0; 00057 00058 CORBA::ULong max_possible_offers_in_sequence = 00059 (n < this->offer_ids_.size ()) ? n : 00060 static_cast<CORBA::ULong> (this->offer_ids_.size ()); 00061 00062 ACE_NEW_THROW_EX (offers, 00063 CosTrading::OfferSeq, 00064 CORBA::NO_MEMORY ()); 00065 ACE_CHECK_RETURN (0); 00066 00067 offers->length (max_possible_offers_in_sequence); 00068 00069 // While there are entries left and we haven't filled <offers> 00070 // with requested number. 00071 while (! this->offer_ids_.is_empty () 00072 && n > ret_offers) 00073 { 00074 // If offer is found, put it into the sequence. 00075 // remove this id irrespective of whether the offer is found 00076 // or not. 00077 CosTrading::OfferId id = 0; 00078 this->offer_ids_.dequeue_head (id); 00079 00080 CosTrading::OfferId_var offerid_var (id); 00081 CosTrading::Offer* offer = this->db_.lookup_offer (id ACE_ENV_ARG_PARAMETER); 00082 ACE_CHECK_RETURN (0); 00083 00084 if (offer != 0) 00085 this->pfilter_.filter_offer (offer, 00086 offers[ret_offers++]); 00087 } 00088 00089 // Reset the length to the correct value 00090 offers->length (ret_offers); 00091 00092 return static_cast<CORBA::Boolean> (ret_offers != 0); 00093 } 00094 00095 TAO_END_VERSIONED_NAMESPACE_DECL 00096 00097 #endif /* TAO_REGISTER_OFFER_ITERATOR_CPP */