00001 #include "tao/PI/ClientRequestInterceptor_Adapter_Impl.h"
00002
00003 #if TAO_HAS_INTERCEPTORS == 1
00004
00005 #if !defined (__ACE_INLINE__)
00006 #include "tao/PI/ClientRequestInterceptor_Adapter_Impl.inl"
00007 #endif
00008
00009 #include "tao/PI/ClientRequestInfo.h"
00010
00011 #include "tao/Invocation_Base.h"
00012 #include "tao/ORB_Core.h"
00013 #include "tao/ORB_Core_TSS_Resources.h"
00014 #include "tao/PortableInterceptorC.h"
00015
00016 ACE_RCSID (PI,
00017 ClientRequestInterceptorAdapter_Impl,
00018 "ClientRequestInterceptor_Adapter_Impl.cpp,v 1.9 2006/03/10 07:19:12 jtc Exp")
00019
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021
00022 namespace TAO
00023 {
00024 void
00025 ClientRequestInterceptor_Adapter_Impl::send_request (
00026 Invocation_Base &invocation
00027 ACE_ENV_ARG_DECL)
00028 {
00029
00030
00031
00032 bool is_remote_request = invocation.is_remote_request();
00033
00034 ACE_TRY
00035 {
00036 TAO_ClientRequestInfo ri (&invocation);
00037
00038 for (size_t i = 0 ; i < this->interceptor_list_.size (); ++i)
00039 {
00040 ClientRequestInterceptor_List::RegisteredInterceptor& registered =
00041 this->interceptor_list_.registered_interceptor (i);
00042
00043 if (registered.details_.should_be_processed (is_remote_request))
00044 {
00045 registered.interceptor_->
00046 send_request (&ri
00047 ACE_ENV_ARG_PARAMETER);
00048 ACE_TRY_CHECK;
00049 }
00050
00051
00052
00053 ++invocation.stack_size ();
00054 }
00055 }
00056 ACE_CATCH (PortableInterceptor::ForwardRequest, exc)
00057 {
00058 this->process_forward_request (invocation,
00059 exc
00060 ACE_ENV_ARG_PARAMETER);
00061 ACE_TRY_CHECK;
00062 }
00063 ACE_ENDTRY;
00064 ACE_CHECK;
00065 }
00066
00067 void
00068 ClientRequestInterceptor_Adapter_Impl::receive_reply (
00069 Invocation_Base &invocation
00070 ACE_ENV_ARG_DECL)
00071 {
00072
00073
00074
00075 bool is_remote_request = invocation.is_remote_request();
00076
00077
00078
00079
00080
00081 TAO_ClientRequestInfo ri (&invocation);
00082
00083
00084 const size_t len = invocation.stack_size ();
00085 for (size_t i = 0; i < len; ++i)
00086 {
00087
00088
00089
00090
00091 --invocation.stack_size ();
00092
00093 ClientRequestInterceptor_List::RegisteredInterceptor& registered =
00094 this->interceptor_list_.registered_interceptor (
00095 invocation.stack_size ());
00096
00097 if (registered.details_.should_be_processed (is_remote_request))
00098 {
00099 registered.interceptor_->
00100 receive_reply (
00101 &ri
00102 ACE_ENV_ARG_PARAMETER);
00103 ACE_CHECK;
00104 }
00105 }
00106
00107
00108
00109
00110 }
00111
00112 void
00113 ClientRequestInterceptor_Adapter_Impl::receive_exception (
00114 Invocation_Base &invocation
00115 ACE_ENV_ARG_DECL)
00116 {
00117
00118
00119
00120 bool is_remote_request = invocation.is_remote_request();
00121
00122
00123
00124
00125 ACE_TRY
00126 {
00127 TAO_ClientRequestInfo ri (&invocation);
00128
00129
00130 const size_t len = invocation.stack_size ();
00131 for (size_t i = 0; i < len; ++i)
00132 {
00133
00134
00135
00136
00137 --invocation.stack_size ();
00138
00139 ClientRequestInterceptor_List::RegisteredInterceptor& registered =
00140 this->interceptor_list_.registered_interceptor (
00141 invocation.stack_size ());
00142
00143 if (registered.details_.should_be_processed (is_remote_request))
00144 {
00145 registered.interceptor_->
00146 receive_exception (
00147 &ri
00148 ACE_ENV_ARG_PARAMETER);
00149 ACE_TRY_CHECK;
00150 }
00151 }
00152 }
00153 ACE_CATCH (PortableInterceptor::ForwardRequest, exc)
00154 {
00155 this->process_forward_request (invocation,
00156 exc
00157 ACE_ENV_ARG_PARAMETER);
00158 ACE_TRY_CHECK;
00159 }
00160 ACE_CATCHANY
00161 {
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 invocation.exception (&ACE_ANY_EXCEPTION);
00173
00174 this->receive_exception (invocation ACE_ENV_ARG_PARAMETER);
00175 ACE_TRY_CHECK;
00176
00177 PortableInterceptor::ReplyStatus status =
00178 this->reply_status (invocation);
00179
00180
00181
00182
00183 if (status == PortableInterceptor::SYSTEM_EXCEPTION
00184 || status == PortableInterceptor::USER_EXCEPTION)
00185 ACE_RE_THROW;
00186 }
00187 ACE_ENDTRY;
00188 ACE_CHECK;
00189 }
00190
00191 void
00192 ClientRequestInterceptor_Adapter_Impl::receive_other (
00193 Invocation_Base &invocation
00194 ACE_ENV_ARG_DECL)
00195 {
00196
00197
00198
00199 bool is_remote_request = invocation.is_remote_request();
00200
00201
00202
00203
00204
00205 ACE_TRY
00206 {
00207 TAO_ClientRequestInfo ri (&invocation);
00208
00209
00210 const size_t len = invocation.stack_size ();
00211 for (size_t i = 0; i < len; ++i)
00212 {
00213
00214
00215
00216
00217 --invocation.stack_size ();
00218
00219 ClientRequestInterceptor_List::RegisteredInterceptor& registered =
00220 this->interceptor_list_.registered_interceptor (
00221 invocation.stack_size ());
00222
00223 if (registered.details_.should_be_processed (is_remote_request))
00224 {
00225 registered.interceptor_->
00226 receive_other (
00227 &ri
00228 ACE_ENV_ARG_PARAMETER);
00229 ACE_TRY_CHECK;
00230 }
00231 }
00232 }
00233 ACE_CATCH (PortableInterceptor::ForwardRequest, exc)
00234 {
00235 this->process_forward_request (invocation,
00236 exc
00237 ACE_ENV_ARG_PARAMETER);
00238 ACE_TRY_CHECK;
00239 }
00240 ACE_ENDTRY;
00241 ACE_CHECK;
00242 }
00243
00244 void
00245 ClientRequestInterceptor_Adapter_Impl::process_forward_request (
00246 Invocation_Base &invocation,
00247 PortableInterceptor::ForwardRequest &exc
00248 ACE_ENV_ARG_DECL)
00249 {
00250 invocation.forwarded_reference (exc.forward.in ());
00251
00252
00253 this->receive_other (invocation
00254 ACE_ENV_ARG_PARAMETER);
00255 ACE_CHECK;
00256 }
00257
00258 void
00259 ClientRequestInterceptor_Adapter_Impl::add_interceptor (
00260 PortableInterceptor::ClientRequestInterceptor_ptr interceptor
00261 ACE_ENV_ARG_DECL)
00262 {
00263 this->interceptor_list_.add_interceptor (interceptor ACE_ENV_ARG_PARAMETER);
00264 ACE_CHECK;
00265 }
00266
00267 void
00268 ClientRequestInterceptor_Adapter_Impl::add_interceptor (
00269 PortableInterceptor::ClientRequestInterceptor_ptr interceptor,
00270 const CORBA::PolicyList& policies
00271 ACE_ENV_ARG_DECL)
00272 {
00273 this->interceptor_list_.add_interceptor (interceptor,
00274 policies
00275 ACE_ENV_ARG_PARAMETER);
00276 ACE_CHECK;
00277 }
00278
00279 void
00280 ClientRequestInterceptor_Adapter_Impl::destroy_interceptors (
00281 ACE_ENV_SINGLE_ARG_DECL)
00282 {
00283 this->interceptor_list_.destroy_interceptors (ACE_ENV_SINGLE_ARG_PARAMETER);
00284 ACE_CHECK;
00285 }
00286
00287 PortableInterceptor::ReplyStatus
00288 ClientRequestInterceptor_Adapter_Impl::reply_status (
00289 TAO::Invocation_Base const &invocation_base)
00290 {
00291 PortableInterceptor::ReplyStatus reply_status;
00292
00293 switch (invocation_base.invoke_status ())
00294 {
00295 case TAO::TAO_INVOKE_SUCCESS:
00296 reply_status = PortableInterceptor::SUCCESSFUL;
00297 break;
00298 case TAO::TAO_INVOKE_RESTART:
00299 if (invocation_base.is_forwarded ())
00300 reply_status = PortableInterceptor::LOCATION_FORWARD;
00301 else
00302 reply_status = PortableInterceptor::TRANSPORT_RETRY;
00303 break;
00304 case TAO::TAO_INVOKE_USER_EXCEPTION:
00305 reply_status = PortableInterceptor::USER_EXCEPTION;
00306 break;
00307 case TAO::TAO_INVOKE_SYSTEM_EXCEPTION:
00308 reply_status = PortableInterceptor::SYSTEM_EXCEPTION;
00309 break;
00310 default:
00311 reply_status = PortableInterceptor::UNKNOWN;
00312 break;
00313 }
00314
00315 return reply_status;
00316 }
00317 }
00318
00319 TAO_END_VERSIONED_NAMESPACE_DECL
00320
00321 #endif