CORBA::Environment Class Reference

Environment. More...

#include <Environment.h>

Collaboration diagram for CORBA::Environment:

Collaboration graph
[legend]
List of all members.

Public Types

typedef CORBA::Environment_ptr _ptr_type
typedef CORBA::Environment_var _var_type
typedef CORBA::Environment_out _out_type

Public Member Functions

 Environment (void)
 Environment (const Environment &ACE_TRY_ENV)
 Copy constructor.
Environmentoperator= (const Environment &ACE_TRY_ENV)
 Assingment.
 ~Environment (void)
 Destructor, release the exception.
int exception_type (void) const
const char * exception_id (void) const
 return the repository ID for the exception.
void clear (void)
 Clear the exception.
void print_exception (const char *info, FILE *f=stdout) const

Static Public Member Functions

static Environment_duplicate (Environment *)
 Some static methods that need to be defined in every pseudo object.
static Environment_nil (void)
static CORBA::Environmentdefault_environment (void)

Public Attributes

CORBA::Exception *exception
void 
const
 Return the contained CORBA::Exception.
void exception CORBA::Exceptionex
 Set the contained CORBA::Exception to <ex>.

Private Member Functions

 Environment (TAO_ORB_Core *orb_core)

Private Attributes

CORBA::Exceptionexception_
 Pointer to the exception object contained in the environment.
Environmentprevious_
 The previous environment on the "default environment stack".

Detailed Description

Environment.

A CORBA::Environment is a way to automagically ensure that exception data is freed -- the "var" class for Exceptions. It adds just a bit of convenience function support, helping classify exceptions as well as reducing memory leakage. The thread has a default environment to simplify porting between platforms that support native C++ exceptions and those that don't. This is a TSS resource (always), but with a twist: if the user creates a new environment the old one is "pushed" (actually the new one remembers it), eventually the new environment destructor pops itself from the stack and we recover the old environment. This means that if the user create a new environment and somebody calls a function using the default one the exception will still be received in the environment created by the user. The only drawback is that environments life time must nest properly, this shouldn't be a problem because environments are usually created on the stack, but, the spec allows their creation on the heap and/or as class members; we need to investigate the tradeoffs and take a decision.

Definition at line 73 of file Environment.h.


Member Typedef Documentation

typedef CORBA::Environment_out CORBA::Environment::_out_type

Definition at line 137 of file Environment.h.

typedef CORBA::Environment_ptr CORBA::Environment::_ptr_type

Definition at line 135 of file Environment.h.

typedef CORBA::Environment_var CORBA::Environment::_var_type

Definition at line 136 of file Environment.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL CORBA::Environment::Environment ( void   ) 

The default constructor. The environment will hold no exceptions.

Definition at line 20 of file Environment.cpp.

00021   : exception_ (0)
00022   , previous_ (0)
00023 {
00024 }

CORBA::Environment::Environment ( const Environment ACE_TRY_ENV  ) 

Copy constructor.

Definition at line 26 of file Environment.cpp.

References CORBA::Exception::_tao_duplicate(), and exception_.

00027   : exception_ (0)
00028   , previous_ (0)
00029 {
00030   if (rhs.exception_)
00031     this->exception_ = rhs.exception_->_tao_duplicate ();
00032 }

CORBA::Environment::~Environment ( void   ) 

Destructor, release the exception.

Definition at line 58 of file Environment.cpp.

References clear(), TAO_ORB_Core::default_environment(), and TAO_ORB_Core_instance().

00059 {
00060   this->clear ();
00061 
00062   // If previous is 0 then this is the first Environment, allocated
00063   // with the ORB, it shouldn't try to pop because the ORB is beign
00064   // destroyed also.
00065   if (this->previous_ != 0)
00066     TAO_ORB_Core_instance ()->default_environment (this->previous_);
00067 }

CORBA::Environment::Environment ( TAO_ORB_Core orb_core  )  [private]

Initialize using a well known ORB Core; this is intended for the bootstraping of the ORB_Core, not for general consumption.

Definition at line 34 of file Environment.cpp.

References TAO_ORB_Core::default_environment().

00035   : exception_ (0)
00036   , previous_ (orb_core->default_environment ())
00037 {
00038   orb_core->default_environment (this);
00039 }


Member Function Documentation

ACE_INLINE CORBA::Environment * CORBA::Environment::_duplicate ( Environment  )  [static]

Some static methods that need to be defined in every pseudo object.

Definition at line 33 of file Environment.inl.

References ACE_NEW_RETURN.

00034 {
00035   if (x == 0)
00036     {
00037       return 0;
00038     }
00039 
00040   CORBA::Environment* ptr = 0;
00041   ACE_NEW_RETURN (ptr,
00042                   CORBA::Environment (*x),
00043                   0);
00044   return ptr;
00045 }

ACE_INLINE CORBA::Environment_ptr CORBA::Environment::_nil ( void   )  [static]

Definition at line 49 of file Environment.inl.

00050 {
00051   return static_cast <CORBA::Environment_ptr> (0);
00052 }

void CORBA::Environment::clear ( void   ) 

Clear the exception.

Definition at line 98 of file Environment.cpp.

References exception_.

Referenced by default_environment(), and ~Environment().

00099 {
00100   delete this->exception_;
00101   this->exception_ = 0;
00102 }

CORBA::Environment & CORBA::Environment::default_environment ( void   )  [static]

Definition at line 105 of file Environment.cpp.

References clear(), TAO_ORB_Core::default_environment(), TAO_default_environment(), and TAO_ORB_Core_instance().

00106 {
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 
00123   return TAO_default_environment ();;
00124 }

const char * CORBA::Environment::exception_id ( void   )  const

return the repository ID for the exception.

Definition at line 167 of file Environment.cpp.

References CORBA::Exception::_rep_id(), and exception_.

00168 {
00169   if (this->exception_ == 0)
00170     return 0;
00171 
00172   return this->exception_->_rep_id ();
00173 }

int CORBA::Environment::exception_type ( void   )  const

Return if the exception is a user exception or a system exception.

Definition at line 129 of file Environment.cpp.

References CORBA::Exception::_rep_id(), exception_, CORBA::NO_EXCEPTION, ACE_OS::strncmp(), CORBA::SYSTEM_EXCEPTION, and CORBA::USER_EXCEPTION.

00130 {
00131   // @@ Carlos, is this stuff that's properly "transformed" for EBCDIC
00132   //    platforms?!
00133   // @@ Doug: Yes, they are used to compare against the _id() of the
00134   //    exception, which should have been mappend to the native
00135   //    codeset.  Notice the "should" we haven't tried that stuff yet,
00136   //    and i find it hard to keep track of all the transformations
00137   //    going on, specially for the TypeCodes that are generated by
00138   //    the IDL compiler vs. the ones hard-coded in
00139   //    $TAO_ROOT/tao/Typecode_Constants.cpp
00140 
00141   static char sysex_prefix [] = "IDL:omg.org/CORBA/";
00142   static char typecode_extra [] = "TypeCode/";
00143 
00144   if (!this->exception_)
00145     {
00146       return CORBA::NO_EXCEPTION;
00147     }
00148 
00149   // All exceptions currently (CORBA 2.0) defined in the CORBA scope
00150   // are system exceptions ... except for a couple that are related to
00151   // TypeCodes.
00152 
00153   const char *id = this->exception_->_rep_id ();
00154 
00155   if ((ACE_OS::strncmp (id,
00156                         sysex_prefix,
00157                         sizeof sysex_prefix - 1) == 0
00158        && ACE_OS::strncmp (id + sizeof sysex_prefix - 1,
00159                            typecode_extra,
00160                            sizeof typecode_extra - 1) != 0))
00161     return CORBA::SYSTEM_EXCEPTION;
00162   else
00163     return CORBA::USER_EXCEPTION;
00164 }

CORBA::Environment & CORBA::Environment::operator= ( const Environment ACE_TRY_ENV  ) 

Assingment.

Definition at line 42 of file Environment.cpp.

References exception_, and previous_.

00043 {
00044   CORBA::Environment tmp (rhs);
00045   {
00046     CORBA::Exception *tmp_ex = this->exception_;
00047     this->exception_ = tmp.exception_;
00048     tmp.exception_ = tmp_ex;
00049   }
00050   {
00051     CORBA::Environment *tmp_env = this->previous_;
00052     this->previous_ = rhs.previous_;
00053     tmp.previous_ = tmp_env;
00054   }
00055   return *this;
00056 }

void CORBA::Environment::print_exception ( const char *  info,
FILE *  f = stdout 
) const

Print the exception to output determined by f. This function is not CORBA compliant.

Definition at line 179 of file Environment.cpp.

References CORBA::SystemException::_downcast(), CORBA::Exception::_rep_id(), CORBA::SystemException::_tao_print_system_exception(), ACE_ERROR, ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, exception_, and LM_ERROR.

00181 {
00182   if (this->exception_)
00183     {
00184       const char *id = this->exception_->_rep_id ();
00185 
00186       ACE_ERROR ((LM_ERROR,
00187                   ACE_TEXT ("TAO: (%P|%t) EXCEPTION, %s\n"),
00188                   ACE_TEXT_CHAR_TO_TCHAR (info)));
00189 
00190       CORBA::SystemException *x2 =
00191         CORBA::SystemException::_downcast (this->exception_);
00192 
00193       if (x2 != 0)
00194         x2->_tao_print_system_exception ();
00195       else
00196         // @@ we can use the exception's typecode to dump all the data
00197         // held within it ...
00198 
00199         ACE_ERROR ((LM_ERROR,
00200                     ACE_TEXT ("TAO: (%P|%t) user exception, ID '%s'\n"),
00201                     ACE_TEXT_CHAR_TO_TCHAR (id)));
00202     }
00203   else
00204     ACE_ERROR ((LM_ERROR,
00205                 ACE_TEXT ("TAO: (%P|%t) no exception, %s\n"), ACE_TEXT_CHAR_TO_TCHAR (info)));
00206 }


Member Data Documentation

CORBA::Exception* exception void CORBA::Environment::const

Return the contained CORBA::Exception.

CORBA::Environment retains ownership of the exception, this is contrary to the normal memory management rules in the C++ mapping, but actually mandated by the specification:

"C++ Language Mapping" (formal/00-01-02). Section 1.27 Environment (page 1-113)

Definition at line 102 of file Environment.h.

void exception CORBA::Exception* CORBA::Environment::ex

Set the contained CORBA::Exception to <ex>.

CORBA::Environment assumes ownership of the exception, this is contrary to the normal memory management rules in the C++ mapping, but actually mandated by the specification:

"C++ Language Mapping" (formal/00-01-02). Section 1.27 Environment (page 1-113)

Definition at line 114 of file Environment.h.

CORBA::Exception* CORBA::Environment::exception_ [private]

Pointer to the exception object contained in the environment.

Definition at line 147 of file Environment.h.

Referenced by clear(), Environment(), exception_id(), exception_type(), operator=(), and print_exception().

Environment* CORBA::Environment::previous_ [private]

The previous environment on the "default environment stack".

Definition at line 150 of file Environment.h.

Referenced by operator=().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:39:56 2010 for TAO by  doxygen 1.4.7