Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Environment.cpp

Go to the documentation of this file.
00001 #include "tao_pch.h"
00002 // $Id: Environment.cpp,v 1.1.1.4.2.1 2003/03/14 16:05:12 chad Exp $
00003 
00004 #include "tao/Environment.h"
00005 #include "tao/ORB_Core.h"
00006 #include "tao/Exception.h"
00007 
00008 #if !defined (__ACE_INLINE__)
00009 # include "tao/Environment.i"
00010 #endif /* __ACE_INLINE__ */
00011 
00012 
00013 ACE_RCSID(tao, Environment, "$Id: Environment.cpp,v 1.1.1.4.2.1 2003/03/14 16:05:12 chad Exp $")
00014 
00015 
00016 CORBA_Environment::CORBA_Environment (void)
00017   : exception_ (0)
00018   , previous_ (0)
00019 {
00020   //  TAO_ORB_Core_instance ()->default_environment (this);
00021 }
00022 
00023 CORBA_Environment::CORBA_Environment (const CORBA_Environment& rhs)
00024   : exception_ (0)
00025   , previous_ (0)
00026 {
00027   if (rhs.exception_)
00028     this->exception_ = rhs.exception_->_tao_duplicate ();
00029 }
00030 
00031 CORBA_Environment::CORBA_Environment (TAO_ORB_Core* orb_core)
00032   : exception_ (0)
00033   , previous_ (orb_core->default_environment ())
00034 {
00035   orb_core->default_environment (this);
00036 }
00037 
00038 CORBA_Environment&
00039 CORBA_Environment::operator= (const CORBA_Environment& rhs)
00040 {
00041   CORBA_Environment tmp (rhs);
00042   {
00043     CORBA_Exception *tmp_ex = this->exception_;
00044     this->exception_ = tmp.exception_;
00045     tmp.exception_ = tmp_ex;
00046   }
00047   {
00048     CORBA_Environment *tmp_env = this->previous_;
00049     this->previous_ = rhs.previous_;
00050     tmp.previous_ = tmp_env;
00051   }
00052   return *this;
00053 }
00054 
00055 CORBA_Environment::~CORBA_Environment (void)
00056 {
00057   this->clear ();
00058 
00059   // If previous is 0 then this is the first Environment, allocated
00060   // with the ORB, it shouldn't try to pop because the ORB is beign
00061   // destroyed also.
00062   if (this->previous_ != 0)
00063     TAO_ORB_Core_instance ()->default_environment (this->previous_);
00064 }
00065 
00066 void
00067 CORBA_Environment::exception (CORBA_Exception *ex)
00068 {
00069   // @@ This does not look right, setting the exception to the
00070   //    contained exception is a bug,  the application is only
00071   //    supposed to pass in a pointer to an exception that it (the
00072   //    application) owns, however, if we contain the exception then
00073   //    *WE* own it.
00074   //    Normally I (coryan) would remove code like this, but I feel
00075   //    that it is a typical example of defensive programming for the
00076   //    *BAD*, i.e. we are not helping the application to get better
00077   //    and only making the ORB bigger and slower.
00078 #if 0
00079   if (ex != this->exception_)
00080     {
00081       this->clear ();
00082     }
00083 #else
00084   ACE_ASSERT (ex != this->exception_);
00085   this->clear ();
00086 #endif /* 0 */
00087 
00088   this->exception_ = ex;
00089 
00090 #if defined (TAO_HAS_EXCEPTIONS)
00091   if (this->exception_ != 0)
00092     this->exception_->_raise ();
00093 #endif /* TAO_HAS_EXCEPTIONS */
00094 }
00095 
00096 void
00097 CORBA_Environment::clear (void)
00098 {
00099   delete this->exception_;
00100   this->exception_ = 0;
00101 }
00102 
00103 CORBA_Environment&
00104 CORBA_Environment::default_environment ()
00105 {
00106 #if defined (TAO_HAS_EXCEPTIONS)
00107   //
00108   // If we are using native C++ exceptions the user is *not* supposed
00109   // to clear the environment every time she calls into TAO, in fact
00110   // the user is not supposed to use the environment at all!
00111   //
00112   // But TAO is using the default environment internally, thus
00113   // somebody has to clear it. Since TAO passes the environment around
00114   // this function should only be called when going from the user code
00115   // into TAO's code.
00116   //
00117   // This is not an issue when using the alternative C++ mapping (with
00118   // the Environment argument) because then the user is supposed to
00119   // clear the environment before calling into the ORB.
00120   //
00121   TAO_ORB_Core_instance ()->default_environment ()->clear ();
00122 #endif /* TAO_HAS_EXCEPTIONS */
00123 
00124   return CORBA::default_environment ();
00125 }
00126 
00127 // Convenience -- say if the exception is a system exception or not.
00128 
00129 int
00130 CORBA::Environment::exception_type (void) const
00131 {
00132   // @@ Carlos, is this stuff that's properly "transformed" for EBCDIC
00133   //    platforms?!
00134   // @@ Doug: Yes, they are used to compare against the _id() of the
00135   //    exception, which should have been mappend to the native
00136   //    codeset.  Notice the "should" we haven't tried that stuff yet,
00137   //    and i find it hard to keep track of all the transformations
00138   //    going on, specially for the TypeCodes that are generated by
00139   //    the IDL compiler vs. the ones hard-coded in
00140   //    $TAO_ROOT/tao/Typecode_Constants.cpp
00141 
00142   static char sysex_prefix [] = "IDL:omg.org/CORBA/";
00143   static char typecode_extra [] = "TypeCode/";
00144 
00145   if (!this->exception_)
00146     return CORBA::NO_EXCEPTION;
00147 
00148   // All exceptions currently (CORBA 2.0) defined in the CORBA scope
00149   // are system exceptions ... except for a couple that are related to
00150   // TypeCodes.
00151 
00152   const char *id = this->exception_->_rep_id ();
00153 
00154   if ((ACE_OS::strncmp (id,
00155                         sysex_prefix,
00156                         sizeof sysex_prefix - 1) == 0
00157        && ACE_OS::strncmp (id + sizeof sysex_prefix - 1,
00158                            typecode_extra,
00159                            sizeof typecode_extra - 1) != 0))
00160     return CORBA::SYSTEM_EXCEPTION;
00161   else
00162     return CORBA::USER_EXCEPTION;
00163 }
00164 
00165 const char*
00166 CORBA_Environment::exception_id (void) const
00167 {
00168   if (this->exception_ == 0)
00169     return 0;
00170 
00171   return this->exception_->_rep_id ();
00172 }
00173 
00174 // Diagnostic utility routine: describe the exception onto the
00175 // standard I/O stream passed as a parameter.
00176 
00177 void
00178 CORBA::Environment::print_exception (const char *info,
00179                                      FILE *) const
00180 {
00181   if (this->exception_)
00182     {
00183       const char *id = this->exception_->_rep_id ();
00184 
00185       ACE_DEBUG ((LM_ERROR,
00186                   ACE_TEXT ("TAO: (%P|%t) EXCEPTION, %s\n"),
00187                   info));
00188 
00189       CORBA::SystemException *x2 =
00190         CORBA_SystemException::_downcast (this->exception_);
00191 
00192       if (x2 != 0)
00193         x2->_tao_print_system_exception ();
00194       else
00195         // @@ we can use the exception's typecode to dump all the data
00196         // held within it ...
00197 
00198         ACE_DEBUG ((LM_ERROR,
00199                     ACE_TEXT ("TAO: (%P|%t) user exception, ID '%s'\n"),
00200                     id));
00201     }
00202   else
00203     ACE_DEBUG ((LM_ERROR,
00204                 ACE_TEXT ("TAO: (%P|%t) no exception, %s\n"), info));
00205 }
00206 
00207 CORBA_Environment_var &
00208 CORBA_Environment_var::operator= (CORBA_Environment_ptr p)
00209 {
00210   CORBA_Environment_var tmp (p);
00211   // @@ We need as ACE_Swap<> template!!
00212   CORBA_Environment *tmp_ptr = this->ptr_;
00213   this->ptr_ = tmp.ptr_;
00214   tmp.ptr_ = tmp_ptr;
00215   return *this;
00216 }
00217 
00218 CORBA_Environment_var &
00219 CORBA_Environment_var::operator= (const CORBA_Environment_var &r)
00220 {
00221   CORBA_Environment_var tmp (r);
00222   // @@ We need as ACE_Swap<> template!!
00223   CORBA_Environment *tmp_ptr = this->ptr_;
00224   this->ptr_ = tmp.ptr_;
00225   tmp.ptr_ = tmp_ptr;
00226   return *this;
00227 }

Generated on Mon Jun 16 13:48:22 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002