void TAO_CosNotify_Service::finalize_service ( CosNotifyChannelAdmin::EventChannelFactory_ptr factory) { // Get out early if we can if (CORBA::is_nil (factory)) return; // Make sure the factory doesn't go away while we're in here CosNotifyChannelAdmin::EventChannelFactory_var ecf = CosNotifyChannelAdmin::EventChannelFactory::_duplicate (factory); // Find all the consumer admin objects and shutdown the worker tasks CosNotifyChannelAdmin::ChannelIDSeq_var channels = ecf->get_all_channels (); CORBA::ULong length = channels->length (); for(CORBA::ULong i = 0; i < length; i++) { try { CosNotifyChannelAdmin::EventChannel_var ec = ecf->get_event_channel (channels[i]); if (!CORBA::is_nil (ec.in ())) { TAO_Notify_EventChannel* nec = dynamic_cast<TAO_Notify_EventChannel*> (ec->_servant ()); if (nec != 0) nec->destroy (); } } catch (const CORBA::Exception&) { // We're shutting things down, so ignore exceptions } } TAO_Notify_EventChannelFactory* necf = dynamic_cast<TAO_Notify_EventChannelFactory*> (ecf->_servant ()); if (necf != 0) necf->stop_validator(); }
CosNotifyChannelAdmin::EventChannel_var get_event_channel(CORBA::ORB_ptr orb) { CosNotifyChannelAdmin::EventChannel_var ec; CosNotifyChannelAdmin::ChannelID id; CosNotification::QoSProperties init_qos(0); CosNotification::AdminProperties init_admin(0); std::cout << "Get CosNotifyChannelAdmin::EventChannelFactory" << std::endl; std::cout << "IorEventChannelFactory=" << ior << std::endl; CORBA::Object_var obj = orb->string_to_object(ior); if (CORBA::is_nil(obj.in ())) { std::cerr << "Bad ec_fact.ior " << std::endl; exit(1); } CosNotifyChannelAdmin::EventChannelFactory_var factory = CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj.in ()); if (CORBA::is_nil(factory.in())) { std::cerr << "Could not _narrow object to type CosNotifyChannelAdmin::EventChannelFactory" << std::endl; exit(1); } //Get the first ec CosNotifyChannelAdmin::ChannelIDSeq_var channelIdSeq; try { channelIdSeq = factory->get_all_channels(); } catch (CORBA::SystemException& se ) { std::cerr << "System exception occurred during get_all_channels: " << se << std::endl; exit(1); } if( channelIdSeq->length() == 0 ) { try { ec = factory->create_channel( init_qos, init_admin, id); } catch (CORBA::SystemException& se ) { std::cerr << "System exception occurred during find_channel: " << se << std::endl; exit(1); } } else { try { ec = factory->get_event_channel(channelIdSeq.in()[0]); } catch (CosNotifyChannelAdmin::ChannelNotFound&) { std::cerr << "ChannelNotFound: " << channelIdSeq.in()[0] << std::endl; exit(1); } catch (CORBA::SystemException& se ) { std::cerr << "System exception occurred during get_event_channel: " << se << std::endl; exit(1); } } return ec._retn(); }
int main(int argc,char *argv []) { CORBA::ORB_ptr orb_ptr; try { /************************************************************************/ /* INICIALIZAMOS LA PARTE DEL ORB */ /************************************************************************/ int alt_argc = 0; char ** alt_argv; const char * orb_id="Test_TIDNotification"; orb_ptr=CORBA::ORB_init(argc, argv, orb_id); if (!orb_ptr) { cerr<<"El ORB es null"<<endl; return -1; } CORBA::Object_ptr delegado_POA; PortableServer::POA_ptr rootPOA; try { delegado_POA = orb_ptr->resolve_initial_references("RootPOA"); } catch ( CORBA::ORB::InvalidName ex ) { ex._name(); return -1; } rootPOA = PortableServer::_POAHelper::narrow( delegado_POA,true ); PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager(); CORBA::PolicyList_var policies = NULL; policies = new CORBA::PolicyList(2); policies->length(2); // Valores cambiados (*policies)[0] = rootPOA->create_lifespan_policy ( PortableServer::PERSISTENT ); (*policies)[1] = rootPOA->create_id_assignment_policy ( PortableServer::USER_ID ); PortableServer::POA_var consumerPOA = rootPOA->create_POA("consumerPOA", poa_manager, *policies ); /***********************************************************************/ /* OBTENEMOS LA FACTORIA DEL CANAL DE EVENTOS Y CREAMOS EL CANAL */ /**********************************************************************/ CORBA::Object_ptr delegado_event_channel_factory; delegado_event_channel_factory=orb_ptr->string_to_object(argv[1]); CosNotifyChannelAdmin::EventChannelFactory_var factory; factory = CosNotifyChannelAdmin::EventChannelFactory::_narrow(delegado_event_channel_factory); if (CORBA::is_nil(factory)) { cerr << "[server] ERROR: factoria nula " << endl; return -1; } CosNotifyChannelAdmin::EventChannel_var channel; //CosNotifyChannelAdmin::EventChannel_var channelv[10]; CosNotification::QoSProperties initial_qos; CosNotification::AdminProperties initial_admin; CosNotifyChannelAdmin::ChannelID id; //CosNotifyChannelAdmin::ChannelID idv[10]; // // Politicas Soportadas: // initial_qos.length(9); // initial_qos[0].name = CORBA::string_dup("OrderPolicy"); // initial_qos[0].value <<= CosNotification::FifoOrder; // Any Fifo Priority Deadline // initial_qos[1].name = CORBA::string_dup("EventReliability"); // initial_qos[1].value <<= CosNotification::BestEffort; // Persistent // initial_qos[2].name = CORBA::string_dup("ConnectionReliability"); // initial_qos[2].value <<= CosNotification::BestEffort; // Persistent // initial_qos[3].name = CORBA::string_dup("Priority"); // initial_qos[3].value <<= CosNotification::HighestPriority; // Highest, Default // initial_qos[4].name = CORBA::string_dup("StartTime"); // initial_qos[4].value <<= *(new TimeBase::UtcT( // TIDorb::core::util::Time::currentTimeMillis(), // 0,0,0)); // initial_qos[5].name = CORBA::string_dup("StopTime"); // initial_qos[5].value <<= *(new TimeBase::UtcT( // TIDorb::core::util::Time::currentTimeMillis(), // 0,0,0)); // initial_qos[6].name = CORBA::string_dup("Timeout"); // initial_qos[6].value <<= (TimeBase::TimeT)TIDorb::core::util::Time::currentTimeMillis(); // initial_qos[7].name = CORBA::string_dup("StartTimeSupported"); // initial_qos[7].value <<= (CORBA::Boolean) 0; // initial_qos[8].name = CORBA::string_dup("StopTimeSupported"); // initial_qos[8].value <<= (CORBA::Boolean) 1; // // Politicas de QoS no soportadas // // initial_qos[0].name = CORBA::string_dup("DiscardPolicy"); // initial_qos[0].value <<= CosNotification::AnyOrder; // Any Fifo Priority Deadline // initial_qos[7].name = CORBA::string_dup("MaximumBatchSize"); // initial_qos[7].value <<= (CORBA::Long) 20; // initial_qos[0].name = CORBA::string_dup("PacingInterval"); // initial_qos[0].value <<= (TimeBase::TimeT)TIDorb::core::util::Time::currentTimeMillis(); // initial_qos[9].name = CORBA::string_dup("MaxEventsPerConsumer"); // initial_qos[9].value <<= (CORBA::Long) 20; try { // Crear el canal channel = factory->get_event_channel(0); // for(int i=0; i < 10; i++){ // channelv[i] = factory->create_channel(initial_qos, initial_admin, idv[i]); // } } catch (CosNotifyChannelAdmin::ChannelNotFound &ex) { cerr << "[server_consumer] CosNotifyChannelAdmin::ChannelNotFound: " << ex._name(); return -1; } /**************************************************************************/ /* OBTENEMOS EL CONSUMERADMIN POR DEFECTO */ /**************************************************************************/ CosNotifyChannelAdmin::ConsumerAdmin_ptr consumerAdmin; consumerAdmin = channel->default_consumer_admin(); //Metemos los filtros en el consumer admin CosNotifyFilter::Filter* filter_II = create_filter(channel,"GSyC","test","$domain_name != 'GSyC'"); //consumerAdmin->add_filter(filter_II); //CosNotifyFilter::Filter* filter_III = create_filter(channel,"GSyC","test","$.remainder_of_boy.campo_uno != 1"); //consumerAdmin->add_filter(filter_III); /**************************************************************************/ /* OBTENEMOS EL PROXYSUPPLIER APARTIR DEL CONSUMERADMIN */ /**************************************************************************/ //TODO_MORFEO: add new filters CosNotifyChannelAdmin::ProxySupplier_ptr proxySupplier; CosNotifyChannelAdmin::ProxyID proxySupplierID = 1; proxySupplier = consumerAdmin->obtain_notification_push_supplier(CosNotifyChannelAdmin::ANY_EVENT, proxySupplierID); /**************************************************************************/ /* OBTENEMOS EL PROXYPUSHSUPPLIER APARTIR DEL CONSUMERADMIN */ /**************************************************************************/ CosNotifyChannelAdmin::StructuredProxyPushSupplier_ptr proxyPushSupplier; proxyPushSupplier = CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(proxySupplier); /**************************************************************************/ /* INSTANCIAMOS LOS PROXYS Y LOS ACTIVAMOS EN EL POA */ /**************************************************************************/ my_push_consumer * my_consumer = new my_push_consumer(orb_ptr,proxyPushSupplier); PortableServer::ObjectId_ptr consumer_objectID = PortableServer::string_to_ObjectId("My_Consumer:1.0"); consumerPOA->activate_object_with_id(*consumer_objectID,my_consumer); poa_manager->activate(); CORBA::Object_ptr obj_consumer = consumerPOA->id_to_reference(*consumer_objectID); CosNotifyComm::StructuredPushConsumer_ptr my_pushConsumer = CosNotifyComm::StructuredPushConsumer::_narrow(obj_consumer); /***********************************************************************/ /* CONECTAMOS EL PUSHSUPPLIER Y EL PUSHCONSUMER */ /***********************************************************************/ proxyPushSupplier->connect_structured_push_consumer(my_pushConsumer); orb_ptr->run(); } catch (CORBA::Exception & e) { cerr<<"[Test_Filter] unknown error"<< typeid(e).name() << e._name(); return -1; } }