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"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::Object_var object = orb->resolve_initial_references ("PolicyCurrent"); CORBA::PolicyCurrent_var policy_current = CORBA::PolicyCurrent::_narrow (object.in ()); if (CORBA::is_nil (policy_current.in ())) { ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n")); return 1; } CORBA::Any scope_as_any; scope_as_any <<= Messaging::SYNC_WITH_SERVER; CORBA::PolicyList policies(1); policies.length (1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, scope_as_any); policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); seed = (unsigned int) ACE_OS::gethrtime (); if (parse_args (argc, argv) != 0) return 1; ACE_DEBUG ((LM_DEBUG, "SEED = %u\n", seed)); Server_Peer *impl; ACE_NEW_RETURN (impl, Server_Peer (seed, orb.in (), payload_size), 1); PortableServer::ServantBase_var owner_transfer(impl); PortableServer::ObjectId_var id = root_poa->activate_object (impl); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); Test::Peer_var peer = Test::Peer::_narrow (object_act.in ()); CORBA::String_var ior = orb->object_to_string (peer.in ()); // If the ior_output_file exists, output the ior to it 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); poa_manager->activate (); Sleeper sleeper (orb.in ()); ACE_Time_Value interval(0, 500000); ACE_Reactor * reactor = orb->orb_core()->reactor(); reactor->schedule_timer(&sleeper, 0, interval, interval); // ACE_Time_Value run_time(600, 0); // orb->run (run_time); orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "PerformanceClient"); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var object = orb->string_to_object (ior); UDP_var udp_var = UDP::_narrow (object.in ()); if (CORBA::is_nil (udp_var.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "Object reference <%s> is nil.\n", ior), 1); } // Activate POA to handle the call back. CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); // Instantiate reply handler UDP_i udp_i; // let it remember our ORB udp_i.orb (orb.in ()); UDP_var udpHandler_var = udp_i._this (); // Instantiate client ACE_Task_Base* client = new UDP_PerformanceClient (orb.in (), udp_var.in (), &udp_i, burst_messages); // let the client run in a separate thread client->activate (); // ORB loop, will be shut down by our client thread orb->run (); // Fetch responses ACE_DEBUG ((LM_DEBUG, "ORB finished\n")); client->wait (); root_poa->destroy (1, // ethernalize objects 0 // wait for completion ); orb->destroy (); // it is save to delete the client, because the client was actually // the one calling orb->shutdown () triggering the end of the ORB // event loop. delete client; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return 1; } return 0; }
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"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; CORBA::String_var repo_id = "IDL:omg.org/CosNotifyComm/StructuredPushConsumer:1.0"; CORBA::Object_var object = root_poa->create_reference (repo_id.in()); CORBA::String_var ior = orb->object_to_string (object.in ()); FILE *output_file= ACE_OS::fopen (output_filename, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Cannot open output file for writing IOR: %C\n"), output_file), 1); const char * dummy_consumer_proxy = ior.in(); ACE_OS::fprintf (output_file, format, dummy_consumer_proxy, dummy_consumer_proxy, dummy_consumer_proxy, dummy_consumer_proxy); ACE_OS::fclose (output_file); poa_manager->activate (); orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int main (int argc, char** argv) { cout << "Test Client for Stream Container" << endl; CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); orb->register_value_factory ("IDL:omg.org/Components/FacetDescription:1.0", new FacetDescriptionFactory_impl()); orb->register_value_factory ("IDL:omg.org/Components/ReceptacleDescription:1.0", new ReceptacleDescriptionFactory_impl()); orb->register_value_factory ("IDL:omg.org/Components/SubscriberDescription:1.0", new SubscriberDescriptionFactory_impl()); orb->register_value_factory ("IDL:omg.org/Components/EmitterDescription:1.0", new EmitterDescriptionFactory_impl()); orb->register_value_factory ("IDL:omg.org/Components/ConsumerDescription:1.0", new ConsumerDescriptionFactory_impl()); orb->register_value_factory ("IDL:omg.org/Components/ComponentPortDescription:1.0", new ComponentPortDescriptionFactory_impl()); orb->register_value_factory ("IDL:omg.org/Components/Cookie:1.0", new CookieFactory_impl()); CosNaming::NamingContext_var ns; try { CORBA::Object_var ns_obj = orb->resolve_initial_references ("NameService"); ns = CosNaming::NamingContext::_narrow (ns_obj); } catch (CORBA::ORB::InvalidName&) { cerr << "Name Service not found" << endl; orb->destroy(); exit (1); } catch (CORBA::SystemException&) { cerr << "Cannot narrow object reference of Name Service" << endl; orb->destroy(); exit (1); } if (CORBA::is_nil (ns)) { cerr << "Name Service is nil" << endl; orb->destroy(); exit (1); } // Now get the Component Server Activator from the Name Service, use the name TETRA/Activators/<hostname> char hostname[256]; if (gethostname (hostname, 256)) { cerr << "Cannot determine my hostname" << endl; orb->destroy(); exit (1); } // Get the Server Activator Components::Deployment::ServerActivator_var server_activator = get_server_activator (orb, ns, hostname); // Feed our test deployment into the Component Installer deploy_test_components (orb, ns, hostname); // // Begin tests // // Create Component Server Components::ConfigValues config; Components::ConfigValues config1; Components::Deployment::ComponentServer_var component_server; Components::Deployment::ComponentServer_var component_server1; Components::Deployment::ComponentServer_var component_server2; try { component_server = server_activator->create_component_server (config1); } catch (CORBA::Exception&) { cerr << "Exception during test run" << endl; orb->destroy(); exit (1); } if (CORBA::is_nil (component_server)) { cerr << "I got a nil reference for the created Component Server" << endl; orb->destroy(); exit (1); } #if 0 try { component_server1 = server_activator->create_component_server (config1); } catch (CORBA::Exception&) { cerr << "Exception during test run" << endl; orb->destroy(); exit (1); } if (CORBA::is_nil (component_server1)) { cerr << "I got a nil reference for the created Component Server" << endl; orb->destroy(); exit (1); } try { component_server2 = server_activator->create_component_server (config1); } catch (CORBA::Exception&) { cerr << "Exception during test run" << endl; orb->destroy(); exit (1); } if (CORBA::is_nil (component_server2)) { cerr << "I got a nil reference for the created Component Server" << endl; orb->destroy(); exit (1); } #endif // Create Container Components::Deployment::Container_var container; Components::Deployment::Container_var container1; Components::Deployment::Container_var container2; config.length (1); CORBA::Any any; any <<= "SESSION"; config[0] = new ConfigValue_impl ("CONTAINER_TYPE", any); try { container = component_server->create_container (config); } catch (CORBA::SystemException& ex) { cerr << "CORBA system exception during creating container : " << ex << endl; orb->destroy(); exit (1); } #if 0 try { container1 = component_server1->create_container (config); } catch (CORBA::SystemException& ex) { cerr << "CORBA system exception during creating container : " << ex << endl; orb->destroy(); exit (1); } try { container2 = component_server2->create_container (config); } catch (CORBA::SystemException& ex) { cerr << "CORBA system exception during creating container : " << ex << endl; orb->destroy(); exit (1); } #endif //config.length(0); Components::CCMHome_var home; home = container->install_home ("PHILOSOPHER", "", config1); dinner::PhilosopherHome_var p_home = dinner::PhilosopherHome::_narrow (home); #if 0 home = container1->install_home ("CUTLERY", "", config1); dinner::CutleryHome_var c_home = dinner::CutleryHome::_narrow (home); home = container2->install_home ("OBSERVER", "", config1); dinner::ObserverHome_var o_home = dinner::ObserverHome::_narrow (home); #else home = container->install_home ("CUTLERY", "", config1); dinner::CutleryHome_var c_home = dinner::CutleryHome::_narrow (home); home = container->install_home ("OBSERVER", "", config1); dinner::ObserverHome_var o_home = dinner::ObserverHome::_narrow (home); #endif dinner::Philosopher_var phil1; dinner::Philosopher_var phil2; dinner::Philosopher_var phil3; dinner::Cutlery_var cut1; dinner::Cutlery_var cut2; dinner::Observer_var obs; dinner::Observer_var obs1; try { phil1 = p_home->create(); phil2 = p_home->create(); phil3 = p_home->create(); cut1 = c_home->create(); cut2 = c_home->create(); obs = o_home->create(); obs1 = o_home->create(); } catch (Components::CreateFailure&) { cerr << "Create Failure exception" << endl; } catch (CORBA::SystemException& ex) { cerr << ex << endl; } try { phil1->name ("Frank"); phil2->name ("Bert"); phil3->name ("Harry"); phil1->thinking_seconds (5); phil2->thinking_seconds (3); phil3->thinking_seconds (6); phil1->eating_seconds (4); phil2->eating_seconds (6); phil3->eating_seconds (3); phil1->sleeping_seconds (6); phil2->sleeping_seconds (7); phil3->sleeping_seconds (5); dinner::Fork_var a_fork; a_fork = cut1->provide_the_fork(); phil1->connect_left_hand (a_fork); phil2->connect_left_hand (a_fork); phil3->connect_left_hand (a_fork); a_fork = cut2->provide_the_fork(); phil1->connect_right_hand (a_fork); phil2->connect_right_hand (a_fork); phil3->connect_right_hand (a_fork); Components::Cookie* ck; dinner::PhilosopherStateConsumer_var consumer = obs->get_consumer_philosopher_state(); ck = phil1->subscribe_philosopher_state (consumer); ck = phil2->subscribe_philosopher_state (consumer); ck = phil3->subscribe_philosopher_state (consumer); consumer = obs1->get_consumer_philosopher_state(); ck = phil1->subscribe_philosopher_state (consumer); ck = phil2->subscribe_philosopher_state (consumer); ck = phil3->subscribe_philosopher_state (consumer); phil1->configuration_complete(); phil2->configuration_complete(); phil3->configuration_complete(); cut1->configuration_complete(); cut2->configuration_complete(); obs->configuration_complete(); obs1->configuration_complete(); } catch (CORBA::SystemException& ex) { cerr << ex << endl; } sleep (30); try { phil1->remove(); phil2->remove(); phil3->remove(); c_home->remove_component (cut1); c_home->remove_component (cut2); obs->remove(); obs1->remove(); } catch (Components::RemoveFailure&) { cerr << "Remove Failure during remove_component()" << endl; } catch (CORBA::SystemException& ex) { cerr << ex << endl; } try { #if 0 container1->remove_home (c_home); container2->remove_home (o_home); #else container->remove_home (c_home); container->remove_home (o_home); #endif // remove at last because of it was installed first // registering the valuetype factories container->remove_home (p_home); } catch (Components::RemoveFailure&) { cerr << "Remove Failure during removing home" << endl; } catch (CORBA::SystemException& ex) { cerr << ex << endl; } try { container->remove(); } catch (Components::RemoveFailure&) { cerr << "Remove Failure during removing container" << endl; } catch (CORBA::SystemException& ex) { cerr << ex << endl; } try { component_server->remove(); #if 0 getchar(); component_server1->remove(); getchar(); component_server2->remove(); #endif } catch (Components::RemoveFailure&) { cerr << "Remove Failure during removing component server" << endl; } catch (CORBA::SystemException& ex) { cerr << ex << endl; } return 0; }
CORBA::Object_ptr TAO_Trading_Loader::create_object (CORBA::ORB_ptr orb_ptr, int argc, ACE_TCHAR *argv[]) { // Duplicate the ORB CORBA::ORB_var orb = CORBA::ORB::_duplicate (orb_ptr); // Activating the poa manager this->orb_manager_.activate_poa_manager (); // Create a Trader Object and set its Service Type Repository. auto_ptr<TAO_Trader_Factory::TAO_TRADER> auto_trader (TAO_Trader_Factory::create_trader (argc, argv)); this->trader_ = auto_trader; TAO_Support_Attributes_i &sup_attr = this->trader_->support_attributes (); TAO_Trading_Components_i &trd_comp = this->trader_->trading_components (); sup_attr.type_repos (this->type_repos_._this ()); // The Spec says: return a reference to the Lookup interface from // the resolve_initial_references method. CosTrading::Lookup_ptr lookup = trd_comp.lookup_if (); this->ior_ = orb->object_to_string (lookup); // Parse the args if (this->parse_args (argc, argv) == -1) return CORBA::Object::_nil (); // Dump the ior to a file. if (this->ior_output_file_ != 0) { ACE_OS::fprintf (this->ior_output_file_, "%s", this->ior_.in ()); ACE_OS::fclose (this->ior_output_file_); } CORBA::Object_var table_object = orb->resolve_initial_references ("IORTable"); IORTable::Table_var adapter = IORTable::Table::_narrow (table_object.in ()); if (CORBA::is_nil (adapter.in ())) { ORBSVCS_ERROR ((LM_ERROR, "Nil IORTable\n")); } else { adapter->bind ("TradingService", this->ior_.in ()); } if (this->federate_) { // Only become a multicast server if we're the only trader // on the multicast network. // @@ Could do other things. For example, every timeout // period try to federate again, but let's not hardcode that // policy. int rc = this->bootstrap_to_federation (); if (rc == -1) this->init_multicast_server (); } else this->init_multicast_server (); return CORBA::Object::_nil (); }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { Server_ORBInitializer *temp_initializer = 0; ACE_NEW_RETURN (temp_initializer, Server_ORBInitializer, -1); // No exceptions yet! PortableInterceptor::ORBInitializer_var orb_initializer = temp_initializer; PortableInterceptor::register_orb_initializer (orb_initializer.in ()); CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // We do the command line parsing first if (parse_args (argc, argv) != 0) return -1; CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), -1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::PolicyList policies; policies.length (3); policies[0] = root_poa->create_id_assignment_policy ( PortableServer::USER_ID); policies[1] = root_poa->create_implicit_activation_policy ( PortableServer::NO_IMPLICIT_ACTIVATION); policies[2] = root_poa->create_lifespan_policy ( PortableServer::PERSISTENT); PortableServer::POA_var poa = root_poa->create_POA ( "PERS_POA", poa_manager.in (), policies); for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } // Instantiate the LCD_Display implementation class Simple_Server_i display_impl (orb.in (), ACE_TEXT_ALWAYS_CHAR(key)); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("IOGR_OID"); poa->activate_object_with_id (id.in(), &display_impl); CORBA::Object_var server = poa->id_to_reference (id.in ()); CORBA::String_var ior = orb->object_to_string (server.in ()); ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ())); // If the ior_output_file exists, output the ior to it if (ior_output_file != 0) { 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); } // Set the forward references in the server request interceptor. PortableInterceptor::ServerRequestInterceptor_var server_interceptor = temp_initializer->server_interceptor (); Simple_ServerRequestInterceptor_var interceptor = Simple_ServerRequestInterceptor::_narrow ( server_interceptor.in ()); if (CORBA::is_nil (interceptor.in ())) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Could not obtain reference to " "server request interceptor.\n"), -1); interceptor->forward_reference (ACE_TEXT_ALWAYS_CHAR(merged_iorstr)); poa_manager->activate (); orb->run (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return -1; } return 0; }
int TestTask::svc() { try { // Get reference to Root POA CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); // Activate POA Manager PortableServer::POAManager_var mgr = poa->the_POAManager(); mgr->activate(); // Find the Naming Service obj = orb_->string_to_object ("corbaloc:iiop:1.2@localhost:9932/NameService"); CosNaming::NamingContext_var root = CosNaming::NamingContext::_narrow(obj.in()); if (CORBA::is_nil(root.in())) { ACE_ERROR ((LM_ERROR, "Error, Nil Naming Context reference\n")); return 1; } // Bind the example Naming Context, if necessary CosNaming::NamingContext_var example_nc; CosNaming::Name name; name.length(1); name[0].id = CORBA::string_dup("example"); try { obj = root->resolve(name); example_nc = CosNaming::NamingContext::_narrow(obj.in()); } catch (const CosNaming::NamingContext::NotFound&) { example_nc = root->bind_new_context(name); } // Bind the Test object name.length(2); name[1].id = CORBA::string_dup("Hello"); // Create an object Hello servant(orb_.in ()); PortableServer::ObjectId_var oid = poa->activate_object(&servant); obj = poa->id_to_reference(oid.in()); root->rebind(name, obj.in()); ACE_DEBUG ((LM_INFO, "Hello object bound in Naming Service B\n")); name.length(1); obj = orb_->string_to_object ("corbaloc:iiop:1.2@localhost:9931/NameService"); root = CosNaming::NamingContext::_narrow(obj.in()); root->bind_context (name, example_nc.in ()); ACE_DEBUG ((LM_INFO, "'example' context of NS B bound in Naming Service A\n")); CORBA::String_var ior = orb_->object_to_string (obj.in ()); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file %s for writing IOR: %C\n", ior_output_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); ACE_DEBUG ((LM_INFO, "Wrote IOR file\n")); // Normally we run the orb and the orb is shutdown by // calling TestTask::end(). // Accept requests orb_->run(); orb_->destroy(); return 0; } catch (CORBA::Exception& ex) { ex._tao_print_exception ("CORBA exception: "); } return -1; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { ORBInitializer *initializer = 0; ACE_NEW_RETURN (initializer, ORBInitializer, -1); // No exceptions yet! PortableInterceptor::ORBInitializer_var orb_initializer = initializer; PortableInterceptor::register_orb_initializer (orb_initializer.in ()); 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 ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; poa_manager->activate (); CORBA::Object_var lm_object = orb->resolve_initial_references ("LoadManager"); CosLoadBalancing::LoadManager_var load_manager = CosLoadBalancing::LoadManager::_narrow (lm_object.in ()); RPS_Monitor * monitor_servant; ACE_NEW_THROW_EX (monitor_servant, RPS_Monitor (initializer->interceptor ()), CORBA::NO_MEMORY ()); PortableServer::ServantBase_var safe_monitor_servant (monitor_servant); CosLoadBalancing::LoadMonitor_var load_monitor = monitor_servant->_this (); PortableGroup::Location_var location = load_monitor->the_location (); CORBA::Object_var stockfactory = ::join_object_group (orb.in (), load_manager.in (), location.in ()); TAO_LB_LoadAlert & alert_servant = initializer->load_alert (); CosLoadBalancing::LoadAlert_var load_alert = alert_servant._this (); CORBA::String_var ior = orb->object_to_string (stockfactory.in ()); // If the ior_output_file exists, output the ior to it 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); load_manager->register_load_monitor (location.in (), load_monitor.in ()); load_manager->register_load_alert (location.in (), load_alert.in ()); orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("lb_server exception"); 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 poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); Publisher_impl publisher(orb.in ()); PortableServer::ObjectId_var id = root_poa->activate_object (&publisher); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Publisher_var publisher_var = Publisher::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string(publisher_var.in()); ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in())); // output the ior 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\n", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); poa_manager->activate(); const CORBA::Object_var pmobj (orb->resolve_initial_references("ORBPolicyManager" ) ); CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow(pmobj.in() ); CORBA::Any orb_level; orb_level <<= Messaging::SYNC_NONE; CORBA::PolicyList policy_list; policy_list.length(1); policy_list[0] = orb->create_policy(Messaging::SYNC_SCOPE_POLICY_TYPE, orb_level); policy_manager->set_policy_overrides(policy_list, CORBA::SET_OVERRIDE); ThreadPool pool (orb.in ()); if (pool.activate(THR_NEW_LWP | THR_JOINABLE, 5) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate client threads\n"), 1); pool.thr_mgr ()->wait (); ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); 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("NotifyEventChannelFactory"); CORBA::Object_var obj = naming_context->resolve(name); CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj.in()); if (CORBA::is_nil(notify_factory.in())) { std::cerr << "Unable to find notify factory" << std::endl; return 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; } CosNotifyFilter::FilterFactory_var ffact = ec->default_filter_factory (); // setup a filter at the consumer admin CosNotifyFilter::Filter_var ca_filter = ffact->create_filter (TCL_GRAMMAR); if (CORBA::is_nil (ca_filter.in())) { std::cerr << "Unable to create filetr object" << std::endl; return 1; } CosNotifyFilter::ConstraintExpSeq constraint_list (1); constraint_list.length (1); constraint_list[0].event_types.length (0); constraint_list[0].constraint_expr = CORBA::string_dup (CA_FILTER); ca_filter->add_constraints (constraint_list); consumer_admin ->add_filter (ca_filter.in()); CosNotification::EventTypeSeq added(1); CosNotification::EventTypeSeq removed (0); added.length (1); removed.length (0); added[0].domain_name = CORBA::string_dup ("*"); added[0].type_name = CORBA::string_dup ("*"); consumer_admin->subscription_change (added, removed); 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()); PortableServer::Servant_var<StructuredEventConsumer_i> servant = new StructuredEventConsumer_i(orb.in()); /* CosNotifyComm::StructuredPushConsumer_var consumer = servant->_this(); */ PortableServer::ObjectId_var oid = poa->activate_object(servant.in()); CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); CosNotifyComm::StructuredPushConsumer_var consumer = CosNotifyComm::StructuredPushConsumer::_narrow(consumer_obj.in()); 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()); PortableServer::POAManager_var poa_manager = poa->the_POAManager(); poa_manager->activate(); orb->run(); orb->destroy (); } catch(const CORBA::Exception& ex) { std::cerr << ex << std::endl; return 1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { PortableInterceptor::ORBInitializer_ptr tmp; ACE_NEW_RETURN (tmp, ServerORBInitializer, -1); // No CORBA exceptions yet! PortableInterceptor::ORBInitializer_var orb_initializer = tmp; PortableInterceptor::register_orb_initializer (orb_initializer.in ()); // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "ORT Test ORB"); if (parse_args (argc, argv) != 0) return -1; CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); // Narrow PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); // Check for nil references if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, "Unable to obtain RootPOA reference.\n"), -1); // Get poa_manager reference PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); // Activate it. poa_manager->activate (); CORBA::PolicyList policies (0); policies.length (0); // Lets create some POA's PortableServer::POA_var first_poa = root_poa->create_POA ("FIRST_POA", poa_manager.in (), policies); PortableServer::POA_var second_poa = first_poa->create_POA ("SECOND_POA", poa_manager.in (), policies); PortableServer::POA_var third_poa = second_poa->create_POA ("THIRD_POA", poa_manager.in (), policies); PortableServer::POA_var fourth_poa = third_poa->create_POA ("FOURTH_POA", poa_manager.in (), policies); ORT_test_i ort_test_impl (orb.in ()); PortableServer::ObjectId_var oid = fourth_poa->activate_object (&ort_test_impl); obj = fourth_poa->servant_to_reference (&ort_test_impl); // Convert the object reference to a string format. CORBA::String_var ior = orb->object_to_string (obj.in ()); // Dump it to a file. if (ior_output_file != 0) { FILE *output_file = ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file %s for writing " "IOR: %C", ior_output_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } orb->run (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("ORT test server:"); return -1; } return 0; }
int acscomponentTestServer (char *szCmdLn) { int argc; char *argv[100]; argc = argUnpack(szCmdLn, argv); argv[0] = "acscomponentTestServer"; #else int main(int argc, char* argv[]) { #endif // defined( MAKE_VXWORKS ) // creating ORB ACS_TEST_INIT_CORBA; try { ACE_OS::signal(SIGINT, TerminationSignalHandler); // Ctrl+C ACE_OS::signal(SIGTERM, TerminationSignalHandler); // termination request //Get a reference to the RootPOA CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // The component will throw an exception if receives a NULL ContainerServices // in the constructor. // We pass a value only to avoid that i throws the exception. On the other // hand the test doe not use the ContainerServices (remember: ContainerServices // does not yet exist at this point!!!!) ACE_CString compName("TEST"); ACSComponentTestClassImpl mytestImpl(compName.c_str(), new TestContainerServices(compName,NULL)); ACSCOMPONENT_TEST::ACSComponentTestClass_var mytest = mytestImpl._this ();; poa_manager->activate (); ACS_DEBUG ("acscomponentTestServer","POA Manager -> activate"); ACS_DEBUG ("acscomponentTestServer", "Writing ior to the file: ACSCOMPONENTTEST1"); char* ior = orb->object_to_string (mytest.in()); char fileName[64]; sprintf(fileName, "%s.ior", "ACSCOMPONENTTEST1"); FILE *output_file = ACE_OS::fopen (fileName, "w"); if (output_file == 0) { ACS_SHORT_LOG((LM_ERROR, "Cannot open output files for writing IOR: ior.ior")); return -1; } int result = ACE_OS::fprintf (output_file, "%s", ior); if (result < 0) { ACE_ERROR_RETURN ((LM_ERROR, "ACE_OS::fprintf failed while writing %s to ior.ior", ior), -1); } ACE_OS::fclose (output_file); ACS_DEBUG ("acscomponentTestServer", "Waiting for requests ..."); orb->run (); } catch( CORBA::Exception &_ex ) { _ex._tao_print_exception("EXCEPTION CAUGHT"); return -1; } // orb->shutdown(true); //wait until all requests have completed return 0; }
int main(int argc, char* argv[]) { int i; string url = "file://"; double ddp = 0.001; double timeK = 10.0; // -urlでモデルのURLを指定 for(i=0; i < argc - 1; i++) { if( strcmp(argv[i], "-url") == 0) { url += argv[++i]; } else if( strcmp(argv[i], "-ddp") == 0) { ddp = strtod( argv[++i], NULL); } else if( strcmp(argv[i], "-timeK") == 0) { timeK = strtod( argv[++i], NULL); } } string robot_url = url+"sample.wrl"; string floor_url = url+"floor.wrl"; const char *ROBOT_URL = robot_url.c_str(); const char *FLOOR_URL = floor_url.c_str(); ////////////////////////////////////////////////////////////////////// // CORBA初期化 CORBA::ORB_var orb; orb = CORBA::ORB_init(argc, argv); // ROOT POA CORBA::Object_var poaObj = orb -> resolve_initial_references("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObj); // POAマネージャへの参照を取得 PortableServer::POAManager_var manager = rootPOA -> the_POAManager(); // NamingServiceの参照取得 CosNaming::NamingContext_var cxT; { CORBA::Object_var nS = orb->resolve_initial_references("NameService"); cxT = CosNaming::NamingContext::_narrow(nS); } ///////////////////////////////////////////////////////////////////////// // DynamicsSimulatorの取得 DynamicsSimulatorFactory_var dynamicsSimulatorFactory; dynamicsSimulatorFactory = checkCorbaServer <DynamicsSimulatorFactory, DynamicsSimulatorFactory_var> ("DynamicsSimulatorFactory", cxT); if (CORBA::is_nil(dynamicsSimulatorFactory)) { std::cerr << "DynamicsSimulatorFactory not found" << std::endl; } DynamicsSimulator_var dynamicsSimulator = dynamicsSimulatorFactory->create(); // モデルの読み込み・登録 BodyInfo_var robotInfo = loadBodyInfo(ROBOT_URL, argc, argv); dynamicsSimulator->registerCharacter("robot", robotInfo); // 床の読み込み・登録 BodyInfo_var floorInfo = loadBodyInfo(FLOOR_URL, argc, argv); dynamicsSimulator->registerCharacter("floor", floorInfo); ///////////////////////////////////////////////////////////////////////// // DynamicsSimulatorの初期化 dynamicsSimulator->init(0.002, DynamicsSimulator::RUNGE_KUTTA, DynamicsSimulator::ENABLE_SENSOR); // 重力ベクトルの設定 DblSequence3 gVector; gVector.length(3); gVector[0] = gVector[1] = 0; gVector[2] = 9.8; dynamicsSimulator->setGVector(gVector); // 関節駆動モードの設定 dynamicsSimulator->setCharacterAllJointModes( "robot", DynamicsSimulator::TORQUE_MODE); // 初期姿勢 double init_pos[] = {0.00E+00, -3.60E-02, 0, 7.85E-02, -4.25E-02, 0.00E+00, 1.75E-01, -3.49E-03, 0, -1.57E+00, 0.00E+00, 0.00E+00, 0.00E+00, 0.00E+00, -3.60E-02, 0, 7.85E-02, -4.25E-02, 0.00E+00, 1.75E-01, 3.49E-03, 0, -1.57E+00, 0.00E+00, 0.00E+00, 0.00E+00, 0, 0, 0}; // 初期姿勢を関節角にセット DblSequence q; q.length(DOF); for (int i=0; i<DOF; i++) { q[i] = init_pos[i]; } dynamicsSimulator->setCharacterAllLinkData( "robot", DynamicsSimulator::JOINT_VALUE, q); // 順運動学計算 dynamicsSimulator->calcWorldForwardKinematics(); // 干渉チェックペアの設定−両手 DblSequence6 dc, sc; dc.length(0); sc.length(0); dynamicsSimulator->registerCollisionCheckPair( "robot", "RARM_WRIST_R", "robot", "LARM_WRIST_R", 0.5, 0.5, dc, sc, 0.0, 0.0); dynamicsSimulator->initSimulation(); ///////////////////////////////////////////////////////////////////////// // OnlineViewerの取得 OnlineViewer_var onlineViewer = getOnlineViewer(argc, argv); // OnlineViewerに対するモデルロード try { onlineViewer->load("robot", ROBOT_URL); onlineViewer->load("floor", FLOOR_URL); onlineViewer->setLogName("clap"); onlineViewer->clearLog(); } catch (CORBA::SystemException& ex) { std::cerr << "Failed to connect GrxUI." << endl; return 1; } ///////////////////////////////////////////////////////////////////////// // 逆運動学計算の準備 double RARM_p[] = {0.197403, -0.210919, 0.93732}; double RARM_R[] = {0.174891, -0.000607636, -0.984588, 0.00348999, 0.999994, 2.77917e-06, 0.984582, -0.00343669, 0.174892}; double LARM_p[] = {0.197403, 0.210919, 0.93732}; double LARM_R[] = {0.174891, 0.000607636, -0.984588, -0.00348999, 0.999994, -2.77917e-06, 0.984582, 0.00343669, 0.174892}; double dp = 0.0; ///////////////////////////////////////////////////////////////////////// WorldState_var state; while (1) { // 逆運動学計算 LinkPosition link; link.p[0] = RARM_p[0]; link.p[1] = RARM_p[1] + dp; link.p[2] = RARM_p[2]; for (int i=0; i<9; i++) link.R[i] = RARM_R[i]; dynamicsSimulator->calcCharacterInverseKinematics(CORBA::string_dup("robot"), CORBA::string_dup("CHEST"), CORBA::string_dup("RARM_WRIST_R"), link); link.p[0] = LARM_p[0]; link.p[1] = LARM_p[1] - dp; link.p[2] = LARM_p[2]; for (int i=0; i<9; i++) link.R[i] = LARM_R[i]; dynamicsSimulator->calcCharacterInverseKinematics(CORBA::string_dup("robot"), CORBA::string_dup("CHEST"), CORBA::string_dup("LARM_WRIST_R"), link); dynamicsSimulator->calcWorldForwardKinematics(); dp += ddp; // OnlineViewer更新 try { dynamicsSimulator->getWorldState(state); state->time = dp*timeK; onlineViewer->update(state); } catch (CORBA::SystemException& ex) { std::cerr << "OnlineViewer could not be updated." << endl; std::cerr << "ex._rep_id() = " << ex._rep_id() << endl; return 1; } if(state->time >= 200.0){ std::cout << state->time << endl; } // 干渉チェック dynamicsSimulator->checkCollision(true); if (state->collisions.length() > 0) { if (state->collisions[0].points.length() > 0) { break; } } } return 0; }
int main ( int argc, char **argv ) { std::cout << "CIDL Repository Version " << GENERATOR_VERSION << std::endl; std::cout << "Qedo Team" << std::endl; // // get ORB // CORBA::ORB_var orb; try { orb = CORBA::ORB_init ( argc, argv ); } catch ( ... ) { std::cerr << "Error during ORB_init()" << std::endl; exit ( 1 ); } // // get POA // PortableServer::POA_var root_poa; try { CORBA::Object_var root_poa_obj = orb->resolve_initial_references ( "RootPOA" ); root_poa = PortableServer::POA::_narrow ( root_poa_obj ); } catch ( ... ) { std::cerr << "Error during getting root POA" << std::endl; orb -> destroy(); exit ( 1 ); } // // get POA manager and activate it // PortableServer::POAManager_var root_poa_manager; try { root_poa_manager = root_poa -> the_POAManager(); } catch ( ... ) { std::cerr << "Error getting root POA manager" << std::endl; orb->destroy(); exit ( 1 ); } root_poa_manager -> activate(); QEDO_ComponentRepository::CIDLRepository_impl* repository = new QEDO_ComponentRepository::CIDLRepository_impl ( orb, root_poa ); CORBA::Object_var anObject = root_poa->servant_to_reference(repository); CIDL::CIDLRepository_var rep_ref = CIDL::CIDLRepository::_narrow(anObject); std::string rep_ior; rep_ior = orb->object_to_string(rep_ref); std::ofstream ior_file; ior_file.open("rep.ior"); ior_file << rep_ior.c_str(); ior_file.close(); orb->run(); 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) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("ERROR: wrong arguments\n")), -1); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableGroup::GOA_var root_goa = PortableGroup::GOA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_goa.in ())) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("ERROR: nil RootPOA\n")), -1); PortableServer::POAManager_var poa_manager = root_goa->the_POAManager (); // Create UIPMC reference. CORBA::Object_var obj = orb->string_to_object (uipmc_url); // Create id. PortableServer::ObjectId_var id = root_goa->create_id_for_reference (obj.in ()); // Activate UIPMC Object. UIPMC_Object_Impl* uipmc_impl; ACE_NEW_RETURN (uipmc_impl, UIPMC_Object_Impl (payload_length, client_threads, payload_calls), -1); PortableServer::ServantBase_var owner_transfer1 (uipmc_impl); root_goa->activate_object_with_id (id.in (), uipmc_impl); Test::UIPMC_Object_var uipmc_obj = Test::UIPMC_Object::_unchecked_narrow (obj.in ()); if (CORBA::is_nil (uipmc_obj.in ())) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("ERROR: nil Hello object\n")), -1); CORBA::String_var ior = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("MIOP object is <%C>\n"), ior.in ())); Hello_Impl* hello_impl; ACE_NEW_RETURN (hello_impl, Hello_Impl (orb.in (), uipmc_obj.in ()), -1); PortableServer::ServantBase_var owner_transfer2 (hello_impl); obj = hello_impl->_this (); ior = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Activated as <%C>\n"), ior.in ())); // If the ior_output_file exists, output the ior to it. if (ior_output_file != 0) { FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Cannot open output file ") ACE_TEXT ("for writing IOR: %s"), ior_output_file), -1); } ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } poa_manager->activate (); { // start clients OrbThread orb_thr (orb.in ()); orb_thr.activate (THR_NEW_LWP | THR_JOINABLE, orb_threads); orb_thr.wait (); } root_goa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in server main ():"); return -1; } if (Number_of_Problems.value ()) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nServer finished with *Possiably* %u PROBLEMS.\n"), Number_of_Problems.value ())); return 1; } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nServer finished successfully.\n"))); 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; A::AMI_Test_var server; CORBA::Object_var object = orb->string_to_object (ior); server = A::AMI_Test::_narrow (object.in ()); if (CORBA::is_nil (server.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "Object reference <%s> is nil.\n", ior), 1); } // Activate POA to handle the call back. CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); // Let the client perform the test in a separate thread Client client (server.in (), niterations); if (client.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate client threads\n"), 1); // Main thread collects replies. It needs to collect // <nthreads*niterations> replies. number_of_replies = nthreads *niterations; if (perform_work_flag) { if (debug) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) : Entering perform_work loop to receive <%d> replies\n", number_of_replies)); } // ORB loop. while (number_of_replies > 0) { CORBA::Boolean pending = orb->work_pending(); if (pending) { orb->perform_work(); } } if (debug) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) : Exited perform_work loop\n")); } } client.thr_mgr ()->wait (); ACE_DEBUG ((LM_DEBUG, "threads finished\n")); if (debug) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) : Received <%d> replies\n", (nthreads*niterations) - number_of_replies)); } if (shutdown_flag) { server->shutdown (); } root_poa->destroy (1, // ethernalize objects 0); // wait for completion orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return 1; } return parameter_corruption; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService"); CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow(naming_obj.in()); CosNaming::Name name; 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()); CosNotifyChannelAdmin::AdminID adminid; CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::AND_OP; CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = ec->new_for_consumers(ifgop, adminid); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in()); PortableServer::Servant_var<StructuredEventConsumer_i> servant = new StructuredEventConsumer_i(orb.in()); PortableServer::ObjectId_var objectId = poa->activate_object (servant.in()); CORBA::Object_var consumer_obj = poa->id_to_reference (objectId.in ()); CosNotifyComm::StructuredPushConsumer_var consumer = CosNotifyComm::StructuredPushConsumer::_narrow (consumer_obj.in ()); CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = consumer_admin->obtain_notification_push_supplier( CosNotifyChannelAdmin::STRUCTURED_EVENT, consumeradmin_proxy_id); CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy; supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier:: _narrow(proxy_supplier.in()); 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); PortableServer::POAManager_var poa_manager = poa->the_POAManager(); poa_manager->activate(); orb->run(); } catch(const CORBA::Exception& ex) { std::cerr << "Caught exception: " << ex << std::endl; return 1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { { PortableInterceptor::ORBInitializer_var initializer ( new Client_ORBInitializer); PortableInterceptor::register_orb_initializer (initializer.in()); } CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::Object_var tmp = orb->string_to_object (ior); Test::Echo_var echo = Test::Echo::_narrow (tmp.in ()); poa_manager->activate (); if (CORBA::is_nil (echo.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Nil Test::Echo reference <%s>\n", ior), 1); } test_synchronous (echo.in ()); test_ami (orb.in (), echo.in ()); echo->shutdown (); orb->destroy (); unsigned long request_count = Echo_Client_Request_Interceptor::request_count; unsigned long response_count = Echo_Client_Request_Interceptor::reply_count + Echo_Client_Request_Interceptor::other_count + Echo_Client_Request_Interceptor::exception_count; if (request_count != response_count) { ACE_ERROR ((LM_ERROR, "ERROR: Mismatched count of requests and responses " " (request = %d, response = %d)\n", request_count, response_count)); } if (request_count == 0) { ACE_ERROR ((LM_ERROR, "ERROR: No requests handled ")); } if (response_count == 0) { ACE_ERROR ((LM_ERROR, "ERROR: No response handled ")); } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return exit_status; }
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"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); // Using naming server. TAO_Naming_Client my_name_client; if (my_name_client.init (orb.in ()) < 0) return 1; // Create PropertySetDef object and register. TAO_PropertySetDef *propsetdef_impl = 0; ACE_NEW_RETURN (propsetdef_impl, TAO_PropertySetDef, -1); CosPropertyService::PropertySetDef_var propsetdef = propsetdef_impl->_this (); CosNaming::Name propsetdef_name (1); propsetdef_name.length (1); propsetdef_name[0].id = CORBA::string_dup ("PropertySetDef"); my_name_client->bind (propsetdef_name, propsetdef.in ()); CORBA::Any any_val; // Make this IOR as one of the properties in there. any_val <<= propsetdef.in (); CORBA::Object_var ior = CosPropertyService::PropertySetDef::_duplicate (propsetdef.in()); CORBA::Object_ptr ior_ptr = ior.in (); any_val <<= ior_ptr; propsetdef_impl->define_property_with_mode ("PropertySetDef_IOR", any_val, CosPropertyService::fixed_readonly); // Create PropertySet factory and then register. TAO_PropertySetFactory *propset_factory_impl; ACE_NEW_RETURN (propset_factory_impl, TAO_PropertySetFactory, -1); CosPropertyService::PropertySetFactory_var propset_factory = propset_factory_impl->_this (); CosNaming::Name propset_factory_name (1); propset_factory_name.length (1); propset_factory_name[0].id = CORBA::string_dup ("PropertySetFactory"); my_name_client->bind (propset_factory_name, propset_factory.in ()); poa_manager->activate (); // Run the ORB Event loop. orb->run (); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::SystemException& sysex) { sysex._tao_print_exception ("System Exception"); return 1; } catch (const CORBA::UserException& userex) { userex._tao_print_exception ("User Exception"); return 1; } ACE_DEBUG ((LM_DEBUG, "\nServer is terminating")); return 0; }
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"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return -1; test_i servant (orb.in ()); PortableServer::ObjectId_var id = root_poa->activate_object (&servant); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); test_var server = test::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (server.in ()); ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ())); 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); poa_manager->activate (); orb->run (); ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); root_poa->destroy (1, 1); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Server side exception caught:"); return -1; } return 0; }
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"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; Hello *hello_impl; ACE_NEW_RETURN (hello_impl, Hello (orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(hello_impl); PortableServer::ObjectId_var id = root_poa->activate_object (hello_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Hello_var hello = Test::Hello::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (hello.in ()); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "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); poa_manager->activate (); orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
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 ())) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("SERVER: Unable to initialize the POA.\n")), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (::parse_args (argc, argv) != 0) return -1; // Servant test_i *servant = 0; ACE_NEW_RETURN (servant, test_i (0, orb.in ()), -1); PortableServer::ServantBase_var safe (servant); PortableServer::ObjectId_var oid = root_poa->activate_object (servant); CORBA::Object_var obj = root_poa->servant_to_reference (servant); CORBA::String_var ior = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("SERVER: test_i servant: <%C>\n"), ior.in ())); poa_manager->activate (); // IOR FILE *output_file= ACE_OS::fopen (ior_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("SERVER: Cannot open output file <%s> ") ACE_TEXT ("for writting IOR: %C"), ior_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); // Run the ORB event loop. orb->run (); root_poa->destroy (1, 1); orb->destroy (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("SERVER: Event loop finished.\n"))); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return -1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB 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 ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); // Get a Root POA reference PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; Simple_Server_i server_impl (orb.in ()); Simple_Server_var server = server_impl._this (); CORBA::String_var ior = orb->object_to_string (server.in ()); ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ())); // If the ior_output_file exists, output the ior to it if (ior_output_file != 0) { 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); } poa_manager->activate (); Server_Worker worker (orb.in ()); if (worker.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate client threads\n"), 1); worker.thr_mgr ()->wait (); ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize ORB and POA, POA Manager, parse args. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) == -1) return 1; CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ()); if (check_for_nil (poa.in (), "POA") == -1) return 1; PortableServer::POAManager_var manager = poa->the_POAManager (); // Obtain reference to EC. obj = orb->resolve_initial_references ("Event_Service"); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow (obj.in ()); if (check_for_nil (ec.in (), "EC") == -1) return 1; // Create the consumer and register it with POA. PortableServer::Servant_var<EC_Consumer> consumer_impl = new EC_Consumer (orb, ec); if (!consumer_impl.in ()) return -1; RtecEventComm::PushConsumer_var consumer; TAO_EC_Object_Deactivator consumer_deactivator; activate (consumer, poa.in (), consumer_impl.in (), consumer_deactivator); consumer_deactivator.disallow_deactivation (); // Obtain reference to ConsumerAdmin. RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin = ec->for_consumers (); // Obtain ProxyPushSupplier and connect this consumer. RtecEventChannelAdmin::ProxyPushSupplier_var supplier = consumer_admin->obtain_push_supplier (); ACE_ConsumerQOS_Factory qos; qos.start_disjunction_group (3); qos.insert_type (A_EVENT_TYPE, 0); qos.insert_type (B_EVENT_TYPE, 0); qos.insert_type (C_EVENT_TYPE, 0); supplier->connect_push_consumer (consumer.in (), qos.get_ConsumerQOS ()); // Allow processing of CORBA requests. manager->activate (); // Receive events from EC. orb->run (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception in Consumer:"); return 1; } return 0; }
int TAO_Trading_Loader::bootstrap_to_federation (void) { // If all traders follow this strategy, it creates a complete graph // of all known traders on a multicast network. CORBA::ORB_var orb = this->orb_manager_.orb (); ORBSVCS_DEBUG ((LM_DEBUG, "*** Bootstrapping to another Trading Service.\n")); CORBA::Object_var trading_obj = orb->resolve_initial_references ("TradingService"); if (CORBA::is_nil (trading_obj.in ())) ORBSVCS_ERROR_RETURN ((LM_ERROR, "We're all alone. " "Unable to link to other traders.\n"), -1); ORBSVCS_DEBUG ((LM_DEBUG, "*** Narrowing the lookup interface.\n")); CosTrading::Lookup_var lookup_if = CosTrading::Lookup::_narrow (trading_obj.in ()); ORBSVCS_DEBUG ((LM_DEBUG, "*** Obtaining the link interface.\n")); CosTrading::Link_var link_if = lookup_if->link_if (); TAO_Trading_Components_i &trd_comp = this->trader_->trading_components (); CosTrading::Lookup_ptr our_lookup = trd_comp.lookup_if (); CosTrading::Link_ptr our_link = trd_comp.link_if (); ORBSVCS_DEBUG ((LM_DEBUG, "*** Linking found trader to self.\n")); link_if->add_link (this->name_.in (), our_lookup, CosTrading::always, CosTrading::always); ORBSVCS_DEBUG ((LM_DEBUG, "*** Linking self to found trader.\n")); our_link->add_link ("Bootstrap", lookup_if.in (), CosTrading::always, CosTrading::always); ORBSVCS_DEBUG ((LM_DEBUG, "*** Retrieving list of known linked traders.\n")); CosTrading::LinkNameSeq_var link_name_seq = link_if->list_links (); ORBSVCS_DEBUG ((LM_DEBUG, "*** Linking self to all linked traders.\n")); for (CORBA::ULong i = link_name_seq->length () - 1; i > 0; i--) { // Avoid linking to ourselves. if (ACE_OS::strcmp (static_cast<const char *> (link_name_seq[i]), this->name_.in ()) != 0) { ORBSVCS_DEBUG ((LM_DEBUG, "*** Getting info for link %s.\n", static_cast<const char *> (link_name_seq[i]))); CosTrading::Link::LinkInfo_var link_info = link_if->describe_link (link_name_seq[i]); CosTrading::Lookup_ptr remote_lookup; remote_lookup = link_info->target.in (); ORBSVCS_DEBUG ((LM_DEBUG, "*** Retrieving its link interface.\n")); CosTrading::Link_var remote_link = remote_lookup->link_if (); ORBSVCS_DEBUG ((LM_DEBUG, "*** Creating a link to me from it.\n")); remote_link->add_link (this->name_.in (), our_lookup, CosTrading::always, CosTrading::always); ORBSVCS_DEBUG ((LM_DEBUG, "*** Creating a link to it from me.\n")); our_link->add_link (link_name_seq[i], remote_lookup, CosTrading::always, CosTrading::always); } } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { #if TAO_HAS_INTERCEPTORS == 1 bool destroy_called = false; Server_ORBInitializer *temp_initializer = 0; ACE_NEW_RETURN (temp_initializer, Server_ORBInitializer (destroy_called), -1); // No exceptions yet! PortableInterceptor::ORBInitializer_var orb_initializer = temp_initializer; PortableInterceptor::register_orb_initializer (orb_initializer.in ()); #endif /* TAO_HAS_INTERCEPTORS == 1 */ CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "Server ORB"); CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); if (::parse_args (argc, argv) != 0) return -1; test_i servant (orb.in ()); PortableServer::ObjectId_var id = root_poa->activate_object (&servant); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); CORBA::Object_var obj = CORBA::Object::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "test servant: <%C>\n", ior.in ())); // Write IOR to a file. FILE *output_file= ACE_OS::fopen (ior_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file <%s> for writing " "IOR: %C", ior_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); // Run the ORB event loop. orb->run (); root_poa->destroy (1, 1); orb->destroy (); #if TAO_HAS_INTERCEPTORS == 1 ACE_TEST_ASSERT (destroy_called == true); #endif ACE_DEBUG ((LM_DEBUG, "Event loop finished.\n")); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return -1; } return 0; }
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"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); Hello_impl * h = 0; ACE_NEW_RETURN (h,Hello_impl, 1); CORBA::ULong before_act = h->_refcount_value (); ACE_DEBUG ((LM_DEBUG, "Before activation: %d\n", before_act)); PortableServer::ObjectId_var oid = poa->activate_object (h); CORBA::ULong after_act = h->_refcount_value (); ACE_DEBUG ((LM_DEBUG, "After activation: %d\n", after_act)); { /* * C++ Language Mapping (formal/03-06-03), section 1.37.3 (Servant * Memory Management Considerations), first bullet on page 1-136: * * POA::id_to_servant returns a Servant. The POA invokes _add_ref * once on the Servant before returning it; the caller of * id_to_servant is responsible for invoking _remove_ref on the * returned servant when it is finished with it. */ CORBA::ULong refCountBeforeIdToServant = h->_refcount_value (); ACE_DEBUG ((LM_DEBUG, "Before id_to_servant: %d\n", refCountBeforeIdToServant)); PortableServer::ServantBase_var srv = poa->id_to_servant (oid.in()); CORBA::ULong refCountAfterIdToServant = srv->_refcount_value ();; ACE_DEBUG ((LM_DEBUG, "After id_to_servant: %d\n", refCountAfterIdToServant)); /* * According to the above quote, this assertion shall be true. */ ACE_ASSERT (refCountAfterIdToServant == refCountBeforeIdToServant + 1); /* * At the end of this scope, "srv" is destructed, which decrements * the servant's reference count. */ } CORBA::ULong before_deact = h->_refcount_value (); ACE_DEBUG ((LM_DEBUG, "Before deactivate_object: %d\n", before_deact)); poa->deactivate_object (oid.in()); /* * Because id_to_servant did not increment the reference count, but * the reference count was decremented by the "srv" destructor, the * reference count, using TAO 1.4.5, is now 0, and the servant has * been destructed. So the following will crash, despite being * correct. */ CORBA::ULong after_deact = h->_refcount_value (); ACE_DEBUG ((LM_DEBUG, "After deactivate_object: %d\n", after_deact)); h->_remove_ref (); orb->shutdown (1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int result = 1; try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var tmp = orb->string_to_object(ior); Test::Server_var test_server = Test::Server::_narrow(tmp.in ()); if (CORBA::is_nil (test_server.in ())) ACE_ERROR_RETURN ((LM_DEBUG, "ERROR: Nil reference in Test::Server reference <%s>\n", ior), 1); CORBA::Any scope_as_any; scope_as_any <<= Messaging::SYNC_NONE; CORBA::PolicyList policies(1); policies.length (1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, scope_as_any); tmp = test_server->_set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); Test::Server_var test_server_no_sync = Test::Server::_narrow(tmp.in ()); if (CORBA::is_nil (test_server_no_sync.in ())) ACE_ERROR_RETURN ((LM_DEBUG, "ERROR: Nil reference in Test::Server reference <%s>\n", ior), 1); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); Worker worker (orb.in ()); if (worker.activate (THR_NEW_LWP | THR_JOINABLE, 1) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate client server thread\n"), 1); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test starting . . .\n")); Client client_impl; PortableServer::ObjectId_var id = root_poa->activate_object (&client_impl); tmp = root_poa->id_to_reference (id.in ()); Test::Client_var test_client = Test::Client::_narrow (tmp.in ()); // setup client callback at server test_server_no_sync->setup (test_client.in ()); // send oneway request to server test_server_no_sync->request (1); // sleep 2 sec to give ample opportunity for oneway reply to be received by worker ACE_OS::sleep (2); // check if reply received if (client_impl.reply_count () > 0) { ACE_DEBUG ((LM_INFO, "(%P|%t) Oneway reply correctly received\n")); result = 0; // test OK } else { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: Oneway reply not received\n")); // send second request to trigger reception of first and second reply test_server_no_sync->request (2); // sleep 2 sec to give ample opportunity for oneway reply to be received by worker ACE_OS::sleep (2); if (client_impl.reply_count () > 1) { ACE_DEBUG ((LM_INFO, "(%P|%t) Received both replies after second request\n")); } else { ACE_ERROR ((LM_ERROR, "(%P|%t) FATAL ERROR: Still no replies received\n")); } } // shutdown server (use original synchronous reference to be sure to deliver message) test_server->shutdown (); // shutdown worker orb->shutdown (1); worker.thr_mgr ()->wait (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return result; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { CORBA::ORB_var orb; CORBA::Object_var obj; PortableServer::POA_var root_poa; PortableServer::POAManagerFactory_var poa_manager_factory; if (parse_args (argc, argv) != 0) return 1; const ACE_TCHAR *e1_format= ACE_TEXT ("iiop://%s:%d"); const ACE_TCHAR *e2_format= ACE_TEXT ("iiop://%s:%d/hostname_in_ior=unreachable"); ACE_TCHAR hostname[256]; int num_extra = 4; switch (host_form) { case from_hostname: ACE_OS::hostname (hostname, sizeof(hostname) / sizeof (ACE_TCHAR)); break; case use_localhost: ACE_OS::strcpy (hostname, ACE_TEXT ("localhost")); break; case use_defaulted: hostname[0] = ACE_TEXT ('\0'); break; case multi_protocol: hostname[0] = ACE_TEXT ('\0'); e2_format = ACE_TEXT ("diop://"); num_extra = 6; break; } size_t hostname_len = ACE_OS::strlen (hostname); size_t e1_len = ACE_OS::strlen (e1_format) + 5; // 5 for the port# size_t e2_len = ACE_OS::strlen (e2_format) + 5; ACE_TCHAR **extra = 0; ACE_NEW_RETURN (extra, ACE_TCHAR *[num_extra], -1); extra[0] = ACE::strnew (ACE_TEXT ("-ORBEndpoint")); ACE_NEW_RETURN (extra[1], ACE_TCHAR[e1_len + hostname_len + 1], -1); ACE_OS::sprintf (extra[1], e1_format, hostname, endpoint_port); extra[2] = ACE::strnew (ACE_TEXT ("-ORBEndpoint")); ACE_NEW_RETURN (extra[3], ACE_TCHAR[e2_len + hostname_len + 1], -1); ACE_OS::sprintf (extra[3], e2_format, hostname, endpoint_port+1); if (host_form == multi_protocol) { extra[4] = ACE::strnew (ACE_TEXT ("-ORBSvcConf")); extra[5] = ACE::strnew (svc_conf_file); } ACE_TCHAR **largv = new ACE_TCHAR *[argc+num_extra]; int i = 0; for (i = 0; i < argc; i++) largv[i] = argv[i]; ACE_DEBUG ((LM_DEBUG,"server adding args: ")); for (i = 0; i < num_extra; i++) { ACE_DEBUG ((LM_DEBUG, "%s ", extra[i])); largv[argc+i] = extra[i]; } ACE_DEBUG ((LM_DEBUG, "\n")); argc += num_extra; try { orb = CORBA::ORB_init (argc, largv, "EndpointPolicy"); obj = orb->resolve_initial_references("RootPOA"); root_poa = PortableServer::POA::_narrow (obj.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); poa_manager_factory = root_poa->the_POAManagerFactory (); } catch (CORBA::Exception &ex) { ex._tao_print_exception("initialization error "); return 1; } for (i = 0; i < num_extra; i++) ACE::strdelete (extra[i]); delete [] extra; delete [] largv; //----------------------------------------------------------------------- // Create two valid endpoint policies. One to match each of the generated // endpoint arguments supplied to ORB_init(). PortableServer::POAManager_var good_pm; PortableServer::POAManager_var bad_pm; CORBA::PolicyList policies; policies.length (1); EndpointPolicy::EndpointList list; list.length (1); list[0] = new IIOPEndpointValue_i (ACE_TEXT_ALWAYS_CHAR (hostname), endpoint_port); try { CORBA::Any policy_value; policy_value <<= list; policies[0] = orb->create_policy (EndpointPolicy::ENDPOINT_POLICY_TYPE, policy_value); good_pm = poa_manager_factory->create_POAManager ("goodPOAManager", policies); if (host_form == use_defaulted) { ACE_ERROR_RETURN ((LM_DEBUG, "ERROR: Expected to catch policy error with " "defaulted hostname, but didn't.\n"),1); } } catch (CORBA::PolicyError &) { if (host_form == use_defaulted) { ACE_ERROR_RETURN ((LM_DEBUG, "Defaulted hostname properly rejected\n"), 0); } ACE_ERROR_RETURN ((LM_DEBUG, "ERROR: Unexpectedly caught PolicyError " "exception host_form = %s\n", form_arg), 1); } catch (CORBA::Exception &ex) { ex._tao_print_exception ("Failed to create reachable POA manager"); return 1; } list[0] = new IIOPEndpointValue_i("unreachable", endpoint_port+1); try { CORBA::Any policy_value; policy_value <<= list; policies[0] = orb->create_policy (EndpointPolicy::ENDPOINT_POLICY_TYPE, policy_value); bad_pm = poa_manager_factory->create_POAManager ("badPOAManager", policies); } catch (CORBA::Exception &ex) { ex._tao_print_exception ("Failed to create unreachable POA manager"); return 1; } try { Hello *hello_impl; ACE_NEW_RETURN (hello_impl, Hello (orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(hello_impl); // Create poas assiciated with the each the good poa manager and the // bad poa manager. policies.length(0); PortableServer::POA_var good_poa = root_poa->create_POA ("goodPOA", good_pm.in (), policies); int result = 0; result = make_ior (orb.in(), root_poa.in(), hello_impl, root_ior_file); if (result != 0) return result; result = make_ior (orb.in(), good_poa.in(), hello_impl, good_ior_file); if (result != 0) return result; good_pm->activate (); PortableServer::POA_var bad_poa; if (host_form != multi_protocol) { bad_poa = root_poa->create_POA ("badPOA", bad_pm.in (), policies); result = make_ior (orb.in(), bad_poa.in(), hello_impl, bad_ior_file); if (result != 0) return result; bad_pm->activate (); } if (host_form == from_hostname || host_form == use_localhost) { orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); } } catch (CORBA::Exception &ex) { ex._tao_print_exception ("cannot run server"); } try { root_poa->destroy (1, 1); orb->destroy (); } catch (CORBA::Exception &ex) { ex._tao_print_exception ("CORBA exception during shutdown"); } return 0; }
int main(int argc, char *argv[]) { int c, instance = -1; ACE_CString daemonRef; ACE_CString hostName; ACE_CString additional; for (;;) { int option_index = 0; c = getopt_long(argc, argv, "hi:d:H:a:", long_options, &option_index); if (c == -1) break; switch (c) { case 'h': usage(argv[0]); return 0; case 'i': instance = ACE_OS::atoi(optarg); break; case 'd': daemonRef = optarg; break; case 'H': hostName = optarg; break; case 'a': additional = optarg; break; } } if (instance == -1) { ACE_OS::printf("Error: instance is a mandatory option try %s -h\n", argv[0]); return -1; } #define DEFAULT_LOG_FILE_NAME "acs_local_log" ACE_CString daemonsLogFileName = getTempFileName(0, DEFAULT_LOG_FILE_NAME); // replace "ACS_INSTANCE.x" with "acsdaemonStartAcs_" + <timestamp> ACE_CString daemonsDir = "acsdaemonStartAcs_" + getStringifiedTimeStamp(); ACE_CString instancePart("ACS_INSTANCE."); ACE_CString::size_type pos = daemonsLogFileName.find(instancePart); daemonsLogFileName = daemonsLogFileName.substring(0, pos) + daemonsDir + daemonsLogFileName.substring(pos + instancePart.length() + 1); // +1 for skipping instance number ACE_OS::setenv("ACS_LOG_FILE", daemonsLogFileName.c_str(), 1); LoggingProxy *logger = new LoggingProxy(0, 0, 31); if (logger) { LoggingProxy::init(logger); LoggingProxy::ProcessName(argv[0]); LoggingProxy::ThreadName("main"); } else ACS_SHORT_LOG((LM_INFO, "Failed to initialize logging.")); StartCallback* sc = new StartCallback(); try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "TAO"); // get a reference to the RootPOA CORBA::Object_var pobj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(pobj.in()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // create policies CORBA::PolicyList policy_list; policy_list.length(5); policy_list[0] = root_poa->create_request_processing_policy(PortableServer::USE_DEFAULT_SERVANT); policy_list[1] = root_poa->create_id_uniqueness_policy(PortableServer::MULTIPLE_ID); policy_list[2] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); policy_list[3] = root_poa->create_servant_retention_policy(PortableServer::NON_RETAIN); policy_list[4] = root_poa->create_lifespan_policy(PortableServer::PERSISTENT); // create a ACSDaemon POA with policies PortableServer::POA_var poa = root_poa->create_POA("DaemonCallback", poa_manager.in(), policy_list); // destroy policies for (CORBA::ULong i = 0; i < policy_list.length(); ++i) { CORBA::Policy_ptr policy = policy_list[i]; policy->destroy(); } // set as default servant poa->set_servant(sc); // create reference PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("DaemonCallback"); pobj = poa->create_reference_with_id (oid.in(), sc->_interface_repository_id()); CORBA::String_var m_ior = orb->object_to_string(pobj.in()); // bind to IOR table CORBA::Object_var table_object = orb->resolve_initial_references("IORTable"); IORTable::Table_var adapter = IORTable::Table::_narrow(table_object.in()); if (CORBA::is_nil(adapter.in())) { ACS_SHORT_LOG ((LM_ERROR, "Nil IORTable")); return -1; } else { adapter->bind("DaemonCallback", m_ior.in()); } // activate POA poa_manager->activate(); ACS_SHORT_LOG((LM_INFO, "%s is waiting for incoming requests.", "DaemonCallback")); // construct default one if (daemonRef.length() == 0) { if (hostName.length() == 0) { hostName = ACSPorts::getIP(); } daemonRef = "corbaloc::"; daemonRef = daemonRef + hostName + ":" + ACSPorts::getServicesDaemonPort().c_str() + "/" + ::acsdaemon::servicesDaemonServiceName; ACS_SHORT_LOG((LM_INFO, "Using local ACS Services Daemon reference: '%s'", daemonRef.c_str())); } else { ACS_SHORT_LOG((LM_INFO, "ACS Services Daemon reference obtained via command line: '%s'", daemonRef.c_str())); } CORBA::Object_var obj = orb->string_to_object(daemonRef.c_str()); if (CORBA::is_nil(obj.in())) { ACS_SHORT_LOG((LM_INFO, "Failed to resolve reference '%s'.", daemonRef.c_str())); return -1; } acsdaemon::ServicesDaemon_var daemon = acsdaemon::ServicesDaemon::_narrow(obj.in()); if (CORBA::is_nil(daemon.in())) { ACS_SHORT_LOG((LM_INFO, "Failed to narrow reference '%s'.", daemonRef.c_str())); return -1; } // @todo implement support for callback and wait for completion call acsdaemon::DaemonSequenceCallback_var dummyCallback = sc->_this(); ACS_SHORT_LOG((LM_INFO, "Calling start_acs(%d, %s, dummyCallback).", instance, additional.c_str())); daemon->start_acs(dummyCallback.in(), instance, additional.c_str()); ACS_SHORT_LOG((LM_INFO, "ACS start message issued.")); while(!sc->isComplete()) { if (orb->work_pending()) orb->perform_work(); } } catch(ACSErrTypeCommon::BadParameterEx & ex) { ACSErrTypeCommon::BadParameterExImpl exImpl(ex); exImpl.log(); return -1; } catch(CORBA::Exception & ex) { ACS_SHORT_LOG((LM_INFO, "Failed.")); ex._tao_print_exception("Caught unexpected exception:"); return -1; } return 0; }