AMH_DSI_Response_Handler.cpp

Go to the documentation of this file.
00001 // $Id: AMH_DSI_Response_Handler.cpp 79339 2007-08-14 17:49:17Z sowayaa $
00002 
00003 #include "AMH_DSI_Response_Handler.h"
00004 #include "Request.h"
00005 #include "ExceptionList.h"
00006 #include "DII_Invocation.h"
00007 #include "Server_Request.h"
00008 
00009 #include "tao/ORB_Core.h"
00010 #include "tao/GIOP_Utils.h"
00011 #include "tao/PortableServer/Root_POA.h"
00012 #include "tao/Valuetype/ValueFactory.h"
00013 #include "tao/Object.h"
00014 #include "tao/Pluggable_Messaging_Utils.h"
00015 #include "tao/AnyTypeCode/Any_Impl.h"
00016 
00017 ACE_RCSID (DynamicInterface, AMH_DSI_Response_Handler,
00018            "$Id: AMH_DSI_Response_Handler.cpp 79339 2007-08-14 17:49:17Z sowayaa $")
00019 
00020 #if !defined (__ACE_INLINE__)
00021 # include "AMH_DSI_Response_Handler.inl"
00022 #endif /* ! __ACE_INLINE__ */
00023 
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025 
00026 const char*
00027 TAO_AMH_DSI_Exception_Holder::_tao_obv_static_repository_id ()
00028 {
00029   return "IDL:TAO_AMH_DSI_Exception_Holder:1.0";
00030 }
00031 
00032 TAO_AMH_DSI_Exception_Holder::TAO_AMH_DSI_Exception_Holder (CORBA::Exception *ex)
00033   : exception_ (ex)
00034 {
00035 }
00036 
00037 TAO_AMH_DSI_Exception_Holder::~TAO_AMH_DSI_Exception_Holder ()
00038 {
00039 }
00040 
00041 void
00042 tao_TAO_AMH_DSI_Exception_Holder_add_ref (TAO_AMH_DSI_Exception_Holder * p)
00043 {
00044   CORBA::add_ref (p);
00045 }
00046 
00047 void
00048 tao_TAO_AMH_DSI_Exception_Holder_remove_ref (TAO_AMH_DSI_Exception_Holder * p)
00049 {
00050   CORBA::remove_ref (p);
00051 }
00052 
00053 
00054 TAO_AMH_DSI_Exception_Holder_var::TAO_AMH_DSI_Exception_Holder_var (void)
00055   : ptr_ (0)
00056 {
00057 }
00058 
00059 TAO_AMH_DSI_Exception_Holder_var::TAO_AMH_DSI_Exception_Holder_var (
00060     TAO_AMH_DSI_Exception_Holder * p)
00061   : ptr_ (p)
00062 {
00063 }
00064 
00065 TAO_AMH_DSI_Exception_Holder_var::TAO_AMH_DSI_Exception_Holder_var (
00066     const TAO_AMH_DSI_Exception_Holder * p)
00067   : ptr_ (const_cast<TAO_AMH_DSI_Exception_Holder *> (p))
00068 {
00069 }
00070 
00071 TAO_AMH_DSI_Exception_Holder *
00072 TAO_AMH_DSI_Exception_Holder_var::ptr (void) const
00073 {
00074   return this->ptr_;
00075 }
00076 
00077 TAO_AMH_DSI_Exception_Holder_var::TAO_AMH_DSI_Exception_Holder_var (
00078     const TAO_AMH_DSI_Exception_Holder_var & p)
00079 {
00080   CORBA::add_ref (p.ptr ());
00081   this->ptr_ = p.ptr ();
00082 }
00083 
00084 TAO_AMH_DSI_Exception_Holder_var::~TAO_AMH_DSI_Exception_Holder_var (void)
00085 {
00086   CORBA::remove_ref (this->ptr_);
00087 }
00088 
00089 TAO_AMH_DSI_Exception_Holder_var &
00090 TAO_AMH_DSI_Exception_Holder_var::operator= (TAO_AMH_DSI_Exception_Holder *p)
00091 {
00092   CORBA::remove_ref (this->ptr_);
00093   this->ptr_ = p;
00094   return *this;
00095 }
00096 
00097 TAO_AMH_DSI_Exception_Holder_var &
00098 TAO_AMH_DSI_Exception_Holder_var::operator= (
00099     const TAO_AMH_DSI_Exception_Holder_var & p)
00100 {
00101   if (this != &p)
00102     {
00103       CORBA::remove_ref (this->ptr_);
00104       TAO_AMH_DSI_Exception_Holder *tmp = p.ptr ();
00105       CORBA::add_ref (tmp);
00106       this->ptr_ = tmp;
00107     }
00108 
00109   return *this;
00110 }
00111 
00112 TAO_AMH_DSI_Exception_Holder_var::operator const TAO_AMH_DSI_Exception_Holder* (
00113     ) const // cast
00114 {
00115   return this->ptr_;
00116 }
00117 
00118 TAO_AMH_DSI_Exception_Holder_var::operator TAO_AMH_DSI_Exception_Holder*& (
00119     ) // cast
00120 {
00121   return this->ptr_;
00122 }
00123 
00124 TAO_AMH_DSI_Exception_Holder *
00125 TAO_AMH_DSI_Exception_Holder_var::operator-> (void) const
00126 {
00127   return this->ptr_;
00128 }
00129 
00130 TAO_AMH_DSI_Exception_Holder *
00131 TAO_AMH_DSI_Exception_Holder_var::in (void) const
00132 {
00133   return this->ptr_;
00134 }
00135 
00136 TAO_AMH_DSI_Exception_Holder *&
00137 TAO_AMH_DSI_Exception_Holder_var::inout (void)
00138 {
00139   return this->ptr_;
00140 }
00141 
00142 TAO_AMH_DSI_Exception_Holder *&
00143 TAO_AMH_DSI_Exception_Holder_var::out (void)
00144 {
00145   CORBA::remove_ref (this->ptr_);
00146   this->ptr_ = 0;
00147   return this->ptr_;
00148 }
00149 
00150 TAO_AMH_DSI_Exception_Holder *
00151 TAO_AMH_DSI_Exception_Holder_var::_retn (void)
00152 {
00153   // yield ownership of managed obj reference
00154   TAO_AMH_DSI_Exception_Holder* tmp = this->ptr_;
00155   this->ptr_ = 0;
00156   return tmp;
00157 }
00158 
00159 void
00160 TAO_AMH_DSI_Exception_Holder_var::tao_add_ref (
00161     TAO_AMH_DSI_Exception_Holder *p
00162   )
00163 {
00164   CORBA::add_ref (p);
00165 }
00166 
00167 void
00168 TAO_AMH_DSI_Exception_Holder_var::tao_remove_ref (
00169     TAO_AMH_DSI_Exception_Holder *p
00170   )
00171 {
00172   CORBA::remove_ref (p);
00173 }
00174 
00175 TAO_AMH_DSI_Exception_Holder_out::TAO_AMH_DSI_Exception_Holder_out (
00176     TAO_AMH_DSI_Exception_Holder * &p)
00177   : ptr_ (p)
00178 {
00179   this->ptr_ = 0;
00180 }
00181 
00182 TAO_AMH_DSI_Exception_Holder_out::TAO_AMH_DSI_Exception_Holder_out (
00183      TAO_AMH_DSI_Exception_Holder_var & p)
00184   : ptr_ (p.out ())
00185 {
00186   CORBA::remove_ref (this->ptr_);
00187   this->ptr_ = 0;
00188 }
00189 
00190 TAO_AMH_DSI_Exception_Holder_out::TAO_AMH_DSI_Exception_Holder_out (
00191     const TAO_AMH_DSI_Exception_Holder_out &p)
00192   : ptr_ (const_cast<TAO_AMH_DSI_Exception_Holder_out&> (p).ptr_)
00193 {}
00194 
00195 TAO_AMH_DSI_Exception_Holder_out &
00196 TAO_AMH_DSI_Exception_Holder_out::operator= (
00197     const TAO_AMH_DSI_Exception_Holder_out &p)
00198 {
00199   this->ptr_ = const_cast<TAO_AMH_DSI_Exception_Holder_out &> (p).ptr_;
00200   return *this;
00201 }
00202 
00203 TAO_AMH_DSI_Exception_Holder_out &
00204 TAO_AMH_DSI_Exception_Holder_out::operator= (
00205     const TAO_AMH_DSI_Exception_Holder_var &p)
00206 {
00207   TAO_AMH_DSI_Exception_Holder *tmp = p.ptr ();
00208   CORBA::add_ref (tmp);
00209   this->ptr_ = tmp;
00210   return *this;
00211 }
00212 
00213 TAO_AMH_DSI_Exception_Holder_out &
00214 TAO_AMH_DSI_Exception_Holder_out::operator= (TAO_AMH_DSI_Exception_Holder *p)
00215 {
00216   this->ptr_ = p;
00217   return *this;
00218 }
00219 
00220 TAO_AMH_DSI_Exception_Holder_out::operator TAO_AMH_DSI_Exception_Holder*& ()
00221 {
00222   return this->ptr_;
00223 }
00224 
00225 TAO_AMH_DSI_Exception_Holder *&
00226 TAO_AMH_DSI_Exception_Holder_out::ptr (void) // ptr
00227 {
00228   return this->ptr_;
00229 }
00230 
00231 TAO_AMH_DSI_Exception_Holder *
00232 TAO_AMH_DSI_Exception_Holder_out::operator-> (void)
00233 {
00234   return this->ptr_;
00235 }
00236 
00237 TAO_AMH_DSI_Exception_Holder *
00238 TAO_AMH_DSI_Exception_Holder::_downcast (CORBA::ValueBase * v)
00239 {
00240   return dynamic_cast < TAO_AMH_DSI_Exception_Holder * >(v);
00241 }
00242 
00243 const char *
00244 TAO_AMH_DSI_Exception_Holder::_tao_obv_repository_id (void) const
00245 {
00246   return this->_tao_obv_static_repository_id ();
00247 }
00248 
00249 void
00250 TAO_AMH_DSI_Exception_Holder::_tao_any_destructor (void *_tao_void_pointer)
00251 {
00252   TAO_AMH_DSI_Exception_Holder *tmp =
00253     static_cast<TAO_AMH_DSI_Exception_Holder *> (_tao_void_pointer);
00254   delete tmp;
00255 }
00256 
00257 CORBA::Boolean
00258 TAO_AMH_DSI_Exception_Holder::_tao_unmarshal (
00259     TAO_InputCDR &strm,
00260     TAO_AMH_DSI_Exception_Holder *&new_object
00261   )
00262 {
00263   CORBA::ValueBase *base = 0;
00264   CORBA::ValueFactory_var factory;
00265   CORBA::Boolean retval =
00266     CORBA::ValueBase::_tao_unmarshal_pre (
00267         strm,
00268         base,
00269         TAO_AMH_DSI_Exception_Holder::_tao_obv_static_repository_id ()
00270       );
00271 
00272   if (retval == 0)
00273     {
00274       return false;
00275     }
00276 
00277   if (factory.in () != 0)
00278     {
00279       base = factory->create_for_unmarshal ();
00280 
00281       if (base == 0)
00282         {
00283           return false;  // %! except.?
00284         }
00285 
00286       retval = base->_tao_unmarshal_v (strm);
00287 
00288       if (retval == 0)
00289         {
00290           return false;
00291         }
00292     }
00293 
00294   // Now base must be null or point to the unmarshaled object.
00295   // Align the pointer to the right subobject.
00296   new_object = TAO_AMH_DSI_Exception_Holder::_downcast (base);
00297   return retval;
00298 }
00299 
00300 void
00301 TAO_AMH_DSI_Exception_Holder::raise_invoke ()
00302 {
00303   this->exception_->_raise ();
00304 }
00305 
00306 // The pseudo-object _nil method.
00307 TAO_AMH_DSI_Response_Handler_ptr
00308 TAO_AMH_DSI_Response_Handler::_nil (void)
00309 {
00310   return (TAO_AMH_DSI_Response_Handler_ptr) 0;
00311 }
00312 
00313 
00314 TAO_AMH_DSI_Response_Handler::TAO_AMH_DSI_Response_Handler (
00315     TAO_ServerRequest & sr)
00316   : TAO_AMH_Response_Handler (),
00317     orb_core_ (sr.orb_core ())
00318 {
00319 }
00320 
00321 TAO_AMH_DSI_Response_Handler::~TAO_AMH_DSI_Response_Handler (void)
00322 {
00323 }
00324 
00325 void
00326 TAO_AMH_DSI_Response_Handler::invoke_reply (CORBA::NVList_ptr args,
00327                                             CORBA::NamedValue_ptr result)
00328 {
00329   try
00330    {
00331      this->_tao_rh_init_reply ();
00332 
00333     // Send the return value, if any.
00334     if (result != 0 && result->value () != 0)
00335       {
00336         result->value ()->impl ()->marshal_value (this->_tao_out);
00337       }
00338 
00339     // Send the "inout" and "out" parameters.
00340     if (args != 0)
00341       {
00342         args->_tao_encode (this->_tao_out, CORBA::ARG_INOUT | CORBA::ARG_OUT);
00343       }
00344     this->_tao_rh_send_reply ();
00345   }
00346   catch (const CORBA::Exception &)
00347     {
00348       // TODO:
00349     }
00350 }
00351 
00352 void
00353 TAO_AMH_DSI_Response_Handler::invoke_excep (TAO_AMH_DSI_Exception_Holder * h)
00354 {
00355   try
00356     {
00357       h->raise_invoke ();
00358     }
00359   catch (const CORBA::Exception & ex)
00360     {
00361       this->_tao_rh_send_exception (ex);
00362     }
00363 }
00364 
00365 void
00366 TAO_AMH_DSI_Response_Handler::gateway_exception_reply (
00367     CORBA::ULong reply_status,
00368     TAO_OutputCDR & encap)
00369 {
00370   // for this to be effective, ACE & TAO must be built with
00371   // ACE_ENABLE_SWAP_ON_WRITE defined in ace/config.h
00372   this->_tao_out.reset_byte_order (encap.byte_order ());
00373   // This reply path handles only user exceptions.
00374   switch (reply_status)
00375     {
00376     case TAO_AMI_REPLY_USER_EXCEPTION:
00377       this->exception_type_ = TAO_GIOP_USER_EXCEPTION;
00378       break;
00379     case TAO_AMI_REPLY_SYSTEM_EXCEPTION:
00380       this->exception_type_ = TAO_GIOP_SYSTEM_EXCEPTION;
00381       break;
00382 
00383       // TODO: we don't handle location forward at this moment.
00384       // need to be addressed later.
00385       //
00386       //case TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD:
00387       //  this->exception_type_ = TAO_GIOP_LOCATION_FORWARD;
00388       //  break;
00389     }
00390   try
00391     {
00392       this->_tao_rh_init_reply ();
00393 
00394       // We know nothing about this exception, so we marshal it as a block
00395       // of bytes. The outgoing stream's byte order has already been matched
00396       // to the original source of the reply.
00397       this->_tao_out.write_char_array (encap.buffer (), encap.length ());
00398       // This will prevent the marshaling of any parameters into this reply.
00399       //  this->sent_gateway_exception_ = 1;
00400       this->_tao_rh_send_reply ();
00401     }
00402   catch (const CORBA::Exception &)
00403     {
00404       // TODO:
00405     }
00406 
00407 }
00408 
00409 void
00410 TAO_AMH_DSI_Response_Handler::gateway_exception_reply (
00411     CORBA::ULong reply_status,
00412     TAO_InputCDR &encap)
00413 {
00414   // for this to be effective, ACE & TAO must be built with
00415   // ACE_ENABLE_SWAP_ON_WRITE defined in ace/config.h
00416   this->_tao_out.reset_byte_order(encap.byte_order());
00417   // This reply path handles only user exceptions.
00418   switch (reply_status)
00419     {
00420     //case TAO_PLUGGABLE_MESSAGE_USER_EXCEPTION:
00421     case TAO_AMI_REPLY_USER_EXCEPTION:
00422       this->exception_type_ = TAO_GIOP_USER_EXCEPTION;
00423       break;
00424     case TAO_AMI_REPLY_SYSTEM_EXCEPTION:
00425       this->exception_type_ = TAO_GIOP_SYSTEM_EXCEPTION;
00426       break;
00427 
00428     // we don't handle location forward at this moment.
00429     // need to be addressed later.
00430     //
00431     //case TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD:
00432     //  this->exception_type_ = TAO_GIOP_LOCATION_FORWARD;
00433     //  break;
00434     }
00435   try
00436   {
00437     this->_tao_rh_init_reply ();
00438 
00439   // We know nothing about this exception, so we marshal it as a block
00440   // of bytes. The outgoing stream's byte order has already been matched
00441   // to the original source of the reply.
00442     this->_tao_out.write_octet_array_mb (encap.start());
00443   // This will prevent the marshaling of any parameters into this reply.
00444   //  this->sent_gateway_exception_ = 1;
00445     this->_tao_rh_send_reply ();
00446   }
00447   catch (const CORBA::Exception &)
00448   {
00449     // TODO:
00450   }
00451 
00452 }
00453 
00454 void *
00455 TAO_AMH_DSI_Response_Handler::_downcast (const char *)
00456 {
00457   return this;
00458 }
00459 
00460 TAO_AMH_DSI_Response_Handler_ptr
00461 TAO_AMH_DSI_Response_Handler::_narrow (CORBA::Object_ptr obj)
00462 {
00463   return TAO_AMH_DSI_Response_Handler::_unchecked_narrow (obj);
00464 }
00465 
00466 TAO_AMH_DSI_Response_Handler_ptr
00467 TAO_AMH_DSI_Response_Handler::_unchecked_narrow (CORBA::Object_ptr obj)
00468 {
00469   if (CORBA::is_nil (obj))
00470     return TAO_AMH_DSI_Response_Handler::_nil ();
00471 
00472   return dynamic_cast < TAO_AMH_DSI_Response_Handler_ptr > (obj);
00473 }
00474 
00475 const char*
00476 TAO_AMH_DSI_Response_Handler::_interface_repository_id (void) const
00477 {
00478   return 0;
00479 }
00480 
00481 CORBA::TypeCode_ptr
00482 TAO_AMH_DSI_Exception_Holder::_tao_type (void) const
00483 {
00484   return 0;
00485 }
00486 
00487 void
00488 TAO_AMH_DSI_Exception_Holder::_tao_obv_truncatable_repo_ids (
00489     Repository_Id_List &) const
00490 {
00491 }
00492 
00493 CORBA::Boolean
00494 TAO_AMH_DSI_Exception_Holder::_tao_match_formal_type (ptrdiff_t ) const
00495 {
00496   return false;
00497 }
00498 
00499 CORBA::Boolean
00500 TAO_AMH_DSI_Exception_Holder::_tao_marshal_v (TAO_OutputCDR &) const
00501 {
00502   return true;
00503 }
00504 
00505 CORBA::Boolean
00506 TAO_AMH_DSI_Exception_Holder::_tao_unmarshal_v (TAO_InputCDR &)
00507 {
00508   return true;
00509 }
00510 
00511 CORBA::Boolean
00512 TAO_AMH_DSI_Exception_Holder::_tao_marshal__Test_TAO_AMH_DSI_Exception_Holder (
00513     TAO_OutputCDR &)
00514 {
00515   return true;
00516 }
00517 
00518 CORBA::Boolean
00519 TAO_AMH_DSI_Exception_Holder::_tao_unmarshal__Test_TAO_AMH_DSI_Exception_Holder (
00520     TAO_InputCDR &)
00521 {
00522   return true;
00523 }
00524 
00525 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 13:37:31 2008 for TAO_DynamicInterface by doxygen 1.3.6