📄 hash_naming_context.cpp
字号:
// Hash_Naming_Context.cpp,v 1.25 2003/11/18 14:55:09 smcqueen Exp
// ============================================================================
//
// = LIBRARY
// TAO_CosNaming
//
// = FILENAME
// Hash_Naming_Context.cpp
//
// = AUTHOR
// Marina Spivak <marina@cs.wustl.edu> and
// Sergio Flores-Gaitan <sergio@cs.wustl.edu>
//
// ============================================================================
#include "Hash_Naming_Context.h"
#include "nsconf.h"
#include "ace/Auto_Ptr.h"
ACE_RCSID (Naming,
Hash_Naming_Context,
"Hash_Naming_Context.cpp,v 1.25 2003/11/18 14:55:09 smcqueen Exp")
// -------------------------------------------------
TAO_Bindings_Map::~TAO_Bindings_Map (void)
{
}
// -------------------------------------------------
TAO_Hash_Naming_Context::TAO_Hash_Naming_Context (PortableServer::POA_ptr poa,
const char *poa_id)
: context_ (0),
interface_ (0),
destroyed_ (0),
poa_ (PortableServer::POA::_duplicate (poa)),
poa_id_ (poa_id)
{
}
void
TAO_Hash_Naming_Context::interface (TAO_Naming_Context *i)
{
this->interface_ = i;
}
TAO_Hash_Naming_Context::~TAO_Hash_Naming_Context (void)
{
delete context_;
}
PortableServer::POA_ptr
TAO_Hash_Naming_Context::_default_POA (void)
{
return PortableServer::POA::_duplicate (this->poa_.in ());
}
CosNaming::NamingContext_ptr
TAO_Hash_Naming_Context::get_context (const CosNaming::Name &name
ACE_ENV_ARG_DECL)
{
// Naming context we will return.
CosNaming::NamingContext_var result =
CosNaming::NamingContext::_nil ();
// Create compound name to be resolved, i.e.,
// (<name> - last component). To avoid copying, we can just reuse
// <name>'s buffer, since we will not be modifying it.
CORBA::ULong name_len = name.length ();
CosNaming::Name comp_name (name.maximum (),
name_len - 1,
ACE_const_cast
(CosNaming::NameComponent*,
name.get_buffer ()));
ACE_TRY
{
// Resolve the name.
CORBA::Object_var context = resolve (comp_name
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Try narrowing object reference to the NamingContext type.
result = CosNaming::NamingContext::_narrow (context.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCH (CosNaming::NamingContext::NotFound, ex)
{
// Add the last component of the name, which was stripped before
// the call to resolve.
CORBA::ULong rest_len = ex.rest_of_name.length () + 1;
ex.rest_of_name.length (rest_len);
ex.rest_of_name[rest_len - 1] = name[name_len - 1];
ACE_RE_THROW;
}
ACE_ENDTRY;
ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
if (CORBA::is_nil (result.in ()))
{
CosNaming::Name rest;
rest.length (2);
rest[0] = name[name_len - 2];
rest[1] = name[name_len - 1];
ACE_THROW_RETURN (CosNaming::NamingContext::NotFound
(CosNaming::NamingContext::not_context,
rest),
CosNaming::NamingContext::_nil ());
}
// Finally, if everything went smoothly, just return the resolved
// context.
return result._retn ();
}
void
TAO_Hash_Naming_Context::bind (const CosNaming::Name& n,
CORBA::Object_ptr obj
ACE_ENV_ARG_DECL)
{
ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX,
ace_mon, this->lock_,
CORBA::INTERNAL ());
ACE_CHECK;
// Check to make sure this object didn't have <destroy> method
// invoked on it.
if (this->destroyed_)
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
// Get the length of the name.
CORBA::ULong name_len = n.length ();
// Check for invalid name.
if (name_len == 0)
ACE_THROW (CosNaming::NamingContext::InvalidName());
// If we received compound name, resolve it to get the context in
// which the binding should take place, then perform the binding on
// target context.
if (name_len > 1)
{
CosNaming::NamingContext_var context =
this->get_context (n ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CosNaming::Name simple_name;
simple_name.length (1);
simple_name[0] = n[name_len - 1];
ACE_TRY
{
context->bind (simple_name, obj ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCH (CORBA::TIMEOUT, timeoutEx)
{
ACE_PRINT_EXCEPTION (timeoutEx, "Hash_Naming_Context::bind(), Caught CORBA::TIMEOUT exception");
// throw a CannotProceed exception back to the client
//
ACE_TRY_THROW (CosNaming::NamingContext::CannotProceed
(context.in (), simple_name));
}
ACE_ENDTRY;
}
// If we received a simple name, we need to bind it in this context.
else
{
// Try binding the name.
int result = this->context_->bind (n[0].id,
n[0].kind,
obj,
CosNaming::nobject);
if (result == 1)
ACE_THROW (CosNaming::NamingContext::AlreadyBound());
// Something went wrong with the internal structure
else if (result == -1)
ACE_THROW (CORBA::INTERNAL ());
}
}
void
TAO_Hash_Naming_Context::rebind (const CosNaming::Name& n,
CORBA::Object_ptr obj
ACE_ENV_ARG_DECL)
{
ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX, ace_mon,
this->lock_,
CORBA::INTERNAL ());
ACE_CHECK;
// Check to make sure this object didn't have <destroy> method
// invoked on it.
if (this->destroyed_)
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
// Get the length of the name.
CORBA::ULong name_len = n.length ();
// Check for invalid name.
if (name_len == 0)
ACE_THROW (CosNaming::NamingContext::InvalidName());
// If we received compound name, resolve it to get the context in
// which the rebinding should take place, then perform the rebinding
// on target context.
if (name_len > 1)
{
CosNaming::NamingContext_var context =
get_context (n ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CosNaming::Name simple_name;
simple_name.length (1);
simple_name[0] = n[name_len - 1];
ACE_TRY
{
context->rebind (simple_name, obj ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCH (CORBA::TIMEOUT, timeoutEx)
{
ACE_PRINT_EXCEPTION (timeoutEx, "Hash_Naming_Context::rebind(), Caught CORBA::TIMEOUT exception");
// throw a CannotProceed exception back to the client
//
ACE_TRY_THROW (CosNaming::NamingContext::CannotProceed
(context.in (), simple_name));
}
ACE_ENDTRY;
}
else
// If we received a simple name, we need to rebind it in this
// context.
{
int result = this->context_->rebind (n[0].id,
n[0].kind,
obj,
CosNaming::nobject);
// Check for error conditions.
if (result == -1)
ACE_THROW (CORBA::INTERNAL ());
else if (result == -2)
ACE_THROW (CosNaming::NamingContext::NotFound
(CosNaming::NamingContext::not_object,
n));
}
}
void
TAO_Hash_Naming_Context::bind_context (const CosNaming::Name &n,
CosNaming::NamingContext_ptr nc
ACE_ENV_ARG_DECL)
{
ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX, ace_mon,
this->lock_,
CORBA::INTERNAL ());
ACE_CHECK;
// Check to make sure this object didn't have <destroy> method
// invoked on it.
if (this->destroyed_)
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
// Do not allow binding of nil context reference.
if (CORBA::is_nil (nc))
ACE_THROW (CORBA::BAD_PARAM ());
// Get the length of the name.
CORBA::ULong name_len = n.length ();
// Check for invalid name.
if (name_len == 0)
ACE_THROW (CosNaming::NamingContext::InvalidName());
// If we received compound name, resolve it to get the context in
// which the binding should take place, then perform the binding on
// target context.
if (name_len > 1)
{
CosNaming::NamingContext_var context =
get_context (n ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CosNaming::Name simple_name;
simple_name.length (1);
simple_name[0] = n[name_len - 1];
ACE_TRY
{
context->bind_context (simple_name, nc ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCH (CORBA::TIMEOUT, timeoutEx)
{
ACE_PRINT_EXCEPTION (timeoutEx, "Hash_Naming_Context::bind_context (), Caught CORBA::TIMEOUT exception");
ACE_TRY_THROW (CosNaming::NamingContext::CannotProceed
(context.in (), simple_name));
}
ACE_ENDTRY;
}
// If we received a simple name, we need to bind it in this context.
else
{
// Try binding the name.
int result = this->context_->bind (n[0].id,
n[0].kind,
nc,
CosNaming::ncontext);
if (result == 1)
ACE_THROW (CosNaming::NamingContext::AlreadyBound());
// Something went wrong with the internal structure
else if (result == -1)
ACE_THROW (CORBA::INTERNAL ());
}
}
void
TAO_Hash_Naming_Context::rebind_context (const CosNaming::Name &n,
CosNaming::NamingContext_ptr nc
ACE_ENV_ARG_DECL)
{
ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX, ace_mon,
this->lock_,
CORBA::INTERNAL ());
ACE_CHECK;
// Check to make sure this object didn't have <destroy> method
// invoked on it.
if (this->destroyed_)
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
// Get the length of the name.
CORBA::ULong name_len = n.length ();
// Check for invalid name.
if (name_len == 0)
ACE_THROW (CosNaming::NamingContext::InvalidName());
// If we received compound name, resolve it to get the context in
// which the rebinding should take place, then perform the rebinding
// on target context.
if (name_len > 1)
{
CosNaming::NamingContext_var context =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -