summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Notify_Resource_Manager.cpp
blob: 1911c8b0569fe83a16ac3efd732add634aaa7780 (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
// $Id$
#include "Notify_Resource_Manager.h"
#include "Notify_EventChannelFactory_i.h"
#include "Notify_EventChannel_i.h"
#include "Notify_FilterFactory_i.h"
#include "Notify_ConsumerAdmin_i.h"
#include "Notify_SupplierAdmin_i.h"
#include "Notify_StructuredProxyPushSupplier_i.h"
#include "Notify_SequenceProxyPushSupplier_i.h"
#include "Notify_ProxyPushSupplier_i.h"
#include "Notify_StructuredProxyPushConsumer_i.h"
#include "Notify_SequenceProxyPushConsumer_i.h"
#include "Notify_ProxyPushConsumer_i.h"

TAO_Notify_Resource_Manager::TAO_Notify_Resource_Manager (PortableServer::POA_ptr default_POA)
  :default_POA_ (PortableServer::POA::_duplicate (default_POA))
{
  // No-Op.
}

TAO_Notify_Resource_Manager::~TAO_Notify_Resource_Manager ()
{
  // No-Op.
}

TAO_Notify_Resource_Manager*
TAO_Notify_Resource_Manager::create (PortableServer::POA_ptr default_POA, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_Resource_Manager* mgr;
  ACE_NEW_THROW_EX (mgr,
                    TAO_Notify_Resource_Manager (default_POA),
                    CORBA::NO_MEMORY ());
  return mgr;
}

TAO_Notify_EventChannel_i*
TAO_Notify_Resource_Manager::create_event_channel (CosNotifyChannelAdmin::EventChannelFactory_ptr parent, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_EventChannel_i* channel;
  ACE_NEW_THROW_EX (channel,
                    TAO_Notify_EventChannel_i (parent, this),
                    CORBA::NO_MEMORY ());
  return channel;
}

TAO_Notify_ConsumerAdmin_i*
TAO_Notify_Resource_Manager::create_consumer_admin (TAO_Notify_EventChannel_i* event_channel,
                                               CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_ConsumerAdmin_i* consumer_admin_i;
  ACE_NEW_THROW_EX (consumer_admin_i,
                    TAO_Notify_ConsumerAdmin_i (event_channel, this),
                    CORBA::NO_MEMORY ());
  return consumer_admin_i;
}

TAO_Notify_SupplierAdmin_i*
TAO_Notify_Resource_Manager::create_supplier_admin (TAO_Notify_EventChannel_i* event_channel,
                                                   CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_SupplierAdmin_i* supplier_admin_i;

  ACE_NEW_THROW_EX (supplier_admin_i,
                    TAO_Notify_SupplierAdmin_i (event_channel, this),
                    CORBA::NO_MEMORY ());
  return supplier_admin_i;
}

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

TAO_Notify_FilterFactory_i*
TAO_Notify_Resource_Manager::create_filter_factory (CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_FilterFactory_i* filterfactory;
  ACE_NEW_THROW_EX (filterfactory,
                    TAO_Notify_FilterFactory_i (),
                    CORBA::NO_MEMORY ());
  return filterfactory;
}

TAO_Notify_Event_Manager*
TAO_Notify_Resource_Manager::create_event_manager (TAO_Notify_EventChannel_i* channel, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_Event_Manager* event_manager;
  ACE_NEW_THROW_EX (event_manager,
                    TAO_Notify_Event_Manager (channel),
                    CORBA::NO_MEMORY ());
  return event_manager;
}

TAO_Notify_StructuredProxyPushSupplier_i*
TAO_Notify_Resource_Manager::create_struct_proxy_pushsupplier (TAO_Notify_ConsumerAdmin_i* parent, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_StructuredProxyPushSupplier_i* proxy;
  ACE_NEW_THROW_EX (proxy,
                    TAO_Notify_StructuredProxyPushSupplier_i (parent, this),
                    CORBA::NO_MEMORY ());
  return proxy;
}

TAO_Notify_SequenceProxyPushSupplier_i*
TAO_Notify_Resource_Manager::create_seq_proxy_pushsupplier (TAO_Notify_ConsumerAdmin_i* parent, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_SequenceProxyPushSupplier_i* proxy;
  ACE_NEW_THROW_EX (proxy,
                    TAO_Notify_SequenceProxyPushSupplier_i (parent, this),
                    CORBA::NO_MEMORY ());
  return proxy;
}

TAO_Notify_ProxyPushSupplier_i*
TAO_Notify_Resource_Manager::create_proxy_pushsupplier (TAO_Notify_ConsumerAdmin_i* parent, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_ProxyPushSupplier_i* proxy;
  ACE_NEW_THROW_EX (proxy,
                    TAO_Notify_ProxyPushSupplier_i (parent, this),
                    CORBA::NO_MEMORY ());
  return proxy;
}

TAO_Notify_StructuredProxyPushConsumer_i*
TAO_Notify_Resource_Manager::create_struct_proxy_pushconsumer (TAO_Notify_SupplierAdmin_i* parent, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_StructuredProxyPushConsumer_i* proxy;
  ACE_NEW_THROW_EX (proxy,
                    TAO_Notify_StructuredProxyPushConsumer_i (parent, this),
                    CORBA::NO_MEMORY ());
  return proxy;
}

TAO_Notify_SequenceProxyPushConsumer_i*
TAO_Notify_Resource_Manager::create_seq_proxy_pushconsumer (TAO_Notify_SupplierAdmin_i* parent, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_SequenceProxyPushConsumer_i* proxy;
  ACE_NEW_THROW_EX (proxy,
                    TAO_Notify_SequenceProxyPushConsumer_i (parent, this),
                    CORBA::NO_MEMORY ());
  return proxy;
}

TAO_Notify_ProxyPushConsumer_i*
TAO_Notify_Resource_Manager::create_proxy_pushconsumer (TAO_Notify_SupplierAdmin_i* parent, CORBA::Environment &ACE_TRY_ENV)
{
  TAO_Notify_ProxyPushConsumer_i* proxy;
  ACE_NEW_THROW_EX (proxy,
                    TAO_Notify_ProxyPushConsumer_i (parent, this),
                    CORBA::NO_MEMORY ());
  return proxy;
}

PortableServer::POA_ptr
TAO_Notify_Resource_Manager::create_event_channel_POA (PortableServer::POA_ptr parent_poa, CORBA::Environment &ACE_TRY_ENV)
{
  return this->create_generic_childPOA_i (parent_poa, ACE_TRY_ENV);
}

PortableServer::POA_ptr
TAO_Notify_Resource_Manager::create_supplier_admin_POA (PortableServer::POA_ptr parent_poa, CORBA::Environment &ACE_TRY_ENV)
{
  return this->create_generic_childPOA_i (parent_poa, ACE_TRY_ENV);
}

PortableServer::POA_ptr
TAO_Notify_Resource_Manager::create_consumer_admin_POA (PortableServer::POA_ptr parent_poa, CORBA::Environment &ACE_TRY_ENV)
{
  return this->create_generic_childPOA_i (parent_poa, ACE_TRY_ENV);
}

PortableServer::POA_ptr
TAO_Notify_Resource_Manager::create_proxy_pushconsumer_POA (PortableServer::POA_ptr parent_poa, CORBA::Environment &ACE_TRY_ENV)
{
  return this->create_generic_childPOA_i (parent_poa, ACE_TRY_ENV);
}

PortableServer::POA_ptr
TAO_Notify_Resource_Manager::create_proxy_pushsupplier_POA (PortableServer::POA_ptr parent_poa, CORBA::Environment &ACE_TRY_ENV)
{
  return this->create_generic_childPOA_i (parent_poa, ACE_TRY_ENV);
}

PortableServer::POA_ptr
TAO_Notify_Resource_Manager::create_generic_childPOA_i (PortableServer::POA_ptr poa, CORBA::Environment &ACE_TRY_ENV)
{
  // Create a UNIQUE_ID and USER_ID policy because we want the POA
  // to detect duplicates for us.
  PortableServer::IdUniquenessPolicy_var idpolicy =
    poa->create_id_uniqueness_policy (PortableServer::UNIQUE_ID,
                                      ACE_TRY_ENV);
  ACE_CHECK_RETURN (PortableServer::POA::_nil());

  PortableServer::IdAssignmentPolicy_var assignpolicy =
    poa->create_id_assignment_policy (PortableServer::USER_ID,
                                      ACE_TRY_ENV);
  ACE_CHECK_RETURN (PortableServer::POA::_nil ());

  PortableServer::POAManager_ptr manager =
    poa->the_POAManager (ACE_TRY_ENV);
  ACE_CHECK_RETURN (PortableServer::POA::_nil ());

  // Create a PolicyList
  CORBA::PolicyList policy_list;
  policy_list.length (2);
  policy_list [0] =
    PortableServer::IdUniquenessPolicy::_duplicate (idpolicy.in ());
  policy_list [1] =
    PortableServer::IdAssignmentPolicy::_duplicate (assignpolicy.in ());

  char child_poa_name[BUFSIZ];

  CORBA::Long poa_id = this->poa_ids_.get ();

  ACE_OS::sprintf (child_poa_name, "%d", poa_id);

  // Create the child POA.
  PortableServer::POA_var poa_ret = poa->create_POA (child_poa_name,
                                                     manager,
                                                     policy_list,
                                                     ACE_TRY_ENV);
  idpolicy->destroy ();
  assignpolicy->destroy ();

  ACE_CHECK_RETURN (PortableServer::POA::_nil ());

#if 0
  ACE_DEBUG ((LM_DEBUG, "created child poa %s", child_poa_name));
#endif
  this->poa_ids_.next (); // commit this id to the active list

  return poa_ret._retn ();
}

PortableServer::ObjectId *
TAO_Notify_Resource_Manager::long_to_ObjectId (const CORBA::Long id)
{
  // Size of string
  //
  // We DO NOT include the zero terminator, as this is simply an
  // artifact of the way strings are stored in C.
  //
  CORBA::ULong buffer_size = 4;

  // Create the buffer for the Id
  CORBA::Octet *buffer = PortableServer::ObjectId::allocbuf (buffer_size);

  // Copy the contents
  ACE_OS::memcpy (buffer, (char*)&id, buffer_size);

  // Create and return a new ID
  PortableServer::ObjectId *obj_id = 0;
  ACE_NEW_RETURN (obj_id,
                  PortableServer::ObjectId (buffer_size,
                                            buffer_size,
                                            buffer,
                                            1),
                  0);

  return obj_id;
}

CORBA::Object_ptr
TAO_Notify_Resource_Manager::activate_object_with_id (CORBA::Long id, PortableServer::POA_ptr poa, PortableServer::Servant servant, CORBA::Environment &ACE_TRY_ENV)
{
  // Convert CORBA::Long to ObjectId
  PortableServer::ObjectId_var oid =
    this->long_to_ObjectId (id);

  poa->activate_object_with_id (oid.in (),
                                servant,
                                ACE_TRY_ENV);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  return poa->id_to_reference (oid.in (),
                               ACE_TRY_ENV);
}

CORBA::Object_ptr
TAO_Notify_Resource_Manager::activate_object (PortableServer::POA_ptr poa, PortableServer::Servant servant, CORBA::Environment &ACE_TRY_ENV)
{
  poa->activate_object (servant, ACE_TRY_ENV);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  PortableServer::ObjectId_var oid = poa->servant_to_id (servant, ACE_TRY_ENV);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  return poa->id_to_reference (oid.in (), ACE_TRY_ENV);
}

CORBA::Object_ptr
TAO_Notify_Resource_Manager::servant_to_reference (PortableServer::POA_ptr poa, PortableServer::Servant servant, CORBA::Environment &ACE_TRY_ENV)
{
  PortableServer::ObjectId_var oid = poa->servant_to_id (servant, ACE_TRY_ENV);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  return poa->id_to_reference (oid.in (), ACE_TRY_ENV);
}

CORBA::Object_ptr
TAO_Notify_Resource_Manager::id_to_reference (CORBA::Long id, PortableServer::POA_ptr poa, CORBA::Environment &ACE_TRY_ENV)
{
  // Convert CORBA::Long to ObjectId
  PortableServer::ObjectId_var oid =
    this->long_to_ObjectId (id);

  return poa->id_to_reference (oid.in (),
                               ACE_TRY_ENV);
}

void
TAO_Notify_Resource_Manager::destroy_POA (PortableServer::POA_ptr poa, CORBA::Environment &ACE_TRY_ENV)
{
  if (!CORBA::is_nil (poa))
    poa->destroy (1,1,ACE_TRY_ENV);
}

void
TAO_Notify_Resource_Manager::deactivate_object (CORBA::Object_ptr obj, PortableServer::POA_ptr poa, CORBA::Environment &ACE_TRY_ENV)
{
  if (CORBA::is_nil (poa) || CORBA::is_nil (obj))
    return;

  PortableServer::ObjectId_var id =
    poa->reference_to_id (obj, ACE_TRY_ENV);
  ACE_CHECK;
  poa->deactivate_object (id.in (), ACE_TRY_ENV);
  ACE_CHECK;
}

void
TAO_Notify_Resource_Manager::deactivate_object (PortableServer::Servant servant, PortableServer::POA_ptr poa, CORBA::Environment &ACE_TRY_ENV)
{
  if (CORBA::is_nil (poa) || servant == 0)
    return;

  PortableServer::ObjectId_var id =
    poa->servant_to_id (servant, ACE_TRY_ENV);
  ACE_CHECK;
  poa->deactivate_object (id.in (), ACE_TRY_ENV);
  ACE_CHECK;
}

CORBA::Boolean
TAO_Notify_Resource_Manager::default_subscription_enabled (void)
{
  return 1; // @@ true for now, make this a user option
}