Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / DynamicInterface / DII_Invocation_Adapter.cpp
blob642cef4f3013d04997a745490caa6fea926d112f
1 #include "tao/AnyTypeCode/TypeCode.h"
2 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
3 #include "tao/DynamicInterface/DII_Invocation_Adapter.h"
4 #include "tao/DynamicInterface/DII_Invocation.h"
5 #include "tao/DynamicInterface/DII_Arguments_Converter_Impl.h"
6 #include "tao/DynamicInterface/Request.h"
8 #include "tao/Exception.h"
9 #include "tao/Exception_Data.h"
10 #include "tao/ORB_Constants.h"
11 #include "tao/Profile_Transport_Resolver.h"
12 #include "tao/Transport.h"
13 #include "tao/GIOP_Message_Base.h"
14 #include "tao/SystemException.h"
15 #include "tao/operation_details.h"
17 #include "ace/os_include/os_errno.h"
19 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
21 namespace TAO
23 DII_Invocation_Adapter::DII_Invocation_Adapter (CORBA::Object *target,
24 Argument **args,
25 int arg_number,
26 const char *operation,
27 size_t op_len,
28 CORBA::ExceptionList *excp,
29 CORBA::Request *r,
30 Invocation_Mode mode)
32 : Invocation_Adapter (target,
33 args,
34 arg_number,
35 operation,
36 op_len,
37 TAO_CO_THRU_POA_STRATEGY, // default through POA collocation is possible
38 TAO_TWOWAY_INVOCATION,
39 mode)
40 , exception_list_ (excp)
41 , request_ (r)
42 , ex_data_ (0)
46 DII_Invocation_Adapter::~DII_Invocation_Adapter ()
48 delete[] ex_data_;
51 void
52 DII_Invocation_Adapter::invoke (const TAO::Exception_Data * /*ex_data*/,
53 unsigned long ex_count)
55 // Convert DII exception list to a form the invocation can use
56 // to filter raised user exceptions.
57 ex_count = this->exception_list_->count ();
58 ACE_NEW_THROW_EX (this->ex_data_,
59 TAO::Exception_Data[ex_count],
60 CORBA::NO_MEMORY ());
61 for (unsigned long l=0; l<ex_count ;++l)
63 CORBA::TypeCode_var xtc = this->exception_list_->item (l);
64 this->ex_data_[l].id = xtc->id ();
65 this->ex_data_[l].alloc = nullptr;
66 #if TAO_HAS_INTERCEPTORS == 1
67 this->ex_data_[l].tc_ptr = xtc.in ();
68 #endif
71 Invocation_Adapter::invoke (this->ex_data_, ex_count);
74 Invocation_Status
75 DII_Invocation_Adapter::invoke_collocated_i (
76 TAO_Stub *stub,
77 TAO_Operation_Details &details,
78 CORBA::Object_var &effective_target,
79 Collocation_Strategy strat)
81 TAO_DII_Arguments_Converter_Impl* dii_arguments_converter
82 = ACE_Dynamic_Service<TAO_DII_Arguments_Converter_Impl>::instance (
83 "DII_Arguments_Converter");
84 details.cac (dii_arguments_converter);
86 return Invocation_Adapter::invoke_collocated_i (stub,
87 details,
88 effective_target,
89 strat);
92 Invocation_Status
93 DII_Invocation_Adapter::invoke_twoway (
94 TAO_Operation_Details &op,
95 CORBA::Object_var &effective_target,
96 Profile_Transport_Resolver &r,
97 ACE_Time_Value *&max_wait_time,
98 Invocation_Retry_State *)
100 // Simple sanity check
101 if (this->mode_ != TAO_DII_INVOCATION ||
102 this->type_ != TAO_TWOWAY_INVOCATION)
104 throw ::CORBA::INTERNAL (
105 CORBA::SystemException::_tao_minor_code (
106 TAO::VMCID,
107 EINVAL),
108 CORBA::COMPLETED_NO);
111 TAO_Transport* const transport = r.transport ();
113 if (!transport)
115 // Way back, we failed to find a profile we could connect to.
116 // We've come this far only so we reach the interception points
117 // in case they can fix things. Time to bail....
118 throw CORBA::TRANSIENT (CORBA::OMGVMCID | 2, CORBA::COMPLETED_NO);
121 TAO::DII_Invocation synch (this->target_,
124 this->exception_list_,
125 this->request_);
127 // forward requested byte order
128 synch._tao_byte_order (this->_tao_byte_order ());
130 Invocation_Status status = synch.remote_twoway (max_wait_time);
132 if (status == TAO_INVOKE_RESTART &&
133 (synch.reply_status () == GIOP::LOCATION_FORWARD ||
134 synch.reply_status () == GIOP::LOCATION_FORWARD_PERM))
136 CORBA::Boolean const permanent_forward =
137 (synch.reply_status () == GIOP::LOCATION_FORWARD_PERM);
139 effective_target = synch.steal_forwarded_reference ();
141 this->object_forwarded (effective_target,
142 r.stub (),
143 permanent_forward);
145 return status;
148 //================================================================
149 DII_Deferred_Invocation_Adapter::DII_Deferred_Invocation_Adapter (
150 CORBA::Object *target,
151 Argument **args,
152 int arg_number,
153 const char *operation,
154 size_t op_len,
155 int collocation_opportunity,
156 TAO_ORB_Core *oc,
157 CORBA::Request *req,
158 Invocation_Mode mode)
159 : Invocation_Adapter (target,
160 args,
161 arg_number,
162 operation,
163 op_len,
164 collocation_opportunity,
165 TAO_TWOWAY_INVOCATION,
166 mode)
167 , request_ (req)
168 , rd_ (0)
169 , orb_core_ (oc)
173 void
174 DII_Deferred_Invocation_Adapter::invoke (
175 const TAO::Exception_Data *ex,
176 unsigned long ex_count)
178 // New reply dispatcher on the heap, because we will go out of
179 // scope and hand over the reply dispatcher to the ORB.
180 // Manage it in a reference counting Auto_Functor based autopointer
181 // to prevent memory leaks. The invoke may encounter errors
182 // before being able to handover the dispatcher to the invocation
183 // using and managing it.
184 TAO_DII_Deferred_Reply_Dispatcher *new_rd = 0;
185 ACE_NEW_THROW_EX (new_rd,
186 TAO_DII_Deferred_Reply_Dispatcher (this->request_,
187 this->orb_core_),
188 CORBA::NO_MEMORY ());
190 TAO_Asynch_Reply_Dispatcher_Base::intrusive_add_ref (new_rd);
192 this->rd_.reset (new_rd);
194 Invocation_Adapter::invoke (ex, ex_count);
197 Invocation_Status
198 DII_Deferred_Invocation_Adapter::invoke_collocated_i (
199 TAO_Stub *stub,
200 TAO_Operation_Details &details,
201 CORBA::Object_var &effective_target,
202 Collocation_Strategy strat)
204 TAO_DII_Arguments_Converter_Impl* dii_arguments_converter
205 = ACE_Dynamic_Service<TAO_DII_Arguments_Converter_Impl>::instance (
206 "DII_Arguments_Converter");
207 details.cac (dii_arguments_converter);
209 return Invocation_Adapter::invoke_collocated_i (stub,
210 details,
211 effective_target,
212 strat);
215 Invocation_Status
216 DII_Deferred_Invocation_Adapter::invoke_twoway (
217 TAO_Operation_Details &op,
218 CORBA::Object_var &effective_target,
219 Profile_Transport_Resolver &r,
220 ACE_Time_Value *&max_wait_time,
221 Invocation_Retry_State *)
223 // Simple sanity check
224 if (this->mode_ != TAO_DII_DEFERRED_INVOCATION ||
225 this->type_ != TAO_TWOWAY_INVOCATION)
227 throw ::CORBA::INTERNAL (
228 CORBA::SystemException::_tao_minor_code (
229 TAO::VMCID,
230 EINVAL),
231 CORBA::COMPLETED_NO);
234 TAO_Transport* const transport = r.transport ();
236 if (!transport)
238 // Way back, we failed to find a profile we could connect to.
239 // We've come this far only so we reach the interception points
240 // in case they can fix things. Time to bail....
241 throw CORBA::TRANSIENT (CORBA::OMGVMCID | 2, CORBA::COMPLETED_NO);
244 TAO::DII_Deferred_Invocation synch (
245 this->target_,
248 this->rd_.get ());
250 // forward requested byte order
251 synch._tao_byte_order (this->_tao_byte_order ());
253 Invocation_Status const status = synch.remote_invocation (max_wait_time);
255 if (status == TAO_INVOKE_RESTART)
257 CORBA::Boolean const is_permanent_forward =
258 (synch.reply_status () == GIOP::LOCATION_FORWARD_PERM);
260 effective_target = synch.steal_forwarded_reference ();
262 this->object_forwarded (effective_target,
263 r.stub (),
264 is_permanent_forward);
267 return status;
270 DII_Oneway_Invocation_Adapter::DII_Oneway_Invocation_Adapter (
271 CORBA::Object *target,
272 Argument **args,
273 int arg_count,
274 const char *operation,
275 int op_len,
276 TAO::Invocation_Mode mode)
277 : Invocation_Adapter (target,
278 args,
279 arg_count,
280 operation,
281 op_len,
282 TAO_CO_THRU_POA_STRATEGY,
283 TAO_ONEWAY_INVOCATION,
284 mode)
288 Invocation_Status
289 DII_Oneway_Invocation_Adapter::invoke_collocated_i (
290 TAO_Stub *stub,
291 TAO_Operation_Details &details,
292 CORBA::Object_var &effective_target,
293 Collocation_Strategy strat)
295 TAO_DII_Arguments_Converter_Impl* dii_arguments_converter
296 = ACE_Dynamic_Service<TAO_DII_Arguments_Converter_Impl>::instance (
297 "DII_Arguments_Converter");
298 details.cac (dii_arguments_converter);
300 return Invocation_Adapter::invoke_collocated_i (stub,
301 details,
302 effective_target,
303 strat);
307 } // End namespace TAO
308 TAO_END_VERSIONED_NAMESPACE_DECL