Remote_Invocation.cpp

Go to the documentation of this file.
00001 //Remote_Invocation.cpp,v 1.15 2006/04/20 12:37:17 jwillemsen Exp
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/debug.h"
00013 
00014 ACE_RCSID (tao,
00015            Remote_Invocation,
00016            "Remote_Invocation.cpp,v 1.15 2006/04/20 12:37:17 jwillemsen Exp")
00017 
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 namespace TAO
00021 {
00022   Remote_Invocation::Remote_Invocation (
00023     CORBA::Object_ptr otarget,
00024     Profile_Transport_Resolver &resolver,
00025     TAO_Operation_Details &detail,
00026     bool response_expected)
00027     : Invocation_Base (otarget,
00028                        resolver.object (),
00029                        resolver.stub (),
00030                        detail,
00031                        response_expected,
00032                        true /* request_is_remote */ )
00033     , resolver_ (resolver)
00034   {
00035   }
00036 
00037   void
00038   Remote_Invocation::init_target_spec (TAO_Target_Specification &target_spec
00039                                        ACE_ENV_ARG_DECL)
00040   {
00041     /**
00042      * Mega hack for RTCORBA start. I don't think that
00043      * PortableInterceptor  would work here esp. for RTCORBA. PI needs
00044      * to be improved to  help our cause.
00045      */
00046     this->resolver_.stub ()->orb_core ()->service_context_list (
00047       this->resolver_.stub (),
00048       this->details_.request_service_context (),
00049       0
00050       ACE_ENV_ARG_PARAMETER);
00051     ACE_CHECK;
00052     /**
00053      * Mega hack for RTCORBA END
00054      */
00055 
00056     TAO_Profile *pfile = this->resolver_.profile ();
00057 
00058     // Set the target specification mode
00059     switch (pfile->addressing_mode ())
00060       {
00061       case TAO_Target_Specification::Key_Addr:
00062         target_spec.target_specifier (pfile->object_key ());
00063         break;
00064       case TAO_Target_Specification::Profile_Addr:
00065         {
00066           IOP::TaggedProfile *tp =
00067             pfile->create_tagged_profile ();
00068 
00069         if (tp)
00070           {
00071             target_spec.target_specifier (*tp);
00072           }
00073         }
00074         break;
00075 
00076     case TAO_Target_Specification::Reference_Addr:
00077       // We need to call the method seperately. If there is no
00078       // IOP::IOR info, the call would create the info and return the
00079       // index that we need.
00080       CORBA::ULong index = 0;
00081       IOP::IOR *ior_info = 0;
00082       int const retval =
00083         this->resolver_.stub ()->create_ior_info (ior_info,
00084                                                   index
00085                                                   ACE_ENV_ARG_PARAMETER);
00086       ACE_CHECK;
00087 
00088       if (retval == -1)
00089         {
00090           if (TAO_debug_level > 0)
00091             {
00092               ACE_ERROR ((LM_ERROR,
00093                           ACE_TEXT ("TAO (%P|%t) - ")
00094                           ACE_TEXT ("Remote_Invocation::init_target_spec, ")
00095                           ACE_TEXT ("Error in finding index for ")
00096                           ACE_TEXT ("IOP::IOR \n")));
00097             }
00098 
00099           return;
00100         }
00101 
00102       target_spec.target_specifier (*ior_info,
00103                                     index);
00104       break;
00105     }
00106 
00107 
00108   }
00109 
00110   void
00111   Remote_Invocation::write_header (TAO_Target_Specification &spec,
00112                                    TAO_OutputCDR &out_stream
00113                                    ACE_ENV_ARG_DECL)
00114   {
00115     this->resolver_.transport ()->clear_translators (0,
00116                                                      &out_stream);
00117 
00118     // Send the request for the header
00119     if (this->resolver_.transport ()->generate_request_header (this->details_,
00120                                                                spec,
00121                                                                out_stream)
00122         == -1)
00123       {
00124         ACE_THROW (CORBA::MARSHAL ());
00125       }
00126 
00127     this->resolver_.transport ()->assign_translators (0,
00128                                                       &out_stream);
00129   }
00130 
00131   void
00132   Remote_Invocation::marshal_data (TAO_OutputCDR &out_stream
00133                                    ACE_ENV_ARG_DECL)
00134   {
00135     if (this->details_.marshal_args (out_stream) == false)
00136       {
00137         ACE_THROW (CORBA::MARSHAL ());
00138       }
00139 
00140     return;
00141   }
00142 
00143   Invocation_Status
00144   Remote_Invocation::send_message (TAO_OutputCDR &cdr,
00145                                    short message_semantics,
00146                                    ACE_Time_Value *max_wait_time
00147                                    ACE_ENV_ARG_DECL)
00148   {
00149     TAO_Protocols_Hooks *tph =
00150       this->resolver_.stub ()->orb_core ()->get_protocols_hooks ();
00151 
00152     CORBA::Boolean set_client_network_priority =
00153       tph->set_client_network_priority (this->resolver_.transport ()->tag (),
00154                                         this->resolver_.stub ()
00155                                         ACE_ENV_ARG_PARAMETER);
00156     ACE_CHECK_RETURN (TAO_INVOKE_FAILURE);
00157 
00158     TAO_Connection_Handler *connection_handler =
00159       this->resolver_.transport ()->connection_handler ();
00160 
00161     connection_handler->set_dscp_codepoint (set_client_network_priority);
00162 
00163     int const retval =
00164       this->resolver_.transport ()->send_request (
00165         this->resolver_.stub (),
00166         this->resolver_.stub ()->orb_core (),
00167         cdr,
00168         message_semantics,
00169         max_wait_time);
00170 
00171     if (retval == -1)
00172       {
00173         if (errno == ETIME)
00174           {
00175             // We sent a message already and we haven't gotten a
00176             // reply.  Just throw TIMEOUT with *COMPLETED_MAYBE*.
00177             ACE_THROW_RETURN (
00178                 CORBA::TIMEOUT (
00179                     CORBA::SystemException::_tao_minor_code (
00180                         TAO_TIMEOUT_SEND_MINOR_CODE,
00181                         errno
00182                         ),
00183                     CORBA::COMPLETED_MAYBE
00184                     ),
00185                 TAO_INVOKE_FAILURE
00186                 );
00187           }
00188 
00189         if (TAO_debug_level > 2)
00190           {
00191             ACE_DEBUG ((LM_DEBUG,
00192                         ACE_TEXT ("TAO (%P|%t) - ")
00193                         ACE_TEXT ("Remote_Invocation::send_message, ")
00194                         ACE_TEXT ("failure while sending message \n")));
00195           }
00196 
00197         // Close the transport and all the associated stuff along with
00198         // it.
00199         this->resolver_.transport ()->close_connection ();
00200         this->resolver_.stub ()->reset_profiles ();
00201         return TAO_INVOKE_RESTART;
00202       }
00203 
00204     this->resolver_.stub ()->set_valid_profile ();
00205     return TAO_INVOKE_SUCCESS;
00206   }
00207 }
00208 
00209 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 11:54:21 2006 for TAO by doxygen 1.3.6