Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / EventServices / RTEC_Federated / EchoEventConsumerMain.cpp
blob6a00490e6cf3f2e9f2090b4976490d5576526eaf
1 // EchoEventConsumerMain.cpp
2 // Main program for a PushConsumer of Echo events.
4 #include "EchoEventConsumer_i.h"
6 #include "orbsvcs/RtecEventCommC.h"
7 #include "orbsvcs/RtecEventChannelAdminC.h"
8 #include "orbsvcs/Time_Utilities.h"
9 #include "orbsvcs/Event_Utilities.h"
10 #include "orbsvcs/CosNamingC.h"
12 #include <iostream>
13 const RtecEventComm::EventSourceID MY_SOURCE_ID = ACE_ES_EVENT_SOURCE_ANY + 1;
14 const RtecEventComm::EventType MY_EVENT_TYPE = ACE_ES_EVENT_UNDEFINED + 1;
16 const int EVENT_LIMIT = 10;
18 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
20 try
22 // Initialize the ORB.
23 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
25 const ACE_TCHAR *ecname = ACE_TEXT ("EventService");
26 for (int i = 0; argv[i] != 0; i++) {
27 if (ACE_OS::strcmp(argv[i], ACE_TEXT("-ecname")) == 0) {
28 if (argv[i+1] != 0) {
29 ecname = argv[i+1];
30 } else {
31 std::cerr << "Missing Event channel name" << std::endl;
36 // Find the Naming Service.
37 CORBA::Object_var obj = orb->resolve_initial_references("NameService");
38 CosNaming::NamingContextExt_var root_context
39 = CosNaming::NamingContextExt::_narrow(obj.in());
41 // Find the EchoEventChannel.
42 obj = root_context->resolve_str (ACE_TEXT_ALWAYS_CHAR (ecname));
44 // Downcast the object reference to an EventChannel reference.
45 RtecEventChannelAdmin::EventChannel_var ec =
46 RtecEventChannelAdmin::EventChannel::_narrow(obj.in());
47 if (CORBA::is_nil(ec.in())) {
48 std::cerr << "Could not narrow EchoEventChannel." << std::endl;
49 return 1;
51 std::cout << "EchoEventConsumerMain.cpp: Found the EchoEventChannel." << std::endl;
53 // Obtain a reference to the consumer administration object.
54 RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers();
56 // Obtain a reference to the push supplier proxy.
57 RtecEventChannelAdmin::ProxyPushSupplier_var supplier =
58 admin->obtain_push_supplier();
60 // Get the RootPOA.
61 obj = orb->resolve_initial_references("RootPOA");
62 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
64 // Instantiate an EchoEventConsumer_i servant and register it
65 // with the RootPOA
66 PortableServer::Servant_var<EchoEventConsumer_i> servant =
67 new EchoEventConsumer_i(orb.in(), supplier.in(), EVENT_LIMIT);
68 PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
69 CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in());
70 RtecEventComm::PushConsumer_var consumer =
71 RtecEventComm::PushConsumer::_narrow(consumer_obj.in());
73 // Connect as a consumer.
74 ACE_ConsumerQOS_Factory qos;
75 qos.start_disjunction_group ();
76 qos.insert (MY_SOURCE_ID, // Source ID
77 MY_EVENT_TYPE, // Event Type
78 0); // handle to the rt_info
79 supplier->connect_push_consumer (consumer.in (),
80 qos.get_ConsumerQOS ());
82 // Activate the POA via its POAManager.
83 PortableServer::POAManager_var poa_manager = poa->the_POAManager();
84 poa_manager->activate();
86 std::cout << "EchoEventConsumerMain.cpp: Ready to receive events..." << std::endl;
88 // Enter the ORB event loop.
89 orb->run();
91 // If we have reached this, we must be shutting down...
92 // Disconnect the ProxyPushSupplier.
93 orb->destroy();
95 std::cout << "Test completed." << std::endl;
97 return 0;
99 catch(const CORBA::Exception& exc)
101 std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl;
103 return 1;