00001
00002
00003 #ifndef TAO_BINDINGS_ITERATOR_T_CPP
00004 #define TAO_BINDINGS_ITERATOR_T_CPP
00005
00006 #include "orbsvcs/Naming/Bindings_Iterator_T.h"
00007
00008 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00009 # pragma once
00010 #endif
00011
00012 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00013
00014 template <class ITERATOR, class TABLE_ENTRY>
00015 TAO_Bindings_Iterator<ITERATOR, TABLE_ENTRY>::TAO_Bindings_Iterator (
00016 TAO_Hash_Naming_Context *context,
00017 ITERATOR *hash_iter,
00018 PortableServer::POA_ptr poa,
00019 TAO_SYNCH_RECURSIVE_MUTEX &lock)
00020 : destroyed_ (0),
00021 context_ (context),
00022 hash_iter_ (hash_iter),
00023 lock_ (lock),
00024 poa_ (PortableServer::POA::_duplicate (poa))
00025
00026 {
00027 }
00028
00029 template <class ITERATOR, class TABLE_ENTRY>
00030 TAO_Bindings_Iterator<ITERATOR, TABLE_ENTRY>::~TAO_Bindings_Iterator (void)
00031 {
00032 ACE_DECLARE_NEW_CORBA_ENV;
00033 delete hash_iter_;
00034
00035
00036
00037 context_->interface ()->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER);
00038 }
00039
00040
00041 template <class ITERATOR, class TABLE_ENTRY> PortableServer::POA_ptr
00042 TAO_Bindings_Iterator<ITERATOR, TABLE_ENTRY>::_default_POA (
00043 ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00044 {
00045 return PortableServer::POA::_duplicate (this->poa_.in ());
00046 }
00047
00048 template <class ITERATOR, class TABLE_ENTRY> CORBA::Boolean
00049 TAO_Bindings_Iterator<ITERATOR, TABLE_ENTRY>::next_one (
00050 CosNaming::Binding_out b
00051 ACE_ENV_ARG_DECL)
00052 ACE_THROW_SPEC ((CORBA::SystemException))
00053 {
00054 CosNaming::Binding *binding;
00055
00056
00057
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
00072 if (this->destroyed_)
00073 ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (), 0);
00074
00075
00076
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
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
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 }
00105
00106 template <class ITERATOR, class TABLE_ENTRY> CORBA::Boolean
00107 TAO_Bindings_Iterator<ITERATOR, TABLE_ENTRY>::next_n (
00108 CORBA::ULong how_many,
00109 CosNaming::BindingList_out bl
00110 ACE_ENV_ARG_DECL)
00111 ACE_THROW_SPEC ((CORBA::SystemException))
00112 {
00113
00114
00115 ACE_NEW_THROW_EX (bl,
00116 CosNaming::BindingList (0),
00117 CORBA::NO_MEMORY ());
00118 ACE_CHECK_RETURN (0);
00119
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
00127 if (this->destroyed_)
00128 ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (), 0);
00129
00130
00131
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
00141 if (how_many == 0)
00142 ACE_THROW_RETURN (CORBA::BAD_PARAM (), 0);
00143
00144
00145 if (hash_iter_->done ())
00146 return 0;
00147 else
00148 {
00149
00150
00151 bl->length (how_many);
00152
00153 TABLE_ENTRY *hash_entry = 0;
00154
00155
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
00166
00167 bl->length (i + 1);
00168 break;
00169 }
00170 }
00171 return 1;
00172 }
00173 }
00174
00175 template <class ITERATOR, class TABLE_ENTRY> void
00176 TAO_Bindings_Iterator<ITERATOR, TABLE_ENTRY>::destroy (ACE_ENV_SINGLE_ARG_DECL)
00177 ACE_THROW_SPEC ((CORBA::SystemException))
00178 {
00179 ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX,
00180 ace_mon,
00181 this->lock_,
00182 CORBA::INTERNAL ());
00183 ACE_CHECK;
00184
00185
00186 if (this->destroyed_)
00187 ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
00188
00189
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 }
00201
00202 template <class ITERATOR, class TABLE_ENTRY> int
00203 TAO_Bindings_Iterator<ITERATOR, TABLE_ENTRY>::populate_binding (
00204 TABLE_ENTRY *hash_entry,
00205 CosNaming::Binding &b)
00206 {
00207 b.binding_type = hash_entry->int_id_.type_;
00208 b.binding_name.length (1);
00209
00210
00211
00212
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 }
00229
00230 TAO_END_VERSIONED_NAMESPACE_DECL
00231
00232 #endif