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 (); 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 ()); 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); Event_Loop_Task event_loop_task (orb.in ()); if (event_loop_task.activate (THR_NEW_LWP | THR_JOINABLE, number_of_event_loop_threads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate event_loop threads\n"), -1); event_loop_task.thr_mgr ()->wait (); ACE_DEBUG ((LM_DEBUG, "Server: Event loop finished\n")); root_poa->destroy (1, 1); } 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 the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Initialize options based on command-line arguments. int parse_args_result = parse_args (argc, argv); if (parse_args_result != 0) return parse_args_result; // Get an object reference from the argument string. CORBA::Object_var object = orb->string_to_object (IOR); // Try to narrow the object reference to a <server> reference. test_var server = test::_narrow (object.in ()); Client_Task client_task (server.in ()); if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, number_of_client_threads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate client threads\n"), -1); // Make sure to give the client threads enough time to become // leaders. ACE_OS::sleep (4); Event_Loop_Task event_loop_task (orb.in ()); if (event_loop_task.activate (THR_NEW_LWP | THR_JOINABLE, number_of_event_loop_threads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate event_loop threads\n"), -1); event_loop_task.thr_mgr ()->wait (); client_task.thr_mgr ()->wait (); ACE_DEBUG ((LM_DEBUG, "Client: All threads finished @ %T\n")); // Shutdown server. if (shutdown_server) { server->shutdown (); } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return -1; } return 0; }
void test_reactor_upcall (ACE_Reactor &reactor) { Handler handler (reactor); if (handler.shutdown_) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error initializing test; abort.\n"))); return; } Event_Loop_Task event_loop_task (reactor); // Start up the event loop threads. int result = event_loop_task.activate (THR_NEW_LWP | THR_JOINABLE, number_of_event_loop_threads); if (result != 0) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("test_reactor_upcall, activate"))); // Data message. Message data_message; data_message.type_ = Message::DATA; data_message.size_ = ACE_OS::strlen (message); ACE_OS::strcpy (data_message.data_, message); // Send in three pieces because the struct members may not be adjacent // in memory. for (int i = 0; i < number_of_messages; ++i) { // This should trigger a call to <handle_input>. ssize_t sent = ACE::send_n (handler.pipe_.write_handle (), &data_message.type_, sizeof (data_message.type_)); if (sent == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t): %p\n"), ACE_TEXT ("send 1"))); sent = ACE::send_n (handler.pipe_.write_handle (), &data_message.size_, sizeof (data_message.size_)); if (sent == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t): %p\n"), ACE_TEXT ("send 2"))); sent = ACE::send_n (handler.pipe_.write_handle (), &data_message.data_, data_message.size_); if (sent == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t): %p\n"), ACE_TEXT ("send 3"))); } // We are done: send shutdown message. Message shutdown_message; shutdown_message.type_ = Message::SHUTDOWN; shutdown_message.size_ = 0; // This should trigger a call to <handle_input>. ssize_t sent = ACE::send_n (handler.pipe_.write_handle (), &shutdown_message.type_, sizeof (shutdown_message.type_)); if (sent == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t): %p\n"), ACE_TEXT ("send 4"))); sent = ACE::send_n (handler.pipe_.write_handle (), &shutdown_message.size_, sizeof (shutdown_message.size_)); if (sent == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t): %p\n"), ACE_TEXT ("send 5"))); // Wait for the event loop tasks to exit. event_loop_task.wait (); }