TAO_Service_Offer_Iterator< LOCK_TYPE > Class Template Reference

TAO_Service_Offer_Iterator iterates over the set of exported offers for a given type. Handily, it takes care of all the necessary locking, acquiring them in the constructor, and releasing them in the destructor. More...

#include <Offer_Database.h>

Collaboration diagram for TAO_Service_Offer_Iterator< LOCK_TYPE >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef TAO_Offer_Database<
LOCK_TYPE > 
Offer_Database

Public Member Functions

 TAO_Service_Offer_Iterator (const char *type, TAO_Offer_Database< LOCK_TYPE > &offer_database)
 ~TAO_Service_Offer_Iterator (void)
 Release all the locks acquired.
int has_more_offers (void)
 Returns 1 if there are more offers, 0 otherwise.
CosTrading::OfferId get_id (void)
 Get the id for the current offer.
CosTrading::Offerget_offer (void)
 Returns the next offer in the series.
void next_offer (void)
 Advances the iterator 1.

Private Attributes

TAO_Offer_Database< LOCK_TYPE > & stm_
 Lock the top_level map.
LOCK_TYPE * lock_
 Lock for the internal map.
TAO_Offer_Map::iteratoroffer_iter_
 Iterator over the actual offer map.
const char * type_
 The name of the type. Used for constructing offer ids.

Detailed Description

template<class LOCK_TYPE>
class TAO_Service_Offer_Iterator< LOCK_TYPE >

TAO_Service_Offer_Iterator iterates over the set of exported offers for a given type. Handily, it takes care of all the necessary locking, acquiring them in the constructor, and releasing them in the destructor.

Definition at line 153 of file Offer_Database.h.


Member Typedef Documentation

template<class LOCK_TYPE>
typedef TAO_Offer_Database<LOCK_TYPE> TAO_Service_Offer_Iterator< LOCK_TYPE >::Offer_Database

Definition at line 157 of file Offer_Database.h.


Constructor & Destructor Documentation

template<class LOCK_TYPE>
TAO_Service_Offer_Iterator< LOCK_TYPE >::TAO_Service_Offer_Iterator ( const char *  type,
TAO_Offer_Database< LOCK_TYPE > &  offer_database 
)

Definition at line 305 of file Offer_Database.cpp.

References ACE_NEW, TAO_Service_Offer_Iterator< LOCK_TYPE >::lock_, and TAO_Service_Offer_Iterator< LOCK_TYPE >::offer_iter_.

00307   : stm_ (offer_database),
00308     lock_ (0),
00309     offer_iter_ (0),
00310     type_ (type)
00311 {
00312   CORBA::String_var service_type (type);
00313 
00314   if (this->stm_.db_lock_.acquire_read () == -1)
00315     return;
00316 
00317   typename TAO_Offer_Database<LOCK_TYPE>::Offer_Map_Entry* entry = 0;
00318   if (this->stm_.offer_db_.find (service_type, entry) == -1)
00319     return;
00320   else
00321     {
00322       this->lock_ = &entry->lock_;
00323       if (this->lock_->acquire_read () == -1)
00324         return;
00325 
00326       ACE_NEW (offer_iter_,
00327                TAO_Offer_Map::iterator (*entry->offer_map_));
00328     }
00329 }

template<class LOCK_TYPE>
TAO_Service_Offer_Iterator< LOCK_TYPE >::~TAO_Service_Offer_Iterator ( void   ) 

Release all the locks acquired.

Definition at line 332 of file Offer_Database.cpp.

References TAO_Service_Offer_Iterator< LOCK_TYPE >::lock_, TAO_Service_Offer_Iterator< LOCK_TYPE >::offer_iter_, and TAO_Service_Offer_Iterator< LOCK_TYPE >::stm_.

00333 {
00334   this->stm_.db_lock_.release ();
00335 
00336   if (this->lock_ != 0)
00337     {
00338       this->lock_->release ();
00339       delete this->offer_iter_;
00340     }
00341 }


Member Function Documentation

template<class LOCK_TYPE>
CosTrading::OfferId TAO_Service_Offer_Iterator< LOCK_TYPE >::get_id ( void   ) 

Get the id for the current offer.

Definition at line 344 of file Offer_Database.cpp.

References TAO_Offer_Database< LOCK_TYPE >::generate_offer_id().

00345 {
00346   return (this->offer_iter_ != 0)
00347     ? TAO_Offer_Database<LOCK_TYPE>::generate_offer_id (this->type_, (**this->offer_iter_).ext_id_)
00348     : 0;
00349 }

template<class LOCK_TYPE>
CosTrading::Offer * TAO_Service_Offer_Iterator< LOCK_TYPE >::get_offer ( void   ) 

Returns the next offer in the series.

Definition at line 359 of file Offer_Database.cpp.

References TAO_Service_Offer_Iterator< LOCK_TYPE >::offer_iter_.

00360 {
00361   return (this->offer_iter_ != 0) ? (**this->offer_iter_).int_id_ : 0;
00362 }

template<class LOCK_TYPE>
int TAO_Service_Offer_Iterator< LOCK_TYPE >::has_more_offers ( void   ) 

Returns 1 if there are more offers, 0 otherwise.

Definition at line 352 of file Offer_Database.cpp.

References TAO_Service_Offer_Iterator< LOCK_TYPE >::offer_iter_.

00353 {
00354   return (this->offer_iter_ != 0) ? ! this->offer_iter_->done () : 0;
00355 }

template<class LOCK_TYPE>
void TAO_Service_Offer_Iterator< LOCK_TYPE >::next_offer ( void   ) 

Advances the iterator 1.

Definition at line 365 of file Offer_Database.cpp.

References TAO_Service_Offer_Iterator< LOCK_TYPE >::offer_iter_.

00366 {
00367   if (this->offer_iter_ != 0)
00368     this->offer_iter_->advance ();
00369 }


Member Data Documentation

template<class LOCK_TYPE>
LOCK_TYPE* TAO_Service_Offer_Iterator< LOCK_TYPE >::lock_ [private]

Lock for the internal map.

Definition at line 184 of file Offer_Database.h.

Referenced by TAO_Service_Offer_Iterator< LOCK_TYPE >::TAO_Service_Offer_Iterator(), and TAO_Service_Offer_Iterator< LOCK_TYPE >::~TAO_Service_Offer_Iterator().

template<class LOCK_TYPE>
TAO_Offer_Map::iterator* TAO_Service_Offer_Iterator< LOCK_TYPE >::offer_iter_ [private]

Iterator over the actual offer map.

Definition at line 187 of file Offer_Database.h.

Referenced by TAO_Service_Offer_Iterator< LOCK_TYPE >::get_offer(), TAO_Service_Offer_Iterator< LOCK_TYPE >::has_more_offers(), TAO_Service_Offer_Iterator< LOCK_TYPE >::next_offer(), TAO_Service_Offer_Iterator< LOCK_TYPE >::TAO_Service_Offer_Iterator(), and TAO_Service_Offer_Iterator< LOCK_TYPE >::~TAO_Service_Offer_Iterator().

template<class LOCK_TYPE>
TAO_Offer_Database<LOCK_TYPE>& TAO_Service_Offer_Iterator< LOCK_TYPE >::stm_ [private]

Lock the top_level map.

Definition at line 181 of file Offer_Database.h.

Referenced by TAO_Service_Offer_Iterator< LOCK_TYPE >::~TAO_Service_Offer_Iterator().

template<class LOCK_TYPE>
const char* TAO_Service_Offer_Iterator< LOCK_TYPE >::type_ [private]

The name of the type. Used for constructing offer ids.

Definition at line 190 of file Offer_Database.h.


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:49:35 2010 for TAO_CosTrader by  doxygen 1.4.7