summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Notify_EventChannelFactory_i.cpp
blob: 987efbe7cde8af1966e12d1e96b2ccf7b6c2cd2c (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
// $Id$

#include "Notify_EventChannelFactory_i.h"
#include "Notify_EventChannel_i.h"
#include "Notify_Channel_Objects_Factory.h"
#include "Notify_POA_Factory.h"
#include "Notify_Factory.h"
#include "Notify_FilterFactory_i.h"
#include "Notify_Event.h"

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

TAO_Notify_EventChannelFactory_i::TAO_Notify_EventChannelFactory_i (void)
{
}

TAO_Notify_EventChannelFactory_i::~TAO_Notify_EventChannelFactory_i (void)
{
  TAO_Notify_Factory::shutdown ();
}

CosNotifyChannelAdmin::EventChannelFactory_ptr
TAO_Notify_EventChannelFactory_i::create (PortableServer::POA_ptr default_POA, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_EventChannelFactory_i* channelfactory;
  ACE_NEW_THROW_EX (channelfactory,
                    TAO_Notify_EventChannelFactory_i (),
                    CORBA::NO_MEMORY ());
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::EventChannelFactory::_nil ());

  PortableServer::ServantBase_var channelfactory_var (channelfactory);

  channelfactory->init_i (default_POA, ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::EventChannelFactory::_nil ());

  CORBA::Object_var obj = channelfactory->poa_factory_->
    activate_object (channelfactory->my_POA_.in (),
                     channelfactory, ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::EventChannelFactory::_nil ());

  return CosNotifyChannelAdmin::EventChannelFactory
    ::_narrow (obj.in (), ACE_TRY_ENV);
}

void
TAO_Notify_EventChannelFactory_i::init_i (PortableServer::POA_ptr default_POA, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_Factory::init (ACE_TRY_ENV);
  ACE_CHECK;

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

  this->channel_objects_factory_ =
    TAO_Notify_Factory::get_channel_objects_factory ();

  this->poa_factory_ = TAO_Notify_Factory::get_poa_factory ();

  // The POA that we should activate the Event Channels in.
  this->ec_POA_ = this->poa_factory_->
    create_event_channel_POA (this->my_POA_.in (), ACE_TRY_ENV);
  ACE_CHECK;

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

  this->default_filter_factory_ =
    this->create_default_filter_factory_i (ACE_TRY_ENV);
}

CosNotifyChannelAdmin::EventChannelFactory_ptr
TAO_Notify_EventChannelFactory_i::get_ref (CORBA::Environment &ACE_TRY_ENV)
{
  return CosNotifyChannelAdmin::EventChannelFactory
    ::_narrow (this->poa_factory_->
               servant_to_reference (this->my_POA_.in (), this, ACE_TRY_ENV));
}

void
TAO_Notify_EventChannelFactory_i::event_channel_destroyed (CosNotifyChannelAdmin::ChannelID channel_id)
{
  ACE_DEBUG ((LM_DEBUG, "event_channel_destroyed %d\n", channel_id));
}

void TAO_Notify_EventChannelFactory_i::shutdown (CORBA::Environment &ACE_TRY_ENV, CORBA::Boolean destroy_children)
{
  if (destroy_children == 1)
    {
      this->poa_factory_->destroy_POA (this->ec_POA_.in (), ACE_TRY_ENV);

      this->poa_factory_->deactivate_object(this->default_filter_factory_.in (),
                                            this->my_POA_.in (),
                                            ACE_TRY_ENV);
    }
  // Deactivate ourselves.
  this->poa_factory_->deactivate_object (this,
                                         this->my_POA_.in (),
                                         ACE_TRY_ENV);
}

CosNotifyChannelAdmin::EventChannel_ptr
TAO_Notify_EventChannelFactory_i::create_channel(const CosNotification::QoSProperties& initial_qos,
                                                 const CosNotification::AdminProperties& initial_admin,
                                                 CosNotifyChannelAdmin::ChannelID_out ec_id,
                                                 CORBA::Environment &ACE_TRY_ENV
                                                 )
  ACE_THROW_SPEC ((
                   CORBA::SystemException,
                   CosNotification::UnsupportedQoS,
                   CosNotification::UnsupportedAdmin
                   ))
{
  TAO_Notify_EventChannel_i* channel =
    this->channel_objects_factory_->create_event_channel (this,
                                                          ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::EventChannel::_nil ());

  PortableServer::ServantBase_var channel_var (channel);

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

    ec_id = this->ec_ids_.get ();

    ACE_DEBUG ((LM_DEBUG, "event_channel created %d\n", ec_id));
  }

  channel->init (ec_id, initial_qos, initial_admin, this->my_POA_.in (), this->ec_POA_.in (),
                 ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::EventChannel::_nil ());

  CORBA::Object_var obj = this->poa_factory_->
    activate_object_with_id (ec_id, this->ec_POA_.in (), channel,
                             ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::EventChannel::_nil ());

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

CosNotifyChannelAdmin::ChannelIDSeq*
TAO_Notify_EventChannelFactory_i::get_all_channels (CORBA::Environment & ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException
                   ))
{
  ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0);

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

CosNotifyChannelAdmin::EventChannel_ptr
TAO_Notify_EventChannelFactory_i::get_event_channel (CosNotifyChannelAdmin::ChannelID id, CORBA::Environment & ACE_TRY_ENV)
  ACE_THROW_SPEC ((
                   CORBA::SystemException,
                   CosNotifyChannelAdmin::ChannelNotFound
                   ))
{
  CORBA::Object_var obj;

  ACE_TRY
    {
      obj = this->poa_factory_->id_to_reference (id, this->ec_POA_.in (),
                                                 ACE_TRY_ENV);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY // Translate any exception to "not found"
    {
      ACE_TRY_THROW (CosNotifyChannelAdmin::ChannelNotFound ());
    }
  ACE_ENDTRY;
  ACE_CHECK_RETURN (CosNotifyChannelAdmin::EventChannel::_nil ());

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

CosNotifyFilter::FilterFactory_ptr
TAO_Notify_EventChannelFactory_i::create_default_filter_factory_i (CORBA::Environment& ACE_TRY_ENV)
{
  TAO_Notify_FilterFactory_i* filterfactory =
    this->channel_objects_factory_->create_filter_factory (ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyFilter::FilterFactory::_nil ());

  PortableServer::ServantBase_var filterfactory_var (filterfactory);

  // Init goes here.
  // ACE_CHECK_RETURN (CosNotifyFilter::FilterFactory::_nil ());

  CORBA::Object_var obj =
    this->poa_factory_->activate_object (this->my_POA_.in (),
                                         filterfactory, ACE_TRY_ENV);
  ACE_CHECK_RETURN (CosNotifyFilter::FilterFactory::_nil ());

  return CosNotifyFilter::FilterFactory::_narrow (obj.in ());
}

CosNotifyFilter::FilterFactory_ptr
TAO_Notify_EventChannelFactory_i::get_default_filter_factory (void)
{
  return CosNotifyFilter::FilterFactory::
    _duplicate (this->default_filter_factory_.in ());
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class TAO_Notify_ID_Pool_Ex<CosNotifyChannelAdmin::ChannelID, CosNotifyChannelAdmin::ChannelIDSeq>;

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate TAO_Notify_ID_Pool_Ex<CosNotifyChannelAdmin::ChannelID, CosNotifyChannelAdmin::ChannelIDSeq>

#endif /*ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */