DII_Arguments_Converter_Impl.cpp

Go to the documentation of this file.
00001 // $Id: DII_Arguments_Converter_Impl.cpp 80380 2008-01-07 13:11:49Z mcorino $
00002 #include "tao/DynamicInterface/DII_Arguments_Converter_Impl.h"
00003 #include "tao/DynamicInterface/DII_Arguments.h"
00004 #include "tao/AnyTypeCode/NVList.h"
00005 #include "tao/AnyTypeCode/Any_Impl.h"
00006 #include "tao/operation_details.h"
00007 #include "tao/SystemException.h"
00008 #include "tao/CDR.h"
00009 
00010 ACE_RCSID (DynamicInterface,
00011            DII_Arguments_Converter_Impl,
00012            "$Id: DII_Arguments_Converter_Impl.cpp 80380 2008-01-07 13:11:49Z mcorino $")
00013 
00014 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00015 
00016 void
00017 TAO_DII_Arguments_Converter_Impl::convert_request (
00018     TAO_ServerRequest & server_request,
00019     TAO::Argument * const args[],
00020     size_t nargs)
00021 {
00022   // The DII requests on client side always have two arguments
00023   // - one is the return argument and the other is NVList_Argument.
00024   // Since the argument list in the client side is used by server side
00025   // in collocation case and the server expects the list of arguments
00026   // and not the NVList_Argument, we need expand the NVList_Argument
00027   // to be list of Arguments.
00028 
00029   // Before expanding NVList_Argument logic was added, the
00030   // $TAO_ROOT/tests/DII_Collocated_Tests/run_test.pl should fail.
00031   // The servant will get incorrect "IN" parameter from the oneway
00032   // operation with single "IN" parameter and get access violation on
00033   // get_in_arg () from the oneway operation with multiple "IN"
00034   // parameters.
00035   CORBA::NVList_ptr lst
00036     = static_cast<TAO::NVList_Argument *> (
00037         server_request.operation_details ()->args()[1])->arg ();
00038 
00039   CORBA::ULong const sz = lst->count ();
00040 
00041   if (sz != nargs - 1)
00042     {
00043       throw ::CORBA::BAD_PARAM ();
00044     }
00045 
00046   // To avoid the use of extraction operators on CORBA::Any, we will
00047   // marshal the arguments in the NVList into an output cdr and then
00048   // demarshal them into the TAO::Argument array.
00049   TAO_OutputCDR output;
00050   for (CORBA::ULong i = 0; i < sz; ++i)
00051     {
00052       CORBA::NamedValue_ptr theitem = lst->item (i);
00053 
00054       if (!(theitem->value ()->impl ()->marshal_value (output)))
00055         {
00056           throw ::CORBA::BAD_PARAM ();
00057         }
00058     }
00059 
00060   TAO_InputCDR input (output);
00061   for (CORBA::ULong j = 0; j < sz; ++j)
00062     {
00063       if (!(args[j + 1]->demarshal (input)))
00064         {
00065           throw ::CORBA::BAD_PARAM ();
00066         }
00067     }
00068 
00069   TAO_Operation_Details* details
00070     = const_cast <TAO_Operation_Details*> (server_request.operation_details ());
00071 
00072   // The NVList_Argument in operation details is converted to skel
00073   // args, the invocation of the dii collocation requests should use
00074   // the skel args and not use the stub args.
00075   details->use_stub_args (false);
00076 }
00077 
00078 void 
00079 TAO_DII_Arguments_Converter_Impl::dsi_convert_request (
00080     TAO_ServerRequest & server_request,
00081     TAO_OutputCDR & output)
00082 {
00083   // The DII requests on client side always have two arguments
00084   // - one is the return argument and the other is NVList_Argument.
00085   CORBA::NVList_ptr lst
00086     = static_cast<TAO::NVList_Argument *> (
00087         server_request.operation_details ()->args()[1])->arg ();
00088 
00089   // Only marshal the in(out) arguments since we use this to demarshal
00090   // these values in the serverside argument list.
00091   lst->_tao_encode (output, CORBA::ARG_IN | CORBA::ARG_INOUT);
00092 }
00093 
00094 void
00095 TAO_DII_Arguments_Converter_Impl::convert_reply (
00096     TAO_ServerRequest & server_request,
00097     TAO::Argument * const args[],
00098     size_t nargs)
00099 {
00100   TAO_OutputCDR output;
00101   for (CORBA::ULong j = 0; j < nargs; ++j)
00102     {
00103       if (!(args[j]->marshal (output)))
00104         {
00105           TAO_OutputCDR::throw_skel_exception (errno);
00106         }
00107     }
00108   TAO_InputCDR input (output);
00109   this->dsi_convert_reply (server_request, input);
00110 }
00111 
00112 void 
00113 TAO_DII_Arguments_Converter_Impl::dsi_convert_reply (
00114     TAO_ServerRequest & server_request,
00115     TAO_InputCDR & input)
00116 {
00117   TAO::NamedValue_Argument * _ret_val
00118     = static_cast<TAO::NamedValue_Argument *> (
00119         server_request.operation_details ()->args()[0]);
00120   
00121   _ret_val->demarshal (input);
00122   
00123   CORBA::NVList_ptr lst
00124     = static_cast<TAO::NVList_Argument *> (
00125         server_request.operation_details ()->args()[1])->arg ();
00126 
00127   lst->_tao_decode (input, 
00128                     CORBA::ARG_INOUT | CORBA::ARG_OUT);
00129 }
00130 
00131 void
00132 TAO_DII_Arguments_Converter_Impl::handle_corba_exception (
00133   TAO_ServerRequest & /*server_request*/,
00134   CORBA::Exception *exception)
00135 {
00136   exception->_raise ();
00137 }
00138 
00139 // *********************************************************************
00140 
00141 // Initialization and registration of dynamic service object.
00142 
00143 int
00144 TAO_DII_Arguments_Converter_Impl::Initializer (void)
00145 {
00146   return ACE_Service_Config::process_directive (
00147     ace_svc_desc_TAO_DII_Arguments_Converter_Impl);
00148 }
00149 
00150 
00151 TAO_END_VERSIONED_NAMESPACE_DECL
00152 
00153 ACE_STATIC_SVC_DEFINE (
00154   TAO_DII_Arguments_Converter_Impl,
00155   ACE_TEXT ("DII_Arguments_Converter"),
00156   ACE_SVC_OBJ_T,
00157   &ACE_SVC_NAME (TAO_DII_Arguments_Converter_Impl),
00158   ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00159   0
00160   )
00161 
00162 ACE_FACTORY_DEFINE (TAO_DynamicInterface, TAO_DII_Arguments_Converter_Impl)
00163 

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