00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Bindings_Iterator_T.h 00006 * 00007 * $Id: Bindings_Iterator_T.h 77276 2007-02-21 08:26:36Z johnnyw $ 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 (void); 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 00078 /** 00079 * This operation passes back at most <how_many> unseen bindings. 00080 * True is returned if bindings were passed back, and false is 00081 * returned if no bindings were passed back. 00082 */ 00083 CORBA::Boolean next_n (CORBA::ULong how_many, 00084 CosNaming::BindingList_out bl); 00085 00086 /// This operation destroys the iterator. 00087 void destroy (void); 00088 00089 // = Helper method. 00090 00091 /** 00092 * Helper function used by TAO_*_Naming_Context and 00093 * TAO_BindingIterator: populate a binding <b> with info contained 00094 * in <hash_entry>. Return 1 if everything went smoothly, 0 if an 00095 * allocation failed. 00096 */ 00097 static int populate_binding (TABLE_ENTRY *hash_entry, CosNaming::Binding &b); 00098 00099 private: 00100 /** 00101 * Flag indicating whether this iterator is still valid. (The 00102 * iterator becomes invalid when <destroy> method has been invoked 00103 * on it, or when <destroy> method has been invoked on the 00104 * corresponding Naming Context.) This flag is necessary 00105 * because immediate destruction of this servant might not be possible 00106 * due to pending requests in the POA. 00107 */ 00108 bool destroyed_; 00109 00110 /** 00111 * Pointer to the Naming Context we are iterating over. We need 00112 * this pointer to make sure the context is still valid before 00113 * each iteration, and to decrement its reference count once we are <destroyed>. 00114 */ 00115 TAO_Hash_Naming_Context *context_; 00116 00117 /// A pointer to the hash map iterator. 00118 ITERATOR *hash_iter_; 00119 00120 /// Lock passed on from Naming Context to serialize access to the 00121 /// internal data structure. 00122 TAO_SYNCH_RECURSIVE_MUTEX &lock_; 00123 00124 /// Implement a different _default_POA(). 00125 PortableServer::POA_var poa_; 00126 }; 00127 00128 TAO_END_VERSIONED_NAMESPACE_DECL 00129 00130 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00131 #include "orbsvcs/Naming/Bindings_Iterator_T.cpp" 00132 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00133 00134 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00135 #pragma implementation ("Bindings_Iterator_T.cpp") 00136 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00137 00138 #include /**/ "ace/post.h" 00139 #endif /* TAO_BINDINGS_ITERATOR_T_H */