#include <Environment.h>
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. | |
Environment & | operator= (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::Environment & | default_environment (void) |
Public Attributes | |
CORBA::Exception *exception void | const |
Return the contained CORBA::Exception. | |
void exception CORBA::Exception * | ex |
Set the contained CORBA::Exception to <ex> | |
Private Member Functions | |
Environment (TAO_ORB_Core *orb_core) | |
Private Attributes | |
CORBA::Exception * | exception_ |
Pointer to the exception object contained in the environment. | |
Environment * | previous_ |
The previous environment on the "default environment stack". |
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.
Definition at line 137 of file Environment.h.
Definition at line 135 of file Environment.h.
Definition at line 136 of file Environment.h.
CORBA::Environment::Environment | ( | void | ) |
The default constructor. The environment will hold no exceptions.
Definition at line 20 of file Environment.cpp.
: exception_ (0) , previous_ (0) { }
CORBA::Environment::Environment | ( | const Environment & | ACE_TRY_ENV | ) |
Copy constructor.
Definition at line 26 of file Environment.cpp.
: exception_ (0) , previous_ (0) { if (rhs.exception_) this->exception_ = rhs.exception_->_tao_duplicate (); }
CORBA::Environment::~Environment | ( | void | ) |
Destructor, release the exception.
Definition at line 58 of file Environment.cpp.
{ this->clear (); // If previous is 0 then this is the first Environment, allocated // with the ORB, it shouldn't try to pop because the ORB is beign // destroyed also. if (this->previous_ != 0) TAO_ORB_Core_instance ()->default_environment (this->previous_); }
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.
: exception_ (0) , previous_ (orb_core->default_environment ()) { orb_core->default_environment (this); }
CORBA::Environment * CORBA::Environment::_duplicate | ( | CORBA::Environment * | x | ) | [static] |
Some static methods that need to be defined in every pseudo object.
Definition at line 33 of file Environment.inl.
{ if (x == 0) { return 0; } CORBA::Environment* ptr = 0; ACE_NEW_RETURN (ptr, CORBA::Environment (*x), 0); return ptr; }
CORBA::Environment_ptr CORBA::Environment::_nil | ( | void | ) | [static] |
Definition at line 49 of file Environment.inl.
{ return static_cast <CORBA::Environment_ptr> (0); }
void CORBA::Environment::clear | ( | void | ) |
Clear the exception.
Definition at line 98 of file Environment.cpp.
{ delete this->exception_; this->exception_ = 0; }
CORBA::Environment & CORBA::Environment::default_environment | ( | void | ) | [static] |
Definition at line 105 of file Environment.cpp.
{ // // If we are using native C++ exceptions the user is *not* supposed // to clear the environment every time she calls into TAO. In fact // the user is not supposed to use the environment at all! // // But TAO is using the default environment internally, thus // somebody has to clear it. Since TAO passes the environment around // this function should only be called when going from the user code // into TAO's code. // // This is not an issue when using the alternative C++ mapping (with // the Environment argument) because then the user is supposed to // clear the environment before calling into the ORB. // TAO_ORB_Core_instance ()->default_environment ()->clear (); return TAO_default_environment ();; }
const char * CORBA::Environment::exception_id | ( | void | ) | const |
return the repository ID for the exception.
Definition at line 167 of file Environment.cpp.
{ if (this->exception_ == 0) return 0; return this->exception_->_rep_id (); }
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.
{ // @@ Carlos, is this stuff that's properly "transformed" for EBCDIC // platforms?! // @@ Doug: Yes, they are used to compare against the _id() of the // exception, which should have been mappend to the native // codeset. Notice the "should" we haven't tried that stuff yet, // and i find it hard to keep track of all the transformations // going on, specially for the TypeCodes that are generated by // the IDL compiler vs. the ones hard-coded in // $TAO_ROOT/tao/Typecode_Constants.cpp static char sysex_prefix [] = "IDL:omg.org/CORBA/"; static char typecode_extra [] = "TypeCode/"; if (!this->exception_) { return CORBA::NO_EXCEPTION; } // All exceptions currently (CORBA 2.0) defined in the CORBA scope // are system exceptions ... except for a couple that are related to // TypeCodes. const char *id = this->exception_->_rep_id (); if ((ACE_OS::strncmp (id, sysex_prefix, sizeof sysex_prefix - 1) == 0 && ACE_OS::strncmp (id + sizeof sysex_prefix - 1, typecode_extra, sizeof typecode_extra - 1) != 0)) return CORBA::SYSTEM_EXCEPTION; else return CORBA::USER_EXCEPTION; }
CORBA::Environment & CORBA::Environment::operator= | ( | const Environment & | ACE_TRY_ENV | ) |
Assingment.
Definition at line 42 of file Environment.cpp.
{ CORBA::Environment tmp (rhs); { CORBA::Exception *tmp_ex = this->exception_; this->exception_ = tmp.exception_; tmp.exception_ = tmp_ex; } { CORBA::Environment *tmp_env = this->previous_; this->previous_ = rhs.previous_; tmp.previous_ = tmp_env; } return *this; }
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.
{ if (this->exception_) { const char *id = this->exception_->_rep_id (); ACE_ERROR ((LM_ERROR, ACE_TEXT ("TAO: (%P|%t) EXCEPTION, %C\n"), info)); CORBA::SystemException *x2 = CORBA::SystemException::_downcast (this->exception_); if (x2 != 0) x2->_tao_print_system_exception (); else // @@ we can use the exception's typecode to dump all the data // held within it ... ACE_ERROR ((LM_ERROR, ACE_TEXT ("TAO: (%P|%t) user exception, ID '%C'\n"), id)); } else ACE_ERROR ((LM_ERROR, ACE_TEXT ("TAO: (%P|%t) no exception, %C\n"), info)); }
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.
Environment* CORBA::Environment::previous_ [private] |
The previous environment on the "default environment stack".
Definition at line 150 of file Environment.h.