Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / CosEvent / Basic / Shutdown.cpp
blob97f5c3e325f6cdec12aadf9d81a99880fedc9011
1 #include "Counting_Consumer.h"
2 #include "Counting_Supplier.h"
3 #include "orbsvcs/CosEvent/CEC_EventChannel.h"
4 #include "orbsvcs/CosEvent/CEC_Default_Factory.h"
6 static void run_test (PortableServer::POA_ptr poa,
7 int with_callbacks);
9 int
10 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
12 TAO_CEC_Default_Factory::init_svcs ();
14 try
16 // ORB initialization boiler plate...
17 CORBA::ORB_var orb =
18 CORBA::ORB_init (argc, argv);
20 CORBA::Object_var object =
21 orb->resolve_initial_references ("RootPOA");
22 PortableServer::POA_var poa =
23 PortableServer::POA::_narrow (object.in ());
24 PortableServer::POAManager_var poa_manager =
25 poa->the_POAManager ();
26 poa_manager->activate ();
28 // ****************************************************************
30 run_test (poa.in (), 0);
32 run_test (poa.in (), 1);
34 // ****************************************************************
36 poa->destroy (true, true);
38 orb->destroy ();
40 catch (const CORBA::Exception& ex)
42 ex._tao_print_exception ("Service");
43 return 1;
45 return 0;
48 void
49 deactivate_servant (PortableServer::Servant servant)
51 PortableServer::POA_var poa =
52 servant->_default_POA ();
53 PortableServer::ObjectId_var id =
54 poa->servant_to_id (servant);
55 poa->deactivate_object (id.in ());
58 static void
59 run_test (PortableServer::POA_ptr poa,
60 int with_callbacks)
62 TAO_CEC_EventChannel_Attributes attributes (poa,
63 poa);
64 attributes.disconnect_callbacks = with_callbacks;
66 TAO_CEC_EventChannel ec_impl (attributes);
67 ec_impl.activate ();
69 CosEventChannelAdmin::EventChannel_var event_channel =
70 ec_impl._this ();
72 // ****************************************************************
74 // Obtain the consumer admin..
75 CosEventChannelAdmin::ConsumerAdmin_var consumer_admin =
76 event_channel->for_consumers ();
78 // Obtain the supplier admin..
79 CosEventChannelAdmin::SupplierAdmin_var supplier_admin =
80 event_channel->for_suppliers ();
82 // ****************************************************************
84 CEC_Counting_Consumer **consumer = 0;
85 CEC_Counting_Supplier **supplier = 0;
87 const int n = 200;
88 ACE_NEW (consumer, CEC_Counting_Consumer*[n]);
89 ACE_NEW (supplier, CEC_Counting_Supplier*[n]);
91 int i = 0;
92 for (i = 0; i != n; ++i)
94 char consumer_name[64];
95 ACE_OS::sprintf (consumer_name, "Consumer/%4.4d", i);
96 ACE_NEW (consumer[i],
97 CEC_Counting_Consumer (consumer_name));
99 ACE_NEW (supplier[i], CEC_Counting_Supplier ());
102 for (i = 0; i != n; ++i)
104 consumer[i]->connect (consumer_admin.in ());
106 supplier[i]->connect (supplier_admin.in ());
109 // ****************************************************************
111 // Destroy the event channel, *before* disconnecting the
112 // clients.
113 event_channel->destroy ();
115 // ****************************************************************
117 for (i = 0; i != n; ++i)
119 if (consumer[i]->disconnect_count != 1)
120 ACE_DEBUG ((LM_DEBUG,
121 "ERRROR unexpected "
122 "disconnect count (%d) in Consumer/%04.4d\n",
123 consumer[i]->disconnect_count,
124 i));
126 if (supplier[i]->disconnect_count != 1)
127 ACE_DEBUG ((LM_DEBUG,
128 "ERRROR unexpected "
129 "disconnect count (%d) in Supplier/%04.4d\n",
130 supplier[i]->disconnect_count,
131 i));
134 // ****************************************************************
136 for (i = 0; i != n; ++i)
138 deactivate_servant (supplier[i]);
139 delete supplier[i];
141 deactivate_servant (consumer[i]);
142 delete consumer[i];
144 delete[] supplier;
145 delete[] consumer;
147 deactivate_servant (&ec_impl);