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
|
// $Id$
#include "Counting_Consumer.h"
#include "Counting_Supplier.h"
#include "orbsvcs/CosEvent/CEC_EventChannel.h"
#include "orbsvcs/CosEvent/CEC_Default_Factory.h"
ACE_RCSID( CEC_Tests_Basic,
Shutdown,
"$Id$")
static void run_test (PortableServer::POA_ptr poa,
int with_callbacks);
int
main (int argc, char* argv[])
{
TAO_CEC_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 ());
}
static void
run_test (PortableServer::POA_ptr poa,
int with_callbacks)
{
TAO_CEC_EventChannel_Attributes attributes (poa,
poa);
attributes.disconnect_callbacks = with_callbacks;
TAO_CEC_EventChannel ec_impl (attributes);
ec_impl.activate ();
CosEventChannelAdmin::EventChannel_var event_channel =
ec_impl._this ();
// ****************************************************************
// Obtain the consumer admin..
CosEventChannelAdmin::ConsumerAdmin_var consumer_admin =
event_channel->for_consumers ();
// Obtain the supplier admin..
CosEventChannelAdmin::SupplierAdmin_var supplier_admin =
event_channel->for_suppliers ();
// ****************************************************************
CEC_Counting_Consumer **consumer = 0;
CEC_Counting_Supplier **supplier = 0;
const int n = 200;
ACE_NEW (consumer, CEC_Counting_Consumer*[n]);
ACE_NEW (supplier, CEC_Counting_Supplier*[n]);
int i = 0;
for (i = 0; i != n; ++i)
{
char consumer_name[64];
ACE_OS::sprintf (consumer_name, "Consumer/%4.4d", i);
ACE_NEW (consumer[i],
CEC_Counting_Consumer (consumer_name));
ACE_NEW (supplier[i], CEC_Counting_Supplier ());
}
for (i = 0; i != n; ++i)
{
consumer[i]->connect (consumer_admin.in ());
supplier[i]->connect (supplier_admin.in ());
}
// ****************************************************************
// Destroy the event channel, *before* disconnecting the
// clients.
event_channel->destroy ();
// ****************************************************************
for (i = 0; i != n; ++i)
{
if (consumer[i]->disconnect_count != 1)
ACE_DEBUG ((LM_DEBUG,
"ERRROR unexpected "
"disconnect count (%d) in Consumer/%04.4d\n",
consumer[i]->disconnect_count,
i));
if (supplier[i]->disconnect_count != 1)
ACE_DEBUG ((LM_DEBUG,
"ERRROR unexpected "
"disconnect count (%d) in Supplier/%04.4d\n",
supplier[i]->disconnect_count,
i));
}
// ****************************************************************
for (i = 0; i != n; ++i)
{
deactivate_servant (supplier[i]);
delete supplier[i];
deactivate_servant (consumer[i]);
delete consumer[i];
}
delete[] supplier;
delete[] consumer;
deactivate_servant (&ec_impl);
}
|