param_test_i.cpp

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

CPP
1,081
字号
// param_test_i.cpp,v 1.72 2003/11/04 05:21:39 dhinton Exp

// ============================================================================
//
// = LIBRARY
//    TAO/tests/Param_Test
//
// = FILENAME
//    param_test_i.cpp
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

#include "param_test_i.h"

#include "tao/debug.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_wchar.h"
#include "ace/OS_NS_string.h"

ACE_RCSID (Param_Test,
           param_test_i, 
           "param_test_i.cpp,v 1.72 2003/11/04 05:21:39 dhinton Exp")

// ********* class Coffee_i ****************
// Constructor

Coffee_i::Coffee_i (const char *name)
  : name_ (name)
{
}

// Destructor

Coffee_i::~Coffee_i (void)
{
}

// get attribute
Coffee::Desc *
Coffee_i::description (ACE_ENV_SINGLE_ARG_DECL_NOT_USED /*env*/)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  Coffee::Desc *desc = new Coffee::Desc;
  desc->name = CORBA::string_dup (this->name_.in ());
  return desc;
}

// set attribute
void
Coffee_i::description (const Coffee::Desc &description
                       ACE_ENV_ARG_DECL_NOT_USED /*env*/)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  this->name_ = CORBA::string_dup (description.name);
}


// ********* class Param_Test_i ****************

// Constructor

Param_Test_i::Param_Test_i (const char *coffee_name,
                            CORBA::ORB_ptr orb)
  : orb_ (CORBA::ORB::_duplicate (orb)),
    obj_ (coffee_name)
{
}

// Destructor

Param_Test_i::~Param_Test_i (void)
{
}

// test shorts
CORBA::Short
Param_Test_i::test_short (CORBA::Short s1,
                          CORBA::Short &s2,
                          CORBA::Short_out s3
                          ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  s2 = (CORBA::Short) (s1 * 2);
  s3 = (CORBA::Short) (s1 * 3);
  if (TAO_debug_level > 0)
    {
      ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*SERVER SIDE=*=*=*=*=*=*=\n"));
      ACE_DEBUG ((LM_DEBUG, " in = %d, inout = %d, out = %d\n",
                  s1, s2, s3));
    }
  return (CORBA::Short) (s1 * 4);
}

// test long long
CORBA::ULongLong
Param_Test_i::test_ulonglong (CORBA::ULongLong s1,
                              CORBA::ULongLong &s2,
                              CORBA::ULongLong_out s3
                              ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  s2 = s1 * 2;
  s3 = s1 * 3;
  return s1 * 4;
}

// test unbounded strings. For return and out types, we return duplicates of
// the in string. For the inout, we append the same string to itself and send
// it back
char *
Param_Test_i::test_unbounded_string (const char *s1,
                                     char *&s2,
                                     CORBA::String_out s3
                                     ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  char *retstr = CORBA::string_dup (s1);
  s3 = CORBA::string_dup (s1);
  char *tmp = CORBA::string_alloc (2*ACE_OS::strlen (s2));
  ACE_OS::sprintf (tmp, "%s%s", s2, s2);
  CORBA::string_free (s2);
  s2 = tmp;
  return retstr;
}

// test bounded strings. For return and out types, we return duplicates of
// the in string. For the inout, we append the same string to itself and send
// it back
char *
Param_Test_i::test_bounded_string (const char *s1,
                                   char *&s2,
                                   CORBA::String_out s3
                                   ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  char *retstr = CORBA::string_dup (s1);
  s3 = CORBA::string_dup (s1);
  char *tmp = CORBA::string_alloc (2*ACE_OS::strlen (s2));
  ACE_OS::sprintf (tmp, "%s%s", s2, s2);
  CORBA::string_free (s2);
  s2 = tmp;
  return retstr;
}

// test unbounded strings. For return and out types, we return duplicates of
// the in string. For the inout, we append the same string to itself and send
// it back
CORBA::WChar *
Param_Test_i::test_unbounded_wstring (const CORBA::WChar *ws1,
                                      CORBA::WChar *&ws2,
                                      CORBA::WString_out ws3
                                      ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  CORBA::WChar *retwstr = CORBA::wstring_dup (ws1);
  ws3 = CORBA::wstring_dup (ws1);
  CORBA::ULong len = ACE_OS::wslen (ws2);
  CORBA::WChar *tmp = CORBA::wstring_alloc (2*len);
  for (CORBA::ULong i = 0; i < 2; i++)
    for (CORBA::ULong j = 0; j < len; j++)
      tmp[j + i*len] = ws2[j];
  tmp[2*len] = 0;
  CORBA::wstring_free (ws2);
  ws2 = tmp;
  return retwstr;
}

// test bounded strings. For return and out types, we return duplicates of
// the in string. For the inout, we append the same string to itself and send
// it back
CORBA::WChar *
Param_Test_i::test_bounded_wstring (const CORBA::WChar *ws1,
                                    CORBA::WChar *&ws2,
                                    CORBA::WString_out ws3
                                    ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  CORBA::WChar *retwstr = CORBA::wstring_dup (ws1);
  ws3 = CORBA::wstring_dup (ws1);
  CORBA::ULong len = ACE_OS::wslen (ws2);
  CORBA::WChar *tmp = CORBA::wstring_alloc (2*len);
  for (CORBA::ULong i = 0; i < 2; i++)
    for (CORBA::ULong j = 0; j < len; j++)
      tmp[j + i*len] = ws2[j];
  tmp[2*len] = 0;
  CORBA::wstring_free (ws2);
  ws2 = tmp;
  return retwstr;
}

// test for fixed structures. Just copy the in parameter into all the others
Param_Test::Fixed_Struct
Param_Test_i::test_fixed_struct (const Param_Test::Fixed_Struct &s1,
                                 Param_Test::Fixed_Struct &s2,
                                 Param_Test::Fixed_Struct_out s3
                                 ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  s2 = s1;
  s3 = s1;
  return s1;
}

// = Sequences

Param_Test::Long_Seq *
Param_Test_i::test_long_sequence (const Param_Test::Long_Seq & s1,
                                  Param_Test::Long_Seq & s2,
                                  Param_Test::Long_Seq_out s3
                                  ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  Param_Test::Long_Seq
    *ret = new Param_Test::Long_Seq,
    *out = new Param_Test::Long_Seq;

  s2 = s1;
  *out = s1;
  *ret = s1;
  s3 = out;
  return ret;
}

Param_Test::Short_Seq *
Param_Test_i::test_short_sequence (const Param_Test::Short_Seq & s1,
                                   Param_Test::Short_Seq & s2,
                                   Param_Test::Short_Seq_out s3
                                   ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  Param_Test::Short_Seq
    *ret = new Param_Test::Short_Seq,
    *out = new Param_Test::Short_Seq;

  s2 = s1;
  *out = s1;
  *ret = s1;
  s3 = out;
  return ret;
}

Param_Test::Bounded_Short_Seq *
Param_Test_i::test_bounded_short_sequence (const Param_Test::Bounded_Short_Seq & s1,
                                           Param_Test::Bounded_Short_Seq & s2,
                                           Param_Test::Bounded_Short_Seq_out s3
                                           ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  Param_Test::Bounded_Short_Seq
    *ret = new Param_Test::Bounded_Short_Seq,
    *out = new Param_Test::Bounded_Short_Seq;

  s2 = s1;
  *out = s1;
  *ret = s1;
  s3 = out;
  return ret;
}

Param_Test::Bounded_Long_Seq *
Param_Test_i::test_bounded_long_sequence (const Param_Test::Bounded_Long_Seq & s1,
                                          Param_Test::Bounded_Long_Seq & s2,
                                          Param_Test::Bounded_Long_Seq_out s3
                                          ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  Param_Test::Bounded_Long_Seq
    *ret = new Param_Test::Bounded_Long_Seq,
    *out = new Param_Test::Bounded_Long_Seq;

  s2 = s1;
  *out = s1;
  *ret = s1;
  s3 = out;
  return ret;
}

Param_Test::StrSeq *
Param_Test_i::test_strseq (const Param_Test::StrSeq &s1,
                           Param_Test::StrSeq &s2,
                           Param_Test::StrSeq_out s3
                           ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  // we copy the "in" sequences into all the inout, out and return sequences.

  Param_Test::StrSeq
    *ret = new Param_Test::StrSeq,
    *out = new Param_Test::StrSeq;

  if (TAO_debug_level > 0)
    {
      ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*SERVER SIDE=*=*=*=*=*=*=\n"));
      for (CORBA::ULong i=0; (i < s2.length ()); i++)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "Element #%d\n"
                      "in : %s\n",
                      i,
                      (s2[i]? (const char *)s2[i]:"<nul>")));
        }
      if (s2.length () == 0)
        ACE_DEBUG ((LM_DEBUG, "\ninout sequence is NUL\n"));
    }

  // now copy all elements of s1 into the others using the assignment operator
  s2 = s1;
  *out = s1;
  *ret = s1;
  s3 = out;
  return ret;
}

Param_Test::Bounded_StrSeq *
Param_Test_i::test_bounded_strseq (const Param_Test::Bounded_StrSeq & s1,
                                   Param_Test::Bounded_StrSeq & s2,
                                   Param_Test::Bounded_StrSeq_out s3
                                   ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  // we copy the "in" sequences into all the inout, out and return sequences.

  Param_Test::Bounded_StrSeq
    *ret = new Param_Test::Bounded_StrSeq,
    *out = new Param_Test::Bounded_StrSeq;

  // now copy all elements of s1 into the others using the assignment operator
  s2 = s1;
  *out = s1;
  *ret = s1;
  s3 = out;
  return ret;
}

Param_Test::WStrSeq *
Param_Test_i::test_wstrseq (const Param_Test::WStrSeq &ws1,
                            Param_Test::WStrSeq &ws2,
                            Param_Test::WStrSeq_out ws3
                            ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  // we copy the "in" sequences into all the inout, out and return sequences.

  Param_Test::WStrSeq
    *ret = new Param_Test::WStrSeq,
    *out = new Param_Test::WStrSeq;

  // now copy all elements of s1 into the others using the assignment operator
  ws2 = ws1;
  *out = ws1;
  *ret = ws1;
  ws3 = out;
  return ret;
}

Param_Test::Bounded_WStrSeq *
Param_Test_i::test_bounded_wstrseq (const Param_Test::Bounded_WStrSeq & ws1,
                                    Param_Test::Bounded_WStrSeq & ws2,

⌨️ 快捷键说明

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