Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / CosEvent / Basic / MT_Disconnect.cpp
blob3074ea3b24602e78d6cb7cf6d1e5e4a9c9c0e366
1 #include "MT_Disconnect.h"
2 #include "Counting_Consumer.h"
3 #include "Counting_Supplier.h"
5 #include "orbsvcs/CosEvent/CEC_EventChannel.h"
6 #include "orbsvcs/CosEvent/CEC_Default_Factory.h"
8 static void run_test (PortableServer::POA_ptr poa,
9 int use_callbacks);
11 int
12 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
14 TAO_CEC_Default_Factory::init_svcs ();
16 try
18 // ORB initialization boiler plate...
19 CORBA::ORB_var orb =
20 CORBA::ORB_init (argc, argv);
22 CORBA::Object_var object =
23 orb->resolve_initial_references ("RootPOA");
24 PortableServer::POA_var poa =
25 PortableServer::POA::_narrow (object.in ());
26 PortableServer::POAManager_var poa_manager =
27 poa->the_POAManager ();
28 poa_manager->activate ();
30 // ****************************************************************
32 run_test (poa.in (), 0);
34 run_test (poa.in (), 1);
36 // ****************************************************************
38 poa->destroy (true, true);
40 orb->destroy ();
42 catch (const CORBA::Exception& ex)
44 ex._tao_print_exception ("Service");
45 return 1;
47 return 0;
50 // ****************************************************************
52 void
53 deactivate_servant (PortableServer::Servant servant)
55 PortableServer::POA_var poa =
56 servant->_default_POA ();
57 PortableServer::ObjectId_var id =
58 poa->servant_to_id (servant);
59 poa->deactivate_object (id.in ());
62 void
63 run_test (PortableServer::POA_ptr poa,
64 int use_callbacks)
66 TAO_CEC_EventChannel_Attributes attributes (poa, poa);
67 attributes.disconnect_callbacks = use_callbacks;
69 TAO_CEC_EventChannel ec_impl (attributes);
70 ec_impl.activate ();
72 CosEventChannelAdmin::EventChannel_var event_channel =
73 ec_impl._this ();
75 MTD_Task task (event_channel.in (), use_callbacks);
77 if (task.activate (THR_BOUND|THR_NEW_LWP, 1) != 0)
79 ACE_ERROR ((LM_ERROR, "Cannot activate the tasks\n"));
82 // Wait for all the threads to complete and the return
83 ACE_Thread_Manager::instance ()->wait ();
85 event_channel->destroy ();
87 deactivate_servant (&ec_impl);
90 MTD_Task::MTD_Task (CosEventChannelAdmin::EventChannel_ptr ec,
91 int callbacks)
92 : event_channel (CosEventChannelAdmin::EventChannel::_duplicate (ec)),
93 use_callbacks (callbacks)
98 int
99 MTD_Task::svc ()
101 for (int i = 0; i < 10; ++i)
105 this->run_iteration ();
107 catch (const CORBA::Exception&)
109 return -1;
112 return 0;
115 void
116 MTD_Task::run_iteration ()
118 // Obtain the consumer admin..
119 CosEventChannelAdmin::ConsumerAdmin_var consumer_admin =
120 this->event_channel->for_consumers ();
122 // and the supplier admin..
123 CosEventChannelAdmin::SupplierAdmin_var supplier_admin =
124 this->event_channel->for_suppliers ();
126 // ****************************************************************
128 int iterations = 100;
130 CEC_Counting_Supplier supplier_0;
131 CEC_Counting_Supplier supplier_1;
132 CEC_Counting_Consumer consumer_0 ("Consumer/0");
133 CEC_Counting_Consumer consumer_1 ("Consumer/1");
135 for (int i = 0; i != iterations; ++i)
137 supplier_0.connect (supplier_admin.in ());
138 consumer_0.connect (consumer_admin.in ());
139 if (i % 2 == 1)
141 supplier_1.connect (supplier_admin.in ());
142 consumer_1.connect (consumer_admin.in ());
144 supplier_0.disconnect ();
145 consumer_0.disconnect ();
146 if (i % 2 == 1)
148 consumer_1.disconnect ();
149 supplier_1.disconnect ();
153 deactivate_servant (&supplier_0);
155 deactivate_servant (&consumer_0);
157 CORBA::ULong count_0 = 0;
158 CORBA::ULong count_1 = 0;
159 if (use_callbacks)
161 count_0 += iterations;
162 count_1 += iterations / 2;
165 if (consumer_0.disconnect_count != count_0)
166 ACE_ERROR ((LM_ERROR,
167 "ERROR: incorrect number of disconnect calls (%d/%d) for "
168 "consumer 0 (%d)\n",
169 consumer_0.disconnect_count, count_0,
170 use_callbacks));
171 if (supplier_0.disconnect_count != count_0)
172 ACE_ERROR ((LM_ERROR,
173 "ERROR: incorrect number of disconnect calls (%d/%d) for "
174 "supplier 0 (%d)\n",
175 supplier_0.disconnect_count, count_0,
176 use_callbacks));
178 if (consumer_1.disconnect_count != count_1)
179 ACE_ERROR ((LM_ERROR,
180 "ERROR: incorrect number of disconnect calls (%d/%d) for "
181 "consumer 1 (%d)\n",
182 consumer_1.disconnect_count, count_1,
183 use_callbacks));
184 if (supplier_1.disconnect_count != count_1)
185 ACE_ERROR ((LM_ERROR,
186 "ERROR: incorrect number of disconnect calls (%d/%d) for "
187 "supplier 1 (%d)\n",
188 supplier_1.disconnect_count, count_1,
189 use_callbacks));