DII_Invocation_Adapter.cpp

Go to the documentation of this file.
00001 //$Id: DII_Invocation_Adapter.cpp 81632 2008-05-07 09:19:05Z vzykov $
00002 #include "tao/AnyTypeCode/TypeCode.h"
00003 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
00004 #include "tao/DynamicInterface/DII_Invocation_Adapter.h"
00005 #include "tao/DynamicInterface/DII_Invocation.h"
00006 #include "tao/DynamicInterface/DII_Reply_Dispatcher.h"
00007 #include "tao/DynamicInterface/DII_Arguments_Converter_Impl.h"
00008 #include "tao/DynamicInterface/Request.h"
00009 
00010 #include "tao/Exception.h"
00011 #include "tao/Exception_Data.h"
00012 #include "tao/ORB_Constants.h"
00013 #include "tao/Profile_Transport_Resolver.h"
00014 #include "tao/Transport.h"
00015 #include "tao/GIOP_Message_Base.h"
00016 #include "tao/SystemException.h"
00017 #include "tao/operation_details.h"
00018 
00019 #include "ace/os_include/os_errno.h"
00020 
00021 ACE_RCSID (DynamicInterface,
00022            DII_Invocation_Adapter,
00023            "$Id: DII_Invocation_Adapter.cpp 81632 2008-05-07 09:19:05Z vzykov $")
00024 
00025 
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027 
00028 namespace TAO
00029 {
00030   DII_Invocation_Adapter::DII_Invocation_Adapter (CORBA::Object *target,
00031                                                   Argument **args,
00032                                                   int arg_number,
00033                                                   const char *operation,
00034                                                   size_t op_len,
00035                                                   CORBA::ExceptionList *excp,
00036                                                   CORBA::Request *r,
00037                                                   Invocation_Mode mode)
00038 
00039     : Invocation_Adapter (target,
00040                           args,
00041                           arg_number,
00042                           operation,
00043                           op_len,
00044                           0, // Collocation Proxy broker pointer
00045                           TAO_TWOWAY_INVOCATION,
00046                           mode)
00047       , exception_list_ (excp)
00048       , request_ (r)
00049       , ex_data_ (0)
00050   {
00051   }
00052 
00053   DII_Invocation_Adapter::~DII_Invocation_Adapter (void)
00054   {
00055     delete[] ex_data_;
00056   }
00057 
00058   void
00059   DII_Invocation_Adapter::invoke (TAO::Exception_Data * /*ex_data*/,
00060                                   unsigned long ex_count)
00061   {
00062     // Convert DII exception list to a form the invocation can use
00063     // to filter raised user exceptions.
00064     ex_count = this->exception_list_->count ();
00065     ACE_NEW_THROW_EX (this->ex_data_,
00066                       TAO::Exception_Data[ex_count],
00067                       CORBA::NO_MEMORY ());
00068     for (unsigned long l=0; l<ex_count ;++l)
00069     {
00070       CORBA::TypeCode_var xtc = this->exception_list_->item (l);
00071       this->ex_data_[l].id = xtc->id ();
00072       this->ex_data_[l].alloc = 0;
00073 #if TAO_HAS_INTERCEPTORS == 1
00074       this->ex_data_[l].tc_ptr = xtc.in ();
00075 #endif
00076     }
00077 
00078     Invocation_Adapter::invoke (this->ex_data_, ex_count);
00079   }
00080 
00081   Invocation_Status
00082   DII_Invocation_Adapter::invoke_collocated_i (
00083     TAO_Stub *stub,
00084     TAO_Operation_Details &details,
00085     CORBA::Object_var &effective_target,
00086     Collocation_Strategy strat)
00087   {
00088     TAO_DII_Arguments_Converter_Impl* dii_arguments_converter
00089       = ACE_Dynamic_Service<TAO_DII_Arguments_Converter_Impl>::instance (
00090         "DII_Arguments_Converter");
00091     details.cac (dii_arguments_converter);
00092 
00093     return Invocation_Adapter::invoke_collocated_i (stub,
00094                                                     details,
00095                                                     effective_target,
00096                                                     strat);
00097   }
00098 
00099   Invocation_Status
00100   DII_Invocation_Adapter::invoke_twoway (
00101         TAO_Operation_Details &op,
00102         CORBA::Object_var &effective_target,
00103         Profile_Transport_Resolver &r,
00104         ACE_Time_Value *&max_wait_time)
00105   {
00106     // Simple sanity check
00107     if (this->mode_ != TAO_DII_INVOCATION ||
00108         this->type_ != TAO_TWOWAY_INVOCATION)
00109       {
00110         throw ::CORBA::INTERNAL (
00111           CORBA::SystemException::_tao_minor_code (
00112             TAO::VMCID,
00113             EINVAL),
00114           CORBA::COMPLETED_NO);
00115       }
00116 
00117     TAO_Transport* const transport = r.transport ();
00118 
00119     if (!transport)
00120       {
00121         // Way back, we failed to find a profile we could connect to.
00122         // We've come this far only so we reach the interception points
00123         // in case they can fix things. Time to bail....
00124         throw CORBA::TRANSIENT (CORBA::OMGVMCID | 2, CORBA::COMPLETED_NO);
00125       }
00126 
00127     transport->messaging_object ()->out_stream ().reset_byte_order (
00128         request_->_tao_byte_order ());
00129 
00130     TAO::DII_Invocation synch (this->target_,
00131                                r,
00132                                op,
00133                                this->exception_list_,
00134                                this->request_);
00135 
00136 
00137     Invocation_Status status = synch.remote_invocation (max_wait_time);
00138 
00139     if (status == TAO_INVOKE_RESTART &&                                                                                                                    
00140         (synch.reply_status () == GIOP::LOCATION_FORWARD ||                                                                                              
00141          synch.reply_status () == GIOP::LOCATION_FORWARD_PERM))
00142       {
00143         CORBA::Boolean const permanent_forward =
00144           (synch.reply_status () == GIOP::LOCATION_FORWARD_PERM);
00145 
00146         effective_target = synch.steal_forwarded_reference ();
00147 
00148         this->object_forwarded (effective_target,
00149                                 r.stub (),
00150                                 permanent_forward);
00151       }
00152     return status;
00153   }
00154 
00155   //================================================================
00156   DII_Deferred_Invocation_Adapter::DII_Deferred_Invocation_Adapter (
00157       CORBA::Object *target,
00158       Argument **args,
00159       int arg_number,
00160       const char *operation,
00161       size_t op_len,
00162       Collocation_Proxy_Broker *b,
00163       TAO_ORB_Core *oc,
00164       CORBA::Request *req,
00165       Invocation_Mode mode)
00166     : Invocation_Adapter (target,
00167                           args,
00168                           arg_number,
00169                           operation,
00170                           op_len,
00171                           b,
00172                           TAO_TWOWAY_INVOCATION,
00173                           mode)
00174       , request_ (req)
00175       , rd_ (0)
00176       , orb_core_ (oc)
00177   {
00178   }
00179 
00180   void
00181   DII_Deferred_Invocation_Adapter::invoke (
00182       TAO::Exception_Data *ex,
00183       unsigned long ex_count)
00184   {
00185     // New reply dispatcher on the heap, because we will go out of
00186     // scope and hand over the reply dispatcher to the ORB.
00187     // So this->rd_ is 0, because we do not need to
00188     // hold a pointer to it.
00189     ACE_NEW_THROW_EX (this->rd_,
00190         TAO_DII_Deferred_Reply_Dispatcher (this->request_,
00191                                            this->orb_core_),
00192                       CORBA::NO_MEMORY ());
00193 
00194     Invocation_Adapter::invoke (ex, ex_count);
00195   }
00196 
00197   Invocation_Status
00198   DII_Deferred_Invocation_Adapter::invoke_collocated_i (
00199     TAO_Stub *stub,
00200     TAO_Operation_Details &details,
00201     CORBA::Object_var &effective_target,
00202     Collocation_Strategy strat)
00203   {
00204     TAO_DII_Arguments_Converter_Impl* dii_arguments_converter
00205       = ACE_Dynamic_Service<TAO_DII_Arguments_Converter_Impl>::instance (
00206         "DII_Arguments_Converter");
00207     details.cac (dii_arguments_converter);
00208 
00209     return Invocation_Adapter::invoke_collocated_i (stub,
00210                                                     details,
00211                                                     effective_target,
00212                                                     strat);
00213   }
00214 
00215   Invocation_Status
00216   DII_Deferred_Invocation_Adapter::invoke_twoway (
00217       TAO_Operation_Details &op,
00218       CORBA::Object_var &effective_target,
00219       Profile_Transport_Resolver &r,
00220       ACE_Time_Value *&max_wait_time)
00221   {
00222     // Simple sanity check
00223     if (this->mode_ != TAO_DII_DEFERRED_INVOCATION ||
00224         this->type_ != TAO_TWOWAY_INVOCATION)
00225       {
00226         throw ::CORBA::INTERNAL (
00227           CORBA::SystemException::_tao_minor_code (
00228             TAO::VMCID,
00229             EINVAL),
00230           CORBA::COMPLETED_NO);
00231       }
00232 
00233     TAO_Transport* const transport = r.transport ();
00234 
00235     if (!transport)
00236       {
00237         // Way back, we failed to find a profile we could connect to.
00238         // We've come this far only so we reach the interception points
00239         // in case they can fix things. Time to bail....
00240         throw CORBA::TRANSIENT (CORBA::OMGVMCID | 2, CORBA::COMPLETED_NO);
00241       }
00242 
00243     transport->messaging_object ()->out_stream ().reset_byte_order (
00244       request_->_tao_byte_order ());
00245 
00246     TAO::DII_Deferred_Invocation synch (
00247         this->target_,
00248         r,
00249         op,
00250         this->rd_,
00251         this->request_);
00252 
00253     Invocation_Status status = synch.remote_invocation (max_wait_time);
00254 
00255     if (status == TAO_INVOKE_RESTART)
00256       {
00257         effective_target = synch.steal_forwarded_reference ();
00258       }
00259 
00260     return status;
00261   }
00262 
00263   DII_Asynch_Invocation_Adapter::DII_Asynch_Invocation_Adapter (
00264       CORBA::Object *target,
00265       Argument **args,
00266       int arg_count,
00267       const char *operation,
00268       int op_len,
00269       CORBA::Request *req,
00270       TAO::Invocation_Mode mode)
00271     : DII_Invocation_Adapter (target,
00272                               args,
00273                               arg_count,
00274                               operation,
00275                               op_len,
00276                               0,
00277                               req,
00278                               mode)
00279   {
00280   }
00281 
00282   Invocation_Status
00283   DII_Asynch_Invocation_Adapter::invoke_twoway (
00284         TAO_Operation_Details &,
00285         CORBA::Object_var &,
00286         Profile_Transport_Resolver &,
00287         ACE_Time_Value *&)
00288   {
00289     return TAO_INVOKE_FAILURE;
00290   }
00291 
00292   DII_Oneway_Invocation_Adapter::DII_Oneway_Invocation_Adapter (
00293       CORBA::Object *target,
00294       Argument **args,
00295       int arg_count,
00296       const char *operation,
00297       int op_len,
00298       TAO::Invocation_Mode mode)
00299     : Invocation_Adapter (target,
00300                           args,
00301                           arg_count,
00302                           operation,
00303                           op_len,
00304                           0,
00305                           TAO_ONEWAY_INVOCATION,
00306                           mode)
00307   {
00308   }
00309 
00310   Invocation_Status
00311   DII_Oneway_Invocation_Adapter::invoke_collocated_i (
00312     TAO_Stub *stub,
00313     TAO_Operation_Details &details,
00314     CORBA::Object_var &effective_target,
00315     Collocation_Strategy strat)
00316   {
00317     TAO_DII_Arguments_Converter_Impl* dii_arguments_converter
00318       = ACE_Dynamic_Service<TAO_DII_Arguments_Converter_Impl>::instance (
00319         "DII_Arguments_Converter");
00320     details.cac (dii_arguments_converter);
00321 
00322     return Invocation_Adapter::invoke_collocated_i (stub,
00323                                                     details,
00324                                                     effective_target,
00325                                                     strat);
00326   }
00327 
00328 
00329 } // End namespace TAO
00330 TAO_END_VERSIONED_NAMESPACE_DECL

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