예제 #1
0
void
TAO_AMH_DSI_Response_Handler::gateway_exception_reply (
    CORBA::ULong reply_status,
    TAO_OutputCDR & encap)
{
  // for this to be effective, ACE & TAO must be built with
  // ACE_ENABLE_SWAP_ON_WRITE defined in ace/config.h
  this->_tao_out.reset_byte_order (encap.byte_order ());
  // This reply path handles only user exceptions.
  switch (reply_status)
    {
    case TAO_AMI_REPLY_USER_EXCEPTION:
      this->reply_status_ = GIOP::USER_EXCEPTION;
      break;
    case TAO_AMI_REPLY_SYSTEM_EXCEPTION:
      this->reply_status_ = GIOP::SYSTEM_EXCEPTION;
      break;

      // TODO: we don't handle location forward at this moment.
      // need to be addressed later.
      //
      //case TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD:
      //  this->exception_type_ = TAO_GIOP_LOCATION_FORWARD;
      //  break;
    }
  try
    {
      this->_tao_rh_init_reply ();

      // We know nothing about this exception, so we marshal it as a block
      // of bytes. The outgoing stream's byte order has already been matched
      // to the original source of the reply.
      this->_tao_out.write_char_array (encap.buffer (), encap.length ());
      // This will prevent the marshaling of any parameters into this reply.
      //  this->sent_gateway_exception_ = 1;
      this->_tao_rh_send_reply ();
    }
  catch (const CORBA::Exception &)
    {
      // TODO:
    }

}
예제 #2
0
bool
recursive_union_test ()
{
  bool rc = true;

  ACE_DEBUG ((LM_INFO,
              "Executing recursive union test\n"));


  ACE_DEBUG ((LM_INFO,
              "* Simple marshaling -> demarshaling\n"));
  {
    CORBA::Any the_any, the_out_any;

    static CORBA::Short const test_short = 23901;
    Test::RecursiveUnion3 foo3;
    foo3.a (test_short);

    the_any <<= foo3;

    TAO_OutputCDR out;

    out << the_any;

    out.consolidate ();

    if (TAO_debug_level >= 2)
    {
      if (out.length () > 512)
      {
        ACE_HEX_DUMP ((LM_INFO, out.buffer (), 512, ACE_TEXT ("Encoded union (1):")));
        ACE_HEX_DUMP ((LM_INFO, out.buffer ()+512, out.length ()-512, ACE_TEXT ("Encoded union (2):")));
      }
      else
      {
        ACE_HEX_DUMP ((LM_INFO, out.buffer (), out.length (), ACE_TEXT ("Encoded union:")));
      }
    }

    TAO_InputCDR in(out);

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Extracting any\n"));

    in >> the_out_any;

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Extracted any\n"));
  }
  // Any's typecode out of scope
  if (TAO_debug_level >= 1)
    ACE_DEBUG ((LM_INFO,
                "> Any destructed\n"));

  ACE_DEBUG ((LM_INFO,
              "* Marshaling -> demarshaling with external reference\n"));
  {
    CORBA::TypeCode_var tc;

    {
      CORBA::Any the_any, the_out_any;

      static CORBA::Short const test_short = 23901;
      Test::RecursiveUnion3 foo3;
      foo3.a (test_short);

      the_any <<= foo3;

      TAO_OutputCDR out;

      out << the_any;

      out.consolidate ();

      if (TAO_debug_level >= 2)
      {
        if (out.length () > 512)
        {
          ACE_HEX_DUMP ((LM_INFO, out.buffer (), 512, ACE_TEXT ("Encoded union (1):")));
          ACE_HEX_DUMP ((LM_INFO, out.buffer ()+512, out.length ()-512, ACE_TEXT ("Encoded union (2):")));
        }
        else
        {
          ACE_HEX_DUMP ((LM_INFO, out.buffer (), out.length (), ACE_TEXT ("Encoded union:")));
        }
      }

      TAO_InputCDR in(out);

      if (TAO_debug_level >= 1)
        ACE_DEBUG ((LM_INFO,
                    "> Extracting any\n"));

      in >> the_out_any;

      tc = the_out_any._tao_get_typecode ()->member_type (1); // union case type -> alias
      tc = tc->content_type (); // alias content type -> sequence
      tc = tc->content_type (); // sequence content type -> recursive struct
      tc = tc->member_type (0); // struct member type -> union
      tc = tc->member_type (1); // union case type -> alias
      tc = tc->content_type (); // alias content type -> sequence
      tc = tc->content_type (); // sequence content type -> indirected struct

      if (TAO_debug_level >= 1)
        ACE_DEBUG ((LM_INFO,
                    "> Extracted any and stored external reference to Indirected_Type typecode\n"));
    }
    // Any's typecode out of scope
    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Any destructed\n"));
  }
  // referenced recursive typecode out of scope
  // Any's typecode out of scope
  if (TAO_debug_level >= 1)
    ACE_DEBUG ((LM_INFO,
                "> External Indirected_Type typecode reference destructed\n"));


  ACE_DEBUG ((LM_INFO,
              "* Marshaling -> demarshaling -> marshaling -> demarshaling\n"));
  {
    CORBA::Any the_any, the_out_any, the_out_any2;

    static CORBA::Short const test_short = 23901;
    Test::RecursiveUnion3 foo3;
    foo3.a (test_short);

    the_any <<= foo3;

    TAO_OutputCDR out;

    out << the_any;

    out.consolidate ();

    if (TAO_debug_level >= 2)
    {
      if (out.length () > 512)
      {
        ACE_HEX_DUMP ((LM_INFO, out.buffer (), 512, ACE_TEXT ("Encoded union (1):")));
        ACE_HEX_DUMP ((LM_INFO, out.buffer ()+512, out.length ()-512, ACE_TEXT ("Encoded union (2):")));
      }
      else
      {
        ACE_HEX_DUMP ((LM_INFO, out.buffer (), out.length (), ACE_TEXT ("Encoded union:")));
      }
    }

    TAO_InputCDR in(out);

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Extracting any\n"));

    in >> the_out_any;

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Extracted any\n"));

    TAO_OutputCDR out2;

    out2 << the_out_any;

    out2.consolidate ();

    if (TAO_debug_level >= 2)
    {
      if (out2.length () > 512)
      {
        ACE_HEX_DUMP ((LM_INFO, out2.buffer (), 512, ACE_TEXT ("Re-encoded union (1):")));
        ACE_HEX_DUMP ((LM_INFO, out2.buffer ()+512, out2.length ()-512, ACE_TEXT ("Re-encoded union (2):")));
      }
      else
      {
        ACE_HEX_DUMP ((LM_INFO, out2.buffer (), out2.length (), ACE_TEXT ("Re-encoded union:")));
      }
    }

// Unfortunately this test in unreliable due to the memory management optimizations of ACE, particularly
// concerning the non-initialization of allocated memory. When running with Valgrind all memory is forcibly
// initialized to 0 and than this test passes.
//
//    if (out.length () != out2.length () || ACE_OS::memcmp (out.buffer (), out2.buffer (), out.length ()) != 0)
//    {
//      ACE_ERROR ((LM_ERROR,
//                  "encoded representations of recursive typecodes differ\n"));
//
//      rc = false;
//    }

    TAO_InputCDR in2(out2);

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Re-extracting any\n"));

    in2 >> the_out_any2;

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Re-extracted any\n"));

    if (!the_out_any._tao_get_typecode ()->equal (the_out_any2._tao_get_typecode ()))
    {
      ACE_ERROR ((LM_ERROR,
                  "extracted recursive typecodes differ\n"));
      rc = false;
    }
  }
  // Any's typecodes out of scope
  if (TAO_debug_level >= 1)
    ACE_DEBUG ((LM_INFO,
                "> Anys destructed\n"));

  return rc;
}