Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Invocation_Base.cpp
blob0af8f490d8feb2b8150a201f01ff2f5b7b95e9ab
1 #include "tao/Invocation_Base.h"
2 #include "tao/Stub.h"
3 #include "tao/operation_details.h"
4 #include "tao/ORB_Core.h"
5 #include "tao/SystemException.h"
6 #include "tao/PortableInterceptor.h" /* Must always be visible. */
8 #include "ace/Dynamic_Service.h"
10 #if TAO_HAS_INTERCEPTORS == 1
11 # include "tao/PortableInterceptorC.h"
12 #endif /* TAO_HAS_INTERCEPTORS == 1 */
14 #if !defined (__ACE_INLINE__)
15 # include "tao/Invocation_Base.inl"
16 #endif /* __ACE_INLINE__ */
18 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
20 namespace
22 // Exception used to represent non-CORBA exceptions. A global
23 // instance is used since it will never be modified.
24 CORBA::UNKNOWN /* const */ unknown_exception;
27 namespace TAO
29 Invocation_Base::Invocation_Base (CORBA::Object_ptr ot,
30 CORBA::Object_ptr t,
31 TAO_Stub *stub,
32 TAO_Operation_Details &details,
33 bool response_expected,
34 bool TAO_INTERCEPTOR (request_is_remote))
35 : details_ (details)
36 , forwarded_to_ (nullptr)
37 , response_expected_ (response_expected)
38 , reply_status_ (GIOP::NO_EXCEPTION)
39 , otarget_ (ot)
40 , target_ (t)
41 , stub_ (stub)
42 #if TAO_HAS_INTERCEPTORS == 1
43 , cri_adapter_ (stub_->orb_core ()->clientrequestinterceptor_adapter ())
44 , sri_adapter_ (stub_->orb_core ()->serverrequestinterceptor_adapter ())
45 , stack_size_ (0)
46 , invoke_status_ (TAO_INVOKE_START)
47 , caught_exception_ (nullptr)
48 , is_remote_request_ (request_is_remote)
49 #endif /* TAO_HAS_INTERCEPTORS == 1 */
53 Invocation_Base::~Invocation_Base ()
55 TAO_INTERCEPTOR (cri_adapter_= nullptr);
56 TAO_INTERCEPTOR (sri_adapter_= nullptr);
59 TAO_Service_Context &
60 Invocation_Base::request_service_context ()
62 return this->details_.request_service_context ();
65 TAO_Service_Context &
66 Invocation_Base::reply_service_context ()
68 return this->details_.reply_service_context ();
71 #if TAO_HAS_INTERCEPTORS == 1
72 Invocation_Status
73 Invocation_Base::send_request_interception ()
75 if (cri_adapter_)
77 try
79 // This is a begin interception point
80 this->cri_adapter_->send_request (*this);
82 catch ( ::CORBA::Exception& ex)
84 (void) this->handle_any_exception (&ex);
85 throw;
87 catch (...)
89 (void) this->handle_all_exception ();
90 throw;
93 if (this->reply_status_ == GIOP::LOCATION_FORWARD)
94 return TAO_INVOKE_RESTART;
96 this->cri_adapter_->pushTSC (this->stub_->orb_core ());
98 else if (sri_adapter_)
100 this->sri_adapter_->pushTSC (this->stub_->orb_core ());
103 // What are the other cases??
104 return TAO_INVOKE_SUCCESS;
107 Invocation_Status
108 Invocation_Base::receive_reply_interception ()
110 if (cri_adapter_)
114 this->cri_adapter_->popTSC (this->stub_->orb_core ());
115 this->cri_adapter_->receive_reply (*this);
117 catch ( ::CORBA::Exception& ex)
119 (void) this->handle_any_exception (&ex);
120 throw;
122 catch (...)
124 (void) this->handle_all_exception ();
125 throw;
128 if (this->reply_status_ == GIOP::LOCATION_FORWARD)
129 return TAO_INVOKE_RESTART;
131 else if (sri_adapter_)
133 this->sri_adapter_->popTSC (this->stub_->orb_core ());
136 return TAO_INVOKE_SUCCESS;
139 Invocation_Status
140 Invocation_Base::receive_other_interception ()
142 if (cri_adapter_)
146 this->cri_adapter_->popTSC (this->stub_->orb_core ());
147 this->cri_adapter_->receive_other (*this);
149 catch ( ::CORBA::Exception& ex)
151 (void) this->handle_any_exception (&ex);
152 throw;
154 catch (...)
156 (void) this->handle_all_exception ();
157 throw;
160 if (this->reply_status_ == GIOP::LOCATION_FORWARD)
161 return TAO_INVOKE_RESTART;
163 else if (sri_adapter_)
165 this->sri_adapter_->popTSC (this->stub_->orb_core ());
168 return TAO_INVOKE_SUCCESS;
171 PortableInterceptor::ReplyStatus
172 Invocation_Base::handle_any_exception (CORBA::Exception *ex)
174 this->exception (ex);
176 PortableInterceptor::ReplyStatus status =
177 PortableInterceptor::SYSTEM_EXCEPTION;
179 if (cri_adapter_)
181 this->cri_adapter_->popTSC (this->stub_->orb_core ());
182 this->cri_adapter_->receive_exception (*this);
184 if (this->reply_status_ == GIOP::LOCATION_FORWARD)
186 status = PortableInterceptor::LOCATION_FORWARD;
188 else
190 status = this->cri_adapter_->pi_reply_status (*this);
193 else if (sri_adapter_)
195 this->sri_adapter_->popTSC (this->stub_->orb_core ());
198 return status;
201 PortableInterceptor::ReplyStatus
202 Invocation_Base::handle_all_exception ()
204 this->exception (&unknown_exception);
206 PortableInterceptor::ReplyStatus status =
207 PortableInterceptor::SYSTEM_EXCEPTION;
209 if (cri_adapter_)
211 this->cri_adapter_->popTSC (this->stub_->orb_core ());
212 this->cri_adapter_->receive_exception (*this);
214 status = this->cri_adapter_->pi_reply_status (*this);
216 else if (sri_adapter_)
218 this->sri_adapter_->popTSC (this->stub_->orb_core ());
221 return status;
224 void
225 Invocation_Base::exception (CORBA::Exception *exception)
227 if (CORBA::SystemException::_downcast (exception) != nullptr)
228 this->invoke_status_ = TAO::TAO_INVOKE_SYSTEM_EXCEPTION;
229 else if (CORBA::UserException::_downcast (exception) != nullptr)
230 this->invoke_status_ = TAO::TAO_INVOKE_USER_EXCEPTION;
232 this->forwarded_to_ = CORBA::Object::_nil ();
233 this->reply_status_ = GIOP::NO_EXCEPTION;
234 this->caught_exception_ = exception;
237 PortableInterceptor::ReplyStatus
238 Invocation_Base::pi_reply_status () const
240 if (cri_adapter_)
242 return this->cri_adapter_->pi_reply_status (*this);
244 else
246 return -1;
249 #endif /* TAO_HAS_INTERCEPTORS == 1 */
252 TAO_END_VERSIONED_NAMESPACE_DECL