2 #include "orbsvcs/RtecEventChannelAdminC.h"
3 #include "orbsvcs/Event_Service_Constants.h"
4 #include "orbsvcs/CosNamingC.h"
7 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
11 return consumer
.run (argc
, argv
);
14 // ****************************************************************
22 Consumer::run (int argc
, ACE_TCHAR
* argv
[])
26 // ORB initialization boiler plate...
28 CORBA::ORB_init (argc
, argv
);
30 // Do *NOT* make a copy because we don't want the ORB to outlive
32 this->orb_
= orb
.in ();
34 CORBA::Object_var object
=
35 orb
->resolve_initial_references ("RootPOA");
36 PortableServer::POA_var poa
=
37 PortableServer::POA::_narrow (object
.in ());
38 PortableServer::POAManager_var poa_manager
=
39 poa
->the_POAManager ();
40 poa_manager
->activate ();
42 // Obtain the event channel from the naming service
43 CORBA::Object_var naming_obj
=
44 orb
->resolve_initial_references ("NameService");
46 if (CORBA::is_nil (naming_obj
.in ()))
47 ACE_ERROR_RETURN ((LM_ERROR
,
48 " (%P|%t) Unable to get the Naming Service.\n"),
51 CosNaming::NamingContext_var naming_context
=
52 CosNaming::NamingContext::_narrow (naming_obj
.in ());
54 CosNaming::Name
name (1);
56 name
[0].id
= CORBA::string_dup ("EventService");
58 CORBA::Object_var ec_obj
=
59 naming_context
->resolve (name
);
61 RtecEventChannelAdmin::EventChannel_var event_channel
=
62 RtecEventChannelAdmin::EventChannel::_narrow (ec_obj
.in ());
64 // The canonical protocol to connect to the EC
65 RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin
=
66 event_channel
->for_consumers ();
68 RtecEventChannelAdmin::ProxyPushSupplier_var supplier
=
69 consumer_admin
->obtain_push_supplier ();
71 RtecEventComm::PushConsumer_var consumer
=
74 // Simple subscription, but usually the helper classes in
75 // $TAO_ROOT/orbsvcs/Event_Utils.h are a better way to do this.
76 RtecEventChannelAdmin::ConsumerQOS qos
;
77 qos
.dependencies
.length (2);
78 RtecEventComm::EventHeader
& h0
=
79 qos
.dependencies
[0].event
.header
;
80 h0
.type
= ACE_ES_DISJUNCTION_DESIGNATOR
;
81 h0
.source
= ACE_ES_EVENT_SOURCE_ANY
;
83 RtecEventComm::EventHeader
& h1
=
84 qos
.dependencies
[1].event
.header
;
85 h1
.type
= ACE_ES_EVENT_UNDEFINED
; // first free event type
86 h1
.source
= ACE_ES_EVENT_SOURCE_ANY
;
88 supplier
->connect_push_consumer (consumer
.in (), qos
);
90 // Wait for events, using work_pending()/perform_work() may help
91 // or using another thread, this example is too simple for that.
94 // We don't do any cleanup, it is hard to do it after shutdown,
95 // and would complicate the example; plus it is almost
96 // impossible to do cleanup after ORB->run() because the POA is
97 // in the holding state. Applications should use
98 // work_pending()/perform_work() to do more interesting stuff.
99 // Check the supplier for the proper way to do cleanup.
101 catch (const CORBA::Exception
& ex
)
103 ex
._tao_print_exception ("Consumer::run");
110 Consumer::push (const RtecEventComm::EventSet
& events
)
112 if (events
.length () == 0)
114 ACE_DEBUG ((LM_DEBUG
,
115 "Consumer (%P|%t) no events\n"));
119 this->event_count_
+= events
.length ();
120 if (this->event_count_
% 100 == 0)
122 ACE_DEBUG ((LM_DEBUG
,
123 "Consumer (%P|%t): %d events received\n",
124 this->event_count_
));
129 Consumer::disconnect_push_consumer ()
131 // In this example we shutdown the ORB when we disconnect from the
132 // EC (or rather the EC disconnects from us), but this doesn't have
133 // to be the case....
134 this->orb_
->shutdown (false);