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"
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
= 20;
18 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
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) {
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
= CosNaming::NamingContextExt::_narrow(obj
.in());
40 // Find the EchoEventChannel.
41 obj
= root_context
->resolve_str (ACE_TEXT_ALWAYS_CHAR (ecname
));
43 // Downcast the object reference to an EventChannel reference.
44 RtecEventChannelAdmin::EventChannel_var ec
=
45 RtecEventChannelAdmin::EventChannel::_narrow(obj
.in());
46 if (CORBA::is_nil(ec
.in())) {
47 std::cerr
<< "Could not narrow EchoEventChannel." << std::endl
;
50 std::cout
<< "EchoEventConsumerMain.cpp: Found the EchoEventChannel." << std::endl
;
52 // Obtain a reference to the consumer administration object.
53 RtecEventChannelAdmin::ConsumerAdmin_var admin
= ec
->for_consumers();
55 // Obtain a reference to the push supplier proxy.
56 RtecEventChannelAdmin::ProxyPushSupplier_var supplier
=
57 admin
->obtain_push_supplier();
60 obj
= orb
->resolve_initial_references("RootPOA");
61 PortableServer::POA_var poa
= PortableServer::POA::_narrow(obj
.in());
63 // Instantiate an EchoEventConsumer_i servant.
64 PortableServer::Servant_var
<EchoEventConsumer_i
> servant
=
65 new EchoEventConsumer_i(orb
.in(), supplier
.in(), EVENT_LIMIT
);
67 // Register it with the RootPOA.
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.
91 // If we have reached this, we must be shutting down...
92 // Disconnect the ProxyPushSupplier.
98 catch(const CORBA::Exception
& exc
)
100 std::cerr
<< "Caught CORBA::Exception" << std::endl
<< exc
<< std::endl
;