summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Naming/Persistent_Naming_Context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/orbsvcs/orbsvcs/Naming/Persistent_Naming_Context.cpp')
-rw-r--r--TAO/orbsvcs/orbsvcs/Naming/Persistent_Naming_Context.cpp207
1 files changed, 77 insertions, 130 deletions
diff --git a/TAO/orbsvcs/orbsvcs/Naming/Persistent_Naming_Context.cpp b/TAO/orbsvcs/orbsvcs/Naming/Persistent_Naming_Context.cpp
index 6542dc39e89..1b9277dc1c6 100644
--- a/TAO/orbsvcs/orbsvcs/Naming/Persistent_Naming_Context.cpp
+++ b/TAO/orbsvcs/orbsvcs/Naming/Persistent_Naming_Context.cpp
@@ -73,7 +73,7 @@ TAO_Persistent_Bindings_Map::find (const char *id,
ACE_DECLARE_NEW_CORBA_ENV;
obj = orb_->string_to_object (entry.ref_, ACE_TRY_ENV);
ACE_CHECK_RETURN (-1);
- type = entry.type_;
+ type = entry.type ();
return 0;
}
@@ -93,20 +93,19 @@ TAO_Persistent_Bindings_Map::~TAO_Persistent_Bindings_Map (void)
void
TAO_Persistent_Bindings_Map::destroy (void)
{
- this->map_->ACE_Hash_Map_With_Allocator<TAO_Persistent_ExtId, TAO_Persistent_IntId>::~ACE_Hash_Map_With_Allocator ();
- this->allocator_->free (map_);
+ allocator_->free (map_);
}
TAO_Persistent_Bindings_Map::HASH_MAP *
TAO_Persistent_Bindings_Map::map (void)
{
- return this->map_;
+ return map_;
}
size_t
TAO_Persistent_Bindings_Map::total_size (void)
{
- return this->map_->total_size ();
+ return map_->total_size ();
}
size_t
@@ -125,25 +124,13 @@ TAO_Persistent_Bindings_Map::open (size_t hash_table_size,
void *hash_map = 0;
size_t map_size = sizeof (HASH_MAP);
hash_map = this->allocator_->malloc (map_size);
-
- // If allocation failed ...
- if (hash_map == 0)
- return -1;
+ //@@ check if hash_map == 0 ??
// Initialize allocated hash map through placement new.
- if (open_helper (hash_table_size, hash_map) == -1)
- this->allocator_->free (hash_map);
-
- return 0;
-}
-
-int
-TAO_Persistent_Bindings_Map::open_helper (size_t hash_table_size,
- void *buffer)
-{
ACE_NEW_RETURN (this->map_,
- (buffer) HASH_MAP (hash_table_size, this->allocator_),
+ (hash_map) HASH_MAP (hash_table_size, this->allocator_),
-1);
+
return 0;
}
@@ -162,7 +149,7 @@ TAO_Persistent_Bindings_Map::shared_bind (const char * id,
CosNaming::BindingType type,
int rebind)
{
- // Obtain a stringified ior of <obj> (i.e., the representation we can store).
+ // Obtain a stringified ior ob <obj> (i.e., the representation we can store).
ACE_DECLARE_NEW_CORBA_ENV;
CORBA::String_var ref = orb_->object_to_string (obj, ACE_TRY_ENV);
ACE_CHECK_RETURN (-1);
@@ -211,40 +198,29 @@ TAO_Persistent_Bindings_Map::shared_bind (const char * id,
}
}
else
- // Rebind.
{
+ // Do a rebind. If there's already any entry, this will return the existing
+ // <new_name> and <new_internal> and overwrite the existing name binding.
TAO_Persistent_ExtId old_name;
TAO_Persistent_IntId old_entry;
- // Check that the types of old and new entries match.
- if (this->map_->find (new_name,
- old_entry,
- this->allocator_) == 0
- && type != old_entry.type_)
- result = -2;
-
- // If types match, perform rebind.
- else
- result = this->map_->rebind (new_name, new_entry,
- old_name, old_entry,
- this->allocator_);
+ result = this->map_->rebind (new_name, new_entry,
+ old_name, old_entry,
+ this->allocator_);
if (result == 1)
{
- // Free up the old binding's memory, if it was replaced.
- // Note, this assumes that the "ref" pointer comes
- // first, and that the id, kind, and ref are contiguously
- // allocated (see beginning of this method for details).
+ // Free up the memory we allocated in shared_bind(). Note that this
+ // assumes that the "ref" pointer comes first and that the id,
+ // kind, and ref are contiguously allocated (see above for details)
this->allocator_->free ((void *) old_entry.ref_);
}
}
- // Check for failures, and clean up dynamically allocated memory
- // if necessary.
- if (result < 0)
+ if (result == -1)
+ // Free our dynamically allocated memory.
this->allocator_->free ((void *) ptr);
-
else
- // If bind() or rebind() succeeded, they will automatically sync
+ // If bind() or rebind() succeed, they will automatically sync
// up the map manager entry. However, we must sync up our
// name/value memory.
this->allocator_->sync (ptr, total_len);
@@ -298,43 +274,50 @@ TAO_Persistent_Naming_Context::init (size_t hash_table_size)
TAO_Persistent_Naming_Context::~TAO_Persistent_Naming_Context (void)
{
- // Perform appropriate cleanup based on the destruction level specified.
-
- if (this->destroyed_ > 1)
+ // This should only get called if we are destroyed, i.e., we don't
+ // want persistent state.
+ if (this->destroyed_)
{
// Remove ourselves from context index.
index_->unbind (poa_id_.c_str ());
// Remove the underlying data structure from persistent storage.
persistent_context_->destroy ();
}
- else if (this->destroyed_ == 1)
- // Remove the underlying data structure from persistent storage.
- persistent_context_->destroy ();
-}
-
-void
-TAO_Persistent_Naming_Context::set_cleanup_level (int level)
-{
- this->destroyed_ = level;
}
+//@@This method may need adjustments to deal with errors correctly.
CosNaming::NamingContext_ptr
-TAO_Persistent_Naming_Context::make_new_context (PortableServer::POA_ptr poa,
- const char *poa_id,
- size_t context_size,
- TAO_Persistent_Context_Index * ind,
- CORBA::Environment &ACE_TRY_ENV)
+TAO_Persistent_Naming_Context::new_context (CORBA::Environment &ACE_TRY_ENV)
{
- // Store the stub we will return here.
+ ACE_GUARD_THROW_EX (ACE_SYNCH_RECURSIVE_MUTEX,
+ ace_mon,
+ this->lock_,
+ CORBA::INTERNAL ());
+ ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
+
+ // Check to make sure this object didn't have <destroy> method
+ // invoked on it.
+ if (this->destroyed_)
+ ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
+ CosNaming::NamingContext::_nil ());
+
+ // Store the stub we will return from the method here.
CosNaming::NamingContext_var result;
+ // Generate a POA id for the new context.
+ char poa_id[BUFSIZ];
+ ACE_OS::sprintf (poa_id,
+ "%s_%ld",
+ this->poa_id_.c_str (),
+ (*this->counter_)++);
+
// Put together a servant for the new Naming Context.
TAO_Persistent_Naming_Context *context_impl = 0;
ACE_NEW_THROW_EX (context_impl,
- TAO_Persistent_Naming_Context (poa,
+ TAO_Persistent_Naming_Context (poa_.in (),
poa_id,
- ind),
+ index_),
CORBA::NO_MEMORY ());
ACE_CHECK_RETURN (result._retn ());
@@ -342,20 +325,15 @@ TAO_Persistent_Naming_Context::make_new_context (PortableServer::POA_ptr poa,
// allocation fails.
ACE_Auto_Basic_Ptr<TAO_Persistent_Naming_Context> temp (context_impl);
- if (context_impl->init (context_size) == -1)
+ if (context_impl->init (persistent_context_->total_size ()) == -1)
ACE_THROW_RETURN (CORBA::NO_MEMORY (), result._retn ());
- // Insure appropriate cleanup in case of exception conditions ahead.
- context_impl->set_cleanup_level (1);
-
// Register with the index of Naming Contexts.
- if (ind->bind (context_impl->poa_id_.c_str (),
- context_impl->counter_,
- context_impl->persistent_context_->map ()) == -1)
+ if (index_->bind (context_impl->poa_id_.c_str (),
+ context_impl->counter_,
+ context_impl->persistent_context_->map ()) == -1)
ACE_THROW_RETURN (CORBA::INTERNAL (), result._retn ());
-
- // Insure appropriate cleanup in case of exception conditions ahead.
- context_impl->set_cleanup_level (2);
+ //@@ At this point destroy_ flag should be enabled to avoid mem. leaks?
TAO_Naming_Context *context = 0;
ACE_NEW_THROW_EX (context,
@@ -363,62 +341,28 @@ TAO_Persistent_Naming_Context::make_new_context (PortableServer::POA_ptr poa,
CORBA::NO_MEMORY ());
ACE_CHECK_RETURN (result._retn ());
- // Let <implementation> know about it's <interface>.
- context_impl->interface (context);
-
- // Release auto pointer, and start using reference counting to
- // control our servant.
+ // Change what we hold in auto pointer.
temp.release ();
- PortableServer::ServantBase_var s = context;
+ ACE_Auto_Basic_Ptr<TAO_Naming_Context> temp2 (context);
// Register the new context with the POA.
PortableServer::ObjectId_var id =
PortableServer::string_to_ObjectId (poa_id);
- poa->activate_object_with_id (id.in (),
- context,
- ACE_TRY_ENV);
+ this->poa_->activate_object_with_id (id.in (),
+ context,
+ ACE_TRY_ENV);
ACE_CHECK_RETURN (result._retn ());
result = context->_this (ACE_TRY_ENV);
ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
- // Everything went smoothly, without errors - we don't need any cleanup.
- context_impl->set_cleanup_level (0);
-
- return result._retn ();
-}
-
-CosNaming::NamingContext_ptr
-TAO_Persistent_Naming_Context::new_context (CORBA::Environment &ACE_TRY_ENV)
-{
- ACE_GUARD_THROW_EX (ACE_SYNCH_RECURSIVE_MUTEX,
- ace_mon,
- this->lock_,
- CORBA::INTERNAL ());
- ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
-
- // Check to make sure this object didn't have <destroy> method
- // invoked on it.
- if (this->destroyed_)
- ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
- CosNaming::NamingContext::_nil ());
-
- // Generate a POA id for the new context.
- char poa_id[BUFSIZ];
- ACE_OS::sprintf (poa_id,
- "%s_%ld",
- this->poa_id_.c_str (),
- (*this->counter_)++);
-
- CosNaming::NamingContext_var result =
- make_new_context (this->poa_.in (),
- poa_id,
- this->persistent_context_->total_size (),
- this->index_,
- ACE_TRY_ENV);
+ // Give POA the ownership of this servant.
+ context->_remove_ref (ACE_TRY_ENV);
ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
+ // Everything went without errors: release auto pointer and return.
+ temp2.release ();
return result._retn ();
}
@@ -462,8 +406,8 @@ TAO_Persistent_Naming_Context::list (CORBA::ULong how_many,
// Silliness below is required because of broken old g++!!! E.g.,
// without it, we could have just said HASH_MAP::ITERATOR everywhere we use ITER_DEF.
- typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_ExtId, TAO_Persistent_IntId>::ITERATOR ITER_DEF;
- typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_ExtId, TAO_Persistent_IntId>::ENTRY ENTRY_DEF;
+ typedef ACE_Shared_Hash_Map<TAO_Persistent_ExtId, TAO_Persistent_IntId>::ITERATOR ITER_DEF;
+ typedef ACE_Shared_Hash_Map<TAO_Persistent_ExtId, TAO_Persistent_IntId>::ENTRY ENTRY_DEF;
// Typedef to the type of BindingIterator servant for ease of use.
typedef TAO_Bindings_Iterator<ITER_DEF, ENTRY_DEF> ITER_SERVANT;
@@ -504,18 +448,13 @@ TAO_Persistent_Naming_Context::list (CORBA::ULong how_many,
{
// Create a BindingIterator for return.
ACE_NEW_THROW_EX (bind_iter,
- ITER_SERVANT (this, hash_iter, this->poa_.in (), this->lock_),
+ ITER_SERVANT (hash_iter, this->poa_.in (), this->lock_),
CORBA::NO_MEMORY ());
- // Release <hash_iter> from auto pointer, and start using the
- // reference counting to control our servant.
+ // Release <hash_iter> from auto pointer and put <bind_iter> into
+ // one.
temp.release ();
- PortableServer::ServantBase_var iter = bind_iter;
-
- // Increment reference count on this Naming Context, so it doesn't get
- // deleted before the BindingIterator servant gets deleted.
- interface_->_add_ref (ACE_TRY_ENV);
- ACE_CHECK;
+ ACE_Auto_Basic_Ptr<ITER_SERVANT> temp2 (bind_iter);
// Register with the POA.
char poa_id[BUFSIZ];
@@ -533,11 +472,20 @@ TAO_Persistent_Naming_Context::list (CORBA::ULong how_many,
bi = bind_iter->_this (ACE_TRY_ENV);
ACE_CHECK;
+
+ // Give POA the ownership of this servant.
+ bind_iter->_remove_ref (ACE_TRY_ENV);
+ ACE_CHECK;
+
+ // Everything went without error, release the auto pointer.
+ temp2.release ();
}
}
+//@@ Need instantiation for TAO_Bindings_Iterator.
+
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
-template class ACE_Hash_Map_With_Allocator<TAO_Persistent_ExtId, TAO_Persistent_IntId>;
+template class ACE_Shared_Hash_Map<TAO_Persistent_ExtId, TAO_Persistent_IntId>;
template class ACE_Hash_Map_Manager<TAO_Persistent_ExtId, TAO_Persistent_IntId, ACE_Null_Mutex>;
template class ACE_Hash_Map_Manager_Ex<TAO_Persistent_ExtId, TAO_Persistent_IntId, ACE_Hash<TAO_Persistent_ExtId>, ACE_Equal_To<TAO_Persistent_ExtId>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Entry<TAO_Persistent_ExtId, TAO_Persistent_IntId>;
@@ -552,10 +500,9 @@ template class ACE_Auto_Basic_Ptr<TAO_Persistent_Naming_Context>;
template class ACE_Auto_Basic_Ptr<ACE_Hash_Map_Iterator_Ex<TAO_Persistent_ExtId, TAO_Persistent_IntId, ACE_Hash<TAO_Persistent_ExtId>, ACE_Equal_To<TAO_Persistent_ExtId>, ACE_Null_Mutex > >;
template class TAO_Bindings_Iterator<ACE_Hash_Map_Iterator_Ex<TAO_Persistent_ExtId, TAO_Persistent_IntId, ACE_Hash<TAO_Persistent_ExtId>, ACE_Equal_To<TAO_Persistent_ExtId>, ACE_Null_Mutex>, ACE_Hash_Map_Entry<TAO_Persistent_ExtId, TAO_Persistent_IntId> >;
template class ACE_Auto_Basic_Ptr<TAO_Bindings_Iterator<ACE_Hash_Map_Iterator_Ex<TAO_Persistent_ExtId, TAO_Persistent_IntId, ACE_Hash<TAO_Persistent_ExtId>, ACE_Equal_To<TAO_Persistent_ExtId>, ACE_Null_Mutex>, ACE_Hash_Map_Entry<TAO_Persistent_ExtId, TAO_Persistent_IntId> > >;
-
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
-#pragma instantiate ACE_Hash_Map_With_Allocator<TAO_Persistent_ExtId, TAO_Persistent_IntId>
+#pragma instantiate ACE_Shared_Hash_Map<TAO_Persistent_ExtId, TAO_Persistent_IntId>
#pragma instantiate ACE_Hash_Map_Manager<TAO_Persistent_ExtId, TAO_Persistent_IntId, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Manager_Ex<TAO_Persistent_ExtId, TAO_Persistent_IntId, ACE_Hash<TAO_Persistent_ExtId>, ACE_Equal_To<TAO_Persistent_ExtId>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Entry<TAO_Persistent_ExtId, TAO_Persistent_IntId>