summaryrefslogtreecommitdiff
path: root/TAO/tao/ORBInitInfo.cpp
blob: ca9de009f2fdb178e487814b1b89d1ccc7d84532 (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
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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
// -*- C++ -*-
//
// $Id$

#include "ORBInitInfo.h"
#include "ORB_Core.h"
#include "StringSeqC.h"
#include "CodecFactory.h"

ACE_RCSID (TAO,
           ORBInitInfo,
           "$Id$")

#if !defined (__ACE_INLINE__)
#include "ORBInitInfo.inl"
#endif /* defined INLINE */

TAO_ORBInitInfo::TAO_ORBInitInfo (TAO_ORB_Core *orb_core,
                                  int  argc ,
                                  char *argv[])
  : orb_core_ (orb_core),
    argc_ (argc),
    argv_ (argv),
    codec_factory_ ()
{
}

TAO_ORBInitInfo::~TAO_ORBInitInfo (void)
{
}

CORBA::StringSeq *
TAO_ORBInitInfo::arguments (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  this->check_validity (ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  // In accordance with the C++ mapping for sequences, it is up to the
  // caller to deallocate storage for returned sequences.

  CORBA::StringSeq *args = 0;
  ACE_NEW_THROW_EX (args,
                    CORBA::StringSeq,
                    CORBA::NO_MEMORY (
                      CORBA_SystemException::_tao_minor_code (
                        TAO_DEFAULT_MINOR_CODE,
                        ENOMEM),
                      CORBA::COMPLETED_NO));
  ACE_CHECK_RETURN (0);

  CORBA::StringSeq_var safe_args (args);

  // Copy the argument vector to the string sequence.

  args->length (this->argc_);   // Not a problem if argc is zero.
  for (int i = 0; i < this->argc_; ++i)
    (*args)[i] = CORBA::string_dup (this->argv_[i]);

  return safe_args._retn ();
}

char *
TAO_ORBInitInfo::orb_id (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  this->check_validity (ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  // In accordance with the C++ mapping for strings, return a copy.

  return CORBA::string_dup (this->orb_core_->orbid ());
}

IOP::CodecFactory_ptr
TAO_ORBInitInfo::codec_factory (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  // The CodecFactory is stateless and reentrant, so share a single
  // instance between all ORBs.

  if (CORBA::is_nil (this->codec_factory_.in ()))
    {
      // A new instance must be allocated since the application code
      // may have registered an ORBInitializer that requires a
      // CodecFactory before the CodecFactory is itself registered
      // with the ORB.
      IOP::CodecFactory_ptr codec_factory;
      ACE_NEW_THROW_EX (codec_factory,
                        TAO_CodecFactory,
                          CORBA::NO_MEMORY (
                            CORBA::SystemException::_tao_minor_code (
                              TAO_DEFAULT_MINOR_CODE,
                              ENOMEM),
                            CORBA::COMPLETED_NO));
      ACE_CHECK;

      this->codec_factory_ = codec_factory;
    }

  return IOP::CodecFactory::_duplicate (this->codec_factory_.in ());
}

void
TAO_ORBInitInfo::register_initial_reference (
    const char * id,
    CORBA::Object_ptr obj,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ORBInitInfo::InvalidName))
{
  this->check_validity (ACE_TRY_ENV);
  ACE_CHECK;

  if (id == 0)
    ACE_THROW (PortableInterceptor::ORBInitInfo::InvalidName ());
  else if (ACE_OS_String::strlen (id) == 0)
    ACE_THROW (PortableInterceptor::ORBInitInfo::InvalidName ());


  TAO_Object_Ref_Table &table = this->orb_core_->object_ref_table ();

  table.register_initial_reference (id, obj, ACE_TRY_ENV);
  ACE_CHECK;
}

CORBA::Object_ptr
TAO_ORBInitInfo::resolve_initial_references (
    const char * id,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ORBInitInfo::InvalidName))
{
  this->check_validity (ACE_TRY_ENV);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  if (id == 0)
    ACE_THROW_RETURN (PortableInterceptor::ORBInitInfo::InvalidName (),
                      CORBA::Object::_nil ());
  else if (ACE_OS_String::strlen (id) == 0)
    ACE_THROW_RETURN (PortableInterceptor::ORBInitInfo::InvalidName (),
                      CORBA::Object::_nil ());

  // The ORB is practically fully initialized by the time this point
  // is reached so just use the ORB's resolve_initial_references()
  // mechanism.
  return
    this->orb_core_->orb ()->resolve_initial_references (id,
                                                         ACE_TRY_ENV);
}

void
TAO_ORBInitInfo::add_client_request_interceptor (
    PortableInterceptor::ClientRequestInterceptor_ptr interceptor,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ORBInitInfo::DuplicateName))
{
# if TAO_HAS_INTERCEPTORS == 1
  this->check_validity (ACE_TRY_ENV);
  ACE_CHECK;

  this->orb_core_->add_interceptor (interceptor,
                                    ACE_TRY_ENV);
#else
  ACE_UNUSED_ARG (interceptor);
  ACE_THROW (CORBA::NO_IMPLEMENT (
               CORBA_SystemException::_tao_minor_code (
                 TAO_DEFAULT_MINOR_CODE,
                 ENOTSUP),
               CORBA::COMPLETED_NO));
#endif  /* TAO_HAS_INTERCEPTORS == 1 */
}

void
TAO_ORBInitInfo::add_server_request_interceptor (
    PortableInterceptor::ServerRequestInterceptor_ptr interceptor,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ORBInitInfo::DuplicateName))
{
# if TAO_HAS_INTERCEPTORS == 1
  this->check_validity (ACE_TRY_ENV);
  ACE_CHECK;

  this->orb_core_->add_interceptor (interceptor,
                                    ACE_TRY_ENV);

#else
  ACE_UNUSED_ARG (interceptor);
  ACE_THROW (CORBA::NO_IMPLEMENT (
               CORBA_SystemException::_tao_minor_code (
                 TAO_DEFAULT_MINOR_CODE,
                 ENOTSUP),
               CORBA::COMPLETED_NO));
#endif  /* TAO_HAS_INTERCEPTORS == 1 */
}

void
TAO_ORBInitInfo::add_ior_interceptor (
    PortableInterceptor::IORInterceptor_ptr interceptor,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ORBInitInfo::DuplicateName))
{
  this->check_validity (ACE_TRY_ENV);
  ACE_CHECK;

  this->orb_core_->add_interceptor (interceptor,
                                    ACE_TRY_ENV);
}

PortableInterceptor::SlotId
TAO_ORBInitInfo::allocate_slot_id (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  this->check_validity (ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (
                      CORBA_SystemException::_tao_minor_code (
                        TAO_DEFAULT_MINOR_CODE,
                        ENOTSUP),
                      CORBA::COMPLETED_NO),
                    0);
}

void
TAO_ORBInitInfo::register_policy_factory (
    CORBA::PolicyType type,
    PortableInterceptor::PolicyFactory_ptr policy_factory,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  this->check_validity (ACE_TRY_ENV);
  ACE_CHECK;

  TAO_PolicyFactory_Registry *registry =
    this->orb_core_->policy_factory_registry ();

  registry->register_policy_factory (type,
                                     policy_factory,
                                     ACE_TRY_ENV);
}

size_t
TAO_ORBInitInfo::allocate_tss_slot_id (ACE_CLEANUP_FUNC cleanup,
                                       CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  this->check_validity (ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  size_t slot_id = 0;

  int result = this->orb_core_->add_tss_cleanup_func (cleanup,
                                                      slot_id);

  if (result != 0)
    ACE_THROW_RETURN (CORBA::INTERNAL (
                        CORBA_SystemException::_tao_minor_code (
                          TAO_DEFAULT_MINOR_CODE,
                          errno),
                        CORBA::COMPLETED_NO),
                      0);

  return slot_id;
}

void
TAO_ORBInitInfo::check_validity (CORBA_Environment &ACE_TRY_ENV)
{
  if (this->orb_core_ == 0)
    {
      // As defined by the Portable Interceptor specification, throw a
      // CORBA::OBJECT_NOT_EXIST exception after CORBA::ORB_init() has
      // completed.  CORBA::ORB_init() sets the ORB core pointer in
      // this instance to zero when it is done initializing the ORB,
      // which is why we base "existence" on the validity of the ORB
      // core pointer.
      ACE_THROW (CORBA::OBJECT_NOT_EXIST (TAO_DEFAULT_MINOR_CODE,
                                          CORBA::COMPLETED_NO));
    }
}

TAO_ORBInitInfo_ptr TAO_ORBInitInfo::_narrow (
    CORBA::Object_ptr obj,
    CORBA::Environment &ACE_TRY_ENV
  )
{
  return TAO_ORBInitInfo::_unchecked_narrow (obj, ACE_TRY_ENV);
}

TAO_ORBInitInfo_ptr TAO_ORBInitInfo::_unchecked_narrow (
    CORBA::Object_ptr obj,
    CORBA::Environment &
  )
{
  if (CORBA::is_nil (obj))
    return TAO_ORBInitInfo::_nil ();
  return
      ACE_reinterpret_cast
        (
          TAO_ORBInitInfo_ptr,
            obj->_tao_QueryInterface
              (
                ACE_reinterpret_cast
                  (
                    ptr_arith_t,
                    &TAO_ORBInitInfo::_narrow
                  )
              )
        );
}

TAO_ORBInitInfo_ptr
TAO_ORBInitInfo::_duplicate (TAO_ORBInitInfo_ptr obj)
{
  if (!CORBA::is_nil (obj))
    obj->_add_ref ();
  return obj;
}

void *TAO_ORBInitInfo::_tao_QueryInterface (ptr_arith_t type)
{
  void *retv = 0;
  if (type == ACE_reinterpret_cast
    (ptr_arith_t,
      &TAO_ORBInitInfo::_narrow))
    retv = ACE_reinterpret_cast (void*, this);
  else if (type == ACE_reinterpret_cast
    (ptr_arith_t,
      &::PortableInterceptor::ORBInitInfo::_narrow))
    retv = ACE_reinterpret_cast
      (
        void *,
        ACE_static_cast
          (
            PortableInterceptor::ORBInitInfo_ptr,
            this
          )
      );
  else if (type == ACE_reinterpret_cast (ptr_arith_t, &CORBA::Object::_narrow))
    retv = ACE_reinterpret_cast (void *,
      ACE_static_cast (CORBA::Object_ptr, this));

  if (retv)
    this->_add_ref ();
  return retv;
}

const char* TAO_ORBInitInfo::_interface_repository_id (void) const
{
  return "IDL:TAO_ORBInitInfo:1.0";
}

// *************************************************************
TAO_ORBInitInfo_ptr
tao_TAO_ORBInitInfo_duplicate (
    TAO_ORBInitInfo_ptr p
  )
{
  return TAO_ORBInitInfo::_duplicate (p);
}

void
tao_TAO_ORBInitInfo_release (
    TAO_ORBInitInfo_ptr p
  )
{
  CORBA::release (p);
}

TAO_ORBInitInfo_ptr
tao_TAO_ORBInitInfo_nil (
    void
  )
{
  return TAO_ORBInitInfo::_nil ();
}

TAO_ORBInitInfo_ptr
tao_TAO_ORBInitInfo_narrow (
    CORBA::Object *p,
    CORBA::Environment &ACE_TRY_ENV
  )
{
  return TAO_ORBInitInfo::_narrow (p, ACE_TRY_ENV);
}

CORBA::Object *
tao_TAO_ORBInitInfo_upcast (
    void *src
  )
{
  TAO_ORBInitInfo **tmp =
    ACE_static_cast (TAO_ORBInitInfo **, src);
  return *tmp;
}

// *************************************************************

// *************************************************************
// Operations for class TAO_ORBInitInfo_var
// *************************************************************

TAO_ORBInitInfo_var::TAO_ORBInitInfo_var (void) // default constructor
  : ptr_ (TAO_ORBInitInfo::_nil ())
{}

::TAO_ORBInitInfo_ptr
TAO_ORBInitInfo_var::ptr (void) const
{
  return this->ptr_;
}

TAO_ORBInitInfo_var::TAO_ORBInitInfo_var (const ::TAO_ORBInitInfo_var &p)
  : TAO_Base_var (),
    ptr_ (TAO_ORBInitInfo::_duplicate (p.ptr ()))
{}

TAO_ORBInitInfo_var::~TAO_ORBInitInfo_var (void) // destructor
{
  CORBA::release (this->ptr_);
}

TAO_ORBInitInfo_var &
TAO_ORBInitInfo_var::operator= (TAO_ORBInitInfo_ptr p)
{
  CORBA::release (this->ptr_);
  this->ptr_ = p;
  return *this;
}

TAO_ORBInitInfo_var &
TAO_ORBInitInfo_var::operator= (const ::TAO_ORBInitInfo_var &p)
{
  if (this != &p)
  {
    CORBA::release (this->ptr_);
    this->ptr_ = ::TAO_ORBInitInfo::_duplicate (p.ptr ());
  }
  return *this;
}

TAO_ORBInitInfo_var::operator const ::TAO_ORBInitInfo_ptr &() const
{
  return this->ptr_;
}

TAO_ORBInitInfo_var::operator ::TAO_ORBInitInfo_ptr &()
{
  return this->ptr_;
}

TAO_ORBInitInfo_ptr
TAO_ORBInitInfo_var::operator-> (void) const
{
  return this->ptr_;
}

TAO_ORBInitInfo_ptr
TAO_ORBInitInfo_var::in (void) const
{
  return this->ptr_;
}

TAO_ORBInitInfo_ptr &
TAO_ORBInitInfo_var::inout (void)
{
  return this->ptr_;
}

TAO_ORBInitInfo_ptr &
TAO_ORBInitInfo_var::out (void)
{
  CORBA::release (this->ptr_);
  this->ptr_ = ::TAO_ORBInitInfo::_nil ();
  return this->ptr_;
}

TAO_ORBInitInfo_ptr
TAO_ORBInitInfo_var::_retn (void)
{
  // yield ownership of managed obj reference
  ::TAO_ORBInitInfo_ptr val = this->ptr_;
  this->ptr_ = ::TAO_ORBInitInfo::_nil ();
  return val;
}

TAO_ORBInitInfo_ptr
TAO_ORBInitInfo_var::duplicate (TAO_ORBInitInfo_ptr p)
{
  return ::TAO_ORBInitInfo::_duplicate (p);
}

void
TAO_ORBInitInfo_var::release (TAO_ORBInitInfo_ptr p)
{
  CORBA::release (p);
}

TAO_ORBInitInfo_ptr
TAO_ORBInitInfo_var::nil (void)
{
  return ::TAO_ORBInitInfo::_nil ();
}

TAO_ORBInitInfo_ptr
TAO_ORBInitInfo_var::narrow (
    CORBA::Object *p,
    CORBA::Environment &ACE_TRY_ENV
  )
{
  return ::TAO_ORBInitInfo::_narrow (p, ACE_TRY_ENV);
}

CORBA::Object *
TAO_ORBInitInfo_var::upcast (void *src)
{
  TAO_ORBInitInfo **tmp =
    ACE_static_cast (TAO_ORBInitInfo **, src);
  return *tmp;
}