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; }
int ACE_TMAIN (int argc, ACE_TCHAR* argv[]) { try { // First initialize the ORB, that will remove some arguments... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Create the servant Quoter_Stock_Factory_i stock_factory_i; // Activate it to obtain the object reference Quoter::Stock_Factory_var stock_factory = stock_factory_i._this (); // Put the object reference as an IOR string CORBA::String_var ior = orb->object_to_string (stock_factory.in ()); // Print it out! cout << ior.in () << endl; orb->run (); // Destroy the POA, waiting until the destruction terminates poa->destroy (1, 1); orb->destroy (); } catch (CORBA::Exception &) { cerr << "CORBA exception raised!" << endl; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { TAO_CEC_Default_Factory::init_svcs (); try { // ORB initialization boiler plate... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // **************************************************************** run_test (poa.in (), 0); run_test (poa.in (), 1); // **************************************************************** poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Service"); return 1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try{ orb = CORBA::ORB_init (argc, argv); RtecEventChannelAdmin::EventChannel_var channel = get_event_channel (argc, argv); if (CORBA::is_nil (channel.in ())) return -1; PortableServer::POA_var poa = resolve_init<PortableServer::POA> (orb.in (), "RootPOA"); PortableServer::POAManager_var mgr = poa->the_POAManager (); mgr->activate (); PushSupplier_impl push_supplier(orb.in ()); if (push_supplier.init(channel.in ()) == -1) return -1; RtecEventComm::PushSupplier_var supplier = push_supplier._this(); orb->run(); } catch (const CORBA::Exception& ex){ ex._tao_print_exception ("A CORBA Exception occurred."); } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize orb CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // 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 (); // Create an object Time_impl time_servant; // Write its stringified reference to stdout Time_var tm = time_servant._this (); CORBA::String_var str = orb->object_to_string (tm.in ()); cout << str.in () << endl; // Accept requests orb->run (); } catch (const CORBA::Exception &) { cerr << "Uncaught CORBA exception" << endl; return 1; } return 0; }
CORBA::Object_ptr TAO_Monitor_Init::create_object (CORBA::ORB_ptr orb, int, ACE_TCHAR *[]) { try { CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ()); PortableServer::POAManager_var mgr = poa->the_POAManager (); mgr->activate (); Monitor_Impl *servant = 0; ACE_NEW_RETURN (servant, Monitor_Impl (orb), CORBA::Object::_nil ()); PortableServer::ObjectId_var id = poa->activate_object (servant); PortableServer::ServantBase_var safe_servant = servant; obj = servant->_this (); return obj._retn (); } catch (const CORBA::Exception&) { } return CORBA::Object::_nil (); }
int NamingTask::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 poaManager = poa->the_POAManager(); poaManager->activate(); // Initialize the naming service // We are not going to look for other naming servers TAO_Naming_Server naming; if (naming.init(orb_.in(), poa.in(), ACE_DEFAULT_MAP_SIZE, 0, 0) == 0) { std::cout << "The Naming Service Task is ready." << std::endl; initialized_ = true; // Accept requests orb_->run(); orb_->destroy(); return 0; } else { std::cerr << "Unable to initialize the Naming Service." << std::endl; } } catch(const CORBA::Exception& ex) { std::cerr << "NamingTask::svc() CORBA::Exception: " << ex << std::endl; } return -1; }
int run() override final { OrbHelper orb(executable_name_); CORBA::Object_var obj = orb.orb()->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); POA_youtils_test::corba_test_tie<CorbaYoutilsServant> corba_youtils_servant(new CorbaYoutilsServant(orb)); PortableServer::ObjectId_var corba_youtils_servant_id = poa->activate_object(&corba_youtils_servant); CORBA::Object_var obj1; obj1 = corba_youtils_servant._this(); orb.bindObjectToName(obj1, "context_name", "context_kind", "object_name", "object_kind"); PortableServer::POAManager_var pman = poa->the_POAManager(); pman->activate(); omni_thread::sleep(1); orb.orb()->run(); poa->deactivate_object(corba_youtils_servant_id); return 0; }
int main(int argc, char* argv[]) { // // Signals staff // signal(SIGINT, handler); // signal(SIGTERM, handler); // signal(SIGKILL, handler); // Print the welcome message printWelcome(); // // Check TIDNaming arguments // /* * Note: this TIDNaming special arguments may be passed to ORB * initialization with no problems. Any unknown argument will be ignored * by ORB, so no change is needed for argv. */ const char * persistence_dir = ""; int max_binding_iterators = 40; const char * ior_file = ""; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--help") == 0) { printUsage(argv[0]); _exit(0); } if (strcmp(argv[i], "--version") == 0) { cerr << "TIDNaming C++ version " << TIDNaming::st_version << endl; _exit(0); } if (strcmp(argv[i], "--persistence-dir") == 0) { if (i == argc - 1) { cerr << "Error: --persistence-dir specified but no path given" << endl; printUsage(argv[0]); _exit(-1); } persistence_dir = argv[i+1]; } if (strcmp(argv[i], "--max_binding_iterators") == 0) { char* ptr; long laux; laux = strtol(argv[i+1], &ptr, 10); max_binding_iterators = laux; } if (strcmp(argv[i], "--ior") == 0) { if (i == argc - 1) { cerr << "Error: --ior specified but no file name given" << endl; printUsage(argv[0]); _exit(-1); } ior_file = argv[i+1]; } } DMSG("Executing in debug mode, a lot of messages will be "\ "printed to stderr"); DMSG_P("Using '", persistence_dir, "' as persistence directory"); DMSG_P("Using '", ior_file, "' as ior output file"); char * port = strdup("2809"); char * ssl_port = strdup(""); bool port_given = false; bool ssl_port_given = false; bool ssl_config = false; try { // // Start TIDThread library // TIDThr::init(); // // Check for -ORB_iiop_orb_port to set NameService default // int new_argc = argc + 2; char * new_argv[new_argc]; for (int i = 1; i < argc; i++) { new_argv[i] = argv[i]; // No strdup is needed if (strcmp(argv[i], "-ORB_iiop_orb_port") == 0) { port_given = true; free(port); port = strdup(argv[i+1]); } if (strcmp(argv[i], "-ORB_ssl_port") == 0) { ssl_port_given = true; // util?? free(ssl_port); ssl_port = strdup(argv[i+1]); } if (strcmp(argv[i], "-ORB_ssl_private_key") == 0) { for (int j = 1; j < argc; j++) { if (strcmp(argv[j], "-ORB_ssl_certificate") == 0) { ssl_config = true; break; } } } } new_argv[new_argc - 2] = "-ORB_iiop_orb_port"; new_argv[new_argc - 1] = port; int orb_argc = port_given ? argc : new_argc; char ** orb_argv = port_given ? argv : new_argv; // // ORB initialization // my_global_orb = CORBA::ORB_init(orb_argc, orb_argv); // Get internal ORB TIDorb::core::TIDORB* m_orb = dynamic_cast<TIDorb::core::TIDORB*> (CORBA::ORB::_duplicate(my_global_orb)); // // Getting RootPOA & Manager references // CORBA::Object_var poa_obj = my_global_orb->resolve_initial_references("RootPOA"); PortableServer::POA_ptr rootPOA = PortableServer::POA::_narrow(poa_obj); PortableServer::POAManager_var manager = rootPOA->the_POAManager(); // // NamingContexts POA creation // CORBA::PolicyList policies; policies.length(4); policies[0] = rootPOA->create_servant_retention_policy(PortableServer::RETAIN); policies[1] = rootPOA->create_request_processing_policy( PortableServer::USE_SERVANT_MANAGER); policies[2] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID); policies[3] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT); PortableServer::POA_var namingContextsPOA = rootPOA->create_POA("namingContextsPOA", manager, policies); PortableServer::POAManager_var namingContextsManager = namingContextsPOA->the_POAManager(); // // BindingIterators POA creation // CORBA::PolicyList bindingIterators_policies; bindingIterators_policies.length(2); bindingIterators_policies[0] = rootPOA->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL); bindingIterators_policies[1] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID); PortableServer::POA_var bindingIteratorsPOA = namingContextsPOA->create_POA("bindingIteratorsPOA", namingContextsManager, bindingIterators_policies); // // Creates and sets a new ServantManager // TIDNaming::ServantManagerNSImpl* servant_manager = new TIDNaming::ServantManagerNSImpl(my_global_orb, bindingIteratorsPOA, max_binding_iterators); namingContextsPOA->set_servant_manager(servant_manager); // Creates the reference to the "root.ctx". Dont create it // This fragment of code is not needed anymore. It creates the // initial reference to root naming context, now created from // PersistenceManager class. /* PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("root.ctx"); // Change to "NameService" CORBA::Object_var obj = namingContextsPOA->create_reference_with_id(oid,"IDL:omg.org/CosNaming/NamingContextExt:1.0"); */ // Manager activation (ORB/POA staff) manager->activate(); namingContextsManager->activate(); // // Check if has persistence // if (strcmp(persistence_dir, "") != 0) { if (m_orb->trace != NULL){ TIDorb::util::StringBuffer msg; msg << "Using '" << persistence_dir << "' as persistence directory"; m_orb->print_trace(TIDorb::util::TR_USER, msg.str().data()); } // // Recover the persistent data // try { TIDNaming::NamingContextFileIOFactory::init(persistence_dir); } catch (TIDNaming::NamingContextFileIOFactory::InvalidPathException & e) { if (m_orb->trace != NULL) { TIDorb::util::StringBuffer msg; msg << "Error: cannot initialize persistence directory '"; msg << e.path << "'"; m_orb->print_trace(TIDorb::util::TR_ERROR, msg.str().data()); } printUsage(argv[0]); _exit(-1); } loadPersistence(namingContextsPOA.inout(), bindingIteratorsPOA.inout(), ior_file); } else { // // Start without persistent data // try { TIDNaming::NamingContextNullIOFactory::init(); } catch (...) { printUsage(argv[0]); _exit(-1); } if (m_orb->trace != NULL) m_orb->print_trace(TIDorb::util::TR_USER, "No root context found. Initializing a new one... "); CosNaming::NamingContext_var root_nc = createNamingContextReference(namingContextsPOA, NamingInternals::RootNamingContextOID); // Get ssl system assigned port if (ssl_config && (!ssl_port_given)) { TIDorb::portable::Stub* stub_obj = dynamic_cast<TIDorb::portable::Stub*> ((CORBA::Object*)root_nc); TIDorb::core::ObjectDelegateImpl* obj_delegate = dynamic_cast<TIDorb::core::ObjectDelegateImpl*> (stub_obj->_get_delegate()); TIDorb::core::iop::IOR* ior = obj_delegate->getReference(); SSLIOP::SSL* _ssl = ior->get_SSL(); free(ssl_port); ssl_port = (char*)malloc(6); sprintf(ssl_port, "%d", _ssl->port); } registerNameService(my_global_orb, root_nc, ior_file); if (m_orb->trace != NULL) m_orb->print_trace(TIDorb::util::TR_DEBUG, "Done"); } // // Run the ORB loop forever // TIDorb::util::StringBuffer msg; msg << "Serving at port " << port << "... " << endl; if (ssl_config) { msg.seekp(0, ios::beg); msg << "Serving at SSL port " << ssl_port << "... " << endl; } if (m_orb->trace != NULL) m_orb->print_trace(TIDorb::util::TR_USER, msg.str().data()); cerr << msg.str().data(); my_global_orb->run(); my_global_orb->destroy(); } catch (const CORBA::INITIALIZE & ex) { cerr << "ERROR: cannot initialize Naming Service at port "; if (ssl_config) cerr << ssl_port; else cerr << port; cerr << " due to: " << ex << endl; } catch (const CORBA::Exception& ex) { cerr << "ERROR: Naming Server Exception: " << ex << endl << flush; exit (1); } catch (...) { cerr << "ERROR: unexpected exception raised" << endl << flush; exit (1); } free(port); free(ssl_port); }
int Consumer::run (int argc, ACE_TCHAR* argv[]) { try { // ORB initialization boiler plate... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Do *NOT* make a copy because we don't want the ORB to outlive // the run() method. this->orb_ = orb.in (); CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Obtain the event channel from the naming service CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService"); if (CORBA::is_nil (naming_obj.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to get the Naming Service.\n"), 1); CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow (naming_obj.in ()); CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup ("EventService"); CORBA::Object_var ec_obj = naming_context->resolve (name); RtecEventChannelAdmin::EventChannel_var event_channel = RtecEventChannelAdmin::EventChannel::_narrow (ec_obj.in ()); // The canonical protocol to connect to the EC RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin = event_channel->for_consumers (); RtecEventChannelAdmin::ProxyPushSupplier_var supplier = consumer_admin->obtain_push_supplier (); RtecEventComm::PushConsumer_var consumer = this->_this (); // Simple subscription, but usually the helper classes in // $TAO_ROOT/orbsvcs/Event_Utils.h are a better way to do this. RtecEventChannelAdmin::ConsumerQOS qos; qos.dependencies.length (2); RtecEventComm::EventHeader& h0 = qos.dependencies[0].event.header; h0.type = ACE_ES_DISJUNCTION_DESIGNATOR; h0.source = ACE_ES_EVENT_SOURCE_ANY; RtecEventComm::EventHeader& h1 = qos.dependencies[1].event.header; h1.type = ACE_ES_EVENT_UNDEFINED; // first free event type h1.source = ACE_ES_EVENT_SOURCE_ANY; supplier->connect_push_consumer (consumer.in (), qos); // Wait for events, using work_pending()/perform_work() may help // or using another thread, this example is too simple for that. orb->run (); // We don't do any cleanup, it is hard to do it after shutdown, // and would complicate the example; plus it is almost // impossible to do cleanup after ORB->run() because the POA is // in the holding state. Applications should use // work_pending()/perform_work() to do more interesting stuff. // Check the supplier for the proper way to do cleanup. } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Consumer::run"); return 1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR* argv[]) { #if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1) try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); TAO_Notify_Service* notify_service = TAO_Notify_Service::load_default (); if (notify_service == 0) { error ("Unable to load the Notify Service"); } notify_service->init_service (orb.in ()); ACE_OS::sleep (1); const ACE_CString ecf_name ("MonitoringEventChannelFactory"); CosNotifyChannelAdmin::EventChannelFactory_var ecf = notify_service->create (poa.in (), ecf_name.c_str ()); NotifyMonitoringExt::EventChannelFactory_var monitor_ec_factory = NotifyMonitoringExt::EventChannelFactory::_narrow (ecf.in ()); if (CORBA::is_nil (monitor_ec_factory.in ())) { error ("Unable to create the Monitoring Event Channel Factory"); } CosNotification::QoSProperties qos_prop; CosNotification::AdminProperties admin_prop; CosNotifyChannelAdmin::ChannelID id; const ACE_CString ec_name ("test1"); CosNotifyChannelAdmin::EventChannel_var ec = monitor_ec_factory->create_named_channel (qos_prop, admin_prop, id, ec_name.c_str ()); NotifyMonitoringExt::EventChannel_var mec = NotifyMonitoringExt::EventChannel::_narrow (ec.in ()); if (CORBA::is_nil (mec.in ())) { error ("Unable to narrow the event channel"); } try { CosNotifyChannelAdmin::ChannelID fake_id; CosNotifyChannelAdmin::EventChannel_var fake = monitor_ec_factory->create_named_channel (qos_prop, admin_prop, fake_id, "test1"); error ("Expected a NotifyMonitoringExt::" "NameAlreadyUsed exception"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { // This is expected. } Monitor_Point_Registry* instance = Monitor_Point_Registry::instance (); ACE_CString stat_name = ecf_name + "/" + ACE_CString (NotifyMonitoringExt::InactiveEventChannelCount); Monitor_Base* stat = instance->get (stat_name); if (stat == 0) { error ("Could not find InactiveEventChannelCount statistic"); } stat->update (); double count = stat->last_sample (); if (!ACE::is_equal (count, 1.0)) { error ("Invalid inactive event channel count"); } stat_name = ecf_name + "/" + ACE_CString (NotifyMonitoringExt::ActiveEventChannelCount); stat = instance->get (stat_name); if (stat == 0) { error ("Could not find ActiveEventChannelCount statistic"); } stat->update (); count = stat->last_sample (); if (!ACE::is_equal (count, 0.0)) { error ("Invalid active event channel count"); } stat_name = ecf_name + "/" + ACE_CString (NotifyMonitoringExt::InactiveEventChannelNames); stat = instance->get (stat_name); if (stat == 0) { error ("Could not find InactiveEventChannels statistic"); } stat->update (); Monitor_Control_Types::NameList list = stat->get_list (); if (list.size () != 1) { error ("Invalid inactive event channel list"); } ACE_CString full_ec_name (ecf_name + "/" + ec_name); if (list[0] != full_ec_name) { error ("Wrong event channel name"); } CosNotifyChannelAdmin::AdminID aid; CosNotifyChannelAdmin::SupplierAdmin_var admin = mec->named_new_for_suppliers (CosNotifyChannelAdmin::AND_OP, aid, "TestSupplierAdmin"); try { admin = mec->named_new_for_suppliers (CosNotifyChannelAdmin::AND_OP, aid, "TestSupplierAdmin"); error ("Expected a SupplierAdmin " "NotifyMonitoringExt::NameAlreadyUsed exception"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { // This is expected. }; // We should be able to create another one with the same name. admin->destroy (); admin = mec->named_new_for_suppliers (CosNotifyChannelAdmin::AND_OP, aid, "TestSupplierAdmin"); NotifyMonitoringExt::SupplierAdmin_var madmin = NotifyMonitoringExt::SupplierAdmin::_narrow (admin.in ()); if (CORBA::is_nil (madmin.in ())) { error ("Could not narrow the supplier admin"); } CosNotifyChannelAdmin::ProxyID pid; CosNotifyChannelAdmin::ProxyConsumer_var conproxy = madmin->obtain_named_notification_push_consumer ( CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "supplier"); try { CosNotifyChannelAdmin::ProxyConsumer_var fake = madmin->obtain_named_notification_push_consumer (CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "supplier"); error ("Expected a ProxyConsumer " "NotifyMonitoringExt::NameAlreadyUsed exception"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { // This is expected. } stat_name = ecf_name + "/" + ec_name + "/" + ACE_CString (NotifyMonitoringExt::EventChannelSupplierCount); stat = instance->get (stat_name); if (stat == 0) { error ("Could not find the event channel suppliers statistic"); } stat->update (); count = stat->last_sample (); if (!ACE::is_equal (count, 1.0)) { error ("Invalid supplier count"); } CosNotifyChannelAdmin::StructuredProxyPushConsumer_var push_conproxy = CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow ( conproxy.in ()); ACE_ASSERT (!CORBA::is_nil (push_conproxy.in ())); push_conproxy->disconnect_structured_push_consumer (); try { CosNotifyChannelAdmin::ProxyConsumer_var fake = madmin->obtain_named_notification_push_consumer ( CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "supplier"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { error ("Unexpected ProxyConsumer " "NotifyMonitoringExt::NameAlreadyUsed exception"); } CosNotifyChannelAdmin::ConsumerAdmin_var cadmin = mec->named_new_for_consumers (CosNotifyChannelAdmin::AND_OP, aid, "TestConsumerAdmin"); try { cadmin = mec->named_new_for_consumers (CosNotifyChannelAdmin::AND_OP, aid, "TestConsumerAdmin"); error ("Expected a ConsumerAdmin " "NotifyMonitoringExt::NameAlreadyUsed exception"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { // This is expected. }; // We should be able to create another one with the same name cadmin->destroy (); cadmin = mec->named_new_for_consumers (CosNotifyChannelAdmin::AND_OP, aid, "TestConsumerAdmin"); NotifyMonitoringExt::ConsumerAdmin_var mcadmin = NotifyMonitoringExt::ConsumerAdmin::_narrow (cadmin.in ()); if (CORBA::is_nil (mcadmin.in ())) { error ("Could not narrow the consumer admin"); } CosNotifyChannelAdmin::ProxySupplier_var supproxy = mcadmin->obtain_named_notification_push_supplier ( CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "consumer"); try { CosNotifyChannelAdmin::ProxySupplier_var fake = mcadmin->obtain_named_notification_push_supplier ( CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "consumer"); error ("Expected a ProxySupplier " "NotifyMonitoringExt::NameAlreadyUsed exception"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { // This is expected. } stat_name = ecf_name + "/" + ec_name + "/" + ACE_CString (NotifyMonitoringExt::EventChannelConsumerCount); stat = instance->get (stat_name); if (stat == 0) { error ("Could not find the event channel consumers statistic"); } stat->update (); count = stat->last_sample (); if (!ACE::is_equal (count, 1.0)) { error ("Invalid consumer count"); } CosNotifyChannelAdmin::StructuredProxyPushSupplier_var push_supproxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow ( supproxy.in()); ACE_ASSERT (!CORBA::is_nil (push_supproxy.in ())); push_supproxy->disconnect_structured_push_supplier (); try { CosNotifyChannelAdmin::ProxySupplier_var fake = mcadmin->obtain_named_notification_push_supplier ( CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "consumer"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { error ("Unexpected ProxySupplier " "NotifyMonitoringExt::NameAlreadyUsed exception"); } TAO_MonitorManager::shutdown (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("MonitorControlExt: "); } catch (...) { error ("Caught an unexpected exception type"); } #else /* ACE_HAS_MONITOR_FRAMEWORK==1 */ ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); #endif /* TAO_HAS_MONITOR_FRAMEWORK==1 */ return 0; }
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 ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { TAO_EC_Default_Factory::init_svcs (); try { // ORB initialization boiler plate... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) == -1) { ACE_ERROR ((LM_ERROR, "Usage: Service [-o IOR_file_name]\n")); return 1; } CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // **************************************************************** #if 0 // Obtain a reference to the naming service... CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService"); CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow (naming_obj.in ()); #endif /* 0 */ // **************************************************************** // Create an scheduling service POA_RtecScheduler::Scheduler* sched_impl = 0; if (config_run) { ACE_NEW_RETURN (sched_impl, RECONFIG_SCHED_TYPE, 1); } else { ACE_NEW_RETURN (sched_impl, RECONFIG_SCHED_TYPE (configs_size, configs, infos_size, infos, 0, 0, 0), 1); } RtecScheduler::Scheduler_var scheduler = sched_impl->_this (); #if 0 // Bind the scheduler with the naming service so clients // (consumers and suppliers) can resolve it, some (old) // implementations of the EC will try to do the same thing // (yikes!) CosNaming::Name schedule_name (1); schedule_name.length (1); schedule_name[0].id = CORBA::string_dup ("ScheduleService"); // Register the servant with the Naming Context.... naming_context->rebind (schedule_name, scheduler.in ()); #endif /* 0 */ // **************************************************************** TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); attributes.scheduler = scheduler.in (); // no need to dup TAO_EC_Event_Channel ec_impl (attributes); ACE_DEBUG ((LM_DEBUG, "activating EC\n")); ec_impl.activate (); ACE_DEBUG ((LM_DEBUG, "EC activated\n")); RtecEventChannelAdmin::EventChannel_var event_channel = ec_impl._this (); // **************************************************************** // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... Consumer consumer_impl; RtecScheduler::handle_t consumer_rt_info1 = scheduler->create ("consumer_event_1"); // Let's say that the execution time for event 1 is 2 // milliseconds... ACE_Time_Value tv (0, 2000); TimeBase::TimeT time; ORBSVCS_Time::Time_Value_to_TimeT (time, tv); scheduler->set (consumer_rt_info1, RtecScheduler::VERY_HIGH_CRITICALITY, time, time, time, 0, RtecScheduler::VERY_LOW_IMPORTANCE, time, 0, RtecScheduler::OPERATION); RtecScheduler::handle_t consumer_rt_info2 = scheduler->create ("consumer_event_2"); // Let's say that the execution time for event 2 is 1 // milliseconds... tv.set (0, 1000); ORBSVCS_Time::Time_Value_to_TimeT (time, tv); scheduler->set (consumer_rt_info2, RtecScheduler::VERY_LOW_CRITICALITY, time, time, time, 0, RtecScheduler::VERY_LOW_IMPORTANCE, time, 0, RtecScheduler::OPERATION); ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_disjunction_group (); // The types int the range [0,ACE_ES_EVENT_UNDEFINED) are // reserved for the EC... consumer_qos.insert_type (ACE_ES_EVENT_UNDEFINED, consumer_rt_info1); consumer_qos.insert_type (ACE_ES_EVENT_UNDEFINED + 1, consumer_rt_info2); // The canonical protocol to connect to the EC RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin = event_channel->for_consumers (); RtecEventChannelAdmin::ProxyPushSupplier_var supplier_proxy = consumer_admin->obtain_push_supplier (); RtecEventComm::PushConsumer_var consumer = consumer_impl._this (); ACE_DEBUG ((LM_DEBUG, "connecting consumer\n")); supplier_proxy->connect_push_consumer (consumer.in (), consumer_qos.get_ConsumerQOS ()); ACE_DEBUG ((LM_DEBUG, "consumer connected\n")); // **************************************************************** Supplier supplier_impl; RtecScheduler::handle_t supplier_rt_info1 = scheduler->create ("supplier_event_1"); // The execution times are set to reasonable values, but // actually they are changed on the real execution, i.e. we // lie to the scheduler to obtain right priorities; but we // don't care if the set is schedulable. tv.set (0, 10000); TimeBase::TimeT tmp; ORBSVCS_Time::Time_Value_to_TimeT (tmp, tv); RtecScheduler::Period_t rate = ACE_U64_TO_U32(tmp); scheduler->set (supplier_rt_info1, RtecScheduler::VERY_HIGH_CRITICALITY, 0, 0, 0, rate, RtecScheduler::VERY_LOW_IMPORTANCE, 0, 1, RtecScheduler::OPERATION); RtecScheduler::handle_t supplier_rt_info2 = scheduler->create ("supplier_event_2"); // The execution times are set to reasonable values, but // actually they are changed on the real execution, i.e. we // lie to the scheduler to obtain right priorities; but we // don't care if the set is schedulable. tv.set (0, 20000); ORBSVCS_Time::Time_Value_to_TimeT (tmp, tv); rate = ACE_U64_TO_U32(tmp); scheduler->set (supplier_rt_info2, RtecScheduler::VERY_HIGH_CRITICALITY, 0, 0, 0, rate, RtecScheduler::VERY_LOW_IMPORTANCE, 0, 1, RtecScheduler::OPERATION); RtecEventComm::EventSourceID supplier_id = 1; ACE_SupplierQOS_Factory supplier_qos; supplier_qos.insert (supplier_id, ACE_ES_EVENT_UNDEFINED, supplier_rt_info1, 1 /* number of calls, but what does that mean? */); supplier_qos.insert (supplier_id, ACE_ES_EVENT_UNDEFINED + 1, supplier_rt_info2, 1 /* number of calls, but what does that mean? */); // The canonical protocol to connect to the EC RtecEventChannelAdmin::SupplierAdmin_var supplier_admin = event_channel->for_suppliers (); RtecEventChannelAdmin::ProxyPushConsumer_var consumer_proxy = supplier_admin->obtain_push_consumer (); RtecEventComm::PushSupplier_var supplier = supplier_impl._this (); ACE_DEBUG ((LM_DEBUG, "connecting supplier\n")); consumer_proxy->connect_push_supplier (supplier.in (), supplier_qos.get_SupplierQOS ()); ACE_DEBUG ((LM_DEBUG, "supplier connected\n")); // **************************************************************** // At this point the consumer and supplier are connected to the // EC, they have provided their QoS info to the Scheduling // Service and the EC has informed the Scheduler about the // dependencies between them. // We can now compute the schedule for this configuration... // The schedule is returned in this variables.... if (config_run) { ACE_DEBUG ((LM_DEBUG, "Computing schedule\n")); RtecScheduler::RT_Info_Set_var infos; RtecScheduler::Dependency_Set_var deps; RtecScheduler::Config_Info_Set_var configs; RtecScheduler::Scheduling_Anomaly_Set_var anomalies; // Obtain the range of valid priorities in the current // platform, the scheduler hard-code this values in the // generated file, but in the future we may just use the // "logical" priorities and define the mapping to OS // priorities at run-time. int min_os_priority = ACE_Sched_Params::priority_min (ACE_SCHED_FIFO, ACE_SCOPE_THREAD); int max_os_priority = ACE_Sched_Params::priority_max (ACE_SCHED_FIFO, ACE_SCOPE_THREAD); scheduler->compute_scheduling (min_os_priority, max_os_priority, infos.out (), deps.out (), configs.out (), anomalies.out ()); // Dump the schedule to a file.. ACE_Scheduler_Factory::dump_schedule (infos.in (), deps.in (), configs.in (), anomalies.in (), ACE_TEXT("schedule.out")); } // **************************************************************** ACE_DEBUG ((LM_DEBUG, "Pushing events\n")); // Generate a few events.... RtecEventComm::EventSet event1 (1); event1.length (1); event1[0].header.type = ACE_ES_EVENT_UNDEFINED; event1[0].header.source = supplier_id; event1[0].header.ttl = 1; RtecEventComm::EventSet event2 (1); event2.length (1); event2[0].header.type = ACE_ES_EVENT_UNDEFINED + 1; event2[0].header.source = supplier_id; event2[0].header.ttl = 1; for (int i = 0; i != 200; ++i) { if (i % 2 == 0) { consumer_proxy->push (event1); } else { consumer_proxy->push (event2); } ACE_Time_Value rate (0, 10000); ACE_OS::sleep (rate); } // **************************************************************** // We should do a lot of cleanup (disconnect from the EC, // deactivate all the objects with the POA, etc.) but this is // just a simple demo so we are going to be lazy. } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Service"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) { return 1; } CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); ORB_Task worker (orb.in ()); worker.activate (THR_NEW_LWP | THR_JOINABLE, 1); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager (); CORBA::PolicyList policies (5); policies.length (5); // Lifespan policy policies[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT); // Servant Retention Policy policies[1] = rootPOA->create_servant_retention_policy (PortableServer::RETAIN ); // ID Assignment Policy policies[2] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID ); // Request Processing Policy policies[3] = rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY ); // Threading policy policies[4] = rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL); if (server_notify_delay > 0) { ACE_OS::sleep (server_notify_delay); ACE_DEBUG ((LM_DEBUG, "(%P|%t)ServerB Now register with IMR \n")); } PortableServer::POA_var poa_a = rootPOA->create_POA ("poaB", poa_manager.in (), policies ); for (CORBA::ULong i = 0; i < policies.length (); ++i) { CORBA::Policy_ptr policy = policies[i]; policy->destroy (); } Test_Dummy_i* dummy = new Test_Dummy_i(); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("Server_B"); poa_a->activate_object_with_id (oid.in (), dummy); CORBA::Object_var dummy_obj = poa_a->id_to_reference(oid.in()); CORBA::String_var ior = orb->object_to_string (dummy_obj.in ()); poa_manager->activate (); // 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, "Cannot open output file for writing IOR: %s", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); worker.wait (); rootPOA->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception &ex) { ex._tao_print_exception ("Exception caught by serverB:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) { return 1; } CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager (); CORBA::PolicyList policies (5); policies.length (5); // Lifespan policy policies[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT); // Servant Retention Policy policies[1] = rootPOA->create_servant_retention_policy (PortableServer::RETAIN ); // ID Assignment Policy policies[2] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID ); // Request Processing Policy policies[3] = rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY ); // Threading policy policies[4] = rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL); PortableServer::POA_var poa_a = rootPOA->create_POA ("poaA", poa_manager.in (), policies ); PortableServer::POA_var poa_c = rootPOA->create_POA ("poaC", poa_manager.in (), policies ); for (CORBA::ULong i = 0; i < policies.length (); ++i) { CORBA::Policy_ptr policy = policies[i]; policy->destroy (); } Test_Time_i* time = new Test_Time_i(); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("Server_A"); poa_a->activate_object_with_id (oid.in (), time); CORBA::Object_var time_obj = poa_a->id_to_reference(oid.in()); CORBA::String_var ior = orb->object_to_string (time_obj.in ()); poa_manager->activate (); FILE *output_file = ACE_OS::fopen (pid_file, ACE_TEXT ("w")); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Cannot open output file for writing IOR: %s\n"), pid_file), 1); int pid = static_cast<int> (ACE_OS::getpid ()); ACE_OS::fprintf (output_file, "%d\n", pid); ACE_OS::fclose (output_file); orb->run (); rootPOA->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception &ex) { ex._tao_print_exception (ACE_TEXT ("server:")); return 1; } return 0; }
/** * Register this object. */ int ReplicationManagerFaultConsumerAdapter::init ( CORBA::ORB_ptr orb) { ACE_DEBUG (( LM_DEBUG, ACE_TEXT ("Entered ReplicationManagerFaultConsumerAdapter::init.\n") )); int result = 0; this->orb_ = CORBA::ORB::_duplicate (orb); ////////////////////////////////////////// // resolve reference to detector factory ACE_DEBUG (( LM_DEBUG, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Getting ready to read iorDetectorFile.\n") )); CORBA::Object_var detector_obj = this->orb_->string_to_object ( this->detector_ior_); this->factory_ = ::FT::FaultDetectorFactory::_narrow ( detector_obj.in()); if (CORBA::is_nil (this->factory_.in())) { ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("FaultDetectorFactory IOR is nil: %s\n"), this->detector_ior_), -1); } ////////////////////////////////////////// // resolve references to notifier ACE_DEBUG (( LM_DEBUG, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Getting ready to read Notifier IOR file.\n") )); CORBA::Object_var notifier_ior = this->orb_->string_to_object ( this->notifier_ior_); this->notifier_ = ::FT::FaultNotifier::_narrow ( notifier_ior.in()); if (CORBA::is_nil (this->notifier_.in())) { ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("FaultNotifier IOR is nil: %s\n"), this->notifier_ior_), -1); } // Create the real FaultConsumer. // // Note: We have to hang onto the servant class pointer so we can // invoke member functions on it, but we also give ownership of it // to a PortableServer::ServantBase_var. ACE_DEBUG (( LM_DEBUG, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Getting ready to create the real FaultConsumer.\n") )); ACE_NEW_RETURN (this->p_fault_consumer_, TAO::FT_FaultConsumer (), -1); if (this->p_fault_consumer_ != 0) { this->consumer_servant_ = this->p_fault_consumer_; } ////////////////////////// // Get ready to initialize the consumer. We need to provide it // with the following: // - The POA in which it is to be activated. // - FT::FaultNotifier IOR. // - FT::ReplicationManager IOR (fake it for now). // Get the RootPOA from the ORB. CORBA::Object_var poa_obj = this->orb_->resolve_initial_references ( "RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow ( poa_obj.in()); // Create a fault analyzer. TAO::FT_FaultAnalyzer * analyzer = 0; ACE_NEW_RETURN (analyzer, TAO::FT_DefaultFaultAnalyzer (), -1); // Initialize the FaultConsumer. // It will activate itself in the POA we pass it and connect to the // Fault Notifier we pass it. ACE_DEBUG (( LM_DEBUG, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Getting ready to initialize the real FaultConsumer.\n") )); result = this->p_fault_consumer_->init ( poa.in(), this->notifier_.in(), analyzer); if (result != 0) { ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Unable to initialize the real FaultConsumer.\n")), result); } this->identity_ = "ReplicationManagerFaultConsumerAdapter"; // Activate the RootPOA. PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); ///////////////////////// // Set up fault detectors if (result == 0) { //////////////////////////////////// // resolve references to replicas // create a fault detector for each replica size_t replicaCount = this->replica_iors_.size(); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Number of replicas being monitored: (%u)\n"), static_cast<unsigned int> (replicaCount) )); for (size_t nRep = 0; result == 0 && nRep < replicaCount; ++nRep) { const char * iorName = this->replica_iors_[nRep]; CORBA::Object_var replica_obj = this->orb_->string_to_object ( iorName); FT::PullMonitorable_var replica = FT::PullMonitorable::_narrow ( replica_obj.in()); if (CORBA::is_nil(replica.in())) { ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Can't resolve Replica IOR: %s\n"), iorName), -1); } else { this->replicas_.push_back(replica); CORBA::String_var type_id = CORBA::string_dup("FaultDetector"); TAO_PG::Properties_Encoder encoder; PortableGroup::Value value; value <<= notifier_.in (); encoder.add(::FT::FT_NOTIFIER, value); value <<= replica.in (); encoder.add(::FT::FT_MONITORABLE, value); FT::FTDomainId domain_id = 0; value <<= domain_id; encoder.add(::FT::FT_DOMAIN_ID, value); PortableGroup::Location object_location; object_location.length(2); object_location[0].id = CORBA::string_dup("test"); object_location[1].id = CORBA::string_dup("Location_A"); value <<= object_location; encoder.add(::FT::FT_LOCATION, value); PortableGroup::TypeId_var object_type = CORBA::string_dup ( "IDL:org.omg/CosNaming/NamingContextExt:1.0"); value <<= object_type.in (); encoder.add(::FT::FT_TYPE_ID, value); PortableGroup::ObjectGroupId group_id = static_cast<PortableGroup::ObjectGroupId> (6191982); value <<= group_id; encoder.add(::FT::FT_GROUP_ID, value); // allocate and populate the criteria PortableGroup::Criteria_var criteria; ACE_NEW_NORETURN (criteria, PortableGroup::Criteria); if (criteria.ptr() == 0) { ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Error cannot allocate criteria.\n")), -1); } else { encoder.encode(criteria); PortableGroup::GenericFactory::FactoryCreationId_var factory_creation_id; this->factory_->create_object ( type_id.in(), criteria.in(), factory_creation_id); } } } // Signal that we are ready to go. if (result == 0 && this->readyFile_ != 0) { FILE* ready = ACE_OS::fopen (this->readyFile_, "w"); if (ready) { ACE_OS::fprintf (ready, "ready\n"); ACE_OS::fclose (ready); } } } return result; }
int main(int argc, char *argv[]) { int wsize=0; double maxEdgeLen=0.0; bool useDefaultLights=true; float bgColor[3]={0,0,0}; for (int i=1; i<argc; i++){ if (strcmp(argv[i], "-size")==0){ wsize = atoi(argv[++i]); }else if(strcmp(argv[i], "-max-edge-length")==0){ maxEdgeLen = atof(argv[++i]); }else if(strcmp(argv[i], "-no-default-lights")==0){ useDefaultLights=false; }else if(strcmp(argv[i], "-bg")==0){ bgColor[0] = atof(argv[++i]); bgColor[1] = atof(argv[++i]); bgColor[2] = atof(argv[++i]); }else if(strcmp(argv[i], "-h")==0 || strcmp(argv[i], "--help")==0){ print_usage(argv[0]); return 1; } } CORBA::ORB_var orb = CORBA::ORB::_nil(); try { orb = CORBA::ORB_init(argc, argv); CORBA::Object_var obj; obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); if(CORBA::is_nil(poa)){ throw std::string("error: failed to narrow root POA."); } PortableServer::POAManager_var poaManager = poa->the_POAManager(); if(CORBA::is_nil(poaManager)){ throw std::string("error: failed to narrow root POA manager."); } LogManager<OpenHRP::WorldState> log; GLscene scene(&log); scene.setBackGroundColor(bgColor); scene.maxEdgeLen(maxEdgeLen); OnlineViewer_impl* OnlineViewerImpl = new OnlineViewer_impl(orb, poa, &scene, &log); poa->activate_object(OnlineViewerImpl); OnlineViewer_var OnlineViewer = OnlineViewerImpl->_this(); OnlineViewerImpl->_remove_ref(); obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(obj); if(CORBA::is_nil(namingContext)){ throw std::string("error: failed to narrow naming context."); } CosNaming::Name name; name.length(1); name[0].id = CORBA::string_dup("OnlineViewer"); name[0].kind = CORBA::string_dup(""); namingContext->rebind(name, OnlineViewer); poaManager->activate(); if (argc >= 2 && argv[1][0] != '-'){ OpenHRP::ModelLoader_var ml = hrp::getModelLoader(namingContext); if (CORBA::is_nil(ml)){ std::cerr << "openhrp-model-loader is not running" << std::endl; return 1; } OpenHRP::ModelLoader::ModelLoadOption opt; opt.readImage = true; opt.AABBdata.length(0); opt.AABBtype = OpenHRP::ModelLoader::AABB_NUM; GLbody *glbody = new GLbody(); std::string url = argv[1]; if (argv[1][0] != '/'){ char buf[MAXPATHLEN]; std::string cwd = getcwd(buf, MAXPATHLEN); url = cwd + '/' + url; } hrp::BodyPtr body(glbody); body->setName("model"); OpenHRP::BodyInfo_var binfo = ml->getBodyInfoEx(url.c_str(), opt); hrp::loadBodyFromBodyInfo(body, binfo, false, GLlinkFactory); loadShapeFromBodyInfo(glbody, binfo); scene.addBody(body); } GLlink::useAbsTransformToDraw(); GLbody::useAbsTransformToDraw(); SDLwindow window(&scene, &log); window.init(wsize, wsize); if (!useDefaultLights) scene.defaultLights(false); while(window.oneStep()); } catch(OpenHRP::ModelLoader::ModelLoaderException ex){ std::cerr << ex.description << std::endl; } catch (CORBA::SystemException& ex) { std::cerr << ex._rep_id() << std::endl; } catch (const std::string& error){ std::cerr << error << std::endl; } try { orb->destroy(); } catch(...){ } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { CORBA::ORB_var orb; try { orb = CORBA::ORB_init (argc, argv); CORBA::Object_var root_poa_o = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (root_poa_o.in ()); if (CORBA::is_nil (rootPOA.in ())) { ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); } PortableServer::POAManager_var poaMgr = rootPOA->the_POAManager (); poaMgr->activate (); CORBA::PolicyList policies; policies.length (3); policies[0] = rootPOA->create_id_assignment_policy ( PortableServer::SYSTEM_ID); policies[1] = rootPOA->create_implicit_activation_policy ( PortableServer::NO_IMPLICIT_ACTIVATION); policies[2] = rootPOA->create_lifespan_policy ( PortableServer::TRANSIENT); PortableServer::POA_var fooPoa = rootPOA->create_POA ( "FOO_POA", poaMgr.in (), policies ); for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } Foo_i servant; PortableServer::ObjectId_var oid = fooPoa->activate_object( &servant ); CORBA::Object_var obj = fooPoa->id_to_reference (oid.in ()); foo_var client = foo::_narrow (obj.in()); client->check(); if (vc_check(client.in())) { orb->destroy(); return 1; } fooPoa->deactivate_object (oid.in () ); //servant is gone if (vc_check(client.in(), false)) //exception expected { orb->destroy(); return 2; } } catch(...) { return 3; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { TAO_EC_Default_Factory::init_svcs (); try { // ORB initialization boiler plate... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // **************************************************************** TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); attributes.consumer_reconnect = 1; attributes.supplier_reconnect = 1; TAO_EC_Event_Channel ec_impl (attributes); ec_impl.activate (); RtecEventChannelAdmin::EventChannel_var event_channel = ec_impl._this (); // **************************************************************** // Obtain the consumer admin.. RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin = event_channel->for_consumers (); // Obtain the supplier admin.. RtecEventChannelAdmin::SupplierAdmin_var supplier_admin = event_channel->for_suppliers (); // **************************************************************** const int milliseconds = 50; EC_Counting_Supplier first_supplier; first_supplier.activate (consumer_admin.in (), milliseconds); first_supplier.connect (supplier_admin.in (), 0x00001111UL, 0x11110000UL, 0x00001111UL, 0x11110000UL); EC_Counting_Supplier second_supplier; second_supplier.activate (consumer_admin.in (), milliseconds); second_supplier.connect (supplier_admin.in (), 0x01100000UL, 0x00000110UL, 0x01100000UL, 0x00000110UL); // **************************************************************** EC_Counting_Consumer consumer_bitmask_reject ("Consumer/bitmask/reject"); // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... { ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_bitmask (0x00001111, 0x11110000); consumer_qos.start_disjunction_group (1); consumer_qos.insert (0x01100000, 0x00000110, 0); consumer_bitmask_reject.connect (consumer_admin.in (), consumer_qos.get_ConsumerQOS ()); } // **************************************************************** EC_Counting_Consumer consumer_bitmask_accept ("Consumer/bitmask/accept"); // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... { ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_bitmask (0x01100110, 0x01100110); consumer_qos.insert_null_terminator (); consumer_bitmask_accept.connect (consumer_admin.in (), consumer_qos.get_ConsumerQOS ()); } // **************************************************************** EC_Counting_Consumer consumer_bitmask_filter ("Consumer/bitmask/filter"); // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... { ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_bitmask (0x00000110, 0x01100000); consumer_qos.insert_null_terminator (); consumer_bitmask_filter.connect (consumer_admin.in (), consumer_qos.get_ConsumerQOS ()); } // **************************************************************** EC_Counting_Consumer consumer_bitmask_value ("Consumer/bitmask/value"); // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... { ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_disjunction_group (1); consumer_qos.insert_bitmasked_value (0x11110000, 0x00001111, 0x01100000, 0x00000110); consumer_bitmask_value.connect (consumer_admin.in (), consumer_qos.get_ConsumerQOS ()); } // **************************************************************** EC_Counting_Consumer consumer_bitmask_loose ("Consumer/bitmask/loose"); // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... { ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_disjunction_group (1); consumer_qos.insert_bitmasked_value (0x11111111, 0x11111111, 0x01100000, 0x00000110); consumer_bitmask_loose.connect (consumer_admin.in (), consumer_qos.get_ConsumerQOS ()); } // **************************************************************** ACE_Time_Value tv (5, 0); // Wait for events, using work_pending()/perform_work() may help // or using another thread, this example is too simple for that. orb->run (tv); // **************************************************************** consumer_bitmask_loose.disconnect (); consumer_bitmask_value.disconnect (); consumer_bitmask_filter.disconnect (); consumer_bitmask_accept.disconnect (); consumer_bitmask_reject.disconnect (); // **************************************************************** second_supplier.deactivate (); second_supplier.disconnect (); first_supplier.deactivate (); first_supplier.disconnect (); // **************************************************************** event_channel->destroy (); // **************************************************************** poa->destroy (1, 1); // **************************************************************** consumer_bitmask_reject.dump_results (0, 5); CORBA::ULong expected = first_supplier.event_count + second_supplier.event_count; consumer_bitmask_accept.dump_results (expected, 5); expected = second_supplier.event_count; consumer_bitmask_filter.dump_results (expected, 5); expected = second_supplier.event_count; consumer_bitmask_value.dump_results (expected, 5); expected = second_supplier.event_count; consumer_bitmask_loose.dump_results (expected, 5); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Service"); return 1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize orb CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Get reference to Root POA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootpoa = PortableServer::POA::_narrow (obj.in ()); // Activate POA manager PortableServer::POAManager_var mgr = rootpoa->the_POAManager (); mgr->activate (); PortableServer::POA_var poa; TAO::Utils::PolicyList_Destroyer PolicyList (3); PolicyList.length (3); PolicyList [0] = rootpoa->create_lifespan_policy (PortableServer::PERSISTENT); PolicyList [1] = rootpoa->create_id_assignment_policy (PortableServer::USER_ID); CORBA::Any CallbackPolicy; CallbackPolicy <<= BiDirPolicy::BOTH; const char* sServerPoaName = "TelemetryServer"; PolicyList [2] = orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, CallbackPolicy); poa = rootpoa->create_POA (sServerPoaName, mgr.in(), PolicyList); PortableServer::ObjectId_var ServerId = PortableServer::string_to_ObjectId ("TimeServer"); // Create an object Time_impl *time_servant = new Time_impl; PortableServer::ServantBase_var self_manage (time_servant); poa->activate_object_with_id (ServerId.in (), time_servant); // Get a reference after activating the object CORBA::Object_var object = poa->id_to_reference (ServerId.in ()); TimeModule::Time_var tm = TimeModule::Time::_narrow (object.in ()); // Get reference to initial naming context CORBA::Object_var name_obj = orb->resolve_initial_references ("NameService"); CosNaming::NamingContext_var inc = CosNaming::NamingContext::_narrow (name_obj.in ()); if (CORBA::is_nil (inc.in ())) { ACE_ERROR ((LM_ERROR, "(%P|%t) Error fetching naming context\n")); } CosNaming::Name service_name; service_name.length(1); service_name[0].id = CORBA::string_dup ("Time"); inc->rebind (service_name, tm.in ()); // Run the event loop for fun ACE_Time_Value tv (3, 0); // Accept requests orb->run (&tv); rootpoa->destroy (0 , 0); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught an exception\n"); return -1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR* argv[]) { try { // First initialize the ORB, that will remove some arguments... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (argc < 2) { ACE_DEBUG ((LM_DEBUG, "\nUsage:\n %s [NAME to insert in Naming Service]\n", argv[0])); return -1; } // Get a reference to the RootPOA CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); // narrow down to the correct reference PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in ()); // Set a POA Manager PortableServer::POAManager_var poa_manager = poa->the_POAManager (); // Activate the POA Manager poa_manager->activate (); // Create the servant corbaloc_Status_i status_i; status_i.set_name (ACE_TEXT_ALWAYS_CHAR (argv[1])); // Activate it to obtain the reference PortableServer::ObjectId_var id = poa->activate_object (&status_i); CORBA::Object_var object = poa->id_to_reference (id.in ()); corbaloc::Status_var status = corbaloc::Status::_narrow (object.in ()); // Get a reference to Naming Context CORBA::Object_var naming_context_object = orb->resolve_initial_references ("NameService"); // Narrow down the reference CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow (naming_context_object.in ()); // Bind Iterator_Factory to the Naming Context CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (argv[1])); naming_context->rebind (name, status.in ()); // Run the orb orb->run (); // Destroy the POA, waiting until the destruction terminates poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::SystemException& ex){ ex._tao_print_exception ("CORBA exception raised! "); } catch (const CORBA::Exception& ex){ ex._tao_print_exception ("Exception caught in server"); } return 0; }
int main (int argc, char** argv) { std::string output; std::vector<std::string> inputs, filenames; // filenames is for conf file std::string conf_file_option, robothardware_conf_file_option, integrate("true"), dt("0.005"), timeStep(dt), joint_properties, method("EULER"); bool use_highgain_mode(true); struct stat st; bool file_exist_flag = false; for (int i = 1; i < argc; ++ i) { std::string arg(argv[i]); normalize(arg); if ( arg == "--output" ) { if (++i < argc) output = argv[i]; } else if ( arg == "--integrate" ) { if (++i < argc) integrate = argv[i]; } else if ( arg == "--dt" ) { if (++i < argc) dt = argv[i]; } else if ( arg == "--timestep" ) { if (++i < argc) timeStep = argv[i]; } else if ( arg == "--conf-file-option" ) { if (++i < argc) conf_file_option += std::string("\n") + argv[i]; } else if ( arg == "--robothardware-conf-file-option" ) { if (++i < argc) robothardware_conf_file_option += std::string("\n") + argv[i]; } else if ( arg == "--joint-properties" ) { if (++i < argc) joint_properties = argv[i]; } else if ( arg == "--use-highgain-mode" ) { if (++i < argc) use_highgain_mode = (std::string(argv[i])==std::string("true")?true:false); } else if ( arg == "--method" ) { if (++i < argc) method = std::string(argv[i]); } else if ( arg.find("--gtest_output") == 0 ||arg.find("--text") == 0 || arg.find("__log") == 0 || arg.find("__name") == 0 ) { // skip } else { inputs.push_back(argv[i]); } } CORBA::ORB_var orb = CORBA::ORB::_nil(); try { orb = CORBA::ORB_init(argc, argv); CORBA::Object_var obj; obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); if(CORBA::is_nil(poa)) { throw string("error: failed to narrow root POA."); } PortableServer::POAManager_var poaManager = poa->the_POAManager(); if(CORBA::is_nil(poaManager)) { throw string("error: failed to narrow root POA manager."); } xmlTextWriterPtr writer; if (stat(output.c_str(), &st) == 0) { file_exist_flag = true; } writer = xmlNewTextWriterFilename(output.c_str(), 0); xmlTextWriterSetIndent(writer, 4); xmlTextWriterStartElement(writer, BAD_CAST "grxui"); { xmlTextWriterStartElement(writer, BAD_CAST "mode"); xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST "Simulation"); { xmlTextWriterStartElement(writer, BAD_CAST "item"); xmlTextWriterWriteAttribute(writer, BAD_CAST "class", BAD_CAST "com.generalrobotix.ui.item.GrxSimulationItem"); xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST "simulationItem"); { xmlTextWriterWriteProperty(writer, "integrate", integrate); xmlTextWriterWriteProperty(writer, "timeStep", timeStep); xmlTextWriterWriteProperty(writer, "totalTime", "2000000.0"); xmlTextWriterWriteProperty(writer, "method", method); } xmlTextWriterEndElement(writer); // item // default WAIST offset hrp::Vector3 WAIST_offset_pos = hrp::Vector3::Zero(); Eigen::AngleAxis<double> WAIST_offset_rot = Eigen::AngleAxis<double>(0, hrp::Vector3(0,0,1)); // rotation in VRML is represented by axis + angle for (std::vector<std::string>::iterator it = inputs.begin(); it != inputs.end(); it++) { // argument for VRML supports following two mode: // 1. xxx.wrl // To specify VRML file. WAIST offsets is 0 transformation. // 2. xxx.wrl,0,0,0,0,0,1,0 // To specify both VRML and WAIST offsets. // WAIST offset: for example, "0,0,0,0,0,1,0" -> position offset (3dof) + axis for rotation offset (3dof) + angle for rotation offset (1dof) vstring filename_arg_str = split(*it, ","); std::string filename = filename_arg_str[0]; filenames.push_back(filename); if ( filename_arg_str.size () > 1 ){ // if WAIST offset is specified for (size_t i = 0; i < 3; i++) { stringTo(WAIST_offset_pos(i), filename_arg_str[i+1].c_str()); stringTo(WAIST_offset_rot.axis()(i), filename_arg_str[i+1+3].c_str()); } stringTo(WAIST_offset_rot.angle(), filename_arg_str[1+3+3].c_str()); } hrp::BodyPtr body(new hrp::Body()); BodyInfo_impl bI(poa); bI.loadModelFile(filename.c_str()); ModelLoaderHelper2 helper; helper.createBody(body, bI); std::string name = body->name(); xmlTextWriterStartElement(writer, BAD_CAST "item"); xmlTextWriterWriteAttribute(writer, BAD_CAST "class", BAD_CAST "com.generalrobotix.ui.item.GrxRTSItem"); xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST name.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "select", BAD_CAST "true"); xmlTextWriterWriteProperty(writer, name+"(Robot)0.period", dt); if (use_highgain_mode) { xmlTextWriterWriteProperty(writer, "HGcontroller0.period", dt); xmlTextWriterWriteProperty(writer, "HGcontroller0.factory", "HGcontroller"); if (it==inputs.begin()) { xmlTextWriterWriteProperty(writer, "connection", "HGcontroller0.qOut:"+name+"(Robot)0.qRef"); xmlTextWriterWriteProperty(writer, "connection", "HGcontroller0.dqOut:"+name+"(Robot)0.dqRef"); xmlTextWriterWriteProperty(writer, "connection", "HGcontroller0.ddqOut:"+name+"(Robot)0.ddqRef"); } } else { xmlTextWriterWriteProperty(writer, "PDcontroller0.period", dt); xmlTextWriterWriteProperty(writer, "PDcontroller0.factory", "PDcontroller"); if (it==inputs.begin()) { xmlTextWriterWriteProperty(writer, "connection", "PDcontroller0.torque:"+name+"(Robot)0.tauRef"); xmlTextWriterWriteProperty(writer, "connection", ""+name+"(Robot)0.q:PDcontroller0.angle"); } } xmlTextWriterEndElement(writer); // item xmlTextWriterStartElement(writer, BAD_CAST "item"); xmlTextWriterWriteAttribute(writer, BAD_CAST "class", BAD_CAST "com.generalrobotix.ui.item.GrxModelItem"); xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST (basename(*it).c_str())); xmlTextWriterWriteAttribute(writer, BAD_CAST "url", BAD_CAST filename.c_str()); xmlTextWriterWriteProperty(writer, "rtcName", name + "(Robot)0"); if (use_highgain_mode) { xmlTextWriterWriteProperty(writer, "inport", "qRef:JOINT_VALUE"); xmlTextWriterWriteProperty(writer, "inport", "dqRef:JOINT_VELOCITY"); xmlTextWriterWriteProperty(writer, "inport", "ddqRef:JOINT_ACCELERATION"); if (integrate == "false") { // For kinematics only simultion xmlTextWriterWriteProperty(writer, "inport", "basePoseRef:"+body->rootLink()->name+":ABS_TRANSFORM"); } } else { xmlTextWriterWriteProperty(writer, "inport", "tauRef:JOINT_TORQUE"); } xmlTextWriterWriteProperty(writer, "outport", "q:JOINT_VALUE"); xmlTextWriterWriteProperty(writer, "outport", "dq:JOINT_VELOCITY"); xmlTextWriterWriteProperty(writer, "outport", "tau:JOINT_TORQUE"); xmlTextWriterWriteProperty(writer, "outport", body->rootLink()->name+":"+body->rootLink()->name+":ABS_TRANSFORM"); // set outport for sensros int nforce = body->numSensors(hrp::Sensor::FORCE); if ( nforce > 0 ) std::cerr << "hrp::Sensor::FORCE"; for (unsigned int i=0; i<nforce; i++){ hrp::Sensor *s = body->sensor(hrp::Sensor::FORCE, i); // port name and sensor name is same in case of ForceSensor xmlTextWriterWriteProperty(writer, "outport", s->name + ":" + s->name + ":FORCE_SENSOR"); std::cerr << " " << s->name; } if ( nforce > 0 ) std::cerr << std::endl; int ngyro = body->numSensors(hrp::Sensor::RATE_GYRO); if ( ngyro > 0 ) std::cerr << "hrp::Sensor::GYRO"; if(ngyro == 1){ // port is named with no number when there is only one gyro hrp::Sensor *s = body->sensor(hrp::Sensor::RATE_GYRO, 0); xmlTextWriterWriteProperty(writer, "outport", s->name + ":" + s->name + ":RATE_GYRO_SENSOR"); std::cerr << " " << s->name; }else{ for (unsigned int i=0; i<ngyro; i++){ hrp::Sensor *s = body->sensor(hrp::Sensor::RATE_GYRO, i); std::stringstream str_strm; str_strm << s->name << i << ":" + s->name << ":RATE_GYRO_SENSOR"; xmlTextWriterWriteProperty(writer, "outport", str_strm.str()); std::cerr << " " << s->name; } } if ( ngyro > 0 ) std::cerr << std::endl; int nacc = body->numSensors(hrp::Sensor::ACCELERATION); if ( nacc > 0 ) std::cerr << "hrp::Sensor::ACCELERATION"; if(nacc == 1){ // port is named with no number when there is only one acc hrp::Sensor *s = body->sensor(hrp::Sensor::ACCELERATION, 0); xmlTextWriterWriteProperty(writer, "outport", s->name + ":" + s->name + ":ACCELERATION_SENSOR"); std::cerr << " " << s->name; }else{ for (unsigned int i=0; i<nacc; i++){ hrp::Sensor *s = body->sensor(hrp::Sensor::ACCELERATION, i); std::stringstream str_strm; str_strm << s->name << i << ":" << s->name << ":ACCELERATION_SENSOR"; xmlTextWriterWriteProperty(writer, "outport", str_strm.str()); std::cerr << " " << s->name; } } if ( nacc > 0 ) std::cerr << std::endl; // std::string root_name = body->rootLink()->name; xmlTextWriterWriteProperty(writer, root_name+".NumOfAABB", "1"); // write waist pos and rot by considering both VRML original WAIST and WAIST_offset_pos and WAIST_offset_rot from arguments std::ostringstream os; os << body->rootLink()->p[0] + WAIST_offset_pos(0) << " " << body->rootLink()->p[1] + WAIST_offset_pos(1) << " " << body->rootLink()->p[2] + WAIST_offset_pos(2); // 10cm margin xmlTextWriterWriteProperty(writer, root_name+".translation", os.str()); os.str(""); // reset ostringstream Eigen::AngleAxis<double> tmpAA = Eigen::AngleAxis<double>(hrp::Matrix33(body->rootLink()->R * WAIST_offset_rot.toRotationMatrix())); os << tmpAA.axis()(0) << " " << tmpAA.axis()(1) << " " << tmpAA.axis()(2) << " " << tmpAA.angle(); xmlTextWriterWriteProperty(writer, root_name+".rotation", os.str()); if ( ! body->isStaticModel() ) { xmlTextWriterWriteProperty(writer, root_name+".mode", "Torque"); xmlTextWriterWriteProperty(writer, "controller", basename(output)); } // store joint properties // [property 1],[value 1],.... // ex. --joint-properties RARM_JOINT0.angle,0.0,RARM_JOINT2.mode,HighGain,... vstring joint_properties_arg_str = split(joint_properties, ","); std::map <std::string, std::string> joint_properties_map; for (size_t i = 0; i < joint_properties_arg_str.size()/2; i++) { joint_properties_map.insert(std::pair<std::string, std::string>(joint_properties_arg_str[i*2], joint_properties_arg_str[i*2+1])); } if ( body->numJoints() > 0 ) std::cerr << "hrp::Joint"; for(int i = 0; i < body->numJoints(); i++){ if ( body->joint(i)->index > 0 ) { std::cerr << " " << body->joint(i)->name << "(" << body->joint(i)->jointId << ")"; std::string joint_name = body->joint(i)->name; std::string j_property = joint_name+".angle"; xmlTextWriterWriteProperty(writer, j_property, (joint_properties_map.find(j_property) != joint_properties_map.end()) ? joint_properties_map[j_property] : "0.0"); j_property = joint_name+".mode"; xmlTextWriterWriteProperty(writer, j_property, (joint_properties_map.find(j_property) != joint_properties_map.end()) ? joint_properties_map[j_property] : (use_highgain_mode?"HighGain":"Torque")); j_property = joint_name+".NumOfAABB"; xmlTextWriterWriteProperty(writer, j_property, (joint_properties_map.find(j_property) != joint_properties_map.end()) ? joint_properties_map[j_property] : "1"); } } xmlTextWriterEndElement(writer); // item if ( body->numJoints() > 0 ) std::cerr << std::endl; // // comment out self collision settings according to issues at https://github.com/fkanehiro/hrpsys-base/issues/122 // xmlTextWriterStartElement(writer, BAD_CAST "item"); // xmlTextWriterWriteAttribute(writer, BAD_CAST "class", BAD_CAST "com.generalrobotix.ui.item.GrxCollisionPairItem"); // xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST std::string("CP#"+name).c_str()); // xmlTextWriterWriteAttribute(writer, BAD_CAST "select", BAD_CAST "true"); // { // xmlTextWriterWriteProperty(writer, "springConstant", "0 0 0 0 0 0"); // xmlTextWriterWriteProperty(writer, "slidingFriction", "0.5"); // xmlTextWriterWriteProperty(writer, "jointName2", ""); // xmlTextWriterWriteProperty(writer, "jointName1", ""); // xmlTextWriterWriteProperty(writer, "damperConstant", "0 0 0 0 0 0"); // xmlTextWriterWriteProperty(writer, "objectName2", name); // xmlTextWriterWriteProperty(writer, "objectName1", name); // xmlTextWriterWriteProperty(writer, "springDamperModel", "false"); // xmlTextWriterWriteProperty(writer, "staticFriction", "0.5"); // } // xmlTextWriterEndElement(writer); // item xmlTextWriterStartElement(writer, BAD_CAST "view"); xmlTextWriterWriteAttribute(writer, BAD_CAST "class", BAD_CAST "com.generalrobotix.ui.view.GrxRobotHardwareClientView"); xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST "RobotHardware RTC Client"); xmlTextWriterWriteProperty(writer, "robotHost", "localhost"); xmlTextWriterWriteProperty(writer, "StateHolderRTC", "StateHolder0"); xmlTextWriterWriteProperty(writer, "interval", "100"); xmlTextWriterWriteProperty(writer, "RobotHardwareServiceRTC", "RobotHardware0"); xmlTextWriterWriteProperty(writer, "robotPort", "2809"); xmlTextWriterWriteProperty(writer, "ROBOT", name.c_str()); xmlTextWriterEndElement(writer); // item xmlTextWriterStartElement(writer, BAD_CAST "view"); xmlTextWriterWriteAttribute(writer, BAD_CAST "class", BAD_CAST "com.generalrobotix.ui.view.Grx3DView"); xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST "3DView"); xmlTextWriterWriteProperty(writer, "view.mode", "Room"); xmlTextWriterWriteProperty(writer, "showCoM", "false"); xmlTextWriterWriteProperty(writer, "showCoMonFloor", "false"); xmlTextWriterWriteProperty(writer, "showDistance", "false"); xmlTextWriterWriteProperty(writer, "showIntersection", "false"); xmlTextWriterWriteProperty(writer, "eyeHomePosition", "-0.70711 -0 0.70711 2 0.70711 -0 0.70711 2 0 1 0 0.8 0 0 0 1 "); xmlTextWriterWriteProperty(writer, "showCollision", "true"); xmlTextWriterWriteProperty(writer, "showActualState", "true"); xmlTextWriterWriteProperty(writer, "showScale", "true"); xmlTextWriterEndElement(writer); // view } { for (std::vector<std::string>::iterator it1 = inputs.begin(); it1 != inputs.end(); it1++) { std::string name1 = basename(*it1); for (std::vector<std::string>::iterator it2 = it1+1; it2 != inputs.end(); it2++) { std::string name2 = basename(*it2); xmlTextWriterStartElement(writer, BAD_CAST "item"); xmlTextWriterWriteAttribute(writer, BAD_CAST "class", BAD_CAST "com.generalrobotix.ui.item.GrxCollisionPairItem"); xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST std::string("CP#"+name2+"_#"+name1+"_").c_str()); { xmlTextWriterWriteProperty(writer, "springConstant", "0 0 0 0 0 0"); xmlTextWriterWriteProperty(writer, "slidingFriction", "0.5"); xmlTextWriterWriteProperty(writer, "jointName2", ""); xmlTextWriterWriteProperty(writer, "jointName1", ""); xmlTextWriterWriteProperty(writer, "damperConstant", "0 0 0 0 0 0"); xmlTextWriterWriteProperty(writer, "objectName2", name2); xmlTextWriterWriteProperty(writer, "objectName1", name1); xmlTextWriterWriteProperty(writer, "springDamperModel", "false"); xmlTextWriterWriteProperty(writer, "staticFriction", "0.5"); } xmlTextWriterEndElement(writer); // item } } } } xmlTextWriterEndElement(writer); // mode } xmlTextWriterEndElement(writer); // grxui xmlFreeTextWriter(writer); if (file_exist_flag) { std::cerr << "\033[1;31mOver\033[0m"; } std::cerr << "Writing project files to .... " << output << std::endl; { std::string conf_file = output.substr(0,output.find_last_of('.'))+".conf"; if (stat(conf_file.c_str(), &st) == 0) { std::cerr << "\033[1;31mOver\033[0m"; } std::fstream s(conf_file.c_str(), std::ios::out); s << "model: file://" << filenames[0] << std::endl; s << "dt: " << dt << std::endl; s << conf_file_option << std::endl; std::cerr << "Writing conf files to ....... " << conf_file << std::endl; } { std::string conf_file = output.substr(0,output.find_last_of('.'))+".RobotHardware.conf"; if (stat(conf_file.c_str(), &st) == 0) { std::cerr << "\033[1;31mOver\033[0m"; } std::fstream s(conf_file.c_str(), std::ios::out); s << "model: file://" << filenames[0] << std::endl; s << "exec_cxt.periodic.type: hrpExecutionContext" << std::endl; s << "exec_cxt.periodic.rate: " << static_cast<size_t>(1/atof(dt.c_str())+0.5) << std::endl; // rounding to specify integer rate value s << robothardware_conf_file_option << std::endl; std::cerr << "Writing hardware files to ... " << conf_file << std::endl; } } catch (CORBA::SystemException& ex) { cerr << ex._rep_id() << endl; } catch (const string& error) { cerr << error << endl; } try { orb->destroy(); } catch(...) { } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the EC Factory so we can customize the EC TAO_EC_Default_Factory::init_svcs (); // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); const ACE_TCHAR* ecname = ACE_TEXT ("EventService"); const ACE_TCHAR* remote_ecname = 0; const ACE_TCHAR* iorfile = 0; for (int i = 0; argv[i] != 0; i++) { if (ACE_OS::strcmp(argv[i], ACE_TEXT("-ecname")) == 0) { if (argv[i+1] != 0) { i++; ecname = argv[i]; } else { std::cerr << "Missing Event channel name" << std::endl; } } if (ACE_OS::strcmp(argv[i], ACE_TEXT("-gateway")) == 0) { if (argv[i+1] != 0) { i++; remote_ecname = argv[i]; } else { std::cerr << "Missing Event channel name" << std::endl; } } if (ACE_OS::strcmp(argv[i], ACE_TEXT("-iorfile")) == 0) { if (argv[i+1] != 0) { i++; iorfile = argv[i]; } } } // Get the POA CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Spawn a thread for the orb ACE_Thread_Manager *thread_mgr = ACE_Thread_Manager::instance(); thread_mgr->spawn(orb_thread, orb.in()); // Create a local event channel and register it with the RootPOA. TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); PortableServer::Servant_var<TAO_EC_Event_Channel> ec_impl = new TAO_EC_Event_Channel(attributes); ec_impl->activate (); PortableServer::ObjectId_var oid = poa->activate_object(ec_impl.in()); CORBA::Object_var ec_obj = poa->id_to_reference(oid.in()); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(ec_obj.in()); // Find the Naming Service. object = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(object.in()); CosNaming::Name_var name = root_context->to_name (ACE_TEXT_ALWAYS_CHAR (ecname)); root_context->rebind(name.in(), ec.in()); // Get a SupplierAdmin object from the EventChannel. RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); // Get a ProxyPushConsumer from the SupplierAdmin. RtecEventChannelAdmin::ProxyPushConsumer_var consumer = admin->obtain_push_consumer(); // Instantiate an EchoEventSupplier_i servant. PortableServer::Servant_var<EchoEventSupplier_i> servant = new EchoEventSupplier_i(orb.in()); // Register it with the RootPOA. oid = poa->activate_object(servant.in()); CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(supplier_obj.in()); // Publish the events the supplier provides. ACE_SupplierQOS_Factory qos; qos.insert (MY_SOURCE_ID, // Supplier's unique id MY_EVENT_TYPE, // Event type 0, // handle to the rt_info structure 1); // number of calls // Connect as a supplier of the published events. consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); // Create an event (just a string in this case). const CORBA::String_var eventData = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (ecname)); // Create an event set for one event RtecEventComm::EventSet event (1); event.length (1); // Initialize event header. event[0].header.source = MY_SOURCE_ID; event[0].header.ttl = 1; event[0].header.type = MY_EVENT_TYPE; // Initialize data fields in event. event[0].data.any_value <<= eventData; PortableServer::Servant_var<TAO_EC_Gateway_IIOP> gateway = new TAO_EC_Gateway_IIOP; int gateway_initialized = 0; std::cout << "Supplier starting sending of events.\n"; while (1) { consumer->push (event); ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); orb->run(tv); if ((remote_ecname != 0) && (!gateway_initialized)) { try { // Get the remote event channel object CORBA::Object_var obj = root_context->resolve_str (ACE_TEXT_ALWAYS_CHAR (remote_ecname)); RtecEventChannelAdmin::EventChannel_var remote_ec = RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); int ok = 0; if (!CORBA::is_nil(remote_ec.in())) { // Now check if we can talk to it... try { RtecEventChannelAdmin::SupplierAdmin_var adm = remote_ec->for_suppliers(); ok = 1; } catch(const CORBA::UserException&) { // What is the correct exception(s) to catch here? } } // There is a good remote event channel so initialize the // gateway. if (ok) { gateway->init(remote_ec.in(), ec.in()); PortableServer::ObjectId_var gateway_oid = poa->activate_object(gateway.in()); CORBA::Object_var gateway_obj = poa->id_to_reference(gateway_oid.in()); RtecEventChannelAdmin::Observer_var obs = RtecEventChannelAdmin::Observer::_narrow(gateway_obj.in()); RtecEventChannelAdmin::Observer_Handle local_ec_obs_handle = ec->append_observer (obs.in ()); ACE_UNUSED_ARG (local_ec_obs_handle); gateway_initialized = 1; std::cout << "Gateway initialized\n"; if (iorfile != 0) { CORBA::String_var str = orb->object_to_string( ec.in() ); std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(iorfile) ); iorFile << str.in() << std::endl; iorFile.close(); } } } catch(const CosNaming::NamingContext::NotFound&) { // Try again later... } } } orb->destroy(); return 0; } catch(const CORBA::Exception& exc) { std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; } return 1; }
int main( int argc, char *argv[] ) { try { // Initialize orb CORBA::ORB_var orb = CORBA::ORB_init( argc, argv ); // Destringify ior CORBA::Object_var obj = orb->string_to_object( "file://IOR" ); if( CORBA::is_nil( obj.in() ) ) { cerr << "Nil reference" << endl; throw 0; } // Narrow CallbackServer_var cb_server = CallbackServer::_narrow( obj.in() ); if( CORBA::is_nil( cb_server.in() ) ) { cerr << "Argument is not a CallbackServer reference" << endl; throw 0; } //Get reference to Root POA obj = orb->resolve_initial_references( "RootPOA" ); PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() ); // Policies for the childPOA to be created. CORBA::PolicyList policies (4); policies.length (4); CORBA::Any pol; pol <<= BiDirPolicy::BOTH; policies[0] = orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, pol); policies[1] = poa->create_id_assignment_policy(PortableServer::SYSTEM_ID); policies[2] = poa->create_implicit_activation_policy( PortableServer::IMPLICIT_ACTIVATION ); policies[3] = poa->create_lifespan_policy(PortableServer::TRANSIENT); PortableServer::POAManager_var mgr = poa->the_POAManager(); // Create POA as child of RootPOA with the above policies. This POA // will receive request in the same connection in which it sent // the request PortableServer::POA_var child_poa = poa->create_POA ("childPOA", mgr.in(), policies); // Creation of childPOA is over. Destroy the Policy objects. for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } // Activate POA Manager mgr->activate(); // Create an object ClientCallback_i servant; // Register the servant with the RootPOA, obtain its object // reference, stringify it, and write it to a file. obj = child_poa->servant_to_reference( &servant ); //ClientCallback_var ccb = ClientCallback::_narrow( obj.in() ); cb_server->callback_hello( ClientCallback::_narrow( obj.in() ), CORBA::string_dup( "Greetings earthling" )); } catch( const CORBA::Exception &ex ) { cerr << "Uncaught CORBA exception: " << ex << endl; return 1; } }
int main (int argc, char* argv[]) { try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // Find the Naming Service. CORBA::Object_var obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var naming_client = CosNaming::NamingContextExt::_narrow(obj.in()); // Get the Event Channel using Naming Services obj = naming_client->resolve_str("EventService"); // Downcast the object reference to an EventChannel reference. RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); if (CORBA::is_nil(ec.in())) { cerr << "Could not resolve EchoEventChannel." << endl; return 1; } // Get a SupplierAdmin object from the EventChannel. RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); // Get a ProxyPushConsumer from the SupplierAdmin. RtecEventChannelAdmin::ProxyPushConsumer_var consumer = admin->obtain_push_consumer(); // Get the RootPOA. obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); // Instantiate an EchoEventConsumer_i servant. EchoEventSupplier_i servant(orb.in()); // Register it with the RootPOA. PortableServer::ObjectId_var oid = poa->activate_object(&servant); CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(supplier_obj.in()); // Publish the events the supplier provides. ACE_SupplierQOS_Factory qos; qos.insert (MY_SOURCE_ID, // Supplier's unique id MY_EVENT_TYPE, // Event type 0, // handle to the rt_info structure 1); // number of calls // Connect as a supplier of the published events. consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); // Activate the POA via its POAManager. PortableServer::POAManager_var poa_manager = poa->the_POAManager(); poa_manager->activate(); // Create an event (just a string in this case). const CORBA::String_var eventData = CORBA::string_dup("Hello, world."); // Create an event set for one event RtecEventComm::EventSet events (1); events.length (1); // Initialize event header. events[0].header.source = MY_SOURCE_ID; events[0].header.type = MY_EVENT_TYPE; // Initialize data fields in event. events[0].data.any_value <<= eventData; cout << "Supplier starting sending of events" << endl; while (1) { consumer->push (events); ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); orb->run(tv); } orb->destroy(); return 0; } catch (CORBA::Exception& ex) { cerr << "Supplier::main() Caught CORBA::Exception" << endl << ex << endl; } return 1; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // Create a MessengerServer object. MessengerServer * server = new MessengerServer (orb.in()); ACE_Auto_Ptr<MessengerServer> safe_ptr (server); // Parse arguments to determine how we should shutdown. if (server->parse_args (argc, argv) != 0) return 1; //Get reference to the RootPOA. CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" ); PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() ); // Activate the POAManager. PortableServer::POAManager_var mgr = poa->the_POAManager(); mgr->activate(); // Create a servant. Messenger_i messenger_servant (orb.in()); // Register the servant with the RootPOA, obtain its object // reference, stringify it, and write it to a file. PortableServer::ObjectId_var oid = poa->activate_object( &messenger_servant ); CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() ); CORBA::String_var str = orb->object_to_string( messenger_obj.in() ); std::ofstream iorFile(ACE_TEXT_ALWAYS_CHAR (ior_output_file.c_str ())); iorFile << str.in() << std::endl; iorFile.close(); std::cout << "IOR written to file " << ACE_TEXT_ALWAYS_CHAR (ior_output_file.c_str ()) << std::endl; switch (s_method) { // shutdown on client invocation case MessengerServer::s_client_call: std::cout << "Will shutdown on client invocation." << std::endl; server->run (); break; // shutdown after some iterations through loop case MessengerServer::s_polling_loop: server->poll (loop_iterations); break; // schedule a timer to shutdown case MessengerServer::s_timer: server->schedule_shutdown_timer (timeout); server->run (); break; // shutdown on console input case MessengerServer::s_console_input: server->shutdown_on_console_input (); server->run (); break; // use CORBA::ORB::run() with time value case MessengerServer::s_run_time_value: server->run (timeout); break; } } catch(const CORBA::Exception& ex) { std::cerr << "CORBA exception: " << ex << std::endl; return 1; } return 0; }
int main(int argc, char* argv[]) { CORBA::ORB_var orb = CORBA::ORB::_nil(); try { orb = CORBA::ORB_init(argc, argv); CORBA::Object_var obj; obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); if(CORBA::is_nil(poa)){ throw string("error: failed to narrow root POA."); } PortableServer::POAManager_var poaManager = poa->the_POAManager(); if(CORBA::is_nil(poaManager)){ throw string("error: failed to narrow root POA manager."); } ModelLoader_impl* modelLoaderImpl = new ModelLoader_impl(orb, poa); poa->activate_object(modelLoaderImpl); ModelLoader_var modelLoader = modelLoaderImpl->_this(); modelLoaderImpl->_remove_ref(); obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(obj); if(CORBA::is_nil(namingContext)){ throw string("error: failed to narrow naming context."); } CosNaming::Name name; name.length(1); name[0].id = CORBA::string_dup("ModelLoader"); name[0].kind = CORBA::string_dup(""); namingContext->rebind(name, modelLoader); poaManager->activate(); cout << "ready" << endl; orb->run(); } catch (CORBA::SystemException& ex) { cerr << ex._rep_id() << endl; } catch (const string& error){ cerr << error << endl; } try { orb->destroy(); } catch(...){ } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the EC Factory so we can customize the EC TAO_EC_Default_Factory::init_svcs (); // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); const ACE_TCHAR *ecname = ACE_TEXT ("EventService"); const ACE_TCHAR *address = ACE_TEXT ("localhost"); const ACE_TCHAR *iorfile = 0; u_short port = 12345; u_short listenport = 12345; int mcast = 1; for (int i = 0; argv[i] != 0; i++) { if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-ecname")) == 0) { if (argv[i+1] != 0) ecname = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing Event channel name\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-address")) == 0) { if (argv[i+1] != 0) address = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing address\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-port")) == 0) { if (argv[i+1] != 0) port = ACE_OS::atoi(argv[++i]); else ACE_ERROR_RETURN ((LM_ERROR, "Missing port\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-listenport")) == 0) { if (argv[i+1] != 0) listenport = ACE_OS::atoi(argv[++i]); else ACE_ERROR_RETURN ((LM_ERROR, "Missing port\n"), 0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-iorfile")) == 0) { if (argv[i+1] != 0) iorfile = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing ior file\n"), 0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-udp")) == 0) mcast = 0; } // Get the POA CORBA::Object_var tmpobj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (tmpobj.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Create a local event channel and register it TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); TAO_EC_Event_Channel ec_impl (attributes); ec_impl.activate (); PortableServer::ObjectId_var oid = poa->activate_object(&ec_impl); tmpobj = poa->id_to_reference(oid.in()); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(tmpobj.in()); // Find the Naming Service. tmpobj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(tmpobj.in()); // Bind the Event Channel using Naming Services CosNaming::Name_var name = root_context->to_name (ACE_TEXT_ALWAYS_CHAR (ecname)); root_context->rebind(name.in(), ec.in()); // Get a proxy push consumer from the EventChannel. RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); RtecEventChannelAdmin::ProxyPushConsumer_var consumer = admin->obtain_push_consumer(); // Instantiate an EchoEventSupplier_i servant. EchoEventSupplier_i servant(orb.in()); // Register it with the RootPOA. oid = poa->activate_object(&servant); tmpobj = poa->id_to_reference(oid.in()); RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(tmpobj.in()); // Connect to the EC. ACE_SupplierQOS_Factory qos; qos.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); // Initialize the address server with the desired address. This will // be used by the sender object and the multicast receiver only if // one is not otherwise available via the naming service. ACE_INET_Addr send_addr (port, address); SimpleAddressServer addr_srv_impl (send_addr); // Create an instance of the addr server for local use PortableServer::ObjectId_var addr_srv_oid = poa->activate_object(&addr_srv_impl); tmpobj = poa->id_to_reference(addr_srv_oid.in()); RtecUDPAdmin::AddrServer_var addr_srv = RtecUDPAdmin::AddrServer::_narrow(tmpobj.in()); // Create and initialize the sender object PortableServer::Servant_var<TAO_ECG_UDP_Sender> sender = TAO_ECG_UDP_Sender::create(); TAO_ECG_UDP_Out_Endpoint endpoint; // need to be explicit about the address type when built with // IPv6 support, otherwise SOCK_DGram::open defaults to ipv6 when // given a sap_any address. This causes trouble on at least solaris // and windows, or at most on not-linux. if (endpoint.dgram ().open (ACE_Addr::sap_any, send_addr.get_type()) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "Cannot open send endpoint\n"), 1); } // TAO_ECG_UDP_Sender::init() takes a TAO_ECG_Refcounted_Endpoint. // If we don't clone our endpoint and pass &endpoint, the sender will // attempt to delete endpoint during shutdown. TAO_ECG_Refcounted_Endpoint clone (new TAO_ECG_UDP_Out_Endpoint (endpoint)); sender->init (ec.in (), addr_srv.in (), clone); // Setup the subscription and connect to the EC ACE_ConsumerQOS_Factory cons_qos_fact; cons_qos_fact.start_disjunction_group (); cons_qos_fact.insert (ACE_ES_EVENT_SOURCE_ANY, ACE_ES_EVENT_ANY, 0); RtecEventChannelAdmin::ConsumerQOS sub = cons_qos_fact.get_ConsumerQOS (); sender->connect (sub); // Create and initialize the receiver PortableServer::Servant_var<TAO_ECG_UDP_Receiver> receiver = TAO_ECG_UDP_Receiver::create(); // TAO_ECG_UDP_Receiver::init() takes a TAO_ECG_Refcounted_Endpoint. // If we don't clone our endpoint and pass &endpoint, the receiver will // attempt to delete endpoint during shutdown. TAO_ECG_Refcounted_Endpoint clone2 (new TAO_ECG_UDP_Out_Endpoint (endpoint)); receiver->init (ec.in (), clone2, addr_srv.in ()); // Setup the registration and connect to the event channel ACE_SupplierQOS_Factory supp_qos_fact; supp_qos_fact.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); RtecEventChannelAdmin::SupplierQOS pub = supp_qos_fact.get_SupplierQOS (); receiver->connect (pub); // Create the appropriate event handler and register it with the reactor auto_ptr<ACE_Event_Handler> eh; if (mcast) { auto_ptr<TAO_ECG_Mcast_EH> mcast_eh(new TAO_ECG_Mcast_EH (receiver.in())); mcast_eh->reactor (orb->orb_core ()->reactor ()); mcast_eh->open (ec.in()); ACE_auto_ptr_reset(eh,mcast_eh.release()); //eh.reset(mcast_eh.release()); } else { auto_ptr<TAO_ECG_UDP_EH> udp_eh (new TAO_ECG_UDP_EH (receiver.in())); udp_eh->reactor (orb->orb_core ()->reactor ()); ACE_INET_Addr local_addr (listenport); if (udp_eh->open (local_addr) == -1) ACE_ERROR ((LM_ERROR,"Cannot open EH\n")); ACE_auto_ptr_reset(eh,udp_eh.release()); //eh.reset(udp_eh.release()); } // Create an event (just a string in this case). // Create an event set for one event RtecEventComm::EventSet event (1); event.length (1); // Initialize event header. event[0].header.source = MY_SOURCE_ID; event[0].header.ttl = 1; event[0].header.type = MY_EVENT_TYPE; #if !defined (TAO_LACKS_EVENT_CHANNEL_ANY) // Initialize data fields in event. const CORBA::String_var eventData = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (ecname)); event[0].data.any_value <<= eventData; #else // Use the octet sequence payload instead char *tmpstr = const_cast<char *>(ACE_TEXT_ALWAYS_CHAR (ecname)); size_t len = ACE_OS::strlen(tmpstr) +1; event[0].data.payload.replace ( len, len, reinterpret_cast<CORBA::Octet *> (tmpstr)); #endif /* !TAO_LACKS_EVENT_CHANNEL_ANY */ if (iorfile != 0) { CORBA::String_var str = orb->object_to_string( ec.in() ); std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(iorfile) ); iorFile << str.in() << std::endl; iorFile.close(); } ACE_DEBUG ((LM_DEBUG, "Starting main loop\n")); const int EVENT_DELAY_MS = 1000; while (1) { consumer->push (event); ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); orb->run(tv); } orb->destroy(); return 0; } catch (const CORBA::Exception& exc) { ACE_ERROR ((LM_ERROR, "Caught CORBA::Exception\n%C (%C)\n", exc._name (), exc._rep_id () )); } return 1; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in())) { std::cerr << "Unable to initialize the POA." << std::endl; return 1; } PortableServer::POA_var poa = PortableServer::POA::_narrow(poa_object.in()); // Activate POA manager PortableServer::POAManager_var mgr = poa->the_POAManager(); mgr->activate(); CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService"); if (CORBA::is_nil(naming_obj.in())) { std::cerr << "Unable to find naming service" << std::endl; return 1; } CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow(naming_obj.in()); CosNaming::Name name(1); name.length (1); name[0].id = CORBA::string_dup("MyEventChannel"); CORBA::Object_var ecObj = naming_context->resolve(name); CosNotifyChannelAdmin::EventChannel_var ec = CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in()); if (CORBA::is_nil (ec.in())) { std::cerr << "Unable to find event channel" << std::endl; return 1; } CosNotifyChannelAdmin::AdminID adminid; CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::AND_OP; CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = ec->new_for_consumers(ifgop, adminid); if (CORBA::is_nil (consumer_admin.in())) { std::cerr << "Unable to find consumer admin" << std::endl; return 1; } PortableServer::Servant_var<StructuredEventConsumer_i> servant = new StructuredEventConsumer_i(orb.in()); CosNotifyComm::StructuredPushConsumer_var consumer = servant->_this(); CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = consumer_admin->obtain_notification_push_supplier( CosNotifyChannelAdmin::STRUCTURED_EVENT, consumeradmin_proxy_id); // The proxy that we are connected to. CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy; supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier:: _narrow(proxy_supplier.in()); if (CORBA::is_nil (supplier_proxy.in())) { std::cerr << "Unable to create structured push supplier proxy" << std::endl; return 1; } supplier_proxy->connect_structured_push_consumer(consumer.in()); CosNotification::EventTypeSeq added (1); CosNotification::EventTypeSeq removed (1); added.length (1); removed.length (1); added[0].domain_name = CORBA::string_dup ("OCI_TAO"); added[0].type_name = CORBA::string_dup ("examples"); removed[0].domain_name = CORBA::string_dup ("*"); removed[0].type_name = CORBA::string_dup ("*"); supplier_proxy->subscription_change(added, removed); orb->run(); } catch(const CORBA::Exception& ex) { std::cerr << "MessengerConsumer:: Caught exception: " << ex << std::endl; return 1; } std::cerr << "MessengerConsumer: success" << std::endl; return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); const ACE_TCHAR *ecname = ACE_TEXT ("EventService"); for (int i = 0; argv[i] != 0; i++) { if (ACE_OS::strcmp(argv[i], ACE_TEXT("-ecname")) == 0) { if (argv[i+1] != 0) { ecname = argv[i+1]; } else { std::cerr << "Missing Event channel name" << std::endl; } } } // Find the Naming Service. CORBA::Object_var obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); // Find the EchoEventChannel. obj = root_context->resolve_str (ACE_TEXT_ALWAYS_CHAR (ecname)); // Downcast the object reference to an EventChannel reference. RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); if (CORBA::is_nil(ec.in())) { std::cerr << "Could not narrow EchoEventChannel." << std::endl; return 1; } std::cout << "EchoEventConsumerMain.cpp: Found the EchoEventChannel." << std::endl; // Obtain a reference to the consumer administration object. RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers(); // Obtain a reference to the push supplier proxy. RtecEventChannelAdmin::ProxyPushSupplier_var supplier = admin->obtain_push_supplier(); // Get the RootPOA. obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); // Instantiate an EchoEventConsumer_i servant and register it // with the RootPOA PortableServer::Servant_var<EchoEventConsumer_i> servant = new EchoEventConsumer_i(orb.in(), supplier.in(), EVENT_LIMIT); PortableServer::ObjectId_var oid = poa->activate_object(servant.in()); CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); RtecEventComm::PushConsumer_var consumer = RtecEventComm::PushConsumer::_narrow(consumer_obj.in()); // Connect as a consumer. ACE_ConsumerQOS_Factory qos; qos.start_disjunction_group (); qos.insert (MY_SOURCE_ID, // Source ID MY_EVENT_TYPE, // Event Type 0); // handle to the rt_info supplier->connect_push_consumer (consumer.in (), qos.get_ConsumerQOS ()); // Activate the POA via its POAManager. PortableServer::POAManager_var poa_manager = poa->the_POAManager(); poa_manager->activate(); std::cout << "EchoEventConsumerMain.cpp: Ready to receive events..." << std::endl; // Enter the ORB event loop. orb->run(); // If we have reached this, we must be shutting down... // Disconnect the ProxyPushSupplier. orb->destroy(); std::cout << "Test completed." << std::endl; return 0; } catch(const CORBA::Exception& exc) { std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; } return 1; }