void TAO_ECG_UDP_Sender::new_connect (const RtecEventChannelAdmin::ConsumerQOS& sub) { // Activate with poa. RtecEventComm::PushConsumer_var consumer_ref; PortableServer::POA_var poa = this->_default_POA (); TAO_EC_Object_Deactivator deactivator; activate (consumer_ref, poa.in (), this, deactivator); // Connect as a consumer to the local EC. RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin = this->lcl_ec_->for_consumers (); RtecEventChannelAdmin::ProxyPushSupplier_var proxy = consumer_admin->obtain_push_supplier (); ECG_Sender_Auto_Proxy_Disconnect new_proxy_disconnect (proxy.in ()); proxy->connect_push_consumer (consumer_ref.in (), sub); // Update resource managers. this->supplier_proxy_ = proxy._retn (); this->auto_proxy_disconnect_.set_command (new_proxy_disconnect); this->set_deactivator (deactivator); }
int TAO_IFR_Server::init_with_orb (int argc, ACE_TCHAR *argv [], CORBA::ORB_ptr orb, int use_multicast_server) { try { // Get the POA from the ORB. CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); if (CORBA::is_nil (poa_object.in ())) { ORBSVCS_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t) IFR_Service::init_with_orb ") ACE_TEXT ("Unable to initialize the POA.\n")), -1); } PortableServer::POA_var rp = PortableServer::POA::_narrow (poa_object.in ()); return this->init_with_poa (argc, argv, orb, rp.in(), use_multicast_server); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("IFR_Service::init_with_orb"); throw; } return 0; }
void TAO_Notify_Tests_Peer_T<Peer_Traits>::connect (void) { // Get the POA PortableServer::POA_var poa; LOOKUP_MANAGER->resolve (poa, this->poa_name_.c_str ()); // set the POA this->set_poa (poa.in ()); // Resolve the admin typename Admin_Traits::VAR admin_var; LOOKUP_MANAGER->resolve (admin_var, this->admin_name_.c_str ()); typename Admin_Ext_Traits::VAR admin_ext_var = Admin_Ext_Traits_INTERFACE::_narrow (admin_var.in ()); typename Proxy_Traits::VAR proxy_var = this->obtain_proxy (admin_ext_var.in (), this->qos_); ACE_ASSERT (!CORBA::is_nil (proxy_var.in ())); // connect supplier to proxy, // also activates the servant as CORBA object in the POA specified. this->connect (proxy_var.in (), this->proxy_id_); }
void Heartbeat_Application::connect_as_consumer (void) { // Activate with poa. RtecEventComm::PushConsumer_var consumer_ref; PortableServer::POA_var poa = this->_default_POA (); TAO_EC_Object_Deactivator deactivator; activate (consumer_ref, poa.in (), this, deactivator); // Obtain reference to ConsumerAdmin. RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin = this->ec_->for_consumers (); // Obtain ProxyPushSupplier.. RtecEventChannelAdmin::ProxyPushSupplier_var proxy = consumer_admin->obtain_push_supplier (); Supplier_Proxy_Disconnect new_proxy_disconnect (proxy.in ()); // Connect this consumer. ACE_ConsumerQOS_Factory qos; qos.start_disjunction_group (1); qos.insert_type (ACE_ES_EVENT_ANY, 0); proxy->connect_push_consumer (consumer_ref.in (), qos.get_ConsumerQOS ()); // Update resource managers. this->supplier_proxy_disconnect_.set_command (new_proxy_disconnect); this->set_deactivator (deactivator); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); try { CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ()); TAO_AV_CORE::instance ()->init (orb.in (), poa.in ()); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("server::init"); return -1; } int result = 0; result = FTP_SERVER::instance ()->init (argc, argv); if (result < 0) ACE_ERROR_RETURN ((LM_ERROR,"FTP_SERVER::init failed\n"),1); result = FTP_SERVER::instance ()->run (); if (result < 0) ACE_ERROR_RETURN ((LM_ERROR,"FTP_SERVER::run failed\n"),1); FTP_SERVER::close (); // Explicitly finalize the Unmanaged_Singleton. return result; }
TAO_Stub * TAO_DynamicImplementation::_create_stub (void) { // If DynamicImplementation::_this() is invoked outside of the // context of a request invocation on a target object being served // by the DSI servant, it raises the PortableServer::WrongPolicy // exception. See the CORBA C++ mapping, section 1.38.3. TAO::Portable_Server::POA_Current_Impl *poa_current_impl = static_cast <TAO::Portable_Server::POA_Current_Impl *> (TAO_TSS_Resources::instance ()->poa_current_impl_); if (poa_current_impl == 0 || this != poa_current_impl->servant ()) { throw PortableServer::POA::WrongPolicy (); } PortableServer::POA_var poa = poa_current_impl->get_POA (); CORBA::PolicyList_var client_exposed_policies = poa_current_impl->poa ()->client_exposed_policies ( poa_current_impl->priority ()); CORBA::RepositoryId_var pinterface = this->_primary_interface (poa_current_impl->object_id (), poa.in ()); return poa_current_impl->poa ()->key_to_stub (poa_current_impl->object_key (), pinterface.in (), poa_current_impl->priority ()); }
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->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); PortableServer::POAManager_var mgr = root_poa->the_POAManager(); const char* poa_name = "MessengerService"; PortableServer::POA_var poa = createPersistentPOA(root_poa.in(), poa_name); PortableServer::Servant_var<Messenger_i> servant1 = new Messenger_i; PortableServer::Servant_var<Messenger_i> servant2 = new Messenger_i; PortableServer::ObjectId_var id1 = PortableServer::string_to_ObjectId("Object1"); poa->activate_object_with_id(id1.in(), servant1.in()); PortableServer::ObjectId_var id2 = PortableServer::string_to_ObjectId("Object2"); poa->activate_object_with_id(id2.in(), servant2.in()); obj = poa->id_to_reference(id1.in()); CORBA::String_var ior1 = orb->object_to_string(obj.in()); obj = poa->id_to_reference(id2.in()); CORBA::String_var ior2 = orb->object_to_string(obj.in()); TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(poa.in()); obj = tpoa->id_to_reference_i(id1.in(), false); CORBA::String_var direct_ior1 = orb->object_to_string(obj.in()); obj = orb->resolve_initial_references("IORTable"); IORTable::Table_var ior_table = IORTable::Table::_narrow(obj.in()); ior_table->bind("MessengerService/Object1", direct_ior1.in()); ior_table->bind("MessengerService/Object2", ior2.in()); writeIORFile(ior1.in(), ior_output_file1); writeIORFile(ior2.in(), ior_output_file2); mgr->activate(); std::cout << "Messenger server ready." << std::endl; orb->run(); std::cout << "Messenger server shutting down." << std::endl; root_poa->destroy(1,1); orb->destroy(); return 0; } catch(const CORBA::Exception& ex) { std::cerr << "Server main() Caught Exception" << ex << std::endl; } return 1; }
int create_POA_and_register_servant (CORBA::Policy_ptr threadpool_policy, const char *poa_name, PortableServer::POAManager_ptr poa_manager, PortableServer::POA_ptr root_poa, CORBA::ORB_ptr orb, RTCORBA::RTORB_ptr rt_orb) { // Policies for the firstPOA to be created. CORBA::PolicyList policies (3); policies.length (3); // Implicit_activation policy. policies[0] = root_poa->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION); // Thread pool policy. policies[1] = CORBA::Policy::_duplicate (threadpool_policy); // Priority Model policy. policies[2] = rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED, 0); // Create the POA under the RootPOA. PortableServer::POA_var poa = root_poa->create_POA (poa_name, poa_manager, policies); // Creation of POAs is over. Destroy the Policy objects. for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } test_i *servant = new test_i (orb, poa.in (), nap_time); PortableServer::ServantBase_var safe_servant (servant); ACE_UNUSED_ARG (safe_servant); PortableServer::ObjectId_var id = poa->activate_object (servant); CORBA::Object_var object = poa->id_to_reference (id.in ()); test_var test = test::_narrow (object.in ()); int const result = write_ior_to_file (orb, test.in ()); return result; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { // We may want this to be alive beyond the next block. PortableServer::Servant_var<Heartbeat_Application> app; 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; // Init our application. app = new Heartbeat_Application; if (!app.in ()) return 1; app->init (orb, ec); // Allow processing of CORBA requests. manager->activate (); // Receive events from EC. orb->run (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception in Heartbeat Application:"); // Since there was an exception, application might not have had // a chance to shutdown. app->shutdown (); return 1; } return 0; }
void ImR_Locator_i::destroy_poa (const ACE_CString &poa_name) { PortableServer::POA_var poa = findPOA (poa_name.c_str()); if (! CORBA::is_nil (poa.in ())) { bool etherealize = true; bool wait = false; poa->destroy (etherealize, wait); } }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { TAO_EC_Default_Factory::init_svcs (); try { // ORB initialization boiler plate... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // **************************************************************** run_test (poa.in (), 0); run_test (poa.in (), 1); // **************************************************************** poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Service"); return 1; } return 0; }
bool ImR_Activator_i::in_upcall (void) { try { PortableServer::POA_var poa = current_->get_POA (); return !CORBA::is_nil (poa.in ()); } catch (const CORBA::Exception& ) { // no-op } return false; }
/// Activate in the POA void TAO_FTEC_ProxyPushSupplier::activate ( RtecEventChannelAdmin::ProxyPushSupplier_ptr &result) { result = RtecEventChannelAdmin::ProxyPushSupplier::_nil(); try{ object_id_ = Request_Context_Repository().get_object_id(); PortableServer::POA_var poa = _default_POA(); activate_object_with_id(result, poa.in(), this, id()); } catch (const CORBA::Exception&) { // ignore exceptions } }
void TAO_Notify_Tests_Direct_Consumer::connect (void) { // Get the POA PortableServer::POA_var poa; LOOKUP_MANAGER->resolve (poa, this->poa_name_.c_str ()); // set the POA this->set_poa (poa.in ()); // Activate the consumer with the default_POA_. CosNotifyComm::StructuredPushConsumer_var consumer_ref = this->_this (); // Register the activated object. LOOKUP_MANAGER->_register (consumer_ref.in (), this->name_.c_str ()); }
void TAO_ECG_Mcast_EH::open (RtecEventChannelAdmin::EventChannel_ptr ec) { if (!this->receiver_) { // We are shut down. throw CORBA::INTERNAL(); } if (CORBA::is_nil (ec)) { ORBSVCS_ERROR ((LM_ERROR, "TAO_ECG_Mcast_EH::open(): " "nil ec argument")); throw CORBA::INTERNAL (); } // Create and activate Event Channel Observer. ACE_NEW (this->observer_, Observer (this)); if (!this->observer_.in ()) { throw CORBA::NO_MEMORY (); } TAO_EC_Object_Deactivator observer_deactivator; RtecEventChannelAdmin::Observer_var observer_ref; PortableServer::POA_var poa = this->observer_->_default_POA (); activate (observer_ref, poa.in (), this->observer_.in (), observer_deactivator); RtecEventChannelAdmin::Observer_Handle handle = ec->append_observer (observer_ref.in ()); this->observer_->set_deactivator (observer_deactivator); this->auto_observer_disconnect_.set_command (Observer_Disconnect_Command (handle, ec)); }
void TAO_Notify_Tests_Direct_Supplier::connect (void) { // Get the POA PortableServer::POA_var poa; LOOKUP_MANAGER->resolve (poa, this->poa_name_.c_str ()); // set the POA this->set_poa (poa.in ()); // Get hold of the reference. CosNotifyComm::StructuredPushSupplier_var supplier_ref = this->_this (); // Register the activated object. LOOKUP_MANAGER->_register (supplier_ref.in (), this->name_.c_str ()); // Resolve the target object. LOOKUP_MANAGER->resolve (this->target_object_, this->target_.c_str ()); }
CORBA::RepositoryId TAO_DynamicImplementation::get_id_from_primary_interface (void) { // If this method is called outside of the // context of a request invocation on a target object being served // by the DSI servant, it raises the PortableServer::WrongPolicy // exception. See the CORBA C++ mapping, section 1.38.3. TAO::Portable_Server::POA_Current_Impl *poa_current_impl = static_cast <TAO::Portable_Server::POA_Current_Impl *> (TAO_TSS_Resources::instance ()->poa_current_impl_); if (poa_current_impl == 0 || this != poa_current_impl->servant ()) { throw PortableServer::POA::WrongPolicy (); } PortableServer::POA_var poa = poa_current_impl->get_POA (); return this->_primary_interface (poa_current_impl->object_id (), poa.in ()); }
void TAO_Notify_Tests_EventChannel_Command::create_collocated_ecf (void) { CosNotifyChannelAdmin::EventChannelFactory_var notify_factory; // The Service Object. TAO_Notify_Service* notify_service = TAO_Notify_Service::load_default (); if (notify_service == 0) { ACE_DEBUG ((LM_DEBUG, "Service not found! check conf. file\n")); return; } // Resolve some helpers. CORBA::ORB_var orb; PortableServer::POA_var poa; CosNaming::NamingContextExt_var naming; LOOKUP_MANAGER->resolve (orb); LOOKUP_MANAGER->resolve (poa); LOOKUP_MANAGER->resolve (naming); notify_service->init_service (orb.in ()); // Activate the factory notify_factory = notify_service->create (poa.in ()); // Register with the Naming Service CosNaming::Name_var name = naming->to_name (TAO_Notify_Tests_Name::event_channel_factory); naming->rebind (name.in (), notify_factory.in ()); }
int NamingTask::svc() { try { // Get reference to Root POA CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); // Activate POA Manager PortableServer::POAManager_var poaManager = poa->the_POAManager(); poaManager->activate(); // Initialize the naming service // We are not going to look for other naming servers TAO_Naming_Server naming; if (naming.init(orb_.in(), poa.in(), ACE_DEFAULT_MAP_SIZE, 0, 0) == 0) { std::cout << "The Naming Service Task is ready." << std::endl; initialized_ = true; // Accept requests orb_->run(); orb_->destroy(); return 0; } else { std::cerr << "Unable to initialize the Naming Service." << std::endl; } } catch(const CORBA::Exception& ex) { std::cerr << "NamingTask::svc() CORBA::Exception: " << ex << std::endl; } return -1; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { TAO_EC_Default_Factory::init_svcs (); try { // ORB initialization boiler plate... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // **************************************************************** TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); attributes.consumer_reconnect = 1; attributes.supplier_reconnect = 1; TAO_EC_Event_Channel ec_impl (attributes); ec_impl.activate (); RtecEventChannelAdmin::EventChannel_var event_channel = ec_impl._this (); // **************************************************************** // Obtain the consumer admin.. RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin = event_channel->for_consumers (); // Obtain the supplier admin.. RtecEventChannelAdmin::SupplierAdmin_var supplier_admin = event_channel->for_suppliers (); // **************************************************************** const int milliseconds = 50; EC_Counting_Supplier first_supplier; first_supplier.activate (consumer_admin.in (), milliseconds); first_supplier.connect (supplier_admin.in (), 0x00001111UL, 0x11110000UL, 0x00001111UL, 0x11110000UL); EC_Counting_Supplier second_supplier; second_supplier.activate (consumer_admin.in (), milliseconds); second_supplier.connect (supplier_admin.in (), 0x01100000UL, 0x00000110UL, 0x01100000UL, 0x00000110UL); // **************************************************************** EC_Counting_Consumer consumer_bitmask_reject ("Consumer/bitmask/reject"); // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... { ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_bitmask (0x00001111, 0x11110000); consumer_qos.start_disjunction_group (1); consumer_qos.insert (0x01100000, 0x00000110, 0); consumer_bitmask_reject.connect (consumer_admin.in (), consumer_qos.get_ConsumerQOS ()); } // **************************************************************** EC_Counting_Consumer consumer_bitmask_accept ("Consumer/bitmask/accept"); // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... { ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_bitmask (0x01100110, 0x01100110); consumer_qos.insert_null_terminator (); consumer_bitmask_accept.connect (consumer_admin.in (), consumer_qos.get_ConsumerQOS ()); } // **************************************************************** EC_Counting_Consumer consumer_bitmask_filter ("Consumer/bitmask/filter"); // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... { ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_bitmask (0x00000110, 0x01100000); consumer_qos.insert_null_terminator (); consumer_bitmask_filter.connect (consumer_admin.in (), consumer_qos.get_ConsumerQOS ()); } // **************************************************************** EC_Counting_Consumer consumer_bitmask_value ("Consumer/bitmask/value"); // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... { ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_disjunction_group (1); consumer_qos.insert_bitmasked_value (0x11110000, 0x00001111, 0x01100000, 0x00000110); consumer_bitmask_value.connect (consumer_admin.in (), consumer_qos.get_ConsumerQOS ()); } // **************************************************************** EC_Counting_Consumer consumer_bitmask_loose ("Consumer/bitmask/loose"); // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... { ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_disjunction_group (1); consumer_qos.insert_bitmasked_value (0x11111111, 0x11111111, 0x01100000, 0x00000110); consumer_bitmask_loose.connect (consumer_admin.in (), consumer_qos.get_ConsumerQOS ()); } // **************************************************************** ACE_Time_Value tv (5, 0); // Wait for events, using work_pending()/perform_work() may help // or using another thread, this example is too simple for that. orb->run (tv); // **************************************************************** consumer_bitmask_loose.disconnect (); consumer_bitmask_value.disconnect (); consumer_bitmask_filter.disconnect (); consumer_bitmask_accept.disconnect (); consumer_bitmask_reject.disconnect (); // **************************************************************** second_supplier.deactivate (); second_supplier.disconnect (); first_supplier.deactivate (); first_supplier.disconnect (); // **************************************************************** event_channel->destroy (); // **************************************************************** poa->destroy (1, 1); // **************************************************************** consumer_bitmask_reject.dump_results (0, 5); CORBA::ULong expected = first_supplier.event_count + second_supplier.event_count; consumer_bitmask_accept.dump_results (expected, 5); expected = second_supplier.event_count; consumer_bitmask_filter.dump_results (expected, 5); expected = second_supplier.event_count; consumer_bitmask_value.dump_results (expected, 5); expected = second_supplier.event_count; consumer_bitmask_loose.dump_results (expected, 5); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Service"); return 1; } return 0; }
// The code that actually processes the request message void Lorica::ProxyServant::invoke_i(CORBA::ServerRequest_ptr request, TAO_AMH_DSI_Response_Handler_ptr response_handler) { Lorica::ServerAgent_var agent; CORBA::Object_var target_obj = mapper_.current_native(agent.out()); EvaluatorBase *evb = this->mapper_.evaluator_for (target_obj.in()); if (!evb) throw CORBA::NO_IMPLEMENT(); bool is_oneway = !request->_tao_server_request().response_expected() || request->_tao_server_request().sync_with_server(); CORBA::NVList_var args; CORBA::NVList_var out_args; this->orb_->create_list(0, args); this->orb_->create_list(0, out_args); PortableServer::POA_var poa = this->current_->get_POA(); PortableServer::ObjectId_var oid = this->current_->get_object_id(); CORBA::NamedValue_var result; try { if (!evb->evaluate_request(request->operation(), poa.in(), request, args.inout(), out_args.inout(), result.out())) { if (!CORBA::is_nil(agent)) { agent->error_occured(errno, "ProxyServant::invoke_i, evaluate_request " "failed, Caught CORBA::BAD_OPERATION()\n"); } if (Lorica_debug_level > 0) { ACE_ERROR((LM_ERROR, "(%T) %N:%l - evaluate_request failed. Caught CORBA::BAD_OPERATION()\n")); } throw CORBA::BAD_OPERATION(); } } catch (CORBA::UserException & ex) { if (Lorica_debug_level > 0) ACE_DEBUG((LM_ERROR, ACE_TEXT("(%T) %N:%l - %s\n"), ex._info().c_str())); if (!CORBA::is_nil(agent)) { agent->error_occured(errno, "ProxyServant::invoke_i, evaluate_request " "failed, A CORBA::BAD_OPERATION() is thrown"); } if (Lorica_debug_level > 0) { ACE_ERROR((LM_ERROR, "(%T) %N:%l - evaluate_request raised %s\n", ex._name())); } throw CORBA::BAD_OPERATION(); } // do the rest, ie set up reply handler CORBA::Request_var target_request; target_obj->_create_request(0, // context request->operation(), args._retn(), // hand off ownership 0, // result, 0, // exception list 0, // context_list target_request.inout(), 0); if (is_oneway) { target_request->send_oneway(); return; } Messaging::ReplyHandler_var rh = new Lorica::ProxyReplyHandler(this->mapper_, request->operation(), poa.in(), evb, out_args._retn(), result._retn(), response_handler); target_request->sendc(rh.in()); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { CORBA::ORB_var orb; try { orb = CORBA::ORB_init (argc, argv); CORBA::Object_var root_poa_o = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (root_poa_o.in ()); if (CORBA::is_nil (rootPOA.in ())) { ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); } PortableServer::POAManager_var poaMgr = rootPOA->the_POAManager (); poaMgr->activate (); CORBA::PolicyList policies; policies.length (3); policies[0] = rootPOA->create_id_assignment_policy ( PortableServer::SYSTEM_ID); policies[1] = rootPOA->create_implicit_activation_policy ( PortableServer::NO_IMPLICIT_ACTIVATION); policies[2] = rootPOA->create_lifespan_policy ( PortableServer::TRANSIENT); PortableServer::POA_var fooPoa = rootPOA->create_POA ( "FOO_POA", poaMgr.in (), policies ); for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } Foo_i servant; PortableServer::ObjectId_var oid = fooPoa->activate_object( &servant ); CORBA::Object_var obj = fooPoa->id_to_reference (oid.in ()); foo_var client = foo::_narrow (obj.in()); client->check(); if (vc_check(client.in())) { orb->destroy(); return 1; } fooPoa->deactivate_object (oid.in () ); //servant is gone if (vc_check(client.in(), false)) //exception expected { orb->destroy(); return 2; } } catch(...) { return 3; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the EC Factory so we can customize the EC TAO_EC_Default_Factory::init_svcs (); // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); const ACE_TCHAR* ecname = ACE_TEXT ("EventService"); const ACE_TCHAR* remote_ecname = 0; const ACE_TCHAR* iorfile = 0; for (int i = 0; argv[i] != 0; i++) { if (ACE_OS::strcmp(argv[i], ACE_TEXT("-ecname")) == 0) { if (argv[i+1] != 0) { i++; ecname = argv[i]; } else { std::cerr << "Missing Event channel name" << std::endl; } } if (ACE_OS::strcmp(argv[i], ACE_TEXT("-gateway")) == 0) { if (argv[i+1] != 0) { i++; remote_ecname = argv[i]; } else { std::cerr << "Missing Event channel name" << std::endl; } } if (ACE_OS::strcmp(argv[i], ACE_TEXT("-iorfile")) == 0) { if (argv[i+1] != 0) { i++; iorfile = argv[i]; } } } // Get the POA CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Spawn a thread for the orb ACE_Thread_Manager *thread_mgr = ACE_Thread_Manager::instance(); thread_mgr->spawn(orb_thread, orb.in()); // Create a local event channel and register it with the RootPOA. TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); PortableServer::Servant_var<TAO_EC_Event_Channel> ec_impl = new TAO_EC_Event_Channel(attributes); ec_impl->activate (); PortableServer::ObjectId_var oid = poa->activate_object(ec_impl.in()); CORBA::Object_var ec_obj = poa->id_to_reference(oid.in()); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(ec_obj.in()); // Find the Naming Service. object = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(object.in()); CosNaming::Name_var name = root_context->to_name (ACE_TEXT_ALWAYS_CHAR (ecname)); root_context->rebind(name.in(), ec.in()); // Get a SupplierAdmin object from the EventChannel. RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); // Get a ProxyPushConsumer from the SupplierAdmin. RtecEventChannelAdmin::ProxyPushConsumer_var consumer = admin->obtain_push_consumer(); // Instantiate an EchoEventSupplier_i servant. PortableServer::Servant_var<EchoEventSupplier_i> servant = new EchoEventSupplier_i(orb.in()); // Register it with the RootPOA. oid = poa->activate_object(servant.in()); CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(supplier_obj.in()); // Publish the events the supplier provides. ACE_SupplierQOS_Factory qos; qos.insert (MY_SOURCE_ID, // Supplier's unique id MY_EVENT_TYPE, // Event type 0, // handle to the rt_info structure 1); // number of calls // Connect as a supplier of the published events. consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); // Create an event (just a string in this case). const CORBA::String_var eventData = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (ecname)); // Create an event set for one event RtecEventComm::EventSet event (1); event.length (1); // Initialize event header. event[0].header.source = MY_SOURCE_ID; event[0].header.ttl = 1; event[0].header.type = MY_EVENT_TYPE; // Initialize data fields in event. event[0].data.any_value <<= eventData; PortableServer::Servant_var<TAO_EC_Gateway_IIOP> gateway = new TAO_EC_Gateway_IIOP; int gateway_initialized = 0; std::cout << "Supplier starting sending of events.\n"; while (1) { consumer->push (event); ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); orb->run(tv); if ((remote_ecname != 0) && (!gateway_initialized)) { try { // Get the remote event channel object CORBA::Object_var obj = root_context->resolve_str (ACE_TEXT_ALWAYS_CHAR (remote_ecname)); RtecEventChannelAdmin::EventChannel_var remote_ec = RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); int ok = 0; if (!CORBA::is_nil(remote_ec.in())) { // Now check if we can talk to it... try { RtecEventChannelAdmin::SupplierAdmin_var adm = remote_ec->for_suppliers(); ok = 1; } catch(const CORBA::UserException&) { // What is the correct exception(s) to catch here? } } // There is a good remote event channel so initialize the // gateway. if (ok) { gateway->init(remote_ec.in(), ec.in()); PortableServer::ObjectId_var gateway_oid = poa->activate_object(gateway.in()); CORBA::Object_var gateway_obj = poa->id_to_reference(gateway_oid.in()); RtecEventChannelAdmin::Observer_var obs = RtecEventChannelAdmin::Observer::_narrow(gateway_obj.in()); RtecEventChannelAdmin::Observer_Handle local_ec_obs_handle = ec->append_observer (obs.in ()); ACE_UNUSED_ARG (local_ec_obs_handle); gateway_initialized = 1; std::cout << "Gateway initialized\n"; if (iorfile != 0) { CORBA::String_var str = orb->object_to_string( ec.in() ); std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(iorfile) ); iorFile << str.in() << std::endl; iorFile.close(); } } } catch(const CosNaming::NamingContext::NotFound&) { // Try again later... } } } orb->destroy(); return 0; } catch(const CORBA::Exception& exc) { std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; } return 1; }
int ACE_TMAIN (int argc, ACE_TCHAR* argv[]) { #if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1) try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); TAO_Notify_Service* notify_service = TAO_Notify_Service::load_default (); if (notify_service == 0) { error ("Unable to load the Notify Service"); } notify_service->init_service (orb.in ()); ACE_OS::sleep (1); const ACE_CString ecf_name ("MonitoringEventChannelFactory"); CosNotifyChannelAdmin::EventChannelFactory_var ecf = notify_service->create (poa.in (), ecf_name.c_str ()); NotifyMonitoringExt::EventChannelFactory_var monitor_ec_factory = NotifyMonitoringExt::EventChannelFactory::_narrow (ecf.in ()); if (CORBA::is_nil (monitor_ec_factory.in ())) { error ("Unable to create the Monitoring Event Channel Factory"); } CosNotification::QoSProperties qos_prop; CosNotification::AdminProperties admin_prop; CosNotifyChannelAdmin::ChannelID id; const ACE_CString ec_name ("test1"); CosNotifyChannelAdmin::EventChannel_var ec = monitor_ec_factory->create_named_channel (qos_prop, admin_prop, id, ec_name.c_str ()); NotifyMonitoringExt::EventChannel_var mec = NotifyMonitoringExt::EventChannel::_narrow (ec.in ()); if (CORBA::is_nil (mec.in ())) { error ("Unable to narrow the event channel"); } try { CosNotifyChannelAdmin::ChannelID fake_id; CosNotifyChannelAdmin::EventChannel_var fake = monitor_ec_factory->create_named_channel (qos_prop, admin_prop, fake_id, "test1"); error ("Expected a NotifyMonitoringExt::" "NameAlreadyUsed exception"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { // This is expected. } Monitor_Point_Registry* instance = Monitor_Point_Registry::instance (); ACE_CString stat_name = ecf_name + "/" + ACE_CString (NotifyMonitoringExt::InactiveEventChannelCount); Monitor_Base* stat = instance->get (stat_name); if (stat == 0) { error ("Could not find InactiveEventChannelCount statistic"); } stat->update (); double count = stat->last_sample (); if (!ACE::is_equal (count, 1.0)) { error ("Invalid inactive event channel count"); } stat_name = ecf_name + "/" + ACE_CString (NotifyMonitoringExt::ActiveEventChannelCount); stat = instance->get (stat_name); if (stat == 0) { error ("Could not find ActiveEventChannelCount statistic"); } stat->update (); count = stat->last_sample (); if (!ACE::is_equal (count, 0.0)) { error ("Invalid active event channel count"); } stat_name = ecf_name + "/" + ACE_CString (NotifyMonitoringExt::InactiveEventChannelNames); stat = instance->get (stat_name); if (stat == 0) { error ("Could not find InactiveEventChannels statistic"); } stat->update (); Monitor_Control_Types::NameList list = stat->get_list (); if (list.size () != 1) { error ("Invalid inactive event channel list"); } ACE_CString full_ec_name (ecf_name + "/" + ec_name); if (list[0] != full_ec_name) { error ("Wrong event channel name"); } CosNotifyChannelAdmin::AdminID aid; CosNotifyChannelAdmin::SupplierAdmin_var admin = mec->named_new_for_suppliers (CosNotifyChannelAdmin::AND_OP, aid, "TestSupplierAdmin"); try { admin = mec->named_new_for_suppliers (CosNotifyChannelAdmin::AND_OP, aid, "TestSupplierAdmin"); error ("Expected a SupplierAdmin " "NotifyMonitoringExt::NameAlreadyUsed exception"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { // This is expected. }; // We should be able to create another one with the same name. admin->destroy (); admin = mec->named_new_for_suppliers (CosNotifyChannelAdmin::AND_OP, aid, "TestSupplierAdmin"); NotifyMonitoringExt::SupplierAdmin_var madmin = NotifyMonitoringExt::SupplierAdmin::_narrow (admin.in ()); if (CORBA::is_nil (madmin.in ())) { error ("Could not narrow the supplier admin"); } CosNotifyChannelAdmin::ProxyID pid; CosNotifyChannelAdmin::ProxyConsumer_var conproxy = madmin->obtain_named_notification_push_consumer ( CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "supplier"); try { CosNotifyChannelAdmin::ProxyConsumer_var fake = madmin->obtain_named_notification_push_consumer (CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "supplier"); error ("Expected a ProxyConsumer " "NotifyMonitoringExt::NameAlreadyUsed exception"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { // This is expected. } stat_name = ecf_name + "/" + ec_name + "/" + ACE_CString (NotifyMonitoringExt::EventChannelSupplierCount); stat = instance->get (stat_name); if (stat == 0) { error ("Could not find the event channel suppliers statistic"); } stat->update (); count = stat->last_sample (); if (!ACE::is_equal (count, 1.0)) { error ("Invalid supplier count"); } CosNotifyChannelAdmin::StructuredProxyPushConsumer_var push_conproxy = CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow ( conproxy.in ()); ACE_ASSERT (!CORBA::is_nil (push_conproxy.in ())); push_conproxy->disconnect_structured_push_consumer (); try { CosNotifyChannelAdmin::ProxyConsumer_var fake = madmin->obtain_named_notification_push_consumer ( CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "supplier"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { error ("Unexpected ProxyConsumer " "NotifyMonitoringExt::NameAlreadyUsed exception"); } CosNotifyChannelAdmin::ConsumerAdmin_var cadmin = mec->named_new_for_consumers (CosNotifyChannelAdmin::AND_OP, aid, "TestConsumerAdmin"); try { cadmin = mec->named_new_for_consumers (CosNotifyChannelAdmin::AND_OP, aid, "TestConsumerAdmin"); error ("Expected a ConsumerAdmin " "NotifyMonitoringExt::NameAlreadyUsed exception"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { // This is expected. }; // We should be able to create another one with the same name cadmin->destroy (); cadmin = mec->named_new_for_consumers (CosNotifyChannelAdmin::AND_OP, aid, "TestConsumerAdmin"); NotifyMonitoringExt::ConsumerAdmin_var mcadmin = NotifyMonitoringExt::ConsumerAdmin::_narrow (cadmin.in ()); if (CORBA::is_nil (mcadmin.in ())) { error ("Could not narrow the consumer admin"); } CosNotifyChannelAdmin::ProxySupplier_var supproxy = mcadmin->obtain_named_notification_push_supplier ( CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "consumer"); try { CosNotifyChannelAdmin::ProxySupplier_var fake = mcadmin->obtain_named_notification_push_supplier ( CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "consumer"); error ("Expected a ProxySupplier " "NotifyMonitoringExt::NameAlreadyUsed exception"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { // This is expected. } stat_name = ecf_name + "/" + ec_name + "/" + ACE_CString (NotifyMonitoringExt::EventChannelConsumerCount); stat = instance->get (stat_name); if (stat == 0) { error ("Could not find the event channel consumers statistic"); } stat->update (); count = stat->last_sample (); if (!ACE::is_equal (count, 1.0)) { error ("Invalid consumer count"); } CosNotifyChannelAdmin::StructuredProxyPushSupplier_var push_supproxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow ( supproxy.in()); ACE_ASSERT (!CORBA::is_nil (push_supproxy.in ())); push_supproxy->disconnect_structured_push_supplier (); try { CosNotifyChannelAdmin::ProxySupplier_var fake = mcadmin->obtain_named_notification_push_supplier ( CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "consumer"); } catch (const NotifyMonitoringExt::NameAlreadyUsed&) { error ("Unexpected ProxySupplier " "NotifyMonitoringExt::NameAlreadyUsed exception"); } TAO_MonitorManager::shutdown (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("MonitorControlExt: "); } catch (...) { error ("Caught an unexpected exception type"); } #else /* ACE_HAS_MONITOR_FRAMEWORK==1 */ ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); #endif /* TAO_HAS_MONITOR_FRAMEWORK==1 */ return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the EC Factory so we can customize the EC TAO_EC_Default_Factory::init_svcs (); // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); const ACE_TCHAR *ecname = ACE_TEXT ("EventService"); const ACE_TCHAR *address = ACE_TEXT ("localhost"); const ACE_TCHAR *iorfile = 0; u_short port = 12345; u_short listenport = 12345; int mcast = 1; for (int i = 0; argv[i] != 0; i++) { if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-ecname")) == 0) { if (argv[i+1] != 0) ecname = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing Event channel name\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-address")) == 0) { if (argv[i+1] != 0) address = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing address\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-port")) == 0) { if (argv[i+1] != 0) port = ACE_OS::atoi(argv[++i]); else ACE_ERROR_RETURN ((LM_ERROR, "Missing port\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-listenport")) == 0) { if (argv[i+1] != 0) listenport = ACE_OS::atoi(argv[++i]); else ACE_ERROR_RETURN ((LM_ERROR, "Missing port\n"), 0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-iorfile")) == 0) { if (argv[i+1] != 0) iorfile = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing ior file\n"), 0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-udp")) == 0) mcast = 0; } // Get the POA CORBA::Object_var tmpobj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (tmpobj.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Create a local event channel and register it TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); TAO_EC_Event_Channel ec_impl (attributes); ec_impl.activate (); PortableServer::ObjectId_var oid = poa->activate_object(&ec_impl); tmpobj = poa->id_to_reference(oid.in()); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(tmpobj.in()); // Find the Naming Service. tmpobj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(tmpobj.in()); // Bind the Event Channel using Naming Services CosNaming::Name_var name = root_context->to_name (ACE_TEXT_ALWAYS_CHAR (ecname)); root_context->rebind(name.in(), ec.in()); // Get a proxy push consumer from the EventChannel. RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); RtecEventChannelAdmin::ProxyPushConsumer_var consumer = admin->obtain_push_consumer(); // Instantiate an EchoEventSupplier_i servant. EchoEventSupplier_i servant(orb.in()); // Register it with the RootPOA. oid = poa->activate_object(&servant); tmpobj = poa->id_to_reference(oid.in()); RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(tmpobj.in()); // Connect to the EC. ACE_SupplierQOS_Factory qos; qos.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); // Initialize the address server with the desired address. This will // be used by the sender object and the multicast receiver only if // one is not otherwise available via the naming service. ACE_INET_Addr send_addr (port, address); SimpleAddressServer addr_srv_impl (send_addr); // Create an instance of the addr server for local use PortableServer::ObjectId_var addr_srv_oid = poa->activate_object(&addr_srv_impl); tmpobj = poa->id_to_reference(addr_srv_oid.in()); RtecUDPAdmin::AddrServer_var addr_srv = RtecUDPAdmin::AddrServer::_narrow(tmpobj.in()); // Create and initialize the sender object PortableServer::Servant_var<TAO_ECG_UDP_Sender> sender = TAO_ECG_UDP_Sender::create(); TAO_ECG_UDP_Out_Endpoint endpoint; // need to be explicit about the address type when built with // IPv6 support, otherwise SOCK_DGram::open defaults to ipv6 when // given a sap_any address. This causes trouble on at least solaris // and windows, or at most on not-linux. if (endpoint.dgram ().open (ACE_Addr::sap_any, send_addr.get_type()) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "Cannot open send endpoint\n"), 1); } // TAO_ECG_UDP_Sender::init() takes a TAO_ECG_Refcounted_Endpoint. // If we don't clone our endpoint and pass &endpoint, the sender will // attempt to delete endpoint during shutdown. TAO_ECG_Refcounted_Endpoint clone (new TAO_ECG_UDP_Out_Endpoint (endpoint)); sender->init (ec.in (), addr_srv.in (), clone); // Setup the subscription and connect to the EC ACE_ConsumerQOS_Factory cons_qos_fact; cons_qos_fact.start_disjunction_group (); cons_qos_fact.insert (ACE_ES_EVENT_SOURCE_ANY, ACE_ES_EVENT_ANY, 0); RtecEventChannelAdmin::ConsumerQOS sub = cons_qos_fact.get_ConsumerQOS (); sender->connect (sub); // Create and initialize the receiver PortableServer::Servant_var<TAO_ECG_UDP_Receiver> receiver = TAO_ECG_UDP_Receiver::create(); // TAO_ECG_UDP_Receiver::init() takes a TAO_ECG_Refcounted_Endpoint. // If we don't clone our endpoint and pass &endpoint, the receiver will // attempt to delete endpoint during shutdown. TAO_ECG_Refcounted_Endpoint clone2 (new TAO_ECG_UDP_Out_Endpoint (endpoint)); receiver->init (ec.in (), clone2, addr_srv.in ()); // Setup the registration and connect to the event channel ACE_SupplierQOS_Factory supp_qos_fact; supp_qos_fact.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); RtecEventChannelAdmin::SupplierQOS pub = supp_qos_fact.get_SupplierQOS (); receiver->connect (pub); // Create the appropriate event handler and register it with the reactor auto_ptr<ACE_Event_Handler> eh; if (mcast) { auto_ptr<TAO_ECG_Mcast_EH> mcast_eh(new TAO_ECG_Mcast_EH (receiver.in())); mcast_eh->reactor (orb->orb_core ()->reactor ()); mcast_eh->open (ec.in()); ACE_auto_ptr_reset(eh,mcast_eh.release()); //eh.reset(mcast_eh.release()); } else { auto_ptr<TAO_ECG_UDP_EH> udp_eh (new TAO_ECG_UDP_EH (receiver.in())); udp_eh->reactor (orb->orb_core ()->reactor ()); ACE_INET_Addr local_addr (listenport); if (udp_eh->open (local_addr) == -1) ACE_ERROR ((LM_ERROR,"Cannot open EH\n")); ACE_auto_ptr_reset(eh,udp_eh.release()); //eh.reset(udp_eh.release()); } // Create an event (just a string in this case). // Create an event set for one event RtecEventComm::EventSet event (1); event.length (1); // Initialize event header. event[0].header.source = MY_SOURCE_ID; event[0].header.ttl = 1; event[0].header.type = MY_EVENT_TYPE; #if !defined (TAO_LACKS_EVENT_CHANNEL_ANY) // Initialize data fields in event. const CORBA::String_var eventData = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (ecname)); event[0].data.any_value <<= eventData; #else // Use the octet sequence payload instead char *tmpstr = const_cast<char *>(ACE_TEXT_ALWAYS_CHAR (ecname)); size_t len = ACE_OS::strlen(tmpstr) +1; event[0].data.payload.replace ( len, len, reinterpret_cast<CORBA::Octet *> (tmpstr)); #endif /* !TAO_LACKS_EVENT_CHANNEL_ANY */ if (iorfile != 0) { CORBA::String_var str = orb->object_to_string( ec.in() ); std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(iorfile) ); iorFile << str.in() << std::endl; iorFile.close(); } ACE_DEBUG ((LM_DEBUG, "Starting main loop\n")); const int EVENT_DELAY_MS = 1000; while (1) { consumer->push (event); ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); orb->run(tv); } orb->destroy(); return 0; } catch (const CORBA::Exception& exc) { ACE_ERROR ((LM_ERROR, "Caught CORBA::Exception\n%C (%C)\n", exc._name (), exc._rep_id () )); } return 1; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { TAO_EC_Default_Factory::init_svcs (); try { // ORB initialization boiler plate... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) == -1) { ACE_ERROR ((LM_ERROR, "Usage: Service [-o IOR_file_name]\n")); return 1; } CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // **************************************************************** #if 0 // Obtain a reference to the naming service... CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService"); CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow (naming_obj.in ()); #endif /* 0 */ // **************************************************************** // Create an scheduling service POA_RtecScheduler::Scheduler* sched_impl = 0; if (config_run) { ACE_NEW_RETURN (sched_impl, RECONFIG_SCHED_TYPE, 1); } else { ACE_NEW_RETURN (sched_impl, RECONFIG_SCHED_TYPE (configs_size, configs, infos_size, infos, 0, 0, 0), 1); } RtecScheduler::Scheduler_var scheduler = sched_impl->_this (); #if 0 // Bind the scheduler with the naming service so clients // (consumers and suppliers) can resolve it, some (old) // implementations of the EC will try to do the same thing // (yikes!) CosNaming::Name schedule_name (1); schedule_name.length (1); schedule_name[0].id = CORBA::string_dup ("ScheduleService"); // Register the servant with the Naming Context.... naming_context->rebind (schedule_name, scheduler.in ()); #endif /* 0 */ // **************************************************************** TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); attributes.scheduler = scheduler.in (); // no need to dup TAO_EC_Event_Channel ec_impl (attributes); ACE_DEBUG ((LM_DEBUG, "activating EC\n")); ec_impl.activate (); ACE_DEBUG ((LM_DEBUG, "EC activated\n")); RtecEventChannelAdmin::EventChannel_var event_channel = ec_impl._this (); // **************************************************************** // Create a consumer, intialize its RT_Info structures, and // connnect to the event channel.... Consumer consumer_impl; RtecScheduler::handle_t consumer_rt_info1 = scheduler->create ("consumer_event_1"); // Let's say that the execution time for event 1 is 2 // milliseconds... ACE_Time_Value tv (0, 2000); TimeBase::TimeT time; ORBSVCS_Time::Time_Value_to_TimeT (time, tv); scheduler->set (consumer_rt_info1, RtecScheduler::VERY_HIGH_CRITICALITY, time, time, time, 0, RtecScheduler::VERY_LOW_IMPORTANCE, time, 0, RtecScheduler::OPERATION); RtecScheduler::handle_t consumer_rt_info2 = scheduler->create ("consumer_event_2"); // Let's say that the execution time for event 2 is 1 // milliseconds... tv.set (0, 1000); ORBSVCS_Time::Time_Value_to_TimeT (time, tv); scheduler->set (consumer_rt_info2, RtecScheduler::VERY_LOW_CRITICALITY, time, time, time, 0, RtecScheduler::VERY_LOW_IMPORTANCE, time, 0, RtecScheduler::OPERATION); ACE_ConsumerQOS_Factory consumer_qos; consumer_qos.start_disjunction_group (); // The types int the range [0,ACE_ES_EVENT_UNDEFINED) are // reserved for the EC... consumer_qos.insert_type (ACE_ES_EVENT_UNDEFINED, consumer_rt_info1); consumer_qos.insert_type (ACE_ES_EVENT_UNDEFINED + 1, consumer_rt_info2); // The canonical protocol to connect to the EC RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin = event_channel->for_consumers (); RtecEventChannelAdmin::ProxyPushSupplier_var supplier_proxy = consumer_admin->obtain_push_supplier (); RtecEventComm::PushConsumer_var consumer = consumer_impl._this (); ACE_DEBUG ((LM_DEBUG, "connecting consumer\n")); supplier_proxy->connect_push_consumer (consumer.in (), consumer_qos.get_ConsumerQOS ()); ACE_DEBUG ((LM_DEBUG, "consumer connected\n")); // **************************************************************** Supplier supplier_impl; RtecScheduler::handle_t supplier_rt_info1 = scheduler->create ("supplier_event_1"); // The execution times are set to reasonable values, but // actually they are changed on the real execution, i.e. we // lie to the scheduler to obtain right priorities; but we // don't care if the set is schedulable. tv.set (0, 10000); TimeBase::TimeT tmp; ORBSVCS_Time::Time_Value_to_TimeT (tmp, tv); RtecScheduler::Period_t rate = ACE_U64_TO_U32(tmp); scheduler->set (supplier_rt_info1, RtecScheduler::VERY_HIGH_CRITICALITY, 0, 0, 0, rate, RtecScheduler::VERY_LOW_IMPORTANCE, 0, 1, RtecScheduler::OPERATION); RtecScheduler::handle_t supplier_rt_info2 = scheduler->create ("supplier_event_2"); // The execution times are set to reasonable values, but // actually they are changed on the real execution, i.e. we // lie to the scheduler to obtain right priorities; but we // don't care if the set is schedulable. tv.set (0, 20000); ORBSVCS_Time::Time_Value_to_TimeT (tmp, tv); rate = ACE_U64_TO_U32(tmp); scheduler->set (supplier_rt_info2, RtecScheduler::VERY_HIGH_CRITICALITY, 0, 0, 0, rate, RtecScheduler::VERY_LOW_IMPORTANCE, 0, 1, RtecScheduler::OPERATION); RtecEventComm::EventSourceID supplier_id = 1; ACE_SupplierQOS_Factory supplier_qos; supplier_qos.insert (supplier_id, ACE_ES_EVENT_UNDEFINED, supplier_rt_info1, 1 /* number of calls, but what does that mean? */); supplier_qos.insert (supplier_id, ACE_ES_EVENT_UNDEFINED + 1, supplier_rt_info2, 1 /* number of calls, but what does that mean? */); // The canonical protocol to connect to the EC RtecEventChannelAdmin::SupplierAdmin_var supplier_admin = event_channel->for_suppliers (); RtecEventChannelAdmin::ProxyPushConsumer_var consumer_proxy = supplier_admin->obtain_push_consumer (); RtecEventComm::PushSupplier_var supplier = supplier_impl._this (); ACE_DEBUG ((LM_DEBUG, "connecting supplier\n")); consumer_proxy->connect_push_supplier (supplier.in (), supplier_qos.get_SupplierQOS ()); ACE_DEBUG ((LM_DEBUG, "supplier connected\n")); // **************************************************************** // At this point the consumer and supplier are connected to the // EC, they have provided their QoS info to the Scheduling // Service and the EC has informed the Scheduler about the // dependencies between them. // We can now compute the schedule for this configuration... // The schedule is returned in this variables.... if (config_run) { ACE_DEBUG ((LM_DEBUG, "Computing schedule\n")); RtecScheduler::RT_Info_Set_var infos; RtecScheduler::Dependency_Set_var deps; RtecScheduler::Config_Info_Set_var configs; RtecScheduler::Scheduling_Anomaly_Set_var anomalies; // Obtain the range of valid priorities in the current // platform, the scheduler hard-code this values in the // generated file, but in the future we may just use the // "logical" priorities and define the mapping to OS // priorities at run-time. int min_os_priority = ACE_Sched_Params::priority_min (ACE_SCHED_FIFO, ACE_SCOPE_THREAD); int max_os_priority = ACE_Sched_Params::priority_max (ACE_SCHED_FIFO, ACE_SCOPE_THREAD); scheduler->compute_scheduling (min_os_priority, max_os_priority, infos.out (), deps.out (), configs.out (), anomalies.out ()); // Dump the schedule to a file.. ACE_Scheduler_Factory::dump_schedule (infos.in (), deps.in (), configs.in (), anomalies.in (), ACE_TEXT("schedule.out")); } // **************************************************************** ACE_DEBUG ((LM_DEBUG, "Pushing events\n")); // Generate a few events.... RtecEventComm::EventSet event1 (1); event1.length (1); event1[0].header.type = ACE_ES_EVENT_UNDEFINED; event1[0].header.source = supplier_id; event1[0].header.ttl = 1; RtecEventComm::EventSet event2 (1); event2.length (1); event2[0].header.type = ACE_ES_EVENT_UNDEFINED + 1; event2[0].header.source = supplier_id; event2[0].header.ttl = 1; for (int i = 0; i != 200; ++i) { if (i % 2 == 0) { consumer_proxy->push (event1); } else { consumer_proxy->push (event2); } ACE_Time_Value rate (0, 10000); ACE_OS::sleep (rate); } // **************************************************************** // We should do a lot of cleanup (disconnect from the EC, // deactivate all the objects with the POA, etc.) but this is // just a simple demo so we are going to be lazy. } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Service"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR * argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); CORBA::Object_var rootObj = orb->resolve_initial_references("NameService"); CosNaming::NamingContext_var rootNC = CosNaming::NamingContext::_narrow(rootObj.in()); // 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 Event Channel factory. CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = TAO_Notify_EventChannelFactory_i::create(poa.in()); ACE_ASSERT (!CORBA::is_nil (notify_factory.in ())); // Create an Event Channel. CosNotifyChannelAdmin::ChannelID id; CosNotification::QoSProperties initial_qos; CosNotification::AdminProperties initial_admin; CosNotifyChannelAdmin::EventChannel_var ec = notify_factory->create_channel (initial_qos, initial_admin, id); // Bind it in the Naming Service. CosNaming::Name name(1); name.length(1); name[0].id = CORBA::string_dup("MyEventChannel"); rootNC->rebind(name, ec.in()); // Become a structured push supplier. CosNotifyChannelAdmin::AdminID adminid; CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::AND_OP; CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = ec->new_for_suppliers (ifgop, adminid); CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id; CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = supplier_admin->obtain_notification_push_consumer( CosNotifyChannelAdmin::STRUCTURED_EVENT, supplieradmin_proxy_id); StructuredEventSupplier_i *servant = new StructuredEventSupplier_i(orb.in()); CosNotifyComm::StructuredPushSupplier_var supplier = servant->_this(); CosNotifyChannelAdmin::StructuredProxyPushConsumer_var consumer_proxy = CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow( proxy_consumer.in()); consumer_proxy->connect_structured_push_supplier(supplier.in()); // Set up events to push. CosNotification::StructuredEvent event; event.header.fixed_header.event_type.domain_name = CORBA::string_dup("OCI_TAO"); event.header.fixed_header.event_type.type_name = CORBA::string_dup("examples"); event.header.fixed_header.event_name = CORBA::string_dup("myevent"); event.filterable_data.length (1); event.filterable_data[0].name = CORBA::string_dup("Message from:"); event.filterable_data[0].value <<= (const char *)user_name; event.filterable_data.length (2); event.filterable_data[1].name = CORBA::string_dup("Subject:"); event.filterable_data[1].value <<= (const char *)subject; event.filterable_data.length (3); event.filterable_data[2].name = CORBA::string_dup("Message:"); event.filterable_data[2].value <<= (const char *)message; // Push events. while (1) { std::cout << "pushing " << std::endl; consumer_proxy->push_structured_event (event); ACE_OS::sleep (1); } } catch(const CORBA::Exception& ex) { return 1; } return 0; }
/** * Register this object. */ int ReplicationManagerFaultConsumerAdapter::init ( CORBA::ORB_ptr orb) { ACE_DEBUG (( LM_DEBUG, ACE_TEXT ("Entered ReplicationManagerFaultConsumerAdapter::init.\n") )); int result = 0; this->orb_ = CORBA::ORB::_duplicate (orb); ////////////////////////////////////////// // resolve reference to detector factory ACE_DEBUG (( LM_DEBUG, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Getting ready to read iorDetectorFile.\n") )); CORBA::Object_var detector_obj = this->orb_->string_to_object ( this->detector_ior_); this->factory_ = ::FT::FaultDetectorFactory::_narrow ( detector_obj.in()); if (CORBA::is_nil (this->factory_.in())) { ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("FaultDetectorFactory IOR is nil: %s\n"), this->detector_ior_), -1); } ////////////////////////////////////////// // resolve references to notifier ACE_DEBUG (( LM_DEBUG, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Getting ready to read Notifier IOR file.\n") )); CORBA::Object_var notifier_ior = this->orb_->string_to_object ( this->notifier_ior_); this->notifier_ = ::FT::FaultNotifier::_narrow ( notifier_ior.in()); if (CORBA::is_nil (this->notifier_.in())) { ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("FaultNotifier IOR is nil: %s\n"), this->notifier_ior_), -1); } // Create the real FaultConsumer. // // Note: We have to hang onto the servant class pointer so we can // invoke member functions on it, but we also give ownership of it // to a PortableServer::ServantBase_var. ACE_DEBUG (( LM_DEBUG, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Getting ready to create the real FaultConsumer.\n") )); ACE_NEW_RETURN (this->p_fault_consumer_, TAO::FT_FaultConsumer (), -1); if (this->p_fault_consumer_ != 0) { this->consumer_servant_ = this->p_fault_consumer_; } ////////////////////////// // Get ready to initialize the consumer. We need to provide it // with the following: // - The POA in which it is to be activated. // - FT::FaultNotifier IOR. // - FT::ReplicationManager IOR (fake it for now). // Get the RootPOA from the ORB. CORBA::Object_var poa_obj = this->orb_->resolve_initial_references ( "RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow ( poa_obj.in()); // Create a fault analyzer. TAO::FT_FaultAnalyzer * analyzer = 0; ACE_NEW_RETURN (analyzer, TAO::FT_DefaultFaultAnalyzer (), -1); // Initialize the FaultConsumer. // It will activate itself in the POA we pass it and connect to the // Fault Notifier we pass it. ACE_DEBUG (( LM_DEBUG, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Getting ready to initialize the real FaultConsumer.\n") )); result = this->p_fault_consumer_->init ( poa.in(), this->notifier_.in(), analyzer); if (result != 0) { ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Unable to initialize the real FaultConsumer.\n")), result); } this->identity_ = "ReplicationManagerFaultConsumerAdapter"; // Activate the RootPOA. PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); ///////////////////////// // Set up fault detectors if (result == 0) { //////////////////////////////////// // resolve references to replicas // create a fault detector for each replica size_t replicaCount = this->replica_iors_.size(); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Number of replicas being monitored: (%u)\n"), static_cast<unsigned int> (replicaCount) )); for (size_t nRep = 0; result == 0 && nRep < replicaCount; ++nRep) { const char * iorName = this->replica_iors_[nRep]; CORBA::Object_var replica_obj = this->orb_->string_to_object ( iorName); FT::PullMonitorable_var replica = FT::PullMonitorable::_narrow ( replica_obj.in()); if (CORBA::is_nil(replica.in())) { ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Can't resolve Replica IOR: %s\n"), iorName), -1); } else { this->replicas_.push_back(replica); CORBA::String_var type_id = CORBA::string_dup("FaultDetector"); TAO_PG::Properties_Encoder encoder; PortableGroup::Value value; value <<= notifier_.in (); encoder.add(::FT::FT_NOTIFIER, value); value <<= replica.in (); encoder.add(::FT::FT_MONITORABLE, value); FT::FTDomainId domain_id = 0; value <<= domain_id; encoder.add(::FT::FT_DOMAIN_ID, value); PortableGroup::Location object_location; object_location.length(2); object_location[0].id = CORBA::string_dup("test"); object_location[1].id = CORBA::string_dup("Location_A"); value <<= object_location; encoder.add(::FT::FT_LOCATION, value); PortableGroup::TypeId_var object_type = CORBA::string_dup ( "IDL:org.omg/CosNaming/NamingContextExt:1.0"); value <<= object_type.in (); encoder.add(::FT::FT_TYPE_ID, value); PortableGroup::ObjectGroupId group_id = static_cast<PortableGroup::ObjectGroupId> (6191982); value <<= group_id; encoder.add(::FT::FT_GROUP_ID, value); // allocate and populate the criteria PortableGroup::Criteria_var criteria; ACE_NEW_NORETURN (criteria, PortableGroup::Criteria); if (criteria.ptr() == 0) { ACE_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ") ACE_TEXT ("Error cannot allocate criteria.\n")), -1); } else { encoder.encode(criteria); PortableGroup::GenericFactory::FactoryCreationId_var factory_creation_id; this->factory_->create_object ( type_id.in(), criteria.in(), factory_creation_id); } } } // Signal that we are ready to go. if (result == 0 && this->readyFile_ != 0) { FILE* ready = ACE_OS::fopen (this->readyFile_, "w"); if (ready) { ACE_OS::fprintf (ready, "ready\n"); ACE_OS::fclose (ready); } } } return result; }
int 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::strcmp(argv[i], ACE_TEXT("-ecname")) == 0) { if (argv[i+1] != 0) { i++; ecname = argv[i]; } else { std::cerr << "Missing Event channel name" << std::endl; } } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-address")) == 0) { if (argv[i+1] != 0) { i++; address = argv[i]; } else { std::cerr << "Missing address" << std::endl; } } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-port")) == 0) { if (argv[i+1] != 0) { i++; port = ACE_OS::atoi(argv[i]); } else { std::cerr << "Missing port" << std::endl; } } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-listenport")) == 0) { if (argv[i+1] != 0) { i++; listenport = ACE_OS::atoi(argv[i]); } else { std::cerr << "Missing port" << std::endl; } } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-iorfile")) == 0) { if (argv[i+1] != 0) { i++; iorfile = argv[i]; } } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-udp")) == 0) { mcast = 0; } } // Get the POA CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Create a local event channel and register it TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); PortableServer::Servant_var<TAO_EC_Event_Channel> ec_impl = new TAO_EC_Event_Channel(attributes); ec_impl->activate (); PortableServer::ObjectId_var oid = poa->activate_object(ec_impl.in()); CORBA::Object_var ec_obj = poa->id_to_reference(oid.in()); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(ec_obj.in()); // Find the Naming Service. CORBA::Object_var obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.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. PortableServer::Servant_var<EchoEventSupplier_i> servant = new EchoEventSupplier_i(orb.in()); // Register it with the RootPOA. oid = poa->activate_object(servant.in()); CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(supplier_obj.in()); // 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. ACE_INET_Addr send_addr (port, address); PortableServer::Servant_var<SimpleAddressServer> addr_srv_impl = new SimpleAddressServer(send_addr); PortableServer::ObjectId_var addr_srv_oid = poa->activate_object(addr_srv_impl.in()); CORBA::Object_var addr_srv_obj = poa->id_to_reference(addr_srv_oid.in()); RtecUDPAdmin::AddrServer_var addr_srv = RtecUDPAdmin::AddrServer::_narrow(addr_srv_obj.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; if (endpoint.dgram ().open (ACE_Addr::sap_any) == -1) { std::cerr << "Cannot open send endpoint" << std::endl; return 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) { std::cerr << "Cannot open EH" << std::endl; } ACE_auto_ptr_reset(eh,udp_eh.release()); //eh.reset(udp_eh.release()); } // Create an event (just a string in this case). const CORBA::String_var eventData = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (ecname)); // Create an event set for one event RtecEventComm::EventSet event (1); event.length (1); // Initialize event header. event[0].header.source = MY_SOURCE_ID; event[0].header.ttl = 1; event[0].header.type = MY_EVENT_TYPE; // Initialize data fields in event. event[0].data.any_value <<= eventData; 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(); } std::cout << "Starting main loop" << std::endl; const int EVENT_DELAY_MS = 10; 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) { std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; } return 1; }
int TAO_Notify_Service_Driver::fini (void) { /// Release all the _vars as the ORB about to go away. CosNotifyChannelAdmin::EventChannelFactory_var factory = this->notify_factory_._retn (); CORBA::ORB_var orb = this->orb_._retn (); CORBA::ORB_var dispatching_orb = this->dispatching_orb_._retn (); PortableServer::POA_var poa = this->poa_._retn (); CosNaming::NamingContextExt_var naming = this->naming_._retn (); // This must be called to ensure that all services shut down // correctly. Depending upon the type of service loaded, it may // or may not actually perform any actions. this->notify_service_->finalize_service (factory.in ()); factory = CosNotifyChannelAdmin::EventChannelFactory::_nil (); this->notify_service_->fini (); // Deactivate. if (this->use_name_svc_ && !CORBA::is_nil (naming.in ())) { // Unbind all event channels from the naming service if (this->register_event_channel_) { for (ACE_Unbounded_Set<ACE_CString>::const_iterator ci ( this->notify_channel_name_); !ci.done(); ci++) { CosNaming::Name_var name = naming->to_name ((*ci).c_str ()); naming->unbind (name.in ()); } } // Unbind from the naming service. CosNaming::Name_var name = naming->to_name (this->notify_factory_name_.c_str ()); naming->unbind (name.in ()); naming = CosNaming::NamingContextExt::_nil (); } if (!CORBA::is_nil (poa.in ())) { poa->destroy (true, true); poa = PortableServer::POA::_nil (); } if (this->shutdown_dispatching_orb_ && !CORBA::is_nil (dispatching_orb_.in ())) { dispatching_orb->shutdown (); } // shutdown the ORB. if (this->shutdown_orb_ && !CORBA::is_nil (orb.in ())) { orb->shutdown (); } // Make sure all worker threads are gone. this->worker_.wait (); this->logging_worker_.wait (); // Destroy the ORB if (this->shutdown_dispatching_orb_ && !CORBA::is_nil (dispatching_orb_.in ())) { dispatching_orb->destroy (); } // Destroy the ORB. if (this->shutdown_orb_ && !CORBA::is_nil (orb.in ())) { orb->destroy (); } dispatching_orb_ = CORBA::ORB::_nil (); worker_.orb (CORBA::ORB::_nil ()); orb = CORBA::ORB::_nil (); return 0; }