TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY > Class Template Reference

This class implements the interface that is part of the idl module. This class works with Hash_Map-based implementations of CosNaming::NamingContext. More...

#include <Bindings_Iterator_T.h>

Collaboration diagram for TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_Bindings_Iterator (TAO_Hash_Naming_Context *context, ITERATOR *hash_iter, PortableServer::POA_ptr poa, TAO_SYNCH_RECURSIVE_MUTEX &lock)
 ~TAO_Bindings_Iterator (void)
 Destructor.

virtual PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL)
 Returns the Default POA of this Servant object.

CORBA::Boolean next_one (CosNaming::Binding_out b ACE_ENV_ARG_DECL) throw (CORBA::SystemException)
CORBA::Boolean next_n (CORBA::ULong how_many, CosNaming::BindingList_out bl ACE_ENV_ARG_DECL) throw (CORBA::SystemException)
void destroy (ACE_ENV_SINGLE_ARG_DECL) throw (CORBA::SystemException)
 This operation destroys the iterator.


Static Public Member Functions

int populate_binding (TABLE_ENTRY *hash_entry, CosNaming::Binding &b)

Private Attributes

int destroyed_
TAO_Hash_Naming_Contextcontext_
ITERATOR * hash_iter_
 A pointer to the hash map iterator.

TAO_SYNCH_RECURSIVE_MUTEXlock_
PortableServer::POA_var poa_
 Implement a different _default_POA().


Detailed Description

template<class ITERATOR, class TABLE_ENTRY>
class TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >

This class implements the interface that is part of the idl module. This class works with Hash_Map-based implementations of CosNaming::NamingContext.

This class is templatized by the types of the underlying hash table iterator and hash table entry, so that it can be used for both TAO_Transient_Naming_Context and TAO_Persistent_Naming_Context (and any other classes with underlying data structures supporting ACE_Hash_Map_Manager/Iterator - like interfaces).

Instances of s affect reference counts of corresponding Naming Contexts. Reference count on a Naming Context is incremented by one for a lifetime of each instance of created for that context, i.e., a Naming Context cannot be cleaned up (but, of course, it can be invalidated) before all of its iterators have been cleaned up. When method is invoked on a Naming Context, all of its iterators are destroyed in a "lazy evaluation" fashion, i.e., whenever a next operation is invoked on an iterator, and it can detect that the corresponding Naming Context has been invalidated, the iterator is destroyed.

Definition at line 51 of file Bindings_Iterator_T.h.


Constructor & Destructor Documentation

template<class ITERATOR, class TABLE_ENTRY>
TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::TAO_Bindings_Iterator TAO_Hash_Naming_Context context,
ITERATOR *  hash_iter,
PortableServer::POA_ptr  poa,
TAO_SYNCH_RECURSIVE_MUTEX lock
 

Constructor expects a pointer to a dynamically allocated hash map iterator (destructor deallocates hash map iterator).

Definition at line 15 of file Bindings_Iterator_T.cpp.

00020   : destroyed_ (0),
00021     context_ (context),
00022     hash_iter_ (hash_iter),
00023     lock_ (lock),
00024     poa_ (PortableServer::POA::_duplicate (poa))
00025 
00026 {
00027 }

template<class ITERATOR, class TABLE_ENTRY>
TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::~TAO_Bindings_Iterator void   ) 
 

Destructor.

Definition at line 30 of file Bindings_Iterator_T.cpp.

References ACE_DECLARE_NEW_CORBA_ENV, ACE_ENV_SINGLE_ARG_PARAMETER, TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::hash_iter_, and TAO_Hash_Naming_Context::interface().

00031 {
00032   ACE_DECLARE_NEW_CORBA_ENV;
00033   delete hash_iter_;
00034 
00035   // Since we are going away, decrement the reference count on the
00036   // Naming Context we were iterating over.
00037   context_->interface ()->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER);
00038 }


Member Function Documentation

template<class ITERATOR, class TABLE_ENTRY>
PortableServer::POA_ptr TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::_default_POA ACE_ENV_SINGLE_ARG_DECL   )  [virtual]
 

Returns the Default POA of this Servant object.

Definition at line 42 of file Bindings_Iterator_T.cpp.

00044 {
00045   return PortableServer::POA::_duplicate (this->poa_.in ());
00046 }

template<class ITERATOR, class TABLE_ENTRY>
void TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::destroy ACE_ENV_SINGLE_ARG_DECL   )  throw (CORBA::SystemException)
 

This operation destroys the iterator.

Definition at line 176 of file Bindings_Iterator_T.cpp.

References ACE_CHECK, ACE_ENV_ARG_PARAMETER, ACE_GUARD_THROW_EX, ACE_THROW, and TAO_SYNCH_RECURSIVE_MUTEX.

00178 {
00179   ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX,
00180                       ace_mon,
00181                       this->lock_,
00182                       CORBA::INTERNAL ());
00183   ACE_CHECK;
00184 
00185   // Check to make sure this object is still valid.
00186   if (this->destroyed_)
00187     ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
00188 
00189   // Mark the object invalid.
00190   this->destroyed_ = 1;
00191 
00192   PortableServer::ObjectId_var id =
00193     poa_->servant_to_id (this
00194                          ACE_ENV_ARG_PARAMETER);
00195   ACE_CHECK;
00196 
00197   poa_->deactivate_object (id.in ()
00198                            ACE_ENV_ARG_PARAMETER);
00199   ACE_CHECK;
00200 }

template<class ITERATOR, class TABLE_ENTRY>
CORBA::Boolean TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::next_n CORBA::ULong  how_many,
CosNaming::BindingList_out bl  ACE_ENV_ARG_DECL
throw (CORBA::SystemException)
 

This operation passes back at most unseen bindings. True is returned if bindings were passed back, and false is returned if no bindings were passed back.

Definition at line 107 of file Bindings_Iterator_T.cpp.

References ACE_CHECK_RETURN, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_GUARD_THROW_EX, ACE_NEW_THROW_EX, ACE_THROW_RETURN, CosNaming::BindingList, and TAO_SYNCH_RECURSIVE_MUTEX.

00112 {
00113   // We perform an allocation before obtaining the lock so that an out
00114   // parameter is allocated in case we fail to obtain the lock.
00115   ACE_NEW_THROW_EX (bl,
00116                     CosNaming::BindingList (0),
00117                     CORBA::NO_MEMORY ());
00118   ACE_CHECK_RETURN (0);
00119   // Obtain the lock.
00120   ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX,
00121                       ace_mon,
00122                       this->lock_,
00123                       CORBA::INTERNAL ());
00124   ACE_CHECK_RETURN (0);
00125 
00126   // Check to make sure this object is still valid.
00127   if (this->destroyed_)
00128     ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (), 0);
00129 
00130   // If the context we are iterating over has been destroyed,
00131   // self-destruct.
00132   if (context_->destroyed ())
00133     {
00134       destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00135       ACE_CHECK_RETURN (0);
00136 
00137       ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (), 0);
00138     }
00139 
00140   // Check for illegal parameter values.
00141   if (how_many == 0)
00142     ACE_THROW_RETURN (CORBA::BAD_PARAM (), 0);
00143 
00144   // If there are no more bindings...
00145   if (hash_iter_->done ())
00146       return 0;
00147   else
00148     {
00149       // Initially assume that the iterator has the requested number of
00150       // bindings.
00151       bl->length (how_many);
00152 
00153       TABLE_ENTRY *hash_entry = 0;
00154 
00155       // Iterate and populate the BindingList.
00156       for (CORBA::ULong i = 0; i < how_many; i++)
00157         {
00158           hash_iter_->next (hash_entry);
00159 
00160           if (populate_binding (hash_entry, bl[i]) == 0)
00161             ACE_THROW_RETURN (CORBA::NO_MEMORY (), 0);
00162 
00163           if (hash_iter_->advance () == 0)
00164             {
00165               // If no more bindings are left, reset length to the actual
00166               // number of bindings populated, and get out of the loop.
00167               bl->length (i + 1);
00168               break;
00169             }
00170         }
00171       return 1;
00172     }
00173 }

template<class ITERATOR, class TABLE_ENTRY>
CORBA::Boolean TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::next_one CosNaming::Binding_out b  ACE_ENV_ARG_DECL  )  throw (CORBA::SystemException)
 

This operation passes back the next unseen binding. True is returned if a binding is passed back, and false is returned otherwise.

Definition at line 49 of file Bindings_Iterator_T.cpp.

References ACE_CHECK_RETURN, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_GUARD_THROW_EX, ACE_NEW_THROW_EX, ACE_THROW_RETURN, and TAO_SYNCH_RECURSIVE_MUTEX.

00053 {
00054   CosNaming::Binding *binding;
00055 
00056   // Allocate a binding to be returned (even if there no more
00057   // bindings, we need to allocate an out parameter.)
00058   ACE_NEW_THROW_EX (binding,
00059                     CosNaming::Binding,
00060                     CORBA::NO_MEMORY ());
00061   ACE_CHECK_RETURN (0);
00062 
00063   b = binding;
00064 
00065   ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX,
00066                       ace_mon,
00067                       this->lock_,
00068                       CORBA::INTERNAL ());
00069   ACE_CHECK_RETURN (0);
00070 
00071   // Check to make sure this object is still valid.
00072   if (this->destroyed_)
00073     ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (), 0);
00074 
00075   // If the context we are iterating over has been destroyed,
00076   // self-destruct.
00077   if (context_->destroyed ())
00078     {
00079       destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00080       ACE_CHECK_RETURN (0);
00081 
00082       ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (), 0);
00083     }
00084 
00085   // If there are no more bindings.
00086   if (hash_iter_->done ())
00087     {
00088       b->binding_type = CosNaming::nobject;
00089       b->binding_name.length (0);
00090       return 0;
00091     }
00092   else
00093     {
00094       // Return a binding.
00095       TABLE_ENTRY *hash_entry = 0;
00096       hash_iter_->next (hash_entry);
00097 
00098       if (populate_binding (hash_entry, *binding) == 0)
00099         ACE_THROW_RETURN (CORBA::NO_MEMORY (), 0);
00100 
00101       hash_iter_->advance ();
00102       return 1;
00103     }
00104 }

template<class ITERATOR, class TABLE_ENTRY>
int TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::populate_binding TABLE_ENTRY *  hash_entry,
CosNaming::Binding b
[static]
 

Helper function used by TAO_*_Naming_Context and TAO_BindingIterator: populate a binding with info contained in . Return 1 if everything went smoothly, 0 if an allocation failed.

Definition at line 203 of file Bindings_Iterator_T.cpp.

References CosNaming::Binding::binding_name, and CosNaming::Binding::binding_type.

00206 {
00207   b.binding_type = hash_entry->int_id_.type_;
00208   b.binding_name.length (1);
00209 
00210   // Here we perform a check before assignment to make sure
00211   // CORBA::string_dup is not called on 0 pointer, since the spec does
00212   // not say what should happen in that case.
00213   if (hash_entry->ext_id_.id () != 0)
00214     {
00215       b.binding_name[0].id =
00216         hash_entry->ext_id_.id ();
00217       if (b.binding_name[0].id.in () == 0)
00218         return 0;
00219     }
00220   if (hash_entry->ext_id_.kind () != 0)
00221     {
00222       b.binding_name[0].kind =
00223         hash_entry->ext_id_.kind ();
00224       if (b.binding_name[0].kind.in () == 0)
00225         return 0;
00226     }
00227   return 1;
00228 }


Member Data Documentation

template<class ITERATOR, class TABLE_ENTRY>
TAO_Hash_Naming_Context* TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::context_ [private]
 

Pointer to the Naming Context we are iterating over. We need this pointer to make sure the context is still valid before each iteration, and to decrement its reference count once we are .

Definition at line 121 of file Bindings_Iterator_T.h.

template<class ITERATOR, class TABLE_ENTRY>
int TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::destroyed_ [private]
 

Flag indicating whether this iterator is still valid. (The iterator becomes invalid when method has been invoked on it, or when method has been invoked on the corresponding Naming Context.) This flag is necessary because immediate destruction of this servant might not be possible due to pending requests in the POA.

Definition at line 114 of file Bindings_Iterator_T.h.

template<class ITERATOR, class TABLE_ENTRY>
ITERATOR* TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::hash_iter_ [private]
 

A pointer to the hash map iterator.

Definition at line 124 of file Bindings_Iterator_T.h.

Referenced by TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::~TAO_Bindings_Iterator().

template<class ITERATOR, class TABLE_ENTRY>
TAO_SYNCH_RECURSIVE_MUTEX& TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::lock_ [private]
 

Lock passed on from Naming Context to serialize access to the internal data structure.

Definition at line 128 of file Bindings_Iterator_T.h.

template<class ITERATOR, class TABLE_ENTRY>
PortableServer::POA_var TAO_Bindings_Iterator< ITERATOR, TABLE_ENTRY >::poa_ [private]
 

Implement a different _default_POA().

Definition at line 131 of file Bindings_Iterator_T.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 13:57:35 2006 for TAO_CosNaming by doxygen 1.3.6