CosNotifyChannelAdmin::AdminID IdAssignment::create_supplier_admin (CosNotifyChannelAdmin::ChannelID channel_id) { CosNotifyChannelAdmin::AdminID adminid; CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::OR_OP; CosNotifyChannelAdmin::EventChannel_var ec = this->notify_factory_->get_event_channel (channel_id); if (CORBA::is_nil (ec.in ())) { ACE_ERROR((LM_ERROR, " (%P|%t) Unable to find event channel\n")); return 0; } CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = ec->new_for_suppliers (ifgop, adminid); if (CORBA::is_nil (supplier_admin.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to create supplier admin\n"),0); if (TAO_debug_level) ACE_DEBUG ((LM_DEBUG, "created supplier admin\n")); return adminid; }
void TAO_Notify_Lanes_Supplier_Client::initialize (void) { PortableServer::POAManager_var poa_manager = this->orb_objects_.root_poa_->the_POAManager (); poa_manager->activate (); CosNotifyChannelAdmin::EventChannel_var ec = this->create_ec (); // Create a Supplier Admin CosNotifyChannelAdmin::AdminID adminid = 0; CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = ec->new_for_suppliers (CosNotifyChannelAdmin::AND_OP, adminid); ACE_ASSERT (!CORBA::is_nil (supplier_admin.in ())); // Create a Supplier this->supplier_ = new TAO_Notify_Lanes_Supplier (this->orb_objects_); // Initialize it. this->supplier_->init (supplier_admin, this->consumer_count_); }
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; }
Messenger_i::Messenger_i (CORBA::ORB_ptr orb) : orb_ (CORBA::ORB::_duplicate (orb)) { CORBA::Object_var naming_obj = orb_->resolve_initial_references ("NameService"); CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow (naming_obj.in()); CosNaming::Name name; name.length (1); name[0].id = CORBA::string_dup ("NotifyEventChannelFactory"); CORBA::Object_var obj = naming_context->resolve (name); CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in ()); CosNotifyChannelAdmin::ChannelID id; CosNotification::QoSProperties initial_qos; CosNotification::AdminProperties initial_admin; CosNotifyChannelAdmin::EventChannel_var ec = notify_factory->create_channel (initial_qos, initial_admin, id); name[0].id = CORBA::string_dup ("MyEventChannel"); naming_context->rebind (name, ec.in()); CosNotifyChannelAdmin::AdminID adminid; CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::OR_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()); CORBA::Object_var poa_obj = orb_->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in ()); PortableServer::POAManager_var mgr = poa->the_POAManager (); mgr->activate (); PortableServer::ObjectId_var objectId = poa->activate_object (servant); CORBA::Object_var supplier_obj = poa->id_to_reference (objectId.in ()); CosNotifyComm::StructuredPushSupplier_var supplier = CosNotifyComm::StructuredPushSupplier::_narrow (supplier_obj.in ()); consumer_proxy_ = CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (proxy_consumer.in()); consumer_proxy_-> connect_structured_push_supplier (supplier.in()); }
int main(int argc, char* argv[]) { char aux1[1000]; time_t seconds; signal(SIGINT, TerminarEjecucion); time(&seconds); srand((unsigned int) seconds); try { // Inicializacion del ORB CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, ""); // Recoge la referencia al canal cin >> aux1; CORBA::Object_var obj = orb->string_to_object(aux1); // Obtiene el canal CosNotifyChannelAdmin::EventChannel_var channel; channel = CosNotifyChannelAdmin::EventChannel::_narrow(obj); if (CORBA::is_nil(channel)) { cerr << "[supplier2] ERROR: canal nulo " << endl; return -1; } // Obtiene el SupplierAdmin CosNotifyChannelAdmin::AdminID id; _supplier_admin = channel->new_for_suppliers(CosNotifyChannelAdmin::AND_OP, id); cerr << "[supplier2] SupplierAdminId = " << id << endl; CosNotifyChannelAdmin::ProxyID proxy_id; CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = _supplier_admin->obtain_notification_push_consumer( CosNotifyChannelAdmin::STRUCTURED_EVENT, proxy_id); cerr << "[supplier2] ProxyId = " << proxy_id << endl; // Obtiene el StructuredProxyPushConsumer _consumer = CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(proxy_consumer); try{ CosNotifyComm::StructuredPushSupplier_var supplier = CosNotifyComm::StructuredPushSupplier::_nil(); _consumer->connect_structured_push_supplier(supplier); if (_consumer == NULL) cerr << "[supplier2] consumer NULO 5" << endl; } catch (CORBA::Exception& exc) { cerr << "[supplier2] Exception in _consumer->connect_push_supplier(...)"; cerr << exc << endl; } catch (...) { cerr << "[supplier2] Unknowed exception "; cerr << "in _consumer->connect_push_supplier(...)"; } #ifdef _TAO sleep(1); #elif defined _TIDORB TIDThr::Thread::sleep(1000); // 1 '' #endif cerr << "[supplier2] Crea un structured event" << flush << endl; try{ CosNotification::StructuredEvent* event = NULL; int rnd = 0; for(int i=0; i < 200; i++) { rnd = rand(); TimeBase::UtcT current_utc = TIDorb::core::util::Time::currentUtcT(); TimeBase::UtcT future_utc = TIDorb::core::util::Time::currentUtcT(); TimeBase::UtcT pass_utc = TIDorb::core::util::Time::currentUtcT(); future_utc.time += (5 * 10000000); // now + 5 '' pass_utc.time -= (5 * 10000000); // now - 5 '' // Rellenamos la informacion del evento event = new CosNotification::StructuredEvent(); event->header.fixed_header.event_name = (rnd % 2) ? CORBA::string_dup("event_name") : CORBA::string_dup("other"); event->header.fixed_header.event_type.domain_name = (rnd % 2) ? CORBA::string_dup("domain_name") : CORBA::string_dup("other"); event->header.fixed_header.event_type.type_name = (rnd % 2) ? CORBA::string_dup("type_name") : CORBA::string_dup("other"); event->header.variable_header.length(5); event->header.variable_header[0].name = CORBA::string_dup("EventReliability"); event->header.variable_header[0].value <<= (CORBA::Short) 0; event->header.variable_header[1].name = CORBA::string_dup("Priority"); event->header.variable_header[1].value <<= (CORBA::Short) 0; event->header.variable_header[2].name = CORBA::string_dup("StartTime"); event->header.variable_header[2].value <<= current_utc; event->header.variable_header[3].name = CORBA::string_dup("StopTime"); event->header.variable_header[3].value <<= pass_utc; event->header.variable_header[4].name = CORBA::string_dup("Timeout"); event->header.variable_header[4].value <<= (TimeBase::TimeT) 0; event->filterable_data.length(2); event->filterable_data[0].name = CORBA::string_dup("int"); event->filterable_data[0].value <<= ( rnd * 1000 ) ; event->filterable_data[1].name = CORBA::string_dup("string"); event->filterable_data[1].value <<= ( (rnd % 2) ? (const char*)"greater" : (const char*)"smaller" ); event->remainder_of_body <<= (const char*) "remainder_of_body"; CORBA::Long my_long; event->filterable_data[0].value >>= my_long; cout << "Enviando mensage " << my_long; cout << ": " << event->header.fixed_header.event_type.domain_name << ", "; cout << event->header.fixed_header.event_type.type_name << endl; // Envia el evento _consumer->push_structured_event(*event); delete event; event = NULL; } // for cerr << "[supplier2] Desconectando... " << flush << endl; _consumer->disconnect_structured_push_consumer(); } catch(...){ cerr << "[supplier2] Excepcion " << endl; } _supplier_admin->destroy(); cerr << "[supplier2] Terminando" << flush << endl; orb->shutdown(true); orb->destroy(); } catch(CORBA::Exception& exc) { cerr << "[supplier2] Excepcion: " << exc << endl; return 1; } }
Messenger_i::Messenger_i (CORBA::ORB_ptr orb) : orb_(CORBA::ORB::_duplicate(orb)) { CORBA::Object_var poa_object = orb_->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in())) { std::cerr << "Unable to initialize the POA." << std::endl; } CORBA::Object_var naming_obj = orb_->resolve_initial_references ("NameService"); if (CORBA::is_nil(naming_obj.in())) { std::cerr << "Unable to find naming service" << std::endl; } CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow(naming_obj.in()); CosNaming::Name name; name.length (1); name[0].id = CORBA::string_dup("NotifyEventChannelFactory"); CORBA::Object_var obj = naming_context->resolve(name); CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj.in()); if (CORBA::is_nil(notify_factory.in())) { std::cerr << "Unable to find notify factory" << std::endl; } CosNotifyChannelAdmin::ChannelID id; CosNotification::QoSProperties initial_qos; CosNotification::AdminProperties initial_admin; CosNotifyChannelAdmin::EventChannel_var ec = notify_factory->create_channel (initial_qos, initial_admin, id); if (CORBA::is_nil (ec.in())) { std::cerr << "Unable to crete event channel" << std::endl; } // name.length(1); name[0].id = CORBA::string_dup("MyEventChannel"); naming_context->rebind(name, ec.in()); CosNotifyChannelAdmin::AdminID adminid; CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::AND_OP; CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = ec->new_for_suppliers (ifgop, adminid); if (CORBA::is_nil (supplier_admin.in())) { std::cerr << "Unable to find supplier admin" << std::endl; } 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(); s_proxy_consumer_ = CosNotifyChannelAdmin::StructuredProxyPushConsumer:: _narrow(proxy_consumer.in()); if (CORBA::is_nil (s_proxy_consumer_.in())) { std::cerr << "Unable to find structured proxy push consumer" << std::endl; } s_proxy_consumer_-> connect_structured_push_supplier(supplier.in()); CosNotification::EventTypeSeq added (1); CosNotification::EventTypeSeq removed (1); added.length (1); removed.length (1); added[0].domain_name = CORBA::string_dup ("OCI_TAO"); added[0].type_name = CORBA::string_dup ("examples"); removed[0].domain_name = CORBA::string_dup ("*"); removed[0].type_name = CORBA::string_dup ("*"); s_proxy_consumer_->offer_change(added, removed); }
int main(int argc, char * argv[]) { CORBA::Object_var obj; //---------------------------------------------------------------------------- // initialize ORB CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); //---------------------------------------------------------------------------- // initialize POA obj = orb->resolve_initial_references("RootPOA"); assert(!CORBA::is_nil(obj)); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); poa_manager->activate(); //---------------------------------------------------------------------------- // get naming service reference obj = orb->resolve_initial_references("NameService"); assert(!CORBA::is_nil(obj)); CosNaming::NamingContext_var naming_service = CosNaming::NamingContext::_narrow(obj); //---------------------------------------------------------------------------- // get event channel reference // resolving name in robots naming context assert(argc >= 2); std::string naming_context = argv[1]; CosNaming::Name name; name.length(2); name[0].id = naming_context.c_str(); name[1].id = string("NotifyEventChannel").c_str(); obj = naming_service->resolve(name); // The event channel CosNotifyChannelAdmin::EventChannel_var ec = CosNotifyChannelAdmin::EventChannel::_narrow(obj); //---------------------------------------------------------------------------- // creating a notification service supplier admin // The group operator between admin-proxy's. CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::OR_OP; // The id of the created adin. CosNotifyChannelAdmin::AdminID admin_id; // The supplier admin used by supplier. CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin; supplier_admin = ec->new_for_suppliers(ifgop, admin_id); //---------------------------------------------------------------------------- // create a notification service proxy consumer, to send events to // This proxy's id. CosNotifyChannelAdmin::ProxyID proxy_id; // The proxy that we are connected to. CosNotifyChannelAdmin::StructuredProxyPushConsumer_var proxy_consumer; obj = supplier_admin-> obtain_notification_push_consumer(CosNotifyChannelAdmin::STRUCTURED_EVENT, proxy_id); assert(!CORBA::is_nil(obj)); // narrow proxy_consumer = CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(obj); //---------------------------------------------------------------------------- // offer/subscription management // don't call us on subscription changes CosNotification::EventTypeSeq_var events = proxy_consumer-> obtain_subscription_types(CosNotifyChannelAdmin::NONE_NOW_UPDATES_OFF); // register the events we gonna offer CosNotification::EventTypeSeq added; CosNotification::EventTypeSeq removed; added.length(1); added[0].domain_name = string("Robot_Name").c_str(); added[0].type_name = string("Event_Name").c_str(); // remove default offer removed.length(1); removed[0].domain_name = string("*").c_str(); removed[0].type_name = string("*").c_str(); supplier_admin->offer_change(added, removed); //---------------------------------------------------------------------------- // create and connect a supplier class class MySupplier : public POA_CosNotifyComm::StructuredPushSupplier { protected: void subscription_change(CosNotification::EventTypeSeq const& added, CosNotification::EventTypeSeq const& removed) throw(CosNotifyComm::InvalidEventType) { cerr << "subscription_change() called" << endl; } void disconnect_structured_push_supplier() throw() { cerr << "disconnect_structured_push_supplier() called" << endl; } }; MySupplier * supplier = new MySupplier(); // activate supplier with poa CosNotifyComm::StructuredPushSupplier_var objref = supplier->_this(); // connect proxy_consumer->connect_structured_push_supplier(objref); //---------------------------------------------------------------------------- // sending an event CosNotification::StructuredEvent event; event.header.fixed_header.event_type.domain_name = CORBA::string_dup("Robot_Name"); event.header.fixed_header.event_type.type_name = string("Event_Name").c_str(); proxy_consumer->push_structured_event(event); proxy_consumer->disconnect_structured_push_consumer(); supplier_admin->destroy(); return 0; }
Messenger_i::Messenger_i (CORBA::ORB_ptr orb) : orb_ (CORBA::ORB::_duplicate(orb)) { try { CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(poa_obj.in()); CORBA::Object_var naming_obj = orb_->resolve_initial_references ("NameService"); if (CORBA::is_nil(naming_obj.in())) { std::cerr << "Unable to find naming service" << std::endl; } CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow(naming_obj.in()); // // Create an instance of TAO's notification event channel // CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = TAO_Notify_EventChannelFactory_i::create(poa.in()); if (CORBA::is_nil (notify_factory.in ())) { std::cerr << "Unable to create the notify event channel" << std::endl; return; } CosNotifyChannelAdmin::ChannelID id; CosNotification::QoSProperties initial_qos; CosNotification::AdminProperties initial_admin; CosNotifyChannelAdmin::EventChannel_var ec = notify_factory->create_channel (initial_qos, initial_admin, id); if (CORBA::is_nil (ec.in())) { std::cerr << "Unable to create event channel" << std::endl; return; } CosNaming::Name name(1); name.length(1); name[0].id = CORBA::string_dup("MyEventChannel"); naming_context->rebind(name, ec.in()); CosNotifyChannelAdmin::AdminID adminid; CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::AND_OP; CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = ec->new_for_suppliers (ifgop, adminid); if (CORBA::is_nil (supplier_admin.in())) { std::cerr << "Unable to find supplier admin" << std::endl; } 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()); PortableServer::ObjectId_var oid = poa->activate_object(servant); CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); CosNotifyComm::StructuredPushSupplier_var supplier = CosNotifyComm::StructuredPushSupplier::_narrow(supplier_obj.in()); consumer_proxy_ = CosNotifyChannelAdmin::StructuredProxyPushConsumer:: _narrow(proxy_consumer.in()); if (CORBA::is_nil (consumer_proxy_.in())) { std::cerr << "Unable to find structured proxy push consumer" << std::endl; } consumer_proxy_->connect_structured_push_supplier(supplier.in()); } catch(const CORBA::Exception& ex) { std::cerr << ex << std::endl; } }