Bindings_Iterator_T.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   Bindings_Iterator_T.h
00006  *
00007  *  Bindings_Iterator_T.h,v 1.13 2006/03/14 06:14:33 jtc Exp
00008  *
00009  *  @author Marina Spivak <marina@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_BINDINGS_ITERATOR_T_H
00015 #define TAO_BINDINGS_ITERATOR_T_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "orbsvcs/Naming/Hash_Naming_Context.h"
00019 
00020 
00021 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00022 
00023 /**
00024  * @class TAO_Bindings_Iterator
00025  *
00026  * @brief This class implements the <BindingIterator> interface that is
00027  * part of the <CosNaming> idl module.   This class works with Hash_Map-based
00028  * implementations of CosNaming::NamingContext.
00029  *
00030  * This class is templatized by the types of the underlying
00031  * hash table iterator and hash table entry, so that it can be
00032  * used for both TAO_Transient_Naming_Context and
00033  * TAO_Persistent_Naming_Context (and any other classes with
00034  * underlying data structures supporting
00035  * ACE_Hash_Map_Manager/Iterator - like interfaces).
00036  *
00037  * Instances of <TAO_Bindings_Iterator>s affect reference counts
00038  * of corresponding Naming Contexts. Reference count on a
00039  * Naming Context is incremented by one for a lifetime of each
00040  * instance of <TAO_Bindings_Iterator> created for that
00041  * context, i.e., a Naming Context cannot
00042  * be cleaned up (but, of course, it can be invalidated) before
00043  * all of its iterators have been cleaned up.  When <destroy>
00044  * method is invoked on a Naming Context, all of its iterators are
00045  * destroyed in a "lazy evaluation" fashion, i.e., whenever a next
00046  * operation is invoked on an iterator, and it can detect that
00047  * the corresponding Naming Context has been invalidated, the
00048  * iterator is destroyed.
00049  */
00050 template <class ITERATOR, class TABLE_ENTRY>
00051 class TAO_Bindings_Iterator : public virtual POA_CosNaming::BindingIterator
00052 {
00053 public:
00054   // = Intialization and termination methods.
00055   /**
00056    * Constructor expects a pointer to a
00057    * dynamically allocated hash map iterator (destructor
00058    * deallocates hash map iterator).
00059    */
00060   TAO_Bindings_Iterator (TAO_Hash_Naming_Context *context,
00061                          ITERATOR *hash_iter,
00062                          PortableServer::POA_ptr poa,
00063                          TAO_SYNCH_RECURSIVE_MUTEX &lock);
00064 
00065 
00066   /// Destructor.
00067   ~TAO_Bindings_Iterator (void);
00068 
00069   /// Returns the Default POA of this Servant object
00070   virtual PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL);
00071 
00072   // = Idl methods.
00073 
00074   /// This operation passes back the next unseen binding.  True is
00075   /// returned if a binding is passed back, and false is returned otherwise.
00076   CORBA::Boolean next_one (CosNaming::Binding_out b
00077                            ACE_ENV_ARG_DECL)
00078     ACE_THROW_SPEC ((CORBA::SystemException));
00079 
00080   /**
00081    * This operation passes back at most <how_many> unseen bindings.
00082    * True is returned if bindings were passed back, and false is
00083    * returned if no bindings were passed back.
00084    */
00085   CORBA::Boolean next_n (CORBA::ULong how_many,
00086                          CosNaming::BindingList_out bl
00087                          ACE_ENV_ARG_DECL)
00088     ACE_THROW_SPEC ((CORBA::SystemException));
00089 
00090   /// This operation destroys the iterator.
00091   void destroy (ACE_ENV_SINGLE_ARG_DECL)
00092     ACE_THROW_SPEC ((CORBA::SystemException));
00093 
00094   // = Helper method.
00095 
00096   /**
00097    * Helper function used by TAO_*_Naming_Context and
00098    * TAO_BindingIterator: populate a binding <b> with info contained
00099    * in <hash_entry>.  Return 1 if everything went smoothly, 0 if an
00100    * allocation failed.
00101    */
00102   static int populate_binding (TABLE_ENTRY *hash_entry,
00103                                CosNaming::Binding &b);
00104 
00105 private:
00106   /**
00107    * Flag indicating whether this iterator is still valid.  (The
00108    * iterator becomes invalid when <destroy> method has been invoked
00109    * on it, or when <destroy> method has been invoked on the
00110    * corresponding Naming Context.) This flag is necessary
00111    * because immediate destruction of this servant might not be possible
00112    * due to pending requests in the POA.
00113    */
00114   int destroyed_;
00115 
00116   /**
00117    * Pointer to the Naming Context we are iterating over.  We need
00118    * this pointer to make sure the context is still valid before
00119    * each iteration, and to decrement its reference count once we are <destroyed>.
00120    */
00121   TAO_Hash_Naming_Context *context_;
00122 
00123   /// A pointer to the hash map iterator.
00124   ITERATOR *hash_iter_;
00125 
00126   /// Lock passed on from Naming Context to serialize access to the
00127   /// internal data structure.
00128   TAO_SYNCH_RECURSIVE_MUTEX &lock_;
00129 
00130   /// Implement a different _default_POA().
00131   PortableServer::POA_var poa_;
00132 };
00133 
00134 TAO_END_VERSIONED_NAMESPACE_DECL
00135 
00136 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00137 #include "orbsvcs/Naming/Bindings_Iterator_T.cpp"
00138 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00139 
00140 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00141 #pragma implementation ("Bindings_Iterator_T.cpp")
00142 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00143 
00144 #include /**/ "ace/post.h"
00145 #endif /* TAO_BINDINGS_ITERATOR_T_H */

Generated on Thu Nov 9 13:57:01 2006 for TAO_CosNaming by doxygen 1.3.6