CosNaming::NamingContext_ptr TAO_Transient_Naming_Context::new_context (void) { ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX, ace_mon, this->lock_, CORBA::INTERNAL ()); // Check to make sure this object didn't have <destroy> method // invoked on it. if (this->destroyed_) throw CORBA::OBJECT_NOT_EXIST (); // Generate a POA id for the new context. char poa_id[BUFSIZ]; ACE_OS::sprintf (poa_id, "%s_%d", this->poa_id_.c_str (), this->counter_++); // Create a new context. CosNaming::NamingContext_var result = make_new_context (this->poa_.in (), poa_id, this->transient_context_->total_size ()); return result._retn (); }
CosNaming::NamingContext_ptr TAO_Hash_Naming_Context::bind_new_context (const CosNaming::Name& n) { // Check to make sure this object didn't have <destroy> method // invoked on it. if (this->destroyed_) 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) 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 operation on // target context. if (name_len > 1) { CosNaming::NamingContext_var context = this->get_context (n); CosNaming::Name simple_name; simple_name.length (1); simple_name[0] = n[name_len - 1]; return context->bind_new_context (simple_name); } // If we received a simple name, we need to bind it in this context. // Stores our new Naming Context. CosNaming::NamingContext_var result = CosNaming::NamingContext::_nil (); // Create new context. result = this->new_context (); // Bind the new context to the name. try { this->bind_context (n, result.in ()); } catch (const CORBA::Exception&) { // If the bind() operation fails we must destroy the recently // created context, should any exceptions be raised by the // destroy() operation we want to ignore them. { try { result->destroy (); } catch (const CORBA::Exception&) { } } // Re-raise the exception in bind_context() throw; } return result._retn (); }
CosNaming::NamingContext_ptr TAO_Transient_Naming_Context::make_new_context (PortableServer::POA_ptr poa, const char *poa_id, size_t context_size) { // Put together a servant for the new Naming Context. TAO_Transient_Naming_Context *context_impl = 0; ACE_NEW_THROW_EX (context_impl, TAO_Transient_Naming_Context (poa, poa_id, context_size), CORBA::NO_MEMORY ()); // Put <context_impl> into the auto pointer temporarily, in case next // allocation fails. ACE_Auto_Basic_Ptr<TAO_Transient_Naming_Context> temp (context_impl); TAO_Naming_Context *context = 0; ACE_NEW_THROW_EX (context, TAO_Naming_Context (context_impl), CORBA::NO_MEMORY ()); // 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. #if defined (CORBA_E_MICRO) PortableServer::ObjectId_var id = poa->activate_object (context); #else PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId (poa_id); poa->activate_object_with_id (id.in (), context); #endif /* CORBA_E_MICRO */ CosNaming::NamingContext_var result = context->_this (); return result._retn (); }
CosNaming::NamingContext_ptr TAO_Hash_Naming_Context::get_context (const CosNaming::Name &name) { 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, const_cast<CosNaming::NameComponent*> (name.get_buffer ())); try { CORBA::Object_var context = this->resolve (comp_name); // Try narrowing object reference to the NamingContext type. result = CosNaming::NamingContext::_narrow (context.in ()); } catch (CosNaming::NamingContext::NotFound& ex) { // Add the last component of the name, which was stripped before // the call to resolve. CORBA::ULong const 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]; throw; } if (CORBA::is_nil (result.in ())) { CosNaming::Name rest; rest.length (2); rest[0] = name[name_len - 2]; rest[1] = name[name_len - 1]; throw CosNaming::NamingContext::NotFound( CosNaming::NamingContext::not_context, rest); } // Finally, if everything went smoothly, just return the resolved // context. return result._retn (); }
CosNaming::NamingContext_ptr TAO_Transient_Naming_Context::new_context (void) { // Generate a POA id for the new context. char poa_id[BUFSIZ]; ACE_OS::sprintf (poa_id, "%s_%d", this->poa_id_.c_str (), this->counter_++); // Create a new context. CosNaming::NamingContext_var result = make_new_context (this->poa_.in (), poa_id, this->transient_context_->total_size ()); return result._retn (); }
CosNaming::NamingContext_ptr TAO_Persistent_Naming_Context::new_context (void) { // Check to make sure this object didn't have <destroy> method // invoked on it. if (this->destroyed_) throw CORBA::OBJECT_NOT_EXIST (); // Generate a POA id for the new context. char poa_id[BUFSIZ]; ACE_OS::sprintf (poa_id, "%s_%d", this->poa_id_.c_str (), (*this->counter_)++); CosNaming::NamingContext_var result = this->make_new_context (this->poa_.in (), poa_id, this->persistent_context_->total_size (), this->index_); return result._retn (); }
int TAO_Persistent_Context_Index::recreate_all (void) { CONTEXT_INDEX::ITERATOR *index_iter = 0; ACE_NEW_RETURN (index_iter, (CONTEXT_INDEX::ITERATOR) (*index_), -1); ACE_Auto_Basic_Ptr<CONTEXT_INDEX::ITERATOR> it (index_iter); // Because of broken old g++!!! typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_Index_ExtId, TAO_Persistent_Index_IntId> IND_DEF; IND_DEF::ENTRY *entry = 0; if (TAO_debug_level > 0) ORBSVCS_DEBUG ((LM_DEBUG, "Starting to recreate Naming Contexts from the file...\n")); // For each entry in <index_>, create a Naming Context servant. do { index_iter->next (entry); // Put together a servant for the new Naming Context // Using the naming context factory to create a naming context of the appropriate type TAO_Persistent_Naming_Context *context_impl = this->context_impl_factory_->create_naming_context_impl (poa_.in (), entry->ext_id_.poa_id_, this, entry->int_id_.hash_map_, entry->int_id_.counter_); // Put <context_impl> into the auto pointer temporarily, in case next // allocation fails. ACE_Auto_Basic_Ptr<TAO_Persistent_Naming_Context> temp (context_impl); TAO_Naming_Context *context = 0; ACE_NEW_RETURN (context, TAO_Naming_Context (context_impl), -1); // 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 with the POA. PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId (entry->ext_id_.poa_id_); this->poa_->activate_object_with_id (id.in (), context); CosNaming::NamingContext_var result = context->_this (); // If this is the root Naming Context, take a note of it. if (context_impl->root ()) this->root_context_= result._retn (); } while (index_iter->advance ()); return 0; }
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) { // Store the stub we will return here. CosNaming::NamingContext_var result; // Put together a servant for the new Naming Context. TAO_Persistent_Naming_Context *context_impl = ind->create_naming_context_impl( poa, poa_id); // Verify that a context implementation was created. If not, throw an exception if (context_impl == 0) throw CORBA::NO_MEMORY (); // Put <context_impl> into the auto pointer temporarily, in case next // allocation fails. ACE_Auto_Basic_Ptr<TAO_Persistent_Naming_Context> temp (context_impl); if (context_impl->init (context_size) == -1) throw CORBA::NO_MEMORY (); // 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) throw CORBA::INTERNAL (); // Insure appropriate cleanup in case of exception conditions ahead. context_impl->set_cleanup_level (2); TAO_Naming_Context *context = 0; ACE_NEW_THROW_EX (context, TAO_Naming_Context (context_impl), CORBA::NO_MEMORY ()); // 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); poa->activate_object_with_id (id.in (), context); result = context->_this (); // Everything went smoothly, without errors - we don't need any cleanup. context_impl->set_cleanup_level (0); return result._retn (); }