Object.cpp

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

Generated on Thu Nov 9 11:54:16 2006 for TAO by doxygen 1.3.6