summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-02 23:49:13 +0000
committerbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-02 23:49:13 +0000
commit36e939192579ebf9732e5cc4c7f8e19367d05364 (patch)
tree0255dbedb554345182b2621c9e40f1dd639984ea
parentc119b0fbd0349f3a557bb9e4330233cf58557331 (diff)
downloadATCD-36e939192579ebf9732e5cc4c7f8e19367d05364.tar.gz
More Iterator changes
-rw-r--r--TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.cpp109
-rw-r--r--TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.h39
-rw-r--r--TAO/orbsvcs/ImplRepo_Service/Repository.cpp22
-rw-r--r--TAO/orbsvcs/ImplRepo_Service/Repository.h6
4 files changed, 157 insertions, 19 deletions
diff --git a/TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.cpp b/TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.cpp
index 50219ceebdc..05255e6ffca 100644
--- a/TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.cpp
+++ b/TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.cpp
@@ -489,29 +489,29 @@ ImplRepo_i::list (CORBA::ULong how_many,
CORBA::NO_MEMORY (CORBA::COMPLETED_NO));
ACE_CHECK;
- // Dynamically allocate the iterator.
-
- Server_Repository::HASH_IR_ITER *hash_iter = 0;
+ // Get a new iterator
+ Server_Repository::HASH_IR_ITER *hash_iter = this->repository_.new_iterator ();
+
+ // Check for a memory error.
+ if (hash_iter == 0)
+ {
+ ACE_THROW (CORBA::NO_MEMORY (CORBA::COMPLETED_NO));
+ ACE_CHECK;
+ }
+
+ // Number of servers that will go into the server_list.
+ CORBA::ULong n;
- ACE_NEW_THROW_EX (hash_iter,
- Server_Repository::HASH_IR_ITER (this->repository_),
- CORBA::NO_MEMORY (CORBA::COMPLETED_NO));
- ACE_CHECK;
+ if (this->repository_.get_repository_size () > how_many)
+ n = how_many;
+ else
+ n = this->repository_.get_repository_size ();
- // Number of bindings that will go into the BindingList.
- CORBA::ULong n;
-
// A pointer to BindingIterator servant.
TAO_Hash_Binding_Iterator *bind_iter = 0;
- // Calculate number of bindings that will go into bl.
- if (this->context_.current_size () > how_many)
- n = how_many;
- else
- n = this->context_.current_size ();
-
// Use hash iterator to populate a BindingList with bindings.
bl->length (n);
@@ -750,3 +750,80 @@ IR_Forwarder::invoke (CORBA::ServerRequest_ptr /* request */,
ACE_ERROR ((LM_ERROR,
"Error: Forward_to reference is nil.\n"));
}
+
+
+// Plain old constructor
+
+IR_Iterator::IR_Iterator (Server_Repository::HASH_IR_ITER *iterator,
+ PortableServer::POA_ptr poa)
+ : iterator_ (iterator),
+ poa_ (poa)
+{
+ // Nothing
+}
+
+
+// Destructor
+
+IR_Iterator::~IR_Iterator ()
+{
+ delete iterator_;
+}
+
+
+// Returns the next list of up to <how_many> servers. If empty, will return
+// false.
+
+CORBA::Boolean
+IR_Iterator::next_n (CORBA::ULong how_many,
+ ImplementationRepository::ServerInformationList_out server_list,
+ CORBA::Environment &ACE_TRY_ENV)
+{
+ // We perform an allocation before obtaining the lock so that an out
+ // parameter is allocated in case we fail to obtain the lock.
+ ACE_NEW_THROW_EX (bl,
+ CosNaming::BindingList (0),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO));
+ ACE_CHECK_RETURN (0);
+ // Obtain a lock.
+ ACE_GUARD_THROW_EX (ACE_Lock,
+ ace_mon,
+ *this->lock_,
+ CORBA::INTERNAL (CORBA::COMPLETED_NO));
+ ACE_CHECK_RETURN (0);
+
+ // If there are no more bindings...
+ if (hash_iter_->done ())
+ return 0;
+ else
+ {
+ // Initially assume that iterator has the requested number of
+ // bindings.
+ bl->length (how_many);
+
+ TAO_Hash_Naming_Context::HASH_MAP::ENTRY *hash_entry;
+
+ // Iterate and populate the BindingList.
+
+ for (CORBA::ULong i = 0; i < how_many; i++)
+ {
+ hash_iter_->next (hash_entry);
+
+ if (TAO_Hash_Naming_Context::populate_binding (hash_entry, bl[i]) == 0)
+ ACE_THROW_RETURN (CORBA::NO_MEMORY (CORBA::COMPLETED_NO), 0);
+
+ if (hash_iter_->advance () == 0)
+ {
+ // If no more bindings left, reset length to the actual
+ // number of bindings populated and get out of the loop.
+ bl->length (i + 1);
+ break;
+ }
+ }
+ return 1;
+ }
+}
+
+void IR_Iterator::destroy (CORBA::Environment &ACE_TRY_ENV = CORBA::Environment::default_environment ());
+ // Destroys the iterator.
+
diff --git a/TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.h b/TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.h
index 53857843dce..ebfb5e0ed26 100644
--- a/TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.h
+++ b/TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.h
@@ -63,8 +63,7 @@ class ImplRepo_i : public POA_ImplementationRepository::Administration
// Implementation Repository
//
// = DESCRIPTION
- // This provides the interface to communicate directly with the
- // Implementation Repository.
+ // This provides the interface to Administer the Implementation Repository.
public:
// = Constructor and destructor
ImplRepo_i (void);
@@ -156,7 +155,13 @@ private:
// The command line arguments.
};
-class IR_Forwarder: public PortableServer::DynamicImplementation
+class IR_Forwarder: public PortableServer::DynamicImplementation
+ // = TITLE
+ // Implementation Repository Forwarder
+ //
+ // = DESCRIPTION
+ // This class is provides a DSI implementation that is used to handle
+ // arbitrary calls and forward them to the correct place.
{
public:
IR_Forwarder (CORBA::ORB_ptr orb_ptr,
@@ -186,4 +191,32 @@ private:
// POA reference.
};
+class IR_Iterator : public POA_ImplementationRepository::ServerInformationIterator
+{
+public:
+ IR_Iterator (Server_Repository::HASH_IR_ITER *iterator,
+ PortableServer::POA_ptr poa);
+ // Constructor
+ // Ownership of iterator is transfered to this class (we'll delete it)
+
+ ~IR_Iterator ();
+ // Destructor
+
+ virtual CORBA::Boolean next_n (CORBA::ULong how_many,
+ ImplementationRepository::ServerInformationList_out server_list,
+ CORBA::Environment &ACE_TRY_ENV = CORBA::Environment::default_environment ());
+ // Returns the next list of up to <how_many> servers. If empty, will return
+ // false.
+
+ virtual void destroy (CORBA::Environment &ACE_TRY_ENV = CORBA::Environment::default_environment ());
+ // Destroys the iterator.
+
+private:
+ Server_Repository::HASH_IR_ITER *iterator_;
+ // Our very own iterator for transversing the server repository.
+
+ PortableServer::POA_var poa_;
+ // Our lovely POA.
+};
+
#endif /* IMPLREPO_I_H */
diff --git a/TAO/orbsvcs/ImplRepo_Service/Repository.cpp b/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
index d85e2e0fa7e..a184a34017e 100644
--- a/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
+++ b/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
@@ -197,6 +197,28 @@ Server_Repository::remove (const ACE_TString POA_name)
{
return this->repository_.unbind (POA_name);
}
+
+
+// Returns a new iterator that travels over the repository.
+
+HASH_IR_ITER *
+Server_Repository::new_iterator ()
+{
+ HASH_IR_ITER *hash_iter;
+ ACE_NEW_RETURN (hash_iter,
+ Server_Repository::HASH_IR_ITER (this->repository_),
+ 0);
+ return hash_iter;
+}
+
+
+// Returns the number of entries in the repository.
+
+size_t
+get_repository_size ()
+{
+ return this->repository_.current_size ();
+}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
diff --git a/TAO/orbsvcs/ImplRepo_Service/Repository.h b/TAO/orbsvcs/ImplRepo_Service/Repository.h
index f4b499be13e..be6b2a08abf 100644
--- a/TAO/orbsvcs/ImplRepo_Service/Repository.h
+++ b/TAO/orbsvcs/ImplRepo_Service/Repository.h
@@ -161,6 +161,12 @@ public:
int remove (const ACE_TString POA_name);
// Removes the server from the Repository.
+ HASH_IR_ITER *new_iterator ();
+ // Returns a new iterator that travels over the repository.
+
+ size_t get_repository_size ();
+ // Returns the number of entries in the repository.
+
private:
HASH_IR_MAP repository_;
};