int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize orb CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); if (parse_args (argc, argv) != 0) return 1; //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->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root = CosNaming::NamingContextExt::_narrow(obj.in()); if (CORBA::is_nil(root.in())) { std::cerr << "Nil Naming Context reference" << std::endl; return 1; } // Bind a new context. CosNaming::Name name; name.length( 1 ); name[0].id = CORBA::string_dup( "root.esc-dot" ); name[0].kind = CORBA::string_dup( "kind1" ); try { obj = root->resolve(name); } catch(const CosNaming::NamingContext::NotFound&) { CosNaming::NamingContext_var dummy = root->bind_new_context(name); } name.length( 2 ); name[1].id = CORBA::string_dup( "leaf/esc-slash" ); name[1].kind = CORBA::string_dup( "kind2" ); // Create an object PortableServer::Servant_var<Messenger_i> servant = new Messenger_i; PortableServer::ObjectId_var oid = poa->activate_object(servant.in()); CORBA::Object_var messenger_obj = poa->id_to_reference(oid.in()); root->rebind(name, messenger_obj.in()); // Also try rebinding to a simple path. CosNaming::Name_var simp_name = root->to_name("Simple"); try { obj = root->resolve(simp_name.in()); } catch(const CosNaming::NamingContext::NotFound&) { CosNaming::NamingContext_var dummy = root->bind_new_context(simp_name.in()); } simp_name = root->to_name("Simple/Messenger"); root->rebind(simp_name.in(), messenger_obj.in()); // Convert Name to String Name. CORBA::String_var str_name = root->to_string(name); std::cout << "str_name: " << str_name.in() << std::endl; CORBA::String_var str_simple = root->to_string(simp_name.in()); std::cout << "simple: " << str_simple.in() << std::endl; // Convert String Name to Name. CosNaming::Name_var tname = root->to_name(str_name.in()); std::cout << "converted back to a CosNaming::Name: " << std::endl; std::cout << " name[0] = " << (* tname)[0].id.in() << " , " << (* tname)[0].kind.in() << std::endl; std::cout << " name[1] = " << (* tname)[1].id.in() << " , " << (* tname)[1].kind.in() << std::endl; // Find the application object by resolve_str. try { obj = root->resolve_str(str_name.in()); } catch(const CosNaming::NamingContext::NotFound&) { std::cerr<<"Couldn't resolve the string name: " << str_name << std::endl; return 1; } ACE_CString base_address (":"); base_address += ACE_TEXT_ALWAYS_CHAR (hostname); base_address += ":"; base_address += ACE_TEXT_ALWAYS_CHAR (port); ACE_CString addr (""); addr = base_address + "/key/str"; // Create an URL string for application object. CORBA::String_var address = CORBA::string_dup (addr.c_str()); std::cout << "call to_url(\"" << address.in() << "\"" << std::endl; std::cout << " ,\"" << str_simple.in() << "\")"<< std::endl; CORBA::String_var url_string = root->to_url(address.in(), str_simple.in()); std::cout << "to_url result: " << url_string.in() << std::endl; // Write NS url to a file to let client read NS URL to get // NamingContext reference. CORBA::String_var ns_addr = CORBA::string_dup(base_address.c_str()); std::cout << "call to_url(\"" <<ns_addr.in() << "\",\"" << str_simple.in() << "\")"<< std::endl; CORBA::String_var url = root->to_url(ns_addr.in(), str_simple.in()); std::cout << "to_url result: " << url.in() << std::endl; std::ofstream iorFile(ACE_TEXT_ALWAYS_CHAR (ior_output_file)); iorFile << url.in() << std::endl; iorFile.close(); std::cout << "Naming Service URL written to file " << ior_output_file << std::endl; // Accept requests orb->run(); orb->destroy(); } catch(const CORBA::Exception& ex) { std::cerr << "Caught a CORBA::Exception: " << ex << std::endl; return 1; } return 0; }
void TAO_Notify_Tests_EventChannel_Command::create_collocated_ecf (void) { CosNotifyChannelAdmin::EventChannelFactory_var notify_factory; // The Service Object. TAO_Notify_Service* notify_service = TAO_Notify_Service::load_default (); if (notify_service == 0) { ACE_DEBUG ((LM_DEBUG, "Service not found! check conf. file\n")); return; } // Resolve some helpers. CORBA::ORB_var orb; PortableServer::POA_var poa; CosNaming::NamingContextExt_var naming; LOOKUP_MANAGER->resolve (orb); LOOKUP_MANAGER->resolve (poa); LOOKUP_MANAGER->resolve (naming); notify_service->init_service (orb.in ()); // Activate the factory notify_factory = notify_service->create (poa.in ()); // Register with the Naming Service CosNaming::Name_var name = naming->to_name (TAO_Notify_Tests_Name::event_channel_factory); naming->rebind (name.in (), notify_factory.in ()); }
int main(int argc, char **argv) { // Removes ORB related arguments CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // Program options std::string register_servant; std::string proxy_reference; _po::options_description _desc("Proxy Server options"); _desc.add_options() ("help,h", "produce help message") ("register-servant,r", _po::value< std::string >(®ister_servant), "register the servant into the name service") ("proxy-reference,p", _po::value< std::string >(&proxy_reference), "forward received calls to another servant"); _po::variables_map _vm; _po::store(_po::parse_command_line(argc, argv, _desc), _vm); _po::notify(_vm); if (_vm.count("help")) { std::cout << _desc << std::endl; return 0; } bool reference_is_ns_entry = false; // TODO // Name Service CosNaming::NamingContextExt_var nc; if (reference_is_ns_entry || !register_servant.empty()) { try { CORBA::Object_var ncObj = orb->resolve_initial_references("NameService"); nc = CosNaming::NamingContextExt::_narrow(ncObj); } catch(...) { } if (CORBA::is_nil(nc)) std::cerr << "Name service unavailable!" << std::endl; } // Proxy reference prueba::Iface_var reference; if (!proxy_reference.empty()) { CORBA::Object_var refObj; if (reference_is_ns_entry && !CORBA::is_nil(nc)) refObj = nc->resolve_str(proxy_reference.c_str()); else refObj = orb->string_to_object(proxy_reference.c_str()); reference = prueba::Iface::_narrow(refObj); } // Servant prueba_Iface_impl _impl(reference.in()); CORBA::Object_var rootPOAObj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(rootPOAObj.in()); PortableServer::POAManager_var manager = rootPOA->the_POAManager(); PortableServer::ObjectId_var myObjID = rootPOA->activate_object(&_impl); CORBA::Object_var obj = rootPOA->servant_to_reference(&_impl); // Displaying reference CORBA::String_var ref = orb->object_to_string(obj); std::cout << ref << std::endl; // Registring servant CosNaming::Name_var name; if (!register_servant.empty() && !CORBA::is_nil(nc)) { name = nc->to_name(register_servant.c_str()); nc->rebind(name, obj); } /*PROTECTED REGION ID(prueba_Iface_impl_server::___main) ENABLED START*/ /*PROTECTED REGION END*/ // Running manager->activate(); orb->run(); // Unbinding servant if (!CORBA::is_nil(nc) && name) nc->unbind(name); return 0; }
int TAO_Notify_Service_Driver::fini (void) { /// Release all the _vars as the ORB about to go away. CosNotifyChannelAdmin::EventChannelFactory_var factory = this->notify_factory_._retn (); CORBA::ORB_var orb = this->orb_._retn (); CORBA::ORB_var dispatching_orb = this->dispatching_orb_._retn (); PortableServer::POA_var poa = this->poa_._retn (); CosNaming::NamingContextExt_var naming = this->naming_._retn (); // This must be called to ensure that all services shut down // correctly. Depending upon the type of service loaded, it may // or may not actually perform any actions. this->notify_service_->finalize_service (factory.in ()); factory = CosNotifyChannelAdmin::EventChannelFactory::_nil (); this->notify_service_->fini (); // Deactivate. if (this->use_name_svc_ && !CORBA::is_nil (naming.in ())) { // Unbind all event channels from the naming service if (this->register_event_channel_) { for (ACE_Unbounded_Set<ACE_CString>::const_iterator ci ( this->notify_channel_name_); !ci.done(); ci++) { CosNaming::Name_var name = naming->to_name ((*ci).c_str ()); naming->unbind (name.in ()); } } // Unbind from the naming service. CosNaming::Name_var name = naming->to_name (this->notify_factory_name_.c_str ()); naming->unbind (name.in ()); naming = CosNaming::NamingContextExt::_nil (); } if (!CORBA::is_nil (poa.in ())) { poa->destroy (true, true); poa = PortableServer::POA::_nil (); } if (this->shutdown_dispatching_orb_ && !CORBA::is_nil (dispatching_orb_.in ())) { dispatching_orb->shutdown (); } // shutdown the ORB. if (this->shutdown_orb_ && !CORBA::is_nil (orb.in ())) { orb->shutdown (); } // Make sure all worker threads are gone. this->worker_.wait (); this->logging_worker_.wait (); // Destroy the ORB if (this->shutdown_dispatching_orb_ && !CORBA::is_nil (dispatching_orb_.in ())) { dispatching_orb->destroy (); } // Destroy the ORB. if (this->shutdown_orb_ && !CORBA::is_nil (orb.in ())) { orb->destroy (); } dispatching_orb_ = CORBA::ORB::_nil (); worker_.orb (CORBA::ORB::_nil ()); orb = CORBA::ORB::_nil (); return 0; }