📄 cubit_client.cpp
字号:
// Cubit_Client.cpp,v 1.49 2003/11/04 08:12:59 dhinton Exp
#include "Cubit_Client.h"
#include "RTI_IO.h"
#include "tao/Timeprobe.h"
#include "tao/TAO_Internal.h"
#include "tao/debug.h"
#include "ace/Env_Value_T.h"
#include "ace/Read_Buffer.h"
#include "ace/OS_NS_fcntl.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_unistd.h"
#include "ace/OS_NS_strings.h"
#include "ace/OS_NS_string.h"
ACE_RCSID(IDL_Cubit, Cubit_Client, "Cubit_Client.cpp,v 1.31 1999/08/04 07:15:14 nanbor Exp")
#if defined (ACE_ENABLE_TIMEPROBES)
static const char *Cubit_Client_Timeprobe_Description[] =
{
"Cubit_Client::cube_oneway - start",
"Cubit_Client::cube_oneway - end",
"Cubit_Client::cube_void - start",
"Cubit_Client::cube_void - end",
"Cubit_Client::cube_octet - start",
"Cubit_Client::cube_octet - end",
"Cubit_Client::cube_short - start",
"Cubit_Client::cube_short - end",
"Cubit_Client::cube_long - start",
"Cubit_Client::cube_long - end",
"Cubit_Client::cube_struct - start",
"Cubit_Client::cube_struct - end",
"Cubit_Client::cube_union - start",
"Cubit_Client::cube_union - end",
"Cubit_Client::cube_long_sequence - start",
"Cubit_Client::cube_long_sequence - end",
"Cubit_Client::cube_octet_sequence - start",
"Cubit_Client::cube_octet_sequence - end",
"Cubit_Client::cube_many_sequence - start",
"Cubit_Client::cube_many_sequence - end",
"Cubit_Client::cube_rti_data - start",
"Cubit_Client::cube_rti_data - end",
"Cubit_Client::cube_any - start",
"Cubit_Client::cube_any - end",
"Cubit_Client::cube_any_struct - start",
"Cubit_Client::cube_any_struct - end"
};
enum
{
// Timeprobe description table start key
CUBIT_CLIENT_CUBE_ONEWAY_START = 10000,
CUBIT_CLIENT_CUBE_ONEWAY_END,
CUBIT_CLIENT_CUBE_VOID_START,
CUBIT_CLIENT_CUBE_VOID_END,
CUBIT_CLIENT_CUBE_OCTET_START,
CUBIT_CLIENT_CUBE_OCTET_END,
CUBIT_CLIENT_CUBE_SHORT_START,
CUBIT_CLIENT_CUBE_SHORT_END,
CUBIT_CLIENT_CUBE_LONG_START,
CUBIT_CLIENT_CUBE_LONG_END,
CUBIT_CLIENT_CUBE_STRUCT_START,
CUBIT_CLIENT_CUBE_STRUCT_END,
CUBIT_CLIENT_CUBE_UNION_START,
CUBIT_CLIENT_CUBE_UNION_END,
CUBIT_CLIENT_CUBE_LONG_SEQUENCE_START,
CUBIT_CLIENT_CUBE_LONG_SEQUENCE_END,
CUBIT_CLIENT_CUBE_OCTET_SEQUENCE_START,
CUBIT_CLIENT_CUBE_OCTET_SEQUENCE_END,
CUBIT_CLIENT_CUBE_MANY_SEQUENCE_START,
CUBIT_CLIENT_CUBE_MANY_SEQUENCE_END,
CUBIT_CLIENT_CUBE_RTI_DATA_START,
CUBIT_CLIENT_CUBE_RTI_DATA_END,
CUBIT_CLIENT_CUBE_ANY_START,
CUBIT_CLIENT_CUBE_ANY_END,
CUBIT_CLIENT_CUBE_ANY_STRUCT_START,
CUBIT_CLIENT_CUBE_ANY_STRUCT_END
};
// Setup Timeprobes
ACE_TIMEPROBE_EVENT_DESCRIPTIONS (Cubit_Client_Timeprobe_Description,
CUBIT_CLIENT_CUBE_ONEWAY_START);
#endif /* ACE_ENABLE_TIMEPROBES */
// Bitmasks for each of the Cubit tests
#define TAO_ENABLE_CUBIT_VOID 1 << 0
#define TAO_ENABLE_CUBIT_OCTET 1 << 1
#define TAO_ENABLE_CUBIT_SHORT 1 << 2
#define TAO_ENABLE_CUBIT_LONG 1 << 3
#define TAO_ENABLE_CUBIT_STRUCT 1 << 4
#define TAO_ENABLE_CUBIT_UNION 1 << 5
#define TAO_ENABLE_CUBIT_SMALL_OCTET_SEQ 1 << 6
#define TAO_ENABLE_CUBIT_LARGE_OCTET_SEQ 1 << 7
#define TAO_ENABLE_CUBIT_SMALL_LONG_SEQ 1 << 8
#define TAO_ENABLE_CUBIT_LARGE_LONG_SEQ 1 << 9
#define TAO_ENABLE_CUBIT_SMALL_STRUCT_SEQ 1 << 10
#define TAO_ENABLE_CUBIT_LARGE_STRUCT_SEQ 1 << 11
#define TAO_ENABLE_CUBIT_MIXIN 1 << 12
#define TAO_ENABLE_CUBIT_RTI_DATA 1 << 13
#define TAO_ENABLE_CUBIT_ONE_WAY 1 << 14
#define TAO_ENABLE_CUBIT_ANY 1 << 15
#define TAO_ENABLE_CUBIT_ANY_STRUCT 1 << 16
// Bitmask to enable all tests
#define TAO_ENABLE_CUBIT_ALL \
TAO_ENABLE_CUBIT_VOID | \
TAO_ENABLE_CUBIT_OCTET | \
TAO_ENABLE_CUBIT_SHORT | \
TAO_ENABLE_CUBIT_LONG | \
TAO_ENABLE_CUBIT_STRUCT | \
TAO_ENABLE_CUBIT_UNION | \
TAO_ENABLE_CUBIT_SMALL_OCTET_SEQ | \
TAO_ENABLE_CUBIT_LARGE_OCTET_SEQ | \
TAO_ENABLE_CUBIT_SMALL_LONG_SEQ | \
TAO_ENABLE_CUBIT_LARGE_LONG_SEQ | \
TAO_ENABLE_CUBIT_SMALL_STRUCT_SEQ | \
TAO_ENABLE_CUBIT_LARGE_STRUCT_SEQ | \
TAO_ENABLE_CUBIT_MIXIN | \
TAO_ENABLE_CUBIT_RTI_DATA | \
TAO_ENABLE_CUBIT_ONE_WAY | \
TAO_ENABLE_CUBIT_ANY | \
TAO_ENABLE_CUBIT_ANY_STRUCT
// Constructor.
Cubit_Client::Cubit_Client (int shutdown)
: cubit_factory_key_ (0),
loop_count_ (250),
shutdown_ (shutdown),
quiet_ (0),
cubit_ (Cubit::_nil ()),
call_count_ (0),
error_count_ (0),
cubit_factory_ior_file_ (0),
f_handle_ (ACE_INVALID_HANDLE),
bytes_in_octet_sequence_ (0),
test_enable_bitset_ (0),
test_disable_bitset_ (0)
{
}
// Simple function that returns the substraction of 117 from the
// parameter.
int
Cubit_Client::func (u_int i)
{
return i - 117;
}
// Reads the Cubit factory ior from a file
int
Cubit_Client::read_ior (const char *filename)
{
// Open the file for reading.
this->f_handle_ = ACE_OS::open (filename,0);
if (this->f_handle_ == ACE_INVALID_HANDLE)
{
ACE_ERROR_RETURN ((LM_ERROR,
"Unable to open <%s> for reading: %p\n",
filename),
-1);
}
ACE_Read_Buffer ior_buffer (this->f_handle_);
char *data = ior_buffer.read ();
if (data == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"Unable to allocate memory to read ior: %p\n"),
-1);
}
this->cubit_factory_key_ = ACE_OS::strdup (data);
ior_buffer.alloc ()->free (data);
return 0;
}
// Parses the command line arguments and returns an error status.
int
Cubit_Client::parse_args (void)
{
ACE_Get_Opt get_opts (argc_, argv_, "b:t:z:ovdn:f:k:xsq");
int c = 0;
int result = 0;
u_int test_mask = 0;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'b':
// bytes in octet sequence
result = ACE_OS::atoi (get_opts.opt_arg ());
if (result <= 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Invalid number of bytes entered: <%s>\n",
get_opts.opt_arg ()),
-1);
else
this->bytes_in_octet_sequence_ = (u_int) result;
break;
case 't':
test_mask = this->opt_to_mask (get_opts.opt_arg ());
if (test_mask == 0)
return -1;
this->enable_test (test_mask);
break;
case 'z':
test_mask = this->opt_to_mask (get_opts.opt_arg ());
if (test_mask == 0)
return -1;
this->disable_test (test_mask);
break;
case 'v':
// For backward compatibility
test_mask = this->opt_to_mask ("void");
if (test_mask == 0)
return -1;
this->enable_test (test_mask);
break;
case 'o':
// For backward compatibility
test_mask = this->opt_to_mask ("one_way");
if (test_mask == 0)
return -1;
this->enable_test (test_mask);
break;
case 'd': // debug flag
TAO_debug_level++;
break;
case 'n': // loop count
result = ACE_OS::atoi (get_opts.opt_arg ());
if (result <= 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Invalid number of iterations entered: <%s>\n",
get_opts.opt_arg ()),
-1);
else
this->loop_count_ = (u_int) result;
break;
case 'f': // read the IOR from the file.
result = this->read_ior (get_opts.opt_arg ());
if (result < 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Unable to read ior from <%s> : %p\n",
get_opts.opt_arg (),
""),
-1);
break;
case 'k': // read the cubit IOR from the command-line.
this->cubit_factory_key_ =
ACE_OS::strdup (get_opts.opt_arg ());
break;
case 'x':
ACE_DEBUG ((LM_DEBUG, "We will shutdown the server\n"));
this->shutdown_ = 1;
break;
case 'q':
this->quiet_ = 1;
break;
case '?':
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s"
" [-b bytes-in-sequence]"
" [-d]"
" [-n loopcount]"
" [-f cubit_factory-obj-ref-key-file]"
" [-k cubit-obj-ref-key]"
" [-x]"
" [-s]"
" [-t test-to-enable]"
" [-z test-to-disable]"
"\n",
this->argv_ [0]),
-1);
}
// Indicates successful parsing of command line.
return 0;
}
u_int
Cubit_Client::opt_to_mask (const char *test_type)
{
if (ACE_OS::strcasecmp (test_type, "void") == 0)
return TAO_ENABLE_CUBIT_VOID;
else if (ACE_OS::strcasecmp (test_type, "octet") == 0)
return TAO_ENABLE_CUBIT_OCTET;
else if (ACE_OS::strcasecmp (test_type, "short") == 0)
return TAO_ENABLE_CUBIT_SHORT;
else if (ACE_OS::strcasecmp (test_type, "long") == 0)
return TAO_ENABLE_CUBIT_LONG;
else if (ACE_OS::strcasecmp (test_type, "struct") == 0)
return TAO_ENABLE_CUBIT_STRUCT;
else if (ACE_OS::strcasecmp (test_type, "union") == 0)
return TAO_ENABLE_CUBIT_UNION;
else if (ACE_OS::strcasecmp (test_type, "small_octet_seq") == 0)
return TAO_ENABLE_CUBIT_SMALL_OCTET_SEQ;
else if (ACE_OS::strcasecmp (test_type, "small_long_seq") == 0)
return TAO_ENABLE_CUBIT_SMALL_LONG_SEQ;
else if (ACE_OS::strcasecmp (test_type, "small_struct_seq") == 0)
return TAO_ENABLE_CUBIT_SMALL_STRUCT_SEQ;
else if (ACE_OS::strcasecmp (test_type, "large_octet_seq") == 0)
return TAO_ENABLE_CUBIT_LARGE_OCTET_SEQ;
else if (ACE_OS::strcasecmp (test_type, "large_long_seq") == 0)
return TAO_ENABLE_CUBIT_LARGE_LONG_SEQ;
else if (ACE_OS::strcasecmp (test_type, "large_struct_seq") == 0)
return TAO_ENABLE_CUBIT_LARGE_STRUCT_SEQ;
else if (ACE_OS::strcasecmp (test_type, "mixin") == 0)
return TAO_ENABLE_CUBIT_MIXIN;
else if (ACE_OS::strcasecmp (test_type, "rti_data") == 0)
return TAO_ENABLE_CUBIT_RTI_DATA;
else if (ACE_OS::strcasecmp (test_type, "one_way") == 0)
return TAO_ENABLE_CUBIT_ONE_WAY;
else if (ACE_OS::strcasecmp (test_type, "any") == 0)
return TAO_ENABLE_CUBIT_ANY;
else if (ACE_OS::strcasecmp (test_type, "any_struct") == 0)
return TAO_ENABLE_CUBIT_ANY_STRUCT;
ACE_ERROR_RETURN ((LM_ERROR,
"Incorrect test: %s\n"
"Valid tests are:\n"
" void, octet, short, long, struct, union,\n"
" small_octet_seq, small_long_seq, small_struct_seq\n"
" large_octet_seq, large_long_seq, large_struct_seq\n"
" mixin, rti_data, one_way, any, any_struct\n",
test_type),
0); // Zero since u_int return type
}
void
Cubit_Client::enable_test (u_int mask)
{
ACE_SET_BITS (this->test_enable_bitset_, mask);
}
void
Cubit_Client::disable_test (u_int mask)
{
ACE_SET_BITS (this->test_disable_bitset_, mask);
}
int
Cubit_Client::check_enabled (u_int mask) const
{
return ACE_BIT_ENABLED (this->test_enable_bitset_, mask);
}
// Exercise the union. Cube a union.
void
Cubit_Client::cube_union (ACE_ENV_SINGLE_ARG_DECL)
{
ACE_TRY
{
Cubit::oneof u;
this->call_count_++;
u.l (3); // use the long union branch.
// Cube a "union" ...
Cubit::oneof r;
{
ACE_FUNCTION_TIMEPROBE (CUBIT_CLIENT_CUBE_UNION_START);
r = this->cubit_->cube_union (u
ACE_ENV_ARG_PARAMETER);
}
ACE_TRY_CHECK;
if (TAO_debug_level > 2)
ACE_DEBUG ((LM_DEBUG, "cube union ..."));
u.l (u.l () * u.l () * u.l ()) ;
if (u.l () != r.l ())
{
ACE_DEBUG ((LM_DEBUG, "** cube_union ERROR\n"));
this->error_count_++;
}
this->call_count_++;
u._d (Cubit::e_3rd);
u.cm ().l = 7;
u.cm ().s = 5;
u.cm ().o = 3;
// Cube another "union" which uses the default arm ... NOT tested yet
{
ACE_FUNCTION_TIMEPROBE (CUBIT_CLIENT_CUBE_UNION_START);
r = this->cubit_->cube_union (u
ACE_ENV_ARG_PARAMETER);
}
ACE_TRY_CHECK;
if (TAO_debug_level > 2)
ACE_DEBUG ((LM_DEBUG, "cube union ..."));
u.cm ().l = u.cm ().l * u.cm ().l * u.cm ().l;
u.cm ().s = u.cm ().s * u.cm ().s * u.cm ().s;
u.cm ().o = u.cm ().o * u.cm ().o * u.cm ().o;
if (u.cm ().l != r.cm ().l
|| u.cm ().s != r.cm ().s
|| u.cm ().o != r.cm ().o)
{
ACE_DEBUG ((LM_DEBUG, "** cube_union ERROR\n"));
this->error_count_++;
}
}
ACE_CATCHANY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -