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
,
12 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
14 TAO_CEC_Default_Factory::init_svcs ();
18 // ORB initialization boiler plate...
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);
42 catch (const CORBA::Exception
& ex
)
44 ex
._tao_print_exception ("Service");
50 // ****************************************************************
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 ());
63 run_test (PortableServer::POA_ptr poa
,
66 TAO_CEC_EventChannel_Attributes
attributes (poa
, poa
);
67 attributes
.disconnect_callbacks
= use_callbacks
;
69 TAO_CEC_EventChannel
ec_impl (attributes
);
72 CosEventChannelAdmin::EventChannel_var event_channel
=
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
,
92 : event_channel (CosEventChannelAdmin::EventChannel::_duplicate (ec
)),
93 use_callbacks (callbacks
)
101 for (int i
= 0; i
< 10; ++i
)
105 this->run_iteration ();
107 catch (const CORBA::Exception
&)
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 ());
141 supplier_1
.connect (supplier_admin
.in ());
142 consumer_1
.connect (consumer_admin
.in ());
144 supplier_0
.disconnect ();
145 consumer_0
.disconnect ();
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;
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 "
169 consumer_0
.disconnect_count
, count_0
,
171 if (supplier_0
.disconnect_count
!= count_0
)
172 ACE_ERROR ((LM_ERROR
,
173 "ERROR: incorrect number of disconnect calls (%d/%d) for "
175 supplier_0
.disconnect_count
, count_0
,
178 if (consumer_1
.disconnect_count
!= count_1
)
179 ACE_ERROR ((LM_ERROR
,
180 "ERROR: incorrect number of disconnect calls (%d/%d) for "
182 consumer_1
.disconnect_count
, count_1
,
184 if (supplier_1
.disconnect_count
!= count_1
)
185 ACE_ERROR ((LM_ERROR
,
186 "ERROR: incorrect number of disconnect calls (%d/%d) for "
188 supplier_1
.disconnect_count
, count_1
,