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[]) { // Fetching the high res timer's global scale factor ensures that it // is calibrated (if necessary on this platform) at the beginning of // the test. While the timer would otherwise be calibrated on first // use, this introduces delay in the middle of the test's execution. // This leads to failures due to timing assumptions (timeouts, etc.) // within the test itself. (void) ACE_High_Res_Timer::global_scale_factor(); try { CORBA::ORB_var orb = initialize_orb_and_poa(argc, argv); parse_args(argc, argv); test_i servant (orb.in()); CORBA::String_var ior = servant.create_and_activate_server(); write_ior_to_file(ior.in()); orb->run(); } catch(...) { report_exception(); return 1; } return 0; }
void test_colocated_calls(CORBA::ORB_ptr orb) { test_i servant (orb); CORBA::String_var ior = servant.create_and_activate_server(); test_impl(orb, ACE_TEXT_CHAR_TO_TCHAR(ior.in()), false); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { long retryCount = 0; const ACE_TCHAR *ior_arg = ACE_TEXT("manager.ior"); CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("r:o:")); int c; while ((c = get_opts ()) != -1) { switch (c) { case 'r': retryCount = ACE_OS::atoi(get_opts.opt_arg()); break; case 'o': ior_arg = get_opts.opt_arg(); break; case '?': default: cout << "Usage: " << argv[0] << " [-r retryCount]" << " [-o iorfile]" << endl; break; } } CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); PortableServer::POAManager_var mgr = poa->the_POAManager(); Manager_i servant(retryCount); PortableServer::ObjectId_var oid = poa->activate_object(&servant); obj = poa->id_to_reference(oid.in()); { CORBA::String_var ior = orb->object_to_string(obj.in()); ofstream iorFile(ACE_TEXT_ALWAYS_CHAR(ior_arg)); iorFile << ior.in() << endl; } cout << "IMR Test Manager activated (servers retry = " << retryCount << ")." << endl; mgr->activate(); orb->run(); poa->destroy(1, 1); orb->destroy(); return 0; } catch (const CORBA::Exception& ex) { cerr << "Manager: " << ex << endl; } return 1; }
// ------------------------------------------------------------------------ // int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { if (parse_args (argc, argv) != 0) return 1; ST_AMH_Server amh_server; CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); amh_server.start_orb_and_poa(orb); ST_AMH_Servant servant(orb.in()); amh_server.register_servant(&servant); CORBA::Object_var object = orb->string_to_object(ior); Test::Roundtrip_var roundtrip = Test::Roundtrip::_narrow(object.in ()); if (CORBA::is_nil(roundtrip.in())) { ACE_ERROR_RETURN ((LM_ERROR, "Nil Test::Roundtrip reference <%s>\n", ior), 1); } ACE_thread_t serverThr; ACE_thread_t clientThr; ACE_Thread_Manager::instance()->spawn(start_server, (void*)&amh_server, THR_NEW_LWP | THR_JOINABLE, &serverThr); ACE_Thread_Manager::instance()->spawn(start_client, (void*)roundtrip.in (), THR_NEW_LWP | THR_JOINABLE, &clientThr); ACE_Thread_Manager::instance()->join(clientThr); ACE_OS::printf("End client\n"); ACE_Thread_Manager::instance()->join(serverThr); ACE_OS::printf("End server\n"); orb->destroy(); return 0; }
int main (int argc, char* argv[]) { try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // Find the Naming Service. CORBA::Object_var obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var naming_client = CosNaming::NamingContextExt::_narrow(obj.in()); // Get the Event Channel using Naming Services obj = naming_client->resolve_str("EventService"); // Downcast the object reference to an EventChannel reference. RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); if (CORBA::is_nil(ec.in())) { cerr << "Could not resolve EchoEventChannel." << endl; return 1; } // Get a SupplierAdmin object from the EventChannel. RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); // Get a ProxyPushConsumer from the SupplierAdmin. RtecEventChannelAdmin::ProxyPushConsumer_var consumer = admin->obtain_push_consumer(); // Get the RootPOA. obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); // Instantiate an EchoEventConsumer_i servant. EchoEventSupplier_i servant(orb.in()); // Register it with the RootPOA. PortableServer::ObjectId_var oid = poa->activate_object(&servant); CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(supplier_obj.in()); // Publish the events the supplier provides. ACE_SupplierQOS_Factory qos; qos.insert (MY_SOURCE_ID, // Supplier's unique id MY_EVENT_TYPE, // Event type 0, // handle to the rt_info structure 1); // number of calls // Connect as a supplier of the published events. consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); // Activate the POA via its POAManager. PortableServer::POAManager_var poa_manager = poa->the_POAManager(); poa_manager->activate(); // Create an event (just a string in this case). const CORBA::String_var eventData = CORBA::string_dup("Hello, world."); // Create an event set for one event RtecEventComm::EventSet events (1); events.length (1); // Initialize event header. events[0].header.source = MY_SOURCE_ID; events[0].header.type = MY_EVENT_TYPE; // Initialize data fields in event. events[0].data.any_value <<= eventData; cout << "Supplier starting sending of events" << endl; while (1) { consumer->push (events); ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); orb->run(tv); } orb->destroy(); return 0; } catch (CORBA::Exception& ex) { cerr << "Supplier::main() Caught CORBA::Exception" << endl << ex << endl; } return 1; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { 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; 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 ())); // 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, "Can't 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 (); root_poa->destroy (1, 1); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Server: exception caught - "); return 1; } return 0; }
void foo(boost::future<boost::shared_ptr<Servant3>> s) { // create a servant3 in the same thread as servant1 ServantProxy3 servant(m_servant1_scheduler,std::move(s)); servant.foo().get(); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the EC Factory so we can customize the EC TAO_EC_Default_Factory::init_svcs (); // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); const ACE_TCHAR *ecname = ACE_TEXT ("EventService"); const ACE_TCHAR *address = ACE_TEXT ("localhost"); const ACE_TCHAR *iorfile = 0; u_short port = 12345; u_short listenport = 12345; int mcast = 1; for (int i = 0; argv[i] != 0; i++) { if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-ecname")) == 0) { if (argv[i+1] != 0) ecname = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing Event channel name\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-address")) == 0) { if (argv[i+1] != 0) address = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing address\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-port")) == 0) { if (argv[i+1] != 0) port = ACE_OS::atoi(argv[++i]); else ACE_ERROR_RETURN ((LM_ERROR, "Missing port\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-listenport")) == 0) { if (argv[i+1] != 0) listenport = ACE_OS::atoi(argv[++i]); else ACE_ERROR_RETURN ((LM_ERROR, "Missing port\n"), 0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-iorfile")) == 0) { if (argv[i+1] != 0) iorfile = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing ior file\n"), 0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-udp")) == 0) mcast = 0; } // Get the POA CORBA::Object_var tmpobj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (tmpobj.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Create a local event channel and register it TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); TAO_EC_Event_Channel ec_impl (attributes); ec_impl.activate (); PortableServer::ObjectId_var oid = poa->activate_object(&ec_impl); tmpobj = poa->id_to_reference(oid.in()); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(tmpobj.in()); // Find the Naming Service. tmpobj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(tmpobj.in()); // Bind the Event Channel using Naming Services CosNaming::Name_var name = root_context->to_name (ACE_TEXT_ALWAYS_CHAR (ecname)); root_context->rebind(name.in(), ec.in()); // Get a proxy push consumer from the EventChannel. RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); RtecEventChannelAdmin::ProxyPushConsumer_var consumer = admin->obtain_push_consumer(); // Instantiate an EchoEventSupplier_i servant. EchoEventSupplier_i servant(orb.in()); // Register it with the RootPOA. oid = poa->activate_object(&servant); tmpobj = poa->id_to_reference(oid.in()); RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(tmpobj.in()); // Connect to the EC. ACE_SupplierQOS_Factory qos; qos.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); // Initialize the address server with the desired address. This will // be used by the sender object and the multicast receiver only if // one is not otherwise available via the naming service. ACE_INET_Addr send_addr (port, address); SimpleAddressServer addr_srv_impl (send_addr); // Create an instance of the addr server for local use PortableServer::ObjectId_var addr_srv_oid = poa->activate_object(&addr_srv_impl); tmpobj = poa->id_to_reference(addr_srv_oid.in()); RtecUDPAdmin::AddrServer_var addr_srv = RtecUDPAdmin::AddrServer::_narrow(tmpobj.in()); // Create and initialize the sender object PortableServer::Servant_var<TAO_ECG_UDP_Sender> sender = TAO_ECG_UDP_Sender::create(); TAO_ECG_UDP_Out_Endpoint endpoint; // need to be explicit about the address type when built with // IPv6 support, otherwise SOCK_DGram::open defaults to ipv6 when // given a sap_any address. This causes trouble on at least solaris // and windows, or at most on not-linux. if (endpoint.dgram ().open (ACE_Addr::sap_any, send_addr.get_type()) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "Cannot open send endpoint\n"), 1); } // TAO_ECG_UDP_Sender::init() takes a TAO_ECG_Refcounted_Endpoint. // If we don't clone our endpoint and pass &endpoint, the sender will // attempt to delete endpoint during shutdown. TAO_ECG_Refcounted_Endpoint clone (new TAO_ECG_UDP_Out_Endpoint (endpoint)); sender->init (ec.in (), addr_srv.in (), clone); // Setup the subscription and connect to the EC ACE_ConsumerQOS_Factory cons_qos_fact; cons_qos_fact.start_disjunction_group (); cons_qos_fact.insert (ACE_ES_EVENT_SOURCE_ANY, ACE_ES_EVENT_ANY, 0); RtecEventChannelAdmin::ConsumerQOS sub = cons_qos_fact.get_ConsumerQOS (); sender->connect (sub); // Create and initialize the receiver PortableServer::Servant_var<TAO_ECG_UDP_Receiver> receiver = TAO_ECG_UDP_Receiver::create(); // TAO_ECG_UDP_Receiver::init() takes a TAO_ECG_Refcounted_Endpoint. // If we don't clone our endpoint and pass &endpoint, the receiver will // attempt to delete endpoint during shutdown. TAO_ECG_Refcounted_Endpoint clone2 (new TAO_ECG_UDP_Out_Endpoint (endpoint)); receiver->init (ec.in (), clone2, addr_srv.in ()); // Setup the registration and connect to the event channel ACE_SupplierQOS_Factory supp_qos_fact; supp_qos_fact.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); RtecEventChannelAdmin::SupplierQOS pub = supp_qos_fact.get_SupplierQOS (); receiver->connect (pub); // Create the appropriate event handler and register it with the reactor auto_ptr<ACE_Event_Handler> eh; if (mcast) { auto_ptr<TAO_ECG_Mcast_EH> mcast_eh(new TAO_ECG_Mcast_EH (receiver.in())); mcast_eh->reactor (orb->orb_core ()->reactor ()); mcast_eh->open (ec.in()); ACE_auto_ptr_reset(eh,mcast_eh.release()); //eh.reset(mcast_eh.release()); } else { auto_ptr<TAO_ECG_UDP_EH> udp_eh (new TAO_ECG_UDP_EH (receiver.in())); udp_eh->reactor (orb->orb_core ()->reactor ()); ACE_INET_Addr local_addr (listenport); if (udp_eh->open (local_addr) == -1) ACE_ERROR ((LM_ERROR,"Cannot open EH\n")); ACE_auto_ptr_reset(eh,udp_eh.release()); //eh.reset(udp_eh.release()); } // Create an event (just a string in this case). // Create an event set for one event RtecEventComm::EventSet event (1); event.length (1); // Initialize event header. event[0].header.source = MY_SOURCE_ID; event[0].header.ttl = 1; event[0].header.type = MY_EVENT_TYPE; #if !defined (TAO_LACKS_EVENT_CHANNEL_ANY) // Initialize data fields in event. const CORBA::String_var eventData = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (ecname)); event[0].data.any_value <<= eventData; #else // Use the octet sequence payload instead char *tmpstr = const_cast<char *>(ACE_TEXT_ALWAYS_CHAR (ecname)); size_t len = ACE_OS::strlen(tmpstr) +1; event[0].data.payload.replace ( len, len, reinterpret_cast<CORBA::Octet *> (tmpstr)); #endif /* !TAO_LACKS_EVENT_CHANNEL_ANY */ if (iorfile != 0) { CORBA::String_var str = orb->object_to_string( ec.in() ); std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(iorfile) ); iorFile << str.in() << std::endl; iorFile.close(); } ACE_DEBUG ((LM_DEBUG, "Starting main loop\n")); const int EVENT_DELAY_MS = 1000; while (1) { consumer->push (event); ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); orb->run(tv); } orb->destroy(); return 0; } catch (const CORBA::Exception& exc) { ACE_ERROR ((LM_ERROR, "Caught CORBA::Exception\n%C (%C)\n", exc._name (), exc._rep_id () )); } return 1; }
void test_poas (CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa, PortableServer::POA_ptr first_poa, PortableServer::POA_ptr second_poa, PortableServer::POA_ptr third_poa, PortableServer::POA_ptr forth_poa, int perform_deactivation_test) { { test_i servant (root_poa); CORBA::Object_var obj = root_poa->create_reference ("IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id = root_poa->reference_to_id (obj.in ()); root_poa->activate_object_with_id (id.in (), &servant); obj = root_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = root_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = root_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } obj = root_poa->servant_to_reference (&servant); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = servant._this (); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_servant = root_poa->servant_to_id (&servant); ACE_ASSERT (id_from_servant.in () == id.in ()); root_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { root_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = root_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); root_poa->deactivate_object (id.in ()); } } { test_i servant (root_poa); PortableServer::ObjectId_var id = root_poa->activate_object (&servant); CORBA::Object_var obj = root_poa->id_to_reference (id.in ()); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = root_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); root_poa->deactivate_object (id.in ()); } { test_i servant (first_poa); CORBA::Object_var obj = first_poa->create_reference ("IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id = first_poa->reference_to_id (obj.in ()); first_poa->activate_object_with_id (id.in (), &servant); obj = first_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = first_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = first_poa->id_to_servant (id.in ()); if (servant_from_reference .in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } first_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { first_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = first_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); first_poa->deactivate_object (id.in ()); } } { test_i servant (first_poa); PortableServer::ObjectId_var id = first_poa->activate_object (&servant); CORBA::Object_var obj = first_poa->id_to_reference (id.in ()); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = first_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); first_poa->deactivate_object (id.in ()); } { test_i servant (second_poa); CORBA::Object_var obj = second_poa->create_reference ("IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id = second_poa->reference_to_id (obj.in ()); second_poa->activate_object_with_id (id.in (), &servant); obj = second_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = second_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = second_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } obj = second_poa->servant_to_reference (&servant); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = servant._this (); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_servant = second_poa->servant_to_id (&servant); ACE_ASSERT (id_from_servant.in () == id.in ()); second_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { second_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = second_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); second_poa->deactivate_object (id.in ()); } } { test_i servant (second_poa); PortableServer::ObjectId_var id = second_poa->activate_object (&servant); CORBA::Object_var obj = second_poa->id_to_reference (id.in ()); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = second_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); second_poa->deactivate_object (id.in ()); } { test_i servant (third_poa); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("hello"); CORBA::Object_var obj = third_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_reference = third_poa->reference_to_id (obj.in ()); string = PortableServer::ObjectId_to_string (id_from_reference.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); ACE_ASSERT (id_from_reference.in () == id.in ()); third_poa->activate_object_with_id (id.in (), &servant); obj = third_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = third_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = third_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } obj = third_poa->servant_to_reference (&servant); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = servant._this (); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_servant = third_poa->servant_to_id (&servant); string = PortableServer::ObjectId_to_string (id_from_servant.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); ACE_ASSERT (id_from_servant.in () == id.in ()); third_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { third_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = third_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); third_poa->deactivate_object (id.in ()); } } { test_i servant (forth_poa); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("hello"); CORBA::Object_var obj = forth_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_reference = forth_poa->reference_to_id (obj.in ()); string = PortableServer::ObjectId_to_string (id_from_reference.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); ACE_ASSERT (id_from_reference.in () == id.in ()); forth_poa->activate_object_with_id (id.in (), &servant); obj = forth_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = forth_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = forth_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } forth_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { forth_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = forth_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); forth_poa->deactivate_object (id.in ()); } } }
int TestTask::svc() { try { // Start the Naming Service tasks namingServiceA_.activate(); // Wait for the Naming Service initialized. namingServiceA_.waitInit(); namingServiceB_.activate(); // Wait for the Naming Service initialized. namingServiceB_.waitInit(); 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: ns.ior\n"), 1); ACE_OS::fprintf (output_file, "%s", namingServiceA_.ior ()); ACE_OS::fclose (output_file); // 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 (namingServiceB_.ior ()); 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 (namingServiceA_.ior ()); 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")); if (shutdown_ns_) { namingServiceB_.end(); ACE_DEBUG ((LM_INFO, "Naming Service B shut down\n")); } // Create shutdown server NsShutdown shutdown_servant(orb_.in ()); PortableServer::ObjectId_var shutdown_oid = poa->activate_object(&shutdown_servant); obj = poa->id_to_reference(shutdown_oid.in()); CORBA::String_var ior = orb_->object_to_string (obj.in ()); output_file= ACE_OS::fopen (ior_shutdown_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file %s for writing IOR: %C\n", ior_shutdown_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); // Normally we run the orb and the orb is shutdown by // calling TestTask::end(). // Accept requests orb_->run(); orb_->destroy(); // Shutdown the Naming Services. namingServiceA_.end(); if (!shutdown_ns_) { namingServiceB_.end(); } return 0; } catch (CORBA::Exception& ex) { ex._tao_print_exception ("CORBA exception: "); } return -1; }
int Task::svc (void) { try { CORBA::Object_var object = this->orb_->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); object = this->orb_->resolve_initial_references ("RTORB"); RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (object.in ()); object = this->orb_->resolve_initial_references ("RTCurrent"); RTCORBA::Current_var current = RTCORBA::Current::_narrow (object.in ()); RTCORBA::Priority default_thread_priority = get_implicit_thread_CORBA_priority (this->orb_.in ()); test_i servant (this->orb_.in (), root_poa.in (), nap_time); PortableServer::ObjectId_var id = root_poa->activate_object (&servant); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); test_var test = test::_narrow (object_act.in ()); int result = write_ior_to_file (this->orb_.in (), test.in ()); if (result != 0) return result; poa_manager->activate (); CORBA::ULong stacksize = 0; CORBA::Boolean allow_request_buffering = false; CORBA::ULong max_buffered_requests = 0; CORBA::ULong max_request_buffer_size = 0; RTCORBA::ThreadpoolId threadpool_id_1 = rt_orb->create_threadpool (stacksize, static_threads, dynamic_threads, default_thread_priority, allow_request_buffering, max_buffered_requests, max_request_buffer_size); CORBA::Policy_var threadpool_policy_1 = rt_orb->create_threadpool_policy (threadpool_id_1); CORBA::Boolean allow_borrowing = false; RTCORBA::ThreadpoolLanes lanes (1); lanes.length (1); lanes[0].lane_priority = default_thread_priority; lanes[0].static_threads = static_threads; lanes[0].dynamic_threads = dynamic_threads; RTCORBA::ThreadpoolId threadpool_id_2 = rt_orb->create_threadpool_with_lanes (stacksize, lanes, allow_borrowing, allow_request_buffering, max_buffered_requests, max_request_buffer_size); CORBA::Policy_var threadpool_policy_2 = rt_orb->create_threadpool_policy (threadpool_id_2); result = create_POA_and_register_servant (threadpool_policy_1.in (), "first_poa", poa_manager.in (), root_poa.in (), this->orb_.in (), rt_orb.in ()); if (result != 0) return result; result = create_POA_and_register_servant (threadpool_policy_2.in (), "second_poa", poa_manager.in (), root_poa.in (), this->orb_.in (), rt_orb.in ()); if (result != 0) return result; this->orb_->run (); this->orb_->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return -1; } return 0; }
void tilecache_build(QApplication* app){ swMiscProperties_t serverprops; if( !swTileServer::instance()->init("/srv/etc/tileserver.xml")){ return ; } if( swTileServer::instance()->getProps().realRender){ serverprops["confile"] = "/srv/etc/mapserv.xml"; if( !swMapServer::instance()->init(serverprops)){ return ; } } QStringList cmdparams = app->arguments(); boost::shared_ptr<swTileServer> servant(new swTileServer()); if( cmdparams.size() >=2 && cmdparams[1]=="test" ){ // params: test scale lon lat vwidth vheight // tileserver test 5000 121.1345 31.01 256 256 //5000 121.4345 31.115 512 512 // test 6000 121.2248 31.022 swmap::MapBitmapTile2T tile; float res = 1/6000.; swmap::GeoPointT cxy; cxy.x = 121.2248; cxy.y = 31.022; swmap::MapTileSizeT size; size.width=256*2; size.height = 256*2; if(cmdparams.size()>=3){ res = cmdparams[2].toFloat(); res = 1/res; } if(cmdparams.size()>=4){ cxy.x = cmdparams[3].toFloat(); } if(cmdparams.size()>=5){ cxy.y = cmdparams[4].toFloat(); } if(cmdparams.size()>=6){ size.width = cmdparams[5].toInt(); } if(cmdparams.size()>=7){ size.height = cmdparams[6].toInt(); } bool render = true; tce::RpcContext ctx; qDebug("scale:%f,loc:%f,%f,size:%d,%d\n",1/res,cxy.x,cxy.y,size.width,size.height); tile = servant->getBitmapTile(swmap::MapIdentT(),res,cxy,size,render,ctx); return; } //rpc 服务启动 tileserver_1 socket1 if( cmdparams.size() ){ swRpcServiceInfo_t rpc; rpc.svcname = cmdparams[1]; rpc.svcfile = "/srv/etc/services.xml"; rpc.epname = cmdparams[2]; //swTileServer::instance()->RpcService(rpc); bool r; tce::Properties_t props; props["svcfile"] = rpc.svcfile.toStdString(); props["svcname"] = rpc.svcname.toStdString(); r = tce::RpcCommunicator::instance().init(props); if(!r){ return ; } tce::RpcCommunicator::instance().getProps().msgDispOnConn = true; tce::RpcCommAdapterPtr adapter = tce::RpcCommunicator::instance().createAdatper(rpc.epname.toStdString()); if(!adapter.get()){ return ; } adapter->addServant("tileserver",servant); printf("tileserver started!"); tce::RpcCommunicator::instance().exec(); //TileServerHelper::instance()->start(); // swMapBitmapTileT t; // TileServerHelper::instance()->render(servant.get(),0,0.234,swGeoPoint(0.123,3.44),swViewSize(2,2),t); // app->exec(); return; } printf( "Help:\n" "tileserver.exe -rpcservice nic:port\n" " -create Task-cache.xml\n"); }
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 { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); const ACE_TCHAR *ecname = ACE_TEXT ("EventService"); for (int i = 0; argv[i] != 0; i++) { if (ACE_OS::strcmp (argv[i], ACE_TEXT ("-ecname")) == 0) { if (argv[i+1] != 0) { ecname = argv[i+1]; } else { ACE_ERROR ((LM_ERROR, "Missing Event channel name\n")); } } } // Find the Naming Service. CORBA::Object_var obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); // Find the EchoEventChannel. obj = root_context->resolve_str (ACE_TEXT_ALWAYS_CHAR (ecname)); // Downcast the object reference to an EventChannel reference. RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); if (CORBA::is_nil(ec.in())) { ACE_ERROR_RETURN ((LM_ERROR, "Could not narrow EchoEventChannel.\n"), 1); } ACE_DEBUG ((LM_DEBUG, "EchoEventConsumerMain.cpp: Found the EchoEventChannel.\n")); // Obtain a reference to the consumer administration object. RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers(); // Obtain a reference to the push supplier proxy. RtecEventChannelAdmin::ProxyPushSupplier_var supplier = admin->obtain_push_supplier(); // Get the RootPOA. obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); // Instantiate an EchoEventConsumer_i servant. EchoEventConsumer_i servant(orb.in(), EVENT_LIMIT); // Register it with the RootPOA. PortableServer::ObjectId_var oid = poa->activate_object(&servant); CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); RtecEventComm::PushConsumer_var consumer = RtecEventComm::PushConsumer::_narrow(consumer_obj.in()); // Connect as a consumer. ACE_ConsumerQOS_Factory qos; qos.start_disjunction_group (); qos.insert (MY_SOURCE_ID, // Source ID MY_EVENT_TYPE, // Event Type 0); // handle to the rt_info supplier->connect_push_consumer (consumer.in (), qos.get_ConsumerQOS ()); // Activate the POA via its POAManager. PortableServer::POAManager_var poa_manager = poa->the_POAManager(); poa_manager->activate(); ACE_DEBUG ((LM_DEBUG, "EchoEventConsumerMain.cpp: Ready to receive events...\n")); // Enter the ORB event loop. orb->run(); // If we have reached this, we must be shutting down... // Disconnect the ProxyPushSupplier. //supplier->disconnect_push_supplier(); //supplier = RtecEventChannelAdmin::ProxyPushSupplier::_nil(); //admin = RtecEventChannelAdmin::ConsumerAdmin::_nil(); orb->destroy(); return 0; } catch (const CORBA::Exception& exc) { ACE_ERROR ((LM_ERROR, "Caught CORBA::Exception\n%C (%C)\n", exc._name (), exc._rep_id () )); } return 1; }