Update bug_report.md
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / EventServices / RTEC_Basic / EchoEventConsumerMain.cpp
bloba401ffdd498462eb426944a9e2a988b967b3c082
1 // Main program for a PushConsumer of Echo events.
3 #include "EchoEventConsumer_i.h"
5 #include "orbsvcs/RtecEventCommC.h"
6 #include "orbsvcs/RtecEventChannelAdminC.h"
7 #include "orbsvcs/Time_Utilities.h"
8 #include "orbsvcs/Event_Utilities.h"
9 #include "orbsvcs/CosNamingC.h"
11 #include <iostream>
12 const int EVENT_LIMIT = 10;
14 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
16 try
18 // Initialize the ORB.
19 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
21 // Find the Naming Service.
22 CORBA::Object_var obj = orb->resolve_initial_references("NameService");
23 CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in());
25 // Find the EchoEventChannel.
26 obj = root_context->resolve_str("EventService");
28 // Downcast the object reference to an EventChannel reference.
29 RtecEventChannelAdmin::EventChannel_var ec =
30 RtecEventChannelAdmin::EventChannel::_narrow(obj.in());
31 if (CORBA::is_nil(ec.in())) {
32 std::cerr << "Could not narrow EchoEventChannel." << std::endl;
33 return 1;
35 std::cout << "EchoEventConsumerMain.cpp: Found the EchoEventChannel." << std::endl;
37 // Obtain a reference to the consumer administration object.
38 RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers();
40 // Obtain a reference to the push supplier proxy.
41 RtecEventChannelAdmin::ProxyPushSupplier_var supplier =
42 admin->obtain_push_supplier();
44 // Get the RootPOA.
45 obj = orb->resolve_initial_references("RootPOA");
46 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
48 // Instantiate an EchoEventConsumer_i servant.
49 PortableServer::Servant_var<EchoEventConsumer_i> servant =
50 new EchoEventConsumer_i(orb.in(), supplier.in(), EVENT_LIMIT);
52 // Register it with the RootPOA.
53 PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
54 CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in());
55 RtecEventComm::PushConsumer_var consumer =
56 RtecEventComm::PushConsumer::_narrow(consumer_obj.in());
58 // Connect as a consumer.
59 ACE_ConsumerQOS_Factory qos;
60 qos.start_disjunction_group (1);
61 qos.insert_type (ACE_ES_EVENT_ANY, // Event Type
62 0); // handle to the rt_info
63 supplier->connect_push_consumer (consumer.in (),
64 qos.get_ConsumerQOS ());
66 // Activate the POA via its POAManager.
67 PortableServer::POAManager_var poa_manager = poa->the_POAManager();
68 poa_manager->activate();
70 std::cout << "EchoEventConsumerMain.cpp: Ready to receive events..." << std::endl;
72 // Enter the ORB event loop.
73 orb->run();
75 // If we have reached this, we must be shutting down...
76 // Disconnect the ProxyPushSupplier.
77 orb->destroy();
79 std::cout << "Test completed." << std::endl;
81 return 0;
83 catch(const CORBA::Exception& ex)
85 std::cerr << "Caught CORBA::Exception" << std::endl << ex << std::endl;
88 return 1;