2 #include "orbsvcs/CosEventChannelAdminS.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR
*ior
= ACE_TEXT ("file://ec.ior");
8 parse_args (int argc
, ACE_TCHAR
*argv
[])
10 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
13 while ((c
= get_opts ()) != -1)
17 ior
= get_opts
.opt_arg ();
22 ACE_ERROR_RETURN ((LM_ERROR
,
29 // Indicates successful parsing of the command line
34 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
38 return consumer
.run (argc
, argv
);
41 // ****************************************************************
49 Consumer::run (int argc
, ACE_TCHAR
* argv
[])
53 // ORB initialization boiler plate...
55 CORBA::ORB_init (argc
, argv
);
57 if (parse_args (argc
, argv
) != 0)
60 // Do *NOT* make a copy because we don't want the ORB to outlive
61 // the Consumer object.
62 this->orb_
= orb
.in ();
64 CORBA::Object_var object
=
65 orb
->resolve_initial_references ("RootPOA");
66 PortableServer::POA_var poa
=
67 PortableServer::POA::_narrow (object
.in ());
68 PortableServer::POAManager_var poa_manager
=
69 poa
->the_POAManager ();
70 poa_manager
->activate ();
72 // Obtain the event channel, we could use a naming service, a
73 // command line argument or resolve_initial_references(), but
76 orb
->string_to_object (ior
);
78 CosEventChannelAdmin::EventChannel_var event_channel
=
79 CosEventChannelAdmin::EventChannel::_narrow (object
.in ());
81 // The canonical protocol to connect to the EC
82 CosEventChannelAdmin::ConsumerAdmin_var consumer_admin
=
83 event_channel
->for_consumers ();
85 CosEventChannelAdmin::ProxyPushSupplier_var supplier
=
86 consumer_admin
->obtain_push_supplier ();
88 CosEventComm::PushConsumer_var consumer
=
91 supplier
->connect_push_consumer (consumer
.in ());
93 // Wait for events, using work_pending()/perform_work() may help
94 // or using another thread, this example is too simple for that.
97 // We don't do any cleanup, it is hard to do it after shutdown,
98 // and would complicate the example; plus it is almost
99 // impossible to do cleanup after ORB->run() because the POA is
100 // in the holding state. Applications should use
101 // work_pending()/perform_work() to do more interesting stuff.
102 // Check the supplier for the proper way to do cleanup.
104 catch (const CORBA::Exception
& ex
)
106 ex
._tao_print_exception ("Consumer::run");
113 Consumer::push (const CORBA::Any
&)
115 this->event_count_
++;
116 if (this->event_count_
% 100 == 0)
118 ACE_DEBUG ((LM_DEBUG
,
119 "Consumer (%P|%t): %d events received\n",
120 this->event_count_
));
125 Consumer::disconnect_push_consumer ()
127 // In this example we shutdown the ORB when we disconnect from the
128 // EC (or rather the EC disconnects from us), but this doesn't have
129 // to be the case....
130 this->orb_
->shutdown (false);