00001 #include "tao/Invocation_Base.h"
00002 #include "tao/Stub.h"
00003 #include "tao/operation_details.h"
00004 #include "tao/ORB_Core.h"
00005 #include "tao/SystemException.h"
00006 #include "tao/PortableInterceptor.h"
00007
00008 #include "ace/Dynamic_Service.h"
00009
00010 #if TAO_HAS_INTERCEPTORS == 1
00011 # include "tao/PortableInterceptorC.h"
00012 # include "tao/ClientRequestInterceptor_Adapter_Factory.h"
00013 #endif
00014
00015 #if !defined (__ACE_INLINE__)
00016 # include "tao/Invocation_Base.inl"
00017 #endif
00018
00019
00020 ACE_RCSID (tao,
00021 Invocation_Base,
00022 "$Id: Invocation_Base.cpp 81632 2008-05-07 09:19:05Z vzykov $")
00023
00024
00025 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00026
00027 namespace
00028 {
00029
00030
00031 CORBA::UNKNOWN unknown_exception;
00032 }
00033
00034 namespace TAO
00035 {
00036 Invocation_Base::Invocation_Base (CORBA::Object_ptr ot,
00037 CORBA::Object_ptr t,
00038 TAO_Stub *stub,
00039 TAO_Operation_Details &details,
00040 bool response_expected,
00041 bool TAO_INTERCEPTOR (request_is_remote))
00042 : details_ (details)
00043 , forwarded_to_ (0)
00044 , response_expected_ (response_expected)
00045 , reply_status_ (GIOP::NO_EXCEPTION)
00046 , otarget_ (ot)
00047 , target_ (t)
00048 , orb_core_ (stub->orb_core ())
00049 , stub_ (stub)
00050 #if TAO_HAS_INTERCEPTORS == 1
00051 , adapter_ (orb_core_->clientrequestinterceptor_adapter ())
00052 , stack_size_ (0)
00053 , invoke_status_ (TAO_INVOKE_START)
00054 , caught_exception_ (0)
00055 , is_remote_request_ (request_is_remote)
00056 #endif
00057 {
00058 }
00059
00060 Invocation_Base::~Invocation_Base (void)
00061 {
00062 TAO_INTERCEPTOR (adapter_ = 0);
00063 }
00064
00065 TAO_Service_Context &
00066 Invocation_Base::request_service_context (void)
00067 {
00068 return this->details_.request_service_context ();
00069 }
00070
00071 TAO_Service_Context &
00072 Invocation_Base::reply_service_context (void)
00073 {
00074 return this->details_.reply_service_context ();
00075 }
00076
00077 #if TAO_HAS_INTERCEPTORS == 1
00078
00079 Invocation_Status
00080 Invocation_Base::send_request_interception (void)
00081 {
00082 if (adapter_ != 0)
00083 {
00084 try
00085 {
00086
00087 this->adapter_->send_request (*this);
00088 }
00089 catch ( ::CORBA::Exception& ex)
00090 {
00091 (void) this->handle_any_exception (&ex);
00092 throw;
00093 }
00094 catch (...)
00095 {
00096 (void) this->handle_all_exception ();
00097 throw;
00098 }
00099
00100 if (this->reply_status_ == GIOP::LOCATION_FORWARD)
00101 return TAO_INVOKE_RESTART;
00102 }
00103
00104
00105 return TAO_INVOKE_SUCCESS;
00106 }
00107
00108 Invocation_Status
00109 Invocation_Base::receive_reply_interception (void)
00110 {
00111 if (adapter_ != 0)
00112 {
00113 try
00114 {
00115 this->adapter_->receive_reply (*this);
00116 }
00117 catch ( ::CORBA::Exception& ex)
00118 {
00119 (void) this->handle_any_exception (&ex);
00120 throw;
00121 }
00122 catch (...)
00123 {
00124 (void) this->handle_all_exception ();
00125 throw;
00126 }
00127
00128 if (this->reply_status_ == GIOP::LOCATION_FORWARD)
00129 return TAO_INVOKE_RESTART;
00130 }
00131
00132 return TAO_INVOKE_SUCCESS;
00133 }
00134
00135 Invocation_Status
00136 Invocation_Base::receive_other_interception (void)
00137 {
00138 if (adapter_ != 0)
00139 {
00140 try
00141 {
00142 this->adapter_->receive_other (*this);
00143 }
00144 catch ( ::CORBA::Exception& ex)
00145 {
00146 (void) this->handle_any_exception (&ex);
00147 throw;
00148 }
00149 catch (...)
00150 {
00151 (void) this->handle_all_exception ();
00152 throw;
00153 }
00154
00155 if (this->reply_status_ == GIOP::LOCATION_FORWARD)
00156 return TAO_INVOKE_RESTART;
00157 }
00158
00159 return TAO_INVOKE_SUCCESS;
00160 }
00161
00162 PortableInterceptor::ReplyStatus
00163 Invocation_Base::handle_any_exception (CORBA::Exception *ex)
00164 {
00165 this->exception (ex);
00166
00167 PortableInterceptor::ReplyStatus status =
00168 PortableInterceptor::SYSTEM_EXCEPTION;
00169
00170 if (adapter_ != 0)
00171 {
00172 this->adapter_->receive_exception (*this);
00173
00174 if (this->reply_status_ == GIOP::LOCATION_FORWARD)
00175 {
00176 status = PortableInterceptor::LOCATION_FORWARD;
00177 }
00178 else
00179 {
00180 status = this->adapter_->pi_reply_status (*this);
00181 }
00182 }
00183
00184 return status;
00185 }
00186
00187 PortableInterceptor::ReplyStatus
00188 Invocation_Base::handle_all_exception (void)
00189 {
00190 this->exception (&unknown_exception);
00191
00192 PortableInterceptor::ReplyStatus status =
00193 PortableInterceptor::SYSTEM_EXCEPTION;
00194
00195 if (adapter_ != 0)
00196 {
00197 this->adapter_->receive_exception (*this);
00198
00199 status = this->adapter_->pi_reply_status (*this);
00200 }
00201
00202 return status;
00203 }
00204
00205 void
00206 Invocation_Base::exception (CORBA::Exception *exception)
00207 {
00208 if (CORBA::SystemException::_downcast (exception) != 0)
00209 this->invoke_status_ = TAO::TAO_INVOKE_SYSTEM_EXCEPTION;
00210 else if (CORBA::UserException::_downcast (exception) != 0)
00211 this->invoke_status_ = TAO::TAO_INVOKE_USER_EXCEPTION;
00212
00213 this->forwarded_to_ = CORBA::Object::_nil ();
00214 this->reply_status_ = GIOP::NO_EXCEPTION;
00215 this->caught_exception_ = exception;
00216 }
00217
00218 PortableInterceptor::ReplyStatus
00219 Invocation_Base::pi_reply_status (void) const
00220 {
00221 if (adapter_ != 0)
00222 {
00223 return this->adapter_->pi_reply_status (*this);
00224 }
00225 else
00226 {
00227 return -1;
00228 }
00229 }
00230 #endif
00231 }
00232
00233 TAO_END_VERSIONED_NAMESPACE_DECL