diff options
Diffstat (limited to 'quellcode/versuch2/ESConsumer.cpp')
| -rwxr-xr-x | quellcode/versuch2/ESConsumer.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/quellcode/versuch2/ESConsumer.cpp b/quellcode/versuch2/ESConsumer.cpp new file mode 100755 index 0000000..6cc7515 --- /dev/null +++ b/quellcode/versuch2/ESConsumer.cpp @@ -0,0 +1,94 @@ +#include "CPXEventConsumer_i.h" + +#include <orbsvcs/RtecEventCommC.h> +#include <orbsvcs/RtecEventChannelAdminC.h> +#include <orbsvcs/Time_Utilities.h> +#include <orbsvcs/Event_Utilities.h> +#include <orbsvcs/CosNamingC.h> + +const int EVENT_LIMIT = 1000; + +int main (int argc, char* argv[]) +{ + + + struct sched_param schedparam; + schedparam.sched_priority = 99; + if (sched_setscheduler(0, SCHED_FIFO, &schedparam) != 0) { + fprintf(stderr, "%s: PID %d: sched_setscheduler() failed errno = %d\n", __FUNCTION__, getpid(), errno); + } + + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EchoEventChannel. + obj = root_context->resolve_str("EventService"); + + // Downcast the object reference to an EventChannel reference. + RtecEventChannelAdmin::EventChannel_var ec = + RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(ec.in())) { + std::cout << "Could not narrow EchoEventChannel." << std::endl; + return 1; + } + std::cout << "CPXEventConsumerMain.cpp: Found the EchoEventChannel." << std::endl; + + // Obtain a reference to the consumer administration object. + RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers(); + + // Obtain a reference to the push supplier proxy. + RtecEventChannelAdmin::ProxyPushSupplier_var supplier = + admin->obtain_push_supplier(); + + // Get the RootPOA. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Instantiate an CPXEventConsumer_i servant. + CPXEventConsumer_i servant(orb.in()/*, EVENT_LIMIT*/); + + // Register it with the RootPOA. + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); + RtecEventComm::PushConsumer_var consumer = + RtecEventComm::PushConsumer::_narrow(consumer_obj.in()); + + // Connect as a consumer. + ACE_ConsumerQOS_Factory qos; + qos.start_disjunction_group (1); + qos.insert_type (ACE_ES_EVENT_ANY, 0); + supplier->connect_push_consumer (consumer.in (), qos.get_ConsumerQOS ()); + + // Activate the POA via its POAManager. + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + poa_manager->activate(); + + std::cout << "CPXEventConsumerMain.cpp: Ready to receive events..." << std::endl; + + // Enter the ORB event loop. + orb->run(); + + // If we have reached this, we must be shutting down... + // Disconnect the ProxyPushSupplier. + supplier->disconnect_push_supplier(); + supplier = RtecEventChannelAdmin::ProxyPushSupplier::_nil(); + admin = RtecEventChannelAdmin::ConsumerAdmin::_nil(); + + orb->destroy(); + + return 0; + } + catch (CORBA::Exception& ex) + { + std::cout << "Caught CORBA::Exception" << std::endl << ex << std::endl; + } + + return 1; +} + |
