AMH_DSI_Response_Handler.cpp

Go to the documentation of this file.
00001 // $Id: AMH_DSI_Response_Handler.cpp 81429 2008-04-24 18:49:54Z johnnyw $
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 81429 2008-04-24 18:49:54Z johnnyw $")
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 {
00120   return this->ptr_;
00121 }
00122 
00123 TAO_AMH_DSI_Exception_Holder *
00124 TAO_AMH_DSI_Exception_Holder_var::operator-> (void) const
00125 {
00126   return this->ptr_;
00127 }
00128 
00129 TAO_AMH_DSI_Exception_Holder *
00130 TAO_AMH_DSI_Exception_Holder_var::in (void) const
00131 {
00132   return this->ptr_;
00133 }
00134 
00135 TAO_AMH_DSI_Exception_Holder *&
00136 TAO_AMH_DSI_Exception_Holder_var::inout (void)
00137 {
00138   return this->ptr_;
00139 }
00140 
00141 TAO_AMH_DSI_Exception_Holder *&
00142 TAO_AMH_DSI_Exception_Holder_var::out (void)
00143 {
00144   CORBA::remove_ref (this->ptr_);
00145   this->ptr_ = 0;
00146   return this->ptr_;
00147 }
00148 
00149 TAO_AMH_DSI_Exception_Holder *
00150 TAO_AMH_DSI_Exception_Holder_var::_retn (void)
00151 {
00152   // yield ownership of managed obj reference
00153   TAO_AMH_DSI_Exception_Holder* tmp = this->ptr_;
00154   this->ptr_ = 0;
00155   return tmp;
00156 }
00157 
00158 void
00159 TAO_AMH_DSI_Exception_Holder_var::tao_add_ref (TAO_AMH_DSI_Exception_Holder *p)
00160 {
00161   CORBA::add_ref (p);
00162 }
00163 
00164 void
00165 TAO_AMH_DSI_Exception_Holder_var::tao_remove_ref (
00166     TAO_AMH_DSI_Exception_Holder *p)
00167 {
00168   CORBA::remove_ref (p);
00169 }
00170 
00171 TAO_AMH_DSI_Exception_Holder_out::TAO_AMH_DSI_Exception_Holder_out (
00172     TAO_AMH_DSI_Exception_Holder * &p)
00173   : ptr_ (p)
00174 {
00175   this->ptr_ = 0;
00176 }
00177 
00178 TAO_AMH_DSI_Exception_Holder_out::TAO_AMH_DSI_Exception_Holder_out (
00179      TAO_AMH_DSI_Exception_Holder_var & p)
00180   : ptr_ (p.out ())
00181 {
00182   CORBA::remove_ref (this->ptr_);
00183   this->ptr_ = 0;
00184 }
00185 
00186 TAO_AMH_DSI_Exception_Holder_out::TAO_AMH_DSI_Exception_Holder_out (
00187     const TAO_AMH_DSI_Exception_Holder_out &p)
00188   : ptr_ (const_cast<TAO_AMH_DSI_Exception_Holder_out&> (p).ptr_)
00189 {}
00190 
00191 TAO_AMH_DSI_Exception_Holder_out &
00192 TAO_AMH_DSI_Exception_Holder_out::operator= (
00193     const TAO_AMH_DSI_Exception_Holder_out &p)
00194 {
00195   this->ptr_ = const_cast<TAO_AMH_DSI_Exception_Holder_out &> (p).ptr_;
00196   return *this;
00197 }
00198 
00199 TAO_AMH_DSI_Exception_Holder_out &
00200 TAO_AMH_DSI_Exception_Holder_out::operator= (
00201     const TAO_AMH_DSI_Exception_Holder_var &p)
00202 {
00203   TAO_AMH_DSI_Exception_Holder *tmp = p.ptr ();
00204   CORBA::add_ref (tmp);
00205   this->ptr_ = tmp;
00206   return *this;
00207 }
00208 
00209 TAO_AMH_DSI_Exception_Holder_out &
00210 TAO_AMH_DSI_Exception_Holder_out::operator= (TAO_AMH_DSI_Exception_Holder *p)
00211 {
00212   this->ptr_ = p;
00213   return *this;
00214 }
00215 
00216 TAO_AMH_DSI_Exception_Holder_out::operator TAO_AMH_DSI_Exception_Holder*& ()
00217 {
00218   return this->ptr_;
00219 }
00220 
00221 TAO_AMH_DSI_Exception_Holder *&
00222 TAO_AMH_DSI_Exception_Holder_out::ptr (void) // ptr
00223 {
00224   return this->ptr_;
00225 }
00226 
00227 TAO_AMH_DSI_Exception_Holder *
00228 TAO_AMH_DSI_Exception_Holder_out::operator-> (void)
00229 {
00230   return this->ptr_;
00231 }
00232 
00233 TAO_AMH_DSI_Exception_Holder *
00234 TAO_AMH_DSI_Exception_Holder::_downcast (CORBA::ValueBase * v)
00235 {
00236   return dynamic_cast < TAO_AMH_DSI_Exception_Holder * >(v);
00237 }
00238 
00239 const char *
00240 TAO_AMH_DSI_Exception_Holder::_tao_obv_repository_id (void) const
00241 {
00242   return this->_tao_obv_static_repository_id ();
00243 }
00244 
00245 void
00246 TAO_AMH_DSI_Exception_Holder::_tao_any_destructor (void *_tao_void_pointer)
00247 {
00248   TAO_AMH_DSI_Exception_Holder *tmp =
00249     static_cast<TAO_AMH_DSI_Exception_Holder *> (_tao_void_pointer);
00250   delete tmp;
00251 }
00252 
00253 CORBA::Boolean
00254 TAO_AMH_DSI_Exception_Holder::_tao_unmarshal (
00255     TAO_InputCDR &strm,
00256     TAO_AMH_DSI_Exception_Holder *&new_object
00257   )
00258 {
00259   CORBA::ValueBase *base = 0;
00260   CORBA::ValueFactory_var factory;
00261   CORBA::Boolean retval =
00262     CORBA::ValueBase::_tao_unmarshal_pre (
00263         strm,
00264         base,
00265         TAO_AMH_DSI_Exception_Holder::_tao_obv_static_repository_id ()
00266       );
00267 
00268   if (retval == 0)
00269     {
00270       return false;
00271     }
00272 
00273   if (factory.in () != 0)
00274     {
00275       base = factory->create_for_unmarshal ();
00276 
00277       if (base == 0)
00278         {
00279           return false;  // %! except.?
00280         }
00281 
00282       retval = base->_tao_unmarshal_v (strm);
00283 
00284       if (retval == 0)
00285         {
00286           return false;
00287         }
00288     }
00289 
00290   // Now base must be null or point to the unmarshaled object.
00291   // Align the pointer to the right subobject.
00292   new_object = TAO_AMH_DSI_Exception_Holder::_downcast (base);
00293   return retval;
00294 }
00295 
00296 void
00297 TAO_AMH_DSI_Exception_Holder::raise_invoke ()
00298 {
00299   this->exception_->_raise ();
00300 }
00301 
00302 // The pseudo-object _nil method.
00303 TAO_AMH_DSI_Response_Handler_ptr
00304 TAO_AMH_DSI_Response_Handler::_nil (void)
00305 {
00306   return (TAO_AMH_DSI_Response_Handler_ptr) 0;
00307 }
00308 
00309 
00310 TAO_AMH_DSI_Response_Handler::TAO_AMH_DSI_Response_Handler (
00311     TAO_ServerRequest & sr)
00312   : TAO_AMH_Response_Handler (),
00313     orb_core_ (sr.orb_core ())
00314 {
00315 }
00316 
00317 TAO_AMH_DSI_Response_Handler::~TAO_AMH_DSI_Response_Handler (void)
00318 {
00319 }
00320 
00321 void
00322 TAO_AMH_DSI_Response_Handler::invoke_reply (CORBA::NVList_ptr args,
00323                                             CORBA::NamedValue_ptr result)
00324 {
00325   try
00326    {
00327      this->_tao_rh_init_reply ();
00328 
00329     // Send the return value, if any.
00330     if (result != 0 && result->value () != 0)
00331       {
00332         result->value ()->impl ()->marshal_value (this->_tao_out);
00333       }
00334 
00335     // Send the "inout" and "out" parameters.
00336     if (args != 0)
00337       {
00338         args->_tao_encode (this->_tao_out, CORBA::ARG_INOUT | CORBA::ARG_OUT);
00339       }
00340     this->_tao_rh_send_reply ();
00341   }
00342   catch (const CORBA::Exception &)
00343     {
00344       // TODO:
00345     }
00346 }
00347 
00348 void
00349 TAO_AMH_DSI_Response_Handler::invoke_excep (TAO_AMH_DSI_Exception_Holder * h)
00350 {
00351   try
00352     {
00353       h->raise_invoke ();
00354     }
00355   catch (const CORBA::Exception & ex)
00356     {
00357       this->_tao_rh_send_exception (ex);
00358     }
00359 }
00360 
00361 void
00362 TAO_AMH_DSI_Response_Handler::invoke_location_forward (CORBA::Object_ptr fwd,
00363                                                        CORBA::Boolean is_perm)
00364 {
00365   this->_tao_rh_send_location_forward (fwd,is_perm);
00366 }
00367 
00368 void
00369 TAO_AMH_DSI_Response_Handler::gateway_exception_reply (
00370     CORBA::ULong reply_status,
00371     TAO_OutputCDR & encap)
00372 {
00373   // for this to be effective, ACE & TAO must be built with
00374   // ACE_ENABLE_SWAP_ON_WRITE defined in ace/config.h
00375   this->_tao_out.reset_byte_order (encap.byte_order ());
00376   // This reply path handles only user exceptions.
00377   switch (reply_status)
00378     {
00379     case TAO_AMI_REPLY_USER_EXCEPTION:
00380       this->reply_status_ = GIOP::USER_EXCEPTION;
00381       break;
00382     case TAO_AMI_REPLY_SYSTEM_EXCEPTION:
00383       this->reply_status_ = GIOP::SYSTEM_EXCEPTION;
00384       break;
00385 
00386       // TODO: we don't handle location forward at this moment.
00387       // need to be addressed later.
00388       //
00389       //case TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD:
00390       //  this->exception_type_ = TAO_GIOP_LOCATION_FORWARD;
00391       //  break;
00392     }
00393   try
00394     {
00395       this->_tao_rh_init_reply ();
00396 
00397       // We know nothing about this exception, so we marshal it as a block
00398       // of bytes. The outgoing stream's byte order has already been matched
00399       // to the original source of the reply.
00400       this->_tao_out.write_char_array (encap.buffer (), encap.length ());
00401       // This will prevent the marshaling of any parameters into this reply.
00402       //  this->sent_gateway_exception_ = 1;
00403       this->_tao_rh_send_reply ();
00404     }
00405   catch (const CORBA::Exception &)
00406     {
00407       // TODO:
00408     }
00409 
00410 }
00411 
00412 void
00413 TAO_AMH_DSI_Response_Handler::gateway_exception_reply (
00414     CORBA::ULong reply_status,
00415     TAO_InputCDR &encap)
00416 {
00417   // for this to be effective, ACE & TAO must be built with
00418   // ACE_ENABLE_SWAP_ON_WRITE defined in ace/config.h
00419   this->_tao_out.reset_byte_order(encap.byte_order());
00420   // This reply path handles only user exceptions.
00421   switch (reply_status)
00422     {
00423     //case TAO_PLUGGABLE_MESSAGE_USER_EXCEPTION:
00424     case TAO_AMI_REPLY_USER_EXCEPTION:
00425       this->reply_status_ = GIOP::USER_EXCEPTION;
00426       break;
00427     case TAO_AMI_REPLY_SYSTEM_EXCEPTION:
00428       this->reply_status_ = GIOP::SYSTEM_EXCEPTION;
00429       break;
00430 
00431     // we don't handle location forward at this moment.
00432     // need to be addressed later.
00433     //
00434     //case TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD:
00435     //  this->exception_type_ = TAO_GIOP_LOCATION_FORWARD;
00436     //  break;
00437     }
00438   try
00439   {
00440     this->_tao_rh_init_reply ();
00441 
00442   // We know nothing about this exception, so we marshal it as a block
00443   // of bytes. The outgoing stream's byte order has already been matched
00444   // to the original source of the reply.
00445     this->_tao_out.write_octet_array_mb (encap.start());
00446   // This will prevent the marshaling of any parameters into this reply.
00447   //  this->sent_gateway_exception_ = 1;
00448     this->_tao_rh_send_reply ();
00449   }
00450   catch (const CORBA::Exception &)
00451   {
00452     // TODO:
00453   }
00454 
00455 }
00456 
00457 void *
00458 TAO_AMH_DSI_Response_Handler::_downcast (const char *)
00459 {
00460   return this;
00461 }
00462 
00463 TAO_AMH_DSI_Response_Handler_ptr
00464 TAO_AMH_DSI_Response_Handler::_narrow (CORBA::Object_ptr obj)
00465 {
00466   return TAO_AMH_DSI_Response_Handler::_unchecked_narrow (obj);
00467 }
00468 
00469 TAO_AMH_DSI_Response_Handler_ptr
00470 TAO_AMH_DSI_Response_Handler::_unchecked_narrow (CORBA::Object_ptr obj)
00471 {
00472   if (CORBA::is_nil (obj))
00473     return TAO_AMH_DSI_Response_Handler::_nil ();
00474 
00475   return dynamic_cast < TAO_AMH_DSI_Response_Handler_ptr > (obj);
00476 }
00477 
00478 const char*
00479 TAO_AMH_DSI_Response_Handler::_interface_repository_id (void) const
00480 {
00481   return 0;
00482 }
00483 
00484 CORBA::TypeCode_ptr
00485 TAO_AMH_DSI_Exception_Holder::_tao_type (void) const
00486 {
00487   return 0;
00488 }
00489 
00490 void
00491 TAO_AMH_DSI_Exception_Holder::_tao_obv_truncatable_repo_ids (
00492     Repository_Id_List &) const
00493 {
00494 }
00495 
00496 CORBA::Boolean
00497 TAO_AMH_DSI_Exception_Holder::_tao_match_formal_type (ptrdiff_t ) const
00498 {
00499   return false;
00500 }
00501 
00502 CORBA::Boolean
00503 TAO_AMH_DSI_Exception_Holder::_tao_marshal_v (TAO_OutputCDR &) const
00504 {
00505   return true;
00506 }
00507 
00508 CORBA::Boolean
00509 TAO_AMH_DSI_Exception_Holder::_tao_unmarshal_v (TAO_InputCDR &)
00510 {
00511   return true;
00512 }
00513 
00514 CORBA::Boolean
00515 TAO_AMH_DSI_Exception_Holder::_tao_marshal__Test_TAO_AMH_DSI_Exception_Holder (
00516     TAO_OutputCDR &)
00517 {
00518   return true;
00519 }
00520 
00521 CORBA::Boolean
00522 TAO_AMH_DSI_Exception_Holder::_tao_unmarshal__Test_TAO_AMH_DSI_Exception_Holder (
00523     TAO_InputCDR &)
00524 {
00525   return true;
00526 }
00527 
00528 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:43:23 2010 for TAO_DynamicInterface by  doxygen 1.4.7