Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / examples / CosEC / Simple / Consumer.cpp
bloba3b3097121aeb1b309569ead14fe757ab3a86c5f
1 #include "Consumer.h"
2 #include "orbsvcs/CosEventChannelAdminS.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR *ior = ACE_TEXT ("file://ec.ior");
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'k':
17 ior = get_opts.opt_arg ();
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-k <ior> "
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 int
34 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
36 Consumer consumer;
38 return consumer.run (argc, argv);
41 // ****************************************************************
43 Consumer::Consumer ()
44 : event_count_ (0)
48 int
49 Consumer::run (int argc, ACE_TCHAR* argv[])
51 try
53 // ORB initialization boiler plate...
54 CORBA::ORB_var orb =
55 CORBA::ORB_init (argc, argv);
57 if (parse_args (argc, argv) != 0)
58 return 1;
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
74 // this is simpler...
75 object =
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 =
89 this->_this ();
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.
95 orb->run ();
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");
107 return 1;
109 return 0;
112 void
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_));
124 void
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);