1 // EchoEventConsumerMain.cpp
2 // Main program for a PushConsumer of Echo events.
5 #include "EchoEventConsumer_i.h"
7 #include "orbsvcs/CosEventCommC.h"
8 #include "orbsvcs/CosEventChannelAdminC.h"
9 #include "orbsvcs/CosNamingC.h"
13 const int EVENTS_TILL_SHUTDOWN
= 10;
15 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
19 // Initialize the ORB.
20 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
22 // Find the Naming Service.
23 CORBA::Object_var obj
= orb
->resolve_initial_references("NameService");
24 CosNaming::NamingContextExt_var root_context
= CosNaming::NamingContextExt::_narrow(obj
.in());
26 // Find the EchoEventChannel.
27 obj
= root_context
->resolve_str("CosEventService");
29 // Downcast the object reference to an EventChannel reference.
30 CosEventChannelAdmin::EventChannel_var echoEC
=
31 CosEventChannelAdmin::EventChannel::_narrow(obj
.in());
32 if (CORBA::is_nil(echoEC
.in())) {
33 std::cerr
<< "Could not narrow EchoEventChannel." << std::endl
;
36 std::cout
<< "Found the EchoEventChannel." << std::endl
;
38 // Get a ConsumerAdmin object from the EventChannel.
39 CosEventChannelAdmin::ConsumerAdmin_var consumerAdmin
=
40 echoEC
->for_consumers();
42 // Get a ProxyPushSupplier from the ConsumerAdmin.
43 CosEventChannelAdmin::ProxyPushSupplier_var supplier
=
44 consumerAdmin
->obtain_push_supplier();
46 // Instantiate an EchoEventConsumer_i servant.
47 PortableServer::Servant_var
<EchoEventConsumer_i
> servant
=
48 new EchoEventConsumer_i(orb
.in(), supplier
.in(), EVENTS_TILL_SHUTDOWN
);
50 // Register it with the RootPOA.
51 obj
= orb
->resolve_initial_references("RootPOA");
52 PortableServer::POA_var poa
= PortableServer::POA::_narrow(obj
.in());
53 PortableServer::ObjectId_var oid
= poa
->activate_object(servant
.in());
54 CORBA::Object_var consumer_obj
= poa
->id_to_reference(oid
.in());
55 CosEventComm::PushConsumer_var consumer
=
56 CosEventComm::PushConsumer::_narrow(consumer_obj
.in());
58 // Connect to the ProxyPushSupplier, passing our PushConsumer object
60 supplier
->connect_push_consumer(consumer
.in());
62 // Activate the POA via its POAManager.
63 PortableServer::POAManager_var poa_manager
= poa
->the_POAManager();
64 poa_manager
->activate();
66 std::cout
<< "Ready to receive events..." << std::endl
;
68 // Enter the ORB event loop.
71 // If we have reached this, we must be shutting down...
74 std::cout
<< "Test complete." << std::endl
;
78 catch(const CORBA::Exception
& ex
)
80 std::cerr
<< "Consumer: Caught CORBA::Exception: " << ex
<< std::endl
;