void CNamingTreeCtrl::OnContextpopupBindnewcontext() { // TODO: Add your command handler code here HTREEITEM hItem = GetSelectedItem(); CNamingObject* pObject = GetTreeObject(hItem); CosNaming::NamingContext_var Context = pObject->NamingContext(); if(CORBA::is_nil(Context.in ())) { return; } CBindNewContext Dialog; if(Dialog.DoModal() != IDOK) { return; } try { CosNaming::NamingContext_var NewContext = Context->new_context(); Context->bind_context(Dialog.GetName(), NewContext); OnContextPopupRefresh(); } catch(CORBA::Exception& ex) { MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception")); } }
void CNamingTreeCtrl::OnContextPopupBindContext() { // TODO: Add your command handler code here CBindDialog Dialog(true, m_pORB); if(Dialog.DoModal() != IDOK) { return; } try { CNamingObject* pObject = GetTreeObject(); CosNaming::NamingContext_var Context = pObject->NamingContext(); if(CORBA::is_nil(Context.in ())) { return; } CosNaming::NamingContext_var NewContext = CosNaming::NamingContext::_narrow(Dialog.GetObject()); if(CORBA::is_nil(NewContext.in ())) { AfxMessageBox(ACE_TEXT ("Object is not a CosNaming::NamingContext")); return; } Context->bind_context(Dialog.GetName(), NewContext); OnContextPopupRefresh(); } catch(CORBA::Exception& ex) { MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception")); } }
void TAO_Hash_Naming_Context::bind_context (const CosNaming::Name &n, CosNaming::NamingContext_ptr nc) { // Check to make sure this object didn't have <destroy> method // invoked on it. if (this->destroyed_) throw CORBA::OBJECT_NOT_EXIST (); // Do not allow binding of nil context reference. if (CORBA::is_nil (nc)) throw CORBA::BAD_PARAM (); // Get the length of the name. CORBA::ULong const 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 binding 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]; try { context->bind_context (simple_name, nc); } catch (const CORBA::SystemException&) { throw CosNaming::NamingContext::CannotProceed( context.in (), simple_name); } } // If we received a simple name, we need to bind it in this context. else { ACE_WRITE_GUARD_THROW_EX (TAO_SYNCH_RW_MUTEX, ace_mon, this->lock_, CORBA::INTERNAL ()); // Try binding the name. int result = this->context_->bind (n[0].id, n[0].kind, nc, CosNaming::ncontext); if (result == 1) throw CosNaming::NamingContext::AlreadyBound(); // Something went wrong with the internal structure else if (result == -1) throw CORBA::INTERNAL (); } }
int TestTask::svc() { try { // Start the Naming Service tasks namingServiceA_.activate(); // Wait for the Naming Service initialized. namingServiceA_.waitInit(); namingServiceB_.activate(); // Wait for the Naming Service initialized. namingServiceB_.waitInit(); FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: ns.ior\n"), 1); ACE_OS::fprintf (output_file, "%s", namingServiceA_.ior ()); ACE_OS::fclose (output_file); // Get reference to Root POA CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); // Activate POA Manager PortableServer::POAManager_var mgr = poa->the_POAManager(); mgr->activate(); // Find the Naming Service obj = orb_->string_to_object (namingServiceB_.ior ()); CosNaming::NamingContext_var root = CosNaming::NamingContext::_narrow(obj.in()); if (CORBA::is_nil(root.in())) { ACE_ERROR ((LM_ERROR, "Error, Nil Naming Context reference\n")); return 1; } // Bind the example Naming Context, if necessary CosNaming::NamingContext_var example_nc; CosNaming::Name name; name.length(1); name[0].id = CORBA::string_dup("example"); try { obj = root->resolve(name); example_nc = CosNaming::NamingContext::_narrow(obj.in()); } catch (const CosNaming::NamingContext::NotFound&) { example_nc = root->bind_new_context(name); } // Bind the Test object name.length(2); name[1].id = CORBA::string_dup("Hello"); // Create an object Hello servant(orb_.in ()); PortableServer::ObjectId_var oid = poa->activate_object(&servant); obj = poa->id_to_reference(oid.in()); root->rebind(name, obj.in()); ACE_DEBUG ((LM_INFO, "Hello object bound in Naming Service B\n")); name.length(1); obj = orb_->string_to_object (namingServiceA_.ior ()); root = CosNaming::NamingContext::_narrow(obj.in()); root->bind_context (name, example_nc.in ()); ACE_DEBUG ((LM_INFO, "'example' context of NS B bound in Naming Service A\n")); if (shutdown_ns_) { namingServiceB_.end(); ACE_DEBUG ((LM_INFO, "Naming Service B shut down\n")); } // Create shutdown server NsShutdown shutdown_servant(orb_.in ()); PortableServer::ObjectId_var shutdown_oid = poa->activate_object(&shutdown_servant); obj = poa->id_to_reference(shutdown_oid.in()); CORBA::String_var ior = orb_->object_to_string (obj.in ()); output_file= ACE_OS::fopen (ior_shutdown_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file %s for writing IOR: %C\n", ior_shutdown_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); // Normally we run the orb and the orb is shutdown by // calling TestTask::end(). // Accept requests orb_->run(); orb_->destroy(); // Shutdown the Naming Services. namingServiceA_.end(); if (!shutdown_ns_) { namingServiceB_.end(); } return 0; } catch (CORBA::Exception& ex) { ex._tao_print_exception ("CORBA exception: "); } return -1; }
int TestTask::svc() { try { // Get reference to Root POA CORBA::Object_var obj = orb_->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ()); // Activate POA Manager PortableServer::POAManager_var mgr = poa->the_POAManager (); mgr->activate (); // Find the Naming Service obj = orb_->string_to_object ( "corbaloc:iiop:1.2@localhost:9932/NameService"); CosNaming::NamingContext_var rootB = CosNaming::NamingContext::_narrow (obj.in ()); if (CORBA::is_nil (rootB.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, Nil Naming Context reference\n"))); return 1; } // Bind the example Naming Context, if necessary CosNaming::NamingContext_var example_nc; CosNaming::Name name; name.length(1); name[0].id = CORBA::string_dup( "example"); try { obj = rootB->resolve (name); example_nc = CosNaming::NamingContext::_narrow (obj.in ()); } catch (const CosNaming::NamingContext::NotFound&) { example_nc = rootB->bind_new_context (name); } // Bind the Test object name.length (2); name[1].id = CORBA::string_dup ("Hello"); // Create an object Hello servant (orb_.in ()); PortableServer::ObjectId_var oid = poa->activate_object (&servant); obj = poa->id_to_reference (oid.in ()); rootB->rebind (name, obj.in ()); ACE_DEBUG ((LM_INFO, ACE_TEXT ("Hello object bound in Naming Service B\n"))); name.length (1); name[0].id = CORBA::string_dup ("nsB"); obj = orb_->string_to_object ( "corbaloc:iiop:1.2@localhost:9931/NameService"); CosNaming::NamingContext_var rootA = CosNaming::NamingContext::_narrow (obj.in ()); rootA->bind_context (name, rootB.in ()); ACE_DEBUG ((LM_INFO, ACE_TEXT ("Root context of NS B bound in Naming Service A ") ACE_TEXT ("under name 'nsB'\n"))); CORBA::String_var ior = orb_->object_to_string (obj.in ()); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Cannot open output file %s for writing ") ACE_TEXT ("IOR: %C\n"), ior_output_file, ior.in ()), 1); ACE_OS::fprintf (output_file, ACE_TEXT ("%s"), ior.in ()); ACE_OS::fclose (output_file); ACE_DEBUG ((LM_INFO, ACE_TEXT ("Wrote IOR file\n"))); // Normally we run the orb and the orb is shutdown by // calling TestTask::end(). // Accept requests orb_->run(); orb_->destroy(); return 0; } catch (CORBA::Exception& ex) { ex._tao_print_exception (ACE_TEXT ("CORBA exception: ")); } return -1; }