Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Collocated_Invocation.cpp
blobbcbfd4b99a7166495132b7a36db3066a6a2c25c6
1 #include "tao/Collocated_Invocation.h"
2 #include "tao/ORB_Core.h"
3 #include "tao/Request_Dispatcher.h"
4 #include "tao/TAO_Server_Request.h"
5 #include "tao/Stub.h"
6 #include "tao/operation_details.h"
7 #include "tao/PortableInterceptor.h"
8 #include "tao/SystemException.h"
9 #include "tao/Abstract_Servant_Base.h"
11 #if TAO_HAS_INTERCEPTORS == 1
12 # include "tao/PortableInterceptorC.h"
13 #endif /*TAO_HAS_INTERCEPTORS */
15 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
17 namespace TAO
19 Collocated_Invocation::Collocated_Invocation (CORBA::Object_ptr t,
20 CORBA::Object_ptr et,
21 TAO_Stub *stub,
22 TAO_Operation_Details &detail,
23 bool response_expected)
24 : Invocation_Base (t,
25 et,
26 stub,
27 detail,
28 response_expected,
29 false /* request_is_remote */ )
33 Invocation_Status
34 Collocated_Invocation::invoke (Collocation_Strategy strat)
36 Invocation_Status s = TAO_INVOKE_FAILURE;
38 /// Start the interception point
39 #if TAO_HAS_INTERCEPTORS == 1
40 s = this->send_request_interception ();
42 if (s != TAO_INVOKE_SUCCESS)
43 return s;
44 #endif /*TAO_HAS_INTERCEPTORS */
46 try
48 if (strat == TAO_CS_THRU_POA_STRATEGY)
50 // Perform invocations on the servant through the servant's ORB.
51 CORBA::ORB_var servant_orb =
52 this->effective_target ()->_stubobj ()->servant_orb_ptr ();
53 TAO_ORB_Core * const orb_core = servant_orb->orb_core ();
55 TAO_ServerRequest request (orb_core,
56 this->details_,
57 this->effective_target ());
59 TAO_Request_Dispatcher * const dispatcher =
60 orb_core->request_dispatcher ();
62 // Retain ownership of the servant's ORB_Core in case
63 // another thread attempts to destroy it (e.g. via
64 // CORBA::ORB::destroy()) before this thread complete the
65 // invocation.
66 orb_core->_incr_refcnt ();
67 TAO_ORB_Core_Auto_Ptr my_orb_core (orb_core);
69 dispatcher->dispatch (orb_core, request, this->forwarded_to_.out ());
71 if (request.is_forwarded ())
73 this->reply_status_ = GIOP::LOCATION_FORWARD;
76 else
78 bool is_forwarded = false;
80 this->effective_target ()->_servant()->_collocated_dispatch (
81 this->effective_target (),
82 this->forwarded_to_.out (),
83 is_forwarded,
84 this->details_.args (),
85 this->details_.args_num (),
86 this->details_.opname (),
87 this->details_.opname_len (),
88 strat);
90 if (is_forwarded)
92 this->reply_status_ = GIOP::LOCATION_FORWARD;
96 // Invocation completed successfully
97 s = TAO_INVOKE_SUCCESS;
99 #if TAO_HAS_INTERCEPTORS == 1
100 if (this->reply_status_ == GIOP::LOCATION_FORWARD ||
101 this->response_expected_ == false)
103 if (this->reply_status_ == GIOP::LOCATION_FORWARD)
104 this->invoke_status (TAO_INVOKE_RESTART);
106 s = this->receive_other_interception ();
108 // NOTE: Any other condition that needs handling?
109 else if (this->response_expected ())
111 this->invoke_status (TAO_INVOKE_SUCCESS);
113 s = this->receive_reply_interception ();
115 if (s != TAO_INVOKE_SUCCESS)
116 return s;
117 #endif /*TAO_HAS_INTERCEPTORS */
119 catch ( ::CORBA::UserException& ex)
121 // Ignore CORBA exceptions for oneways
122 if (this->response_expected_ == false)
123 return TAO_INVOKE_SUCCESS;
125 #if TAO_HAS_INTERCEPTORS == 1
126 PortableInterceptor::ReplyStatus const status =
127 this->handle_any_exception (&ex);
129 if (status == PortableInterceptor::LOCATION_FORWARD ||
130 status == PortableInterceptor::TRANSPORT_RETRY)
131 s = TAO_INVOKE_RESTART;
132 else
133 #endif /* TAO_HAS_INTERCEPTORS */
135 // Check whether the user exception thrown matches the signature
136 // list, if not, then throw an Unknown exception
137 if (!this->details_.has_exception (ex))
139 throw ::CORBA::UNKNOWN (CORBA::OMGVMCID | 1,
140 CORBA::COMPLETED_MAYBE);
142 else
144 throw;
148 catch ( ::CORBA::SystemException& TAO_INTERCEPTOR (ex))
150 // Ignore CORBA exceptions for oneways
151 if (this->response_expected_ == false)
152 return TAO_INVOKE_SUCCESS;
154 #if TAO_HAS_INTERCEPTORS == 1
155 PortableInterceptor::ReplyStatus const status =
156 this->handle_any_exception (&ex);
158 if (status == PortableInterceptor::LOCATION_FORWARD ||
159 status == PortableInterceptor::TRANSPORT_RETRY)
160 s = TAO_INVOKE_RESTART;
161 else
162 #endif /* TAO_HAS_INTERCEPTORS */
163 throw;
165 #if TAO_HAS_INTERCEPTORS == 1
166 catch (...)
168 // Notify interceptors of non-CORBA exception, and propagate
169 // that exception to the caller.
170 PortableInterceptor::ReplyStatus const st =
171 this->handle_all_exception ();
173 if (st == PortableInterceptor::LOCATION_FORWARD ||
174 st == PortableInterceptor::TRANSPORT_RETRY)
175 s = TAO_INVOKE_RESTART;
176 else
177 throw;
179 #endif /* TAO_HAS_INTERCEPTORS == 1 */
181 if (this->reply_status_ == GIOP::LOCATION_FORWARD)
182 s = TAO_INVOKE_RESTART;
184 return s;
189 TAO_END_VERSIONED_NAMESPACE_DECL