1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
// $Id$
#include "MT_Disconnect.h"
#include "Counting_Consumer.h"
#include "Counting_Supplier.h"
#include "orbsvcs/Time_Utilities.h"
#include "orbsvcs/Event_Utilities.h"
#include "orbsvcs/Event/EC_Event_Channel.h"
#include "orbsvcs/Event/EC_Default_Factory.h"
static void run_test (PortableServer::POA_ptr poa,
int use_callbacks);
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
TAO_EC_Default_Factory::init_svcs ();
try
{
// ORB initialization boiler plate...
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv);
CORBA::Object_var object =
orb->resolve_initial_references ("RootPOA");
PortableServer::POA_var poa =
PortableServer::POA::_narrow (object.in ());
PortableServer::POAManager_var poa_manager =
poa->the_POAManager ();
poa_manager->activate ();
// ****************************************************************
run_test (poa.in (), 0);
run_test (poa.in (), 1);
// ****************************************************************
poa->destroy (1, 1);
orb->destroy ();
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Service");
return 1;
}
return 0;
}
// ****************************************************************
void
deactivate_servant (PortableServer::Servant servant)
{
PortableServer::POA_var poa =
servant->_default_POA ();
PortableServer::ObjectId_var id =
poa->servant_to_id (servant);
poa->deactivate_object (id.in ());
}
void
run_test (PortableServer::POA_ptr poa,
int use_callbacks)
{
TAO_EC_Event_Channel_Attributes attributes (poa, poa);
attributes.disconnect_callbacks = use_callbacks;
TAO_EC_Event_Channel ec_impl (attributes);
ec_impl.activate ();
RtecEventChannelAdmin::EventChannel_var event_channel =
ec_impl._this ();
Task task (event_channel.in (), use_callbacks);
if (task.activate (THR_BOUND|THR_NEW_LWP, 1) != 0)
{
ACE_ERROR ((LM_ERROR, "Cannot activate the tasks\n"));
}
// Wait for all the threads to complete and the return
ACE_Thread_Manager::instance ()->wait ();
event_channel->destroy ();
deactivate_servant (&ec_impl);
}
Task::Task (RtecEventChannelAdmin::EventChannel_ptr ec,
int callbacks)
: event_channel (RtecEventChannelAdmin::EventChannel::_duplicate (ec)),
use_callbacks (callbacks)
{
}
int
Task::svc ()
{
for (int i = 0; i < 10; ++i)
{
try
{
this->run_iteration ();
}
catch (const CORBA::Exception&)
{
return -1;
}
}
return 0;
}
void
Task::run_iteration (void)
{
// Obtain the consumer admin..
RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
this->event_channel->for_consumers ();
// and the supplier admin..
RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
this->event_channel->for_suppliers ();
// ****************************************************************
int iterations = 100;
EC_Counting_Supplier supplier_0;
EC_Counting_Supplier supplier_1;
EC_Counting_Consumer consumer_0 ("Consumer/0");
EC_Counting_Consumer consumer_1 ("Consumer/1");
const int event_type = 20;
const int event_source = 10;
ACE_ConsumerQOS_Factory consumer_qos;
consumer_qos.start_disjunction_group ();
consumer_qos.insert (event_source, event_type, 0);
ACE_SupplierQOS_Factory supplier_qos;
supplier_qos.insert (event_source,
event_type,
0, 1);
for (int i = 0; i != iterations; ++i)
{
supplier_0.connect (supplier_admin.in (),
supplier_qos.get_SupplierQOS ());
consumer_0.connect (consumer_admin.in (),
consumer_qos.get_ConsumerQOS ());
if (i % 2 == 1)
{
supplier_1.connect (supplier_admin.in (),
supplier_qos.get_SupplierQOS ());
consumer_1.connect (consumer_admin.in (),
consumer_qos.get_ConsumerQOS ());
}
supplier_0.disconnect ();
consumer_0.disconnect ();
if (i % 2 == 1)
{
consumer_1.disconnect ();
supplier_1.disconnect ();
}
}
deactivate_servant (&supplier_0);
deactivate_servant (&consumer_0);
CORBA::ULong count_0 = 0;
CORBA::ULong count_1 = 0;
if (use_callbacks)
{
count_0 += iterations;
count_1 += iterations / 2;
}
if (consumer_0.disconnect_count != count_0)
ACE_ERROR ((LM_ERROR,
"ERROR: incorrect number of disconnect calls (%d/%d) for "
"consumer 0 (%d)\n",
consumer_0.disconnect_count, count_0,
use_callbacks));
if (supplier_0.disconnect_count != count_0)
ACE_ERROR ((LM_ERROR,
"ERROR: incorrect number of disconnect calls (%d/%d) for "
"supplier 0 (%d)\n",
supplier_0.disconnect_count, count_0,
use_callbacks));
if (consumer_1.disconnect_count != count_1)
ACE_ERROR ((LM_ERROR,
"ERROR: incorrect number of disconnect calls (%d/%d) for "
"consumer 1 (%d)\n",
consumer_1.disconnect_count, count_1,
use_callbacks));
if (supplier_1.disconnect_count != count_1)
ACE_ERROR ((LM_ERROR,
"ERROR: incorrect number of disconnect calls (%d/%d) for "
"supplier 1 (%d)\n",
supplier_1.disconnect_count, count_1,
use_callbacks));
}
|