Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / DynamicInterface / AMH_DSI_Response_Handler.cpp
blobd192e327e5d98aea03e199289d59cfc7d70c5142
1 #include "AMH_DSI_Response_Handler.h"
2 #include "Request.h"
3 #include "ExceptionList.h"
4 #include "DII_Invocation.h"
5 #include "Server_Request.h"
7 #include "tao/ORB_Core.h"
8 #include "tao/GIOP_Utils.h"
9 #include "tao/PortableServer/Root_POA.h"
10 #include "tao/Valuetype/ValueFactory.h"
11 #include "tao/Object.h"
12 #include "tao/Pluggable_Messaging_Utils.h"
13 #include "tao/AnyTypeCode/Any_Impl.h"
15 #include "ace/Truncate.h"
17 #if !defined (__ACE_INLINE__)
18 # include "AMH_DSI_Response_Handler.inl"
19 #endif /* ! __ACE_INLINE__ */
21 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
23 const char*
24 TAO_AMH_DSI_Exception_Holder::_tao_obv_static_repository_id ()
26 return "IDL:TAO_AMH_DSI_Exception_Holder:1.0";
29 TAO_AMH_DSI_Exception_Holder::TAO_AMH_DSI_Exception_Holder (CORBA::Exception *ex)
30 : exception_ (ex)
34 TAO_AMH_DSI_Exception_Holder::~TAO_AMH_DSI_Exception_Holder ()
38 ::CORBA::ValueBase *
39 TAO_AMH_DSI_Exception_Holder::_copy_value ()
41 ::CORBA::ValueBase *ret_val= 0;
42 ACE_NEW_THROW_EX (
43 ret_val,
44 TAO_AMH_DSI_Exception_Holder (
45 exception_
47 ::CORBA::NO_MEMORY ()
49 return ret_val;
52 void
53 tao_TAO_AMH_DSI_Exception_Holder_add_ref (TAO_AMH_DSI_Exception_Holder * p)
55 CORBA::add_ref (p);
58 void
59 tao_TAO_AMH_DSI_Exception_Holder_remove_ref (TAO_AMH_DSI_Exception_Holder * p)
61 CORBA::remove_ref (p);
65 TAO_AMH_DSI_Exception_Holder_var::TAO_AMH_DSI_Exception_Holder_var ()
66 : ptr_ (0)
70 TAO_AMH_DSI_Exception_Holder_var::TAO_AMH_DSI_Exception_Holder_var (
71 TAO_AMH_DSI_Exception_Holder * p)
72 : ptr_ (p)
76 TAO_AMH_DSI_Exception_Holder_var::TAO_AMH_DSI_Exception_Holder_var (
77 const TAO_AMH_DSI_Exception_Holder * p)
78 : ptr_ (const_cast<TAO_AMH_DSI_Exception_Holder *> (p))
82 TAO_AMH_DSI_Exception_Holder *
83 TAO_AMH_DSI_Exception_Holder_var::ptr () const
85 return this->ptr_;
88 TAO_AMH_DSI_Exception_Holder_var::TAO_AMH_DSI_Exception_Holder_var (
89 const TAO_AMH_DSI_Exception_Holder_var & p)
91 CORBA::add_ref (p.ptr ());
92 this->ptr_ = p.ptr ();
95 TAO_AMH_DSI_Exception_Holder_var::~TAO_AMH_DSI_Exception_Holder_var ()
97 CORBA::remove_ref (this->ptr_);
100 TAO_AMH_DSI_Exception_Holder_var &
101 TAO_AMH_DSI_Exception_Holder_var::operator= (TAO_AMH_DSI_Exception_Holder *p)
103 CORBA::remove_ref (this->ptr_);
104 this->ptr_ = p;
105 return *this;
108 TAO_AMH_DSI_Exception_Holder_var &
109 TAO_AMH_DSI_Exception_Holder_var::operator= (
110 const TAO_AMH_DSI_Exception_Holder_var & p)
112 if (this != &p)
114 CORBA::remove_ref (this->ptr_);
115 TAO_AMH_DSI_Exception_Holder *tmp = p.ptr ();
116 CORBA::add_ref (tmp);
117 this->ptr_ = tmp;
120 return *this;
123 TAO_AMH_DSI_Exception_Holder_var::operator const TAO_AMH_DSI_Exception_Holder* () const // cast
125 return this->ptr_;
128 TAO_AMH_DSI_Exception_Holder_var::operator TAO_AMH_DSI_Exception_Holder*& ()
130 return this->ptr_;
133 TAO_AMH_DSI_Exception_Holder *
134 TAO_AMH_DSI_Exception_Holder_var::operator-> () const
136 return this->ptr_;
139 TAO_AMH_DSI_Exception_Holder *
140 TAO_AMH_DSI_Exception_Holder_var::in () const
142 return this->ptr_;
145 TAO_AMH_DSI_Exception_Holder *&
146 TAO_AMH_DSI_Exception_Holder_var::inout ()
148 return this->ptr_;
151 TAO_AMH_DSI_Exception_Holder *&
152 TAO_AMH_DSI_Exception_Holder_var::out ()
154 CORBA::remove_ref (this->ptr_);
155 this->ptr_ = 0;
156 return this->ptr_;
159 TAO_AMH_DSI_Exception_Holder *
160 TAO_AMH_DSI_Exception_Holder_var::_retn ()
162 // yield ownership of managed obj reference
163 TAO_AMH_DSI_Exception_Holder* tmp = this->ptr_;
164 this->ptr_ = 0;
165 return tmp;
168 void
169 TAO_AMH_DSI_Exception_Holder_var::tao_add_ref (TAO_AMH_DSI_Exception_Holder *p)
171 CORBA::add_ref (p);
174 void
175 TAO_AMH_DSI_Exception_Holder_var::tao_remove_ref (
176 TAO_AMH_DSI_Exception_Holder *p)
178 CORBA::remove_ref (p);
181 TAO_AMH_DSI_Exception_Holder_out::TAO_AMH_DSI_Exception_Holder_out (
182 TAO_AMH_DSI_Exception_Holder * &p)
183 : ptr_ (p)
185 this->ptr_ = 0;
188 TAO_AMH_DSI_Exception_Holder_out::TAO_AMH_DSI_Exception_Holder_out (
189 TAO_AMH_DSI_Exception_Holder_var & p)
190 : ptr_ (p.out ())
192 CORBA::remove_ref (this->ptr_);
193 this->ptr_ = 0;
196 TAO_AMH_DSI_Exception_Holder_out::TAO_AMH_DSI_Exception_Holder_out (
197 const TAO_AMH_DSI_Exception_Holder_out &p)
198 : ptr_ (const_cast<TAO_AMH_DSI_Exception_Holder_out&> (p).ptr_)
201 TAO_AMH_DSI_Exception_Holder_out &
202 TAO_AMH_DSI_Exception_Holder_out::operator= (
203 const TAO_AMH_DSI_Exception_Holder_out &p)
205 this->ptr_ = const_cast<TAO_AMH_DSI_Exception_Holder_out &> (p).ptr_;
206 return *this;
209 TAO_AMH_DSI_Exception_Holder_out &
210 TAO_AMH_DSI_Exception_Holder_out::operator= (
211 const TAO_AMH_DSI_Exception_Holder_var &p)
213 TAO_AMH_DSI_Exception_Holder *tmp = p.ptr ();
214 CORBA::add_ref (tmp);
215 this->ptr_ = tmp;
216 return *this;
219 TAO_AMH_DSI_Exception_Holder_out &
220 TAO_AMH_DSI_Exception_Holder_out::operator= (TAO_AMH_DSI_Exception_Holder *p)
222 this->ptr_ = p;
223 return *this;
226 TAO_AMH_DSI_Exception_Holder_out::operator TAO_AMH_DSI_Exception_Holder*& ()
228 return this->ptr_;
231 TAO_AMH_DSI_Exception_Holder *&
232 TAO_AMH_DSI_Exception_Holder_out::ptr () // ptr
234 return this->ptr_;
237 TAO_AMH_DSI_Exception_Holder *
238 TAO_AMH_DSI_Exception_Holder_out::operator-> ()
240 return this->ptr_;
243 TAO_AMH_DSI_Exception_Holder *
244 TAO_AMH_DSI_Exception_Holder::_downcast (CORBA::ValueBase * v)
246 return dynamic_cast < TAO_AMH_DSI_Exception_Holder * >(v);
249 const char *
250 TAO_AMH_DSI_Exception_Holder::_tao_obv_repository_id () const
252 return this->_tao_obv_static_repository_id ();
255 void
256 TAO_AMH_DSI_Exception_Holder::_tao_any_destructor (void *_tao_void_pointer)
258 TAO_AMH_DSI_Exception_Holder *tmp =
259 static_cast<TAO_AMH_DSI_Exception_Holder *> (_tao_void_pointer);
260 delete tmp;
263 CORBA::Boolean
264 TAO_AMH_DSI_Exception_Holder::_tao_unmarshal (
265 TAO_InputCDR &strm,
266 TAO_AMH_DSI_Exception_Holder *&new_object)
268 ::CORBA::ValueBase *base = 0;
269 ::CORBA::Boolean is_indirected = false;
270 ::CORBA::Boolean is_null_object = false;
271 ::CORBA::Boolean const retval =
272 ::CORBA::ValueBase::_tao_unmarshal_pre (
273 strm,
274 base,
275 TAO_AMH_DSI_Exception_Holder::_tao_obv_static_repository_id (),
276 is_null_object,
277 is_indirected);
279 ::CORBA::ValueBase_var owner (base);
281 if (!retval)
282 return false;
284 if (is_null_object)
285 return true;
287 if (!is_indirected && base != 0 && ! base->_tao_unmarshal_v (strm))
288 return false;
290 // Now base must be null or point to the unmarshaled object.
291 // Align the pointer to the right subobject.
292 new_object = TAO_AMH_DSI_Exception_Holder::_downcast (base);
293 if (is_indirected)
294 new_object->_add_ref ();
296 owner._retn ();
297 return true;
300 void
301 TAO_AMH_DSI_Exception_Holder::raise_invoke ()
303 std::unique_ptr< ::CORBA::Exception> safety (this->exception_);
304 this->exception_->_raise ();
307 // The pseudo-object _nil method.
308 TAO_AMH_DSI_Response_Handler_ptr
309 TAO_AMH_DSI_Response_Handler::_nil ()
311 return nullptr;
315 TAO_AMH_DSI_Response_Handler::TAO_AMH_DSI_Response_Handler (
316 TAO_ServerRequest & sr)
317 : TAO_AMH_Response_Handler (),
318 orb_core_ (sr.orb_core ())
322 TAO_AMH_DSI_Response_Handler::~TAO_AMH_DSI_Response_Handler ()
326 void
327 TAO_AMH_DSI_Response_Handler::invoke_reply (CORBA::NVList_ptr args,
328 CORBA::NamedValue_ptr result)
332 this->_tao_rh_init_reply ();
334 // Send the return value, if any.
335 if (result != 0 && result->value () != 0)
337 result->value ()->impl ()->marshal_value (this->_tao_out);
340 // Send the "inout" and "out" parameters.
341 if (args != 0)
343 args->_tao_encode (this->_tao_out, CORBA::ARG_INOUT | CORBA::ARG_OUT);
345 this->_tao_rh_send_reply ();
347 catch (const CORBA::Exception &)
349 // TODO:
353 void
354 TAO_AMH_DSI_Response_Handler::invoke_excep (TAO_AMH_DSI_Exception_Holder * h)
358 h->raise_invoke ();
360 catch (const CORBA::Exception & ex)
362 this->_tao_rh_send_exception (ex);
366 void
367 TAO_AMH_DSI_Response_Handler::invoke_location_forward (CORBA::Object_ptr fwd,
368 CORBA::Boolean is_perm)
370 this->_tao_rh_send_location_forward (fwd,is_perm);
373 void
374 TAO_AMH_DSI_Response_Handler::gateway_exception_reply (
375 CORBA::ULong reply_status,
376 TAO_OutputCDR & encap)
378 // for this to be effective, ACE & TAO must be built with
379 // ACE_ENABLE_SWAP_ON_WRITE defined in ace/config.h
380 this->_tao_out.reset_byte_order (encap.byte_order ());
381 // This reply path handles only user exceptions.
382 switch (reply_status)
384 case TAO_AMI_REPLY_USER_EXCEPTION:
385 this->reply_status_ = GIOP::USER_EXCEPTION;
386 break;
387 case TAO_AMI_REPLY_SYSTEM_EXCEPTION:
388 this->reply_status_ = GIOP::SYSTEM_EXCEPTION;
389 break;
391 // TODO: we don't handle location forward at this moment.
392 // need to be addressed later.
394 //case TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD:
395 // this->exception_type_ = TAO_GIOP_LOCATION_FORWARD;
396 // break;
400 this->_tao_rh_init_reply ();
402 // We know nothing about this exception, so we marshal it as a block
403 // of bytes. The outgoing stream's byte order has already been matched
404 // to the original source of the reply.
405 this->_tao_out.write_char_array (encap.buffer (),
406 ACE_Utils::truncate_cast<ACE_CDR::ULong> (encap.length ()));
407 // This will prevent the marshaling of any parameters into this reply.
408 // this->sent_gateway_exception_ = true;
409 this->_tao_rh_send_reply ();
411 catch (const CORBA::Exception &)
413 // TODO:
418 void
419 TAO_AMH_DSI_Response_Handler::gateway_exception_reply (
420 CORBA::ULong reply_status,
421 TAO_InputCDR &encap)
423 // for this to be effective, ACE & TAO must be built with
424 // ACE_ENABLE_SWAP_ON_WRITE defined in ace/config.h
425 this->_tao_out.reset_byte_order(encap.byte_order());
426 // This reply path handles only user exceptions.
427 switch (reply_status)
429 //case TAO_PLUGGABLE_MESSAGE_USER_EXCEPTION:
430 case TAO_AMI_REPLY_USER_EXCEPTION:
431 this->reply_status_ = GIOP::USER_EXCEPTION;
432 break;
433 case TAO_AMI_REPLY_SYSTEM_EXCEPTION:
434 this->reply_status_ = GIOP::SYSTEM_EXCEPTION;
435 break;
437 // we don't handle location forward at this moment.
438 // need to be addressed later.
440 //case TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD:
441 // this->exception_type_ = TAO_GIOP_LOCATION_FORWARD;
442 // break;
446 this->_tao_rh_init_reply ();
448 // We know nothing about this exception, so we marshal it as a block
449 // of bytes. The outgoing stream's byte order has already been matched
450 // to the original source of the reply.
451 this->_tao_out.write_octet_array_mb (encap.start());
452 // This will prevent the marshaling of any parameters into this reply.
453 // this->sent_gateway_exception_ = true;
454 this->_tao_rh_send_reply ();
456 catch (const CORBA::Exception &)
458 // TODO:
463 void *
464 TAO_AMH_DSI_Response_Handler::_downcast (const char *)
466 return this;
469 TAO_AMH_DSI_Response_Handler_ptr
470 TAO_AMH_DSI_Response_Handler::_narrow (CORBA::Object_ptr obj)
472 return TAO_AMH_DSI_Response_Handler::_unchecked_narrow (obj);
475 TAO_AMH_DSI_Response_Handler_ptr
476 TAO_AMH_DSI_Response_Handler::_unchecked_narrow (CORBA::Object_ptr obj)
478 if (CORBA::is_nil (obj))
479 return TAO_AMH_DSI_Response_Handler::_nil ();
481 return dynamic_cast <TAO_AMH_DSI_Response_Handler_ptr> (obj);
484 const char*
485 TAO_AMH_DSI_Response_Handler::_interface_repository_id () const
487 return 0;
490 CORBA::TypeCode_ptr
491 TAO_AMH_DSI_Exception_Holder::_tao_type () const
493 return 0;
496 void
497 TAO_AMH_DSI_Exception_Holder::_tao_obv_truncatable_repo_ids (
498 Repository_Id_List &) const
502 CORBA::Boolean
503 TAO_AMH_DSI_Exception_Holder::_tao_match_formal_type (ptrdiff_t ) const
505 return false;
508 CORBA::Boolean
509 TAO_AMH_DSI_Exception_Holder::_tao_marshal_v (TAO_OutputCDR &) const
511 return true;
514 CORBA::Boolean
515 TAO_AMH_DSI_Exception_Holder::_tao_unmarshal_v (TAO_InputCDR &)
517 return true;
520 CORBA::Boolean
521 TAO_AMH_DSI_Exception_Holder::_tao_marshal__Test_TAO_AMH_DSI_Exception_Holder (
522 TAO_OutputCDR &)
524 return true;
527 CORBA::Boolean
528 TAO_AMH_DSI_Exception_Holder::_tao_unmarshal__Test_TAO_AMH_DSI_Exception_Holder (
529 TAO_InputCDR &)
531 return true;
534 TAO_END_VERSIONED_NAMESPACE_DECL