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

CORBA_Environment Class Reference

CORBA_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

Public Methods

 CORBA_Environment (void)
 The default constructor, the environment will hold no exceptions. More...

 CORBA_Environment (const CORBA_Environment &ACE_TRY_ENV)
 Copy constructor. More...

CORBA_Environment & operator= (const CORBA_Environment &ACE_TRY_ENV)
 Assingment. More...

 ~CORBA_Environment (void)
 Destructor, release the exception. More...

int exception_type (void) const
 Return if the exception is a user exception or a system exception. More...

const char * exception_id (void) const
 return the repository ID for the exception. More...

void clear (void)
 Clear the exception. More...

void print_exception (const char *info, FILE *f=stdout) const
 Print the exception to output determined by f. This function is not CORBA compliant. More...


Static Public Methods

CORBA_Environment * _duplicate (CORBA_Environment *)
 Some static methods that need to be defined in every pseudo object. More...

CORBA_Environment * _nil (void)
CORBA_Environment & default_environment (void)

Public Attributes

CORBA_Exception *exception
void 
const
 Return the contained CORBA::Exception. More...

void exception CORBA_Exceptionex
 Set the contained CORBA::Exception to <ex>. More...


Private Methods

 CORBA_Environment (TAO_ORB_Core *orb_core)

Private Attributes

CORBA_Exceptionexception_
 Pointer to the exception object contained in the environment. More...

CORBA_Environment * previous_
 The previous environment on the "default environment stack". More...


Friends

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


Detailed Description

CORBA_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 58 of file Environment.h.


Member Typedef Documentation

typedef CORBA_Environment_ptr CORBA_Environment::_ptr_type
 

Definition at line 121 of file Environment.h.

typedef CORBA_Environment_var CORBA_Environment::_var_type
 

Definition at line 122 of file Environment.h.


Constructor & Destructor Documentation

CORBA_Environment::CORBA_Environment void   
 

The default constructor, the environment will hold no exceptions.

Definition at line 16 of file Environment.cpp.

Referenced by _duplicate.

00017   : exception_ (0)
00018   , previous_ (0)
00019 {
00020   //  TAO_ORB_Core_instance ()->default_environment (this);
00021 }

CORBA_Environment::CORBA_Environment const CORBA_Environment &    ACE_TRY_ENV
 

Copy constructor.

Definition at line 23 of file Environment.cpp.

References CORBA_Exception::_tao_duplicate, and exception_.

00024   : exception_ (0)
00025   , previous_ (0)
00026 {
00027   if (rhs.exception_)
00028     this->exception_ = rhs.exception_->_tao_duplicate ();
00029 }

CORBA_Environment::~CORBA_Environment void   
 

Destructor, release the exception.

Definition at line 55 of file Environment.cpp.

References clear, TAO_ORB_Core::default_environment, previous_, and TAO_ORB_Core_instance.

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 }

CORBA_Environment::CORBA_Environment TAO_ORB_Core   orb_core [private]
 

Definition at line 31 of file Environment.cpp.

References CORBA::default_environment.

00032   : exception_ (0)
00033   , previous_ (orb_core->default_environment ())
00034 {
00035   orb_core->default_environment (this);
00036 }


Member Function Documentation

ACE_INLINE CORBA_Environment * CORBA_Environment::_duplicate CORBA_Environment *    [static]
 

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

Definition at line 25 of file Environment.i.

References CORBA_Environment.

00026 {
00027   if (x == 0)
00028     return 0;
00029   return new CORBA_Environment (*x);
00030 }

ACE_INLINE CORBA_Environment_ptr CORBA_Environment::_nil void    [static]
 

Definition at line 33 of file Environment.i.

00034 {
00035   return (CORBA_Environment_ptr)0;
00036 }

void CORBA_Environment::clear void   
 

Clear the exception.

Definition at line 97 of file Environment.cpp.

References exception_.

Referenced by default_environment, and ~CORBA_Environment.

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

CORBA_Environment & CORBA_Environment::default_environment void    [static]
 

Definition at line 104 of file Environment.cpp.

References clear, CORBA::default_environment, TAO_ORB_Core::default_environment, and TAO_ORB_Core_instance.

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 }

const char * CORBA_Environment::exception_id void    const
 

return the repository ID for the exception.

Definition at line 166 of file Environment.cpp.

References CORBA_Exception::_rep_id, and exception_.

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

int CORBA_Environment::exception_type void    const
 

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

CORBA_Environment & CORBA_Environment::operator= const CORBA_Environment &    ACE_TRY_ENV
 

Assingment.

Definition at line 39 of file Environment.cpp.

References exception_, and previous_.

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 }

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.


Friends And Related Function Documentation

friend class TAO_ORB_Core [friend]
 

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

Definition at line 130 of file Environment.h.


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 88 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 100 of file Environment.h.

CORBA_Exception* CORBA_Environment::exception_ [private]
 

Pointer to the exception object contained in the environment.

Definition at line 134 of file Environment.h.

Referenced by clear, CORBA_Environment, exception_id, and operator=.

CORBA_Environment* CORBA_Environment::previous_ [private]
 

The previous environment on the "default environment stack".

Definition at line 137 of file Environment.h.

Referenced by operator=, and ~CORBA_Environment.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 14:57:39 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002