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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
|
// $Id$
#include "orbsvcs/Event/EC_Gateway.h"
#include "orbsvcs/Event_Utilities.h"
#include "orbsvcs/Time_Utilities.h"
ACE_RCSID(Event, EC_Gateway, "$Id$")
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_PushConsumer_Adapter<TAO_EC_Gateway_IIOP>;
template class ACE_PushSupplier_Adapter<TAO_EC_Gateway_IIOP>;
template class ACE_Map_Entry<RtecEventComm::EventSourceID,RtecEventChannelAdmin::ProxyPushConsumer_ptr>;
template class ACE_Map_Manager<RtecEventComm::EventSourceID,RtecEventChannelAdmin::ProxyPushConsumer_ptr,ACE_Null_Mutex>;
template class ACE_Map_Iterator_Base<RtecEventComm::EventSourceID,RtecEventChannelAdmin::ProxyPushConsumer_ptr,ACE_Null_Mutex>;
template class ACE_Map_Iterator<RtecEventComm::EventSourceID,RtecEventChannelAdmin::ProxyPushConsumer_ptr,ACE_Null_Mutex>;
template class ACE_Map_Reverse_Iterator<RtecEventComm::EventSourceID,RtecEventChannelAdmin::ProxyPushConsumer_ptr,ACE_Null_Mutex>;
#elif defined(ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_PushConsumer_Adapter<TAO_EC_Gateway_IIOP>
#pragma instantiate ACE_PushSupplier_Adapter<TAO_EC_Gateway_IIOP>
#pragma instantiate ACE_Map_Entry<RtecEventComm::EventSourceID,RtecEventChannelAdmin::ProxyPushConsumer_ptr>
#pragma instantiate ACE_Map_Manager<RtecEventComm::EventSourceID,RtecEventChannelAdmin::ProxyPushConsumer_ptr,ACE_Null_Mutex>
#pragma instantiate ACE_Map_Iterator_Base<RtecEventComm::EventSourceID,RtecEventChannelAdmin::ProxyPushConsumer_ptr,ACE_Null_Mutex>
#pragma instantiate ACE_Map_Iterator<RtecEventComm::EventSourceID,RtecEventChannelAdmin::ProxyPushConsumer_ptr,ACE_Null_Mutex>
#pragma instantiate ACE_Map_Reverse_Iterator<RtecEventComm::EventSourceID,RtecEventChannelAdmin::ProxyPushConsumer_ptr,ACE_Null_Mutex>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
TAO_EC_Gateway::TAO_EC_Gateway (void)
: handle_ (0)
{
}
TAO_EC_Gateway::~TAO_EC_Gateway (void)
{
}
void
TAO_EC_Gateway::observer_handle (RtecEventChannelAdmin::Observer_Handle h)
{
this->handle_ = h;
}
RtecEventChannelAdmin::Observer_Handle
TAO_EC_Gateway::observer_handle (void) const
{
return this->handle_;
}
TAO_EC_Gateway_IIOP::TAO_EC_Gateway_IIOP (void)
: busy_count_ (0),
update_posted_ (0),
rmt_info_ (0),
lcl_info_ (0),
consumer_ (this),
consumer_is_active_ (0),
supplier_ (this),
supplier_is_active_ (0)
{
}
TAO_EC_Gateway_IIOP::~TAO_EC_Gateway_IIOP (void)
{
}
void
TAO_EC_Gateway_IIOP::init (RtecEventChannelAdmin::EventChannel_ptr rmt_ec,
RtecEventChannelAdmin::EventChannel_ptr lcl_ec
TAO_ENV_ARG_DECL)
{
ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);
this->init_i (rmt_ec, lcl_ec TAO_ENV_ARG_PARAMETER);
}
void
TAO_EC_Gateway_IIOP::init_i (RtecEventChannelAdmin::EventChannel_ptr rmt_ec,
RtecEventChannelAdmin::EventChannel_ptr lcl_ec
TAO_ENV_ARG_DECL_NOT_USED)
{
if (!CORBA::is_nil (this->rmt_ec_.in ()))
return;
this->rmt_ec_ =
RtecEventChannelAdmin::EventChannel::_duplicate (rmt_ec);
this->lcl_ec_ =
RtecEventChannelAdmin::EventChannel::_duplicate (lcl_ec);
}
void
TAO_EC_Gateway_IIOP::close (TAO_ENV_SINGLE_ARG_DECL)
{
ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);
this->close_i (TAO_ENV_SINGLE_ARG_PARAMETER);
}
void
TAO_EC_Gateway_IIOP::close_i (TAO_ENV_SINGLE_ARG_DECL)
{
// ACE_DEBUG ((LM_DEBUG, "ECG (%t) Closing gateway\n"));
if (this->consumer_proxy_map_.current_size () > 0)
{
for (Consumer_Map_Iterator j = this->consumer_proxy_map_.begin ();
j != this->consumer_proxy_map_.end ();
++j)
{
RtecEventComm::PushConsumer_ptr consumer = (*j).int_id_;
if (CORBA::is_nil (consumer))
continue;
ACE_TRY
{
consumer->disconnect_push_consumer (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
}
ACE_ENDTRY;
CORBA::release (consumer);
}
// Remove all the elements on the map. Calling close() does not
// work because the map is left in an inconsistent state.
this->consumer_proxy_map_.open ();
}
if (!CORBA::is_nil (this->default_consumer_proxy_.in ()))
{
this->default_consumer_proxy_->disconnect_push_consumer (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->default_consumer_proxy_ =
RtecEventChannelAdmin::ProxyPushConsumer::_nil ();
}
if (!CORBA::is_nil (this->supplier_proxy_.in ()))
{
this->supplier_proxy_->disconnect_push_supplier (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->supplier_proxy_ =
RtecEventChannelAdmin::ProxyPushSupplier::_nil ();
}
}
void
TAO_EC_Gateway_IIOP::update_consumer (
const RtecEventChannelAdmin::ConsumerQOS& c_qos
TAO_ENV_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException))
{
if (c_qos.dependencies.length () <= 1)
return;
ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);
if (this->busy_count_ != 0)
{
this->update_posted_ = 1;
this->c_qos_ = c_qos;
return;
}
this->update_consumer_i (c_qos TAO_ENV_ARG_PARAMETER);
}
void
TAO_EC_Gateway_IIOP::update_consumer_i (
const RtecEventChannelAdmin::ConsumerQOS& c_qos
TAO_ENV_ARG_DECL)
{
this->close_i (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
if (CORBA::is_nil (this->lcl_ec_.in ())
|| CORBA::is_nil (this->rmt_ec_.in ()))
return;
// ACE_DEBUG ((LM_DEBUG, "ECG (%t) update_consumer_i \n"));
// = Connect as a supplier to the local EC
RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
this->lcl_ec_->for_suppliers (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// Change the RT_Info in the consumer QoS.
// On the same loop we discover the subscriptions by event source,
// and fill the consumer proxy map.
RtecEventChannelAdmin::ConsumerQOS sub = c_qos;
sub.is_gateway = 1;
for (CORBA::ULong i = 0; i < sub.dependencies.length (); ++i)
{
sub.dependencies[i].rt_info = this->rmt_info_;
RtecEventChannelAdmin::ProxyPushConsumer_ptr proxy = 0;
const RtecEventComm::EventHeader &h =
sub.dependencies[i].event.header;
RtecEventComm::EventSourceID sid = h.source;
//ACE_DEBUG ((LM_DEBUG,
// "ECG (%t) trying (%d,%d)\n",
// sid, h.type));
// Skip all subscriptions that do not require an specific source
// id.
if (sid == 0)
continue;
// Skip all the magic event types.
if (0 < h.type && h.type < ACE_ES_EVENT_UNDEFINED)
continue;
if (this->consumer_proxy_map_.find (sid, proxy) == -1)
{
//ACE_DEBUG ((LM_DEBUG,
// "ECG (%t) binding source %d\n",
// sid));
proxy = supplier_admin->obtain_push_consumer (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->consumer_proxy_map_.bind (sid, proxy);
}
}
//ACE_DEBUG ((LM_DEBUG,
// "ECG (%t) consumer map computed (%d entries)\n",
// this->consumer_proxy_map_.current_size ()));
if (this->consumer_proxy_map_.current_size () > 0)
{
this->supplier_is_active_ = 1;
// Obtain a reference to our supplier personality...
RtecEventComm::PushSupplier_var supplier_ref =
this->supplier_._this (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// For each subscription by source build the set of publications
// (they may several, by type, for instance) and connect to the
// consumer proxy.
for (Consumer_Map_Iterator j = this->consumer_proxy_map_.begin ();
j != this->consumer_proxy_map_.end ();
++j)
{
RtecEventChannelAdmin::SupplierQOS pub;
pub.publications.length (sub.dependencies.length () + 1);
pub.is_gateway = 1;
int c = 0;
RtecEventComm::EventSourceID sid = (*j).ext_id_;
for (CORBA::ULong k = 0; k < sub.dependencies.length (); ++k)
{
const RtecEventComm::EventHeader& h =
sub.dependencies[k].event.header;
if (h.source != sid
|| (0 < h.type
&& h.type < ACE_ES_EVENT_UNDEFINED))
continue;
pub.publications[c].event.header = h;
pub.publications[c].dependency_info.dependency_type =
RtecBase::TWO_WAY_CALL;
pub.publications[c].dependency_info.number_of_calls = 1;
pub.publications[c].dependency_info.rt_info = this->lcl_info_;
c++;
}
//ACE_DEBUG ((LM_DEBUG,
// "ECG (%t) supplier id %d has %d elements\n",
// sid, c));
if (c == 0)
continue;
pub.publications.length (c);
// ACE_DEBUG ((LM_DEBUG, "ECG (%P|%t) Gateway/Supplier "));
// ACE_SupplierQOS_Factory::debug (pub);
(*j).int_id_->connect_push_supplier (supplier_ref.in (),
pub
TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
}
}
// Also build the subscriptions that are *not* by source and connect
// to the default consumer proxy.
RtecEventChannelAdmin::SupplierQOS pub;
pub.publications.length (sub.dependencies.length () - 1);
pub.is_gateway = 1;
int c = 0;
for (CORBA::ULong k = 0; k < sub.dependencies.length (); ++k)
{
const RtecEventComm::EventHeader& h =
sub.dependencies[k].event.header;
RtecEventComm::EventSourceID sid = h.source;
if (sid != 0
|| (0 <= h.type
&& h.type < ACE_ES_EVENT_UNDEFINED))
continue;
pub.publications[c].event.header = h;
pub.publications[c].event.header.creation_time = ORBSVCS_Time::zero ();
pub.publications[c].dependency_info.dependency_type =
RtecBase::TWO_WAY_CALL;
pub.publications[c].dependency_info.number_of_calls = 1;
pub.publications[c].dependency_info.rt_info = this->lcl_info_;
c++;
}
if (c > 0)
{
this->supplier_is_active_ = 1;
// Obtain a reference to our supplier personality...
RtecEventComm::PushSupplier_var supplier_ref =
this->supplier_._this (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// Obtain the consumer....
this->default_consumer_proxy_ =
supplier_admin->obtain_push_consumer (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
pub.publications.length (c);
// ACE_DEBUG ((LM_DEBUG, "ECG (%t) Gateway/Supplier "));
// ACE_SupplierQOS_Factory::debug (pub);
this->default_consumer_proxy_->connect_push_supplier (supplier_ref.in (),
pub
TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
}
RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
this->rmt_ec_->for_consumers (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->supplier_proxy_ =
consumer_admin->obtain_push_supplier (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->consumer_is_active_ = 1;
RtecEventComm::PushConsumer_var consumer_ref =
this->consumer_._this (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// ACE_DEBUG ((LM_DEBUG, "ECG (%P|%t) Gateway/Consumer "));
// ACE_ConsumerQOS_Factory::debug (sub);
this->supplier_proxy_->connect_push_consumer (consumer_ref.in (),
sub
TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
}
void
TAO_EC_Gateway_IIOP::update_supplier (
const RtecEventChannelAdmin::SupplierQOS&
TAO_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((CORBA::SystemException))
{
// Do nothing...
}
void
TAO_EC_Gateway_IIOP::disconnect_push_consumer (TAO_ENV_SINGLE_ARG_DECL_NOT_USED)
{
// ACE_DEBUG ((LM_DEBUG,
// "ECG (%t): Supplier-consumer received "
// "disconnect from channel.\n"));
}
void
TAO_EC_Gateway_IIOP::disconnect_push_supplier (TAO_ENV_SINGLE_ARG_DECL_NOT_USED)
{
// ACE_DEBUG ((LM_DEBUG,
// "ECG (%t): Supplier received "
// "disconnect from channel.\n"));
}
void
TAO_EC_Gateway_IIOP::push (const RtecEventComm::EventSet &events
TAO_ENV_ARG_DECL)
{
// ACE_DEBUG ((LM_DEBUG, "TAO_EC_Gateway_IIOP::push (%P|%t) - \n"));
if (events.length () == 0)
{
// ACE_DEBUG ((LM_DEBUG, "no events\n"));
return;
}
{
ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);
this->busy_count_++;
}
// ACE_DEBUG ((LM_DEBUG, "ECG: %d event(s)\n", events.length ()));
// @@ TODO, there is an extra data copy here, we should do the event
// modification without it and only compact the necessary events.
RtecEventComm::EventSet out (1);
out.length (1);
for (CORBA::ULong i = 0; i < events.length (); ++i)
{
if (events[i].header.ttl == 0)
continue;
RtecEventChannelAdmin::ProxyPushConsumer_ptr proxy = 0;
RtecEventComm::EventSourceID sid = events[i].header.source;
if (sid == 0
|| this->consumer_proxy_map_.find (sid, proxy) == -1)
{
// If the source is not in our map we have to use the
// default consumer proxy.
proxy = this->default_consumer_proxy_.in ();
}
if (CORBA::is_nil (proxy))
continue;
out[0] = events[i];
out[0].header.ttl--;
// ACE_DEBUG ((LM_DEBUG, "ECG: event sent to proxy\n"));
proxy->push (out TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
}
{
ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);
this->busy_count_--;
if (this->busy_count_ == 0 && this->update_posted_ != 0)
{
this->update_posted_ = 0;
this->update_consumer_i (this->c_qos_ TAO_ENV_ARG_PARAMETER);
ACE_CHECK;
}
}
}
int
TAO_EC_Gateway_IIOP::shutdown (TAO_ENV_SINGLE_ARG_DECL)
{
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, -1);
this->close_i (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
if (this->supplier_is_active_)
{
PortableServer::POA_var poa =
this->supplier_._default_POA (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
PortableServer::ObjectId_var id =
poa->servant_to_id (&this->supplier_ TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
poa->deactivate_object (id.in () TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
this->supplier_is_active_ = 0;
}
if (this->consumer_is_active_)
{
PortableServer::POA_var poa =
this->consumer_._default_POA (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
PortableServer::ObjectId_var id =
poa->servant_to_id (&this->consumer_ TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
poa->deactivate_object (id.in () TAO_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
this->consumer_is_active_ = 0;
}
this->lcl_ec_ =
RtecEventChannelAdmin::EventChannel::_nil ();
this->rmt_ec_ =
RtecEventChannelAdmin::EventChannel::_nil ();
return 0;
}
|