summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Notify_EventChannel_i.cpp
blob: c78f36407bf6dfd0057b91d8d12c4f43145af5c8 (plain)
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
// $Id$

#include "orbsvcs/ESF/ESF_Proxy_Collection.h"
#include "Notify_EventChannel_i.h"
#include "Notify_EventChannelFactory_i.h"
#include "Notify_SupplierAdmin_i.h"
#include "Notify_ConsumerAdmin_i.h"
#include "Notify_Event_Manager.h"
#include "Notify_Channel_Objects_Factory.h"
#include "Notify_POA_Factory.h"
#include "Notify_Factory.h"
#include "Notify_Event_Manager_Objects_Factory.h"
#include "Notify_Collection_Factory.h"
#include "Notify_AdminProperties.h"

ACE_RCSID(Notify, Notify_EventChannel_i, "$Id$")

TAO_Notify_EventChannel_i::TAO_Notify_EventChannel_i (TAO_Notify_EventChannelFactory_i* my_factory)
  :lock_ (0),
   destory_child_POAs_ (0),
   channel_factory_ (my_factory),
   channel_objects_factory_ (TAO_Notify_Factory::get_channel_objects_factory ()),
   poa_factory_ (TAO_Notify_Factory::get_poa_factory ()),
   event_manager_objects_factory_ (TAO_Notify_Factory::get_event_manager_objects_factory ()),
   default_op_ (CosNotifyChannelAdmin::OR_OP),
   default_id_ (0),
   event_listener_list_ (0)
{
  channel_factory_->_add_ref ();
}

// Implementation skeleton destructor
TAO_Notify_EventChannel_i::~TAO_Notify_EventChannel_i (void)
{
  ACE_DEBUG ((LM_DEBUG,"in EC dtor\n"));
  // Cleanup all resources..

  delete this->event_manager_;
  delete this->lock_;
  delete this->event_listener_list_;

  this->channel_factory_->event_channel_destroyed (this->channel_id_);
  channel_factory_->_remove_ref ();
}

void
TAO_Notify_EventChannel_i::init (CosNotifyChannelAdmin::ChannelID channel_id, const CosNotification::QoSProperties& initial_qos, const CosNotification::AdminProperties& initial_admin, PortableServer::POA_ptr default_POA, PortableServer::POA_ptr my_POA, CORBA::Environment &ACE_TRY_ENV)
{
  this->channel_id_ = channel_id;

  this->my_POA_ = PortableServer::POA::_duplicate (my_POA);
  this->default_POA_ = PortableServer::POA::_duplicate (default_POA);

  this->lock_ =
    this->channel_objects_factory_->create_event_channel_lock (ACE_TRY_ENV);
  ACE_CHECK;

  this->event_manager_ =
    this->event_manager_objects_factory_->create_event_manager (this, ACE_TRY_ENV);
  ACE_CHECK;

  this->event_manager_->init (ACE_TRY_ENV);
  ACE_CHECK;

  // try to set initial qos params
  this->set_qos (initial_qos, ACE_TRY_ENV);
  ACE_CHECK;

  // try to set initial admin params
  this->set_admin (initial_admin, ACE_TRY_ENV);
  ACE_CHECK;

  // Create the POA for the CA's
  this->CA_POA_ =
    this->poa_factory_->create_consumer_admin_POA (this->my_POA_.in (), channel_id,
                                                   ACE_TRY_ENV);
  ACE_CHECK;

  // Create the POA for the SA's
  this->SA_POA_ =
    this->poa_factory_->create_supplier_admin_POA (this->my_POA_.in (), channel_id,
                                                   ACE_TRY_ENV);
  ACE_CHECK;

  this->event_listener_list_ =
    TAO_Notify_Factory::get_collection_factory ()->create_event_listener_list (ACE_TRY_ENV);

  // Create the default Consumer Admin. Because the ID_Pool is being used
  // the first time here, it will generate the id 0.
  CosNotifyChannelAdmin::AdminID id_unused;

  CosNotifyChannelAdmin::ConsumerAdmin_var def_consumer_admin =
    this->new_for_consumers (default_op_, id_unused, ACE_TRY_ENV);
  ACE_CHECK;

  CosNotifyChannelAdmin::SupplierAdmin_var def_supplier_admin =
    this->new_for_suppliers (default_op_, id_unused, ACE_TRY_ENV);
  ACE_CHECK;
}

TAO_Notify_Event_Manager*
TAO_Notify_EventChannel_i::get_event_manager (void)
{
  return this->event_manager_;
}

void
TAO_Notify_EventChannel_i::consumer_admin_destroyed (CosNotifyChannelAdmin::AdminID /*CA_ID*/)
{
}

void
TAO_Notify_EventChannel_i::supplier_admin_destroyed (CosNotifyChannelAdmin::AdminID /*SA_ID*/)
{
}

PortableServer::POA_ptr
TAO_Notify_EventChannel_i::get_default_POA (void)
{
  return PortableServer::POA::_duplicate (this->default_POA_.in ());
}

CosNotifyChannelAdmin::EventChannel_ptr
TAO_Notify_EventChannel_i::get_ref (CORBA::Environment &ACE_TRY_ENV)
{
  CORBA::Object_var obj = this->poa_factory_->
    servant_to_reference (this->my_POA_.in (), this, ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::EventChannel::_nil ());

  return CosNotifyChannelAdmin::EventChannel::_narrow (obj.in ());
}


void
TAO_Notify_EventChannel_i::unregister_listener (TAO_Notify_EventListener* group_listener, CORBA::Environment &ACE_TRY_ENV)
{
  // UnRegister the group listener.
  this->event_listener_list_->disconnected (group_listener, ACE_TRY_ENV);
  ACE_CHECK;
}

void
TAO_Notify_EventChannel_i::destroy (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  this->event_manager_->shutdown (ACE_TRY_ENV);

  // Deactivate ourselves.
  this->poa_factory_->deactivate_object (this,
                                         this->my_POA_.in (),
                                         ACE_TRY_ENV);
  // shutdown consumer admins's.
  TAO_Notify_Shutdown_Worker shutdown_worker;

  this->event_listener_list_->for_each (&shutdown_worker, ACE_TRY_ENV);
  ACE_CHECK;

  // release all references.
  this->event_listener_list_->shutdown (ACE_TRY_ENV);

  // @@ TODO: We need a way to send shutdown messages to the proxy consumers too.
  // (event listeners are proxy suppliers or CA's in disguise)

  this->poa_factory_->destroy_POA (this->CA_POA_.in (),
                                   ACE_TRY_ENV);
  this->poa_factory_->destroy_POA (this->SA_POA_.in (),
                                   ACE_TRY_ENV);
}

CosNotifyChannelAdmin::EventChannelFactory_ptr
TAO_Notify_EventChannel_i::MyFactory (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return this->channel_factory_->get_ref (ACE_TRY_ENV);
}

CosNotifyChannelAdmin::ConsumerAdmin_ptr
TAO_Notify_EventChannel_i::default_consumer_admin (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  return this->get_consumeradmin (this->default_id_, ACE_TRY_ENV);
}

CosNotifyChannelAdmin::SupplierAdmin_ptr
TAO_Notify_EventChannel_i::default_supplier_admin (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  return this->get_supplieradmin (this->default_id_, ACE_TRY_ENV);
}

CosNotifyFilter::FilterFactory_ptr
TAO_Notify_EventChannel_i::default_filter_factory (CORBA::Environment &/*ACE_TRY_ENV*/)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  return this->channel_factory_->get_default_filter_factory ();
}

CosNotifyChannelAdmin::ConsumerAdmin_ptr
TAO_Notify_EventChannel_i::new_for_consumers (CosNotifyChannelAdmin::InterFilterGroupOperator op, CosNotifyChannelAdmin::AdminID_out id, CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  // @@ use auto_ptr
  TAO_Notify_ConsumerAdmin_i* consumer_admin =
    this->channel_objects_factory_->create_consumer_admin (this, ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::ConsumerAdmin::_nil ());

  PortableServer::ServantBase_var consumeradmin_var (consumer_admin);

  {
    ACE_GUARD_THROW_EX (ACE_Lock, ace_mon, *this->lock_,
                        CORBA::INTERNAL ());
    ACE_CHECK_RETURN (CosNotifyChannelAdmin::ConsumerAdmin::_nil ());

    id = this->consumer_admin_ids_.get ();
  }

  consumer_admin->init (id, op, this->CA_POA_.in (), ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::ConsumerAdmin::_nil ());

  CORBA::Object_var obj =
    this->poa_factory_->activate_object_with_id (id,
                                                 this->CA_POA_.in (),
                                                 consumer_admin,
                                                 ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::ConsumerAdmin::_nil ());

  // Register the group listener.
  this->event_listener_list_->connected (consumer_admin, ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::ConsumerAdmin::_nil ());

  return CosNotifyChannelAdmin::ConsumerAdmin::_narrow (obj.in ());
}

CosNotifyChannelAdmin::SupplierAdmin_ptr
TAO_Notify_EventChannel_i::new_for_suppliers (CosNotifyChannelAdmin::InterFilterGroupOperator op, CosNotifyChannelAdmin::AdminID_out id, CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  TAO_Notify_SupplierAdmin_i* supplieradmin =
    this->channel_objects_factory_->create_supplier_admin (this, ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::SupplierAdmin::_nil ());

  PortableServer::ServantBase_var supplieradmin_var (supplieradmin);

  {
    ACE_GUARD_THROW_EX (ACE_Lock, ace_mon, *this->lock_,
                        CORBA::INTERNAL ());
    id = this->supplier_admin_ids_.get ();
  }

  supplieradmin->init (id, op, this->SA_POA_.in (), ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::SupplierAdmin::_nil ());

  CORBA::Object_var obj = this->poa_factory_->
    activate_object_with_id (id,
                             this->SA_POA_.in (),
                             supplieradmin,
                             ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::SupplierAdmin::_nil ());

  return CosNotifyChannelAdmin::SupplierAdmin::_narrow (obj.in ());
}

CosNotifyChannelAdmin::ConsumerAdmin_ptr
TAO_Notify_EventChannel_i::get_consumeradmin (CosNotifyChannelAdmin::AdminID id, CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException,
                   CosNotifyChannelAdmin::AdminNotFound
                   ))
{
  CORBA::Object_var obj =
    this->poa_factory_->id_to_reference (id, this->CA_POA_.in (),
                                         ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::ConsumerAdmin::_nil ());

  return CosNotifyChannelAdmin::ConsumerAdmin::_narrow (obj.in ());
}

CosNotifyChannelAdmin::SupplierAdmin_ptr
TAO_Notify_EventChannel_i::get_supplieradmin (CosNotifyChannelAdmin::AdminID id, CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException,
                   CosNotifyChannelAdmin::AdminNotFound
                   ))
{
  CORBA::Object_var obj =
    this->poa_factory_->id_to_reference (id, this->SA_POA_.in (),
                                         ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::SupplierAdmin::_nil ());

  return CosNotifyChannelAdmin::SupplierAdmin::_narrow (obj.in ());
}

CosNotifyChannelAdmin::AdminIDSeq*
TAO_Notify_EventChannel_i::get_all_consumeradmins (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  return this->consumer_admin_ids_.get_sequence (ACE_TRY_ENV);
}

CosNotifyChannelAdmin::AdminIDSeq*
TAO_Notify_EventChannel_i::get_all_supplieradmins (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  ACE_GUARD_THROW_EX (ACE_Lock, ace_mon, *this->lock_,
                      CORBA::INTERNAL ());
  ACE_CHECK_RETURN (0);

  return this->supplier_admin_ids_.get_sequence (ACE_TRY_ENV);
}

CosNotification::QoSProperties*
TAO_Notify_EventChannel_i::get_qos (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  return this->qos_admin_.get_qos (ACE_TRY_ENV);
}

void
TAO_Notify_EventChannel_i::set_qos (const CosNotification::QoSProperties & qos,CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException,
                   CosNotification::UnsupportedQoS
                   ))
{
  this->qos_admin_.set_qos (qos, ACE_TRY_ENV);
}

void
TAO_Notify_EventChannel_i::validate_qos (const CosNotification::QoSProperties & required_qos, CosNotification::NamedPropertyRangeSeq_out available_qos, CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException,
                   CosNotification::UnsupportedQoS
                   ))
{
  this->qos_admin_.validate_qos (required_qos, available_qos, ACE_TRY_ENV);
}

CosNotification::AdminProperties*
TAO_Notify_EventChannel_i::get_admin (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  // Delegate to Event Manager.
  return this->event_manager_->admin_properties ()->get_admin (ACE_TRY_ENV);
}

void
TAO_Notify_EventChannel_i::set_admin (const CosNotification::AdminProperties & admin, CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException,
                   CosNotification::UnsupportedAdmin
                   ))
{
  this->event_manager_->admin_properties ()->set_admin (admin, ACE_TRY_ENV);
}

CosEventChannelAdmin::ConsumerAdmin_ptr
TAO_Notify_EventChannel_i::for_consumers (CORBA::Environment& ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  // There is no way to destroy CosEventChannelAdmin::ConsumerAdmin's
  // so we just return the default Consumer Admin here.
  // TODO: find a way to disable the destroy method in the default Admin.

  CORBA::Object_var obj =
    this->get_consumeradmin (this->default_id_, ACE_TRY_ENV);

  return CosEventChannelAdmin::ConsumerAdmin::_narrow (obj.in (),
                                                       ACE_TRY_ENV);
}

CosEventChannelAdmin::SupplierAdmin_ptr
TAO_Notify_EventChannel_i::for_suppliers (CORBA::Environment& ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  CORBA::Object_var obj =
    this->get_supplieradmin (this->default_id_, ACE_TRY_ENV);

  return CosEventChannelAdmin::SupplierAdmin::_narrow (obj.in (),
                                                       ACE_TRY_ENV);
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

template class TAO_Notify_ID_Pool_Ex<CosNotifyChannelAdmin::AdminID, CosNotifyChannelAdmin::AdminIDSeq>;
template class TAO_Notify_ID_Pool<CosNotifyChannelAdmin::AdminID>;

template class ACE_Unbounded_Set<CosNotifyChannelAdmin::AdminID>;
template class ACE_Unbounded_Set_Iterator<CosNotifyChannelAdmin::AdminID>;

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#pragma instantiate TAO_Notify_ID_Pool_Ex<CosNotifyChannelAdmin::AdminID, CosNotifyChannelAdmin::AdminIDSeq>;
#pragma instantiate TAO_Notify_ID_Pool<CosNotifyChannelAdmin::AdminID>

#pragma instantiate ACE_Unbounded_Set<CosNotifyChannelAdmin::AdminID>
#pragma instantiate ACE_Unbounded_Set_Iterator<CosNotifyChannelAdmin::AdminID>

#endif /*ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */