Object.cpp

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

Generated on Sun Jan 27 13:07:34 2008 for TAO by doxygen 1.3.6