Invocation_Base.cpp

Go to the documentation of this file.
00001 #include "tao/Invocation_Base.h"
00002 #include "tao/Stub.h"
00003 #include "tao/operation_details.h"
00004 #include "tao/ORB_Core.h"
00005 #include "tao/SystemException.h"
00006 #include "tao/PortableInterceptor.h"  /* Must always be visible. */
00007 
00008 #include "ace/Dynamic_Service.h"
00009 
00010 #if TAO_HAS_INTERCEPTORS == 1
00011 # include "tao/PortableInterceptorC.h"
00012 # include "tao/ClientRequestInterceptor_Adapter_Factory.h"
00013 #endif /* TAO_HAS_INTERCEPTORS == 1 */
00014 
00015 #if !defined (__ACE_INLINE__)
00016 # include "tao/Invocation_Base.inl"
00017 #endif /* __ACE_INLINE__ */
00018 
00019 
00020 ACE_RCSID (tao,
00021            Invocation_Base,
00022            "$Id: Invocation_Base.cpp 76995 2007-02-11 12:51:42Z johnnyw $")
00023 
00024 
00025 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00026 
00027 namespace
00028 {
00029   // Exception used to represent non-CORBA exceptions.  A global
00030   // instance is used since it will never be modified.
00031   CORBA::UNKNOWN /* const */ unknown_exception;
00032 }
00033 
00034 namespace TAO
00035 {
00036   Invocation_Base::Invocation_Base (CORBA::Object_ptr ot,
00037                                     CORBA::Object_ptr t,
00038                                     TAO_Stub *stub,
00039                                     TAO_Operation_Details &details,
00040                                     bool response_expected,
00041                                     bool TAO_INTERCEPTOR (request_is_remote))
00042     : details_ (details)
00043     , forwarded_to_ (0)
00044     , response_expected_ (response_expected)
00045     , otarget_ (ot)
00046     , target_ (t)
00047     , orb_core_ (stub->orb_core ())
00048     , stub_ (stub)
00049 #if TAO_HAS_INTERCEPTORS == 1
00050     , adapter_ (orb_core_->clientrequestinterceptor_adapter ())
00051     , stack_size_ (0)
00052     , invoke_status_ (TAO_INVOKE_START)
00053     , caught_exception_ (0)
00054     , is_remote_request_ (request_is_remote)
00055 #endif /* TAO_HAS_INTERCEPTORS == 1 */
00056   {
00057   }
00058 
00059   Invocation_Base::~Invocation_Base (void)
00060   {
00061 #if TAO_HAS_INTERCEPTORS == 1
00062     adapter_ = 0;
00063 #endif /* TAO_HAS_INTERCEPTORS == 1 */
00064   }
00065 
00066   void
00067   Invocation_Base::reply_received (Invocation_Status TAO_INTERCEPTOR (s))
00068   {
00069     TAO_INTERCEPTOR (invoke_status_ = s);
00070   }
00071 
00072   TAO_Service_Context &
00073   Invocation_Base::request_service_context (void)
00074   {
00075     return this->details_.request_service_context ();
00076   }
00077 
00078   TAO_Service_Context &
00079   Invocation_Base::reply_service_context (void)
00080   {
00081     return this->details_.reply_service_context ();
00082   }
00083 
00084 #if TAO_HAS_INTERCEPTORS == 1
00085 
00086   Invocation_Status
00087   Invocation_Base::send_request_interception (void)
00088   {
00089     if (adapter_ != 0)
00090       {
00091         try
00092           {
00093             // This is a begin interception point
00094             this->adapter_->send_request (*this);
00095           }
00096         catch ( ::CORBA::Exception& ex)
00097           {
00098             (void) this->handle_any_exception (&ex);
00099             throw;
00100           }
00101         catch (...)
00102           {
00103             (void) this->handle_all_exception ();
00104             throw;
00105           }
00106 
00107         if (this->forwarded_to_.in ())
00108           return TAO_INVOKE_RESTART;
00109       }
00110 
00111     // What are the other cases??
00112     return TAO_INVOKE_SUCCESS;
00113   }
00114 
00115   Invocation_Status
00116   Invocation_Base::receive_reply_interception (void)
00117   {
00118     if (adapter_ != 0)
00119       {
00120         try
00121           {
00122             this->adapter_->receive_reply (*this);
00123           }
00124         catch ( ::CORBA::Exception& ex)
00125           {
00126             (void) this->handle_any_exception (&ex);
00127             throw;
00128           }
00129         catch (...)
00130           {
00131             (void) this->handle_all_exception ();
00132             throw;
00133           }
00134 
00135         PortableInterceptor::ReplyStatus const status =
00136           this->adapter_->reply_status (*this);
00137 
00138         if (status == PortableInterceptor::LOCATION_FORWARD ||
00139             status == PortableInterceptor::TRANSPORT_RETRY)
00140           return TAO_INVOKE_RESTART;
00141       }
00142 
00143     return TAO_INVOKE_SUCCESS;
00144   }
00145 
00146 
00147   Invocation_Status
00148   Invocation_Base::receive_other_interception (void)
00149   {
00150     if (adapter_ != 0)
00151       {
00152         try
00153           {
00154             this->adapter_->receive_other (*this);
00155           }
00156         catch ( ::CORBA::Exception& ex)
00157           {
00158             (void) this->handle_any_exception (&ex);
00159             throw;
00160           }
00161         catch (...)
00162           {
00163             (void) this->handle_all_exception ();
00164             throw;
00165           }
00166 
00167         if (this->forwarded_to_.in ())
00168           return TAO_INVOKE_RESTART;
00169       }
00170 
00171     return TAO_INVOKE_SUCCESS;
00172   }
00173 
00174   PortableInterceptor::ReplyStatus
00175   Invocation_Base::handle_any_exception (CORBA::Exception *ex)
00176   {
00177     this->exception (ex);
00178 
00179     PortableInterceptor::ReplyStatus status =
00180       PortableInterceptor::SYSTEM_EXCEPTION;
00181 
00182     if (adapter_ != 0)
00183       {
00184         this->adapter_->receive_exception (*this);
00185 
00186         if (this->forwarded_to_.in ())
00187           {
00188             status = PortableInterceptor::LOCATION_FORWARD;
00189           }
00190         else
00191           {
00192             status = this->adapter_->reply_status (*this);
00193           }
00194       }
00195 
00196     return status;
00197   }
00198 
00199   PortableInterceptor::ReplyStatus
00200   Invocation_Base::handle_all_exception (void)
00201   {
00202     this->exception (&unknown_exception);
00203 
00204     PortableInterceptor::ReplyStatus status =
00205       PortableInterceptor::SYSTEM_EXCEPTION;
00206 
00207     if (adapter_ != 0)
00208       {
00209         this->adapter_->receive_exception (*this);
00210 
00211         status = this->adapter_->reply_status (*this);
00212       }
00213 
00214     return status;
00215   }
00216 
00217   void
00218   Invocation_Base::exception (CORBA::Exception *exception)
00219   {
00220     if (CORBA::SystemException::_downcast (exception) != 0)
00221       this->invoke_status_ = TAO::TAO_INVOKE_SYSTEM_EXCEPTION;
00222     else if (CORBA::UserException::_downcast (exception) != 0)
00223       this->invoke_status_ = TAO::TAO_INVOKE_USER_EXCEPTION;
00224 
00225     this->forwarded_to_ = CORBA::Object::_nil ();
00226     this->caught_exception_ = exception;
00227   }
00228 
00229   PortableInterceptor::ReplyStatus
00230   Invocation_Base::reply_status (void) const
00231   {
00232     if (adapter_ != 0)
00233       {
00234         return this->adapter_->reply_status (*this);
00235       }
00236     else
00237       {
00238         return -1;
00239       }
00240   }
00241 #endif  /* TAO_HAS_INTERCEPTORS == 1 */
00242 }
00243 
00244 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 13:07:33 2008 for TAO by doxygen 1.3.6