1 #include "tao/PI/ClientRequestInterceptor_Adapter_Impl.h"
3 #if TAO_HAS_INTERCEPTORS == 1
5 #if !defined (__ACE_INLINE__)
6 #include "tao/PI/ClientRequestInterceptor_Adapter_Impl.inl"
7 #endif /* defined INLINE */
9 #include "tao/PI/ClientRequestInfo.h"
11 #include "tao/Invocation_Base.h"
12 #include "tao/ORB_Core.h"
13 #include "tao/ORB_Core_TSS_Resources.h"
14 #include "tao/PortableInterceptorC.h"
16 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
21 ClientRequestInterceptor_Adapter_Impl::send_request (
22 Invocation_Base
&invocation
)
24 // This method implements one of the "starting" client side
25 // interception point.
27 bool const is_remote_request
= invocation
.is_remote_request();
31 TAO_ClientRequestInfo
ri (&invocation
);
33 for (size_t i
= 0 ; i
< this->interceptor_list_
.size (); ++i
)
35 ClientRequestInterceptor_List::RegisteredInterceptor
& registered
=
36 this->interceptor_list_
.registered_interceptor (i
);
38 if (registered
.details_
.should_be_processed (is_remote_request
))
40 registered
.interceptor_
->send_request (&ri
);
43 // The starting interception point completed successfully.
44 // Push the interceptor on to the flow stack.
45 ++invocation
.stack_size ();
48 catch (const ::PortableInterceptor::ForwardRequest
& exc
)
50 this->process_forward_request (invocation
, exc
);
55 ClientRequestInterceptor_Adapter_Impl::receive_reply (
56 Invocation_Base
&invocation
)
58 // This is an "ending" interception point so we only process the
59 // interceptors pushed on to the flow stack.
61 bool const is_remote_request
= invocation
.is_remote_request();
63 // Notice that the interceptors are processed in the opposite order
64 // they were pushed onto the stack since this is an "ending"
65 // interception point.
67 TAO_ClientRequestInfo
ri (&invocation
);
70 size_t const len
= invocation
.stack_size ();
71 for (size_t i
= 0; i
< len
; ++i
)
73 // Pop the interceptor off of the flow stack before it is
74 // invoked. This is necessary to prevent an interceptor already
75 // invoked in this "ending" interception point from being
76 // invoked in another "ending" interception point.
77 --invocation
.stack_size ();
79 ClientRequestInterceptor_List::RegisteredInterceptor
& registered
=
80 this->interceptor_list_
.registered_interceptor (
81 invocation
.stack_size ());
83 if (registered
.details_
.should_be_processed (is_remote_request
))
85 registered
.interceptor_
->receive_reply (&ri
);
89 // The receive_reply() interception point does not raise a
90 // PortableInterceptor::ForwardRequest exception so there is no need
91 // to attempt to catch it here.
95 ClientRequestInterceptor_Adapter_Impl::receive_exception (
96 Invocation_Base
&invocation
)
98 // This is an "ending" interception point so we only process the
99 // interceptors pushed on to the flow stack.
101 bool const is_remote_request
= invocation
.is_remote_request();
103 // Notice that the interceptors are processed in the opposite order
104 // they were pushed onto the stack since this is an "ending"
105 // interception point.
108 TAO_ClientRequestInfo
ri (&invocation
);
110 // Unwind the flow stack.
111 size_t const len
= invocation
.stack_size ();
112 for (size_t i
= 0; i
< len
; ++i
)
114 // Pop the interceptor off of the flow stack before it is
115 // invoked. This is necessary to prevent an interceptor
116 // already invoked in this "ending" interception point from
117 // being invoked in another "ending" interception point.
118 --invocation
.stack_size ();
120 ClientRequestInterceptor_List::RegisteredInterceptor
& registered
=
121 this->interceptor_list_
.registered_interceptor (
122 invocation
.stack_size ());
124 if (registered
.details_
.should_be_processed (is_remote_request
))
126 registered
.interceptor_
->receive_exception (&ri
);
130 catch (const ::PortableInterceptor::ForwardRequest
& exc
)
132 this->process_forward_request (invocation
, exc
);
134 catch ( ::CORBA::Exception
& ex
)
136 // The receive_exception() interception point in the remaining
137 // interceptors must be called so call this method (not the
138 // interceptor's corresponding method) recursively. The call is
139 // made recursively since the caught exception must survive
140 // until the remaining interceptors have been called.
142 // Note that the recursion will stop once the flow stack size
143 // drops to zero, i.e., once each interceptor has been invoked.
144 // This prevents infinite recursion from occuring.
146 invocation
.exception (&ex
);
148 this->receive_exception (invocation
);
150 PortableInterceptor::ReplyStatus status
=
151 this->pi_reply_status (invocation
);
153 // Only re-throw the exception if it hasn't been transformed by
154 // the receive_exception() interception point (e.g. to a
155 // LOCATION_FORWARD).
156 if (status
== PortableInterceptor::SYSTEM_EXCEPTION
157 || status
== PortableInterceptor::USER_EXCEPTION
)
163 ClientRequestInterceptor_Adapter_Impl::receive_other (
164 Invocation_Base
&invocation
)
166 // This is an "ending" interception point so we only process the
167 // interceptors pushed on to the flow stack.
169 bool const is_remote_request
= invocation
.is_remote_request();
171 // Notice that the interceptors are processed in the opposite order
172 // they were pushed onto the stack since this is an "ending"
173 // interception point.
177 TAO_ClientRequestInfo
ri (&invocation
);
180 size_t const len
= invocation
.stack_size ();
181 for (size_t i
= 0; i
< len
; ++i
)
183 // Pop the interceptor off of the flow stack before it is
184 // invoked. This is necessary to prevent an interceptor
185 // already invoked in this "ending" interception point from
186 // being invoked in another "ending" interception point.
187 --invocation
.stack_size ();
189 ClientRequestInterceptor_List::RegisteredInterceptor
& registered
=
190 this->interceptor_list_
.registered_interceptor (
191 invocation
.stack_size ());
193 if (registered
.details_
.should_be_processed (is_remote_request
))
195 registered
.interceptor_
->receive_other (&ri
);
199 catch (const ::PortableInterceptor::ForwardRequest
& exc
)
201 this->process_forward_request (invocation
, exc
);
203 catch ( ::CORBA::Exception
& ex
)
205 // The receive_exception() interception point in the remaining
206 // interceptors must be called so call this method (not the
207 // interceptor's corresponding method) recursively. The call is
208 // made recursively since the caught exception must survive
209 // until the remaining interceptors have been called.
211 // Note that the recursion will stop once the flow stack size
212 // drops to zero, i.e., once each interceptor has been invoked.
213 // This prevents infinite recursion from occuring.
215 invocation
.exception (&ex
);
217 this->receive_exception (invocation
);
219 PortableInterceptor::ReplyStatus status
=
220 this->pi_reply_status (invocation
);
222 // Only re-throw the exception if it hasn't been transformed by
223 // the receive_exception() interception point (e.g. to a
224 // LOCATION_FORWARD).
225 if (status
== PortableInterceptor::SYSTEM_EXCEPTION
226 || status
== PortableInterceptor::USER_EXCEPTION
)
232 ClientRequestInterceptor_Adapter_Impl::process_forward_request (
233 Invocation_Base
&invocation
,
234 const PortableInterceptor::ForwardRequest
&exc
)
236 invocation
.forwarded_reference (exc
.forward
.in ());
238 // receive_other() is potentially invoked recursively.
239 this->receive_other (invocation
);
243 ClientRequestInterceptor_Adapter_Impl::add_interceptor (
244 PortableInterceptor::ClientRequestInterceptor_ptr interceptor
)
246 this->interceptor_list_
.add_interceptor (interceptor
);
250 ClientRequestInterceptor_Adapter_Impl::add_interceptor (
251 PortableInterceptor::ClientRequestInterceptor_ptr interceptor
,
252 const CORBA::PolicyList
& policies
)
254 this->interceptor_list_
.add_interceptor (interceptor
, policies
);
258 ClientRequestInterceptor_Adapter_Impl::destroy_interceptors ()
260 this->interceptor_list_
.destroy_interceptors ();
263 PortableInterceptor::ReplyStatus
264 ClientRequestInterceptor_Adapter_Impl::pi_reply_status (
265 TAO::Invocation_Base
const &invocation_base
)
267 PortableInterceptor::ReplyStatus reply_status
;
269 switch (invocation_base
.invoke_status ())
271 case TAO::TAO_INVOKE_SUCCESS
:
272 reply_status
= PortableInterceptor::SUCCESSFUL
;
274 case TAO::TAO_INVOKE_RESTART
:
275 if (invocation_base
.reply_status () == GIOP::LOCATION_FORWARD
||
276 invocation_base
.reply_status () == GIOP::LOCATION_FORWARD_PERM
)
277 reply_status
= PortableInterceptor::LOCATION_FORWARD
;
279 reply_status
= PortableInterceptor::TRANSPORT_RETRY
;
281 case TAO::TAO_INVOKE_USER_EXCEPTION
:
282 reply_status
= PortableInterceptor::USER_EXCEPTION
;
284 case TAO::TAO_INVOKE_SYSTEM_EXCEPTION
:
285 reply_status
= PortableInterceptor::SYSTEM_EXCEPTION
;
288 reply_status
= PortableInterceptor::UNKNOWN
;
296 TAO_END_VERSIONED_NAMESPACE_DECL
298 #endif /* TAO_HAS_INTERCEPTORS == 1 */