Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / examples / CosEC / Simple / Supplier.cpp
blob72f499c239829110cd9058c1ce5cbf2310d4266e
1 #include "Supplier.h"
2 #include "orbsvcs/CosEventChannelAdminS.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/Get_Opt.h"
6 const ACE_TCHAR *ior = ACE_TEXT ("file://ec.ior");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'k':
18 ior = get_opts.opt_arg ();
19 break;
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "-k <ior> "
26 "\n",
27 argv [0]),
28 -1);
30 // Indicates successful parsing of the command line
31 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 Supplier supplier;
39 return supplier.run (argc, argv);
42 // ****************************************************************
44 Supplier::Supplier ()
48 int
49 Supplier::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 CORBA::Object_var object =
61 orb->resolve_initial_references ("RootPOA");
62 PortableServer::POA_var poa =
63 PortableServer::POA::_narrow (object.in ());
64 PortableServer::POAManager_var poa_manager =
65 poa->the_POAManager ();
66 poa_manager->activate ();
68 // Obtain the event channel, we could use a naming service, a
69 // command line argument or resolve_initial_references(), but
70 // this is simpler...
71 object =
72 orb->string_to_object (ior);
74 CosEventChannelAdmin::EventChannel_var event_channel =
75 CosEventChannelAdmin::EventChannel::_narrow (object.in ());
77 // The canonical protocol to connect to the EC
78 CosEventChannelAdmin::SupplierAdmin_var supplier_admin =
79 event_channel->for_suppliers ();
81 CosEventChannelAdmin::ProxyPushConsumer_var consumer =
82 supplier_admin->obtain_push_consumer ();
84 CosEventComm::PushSupplier_var supplier =
85 this->_this ();
87 consumer->connect_push_supplier (supplier.in ());
89 // Push the events...
90 ACE_Time_Value sleep_time (0, 10000); // 10 milliseconds
92 CORBA::Any event;
93 event <<= CORBA::ULong (10);
95 for (int i = 0; i != 2000; ++i)
97 consumer->push (event);
98 ACE_OS::sleep (sleep_time);
101 // Disconnect from the EC
102 consumer->disconnect_push_consumer ();
104 // Destroy the EC....
105 event_channel->destroy ();
107 // Deactivate this object...
108 PortableServer::ObjectId_var id =
109 poa->servant_to_id (this);
110 poa->deactivate_object (id.in ());
112 // Destroy the POA
113 poa->destroy (1, 0);
115 catch (const CORBA::Exception& ex)
117 ex._tao_print_exception ("Supplier::run");
118 return 1;
120 return 0;
123 void
124 Supplier::disconnect_push_supplier ()