Remote_Invocation.cpp

Go to the documentation of this file.
00001 //$Id: Remote_Invocation.cpp 77269 2007-02-20 21:08:04Z jai $
00002 
00003 #include "tao/Remote_Invocation.h"
00004 #include "tao/Profile.h"
00005 #include "tao/Profile_Transport_Resolver.h"
00006 #include "tao/Stub.h"
00007 #include "tao/Transport.h"
00008 #include "tao/Connection_Handler.h"
00009 #include "tao/operation_details.h"
00010 #include "tao/ORB_Core.h"
00011 #include "tao/Protocols_Hooks.h"
00012 #include "tao/Network_Priority_Protocols_Hooks.h"
00013 #include "tao/debug.h"
00014 #include "tao/SystemException.h"
00015 
00016 ACE_RCSID (tao,
00017            Remote_Invocation,
00018            "$Id: Remote_Invocation.cpp 77269 2007-02-20 21:08:04Z jai $")
00019 
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021 
00022 namespace TAO
00023 {
00024   Remote_Invocation::Remote_Invocation (
00025     CORBA::Object_ptr otarget,
00026     Profile_Transport_Resolver &resolver,
00027     TAO_Operation_Details &detail,
00028     bool response_expected)
00029     : Invocation_Base (otarget,
00030                        resolver.object (),
00031                        resolver.stub (),
00032                        detail,
00033                        response_expected,
00034                        true /* request_is_remote */ )
00035     , resolver_ (resolver)
00036   {
00037   }
00038 
00039   void
00040   Remote_Invocation::init_target_spec (TAO_Target_Specification &target_spec)
00041   {
00042     /**
00043      * Mega hack for RTCORBA start. I don't think that
00044      * PortableInterceptor  would work here esp. for RTCORBA. PI needs
00045      * to be improved to  help our cause.
00046      */
00047     this->resolver_.stub ()->orb_core ()->service_context_list (
00048       this->resolver_.stub (),
00049       this->details_.request_service_context (),
00050       0);
00051     /**
00052      * Mega hack for RTCORBA END
00053      */
00054 
00055     TAO_Profile *pfile = this->resolver_.profile ();
00056 
00057     // Set the target specification mode
00058     switch (pfile->addressing_mode ())
00059       {
00060       case TAO_Target_Specification::Key_Addr:
00061         target_spec.target_specifier (pfile->object_key ());
00062         break;
00063       case TAO_Target_Specification::Profile_Addr:
00064         {
00065           IOP::TaggedProfile *tp =
00066             pfile->create_tagged_profile ();
00067 
00068           if (tp)
00069             {
00070               target_spec.target_specifier (*tp);
00071             }
00072         }
00073         break;
00074 
00075     case TAO_Target_Specification::Reference_Addr:
00076       // We need to call the method seperately. If there is no
00077       // IOP::IOR info, the call would create the info and return the
00078       // index that we need.
00079       CORBA::ULong index = 0;
00080       IOP::IOR *ior_info = 0;
00081       int const retval =
00082         this->resolver_.stub ()->create_ior_info (ior_info, index);
00083 
00084       if (retval == -1)
00085         {
00086           if (TAO_debug_level > 0)
00087             {
00088               ACE_ERROR ((LM_ERROR,
00089                           ACE_TEXT ("TAO (%P|%t) - ")
00090                           ACE_TEXT ("Remote_Invocation::init_target_spec, ")
00091                           ACE_TEXT ("Error in finding index for ")
00092                           ACE_TEXT ("IOP::IOR \n")));
00093             }
00094 
00095           return;
00096         }
00097 
00098       target_spec.target_specifier (*ior_info, index);
00099       break;
00100     }
00101   }
00102 
00103   void
00104   Remote_Invocation::write_header (TAO_Target_Specification &spec,
00105                                    TAO_OutputCDR &out_stream)
00106   {
00107     this->resolver_.transport ()->clear_translators (0, &out_stream);
00108 
00109     // Send the request for the header
00110     if (this->resolver_.transport ()->generate_request_header (this->details_,
00111                                                                spec,
00112                                                                out_stream)
00113         == -1)
00114       {
00115         throw ::CORBA::MARSHAL ();
00116       }
00117 
00118     this->resolver_.transport ()->assign_translators (0, &out_stream);
00119   }
00120 
00121   void
00122   Remote_Invocation::marshal_data (TAO_OutputCDR &out_stream)
00123   {
00124     if (this->details_.marshal_args (out_stream) == false)
00125       {
00126         throw ::CORBA::MARSHAL ();
00127       }
00128   }
00129 
00130   Invocation_Status
00131   Remote_Invocation::send_message (TAO_OutputCDR &cdr,
00132                                    short message_semantics,
00133                                    ACE_Time_Value *max_wait_time)
00134   {
00135     TAO_Protocols_Hooks *tph =
00136       this->resolver_.stub ()->orb_core ()->get_protocols_hooks ();
00137 
00138     TAO_Network_Priority_Protocols_Hooks *nph =
00139       this->resolver_.stub ()->orb_core ()->
00140         get_network_priority_protocols_hooks ();
00141 
00142     TAO_Connection_Handler *connection_handler =
00143       this->resolver_.transport ()->connection_handler ();
00144 
00145     if (nph != 0)
00146       {
00147         // nph = 0, means DiffServ library is not used
00148         // nph = 0, means DiffServ library is used, and 
00149         // request DSCP and reply DSCP are set.
00150         // Note that the application could still be using
00151         // RTCORBA, but still setting DIffServ codepoints
00152         // using the DiffServ library takes precedence.
00153         //
00154         CORBA::Long dscp = nph->get_dscp_codepoint (this->resolver_.stub (),
00155           this->resolver_.object ());
00156         connection_handler->set_dscp_codepoint (dscp);
00157       }
00158     else if (tph != 0)
00159       {
00160         // If we execute this code, DiffServ library is not used,
00161         // but RTCORBA could be used.
00162         // Which means that using the enable_network_priority flag,
00163         // the application might want to set DiffServ codepoints.
00164         // Check if that is the case.
00165         //
00166         CORBA::Boolean const set_client_network_priority =
00167           tph->set_client_network_priority (
00168             this->resolver_.transport ()->tag (),
00169             this->resolver_.stub ());
00170         connection_handler->set_dscp_codepoint (set_client_network_priority);
00171       }
00172 
00173     // Note that if noth nph and tph are 0, then we do not make any
00174     // virtual calls any more, because we have removed the default
00175     // implementations.
00176 
00177     int const retval =
00178       this->resolver_.transport ()->send_request (
00179         this->resolver_.stub (),
00180         this->resolver_.stub ()->orb_core (),
00181         cdr,
00182         message_semantics,
00183         max_wait_time);
00184 
00185     if (retval == -1)
00186       {
00187         if (errno == ETIME)
00188           {
00189             // We sent a message already and we haven't gotten a
00190             // reply.  Just throw TIMEOUT with *COMPLETED_MAYBE*.
00191             throw ::CORBA::TIMEOUT (
00192               CORBA::SystemException::_tao_minor_code (
00193                 TAO_TIMEOUT_SEND_MINOR_CODE,
00194                 errno),
00195               CORBA::COMPLETED_MAYBE);
00196           }
00197 
00198         if (TAO_debug_level > 2)
00199           {
00200             ACE_DEBUG ((LM_DEBUG,
00201                         ACE_TEXT ("TAO (%P|%t) - ")
00202                         ACE_TEXT ("Remote_Invocation::send_message, ")
00203                         ACE_TEXT ("failure while sending message \n")));
00204           }
00205 
00206         // Close the transport and all the associated stuff along with
00207         // it.
00208         this->resolver_.transport ()->close_connection ();
00209         this->resolver_.stub ()->reset_profiles ();
00210         return TAO_INVOKE_RESTART;
00211       }
00212 
00213     this->resolver_.stub ()->set_valid_profile ();
00214     return TAO_INVOKE_SUCCESS;
00215   }
00216 }
00217 
00218 TAO_END_VERSIONED_NAMESPACE_DECL

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