1 #include "tao/Environment.h"
2 #include "tao/ORB_Core.h"
3 #include "tao/SystemException.h"
4 #include "tao/default_environment.h"
6 #include "ace/OS_NS_string.h"
8 #if !defined (__ACE_INLINE__)
9 # include "tao/Environment.inl"
10 #endif /* __ACE_INLINE__ */
12 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
14 CORBA::Environment::Environment (const CORBA::Environment
& rhs
)
15 : exception_ (nullptr)
19 this->exception_
= rhs
.exception_
->_tao_duplicate ();
22 CORBA::Environment::Environment (TAO_ORB_Core
* orb_core
)
23 : exception_ (nullptr)
24 , previous_ (orb_core
->default_environment ())
26 orb_core
->default_environment (this);
30 CORBA::Environment::operator= (const CORBA::Environment
& rhs
)
32 CORBA::Environment
tmp (rhs
);
34 CORBA::Exception
*tmp_ex
= this->exception_
;
35 this->exception_
= tmp
.exception_
;
36 tmp
.exception_
= tmp_ex
;
39 CORBA::Environment
*tmp_env
= this->previous_
;
40 this->previous_
= rhs
.previous_
;
41 tmp
.previous_
= tmp_env
;
46 CORBA::Environment::~Environment ()
50 // If previous is 0 then this is the first Environment, allocated
51 // with the ORB, it shouldn't try to pop because the ORB is being
53 if (this->previous_
!= nullptr)
54 TAO_ORB_Core_instance ()->default_environment (this->previous_
);
58 CORBA::Environment::exception (CORBA::Exception
*ex
)
60 // @@ This does not look right, setting the exception to the
61 // contained exception is a bug, the application is only
62 // supposed to pass in a pointer to an exception that it (the
63 // application) owns, however, if we contain the exception then
65 // Normally I (coryan) would remove code like this, but I feel
66 // that it is a typical example of defensive programming for the
67 // *BAD*, i.e. we are not helping the application to get better
68 // and only making the ORB bigger and slower.
70 if (ex
!= this->exception_
)
75 ACE_ASSERT (ex
!= this->exception_
);
79 this->exception_
= ex
;
81 if (this->exception_
!= nullptr)
82 this->exception_
->_raise ();
86 CORBA::Environment::clear ()
88 delete this->exception_
;
89 this->exception_
= nullptr;
93 CORBA::Environment::default_environment ()
95 // If we are using native C++ exceptions the user is *not* supposed
96 // to clear the environment every time she calls into TAO. In fact
97 // the user is not supposed to use the environment at all!
99 // But TAO is using the default environment internally, thus
100 // somebody has to clear it. Since TAO passes the environment around
101 // this function should only be called when going from the user code
104 // This is not an issue when using the alternative C++ mapping (with
105 // the Environment argument) because then the user is supposed to
106 // clear the environment before calling into the ORB.
107 TAO_ORB_Core_instance ()->default_environment ()->clear ();
109 return TAO_default_environment ();
112 // Convenience -- say if the exception is a system exception or not.
115 CORBA::Environment::exception_type () const
117 // @@ Carlos, is this stuff that's properly "transformed" for EBCDIC
119 // @@ Doug: Yes, they are used to compare against the _id() of the
120 // exception, which should have been mappend to the native
121 // codeset. Notice the "should" we haven't tried that stuff yet,
122 // and i find it hard to keep track of all the transformations
123 // going on, specially for the TypeCodes that are generated by
124 // the IDL compiler vs. the ones hard-coded in
125 // $TAO_ROOT/tao/Typecode_Constants.cpp
127 static char sysex_prefix
[] = "IDL:omg.org/CORBA/";
128 static char typecode_extra
[] = "TypeCode/";
130 if (!this->exception_
)
132 return CORBA::NO_EXCEPTION
;
135 // All exceptions currently (CORBA 2.0) defined in the CORBA scope
136 // are system exceptions ... except for a couple that are related to
139 const char *id
= this->exception_
->_rep_id ();
141 if ((ACE_OS::strncmp (id
,
143 sizeof sysex_prefix
- 1) == 0
144 && ACE_OS::strncmp (id
+ sizeof sysex_prefix
- 1,
146 sizeof typecode_extra
- 1) != 0))
147 return CORBA::SYSTEM_EXCEPTION
;
149 return CORBA::USER_EXCEPTION
;
153 CORBA::Environment::exception_id () const
155 if (this->exception_
== nullptr)
158 return this->exception_
->_rep_id ();
161 // Diagnostic utility routine: describe the exception onto the
162 // standard I/O stream passed as a parameter.
165 CORBA::Environment::print_exception (const char *info
,
168 if (this->exception_
)
170 const char *id
= this->exception_
->_rep_id ();
172 TAOLIB_ERROR ((LM_ERROR
,
173 ACE_TEXT ("TAO: (%P|%t) EXCEPTION, %C\n"),
176 CORBA::SystemException
*x2
=
177 CORBA::SystemException::_downcast (this->exception_
);
180 x2
->_tao_print_system_exception ();
182 // @@ we can use the exception's typecode to dump all the data
183 // held within it ...
185 TAOLIB_ERROR ((LM_ERROR
,
186 ACE_TEXT ("TAO: (%P|%t) user exception, ID '%C'\n"),
190 TAOLIB_ERROR ((LM_ERROR
,
191 ACE_TEXT ("TAO: (%P|%t) no exception, %C\n"), info
));
194 TAO_END_VERSIONED_NAMESPACE_DECL