📄 storable_naming_context.cpp
字号:
// Let <implementation> know about it's <interface>.
context_impl->interface (context);
// Release auto pointer, and start using reference counting to
// control our servant.
temp.release ();
PortableServer::ServantBase_var s = context;
// Register the new context with the POA.
PortableServer::ObjectId_var id =
PortableServer::string_to_ObjectId (poa_id);
// If we try to register a naming context that is already registered,
// the following activation causes a POA::ObjectAlreadyActive exception be
// thrown which is transmitted as a CORBA::UNKNOWN on the wire. To rectify
// this problem, we explicitly throw the correct INS exception in
// this situation.
ACE_TRY
{
poa->activate_object_with_id (id.in (),
context
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCH (PortableServer::POA::ObjectAlreadyActive, ex)
{
ACE_THROW_RETURN (CosNaming::NamingContext::AlreadyBound(),
CosNaming::NamingContext::_nil ());
}
ACE_ENDTRY;
ACE_CHECK_RETURN (result._retn ());
result = context->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
// return the address of the new context object so that caller can finish
*new_context = context_impl;
return result._retn ();
}
CosNaming::NamingContext_ptr
TAO_Storable_Naming_Context::new_context (ACE_ENV_SINGLE_ARG_DECL)
{
ACE_TRACE("new_context");
ACE_GUARD_THROW_EX (ACE_SYNCH_RECURSIVE_MUTEX,
ace_mon,
this->lock_,
CORBA::INTERNAL ());
ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
{
// Open the backing file
File_Open_Lock_and_Check flck(this, "r"
ACE_ENV_ARG_PARAMETER);
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 ());
}
TAO_NS_Persistence_Global global;
// Generate a POA id for the new context.
if(redundant_)
{
// acquire a lock on the file that holds our counter
if (gfl_->open() != 0)
{
delete gfl_;
ACE_THROW_RETURN(CORBA::PERSIST_STORE(),
CosNaming::NamingContext::_nil ());
}
if (gfl_ -> flock(0, 0, 0) != 0)
ACE_THROW_RETURN (CORBA::INTERNAL(),
CosNaming::NamingContext::_nil ());
// get the counter from disk
*gfl_ >> global;
gcounter_ = global.counter();
// use it to generate a new name
}
char poa_id[BUFSIZ];
ACE_OS::sprintf (poa_id,
"%s_%d",
root_name_,
gcounter_++);
// then save it back on disk
global.counter(gcounter_);
*gfl_ << global;
if(redundant_)
{
// and release our lock
if (gfl_ -> flock(0, 0, 0) != 0)
ACE_THROW_RETURN(CORBA::INTERNAL(),
CosNaming::NamingContext::_nil ());
gfl_->close();
}
// Create a new context.
TAO_Storable_Naming_Context *new_context = 0;
CosNaming::NamingContext_var result =
make_new_context (this->orb_,
this->poa_.in (),
poa_id,
this->storable_context_->total_size (),
this->factory_,
this->persistence_directory_.c_str (),
&new_context
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
// Since this is a new context, make an empty map in it
ACE_NEW_THROW_EX (new_context->storable_context_,
TAO_Storable_Bindings_Map (hash_table_size_,orb_),
CORBA::NO_MEMORY ());
ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
new_context->context_ = new_context->storable_context_;
File_Open_Lock_and_Check flck(new_context, "wc" ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
new_context->Write(flck.peer());
return result._retn ();
}
void
TAO_Storable_Naming_Context::rebind (const CosNaming::Name& n,
CORBA::Object_ptr obj
ACE_ENV_ARG_DECL)
{
ACE_TRACE("rebind");
// 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());
// we didn't need a lock to check the input arg, but now we do
ACE_GUARD_THROW_EX (ACE_SYNCH_RECURSIVE_MUTEX, ace_mon,
this->lock_,
CORBA::INTERNAL ());
ACE_CHECK;
// Open the backing file
File_Open_Lock_and_Check flck(this, name_len > 1 ? "r" : "rw"
ACE_ENV_ARG_PARAMETER);
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 ());
// 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)
{
// This had been a read on the file so now we are done with it
flck.release();
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];
context->rebind (simple_name, obj ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
// If we received a simple name, we need to rebind it in this
// context.
else
{
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));
this->Write(flck.peer());
}
}
void
TAO_Storable_Naming_Context::bind_context (const CosNaming::Name &n,
CosNaming::NamingContext_ptr nc
ACE_ENV_ARG_DECL)
{
ACE_TRACE("TAO_Storable_Naming_Context::bind_context");
// 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());
// Do not allow binding of nil context reference.
if (CORBA::is_nil (nc))
ACE_THROW (CORBA::BAD_PARAM ());
// we didn't need a lock to check the input arg, but now we do
ACE_GUARD_THROW_EX (ACE_SYNCH_RECURSIVE_MUTEX, ace_mon,
this->lock_,
CORBA::INTERNAL ());
ACE_CHECK;
// Open the backing file
File_Open_Lock_and_Check flck(this, name_len > 1 ? "r" : "rw"
ACE_ENV_ARG_PARAMETER);
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 ());
// 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)
{
// This had been a read on the file so now we are done with it
flck.release();
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];
context->bind_context (simple_name, nc ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
// 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 ());
this->Write(flck.peer());
}
}
void
TAO_Storable_Naming_Context::rebind_context (const CosNaming::Name &n,
CosNaming::NamingContext_ptr nc
ACE_ENV_ARG_DECL)
{
ACE_TRACE("rebind_context");
// 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());
// we didn't need a lock to check the input arg, but now we do
ACE_GUARD_THROW_EX (ACE_SYNCH_RECURSIVE_MUTEX, ace_mon,
this->lock_,
CORBA::INTERNAL ());
ACE_CHECK;
// Open the backing file
File_Open_Lock_and_Check flck(this, name_len > 1 ? "r" : "rw"
ACE_ENV_ARG_PARAMETER);
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 ());
// 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)
{
// This had been a read on the file so now we are done with it
flck.release();
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];
context->rebind_context (simple_name, nc ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
// If we received a simple name, we need to rebind it in this
// context.
else
{
int result = this->context_->rebind (n[0].id,
n[0].kind,
nc,
CosNaming::ncontext);
// Check for error conditions.
if (result == -1)
ACE_THROW (CORBA::INTERNAL ());
else if (result == -2)
ACE_THROW (CosNaming::NamingContext::NotFound
(CosNaming::NamingContext::not_context, n));
this->Write(flck.peer());
}
}
CORBA::Object_ptr
TAO_Storable_Naming_Context::resolve (const CosNaming::Name& n
ACE_ENV_ARG_DECL)
{
ACE_TRACE("resolve");
// Get the length of the name.
CORBA::ULong name_len = n.length ();
// Check for invalid name.
if (name_len == 0)
ACE_THROW_RETURN (CosNaming::NamingContext::InvalidName(),
CORBA::Object::_nil ());
// we didn't need a lock to check the input arg, but now we do
ACE_GUARD_THROW_EX (ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, this->lock_,
CORBA::INTERNAL ());
ACE_CHECK_RETURN (CORBA::Object::_nil ());
// Open the backing file
File_Open_Lock_and_Check flck(this, "r"
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (CORBA::Object::_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 (),
CORBA::Object::_nil ());
// Resolve the first component of the name.
flck.release();
// Stores the binding type for the first name component.
CosNaming::BindingType type;
// Stores the object reference bound to the first name component.
CORBA::Object_ptr obj = CORBA::Object::_nil ();
if (this->context_->find (n[0].id,
n[0].kind,
obj,
type) == -1)
ACE_THROW_RETURN (CosNaming::NamingContext::NotFound
(CosNaming::NamingContext::missing_node, n),
CORBA::Object::_nil ());
// Store the value in var to avoid memory leaks.
CORBA::Object_var result = obj;
// If the name we have to resolve is a compound name, we need to
// resolve it recursively.
if (name_len > 1)
{
CosNaming::NamingContext_var context =
CosNaming::NamingContext::_nil ();
if (type == CosNaming::ncontext)
{
// Narrow to NamingContext.
context = CosNaming::NamingContext::_narrow (result.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (result._retn ());
}
else
// The first name component wasn't bound to a NamingContext.
ACE_THROW_RETURN (CosNaming::NamingContext::NotFound
(CosNaming::NamingContext::not_context,
n),
CORBA::Object::_nil ());
// If narrow failed...
if (CORBA::is_nil (context.in ()))
ACE_THROW_RETURN (CosNaming::NamingContext::NotFound
(CosNaming::NamingContext::not_context, n),
CORBA::Object::_nil ());
else
{
// Successfully resolved the first name component, need to
// recursively call resolve on <n> without the first component.
// We need a name just like <n> but without the first
// component. Instead of copying data we can reuse <n>'s
// buffer since we will only be using it for 'in' parameters
// (no modifications).
CosNaming::Name rest_of_name
(n.maximum () - 1,
n.length () - 1,
ACE_const_cast (CosNaming::NameComponent*,
n.get_buffer ()) + 1);
// If there are any exceptions, they will propagate up.
return context->resolve (rest_of_name
ACE_ENV_ARG_PARAMETER);
}
}
// If the name we had to resolve was simple, we just need to return
// the result.
return result._retn ();
}
void
TAO_Storable_Naming_Context::unbind (const CosNaming::Name& n
ACE_ENV_ARG_DECL)
{
ACE_TRACE("unbind");
// 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());
// we didn't need a lock to check the input arg, but now we do
ACE_GUARD_THROW_EX (ACE_SYNCH_RECURSIVE_MUTEX, ace_mon,
this->lock_,
CORBA::INTERNAL ());
ACE_CHECK;
// Open the backing file
File_Open_Lock_and_Check flck(this, name_len > 1 ? "r" : "rw"
ACE_ENV_ARG_PARAMETER);
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 ());
// If we received compound name, resolve it to get the context in
// which the unbinding should take place, then perform the unbinding
// on target context.
if (name_len > 1)
{
// This had been a read on the file so now we are done with it
flck.release();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -