diff options
author | Ossama Othman <ossama-othman@users.noreply.github.com> | 1999-09-14 20:00:26 +0000 |
---|---|---|
committer | Ossama Othman <ossama-othman@users.noreply.github.com> | 1999-09-14 20:00:26 +0000 |
commit | b2122f8cf6be36b1a2d679e5389adc4fe05d59dc (patch) | |
tree | 976a62c63a78b16fb9856506bff747223b41aa85 /TAO/tao/ORB.cpp | |
parent | 207bb03fb9cdee03fd00568c7d018f84f4ec8349 (diff) | |
download | ATCD-b2122f8cf6be36b1a2d679e5389adc4fe05d59dc.tar.gz |
ChangeLogTag:Tue Sep 14 14:42:04 1999 Ossama Othman <othman@cs.wustl.edu>
Diffstat (limited to 'TAO/tao/ORB.cpp')
-rw-r--r-- | TAO/tao/ORB.cpp | 632 |
1 files changed, 610 insertions, 22 deletions
diff --git a/TAO/tao/ORB.cpp b/TAO/tao/ORB.cpp index 5d7f3025f8f..a6d90e19c39 100644 --- a/TAO/tao/ORB.cpp +++ b/TAO/tao/ORB.cpp @@ -47,7 +47,550 @@ #if defined (ACE_HAS_EXCEPTIONS) # if defined (ACE_MVS) -# include /**/ <unexpect.h> +# include /**/ <unexpect.h>// -*- c++ -*- +// $Id$ + +// ---------------------------------------------------------------------- +// String_var type +// ---------------------------------------------------------------------- + +ACE_INLINE +CORBA_String_var::CORBA_String_var (void) + : ptr_ (0); +{ +} + +ACE_INLINE +CORBA_String_var::CORBA_String_var (const char *p) + : ptr_ (CORBA::string_dup (p)) +{ +} + +ACE_INLINE CORBA::Char & +CORBA_String_var::operator[] (CORBA::ULong slot) +{ + // We need to verify bounds else raise some exception. + return this->ptr_[slot]; +} + +ACE_INLINE CORBA::Char +CORBA_String_var::operator[] (CORBA::ULong slot) const +{ + // We need to verify bounds else raise some exception. + return this->ptr_[slot]; +} + +ACE_INLINE +CORBA_String_var::operator char *() +{ + return this->ptr_; +} + +ACE_INLINE +CORBA_String_var::operator const char *() const +{ + return this->ptr_; +} + +ACE_INLINE const char * +CORBA_String_var::in (void) const +{ + return this->ptr_; +} + +ACE_INLINE char *& +CORBA_String_var::inout (void) +{ + return this->ptr_; +} + +ACE_INLINE char *& +CORBA_String_var::out (void) +{ + CORBA::string_free (this->ptr_); + this->ptr_ = 0; + return this->ptr_; +} + +ACE_INLINE char * +CORBA_String_var::_retn (void) +{ + char *temp = this->ptr_; + this->ptr_ = 0; + return temp; +} + +// ---------------------------------------------------- +// String_out type +// ---------------------------------------------------- + +ACE_INLINE +CORBA_String_out::CORBA_String_out (char *&s) + : ptr_ (s) +{ + this->ptr_ = 0; +} + +ACE_INLINE +CORBA_String_out::CORBA_String_out (CORBA_String_var &s) + : ptr_ (s.out ()) +{ +} + +ACE_INLINE +CORBA_String_out::CORBA_String_out (const CORBA_String_out &s) + : ptr_ (s.ptr_) +{ +} + +ACE_INLINE CORBA_String_out & +CORBA_String_out::operator= (const CORBA_String_out &s) +{ + this->ptr_ = s.ptr_; + return *this; +} + +ACE_INLINE CORBA_String_out & +CORBA_String_out::operator= (char *s) +{ + this->ptr_ = s; + return *this; +} + +ACE_INLINE CORBA_String_out & +CORBA_String_out::operator= (const char *s) +{ + this->ptr_ = CORBA::string_dup (s); + return *this; +} + +ACE_INLINE +CORBA_String_out::operator char *&() +{ + return this->ptr_; +} + +ACE_INLINE char *& +CORBA_String_out::ptr (void) +{ + return this->ptr_; +} + +// **************************************************************** + +// ---------------------------------------------------------------------- +// String_var type +// ---------------------------------------------------------------------- + +ACE_INLINE +CORBA_WString_var::CORBA_WString_var (void) + : ptr_ (0) +{ +} + +ACE_INLINE +CORBA_WString_var::CORBA_WString_var (const CORBA::WChar *p) + : ptr_ (CORBA::wstring_dup (p)) +{ +} + +ACE_INLINE CORBA::WChar & +CORBA_WString_var::operator[] (CORBA::ULong slot) +{ + // We need to verify bounds else raise some exception. + return this->ptr_[slot]; +} + +ACE_INLINE CORBA::WChar +CORBA_WString_var::operator[] (CORBA::ULong slot) const +{ + // We need to verify bounds else raise some exception. + return this->ptr_[slot]; +} + +ACE_INLINE +CORBA_WString_var::operator CORBA::WChar *() +{ + return this->ptr_; +} + +ACE_INLINE +CORBA_WString_var::operator const CORBA::WChar *() const +{ + return this->ptr_; +} + +ACE_INLINE const CORBA::WChar * +CORBA_WString_var::in (void) const +{ + return this->ptr_; +} + +ACE_INLINE CORBA::WChar *& +CORBA_WString_var::inout (void) +{ + return this->ptr_; +} + +ACE_INLINE CORBA::WChar *& +CORBA_WString_var::out (void) +{ + CORBA::wstring_free (this->ptr_); + this->ptr_ = 0; + return this->ptr_; +} + +ACE_INLINE CORBA::WChar * +CORBA_WString_var::_retn (void) +{ + CORBA::WChar *temp = this->ptr_; + this->ptr_ = 0; + return temp; +} + +// ---------------------------------------------------- +// String_out type +// ---------------------------------------------------- + +ACE_INLINE +CORBA_WString_out::CORBA_WString_out (CORBA::WChar *&s) + : ptr_ (s) +{ + this->ptr_ = 0; +} + +ACE_INLINE +CORBA_WString_out::CORBA_WString_out (CORBA_WString_var &s) + : ptr_ (s.out ()) +{ +} + +ACE_INLINE +CORBA_WString_out::CORBA_WString_out (const CORBA_WString_out &s) + : ptr_ (s.ptr_) +{ +} + +ACE_INLINE CORBA_WString_out & +CORBA_WString_out::operator= (const CORBA_WString_out &s) +{ + this->ptr_ = s.ptr_; + return *this; +} + +ACE_INLINE CORBA_WString_out & +CORBA_WString_out::operator= (CORBA::WChar *s) +{ + this->ptr_ = s; + return *this; +} + +ACE_INLINE +CORBA_WString_out::operator CORBA::WChar *&() +{ + return this->ptr_; +} + +ACE_INLINE CORBA::WChar *& +CORBA_WString_out::ptr (void) +{ + return this->ptr_; +} + +// **************************************************************** + +// --------------------------------------------------------------------------- +// ORB specific +// --------------------------------------------------------------------------- + +ACE_INLINE CORBA::ULong +CORBA_ORB::_incr_refcnt (void) +{ + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, lock_, 0); + return ++this->refcount_; +} + +ACE_INLINE CORBA::ULong +CORBA_ORB::_decr_refcnt (void) +{ + { + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->lock_, 0); + this->refcount_--; + if (this->refcount_ != 0) + return this->refcount_; + } + + delete this; + return 0; +} + +ACE_INLINE CORBA::ORB_ptr +CORBA_ORB::_duplicate (CORBA::ORB_ptr obj) +{ + if (obj) + obj->_incr_refcnt (); + return obj; +} + +// Null pointers represent nil objects. + +ACE_INLINE CORBA::ORB_ptr +CORBA_ORB::_nil (void) +{ + return 0; +} + +ACE_INLINE void +CORBA_ORB::_use_omg_ior_format (CORBA::Boolean ior) +{ + this->use_omg_ior_format_ = ior; +} + +ACE_INLINE CORBA::Boolean +CORBA_ORB::_use_omg_ior_format (void) +{ + return this->use_omg_ior_format_; +} + +ACE_INLINE TAO_ORB_Core * +CORBA_ORB::orb_core (void) const +{ + return this->orb_core_; +} + +#if defined (TAO_HAS_INTERCEPTORS) +ACE_INLINE PortableInterceptor::ClientRequestInterceptor_ptr +CORBA_ORB::_register_client_interceptor + (PortableInterceptor::ClientRequestInterceptor_ptr ci, + CORBA_Environment &ACE_TRY_ENV) +{ + if (ci == 0 || + ci->_is_a ("IDL:TAO/PortableInterceptor/ClientRequestInterceptor:1.0")) + { + PortableInterceptor::ClientRequestInterceptor_var oci = + PortableInterceptor::ClientRequestInterceptor::_duplicate ( + this->client_interceptor_.in ()); + this->client_interceptor_ = ci; + return oci._retn (); + } + else + ACE_THROW_RETURN (CORBA::INV_OBJREF (), 0); +} + +ACE_INLINE PortableInterceptor::ServerRequestInterceptor_ptr +CORBA_ORB::_register_server_interceptor + (PortableInterceptor::ServerRequestInterceptor_ptr si, + CORBA_Environment &ACE_TRY_ENV) +{ + if (si == 0 || + si->_is_a ("IDL:TAO/PortableInterceptor/ServerRequestInterceptor:1.0")) + { + PortableInterceptor::ServerRequestInterceptor_var oci = + PortableInterceptor::ServerRequestInterceptor::_duplicate ( + this->server_interceptor_.in ()); + this->server_interceptor_ = si; + return oci._retn (); + } + else + ACE_THROW_RETURN (CORBA::INV_OBJREF (), 0); +} + +ACE_INLINE PortableInterceptor::ClientRequestInterceptor_ptr +CORBA_ORB::_get_client_interceptor (CORBA_Environment &) +{ + return PortableInterceptor::ClientRequestInterceptor::_duplicate ( + this->client_interceptor_.in ()); +} + +ACE_INLINE PortableInterceptor::ServerRequestInterceptor_ptr +CORBA_ORB::_get_server_interceptor (CORBA_Environment &) +{ + return PortableInterceptor::ServerRequestInterceptor::_duplicate ( + this->server_interceptor_.in ()); +} +#endif /* TAO_HAS_INTERCEPTORS */ + +// ************************************************************ +// These are in CORBA namespace +// ************************************************************ + +ACE_INLINE CORBA::Boolean +CORBA::is_nil (CORBA::ORB_ptr obj) +{ + return obj == CORBA_ORB::_nil (); +} + +ACE_INLINE void +CORBA::release (CORBA::ORB_ptr obj) +{ + if (!CORBA::is_nil (obj)) + obj->_decr_refcnt (); +} + +// ************************************************************* +// Inline operations for class CORBA_ORB_var +// ************************************************************* + +ACE_INLINE +CORBA_ORB_var::CORBA_ORB_var (void) // default constructor + : ptr_ (CORBA_ORB::_nil ()) +{ +} + +ACE_INLINE +CORBA_ORB_var::CORBA_ORB_var (CORBA::ORB_ptr p) + : ptr_ (p) +{ +} + +ACE_INLINE CORBA::ORB_ptr +CORBA_ORB_var::ptr (void) const +{ + return this->ptr_; +} + +ACE_INLINE +CORBA_ORB_var::CORBA_ORB_var (const CORBA_ORB_var &p) // copy constructor + : ptr_ (CORBA_ORB::_duplicate (p.ptr ())) +{ +} + +ACE_INLINE +CORBA_ORB_var::~CORBA_ORB_var (void) // destructor +{ + CORBA::release (this->ptr_); +} + +ACE_INLINE CORBA_ORB_var & +CORBA_ORB_var::operator= (CORBA::ORB_ptr p) +{ + CORBA::release (this->ptr_); + this->ptr_ = p; + return *this; +} + +ACE_INLINE CORBA_ORB_var & +CORBA_ORB_var::operator= (const CORBA_ORB_var &p) +{ + if (this != &p) + { + CORBA::release (this->ptr_); + this->ptr_ = CORBA_ORB::_duplicate (p.ptr ()); + } + + return *this; +} + +ACE_INLINE +CORBA_ORB_var::operator const CORBA::ORB_ptr &() const // cast +{ + return this->ptr_; +} + +ACE_INLINE +CORBA_ORB_var::operator CORBA::ORB_ptr &() // cast +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ORB_ptr +CORBA_ORB_var::operator-> (void) const +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ORB_ptr +CORBA_ORB_var::in (void) const +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ORB_ptr & +CORBA_ORB_var::inout (void) +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ORB_ptr & +CORBA_ORB_var::out (void) +{ + CORBA::release (this->ptr_); + this->ptr_ = CORBA_ORB::_nil (); + return this->ptr_; +} + +ACE_INLINE CORBA::ORB_ptr +CORBA_ORB_var::_retn (void) +{ + // yield ownership of managed obj reference + CORBA::ORB_ptr val = this->ptr_; + this->ptr_ = CORBA_ORB::_nil (); + return val; +} + +// ************************************************************* +// Inline operations for class CORBA_ORB_out +// ************************************************************* + +ACE_INLINE +CORBA_ORB_out::CORBA_ORB_out (CORBA::ORB_ptr &p) + : ptr_ (p) +{ + this->ptr_ = CORBA_ORB::_nil (); +} + +ACE_INLINE +CORBA_ORB_out::CORBA_ORB_out (CORBA_ORB_var &p) // constructor from _var + : ptr_ (p.out ()) +{ + CORBA::release (this->ptr_); + this->ptr_ = CORBA_ORB::_nil (); +} + +ACE_INLINE +CORBA_ORB_out::CORBA_ORB_out (const CORBA_ORB_out &p) // copy constructor + : ptr_ (p.ptr_) +{} + +ACE_INLINE CORBA_ORB_out & +CORBA_ORB_out::operator= (CORBA_ORB_out &p) +{ + this->ptr_ = p.ptr_; + return *this; +} + +ACE_INLINE CORBA_ORB_out & +CORBA_ORB_out::operator= (const CORBA_ORB_var &p) +{ + this->ptr_ = CORBA_ORB::_duplicate (p.ptr ()); + return *this; +} + +ACE_INLINE CORBA_ORB_out & +CORBA_ORB_out::operator= (CORBA::ORB_ptr p) +{ + this->ptr_ = p; + return *this; +} + +ACE_INLINE +CORBA_ORB_out::operator CORBA::ORB_ptr &() // cast +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ORB_ptr & +CORBA_ORB_out::ptr (void) // ptr +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ORB_ptr +CORBA_ORB_out::operator-> (void) +{ + return this->ptr_; +} + # else # if defined (ACE_HAS_STANDARD_CPP_LIBRARY) # include /**/ <exception> @@ -159,21 +702,10 @@ CORBA_ORB::CORBA_ORB (TAO_ORB_Core *orb_core) CORBA_ORB::~CORBA_ORB (void) { - this->orb_core_->fini (); - ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, tao_mon, *ACE_Static_Object_Lock::instance ())); CORBA_ORB::orb_init_count_--; - if (CORBA_ORB::orb_init_count_ == 0) - { - // free up all the ORB owned Exceptions - TAO_Exceptions::fini (); - - // free up all the ORB owned TypeCodes - TAO_TypeCodes::fini (); - } - # ifdef TAO_HAS_VALUETYPE // delete valuetype_factory_map_; // not really, its a singleton @@ -185,15 +717,34 @@ CORBA_ORB::shutdown (CORBA::Boolean wait_for_completion, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { + this->check_shutdown (ACE_TRY_ENV); + ACE_CHECK; + this->orb_core ()->shutdown (wait_for_completion, ACE_TRY_ENV); + ACE_CHECK; } void CORBA_ORB::destroy (CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { + this->check_shutdown (ACE_TRY_ENV); + ACE_CHECK; + + if (TAO_debug_level >= 3) + { + ACE_DEBUG ((LM_DEBUG, + "CORBA::ORB::destroy() has been called on ORB <%s>.\n", + this->orb_core ()->orbid ())); + } + this->orb_core ()->destroy (ACE_TRY_ENV); + ACE_CHECK; + + // Now invalidate the pointer to the ORB_Core that created this + // ORB. + this->orb_core_ = 0; } int @@ -349,7 +900,10 @@ CORBA_ORB::run (ACE_Time_Value *tv, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { - return this->orb_core_->run (tv, break_on_timeouts, ACE_TRY_ENV); + this->check_shutdown (ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + return this->orb_core ()->run (tv, break_on_timeouts, ACE_TRY_ENV); } int @@ -814,7 +1368,7 @@ CORBA_ORB::resolve_initial_references (const char *name, // Get the table of initial references specified through // -ORBInitRef. TAO_IOR_LookupTable *table = - this->orb_core_->orb_params ()->ior_lookup_table (); + this->orb_core ()->orb_params ()->ior_lookup_table (); ACE_CString ior; ACE_CString object_id ((const char *) name); @@ -829,7 +1383,7 @@ CORBA_ORB::resolve_initial_references (const char *name, // Get the list of initial reference prefixes specified through // -ORBDefaultInitRef. char * default_init_ref = - this->orb_core_->orb_params ()->default_init_ref (); + this->orb_core ()->orb_params ()->default_init_ref (); // Check if a DefaultInitRef was specified. if (ACE_OS::strlen (default_init_ref) != 0) @@ -842,7 +1396,7 @@ CORBA_ORB::resolve_initial_references (const char *name, // Obtain the appropriate object key delimiter for the // specified protocol. const char object_key_delimiter = - this->orb_core_->connector_registry ()->object_key_delimiter ( + this->orb_core ()->connector_registry ()->object_key_delimiter ( list_of_profiles.c_str ()); // Make sure that the default initial reference doesn't end @@ -883,8 +1437,11 @@ CORBA_ORB::resolve_initial_references (const char *name, CORBA_ORB_ObjectIdList_ptr CORBA_ORB::list_initial_services (CORBA::Environment &ACE_TRY_ENV) { + this->check_shutdown (ACE_TRY_ENV); + ACE_CHECK_RETURN (0); + TAO_IOR_LookupTable *table = - this->orb_core_->orb_params ()->ior_lookup_table (); + this->orb_core ()->orb_params ()->ior_lookup_table (); return table->list_initial_services (ACE_TRY_ENV); } @@ -894,6 +1451,9 @@ CORBA_ORB::create_stub_object (const TAO_ObjectKey &key, const char *type_id, CORBA::Environment &ACE_TRY_ENV) { + this->check_shutdown (ACE_TRY_ENV); + ACE_CHECK_RETURN (0); + return this->orb_core_->create_stub_object (key, type_id, ACE_TRY_ENV); @@ -908,6 +1468,9 @@ CORBA_ORB::key_to_object (const TAO_ObjectKey &key, CORBA::Boolean collocated, CORBA::Environment &ACE_TRY_ENV) { + this->check_shutdown (ACE_TRY_ENV); + ACE_CHECK_RETURN (CORBA::Object::_nil ()); + TAO_Stub *data = this->create_stub_object (key, type_id, ACE_TRY_ENV); ACE_CHECK_RETURN (CORBA::Object::_nil ()); @@ -934,8 +1497,23 @@ void CORBA_ORB::check_shutdown (CORBA_Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { - this->orb_core ()->check_shutdown (ACE_TRY_ENV); - ACE_CHECK; + if (this->orb_core () != 0) + { + this->orb_core ()->check_shutdown (ACE_TRY_ENV); + ACE_CHECK; + } + else + { + // If the ORB_Core pointer is zero, assume that the ORB_Core has + // been destroyed. + + // As defined by the CORBA 2.3 specification, throw a + // CORBA::OBJECT_NOT_EXIST exception with minor code 4 if the ORB + // has shutdown by the time an ORB function is called. + + ACE_THROW (CORBA::OBJECT_NOT_EXIST (TAO_DEFAULT_MINOR_CODE, + CORBA::COMPLETED_NO)); + } } #if !defined (TAO_HAS_MINIMUM_CORBA) @@ -1381,6 +1959,7 @@ CORBA::ORB_init (int &argc, } return CORBA::ORB::_duplicate (oc->orb ()); + } // @@ As part of the ORB re-architecture this will the point where @@ -1408,7 +1987,9 @@ CORBA::ORB_init (int &argc, CORBA::COMPLETED_NO), CORBA::ORB::_nil ()); - return oc->orb (); + // Return a duplicate since the ORB_Core should release the last + // reference to the ORB. + return CORBA::ORB::_duplicate (oc->orb ()); } // **************************************************************** @@ -1544,6 +2125,9 @@ CORBA_ORB::create_policy (CORBA::PolicyType type, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException, CORBA::PolicyError)) { + this->check_shutdown (ACE_TRY_ENV); + ACE_CHECK_RETURN (CORBA::Policy::_nil ()); + PortableServer::POA_var root_poa = this->orb_core_->root_poa_reference (ACE_TRY_ENV); ACE_CHECK_RETURN (CORBA::Policy::_nil ()); @@ -1741,13 +2325,17 @@ CORBA_ORB::url_ior_string_to_object (const char* str, void CORBA_ORB::_optimize_collocation_objects (CORBA::Boolean opt) { - this->orb_core_->optimize_collocation_objects (opt); + if (this->orb_core_ != 0) + this->orb_core_->optimize_collocation_objects (opt); } CORBA::Boolean CORBA_ORB::_optimize_collocation_objects (void) const { - return this->orb_core_->optimize_collocation_objects (); + if (this->orb_core_ != 0) + return this->orb_core_->optimize_collocation_objects (); + else + return 0; // Need to return something } TAO_SERVANT_LOCATION |