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, " (%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 (); // Policies for the childPOA to be created. CORBA::PolicyList policies (1); policies.length (1); CORBA::Any pol; pol <<= BiDirPolicy::BOTH; policies[0] = orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, pol); // 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 = root_poa->create_POA ("childPOA", poa_manager.in (), policies); // Creation of childPOA is over. Destroy the Policy objects. for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } poa_manager->activate (); if (parse_args (argc, argv) != 0) return 1; Simple_Server_i server_impl (orb.in (), no_iterations); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("simple_server"); child_poa->activate_object_with_id (id.in (), &server_impl); CORBA::Object_var obj = child_poa->id_to_reference (id.in ()); CORBA::String_var ior = orb->object_to_string (obj.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); } int retval = 0; while (retval == 0) { // Just process one upcall. We know that we would get the // clients IOR in that call. CORBA::Boolean pending = orb->work_pending(); if (pending) { orb->perform_work(); } // Now that hopefully we have the clients IOR, just start // making remote calls to the client. retval = server_impl.call_client (); } ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); root_poa->destroy (1, 1); } 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); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var obj = orb->string_to_object(ior); Transaction_var trans = Transaction::_narrow(obj.in()); if (CORBA::is_nil(trans.in())) throw std::runtime_error("failed to find a valid Transaction IOR"); Person_var p = new Person_i("TAOUser", 1000); const char* n = p->name(); double bal = p->balance() / 100.0; std::cout << "Client: Sending person:" << n << " starting_balance:$" << bal << std::endl; CORBA::Long b = trans->update(p.in()); while (orb->work_pending()) { orb->perform_work(); } std::cout << "Client: Ending balance: " << b/100.0 << std::endl; orb->destroy(); } catch(const CORBA::Exception& e) { std::cerr << e << std::endl; return 1; } catch (const std::runtime_error &e) { std::cerr << e.what() << std::endl; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB first. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); int result = parse_args (argc, argv); if (result == -1) return -1; // Make sure we have a valid <output_file> output_file = ACE_OS::fopen (output_file_name, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_DEBUG, "Cannot open output file %s\n", output_file_name), -1); else ACE_DEBUG ((LM_DEBUG, "File Opened Successfully\n")); CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); // Get the POA_var object from Object_var. PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); PortableServer::POAManager_var mgr = root_poa->the_POAManager (); mgr->activate (); // Initialize the AVStreams components. TAO_AV_CORE::instance ()->init (orb.in (), root_poa.in ()); Server server; result = server.init (argc, argv); if (result != 0) return result; while ( !done ) { if ( orb->work_pending( ) ) { orb->perform_work (); } } orb->shutdown( 1 ); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("server::init"); return -1; } ACE_OS::fclose (output_file); 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; AMI_Test_i * servant = new AMI_Test_i(orb.in()); PortableServer::ServantBase_var safe (servant); server = servant->_this(); 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 (); // Main thread collects replies. It needs to collect // <nthreads*niterations> replies. number_of_replies = nthreads * niterations; // 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); if (debug) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) : Entering perform_work loop to receive <%d> replies\n", number_of_replies.value ())); } // ORB loop. while (number_of_replies > 0) { CORBA::Boolean pending = orb->work_pending(); if (pending) { orb->perform_work(); } // On some systems this loop must yield or else the other threads // will not get a chance to run. ACE_OS::thr_yield(); } if (debug) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) : Exited perform_work loop Received <%d> replies\n", (nthreads*niterations) - number_of_replies.value ())); } client.thr_mgr ()->wait (); ACE_DEBUG ((LM_DEBUG, "threads finished\n")); 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 invalid_exception; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int idle_count = 0; 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 = 0; 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\n", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); poa_manager->activate (); for (;;) { ACE_Time_Value tv (0, 500); while (orb->work_pending (tv)) { ACE_DEBUG ((LM_DEBUG, "Work pending\n")); ACE_Time_Value tv2 (0, 500); if (orb->work_pending (tv2)) { ACE_Time_Value work_tv (0, 500); orb->perform_work (work_tv); } } ++idle_count; } orb->destroy (); } catch (const CORBA::BAD_INV_ORDER&) { // Expected } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } if (idle_count == 0) { ACE_ERROR_RETURN ((LM_ERROR, "ERROR: Got unexpected idle_count %d\n", idle_count), 1); } else { ACE_DEBUG ((LM_DEBUG, "Got %d idle moments\n", idle_count)); } 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 ac, ACE_TCHAR* av[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(ac, av); NodeFactory::register_new_factory(* orb.in()); BoxedValueFactory::register_new_factory(* orb.in()); BaseValueFactory::register_new_factory(* orb.in()); TValueFactory::register_new_factory(* orb.in()); ConfigValueFactory::register_new_factory(* orb.in()); CORBA::Object_var obj = orb->string_to_object(server_ior); ValueServer_var tst = ValueServer::_narrow(obj.in()); ACE_ASSERT(! CORBA::is_nil(tst.in())); // invoke operations and print the results boxedLong* p1 = new boxedLong (774); boxedLong* p2 = new boxedLong (775); boxedString* s1 = new boxedString ("hello"); boxedString* s2 = new boxedString ("world"); boxedString* null = 0; boxedValue* b = new OBV_demo::value::idl::boxedValue (); b->b1 (p1); b->b2 (p2); boxedValue* bb = new OBV_demo::value::idl::boxedValue (); bb->b1 (p1); bb->b2 (p1); ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing two boxed values in one valuetype: %s\n", tst->receive_boxedvalue (b))); ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing one boxed values twice in one valuetype: %s\n", tst->receive_boxedvalue (bb))); ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing two integers: %s\n", tst->receive_long (p1, p2))); ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing one integer twice: %s\n", tst->receive_long (p1, p1))); ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing two strings: %s\n", tst->receive_string (s1, s2))); ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing null: %s\n", tst->receive_string (s1, null))); Node* n4 = new OBV_demo::value::idl::Node (4, 0); Node* n3 = new OBV_demo::value::idl::Node (3, n4); Node* n2 = new OBV_demo::value::idl::Node (2, n3); Node* n1 = new OBV_demo::value::idl::Node (1, n2); n4->next(n1); ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing a list structure: %s\n", tst->receive_list (n1))); #if 1 TValue* t = new OBV_demo::value::idl::TValue (); t->data (20); t->basic_data (10); ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing inout truncatable: %s\n", tst->receive_truncatable (t))); if (t->data () != 21 || t->basic_data () != 11) { std::cerr << "Received incorrect truncatable data" << std::endl; return 1; } #endif const CORBA::ULong sz = 50; ::demo::value::idl::ConfigValues configs (sz); configs.length (sz); for (CORBA::ULong i = 0; i < sz; ++i) { configs[i] = new ConfigValueImpl ("IOR", IOR); } ACE_DEBUG ((LM_DEBUG, "(%P|%t)Passing sequence: %s\n", tst->receive_sequence (configs))); while (orb->work_pending()) { orb->perform_work(); } orb->destroy(); } catch(const CORBA::Exception& e) { std::cerr << e << std::endl; return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { // Register the default factory in the Service Configurator. // If your platform supports static constructors then you can // simply using the ACE_STATIC_SVC_DEFINE() macro, unfortunately TAO // must run on platforms where static constructors do not work well, // so we have to explicitly invoke this function. TAO_EC_Default_Factory::init_svcs (); // The exception macros are described in $ACE_ROOT/docs/exceptions.html // and defined in $ACE_ROOT/ace/CORBA_macros.h. // If your platform supports native exceptions, and TAO was compiled // with native exception support then you can simply use try/catch // and avoid the argument. // Unfortunately many embedded systems cannot use exceptions due to // the space and time overhead. // try { // **************** HERE STARTS THE ORB SETUP // Create the ORB, pass the argv list for parsing. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Parse the arguments, you usually want to do this after // invoking ORB_init() because ORB_init() will remove all the // -ORB options from the command line. if (parse_args (argc, argv) == -1) { ACE_ERROR ((LM_ERROR, "Usage: Service [-m udp_mcast_addr]\n")); return 1; } if (valuetype) { Hello::ValueTypeData_init *vb_factory = 0; ACE_NEW_RETURN (vb_factory, Hello::ValueTypeData_init, 1); // supplied by mapping orb->register_value_factory (vb_factory->tao_repository_id (), vb_factory); vb_factory->_remove_ref (); // release ownership } // This is the standard code to get access to the POA and // activate it. // The POA starts in the holding state, if it is not activated // it will not process any requests. 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 (); // **************** THAT COMPLETS THE ORB SETUP // **************** HERE START THE LOCAL EVENT CHANNEL SETUP // This structure is used to define the startup time event // channel configuration. // This structure is described in // // $TAO_ROOT/docs/ec_options.html // TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); // Create the Event Channel implementation class TAO_EC_Event_Channel ec_impl (attributes); // Activate the Event Channel, depending on the configuration // that may involve creating some threads. // But it should always be invoked because several internal data // structures are initialized at that point. ec_impl.activate (); // The event channel is activated as any other CORBA servant. // In this case we use the simple implicit activation with the // RootPOA RtecEventChannelAdmin::EventChannel_var event_channel = ec_impl._this (); // **************** THAT COMPLETES THE LOCAL EVENT CHANNEL SETUP // **************** HERE STARTS THE FEDERATION SETUP // The next step is to setup the multicast gateways. // There are two gateways involved, one sends the locally // generated events to the federated peers, the second gateway // receives multicast traffic and turns it into local events. // The sender requires a helper object to select what // multicast group will carry what traffic, this is the // so-called 'Address Server'. // The intention is that advanced applications can use different // multicast groups for different events, this can exploit // network interfaces that filter unwanted multicast traffic. // The helper object is accessed through an IDL interface, so it // can reside remotely. // In this example, and in many application, using a fixed // multicast group is enough, and a local address server is the // right approach. // First we convert the string into an INET address, then we // convert that into the right IDL structure: ACE_INET_Addr udp_addr (udp_mcast_address); ACE_DEBUG ((LM_DEBUG, "udp mcast address is: %s\n", udp_mcast_address)); // Now we create and activate the servant AddrServer as_impl (udp_addr); RtecUDPAdmin::AddrServer_var address_server = as_impl._this (); TAO_ECG_Refcounted_Endpoint endpoint(new TAO_ECG_UDP_Out_Endpoint); // Now we connect the sender as a consumer of events, it will // receive any event from any source and send it to the "right" // multicast group, as defined by the address server set above: RtecEventChannelAdmin::ConsumerQOS sub; sub.is_gateway = 1; sub.dependencies.length (1); sub.dependencies[0].event.header.type = ACE_ES_EVENT_ANY; // first free event type sub.dependencies[0].event.header.source = ACE_ES_EVENT_SOURCE_ANY; // Any source is OK // To receive events we need to setup an event handler: PortableServer::Servant_var<TAO_ECG_UDP_Receiver> receiver = TAO_ECG_UDP_Receiver::create(); TAO_ECG_Mcast_EH mcast_eh (&(*receiver)); // The event handler uses the ORB reactor to wait for multicast // traffic: mcast_eh.reactor (orb->orb_core ()->reactor ()); // The multicast Event Handler needs to know to what multicast // groups it should listen to. To do so it becomes an observer // with the event channel, to determine the list of events // required by all the local consumer. // Then it register for the multicast groups that carry those // events: mcast_eh.open (event_channel.in ()); // Again the receiver connects to the event channel as a // supplier of events, using the Observer features to detect // local consumers and their interests: receiver->init (event_channel.in (), endpoint, address_server.in ()); // The Receiver is also a supplier of events. The exact type of // events is only known to the application, because it depends // on the traffic carried by all the multicast groups that the // different event handlers subscribe to. // In this example we choose to simply describe our publications // using wilcards, any event from any source. More advanced // application could use the Observer features in the event // channel to update this information (and reduce the number of // multicast groups that each receive subscribes to). // In a future version the event channel could perform some of // those tasks automatically RtecEventChannelAdmin::SupplierQOS pub; pub.publications.length (1); pub.publications[0].event.header.type = ACE_ES_EVENT_ANY; pub.publications[0].event.header.source = ACE_ES_EVENT_SOURCE_ANY; pub.is_gateway = 1; receiver->connect (pub); // **************** THAT COMPLETES THE FEDERATION SETUP // **************** HERE STARTS THE CLIENT SETUP // First let us create a consumer and connect it to the event // channel Consumer consumer (valuetype); RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin = event_channel->for_consumers (); consumer.connect (consumer_admin.in ()); // **************** THAT COMPLETES THE CLIENT SETUP // **************** HERE STARTS THE EVENT LOOP // Wait for events, including incoming multicast data. // We could also use orb->run(), but that will not let us // terminate the application in a nice way. for (int i = 0; i != 100; ++i) { CORBA::Boolean there_is_work = orb->work_pending (); if (there_is_work) { // We use a TAO extension. The CORBA mechanism does not // provide any decent way to control the duration of // perform_work() or work_pending(), so just calling // them results in a spin loop. ACE_Time_Value tv (0, 50000); orb->perform_work (tv); } ACE_Time_Value tv (0, 100000); ACE_OS::sleep (tv); if (consumer.event_count () == 25) { break; } } // **************** THAT COMPLETES THE EVENT LOOP // **************** HERE STARTS THE CLEANUP CODE consumer.disconnect (); // Now let us close the Receiver receiver->shutdown (); int const r = mcast_eh.shutdown (); if (r == -1) { ACE_ERROR_RETURN ((LM_ERROR, "Closing MCast event handler\n"), 1); } // The event channel must be destroyed, so it can release its // resources, and inform all the clients that are still // connected that it is going away. event_channel->destroy (); // Deactivating the event channel implementation is not strictly // required, the POA will do it for us, but it is good manners: { // Using _this() activates with the default POA, we must gain // access to that POA to deactivate the object. // Notice that we 'know' that the default POA for this servant // is the root POA, but the code is more robust if we don't // rely on that. PortableServer::POA_var poa = ec_impl._default_POA (); // Get the Object Id used for the servant.. PortableServer::ObjectId_var oid = poa->servant_to_id (&ec_impl); // Deactivate the object poa->deactivate_object (oid.in ()); } // Now we can destroy the POA, the flags mean that we want to // wait until the POA is really destroyed poa->destroy (1, 1); // Finally destroy the ORB orb->destroy (); // **************** THAT COMPLETES THE CLEANUP CODE ACE_DEBUG ((LM_DEBUG, "UDP receiver ready\n")); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Service"); 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); // There must be at least two arguments, the first is the factory // name, the rest are the names of the stock symbols we want to // get quotes for. if (argc < 3) { cerr << "Usage: " << argv[0] << " Factory_IOR symbol symbol..." << endl; return 1; } 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 (); // Use the first argument to create the factory object reference, // in real applications we use the naming service, but let's do // the easy part first! CORBA::Object_var factory_object = orb->string_to_object (argv[1]); // Now downcast the object reference to the appropriate type Quoter::Stock_Factory_var factory = Quoter::Stock_Factory::_narrow (factory_object.in ()); // Create and activate the handler... int response_count = 0; Single_Query_Stock_Handler_i handler_i (&response_count); Quoter::AMI_Single_Query_StockHandler_var handler = handler_i._this (); // Send all the requests, careful with error handling int request_count = 0; for (int i = 2; i != argc; ++i) { try { // Get the stock object Quoter::Stock_var tmp = factory->get_stock (ACE_TEXT_ALWAYS_CHAR (argv[i])); Quoter::Single_Query_Stock_var stock = Quoter::Single_Query_Stock::_narrow (tmp.in ()); if (CORBA::is_nil (stock.in ())) { cerr << "Cannot get single query interface for <" << argv[i] << ">" << endl; } stock->sendc_get_price_and_names (handler.in ()); request_count++; } catch (Quoter::Invalid_Stock_Symbol &) { cerr << "Invalid stock symbol <" << argv[i] << ">" << endl; } } while (response_count < request_count && orb->work_pending ()) { orb->perform_work (); } // Destroy the POA, waiting until the destruction terminates poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception &) { cerr << "CORBA exception raised!" << endl; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { if (argc < 2) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Usage: client filename ") ACE_TEXT ("[filename ...]\n")), -1); // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "Mighty ORB"); // Get the Root POA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ()); // Activate the POA manager. PortableServer::POAManager_var mgr = poa->the_POAManager (); mgr->activate (); // Get an Iterator_Factory reference. Web_Server::Iterator_Factory_var factory = ::get_iterator (orb.in ()); if (CORBA::is_nil (factory.in ())) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Object pointed to by:\n %s\n") ACE_TEXT ("is not an Iterator_Factory object.\n"), argv[1]), -1); // 1 millisecond delay to reduce "busy waiting" in ORB event // loop. (simulating "work") ACE_Time_Value tv (0, 1000); // Variable used to keep track of when file retrieval has // completed. int request_count = 0; ::invoke_requests (argc, argv, &request_count, factory.in ()); // Run the ORB event loop. while (request_count > 0) { CORBA::Boolean more_work; more_work = orb->work_pending (); if (more_work) { orb->perform_work (); } else ACE_OS::sleep (tv); } orb->shutdown (0); orb->destroy (); } catch (const Web_Server::Error_Result& exc) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Caught Web Server exception with ") ACE_TEXT ("status %d\n"), exc.status), -1); } catch (const CORBA::Exception& ex) { ex._tao_print_exception (ACE_TEXT ("Caught unexpected exception:")); return -1; } // Wait for all children to exit. ACE_Process_Manager::instance ()->wait (); 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); if (id_offset + client_threads >= ACE_OS::strlen (Test::ClientIDs)) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("ERROR: too many clients\n")), -1); CORBA::Object_var obj = orb->string_to_object (ior); // Create Hello reference. Test::Hello_var hello = Test::Hello::_narrow (obj.in ()); if (CORBA::is_nil (hello.in ())) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("ERROR: nil Hello object\n")), -1); if (do_shutdown) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nClient sending server shutdown message....\n"))); ACE_OS::sleep (7); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Shutting down NOW\n"))); hello->shutdown (); } else { Test::UIPMC_Object_var uipmc_obj = hello->get_object (); { // start clients ClientThread cln_thr (uipmc_obj.in (), payload_length, id_offset, payload_calls, sleep_millis); cln_thr.activate (THR_NEW_LWP | THR_JOINABLE, client_threads); cln_thr.wait (); } // Give a chance to flush all OS buffers for client. while (orb->work_pending ()) orb->perform_work (); } orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in client main ():"); return 1; } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nClient finished successfully.\n"))); return 0; }
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 (); // Create an object. Time_impl time_servant; // Write its stringified reference to stdout. PortableServer::ObjectId_var id = poa->activate_object (&time_servant); CORBA::Object_var object = poa->id_to_reference (id.in ()); Time_var tm = Time::_narrow (object.in ()); CORBA::String_var str = orb->object_to_string (tm.in ()); ACE_DEBUG ((LM_DEBUG, "%s\n", str.in ())); 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", str.in ()); ACE_OS::fclose (output_file); } // Explicit Event Loop. while (!done) { CORBA::Boolean pending = orb->work_pending (); if (pending) { orb->perform_work (); } do_something_else (); } orb->shutdown (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("server: a CORBA exception occured"); return 1; } catch (...) { ACE_ERROR_RETURN ((LM_ERROR, "%s\n", "client: an unknown exception was caught\n"), 1); } 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; }