Object.cpp

Go to the documentation of this file.
00001 // @(#) $Id: Object.cpp 81617 2008-05-05 20:41:10Z wotte $
00002 //
00003 // Copyright 1994-1995 by Sun Microsystems Inc.
00004 // Copyright 1997-2002 by Washington University
00005 // All Rights Reserved
00006 //
00007 // ORB:         CORBA::Object operations
00008 
00009 #include "tao/Object.h"
00010 #include "tao/Stub.h"
00011 #include "tao/Profile.h"
00012 #include "tao/ORB_Core.h"
00013 #include "tao/Connector_Registry.h"
00014 #include "tao/LocateRequest_Invocation_Adapter.h"
00015 #include "tao/debug.h"
00016 #include "tao/Dynamic_Adapter.h"
00017 #include "tao/IFR_Client_Adapter.h"
00018 #include "tao/Remote_Object_Proxy_Broker.h"
00019 #include "tao/CDR.h"
00020 #include "tao/SystemException.h"
00021 #include "tao/PolicyC.h"
00022 
00023 #include "ace/Dynamic_Service.h"
00024 #include "ace/OS_NS_string.h"
00025 #include "ace/CORBA_macros.h"
00026 
00027 #if !defined (__ACE_INLINE__)
00028 # include "tao/Object.inl"
00029 #endif /* ! __ACE_INLINE__ */
00030 
00031 
00032 ACE_RCSID (tao,
00033            Object,
00034            "$Id: Object.cpp 81617 2008-05-05 20:41:10Z wotte $")
00035 
00036 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00037 
00038 CORBA::Object::~Object (void)
00039 {
00040   if (this->protocol_proxy_)
00041     (void) this->protocol_proxy_->_decr_refcnt ();
00042 
00043   delete this->object_init_lock_;
00044 }
00045 
00046 CORBA::Object::Object (TAO_Stub * protocol_proxy,
00047                        CORBA::Boolean collocated,
00048                        TAO_Abstract_ServantBase * servant,
00049                        TAO_ORB_Core *orb_core)
00050   : is_local_ (false)
00051     , is_evaluated_ (true)
00052     , ior_ (0)
00053     , orb_core_ (orb_core)
00054     , protocol_proxy_ (protocol_proxy)
00055     , object_init_lock_ (0)
00056 {
00057   /// This constructor should not be called when the protocol proxy is
00058   /// null ie. when the object is a LocalObject. Assert that
00059   /// requirement.
00060   ACE_ASSERT (this->protocol_proxy_ != 0);
00061 
00062   if (this->orb_core_ == 0)
00063     this->orb_core_ = this->protocol_proxy_->orb_core ();
00064 
00065   this->object_init_lock_ =
00066     this->orb_core_->resource_factory ()->create_corba_object_lock ();
00067 
00068   this->refcount_ =
00069     this->orb_core_->resource_factory ()->create_corba_object_refcount ();
00070 
00071   // Set the collocation marker on the stub. This may not be news to it.
00072   // This may also change the stub's object proxy broker.
00073   this->protocol_proxy_->is_collocated (collocated);
00074 
00075   // Set the collocated servant pointer (null if not collocated) on the stub.
00076   this->protocol_proxy_->collocated_servant (servant);
00077 }
00078 
00079 CORBA::Object::Object (IOP::IOR *ior,
00080                        TAO_ORB_Core *orb_core)
00081   : is_local_ (false)
00082     , is_evaluated_ (false)
00083     , ior_ (ior)
00084     , orb_core_ (orb_core)
00085     , protocol_proxy_ (0)
00086     , object_init_lock_ (0)
00087 {
00088   this->object_init_lock_ =
00089     this->orb_core_->resource_factory ()->create_corba_object_lock ();
00090 
00091   this->refcount_ =
00092     this->orb_core_->resource_factory ()->create_corba_object_refcount ();
00093 }
00094 
00095 // Too lazy to do this check in every method properly! This is useful
00096 // only  for lazily evaluated IOR's
00097 #define TAO_OBJECT_IOR_EVALUATE \
00098 if (!this->is_evaluated_) \
00099   { \
00100     ACE_GUARD (ACE_Lock , mon, *this->object_init_lock_); \
00101       if (!this->is_evaluated_) \
00102         CORBA::Object::tao_object_initialize (this); \
00103   }
00104 
00105 #define TAO_OBJECT_IOR_EVALUATE_RETURN \
00106 if (!this->is_evaluated_) \
00107   { \
00108     ACE_GUARD_RETURN (ACE_Lock , mon, *this->object_init_lock_, 0); \
00109     if (!this->is_evaluated_) \
00110       CORBA::Object::tao_object_initialize (this); \
00111   }
00112 
00113 void
00114 CORBA::Object::_add_ref (void)
00115 {
00116   this->refcount_.increment ();
00117 }
00118 
00119 void
00120 CORBA::Object::_remove_ref (void)
00121 {
00122   if (this->refcount_.decrement () != 0)
00123     return;
00124 
00125   delete this;
00126 }
00127 
00128 CORBA::ULong
00129 CORBA::Object::_refcount_value(void) const
00130 {
00131   return static_cast<CORBA::ULong> (this->refcount_.value ());
00132 }
00133 
00134 void
00135 CORBA::Object::_tao_any_destructor (void *x)
00136 {
00137   CORBA::Object_ptr tmp = static_cast<CORBA::Object_ptr> (x);
00138   ::CORBA::release (tmp);
00139 }
00140 
00141 // virtual -- do not inline
00142 CORBA::Boolean
00143 CORBA::Object::marshal (TAO_OutputCDR &cdr)
00144 {
00145   return (cdr << this);
00146 }
00147 
00148 /*static*/ CORBA::Boolean
00149 CORBA::Object::marshal (const CORBA::Object_ptr x,
00150                         TAO_OutputCDR &cdr)
00151 {
00152   if (x == 0)
00153     {
00154       // NIL objrefs ... marshal as empty type hint, no elements.
00155       cdr.write_ulong (1);
00156       cdr.write_char ('\0');
00157       cdr.write_ulong (0);
00158       return (CORBA::Boolean) cdr.good_bit ();
00159     }
00160 
00161   return x->marshal (cdr);
00162 }
00163 
00164 #if defined (GEN_OSTREAM_OPS)
00165 
00166 /*static*/ std::ostream &
00167 CORBA::Object::_tao_stream (std::ostream &strm,
00168                             const CORBA::Object_ptr _tao_objref)
00169 {
00170   return _tao_objref->_tao_stream_v (strm);
00171 }
00172 
00173 std::ostream &
00174 CORBA::Object::_tao_stream_v (std::ostream &strm) const
00175 {
00176   return strm << "\"IDL:omg.org/CORBA/Object:1.0\"";
00177 }
00178 
00179 #endif /* GEN_OSTREAM_OPS */
00180 
00181 bool
00182 CORBA::Object::can_convert_to_ior (void) const
00183 {
00184   // By default, objects can not be stringified if they are local
00185   return !this->_is_local ();
00186 }
00187 
00188 char*
00189 CORBA::Object::convert_to_ior (bool, const char*) const
00190 {
00191   return 0;
00192 }
00193 
00194 TAO_Abstract_ServantBase*
00195 CORBA::Object::_servant (void) const
00196 {
00197   if (this->protocol_proxy_ == 0)
00198     {
00199       // No stub set. Should not happen.
00200       return 0;
00201     }
00202 
00203   return this->protocol_proxy_->collocated_servant ();
00204 }
00205 
00206 // IS_A ... ask the object if it's an instance of the type whose
00207 // logical type ID is passed as a parameter.
00208 
00209 CORBA::Boolean
00210 CORBA::Object::_is_a (const char *type_id)
00211 {
00212   TAO_OBJECT_IOR_EVALUATE_RETURN;
00213 
00214   // NOTE: if _stub->type_id is nonzero and we have local knowledge of
00215   // it, we can answer this question without a costly remote call.
00216   //
00217   // That "local knowledge" could come from stubs or skeletons linked
00218   // into this process in the best case, or a "near" repository in a
00219   // slightly worse case.  Or in a trivial case, if the ID being asked
00220   // about is the ID we have recorded, we don't need to ask about the
00221   // inheritance relationships at all!
00222   //
00223   // In real systems having local knowledge will be common, though as
00224   // the systems built atop ORBs become richer it'll also become
00225   // common to have the "real type ID" not be directly understood
00226   // because it's more deeply derived than any locally known types.
00227   //
00228   // XXX if type_id is that of CORBA::Object, "yes, we comply" :-)
00229 
00230   if (this->protocol_proxy_ == 0)
00231     throw ::CORBA::NO_IMPLEMENT ();
00232 
00233   if (this->_stubobj ()->type_id.in () != 0
00234       && ACE_OS::strcmp (type_id,
00235                          this->_stubobj ()->type_id.in ()) == 0)
00236     return true;
00237 
00238   return this->proxy_broker ()->_is_a (this, type_id);
00239 }
00240 
00241 const char*
00242 CORBA::Object::_interface_repository_id (void) const
00243 {
00244   return "IDL:omg.org/CORBA/Object:1.0";
00245 }
00246 
00247 CORBA::Boolean
00248 CORBA::Object::_is_collocated (void) const
00249 {
00250   if (this->protocol_proxy_)
00251     {
00252       return this->protocol_proxy_->is_collocated ();
00253     }
00254 
00255   return false;
00256 }
00257 
00258 void
00259 CORBA::Object::set_collocated_servant (TAO_Abstract_ServantBase *b)
00260 {
00261   this->protocol_proxy_->collocated_servant (b);
00262   this->protocol_proxy_->is_collocated (true);
00263 }
00264 
00265 CORBA::Boolean
00266 CORBA::Object::_is_local (void) const
00267 {
00268   return this->is_local_;
00269 }
00270 
00271 TAO_Stub *
00272 CORBA::Object::_stubobj (void) const
00273 {
00274   return this->protocol_proxy_;
00275 }
00276 
00277 TAO_Stub *
00278 CORBA::Object::_stubobj (void)
00279 {
00280   TAO_OBJECT_IOR_EVALUATE_RETURN;
00281   return this->protocol_proxy_;
00282 }
00283 
00284 CORBA::ULong
00285 CORBA::Object::_hash (CORBA::ULong maximum)
00286 {
00287   TAO_OBJECT_IOR_EVALUATE_RETURN;
00288 
00289   if (this->protocol_proxy_ != 0)
00290     return this->protocol_proxy_->hash (maximum);
00291   else
00292     {
00293       // Locality-constrained object.
00294 
00295       // Note that we reinterpret_cast to an "unsigned long" instead
00296       // of CORBA::ULong since we need to first cast to an integer
00297       // large enough to hold an address to avoid compile-time
00298       // warnings on some 64-bit platforms.
00299       const CORBA::ULong hash =
00300         static_cast<CORBA::ULong> (reinterpret_cast<ptrdiff_t> (this));
00301 
00302       return hash % maximum;
00303     }
00304 }
00305 
00306 CORBA::Boolean
00307 CORBA::Object::_is_equivalent (CORBA::Object_ptr other_obj)
00308 {
00309   if (other_obj == 0)
00310     {
00311       return false;
00312     }
00313   
00314   if (other_obj == this)
00315     {
00316       return true;
00317     }
00318 
00319   TAO_OBJECT_IOR_EVALUATE_RETURN;
00320 
00321   if (this->protocol_proxy_ != 0)
00322     return this->protocol_proxy_->is_equivalent (other_obj);
00323 
00324   return false;
00325 }
00326 
00327 // TAO's extensions
00328 
00329 TAO::ObjectKey *
00330 CORBA::Object::_key (void)
00331 {
00332   TAO_OBJECT_IOR_EVALUATE_RETURN;
00333 
00334   if (this->_stubobj () && this->_stubobj ()->profile_in_use ())
00335     return this->_stubobj ()->profile_in_use ()->_key ();
00336 
00337   if (TAO_debug_level > 2)
00338     {
00339       ACE_ERROR ((LM_ERROR,
00340                   ACE_TEXT ("TAO (%P|%t) Null object key return from ")
00341                   ACE_TEXT ("profile in use\n")));
00342     }
00343 
00344   throw ::CORBA::INTERNAL (
00345     CORBA::SystemException::_tao_minor_code (
00346       0,
00347       EINVAL),
00348     CORBA::COMPLETED_NO);
00349 }
00350 
00351 void
00352 CORBA::Object::_proxy_broker (TAO::Object_Proxy_Broker *proxy_broker)
00353 {
00354   this->protocol_proxy_->object_proxy_broker (proxy_broker);
00355 }
00356 
00357 CORBA::Boolean
00358 CORBA::Object::is_nil_i (CORBA::Object_ptr obj)
00359 {
00360 
00361   // If the profile length is zero for a non-evaluted IOR it is a
00362   // null-object.
00363   if ((!obj->is_evaluated ()) && obj->ior ().profiles.length () == 0)
00364     return true;
00365 
00366   // To accomodate new definitions.
00367   if (obj->orb_core_)
00368     {
00369       return obj->orb_core_->object_is_nil (obj);
00370     }
00371 
00372   return false;
00373 }
00374 
00375 
00376 
00377 #if (TAO_HAS_MINIMUM_CORBA == 0)
00378 
00379 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00380 void
00381 CORBA::Object::_create_request (CORBA::Context_ptr ctx,
00382                                 const char *operation,
00383                                 CORBA::NVList_ptr arg_list,
00384                                 CORBA::NamedValue_ptr result,
00385                                 CORBA::Request_ptr &request,
00386                                 CORBA::Flags req_flags)
00387 {
00388   TAO_OBJECT_IOR_EVALUATE;
00389 
00390   // Since we don't really support Context, anything but a null pointer
00391   // is a no-no.
00392   // Neither can we create a request object from locality constrained
00393   // object references.
00394   if (ctx != 0 || this->protocol_proxy_ == 0)
00395     {
00396       throw ::CORBA::NO_IMPLEMENT ();
00397     }
00398 
00399   TAO_Dynamic_Adapter *dynamic_adapter =
00400     ACE_Dynamic_Service<TAO_Dynamic_Adapter>::instance (
00401         TAO_ORB_Core::dynamic_adapter_name ()
00402       );
00403 
00404   dynamic_adapter->create_request (
00405                        this,
00406                        this->protocol_proxy_->orb_core ()-> orb (),
00407                        operation,
00408                        arg_list,
00409                        result,
00410                        0,
00411                        request,
00412                        req_flags
00413                      );
00414 }
00415 #endif
00416 
00417 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00418 void
00419 CORBA::Object::_create_request (CORBA::Context_ptr ctx,
00420                                 const char *operation,
00421                                 CORBA::NVList_ptr arg_list,
00422                                 CORBA::NamedValue_ptr result,
00423                                 CORBA::ExceptionList_ptr exceptions,
00424                                 CORBA::ContextList_ptr,
00425                                 CORBA::Request_ptr &request,
00426                                 CORBA::Flags req_flags)
00427 {
00428   TAO_OBJECT_IOR_EVALUATE;
00429 
00430   // Since we don't really support Context, anything but a null pointer
00431   // is a no-no.
00432   // Neither can we create a request object from locality constrained
00433   // object references.
00434   if (ctx != 0 || this->protocol_proxy_ == 0)
00435     {
00436       throw ::CORBA::NO_IMPLEMENT ();
00437     }
00438 
00439   TAO_Dynamic_Adapter *dynamic_adapter =
00440     ACE_Dynamic_Service<TAO_Dynamic_Adapter>::instance (
00441         TAO_ORB_Core::dynamic_adapter_name ()
00442       );
00443 
00444   dynamic_adapter->create_request (
00445                        this,
00446                        this->protocol_proxy_->orb_core ()-> orb (),
00447                        operation,
00448                        arg_list,
00449                        result,
00450                        exceptions,
00451                        request,
00452                        req_flags);
00453 }
00454 #endif
00455 
00456 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00457 CORBA::Request_ptr
00458 CORBA::Object::_request (const char *operation)
00459 {
00460   TAO_OBJECT_IOR_EVALUATE_RETURN;
00461   if (this->protocol_proxy_)
00462     {
00463       TAO_Dynamic_Adapter *dynamic_adapter =
00464         ACE_Dynamic_Service<TAO_Dynamic_Adapter>::instance (
00465             TAO_ORB_Core::dynamic_adapter_name ());
00466 
00467       return dynamic_adapter->request (
00468                                   this,
00469                                   this->protocol_proxy_->orb_core ()->orb (),
00470                                   operation);
00471     }
00472   else
00473     {
00474       throw ::CORBA::NO_IMPLEMENT ();
00475     }
00476 }
00477 #endif
00478 
00479 // NON_EXISTENT ... send a simple call to the object, which will
00480 // either elicit a false response or a OBJECT_NOT_EXIST exception.  In
00481 // the latter case, return true.
00482 
00483 CORBA::Boolean
00484 CORBA::Object::_non_existent (void)
00485 {
00486   TAO_OBJECT_IOR_EVALUATE_RETURN;
00487 
00488   CORBA::Boolean retval = false;
00489 
00490   try
00491     {
00492       retval = this->proxy_broker ()->_non_existent (this);
00493     }
00494   catch (const ::CORBA::OBJECT_NOT_EXIST&)
00495     {
00496       retval = true;
00497     }
00498 
00499   return retval;
00500 }
00501 
00502 
00503 #if ! defined (CORBA_E_COMPACT) && ! defined (CORBA_E_MICRO)
00504 CORBA::InterfaceDef_ptr
00505 CORBA::Object::_get_interface (void)
00506 {
00507   TAO_OBJECT_IOR_EVALUATE_RETURN;
00508   return this->proxy_broker ()->_get_interface (this);
00509 }
00510 
00511 CORBA::Object_ptr
00512 CORBA::Object::_get_component (void)
00513 {
00514   TAO_OBJECT_IOR_EVALUATE_RETURN;
00515   return this->proxy_broker ()->_get_component (this);
00516 }
00517 #endif
00518 
00519 char*
00520 CORBA::Object::_repository_id (void)
00521 {
00522   TAO_OBJECT_IOR_EVALUATE_RETURN;
00523   return this->proxy_broker ()->_repository_id (this);
00524 }
00525 
00526 #endif /* TAO_HAS_MINIMUM_CORBA */
00527 
00528 // ****************************************************************
00529 
00530 // @@ Does it make sense to support policy stuff for locality constrained
00531 //    objects?  Also, does it make sense to bind policies with stub object?
00532 //    - nw.
00533 
00534 #if (TAO_HAS_CORBA_MESSAGING == 1)
00535 
00536 CORBA::Policy_ptr
00537 CORBA::Object::_get_policy (CORBA::PolicyType type)
00538 {
00539   TAO_OBJECT_IOR_EVALUATE_RETURN;
00540 
00541   if (this->protocol_proxy_)
00542     return this->protocol_proxy_->get_policy (type);
00543   else
00544     throw ::CORBA::NO_IMPLEMENT ();
00545 }
00546 
00547 CORBA::Policy_ptr
00548 CORBA::Object::_get_cached_policy (TAO_Cached_Policy_Type type)
00549 {
00550   TAO_OBJECT_IOR_EVALUATE_RETURN;
00551 
00552   if (this->protocol_proxy_)
00553     return this->protocol_proxy_->get_cached_policy (type);
00554   else
00555     throw ::CORBA::NO_IMPLEMENT ();
00556 }
00557 
00558 CORBA::Object_ptr
00559 CORBA::Object::_set_policy_overrides (
00560   const CORBA::PolicyList & policies,
00561   CORBA::SetOverrideType set_add)
00562 {
00563   TAO_OBJECT_IOR_EVALUATE_RETURN;
00564 
00565   if (!this->protocol_proxy_)
00566     throw ::CORBA::NO_IMPLEMENT ();
00567 
00568   TAO_Stub* stub =
00569     this->protocol_proxy_->set_policy_overrides (policies, set_add);
00570 
00571   TAO_Stub_Auto_Ptr safe_stub (stub);
00572 
00573   CORBA::Object_ptr obj = CORBA::Object::_nil ();
00574 
00575   ACE_NEW_THROW_EX (obj,
00576                     CORBA::Object (stub,
00577                                   this->_is_collocated ()),
00578                     CORBA::NO_MEMORY (
00579                       CORBA::SystemException::_tao_minor_code (
00580                         0,
00581                         ENOMEM),
00582                       CORBA::COMPLETED_MAYBE));
00583 
00584   // If the stub is collocated and we don't have a collocated server we need
00585   // to reinitialize it to get it.
00586   if (stub->is_collocated () && stub->collocated_servant () == 0)
00587     {
00588       obj->orb_core ()->reinitialize_object (stub);
00589     }
00590 
00591   (void) safe_stub.release ();
00592 
00593   return obj;
00594 }
00595 
00596 CORBA::PolicyList *
00597 CORBA::Object::_get_policy_overrides (const CORBA::PolicyTypeSeq & types)
00598 {
00599   TAO_OBJECT_IOR_EVALUATE_RETURN;
00600   if (this->protocol_proxy_)
00601     return this->protocol_proxy_->get_policy_overrides (types);
00602   else
00603     throw ::CORBA::NO_IMPLEMENT ();
00604 }
00605 
00606 CORBA::Boolean
00607 CORBA::Object::_validate_connection (
00608   CORBA::PolicyList_out inconsistent_policies)
00609 {
00610   TAO_OBJECT_IOR_EVALUATE_RETURN;
00611 
00612   inconsistent_policies = 0;
00613   CORBA::Boolean retval = true;
00614 
00615 #if (TAO_HAS_MINIMUM_CORBA == 0)
00616   // Note that the OBJECT_NOT_EXIST exception should be propagated to
00617   // the caller rather than return false, which is why we do not use
00618   // CORBA::Object::_non_existent().  This behavior is consistent
00619   // with the non-collocated case.
00620   if (this->_is_collocated ())
00621       return !(this->proxy_broker ()->_non_existent (this));
00622 
00623   TAO::LocateRequest_Invocation_Adapter tao_call (this);
00624   try
00625     {
00626       tao_call.invoke ();
00627     }
00628   catch (const ::CORBA::INV_POLICY&)
00629     {
00630       inconsistent_policies = tao_call.get_inconsistent_policies ();
00631       retval = false;
00632     }
00633 #else
00634   retval = false;
00635 #endif /* TAO_HAS_MINIMUM_CORBA */
00636 
00637   return retval;
00638 }
00639 
00640 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
00641 
00642 
00643 CORBA::ORB_ptr
00644 CORBA::Object::_get_orb (void)
00645 {
00646   if (this->orb_core_ != 0)
00647     {
00648       return CORBA::ORB::_duplicate (this->orb_core_->orb ());
00649     }
00650   else
00651     {
00652       TAO_OBJECT_IOR_EVALUATE_RETURN;
00653       if (this->protocol_proxy_)
00654         return CORBA::ORB::_duplicate (this->protocol_proxy_->orb_core ()->orb ());
00655       else
00656         throw ::CORBA::INTERNAL ();
00657     }
00658 }
00659 
00660 TAO::Object_Proxy_Broker *
00661 CORBA::Object::proxy_broker (void) const
00662 {
00663   // Paranoid check. We *should* never access the proxy_broker
00664   // when the object has not been initialised so there *should*
00665   // alway be a stub, but just in case...
00666 
00667   if (this->protocol_proxy_)
00668     {
00669       return this->protocol_proxy_->object_proxy_broker ();
00670     }
00671 
00672   // We have no stub. We cannot be collocated.
00673   return the_tao_remote_object_proxy_broker ();
00674 }
00675 
00676 /*****************************************************************
00677  * Global Functions
00678  ****************************************************************/
00679 
00680 CORBA::Boolean
00681 operator<< (TAO_OutputCDR& cdr, const CORBA::Object* x)
00682 {
00683   if (x == 0)
00684     {
00685       // NIL objrefs ... marshal as empty type hint, no elements.
00686       cdr.write_ulong (1);
00687       cdr.write_char ('\0');
00688       cdr.write_ulong (0);
00689       return (CORBA::Boolean) cdr.good_bit ();
00690     }
00691 
00692   if (!x->is_evaluated ())
00693     {
00694       // @@ This is too inefficient. Need to speed this up if this is
00695       // a bottle neck.
00696       cdr << const_cast<IOP::IOR &> (x->ior ());
00697       return cdr.good_bit ();
00698     }
00699 
00700    TAO_Stub *stubobj = x->_stubobj ();
00701 
00702    if (stubobj == 0)
00703      return false;
00704 
00705   return (stubobj->marshal (cdr));
00706 }
00707 
00708 /*static*/ void
00709 CORBA::Object::tao_object_initialize (CORBA::Object *obj)
00710 {
00711   CORBA::ULong const profile_count =
00712     obj->ior_->profiles.length ();
00713 
00714   // Assumption is that after calling this method, folks should test
00715   // for protocol_proxy_ or whatever to make sure that things have
00716   // been initialized!
00717   if (profile_count == 0)
00718     return;
00719 
00720   // get a profile container to store all profiles in the IOR.
00721   TAO_MProfile mp (profile_count);
00722 
00723   TAO_ORB_Core *&orb_core = obj->orb_core_;
00724   if (orb_core == 0)
00725     {
00726       orb_core = TAO_ORB_Core_instance ();
00727       if (TAO_debug_level > 0)
00728         {
00729           ACE_DEBUG ((LM_WARNING,
00730                       ACE_TEXT ("TAO (%P|%t) - Object::tao_object_initialize ")
00731                       ACE_TEXT ("WARNING: extracting object from ")
00732                       ACE_TEXT ("default ORB_Core\n")));
00733         }
00734     }
00735 
00736   TAO_Stub *objdata = 0;
00737 
00738   try
00739     {
00740       TAO_Connector_Registry *connector_registry =
00741         orb_core->connector_registry ();
00742 
00743       for (CORBA::ULong i = 0; i != profile_count; ++i)
00744         {
00745           IOP::TaggedProfile &tpfile = obj->ior_->profiles[i];
00746 
00747           // NOTE: This is a place for optimizations. Here we have an
00748           // 2 allocations and 2 copies. Future optimizations should
00749           // target this place.
00750           TAO_OutputCDR o_cdr;
00751 
00752           o_cdr << tpfile;
00753 
00754           TAO_InputCDR cdr (o_cdr,
00755                             orb_core->input_cdr_buffer_allocator (),
00756                             orb_core->input_cdr_dblock_allocator (),
00757                             orb_core->input_cdr_msgblock_allocator (),
00758                             orb_core);
00759 
00760           TAO_Profile *pfile = connector_registry->create_profile (cdr);
00761 
00762           if (pfile != 0)
00763             mp.give_profile (pfile);
00764         }
00765 
00766       // Make sure we got some profiles!
00767       if (mp.profile_count () != profile_count)
00768         {
00769           // @@ This occurs when profile creation fails when decoding the
00770           //    profile from the IOR.
00771           ACE_ERROR ((LM_ERROR,
00772                       ACE_TEXT ("TAO (%P|%t) ERROR: XXXXX Could not create all ")
00773                       ACE_TEXT ("profiles while extracting object\n")
00774                       ACE_TEXT ("TAO (%P|%t) ERROR: reference from the ")
00775                       ACE_TEXT ("CDR stream.\n")));
00776         }
00777 
00778 
00779       objdata = orb_core->create_stub (obj->ior_->type_id.in (), mp);
00780     }
00781   catch (const ::CORBA::Exception& ex)
00782     {
00783       if (TAO_debug_level > 0)
00784         ex._tao_print_exception (
00785           ACE_TEXT ("TAO - ERROR creating stub ")
00786           ACE_TEXT ("object when demarshaling object ")
00787           ACE_TEXT ("reference."));
00788 
00789       return;
00790     }
00791 
00792   TAO_Stub_Auto_Ptr safe_objdata (objdata);
00793 
00794   // This call will set the stub proxy broker if necessary
00795   if (orb_core->initialize_object (safe_objdata.get (), obj) == -1)
00796     return;
00797 
00798   obj->protocol_proxy_ = objdata;
00799 
00800   obj->is_evaluated_ = true;
00801 
00802   // Release the contents of the ior to keep memory consumption down.
00803   obj->ior_ = 0;
00804 
00805   // Transfer ownership to the CORBA::Object
00806   (void) safe_objdata.release ();
00807   return;
00808 }
00809 
00810 CORBA::Boolean
00811 operator>> (TAO_InputCDR& cdr, CORBA::Object*& x)
00812 {
00813   bool lazy_strategy = false;
00814   TAO_ORB_Core *orb_core = cdr.orb_core ();
00815 
00816   if (orb_core == 0)
00817     {
00818       orb_core = TAO_ORB_Core_instance ();
00819       if (TAO_debug_level > 0)
00820         {
00821           ACE_DEBUG ((LM_WARNING,
00822                       ACE_TEXT ("TAO (%P|%t) WARNING: extracting object from ")
00823                       ACE_TEXT ("default ORB_Core\n")));
00824         }
00825     }
00826   else
00827     {
00828       if (orb_core->resource_factory ()->resource_usage_strategy () ==
00829           TAO_Resource_Factory::TAO_LAZY)
00830         lazy_strategy = true;
00831     }
00832 
00833   if (!lazy_strategy)
00834     {
00835       // If the user has set up a eager strategy..
00836       CORBA::String_var type_hint;
00837 
00838       if ((cdr >> type_hint.inout ()) == 0)
00839         return 0;
00840 
00841       CORBA::ULong profile_count;
00842       if ((cdr >> profile_count) == 0)
00843         return 0;
00844 
00845       if (profile_count == 0)
00846         {
00847           x = CORBA::Object::_nil ();
00848           return (CORBA::Boolean) cdr.good_bit ();
00849         }
00850 
00851       // get a profile container to store all profiles in the IOR.
00852       TAO_MProfile mp (profile_count);
00853 
00854       TAO_ORB_Core *orb_core = cdr.orb_core ();
00855       if (orb_core == 0)
00856         {
00857           orb_core = TAO_ORB_Core_instance ();
00858           if (TAO_debug_level > 0)
00859             {
00860               ACE_DEBUG ((LM_WARNING,
00861                           ACE_TEXT ("TAO (%P|%t) - Object::tao_object_initialize ")
00862                           ACE_TEXT ("WARNING: extracting object from ")
00863                           ACE_TEXT ("default ORB_Core\n")));
00864             }
00865         }
00866 
00867       // Ownership of type_hint is given to TAO_Stub
00868       // TAO_Stub will make a copy of mp!
00869 
00870       TAO_Stub *objdata = 0;
00871 
00872       try
00873         {
00874           TAO_Connector_Registry *connector_registry =
00875             orb_core->connector_registry ();
00876 
00877           for (CORBA::ULong i = 0; i != profile_count && cdr.good_bit (); ++i)
00878             {
00879               TAO_Profile *pfile = connector_registry->create_profile (cdr);
00880               if (pfile != 0)
00881                 mp.give_profile (pfile);
00882             }
00883 
00884           // Make sure we got some profiles!
00885           if (mp.profile_count () != profile_count)
00886             {
00887               // @@ This occurs when profile creation fails when decoding the
00888               //    profile from the IOR.
00889               ACE_ERROR_RETURN ((LM_ERROR,
00890                                  ACE_TEXT ("TAO (%P|%t) ERROR: Could not create all ")
00891                                  ACE_TEXT ("profiles while extracting object\n")
00892                                  ACE_TEXT ("TAO (%P|%t) ERROR: reference from the ")
00893                                  ACE_TEXT ("CDR stream.\n")),
00894                                 0);
00895             }
00896 
00897           objdata = orb_core->create_stub (type_hint.in (), mp);
00898         }
00899       catch (const ::CORBA::Exception& ex)
00900         {
00901           if (TAO_debug_level > 0)
00902             ex._tao_print_exception (
00903               ACE_TEXT ("TAO - ERROR creating stub ")
00904               ACE_TEXT ("object when demarshaling object ")
00905               ACE_TEXT ("reference.\n"));
00906 
00907           return 0;
00908         }
00909 
00910       TAO_Stub_Auto_Ptr safe_objdata (objdata);
00911 
00912       x = orb_core->create_object (safe_objdata.get ());
00913       if (x == 0)
00914         return 0;
00915 
00916       // Transfer ownership to the CORBA::Object
00917       (void) safe_objdata.release ();
00918     }
00919   else
00920     {
00921       // Lazy strategy!
00922       IOP::IOR *ior = 0;
00923 
00924       ACE_NEW_RETURN (ior,
00925                       IOP::IOR (),
00926                       0);
00927 
00928       cdr >> *ior;
00929       ACE_NEW_RETURN (x,
00930                       CORBA::Object (ior, orb_core),
00931                       0);
00932     }
00933 
00934   return (CORBA::Boolean) cdr.good_bit ();
00935 }
00936 
00937 #if defined (GEN_OSTREAM_OPS)
00938 
00939 std::ostream&
00940 operator<< (std::ostream &strm, CORBA::Object_ptr _tao_objref)
00941 {
00942   return CORBA::Object::_tao_stream (strm, _tao_objref);
00943 }
00944 
00945 #endif /* GEN_OSTREAM_OPS */
00946 
00947 // =========================================================
00948 // Traits specializations for CORBA::Object.
00949 namespace TAO
00950 {
00951 
00952   void In_Object_Argument_Cloner_T<CORBA::InterfaceDef_ptr>::duplicate
00953                                               (CORBA::InterfaceDef_ptr)
00954   {
00955   }
00956 
00957   void In_Object_Argument_Cloner_T<CORBA::InterfaceDef_ptr>::release
00958                                               (CORBA::InterfaceDef_ptr)
00959   {
00960   }
00961 
00962   CORBA::Object_ptr
00963   Objref_Traits<CORBA::Object>::duplicate (CORBA::Object_ptr p)
00964   {
00965     return CORBA::Object::_duplicate (p);
00966   }
00967 
00968   void
00969   Objref_Traits<CORBA::Object>::release (CORBA::Object_ptr p)
00970   {
00971     ::CORBA::release (p);
00972   }
00973 
00974   CORBA::Object_ptr
00975   Objref_Traits<CORBA::Object>::nil (void)
00976   {
00977     return CORBA::Object::_nil ();
00978   }
00979 
00980   CORBA::Boolean
00981   Objref_Traits<CORBA::Object>::marshal (const CORBA::Object_ptr p,
00982                                          TAO_OutputCDR & cdr)
00983   {
00984     return p->marshal (cdr);
00985   }
00986 } // close TAO namespace
00987 
00988 
00989 TAO::Object_Proxy_Broker * (*_TAO_Object_Proxy_Broker_Factory_function_pointer) (void) = 0;
00990 
00991 
00992 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:37:52 2010 for TAO by  doxygen 1.4.7