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
|
// $Id$
#include "Control.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"
ACE_RCSID(EC_Tests, Control, "$Id$")
const int event_type = 20;
const int event_source = 10;
int
main (int argc, char* argv[])
{
TAO_EC_Default_Factory::init_svcs ();
TAO_ENV_DECLARE_NEW_ENV;
ACE_TRY
{
// ORB initialization boiler plate...
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv, "" TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
CORBA::Object_var object =
orb->resolve_initial_references ("RootPOA" TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::POA_var poa =
PortableServer::POA::_narrow (object.in () TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::POAManager_var poa_manager =
poa->the_POAManager (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
poa_manager->activate (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// ****************************************************************
TAO_EC_Event_Channel_Attributes attributes (poa.in (),
poa.in ());
attributes.consumer_reconnect = 1;
attributes.supplier_reconnect = 1;
TAO_EC_Event_Channel ec_impl (attributes);
ec_impl.activate (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
RtecEventChannelAdmin::EventChannel_var event_channel =
ec_impl._this (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// ****************************************************************
// Obtain the consumer admin..
RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
event_channel->for_consumers (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// Obtain the supplier admin..
RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
event_channel->for_suppliers (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// ****************************************************************
EC_Counting_Supplier supplier0;
supplier0.connect (supplier_admin.in (),
event_source,
event_type,
event_source,
event_type
TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// ****************************************************************
Consumer consumer0 ("Consumer/0", 100);
// Create a consumer, intialize its RT_Info structures, and
// connnect to the event channel....
ACE_ConsumerQOS_Factory consumer_qos0;
consumer_qos0.start_disjunction_group ();
consumer_qos0.insert (event_source, event_type, 0);
consumer0.connect (consumer_admin.in (),
consumer_qos0.get_ConsumerQOS ()
TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
Consumer consumer1 ("Consumer/1", 200);
// Create a consumer, intialize its RT_Info structures, and
// connnect to the event channel....
consumer1.connect (consumer_admin.in (),
consumer_qos0.get_ConsumerQOS ()
TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// ****************************************************************
EC_Counting_Supplier_Task task0 (&supplier0);
task0.activate ();
// ****************************************************************
ACE_Time_Value tv (10, 0);
ACE_OS::sleep (tv);
task0.stop ();
ACE_Thread_Manager::instance ()->wait ();
// ****************************************************************
// Cleanup..
// The consumers should be disconnected already, but make sure
// that they did...
//consumer1.disconnect (TAO_ENV_SINGLE_ARG_PARAMETER);
//ACE_TRY_CHECK;
//consumer0.disconnect (TAO_ENV_SINGLE_ARG_PARAMETER);
//ACE_TRY_CHECK;
// ****************************************************************
supplier0.disconnect (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// ****************************************************************
event_channel->destroy (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// ****************************************************************
poa->destroy (1, 1 TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// ****************************************************************
ACE_DEBUG ((LM_DEBUG,
"Task 0 pushed %d events\n", task0.push_count ()));
ACE_DEBUG ((LM_DEBUG,
"Supplier 0 pushed %d events\n", supplier0.event_count));
consumer0.dump_results (100, 5);
consumer1.dump_results (200, 5);
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Service");
return 1;
}
ACE_ENDTRY;
return 0;
}
// ****************************************************************
Consumer::Consumer (const char* name,
int shutdown_count)
: EC_Counting_Consumer (name),
shutdown_count_ (shutdown_count)
{
}
void
Consumer::push (const RtecEventComm::EventSet& events
TAO_ENV_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException))
{
if (events.length () == 0)
{
ACE_DEBUG ((LM_DEBUG,
"%s (%P|%t) no events\n", this->name_));
return;
}
{
ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);
this->event_count++;
if (this->event_count != this->shutdown_count_)
return;
}
this->deactivate (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
}
// ****************************************************************
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
#elif defined(ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|