summaryrefslogtreecommitdiff
path: root/TAO/tao/Object.cpp
blob: caba2a873e8dbc9b11c9225406920d149b9a6e48 (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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
// @(#) $Id$
//
// Copyright 1994-1995 by Sun Microsystems Inc.
// All Rights Reserved
//
// ORB:         CORBA_Object operations

#include "tao/Object.h"
#include "tao/Object_Adapter.h"
#include "tao/Stub.h"
#include "tao/Servant_Base.h"
#include "tao/Request.h"
#include "tao/ORB_Core.h"
#include "tao/Invocation.h"
#include "tao/Connector_Registry.h"
#include "tao/debug.h"

#if (TAO_HAS_INTERFACE_REPOSITORY == 1)
#include "tao/InterfaceC.h"
#endif  /* TAO_HAS_INTERFACE_REPOSITORY == 1 */

#if !defined (__ACE_INLINE__)
# include "tao/Object.i"
#endif /* ! __ACE_INLINE__ */

ACE_RCSID(tao, Object, "$Id$")

CORBA_Object::~CORBA_Object (void)
{
  if (this->protocol_proxy_)
    this->protocol_proxy_->_decr_refcnt ();
}

CORBA_Object::CORBA_Object (TAO_Stub *protocol_proxy,
                            TAO_ServantBase *servant,
                            CORBA::Boolean collocated)
  : servant_ (servant),
    is_collocated_ (collocated),
    is_local_ (0),
    protocol_proxy_ (protocol_proxy),
    refcount_ (1),
    refcount_lock_ ()
{
  // Notice that the refcount_ above is initialized to 1 because
  // the semantics of CORBA Objects are such that obtaining one
  // implicitly takes a reference.
}

void
CORBA_Object::_add_ref (void)
{
  this->_incr_refcnt ();
}

void
CORBA_Object::_remove_ref (void)
{
  this->_decr_refcnt ();
}

void
CORBA_Object::_tao_any_destructor (void *x)
{
  CORBA_Object_ptr tmp = ACE_static_cast(CORBA_Object_ptr,x);
  CORBA::release (tmp);
}

// IS_A ... ask the object if it's an instance of the type whose
// logical type ID is passed as a parameter.

CORBA::Boolean
CORBA_Object::_is_a (const CORBA::Char *type_id,
                     CORBA::Environment &ACE_TRY_ENV)
{
  // NOTE: if istub->type_id is nonzero and we have local knowledge of
  // it, we can answer this question without a costly remote call.
  //
  // That "local knowledge" could come from stubs or skeletons linked
  // into this process in the best case, or a "near" repository in a
  // slightly worse case.  Or in a trivial case, if the ID being asked
  // about is the ID we have recorded, we don't need to ask about the
  // inheritance relationships at all!
  //
  // In real systems having local knowledge will be common, though as
  // the systems built atop ORBs become richer it'll also become
  // common to have the "real type ID" not be directly understood
  // because it's more deeply derived than any locally known types.
  //
  // XXX if type_id is that of CORBA_Object, "yes, we comply" :-)

  if (this->_stubobj ()->type_id.in () != 0
      && ACE_OS::strcmp (type_id,
                         this->_stubobj ()->type_id.in ()) == 0)
    return 1;

  // If the object is collocated then try locally....
  if (this->is_collocated_)
    {
      // Which collocation strategy should we use?
      if (this->protocol_proxy_ != 0 &&
          this->protocol_proxy_->servant_orb_var ()->orb_core ()
          ->get_collocation_strategy () == TAO_ORB_Core::THRU_POA)
        {
          TAO_Object_Adapter::Servant_Upcall servant_upcall
            (*this->_stubobj ()->servant_orb_var ()->orb_core ()
             ->object_adapter ());
          servant_upcall.prepare_for_upcall (this->_object_key (),
                                             "_is_a",
                                             ACE_TRY_ENV);
          ACE_CHECK_RETURN (0);
          return servant_upcall.servant ()->_is_a (type_id, ACE_TRY_ENV);
        }

      // Direct collocation strategy is used.
      if (this->servant_ != 0)
        return this->servant_->_is_a (type_id, ACE_TRY_ENV);
    }

  CORBA::Boolean _tao_retval = 0;

  TAO_Stub *istub = this->_stubobj ();
  if (istub == 0)
    ACE_THROW_RETURN (CORBA::INTERNAL (
                        CORBA_SystemException::_tao_minor_code (
                          TAO_DEFAULT_MINOR_CODE,
                          EINVAL),
                        CORBA::COMPLETED_NO),
                      _tao_retval);


  TAO_GIOP_Twoway_Invocation _tao_call (
      istub,
      "_is_a",
      5,
      istub->orb_core ()
    );


  // Loop until we succeed or we raise an exception.
  // @@ Nanbor: Do we still need to clear the environment variable?
  //  ACE_TRY_ENV.clear ();
  for (;;)
    {
      _tao_call.start (ACE_TRY_ENV);
      ACE_CHECK_RETURN (_tao_retval);

      CORBA::Short flag = TAO_TWOWAY_RESPONSE_FLAG;

      _tao_call.prepare_header (ACE_static_cast (CORBA::Octet, flag),
                               ACE_TRY_ENV);
      ACE_CHECK_RETURN (_tao_retval);

      TAO_OutputCDR &_tao_out = _tao_call.out_stream ();
      if (!(
          (_tao_out << type_id)
      ))
        ACE_THROW_RETURN (CORBA::MARSHAL (), _tao_retval);

      int _invoke_status =
        _tao_call.invoke (0, 0, ACE_TRY_ENV);
      ACE_CHECK_RETURN (_tao_retval);

      if (_invoke_status == TAO_INVOKE_RESTART)
        continue;
      // if (_invoke_status == TAO_INVOKE_EXCEPTION)
        // cannot happen
      if (_invoke_status != TAO_INVOKE_OK)
      {
        ACE_THROW_RETURN (CORBA::UNKNOWN (TAO_DEFAULT_MINOR_CODE,
                                          CORBA::COMPLETED_YES),
                          _tao_retval);

      }
      break;
    }
  TAO_InputCDR &_tao_in = _tao_call.inp_stream ();
  if (!(_tao_in >> CORBA::Any::to_boolean (_tao_retval)))
    ACE_THROW_RETURN (CORBA::MARSHAL (TAO_DEFAULT_MINOR_CODE,
                                      CORBA::COMPLETED_YES),
                      _tao_retval);
  return _tao_retval;
}

const char*
CORBA_Object::_interface_repository_id (void) const
{
  return "IDL:omg.org/CORBA/Object:1.0";
}

TAO_ServantBase *
CORBA_Object::_servant (void) const
{
  return this->servant_;
}

CORBA::Boolean
CORBA_Object::_is_collocated (void) const
{
  return this->is_collocated_;
}

CORBA::Boolean
CORBA_Object::_is_local (void) const
{
  return this->is_local_;
}

// Quickly hash an object reference's representation data.  Used to
// create hash tables.

CORBA::ULong
CORBA_Object::_hash (CORBA::ULong maximum,
                     CORBA::Environment &ACE_TRY_ENV)
{
  if (this->protocol_proxy_ != 0)
    return this->protocol_proxy_->hash (maximum, ACE_TRY_ENV);
  else
    // @@ I really don't know how to support this for
    //    a locality constrained object.  -- nw.
    ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0);
}

// Compare two object references to see if they point to the same
// object.  Used in linear searches, as in hash buckets.
//
// XXX would be useful to also have a trivalued comparison predicate,
// such as strcmp(), to allow more comparison algorithms.

CORBA::Boolean
CORBA_Object::_is_equivalent (CORBA_Object_ptr other_obj,
                              CORBA::Environment &)
    ACE_THROW_SPEC (())
{
  if (other_obj == this)
    {
      return 1;
    }

  if (this->protocol_proxy_ != 0)
    return this->protocol_proxy_->is_equivalent (other_obj);
  else
    return this->servant_ == other_obj->servant_;
}

// TAO's extensions

TAO_ObjectKey *
CORBA::Object::_key (CORBA::Environment &ACE_TRY_ENV)
{
  if (this->_stubobj () && this->_stubobj ()->profile_in_use ())
    return this->_stubobj ()->profile_in_use ()->_key ();

  if (TAO_debug_level > 2)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("TAO (%P|%t) Null object key return from ")
                ACE_TEXT ("profile in use\n")));

  ACE_THROW_RETURN (CORBA::INTERNAL (
                      CORBA_SystemException::_tao_minor_code (
                        TAO_DEFAULT_MINOR_CODE,
                        EINVAL),
                      CORBA::COMPLETED_NO),
                    0);
}

const TAO_ObjectKey &
CORBA::Object::_object_key (void)
{
  return this->_stubobj ()->profile_in_use ()->object_key ();
}

void *
CORBA::Object::_tao_QueryInterface (ptr_arith_t type)
{
  void *retv = 0;

  if (type == ACE_reinterpret_cast (ptr_arith_t,
                                    &CORBA::Object::_narrow))
    retv = ACE_reinterpret_cast (void *, this);

  if (retv)
    this->_add_ref ();

  return 0;
}

// @@ This doesn't seemed to be used anyplace! It should go away!! FRED
void
CORBA::Object::_use_locate_requests (CORBA::Boolean use_it)
{
  if ( this->_stubobj () )
    this->_stubobj ()->use_locate_requests (use_it);

  return;
}

#if (TAO_HAS_MINIMUM_CORBA == 0)

// NON_EXISTENT ... send a simple call to the object, which will
// either elicit a FALSE response or a OBJECT_NOT_EXIST exception.  In
// the latter case, return FALSE.

CORBA::Boolean
CORBA_Object::_non_existent (CORBA::Environment &ACE_TRY_ENV)
{
  CORBA::Boolean _tao_retval = 0;

  ACE_TRY
    {
      // If the object is collocated then try locally....
      if (this->is_collocated_)
        {
          // Which collocation strategy should we use?
          if (this->protocol_proxy_ != 0 &&
              this->protocol_proxy_->servant_orb_var ()->orb_core ()
              ->get_collocation_strategy () == TAO_ORB_Core::THRU_POA)
            {
              TAO_Object_Adapter::Servant_Upcall servant_upcall
                (*this->_stubobj ()->servant_orb_var ()->orb_core ()->object_adapter ());
              servant_upcall.prepare_for_upcall (this->_object_key (),
                                                 "_non_existent",
                                                 ACE_TRY_ENV);
              ACE_TRY_CHECK;
              return servant_upcall.servant ()->_non_existent (ACE_TRY_ENV);
            }

          // Direct collocation strategy is used.
          if (this->servant_ != 0)
            return this->servant_->_non_existent (ACE_TRY_ENV);
        }

      // Must catch exceptions, if the server raises a
      // CORBA::OBJECT_NOT_EXIST then we must return 1, instead of
      // propagating the exception.
      TAO_Stub *istub = this->_stubobj ();
      if (istub == 0)
        ACE_THROW_RETURN (CORBA::INTERNAL (
                            CORBA_SystemException::_tao_minor_code (
                              TAO_DEFAULT_MINOR_CODE,
                              EINVAL),
                            CORBA::COMPLETED_NO),
                          _tao_retval);


      TAO_GIOP_Twoway_Invocation _tao_call (
                istub,
          "_non_existent",
          13,
          istub->orb_core ()
        );


      // ACE_TRY_ENV.clear ();
      for (;;)
        {
          _tao_call.start (ACE_TRY_ENV);
          ACE_TRY_CHECK;

          CORBA::Short flag = TAO_TWOWAY_RESPONSE_FLAG;

          _tao_call.prepare_header (ACE_static_cast (CORBA::Octet, flag),
                                    ACE_TRY_ENV);
          ACE_TRY_CHECK;

          int _invoke_status =
            _tao_call.invoke (0, 0, ACE_TRY_ENV);
          ACE_TRY_CHECK;

          if (_invoke_status == TAO_INVOKE_RESTART)
            continue;
          ACE_ASSERT (_invoke_status != TAO_INVOKE_EXCEPTION);
          if (_invoke_status != TAO_INVOKE_OK)
            {
              ACE_THROW_RETURN (CORBA::UNKNOWN (TAO_DEFAULT_MINOR_CODE,
                                                CORBA::COMPLETED_YES),
                                _tao_retval);
            }
          break;
        }
      TAO_InputCDR &_tao_in = _tao_call.inp_stream ();
      if (!(
          (_tao_in >> CORBA::Any::to_boolean (_tao_retval))
        ))
        ACE_THROW_RETURN (CORBA::MARSHAL (), _tao_retval);
    }
  ACE_CATCH (CORBA::OBJECT_NOT_EXIST, ex)
    {
      _tao_retval = 1;
    }
  ACE_CATCHANY
    {
      ACE_RE_THROW;
    }
  ACE_ENDTRY;
  return _tao_retval;
}

void
CORBA_Object::_create_request (CORBA::Context_ptr ctx,
                               const CORBA::Char *operation,
                               CORBA::NVList_ptr arg_list,
                               CORBA::NamedValue_ptr result,
                               CORBA::Request_ptr &request,
                               CORBA::Flags req_flags,
                               CORBA::Environment &ACE_TRY_ENV)
{
  // Since we don't really support Context, anything but a null pointer
  // is a no-no. - Jeff
  // Neither can we create a request object from locality constraint
  // object references.
  if (ctx || this->protocol_proxy_ == 0)
    ACE_THROW (CORBA::NO_IMPLEMENT ());

  ACE_NEW_THROW_EX (request,
                    CORBA::Request (this,
                                    this->protocol_proxy_->orb_core ()-> orb (),
                                    operation,
                                    arg_list,
                                    result,
                                    req_flags,
                                    CORBA::ExceptionList::_nil (),
                                    ACE_TRY_ENV),
                    CORBA::NO_MEMORY (
                      CORBA_SystemException::_tao_minor_code (
                        TAO_DEFAULT_MINOR_CODE,
                        ENOMEM),
                      CORBA::COMPLETED_MAYBE));
}

void
CORBA_Object::_create_request (CORBA::Context_ptr ctx,
                               const CORBA::Char *operation,
                               CORBA::NVList_ptr arg_list,
                               CORBA::NamedValue_ptr result,
                               CORBA::ExceptionList_ptr exceptions,
                               CORBA::ContextList_ptr,
                               CORBA::Request_ptr &request,
                               CORBA::Flags req_flags,
                               CORBA::Environment &ACE_TRY_ENV)
{
  // Since we don't really support Context, anything but a null pointer
  // is a no-no.
  // Neither can we create a request object from locality constraint
  // object references.
  if (ctx || this->protocol_proxy_ == 0)
      ACE_THROW (CORBA::NO_IMPLEMENT ());

  ACE_NEW_THROW_EX (request,
                    CORBA::Request (this,
                                    this->protocol_proxy_->orb_core ()->orb (),
                                    operation,
                                    arg_list,
                                    result,
                                    req_flags,
                                    exceptions,
                                    ACE_TRY_ENV),
                    CORBA::NO_MEMORY (
                      CORBA_SystemException::_tao_minor_code (
                        TAO_DEFAULT_MINOR_CODE,
                        ENOMEM),
                      CORBA::COMPLETED_MAYBE));
}

CORBA::Request_ptr
CORBA_Object::_request (const CORBA::Char *operation,
                        CORBA::Environment &ACE_TRY_ENV)
{
  //  ACE_TRY_ENV.clear ();
  if (this->protocol_proxy_)
    {
      CORBA::Request_ptr req = CORBA::Request::_nil ();
      ACE_NEW_THROW_EX (req,
                        CORBA::Request (this,
                                        this->protocol_proxy_->orb_core ()->orb (),
                                        operation,
                                        ACE_TRY_ENV),
                        CORBA::NO_MEMORY (
                          CORBA_SystemException::_tao_minor_code (
                          TAO_DEFAULT_MINOR_CODE,
                          ENOMEM),
                        CORBA::COMPLETED_MAYBE));
      ACE_CHECK_RETURN (CORBA::Request::_nil ());

      return req;
    }
  else
      ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), CORBA::Request::_nil ());
}

#if (TAO_HAS_INTERFACE_REPOSITORY == 1)

IR::InterfaceDef_ptr
CORBA_Object::_get_interface (CORBA::Environment &ACE_TRY_ENV)
{
  IR::InterfaceDef_ptr _tao_retval = IR::InterfaceDef::_nil();

  TAO_Stub *istub = this->_stubobj ();
  if (istub == 0)
    ACE_THROW_RETURN (CORBA::INTERNAL (
                        CORBA_SystemException::_tao_minor_code (
                          TAO_DEFAULT_MINOR_CODE,
                          EINVAL),
                        CORBA::COMPLETED_NO),
                      _tao_retval);


  TAO_GIOP_Twoway_Invocation _tao_call (
      istub,
      "_interface",
      10,
      istub->orb_core ()
    );

  for (;;)
    {
      _tao_call.start (ACE_TRY_ENV);
      ACE_CHECK_RETURN (_tao_retval);

    CORBA::Short flag = TAO_TWOWAY_RESPONSE_FLAG;

    _tao_call.prepare_header (ACE_static_cast (CORBA::Octet, flag),
                              ACE_TRY_ENV);
      ACE_CHECK_RETURN (_tao_retval);

      int _invoke_status =
        _tao_call.invoke (0, 0, ACE_TRY_ENV);
      ACE_CHECK_RETURN (_tao_retval);

      if (_invoke_status == TAO_INVOKE_RESTART)
        continue;
      // if (_invoke_status == TAO_INVOKE_EXCEPTION)
      // cannot happen
      if (_invoke_status != TAO_INVOKE_OK)
        {
          ACE_THROW_RETURN (CORBA::UNKNOWN (TAO_DEFAULT_MINOR_CODE,
                                            CORBA::COMPLETED_YES),
                            _tao_retval);
        }
      break;
    }

  TAO_InputCDR &_tao_in = _tao_call.inp_stream ();
  if (!(
        (_tao_in >> _tao_retval)
        ))
    ACE_THROW_RETURN (CORBA::MARSHAL (), _tao_retval);

  return _tao_retval;
}

#endif  /* TAO_HAS_INTERFACE_REPOSITORY == 1 */

CORBA::ImplementationDef_ptr
CORBA_Object::_get_implementation (CORBA::Environment &)
{
  return 0;
}

#endif /* TAO_HAS_MINIMUM_CORBA */

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

// @@ Does it make sense to support policy stuff for locality constrained
//    objects?  Also, does it make sense to bind policies with stub object?
//    - nw.

#if (TAO_HAS_CORBA_MESSAGING == 1)

CORBA::Policy_ptr
CORBA_Object::_get_policy (
    CORBA::PolicyType type,
    CORBA::Environment &ACE_TRY_ENV)
{
  if (this->protocol_proxy_)
    return this->protocol_proxy_->get_policy (type, ACE_TRY_ENV);
  else
    ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), CORBA::Policy::_nil ());
}

CORBA::Policy_ptr
CORBA_Object::_get_client_policy (
    CORBA::PolicyType type,
    CORBA::Environment &ACE_TRY_ENV)
{
  if (this->protocol_proxy_)
    return this->_stubobj ()->get_client_policy (type, ACE_TRY_ENV);
  else
    ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), CORBA::Policy::_nil ());
}

CORBA::Object_ptr
CORBA_Object::_set_policy_overrides (
    const CORBA::PolicyList & policies,
    CORBA::SetOverrideType set_add,
    CORBA::Environment &ACE_TRY_ENV)
{
  if (!this->protocol_proxy_)
    ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), CORBA::Policy::_nil ());

  TAO_Stub* stub =
    this->protocol_proxy_->set_policy_overrides (policies,
                                                 set_add,
                                                 ACE_TRY_ENV);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  CORBA::Object_ptr obj = CORBA::Object::_nil ();

  ACE_NEW_THROW_EX (obj,
                    CORBA_Object (stub,
                                  this->servant_,
                                  this->is_collocated_),
                    CORBA::NO_MEMORY (
                      CORBA_SystemException::_tao_minor_code (
                        TAO_DEFAULT_MINOR_CODE,
                        ENOMEM),
                      CORBA::COMPLETED_MAYBE));
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  return obj;
}

CORBA::PolicyList *
CORBA_Object::_get_policy_overrides (const CORBA::PolicyTypeSeq & types,
                                     CORBA::Environment &ACE_TRY_ENV)
{
  if (this->protocol_proxy_)
    return this->protocol_proxy_->get_policy_overrides (types, ACE_TRY_ENV);
  else
    ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0);
}

CORBA::Boolean
CORBA_Object::_validate_connection (CORBA::PolicyList_out inconsistent_policies,
                                    CORBA::Environment &ACE_TRY_ENV)
{
  inconsistent_policies = 0;

#if (TAO_HAS_MINIMUM_CORBA == 1)

  ACE_UNUSED_ARG (ACE_TRY_ENV);

#else

  // If the object is collocated then use non_existent to see whether
  // it's there.
  if (this->is_collocated_)
      return !(this->_non_existent (ACE_TRY_ENV));

  if (this->protocol_proxy_)
    return this->protocol_proxy_->validate_connection (inconsistent_policies,
                                                       ACE_TRY_ENV);

#endif /* TAO_HAS_MINIMUM_CORBA */

  return 0;
}

#endif /* TAO_HAS_CORBA_MESSAGING == 1 */

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

CORBA::Boolean
operator<< (TAO_OutputCDR& cdr, const CORBA_Object* x)
{
  if (x == 0)
    {
      // NIL objrefs ... marshal as empty type hint, no elements.
      cdr.write_ulong (1);
      cdr.write_char ('\0');
      cdr.write_ulong (0);
      return (CORBA::Boolean) cdr.good_bit ();
    }

  TAO_Stub *stubobj = x->_stubobj ();

  if (stubobj == 0)
    return 0;

  // STRING, a type ID hint
  if ((cdr << stubobj->type_id.in ()) == 0)
    return 0;

  const TAO_MProfile& mprofile = stubobj->base_profiles ();

  CORBA::ULong profile_count = mprofile.profile_count ();
  if ((cdr << profile_count) == 0)
    return 0;

  // @@ The MProfile should be locked during this iteration, is there
  // anyway to achieve that?
  for (CORBA::ULong i = 0; i < profile_count; ++i)
    {
      const TAO_Profile* p = mprofile.get_profile (i);
      if (p->encode (cdr) == 0)
        return 0;
    }
  return (CORBA::Boolean) cdr.good_bit ();
}

CORBA::Boolean
operator>> (TAO_InputCDR& cdr, CORBA_Object*& x)
{
  CORBA::String_var type_hint;

  if ((cdr >> type_hint.inout ()) == 0)
    return 0;

  CORBA::ULong profile_count;
  if ((cdr >> profile_count) == 0)
    return 0;

  if (profile_count == 0)
    {
      x = CORBA::Object::_nil ();
      return (CORBA::Boolean) cdr.good_bit ();
    }

  // get a profile container to store all profiles in the IOR.
  TAO_MProfile mp (profile_count);

  TAO_ORB_Core *orb_core = cdr.orb_core ();
  if (orb_core == 0)
    {
      orb_core = TAO_ORB_Core_instance ();
      if (TAO_debug_level > 0)
        {
          ACE_DEBUG ((LM_WARNING,
                      ACE_TEXT ("WARNING: extracting object from default ORB_Core\n")));
        }
    }

  TAO_Connector_Registry *connector_registry =
    orb_core->connector_registry ();
  for (CORBA::ULong i = 0; i != profile_count && cdr.good_bit (); ++i)
    {
      TAO_Profile *pfile =
        connector_registry->create_profile (cdr);
      if (pfile != 0)
        mp.give_profile (pfile);
    }

  // Make sure we got some profiles!
  if (mp.profile_count () != profile_count)
    {
      // @@ This occurs when profile creation fails when decoding the
      //    profile from the IOR.  Such a problem occurred when, for
      //    example, hostname lookup failed when binding the
      //    ACE_INET_Addr to the IIOP profile in being created.

      ACE_DEBUG ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) Could not create all ")
                  ACE_TEXT ("profiles.\n")
                  ACE_TEXT ("This may be due to an address ")
                  ACE_TEXT ("resolution problem (e.g. DNS).\n")));
      return 0;
    }

  // Ownership of type_hint is given to TAO_Stub
  // TAO_Stub will make a copy of mp!
  TAO_Stub *objdata = 0;
  ACE_NEW_RETURN (objdata, TAO_Stub (type_hint._retn (),
                                     mp,
                                     cdr.orb_core ()), 0);

  TAO_Stub_Auto_Ptr safe_objdata (objdata);

  // Figure out if the servant is collocated.
  TAO_ServantBase *servant = 0;
  TAO_SERVANT_LOCATION servant_location =
    objdata->orb_core ()->orb ()->_get_collocated_servant (safe_objdata.get (),
                                                           servant);

  int collocated = 0;
  if (servant_location != TAO_SERVANT_NOT_FOUND)
    collocated = 1;

  // Create a new CORBA_Object and give it the TAO_Stub just created.
  ACE_NEW_RETURN (x,
                  CORBA_Object (safe_objdata.get (),
                                servant,
                                (CORBA::Boolean) collocated),
                  0);

  // It is now safe to release the TAO_Stub from the TAO_Stub_Auto_Ptr.
  objdata = safe_objdata.release ();

  // the corba proxy would have already incremented the reference count on
  // the objdata. So we decrement it here by 1 so that the objdata is now
  // fully owned by the corba_proxy that was created.
  // objdata->_decr_refcnt ();

  return (CORBA::Boolean) cdr.good_bit ();
}

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

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)


#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)


#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */