big_union.cpp

来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 554 行 · 第 1/2 页

CPP
554
字号
// big_union.cpp,v 1.18 2003/08/14 22:45:36 parsons Exp

// ============================================================================
//
// = LIBRARY
//    TAO/tests/Param_Test
//
// = FILENAME
//    big_union.cpp
//
// = DESCRIPTION
//    tests Big_Unions
//
// = AUTHORS
//      Aniruddha Gokhale
//
// ============================================================================

#include "helper.h"
#include "big_union.h"

ACE_RCSID (Param_Test, 
           big_union, 
           "big_union.cpp,v 1.18 2003/08/14 22:45:36 parsons Exp")

// ************************************************************************
//               Test_Big_Union
// ************************************************************************

size_t Test_Big_Union::counter = 0;

Test_Big_Union::Test_Big_Union (void)
  : opname_ (CORBA::string_dup ("test_big_union"))
{
}

Test_Big_Union::~Test_Big_Union (void)
{
  CORBA::string_free (this->opname_);
  this->opname_ = 0;
}

const char *
Test_Big_Union::opname (void) const
{
  return this->opname_;
}

void
Test_Big_Union::dii_req_invoke (CORBA::Request *req
                                ACE_ENV_ARG_DECL)
{
  req->add_in_arg ("s1") <<= this->in_;
  req->add_inout_arg ("s2") <<= this->inout_;
  req->add_out_arg ("s3") <<= this->out_.in ();

  req->set_return_type (Param_Test::_tc_Big_Union);

  req->invoke (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  Param_Test::Big_Union *tmp;
  req->return_value () >>= tmp;
  this->ret_ = new Param_Test::Big_Union (*tmp);

  CORBA::NamedValue_ptr o2 =
    req->arguments ()->item (1 ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;
  *o2->value () >>= tmp;
  this->inout_ = *tmp;

  CORBA::NamedValue_ptr o3 =
    req->arguments ()->item (2 ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;
  *o3->value () >>= tmp;
  this->out_ = new Param_Test::Big_Union (*tmp);
}

int
Test_Big_Union::init_parameters (Param_Test_ptr objref
                                 ACE_ENV_ARG_DECL)
{
  ACE_TRY
    {
      // get access to a Coffee Object
      this->cobj_ = objref->make_coffee (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      this->reset_parameters ();
      return 0;
    }
  ACE_CATCH (CORBA::SystemException, sysex)
    {
      ACE_PRINT_EXCEPTION (sysex,"System Exception doing make_coffee");
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "An exception caught in make_coffee");
    }
  ACE_ENDTRY;
  return -1;
}

int
Test_Big_Union::reset_parameters (void)
{
  Generator *gen = GENERATOR::instance (); // value generator
  CORBA::ULong index = (counter++ % Test_Big_Union::BIG_UNION_N_BRANCHES);

  switch (index)
    {
    case 0:
      {
        Param_Test::Fixed_Array x;
        for (CORBA::ULong i = 0; i < Param_Test::DIM1; ++i)
          {
            x[i] = gen->gen_long ();
          }
        this->in_.the_array (x);
        this->inout_.the_array (x);
      }
      break;
    case 1:
      {
        this->in_.the_interface (this->cobj_.in ());
        this->inout_.the_interface (this->cobj_.in ());
      }
      break;
    case 2:
      {
        CORBA::Long x = gen->gen_long ();
        this->in_.the_long (x);
        this->inout_.the_long (x);
      }
      break;
    case 3:
      {
        Param_Test::Big_Union::_another_array x;
        for (int i = 0; i < 32; ++i)
          {
            x[i] = gen->gen_short ();
          }
        this->in_.another_array (x);
        this->inout_.another_array (x);
      }
      break;
    case 4:
      {
        CORBA::String_var str = gen->gen_string ();
        this->in_.the_string (str);
        this->inout_.the_string (str);
      }
      break;
    case 5:
      {
        Param_Test::Short_Seq seq;
        seq.length (gen->gen_short () % 50);
        for (size_t i = 0; i < seq.length (); i++)
          seq[i] = gen->gen_short ();
        this->in_.the_sequence (seq);
        this->inout_.the_sequence (seq);
      }
      break;
    case 6:
      {
        CORBA::Any any;
        any <<= CORBA::Short (25);
        this->in_.the_any (any);
        this->inout_.the_any (any);
      }
      break;
    case 7:
      {
        CORBA::Octet octet = gen->gen_short () % 255;
        this->in_.the_octet (octet);
        this->inout_.the_octet (octet);
      }
      break;
    case 8:
      {
        CORBA::Char x = '@';
        this->in_.the_char (x);
        this->inout_.the_char (x);
      }
      break;
    case 9:
      {
        CORBA::Boolean x = gen->gen_short () % 2;
        this->in_.the_boolean (x);
        this->inout_.the_boolean (x);
      }
      break;
    case 10:
      {
        Param_Test::Var_Struct var_struct;
        var_struct.dbl = 3.14159;
        var_struct.boole = gen->gen_short () % 2;
        var_struct.shrt = gen->gen_short ();
        // set the length of the sequence
        var_struct.dummy1 = gen->gen_string ();
        var_struct.dummy2 = gen->gen_string ();
        CORBA::ULong len = gen->gen_long () % 10 + 1;
        var_struct.seq.length (len);
        for (CORBA::ULong i = 0; i != len; ++i)
          {
            var_struct.seq[i] = gen->gen_string ();
          }
        this->in_.the_var_struct (var_struct);
        this->inout_.the_var_struct (var_struct);
      }
      break;
    case 11:
      {
        Param_Test::Fixed_Struct fixed_struct;
        fixed_struct.l = gen->gen_long ();
        fixed_struct.c = gen->gen_long () % 255;
        fixed_struct.s = gen->gen_long () % 32768;
        fixed_struct.o = gen->gen_long () % 255;
        fixed_struct.f = gen->gen_short () / 255.0f;
        fixed_struct.b = gen->gen_long () % 2;
        fixed_struct.d = gen->gen_short () / 255.0;
        this->in_.the_fixed_struct (fixed_struct);
        this->inout_.the_fixed_struct (fixed_struct);
      }
      break;
    }
  this->out_ = new Param_Test::Big_Union (this->in_);
  this->ret_ = new Param_Test::Big_Union (this->in_);
  return 0;
}

int
Test_Big_Union::run_sii_test (Param_Test_ptr objref
                              ACE_ENV_ARG_DECL)
{
  ACE_TRY
    {
      this->ret_ = objref->test_big_union (this->in_,
                                           this->inout_,
                                           this->out_
                                           ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      return 0;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "Test_Big_Union::run_sii_test\n");

    }
  ACE_ENDTRY;
  return -1;
}

CORBA::Boolean
Test_Big_Union::check_validity (void)
{
  if (this->in_._d () != this->inout_._d ()
      || this->in_._d () != this->out_->_d ()
      || this->in_._d () != this->ret_->_d ())
    {
      ACE_DEBUG ((LM_DEBUG, "mismatch of discriminators\n"));
      return 0;
    }


  switch (this->in_._d ())
    {
    case 0:
      {
        Param_Test::Fixed_Array_slice* in_array    = this->in_.the_array ();
        Param_Test::Fixed_Array_slice* inout_array = this->inout_.the_array ();
        Param_Test::Fixed_Array_slice* out_array   = this->out_->the_array ();
        Param_Test::Fixed_Array_slice* ret_array   = this->ret_->the_array ();
        for (CORBA::ULong i = 0; i < Param_Test::DIM1; ++i)
          {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?