📄 cubit_client.cpp
字号:
this->cubit_->cube_many_sequence (input,
vout
ACE_ENV_ARG_PARAMETER);
}
ACE_TRY_CHECK;
if (output->length () != input.length ())
{
ACE_ERROR ((LM_ERROR,
"** cube sequence, wrong length\n"));
this->error_count_++;
return;
}
u_int rl = output->length ();
if (input.length () < rl)
{
rl = input.length ();
}
Cubit::Many &ret_in = input[0];
Cubit::Many &out = output[0];
if (ret_in.l * ret_in.l * ret_in.l != out.l ||
ret_in.s * ret_in.s * ret_in.s != out.s ||
ret_in.o * ret_in.o * ret_in.o != out.o)
{
ACE_ERROR ((LM_ERROR,
"** cube_long_sequence ERROR\n"));
this->error_count_++;
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"from cube_many_sequence");
this->error_count_++;
}
ACE_ENDTRY;
ACE_CHECK;
}
void
Cubit_Client::cube_rti_data (int,
int numUpdates,
int numAttrs
ACE_ENV_ARG_DECL)
{
ACE_TRY
{
this->call_count_++;
Cubit::RtiPacket input;
input.packetHeader.packetLength = 1; // this is probably redundant
input.packetHeader.federationHandle = 2;
input.packetHeader.channelHandle = 3;
input.packetHeader.packetColor = 4;
input.msgs.length (numUpdates);
for (int j = 0; j < numUpdates; ++j)
{
#if (ACE_HAS_PURIFY == 1)
Cubit::RtiObjectUpdateMessageHeader o;
ACE_OS::memset (&o, 0, sizeof(Cubit::RtiObjectUpdateMessageHeader));
input.msgs[j].oumh (o);
#else
input.msgs[j].oumh (Cubit::RtiObjectUpdateMessageHeader ());
#endif /* ACE_HAS_PURIFY == 1 */
Cubit::RtiObjectUpdateMessageHeader & oumh = input.msgs[j].oumh ();
oumh.updateLength = 2001; // redundant
oumh.updateTag = 2002;
oumh.objectHandle = 2003;
oumh.timestamp = 3.14159;
oumh.eventRetractionHandle = 2004;
oumh.classHandle = 2005;
oumh.sendingFederateHandle = 2006;
oumh.userTag = CORBA::string_dup ("beefcake!");
oumh.regionData.length(0);
oumh.transportationHandle = 1;
oumh.orderingHandle = 1;
oumh.messagePayload.length (numAttrs);
for (int k = 0; k < numAttrs; ++k)
{
#if (ACE_HAS_PURIFY == 1)
Cubit::HandleValuePair h;
ACE_OS::memset (&h, 0, sizeof(Cubit::HandleValuePair));
oumh.messagePayload[k] = h;
#else
oumh.messagePayload[k] = Cubit::HandleValuePair ();
#endif /* ACE_HAS_PURIFY == 1 */
Cubit::HandleValuePair &hvp = oumh.messagePayload[k];
hvp.handle = k * k;
const char *d1 = "somedata";
hvp.data.length (ACE_OS::strlen (d1)+1);
ACE_OS::strcpy ((char *) hvp.data.get_buffer (), d1);
}
}
Cubit::RtiPacket_var output;
Cubit::RtiPacket_out vout (output);
// Cube the sequence
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG,
"Input: \n"));
print_RtiPacket (input);
}
{
ACE_FUNCTION_TIMEPROBE (CUBIT_CLIENT_CUBE_RTI_DATA_START);
this->cubit_->cube_rti_data (input,
vout
ACE_ENV_ARG_PARAMETER);
}
ACE_TRY_CHECK;
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG,
"Output: \n"));
print_RtiPacket (*vout.ptr ());
ACE_DEBUG ((LM_DEBUG,
"need to check whether cubing happened\n"));
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"from cube_rtti_data");
this->error_count_++;
}
ACE_ENDTRY;
ACE_CHECK;
}
// calculate the cube from long contained in an any
void
Cubit_Client::cube_any (int i
ACE_ENV_ARG_DECL)
{
ACE_TRY
{
CORBA::Long arg_long = this->func (i);
// Cube a long inside an any.
CORBA::Long ret_long;
CORBA::Any arg_any;
CORBA::Any * ret_any;
// Should the timing include the packing and unpacking of the any? NO.
arg_any <<= arg_long;
{
ACE_FUNCTION_TIMEPROBE (CUBIT_CLIENT_CUBE_ANY_START);
ret_any = this->cubit_->cube_any (arg_any
ACE_ENV_ARG_PARAMETER);
}
ACE_TRY_CHECK;
*ret_any >>= ret_long;
this->call_count_++;
if (TAO_debug_level > 2)
{
ACE_DEBUG ((LM_DEBUG,
"cube any (long): %d --> %d\n",
arg_long,
ret_long));
}
arg_long = arg_long * arg_long * arg_long;
if (arg_long != ret_long)
{
ACE_ERROR ((LM_ERROR,
"** cube_any(%d) ERROR (got %d, expect %d) \n",
(CORBA::Long) this->func (i),
ret_long, arg_long));
this->error_count_++;
}
delete ret_any;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"from cube_any");
this->error_count_++;
}
ACE_ENDTRY;
ACE_CHECK;
}
// Cube the numbers in a struct
void
Cubit_Client::cube_any_struct (int i
ACE_ENV_ARG_DECL)
{
ACE_TRY
{
Cubit::Many arg_struct;
Cubit::Many * ret_struct;
this->call_count_++;
arg_struct.l = this->func (i);
arg_struct.s = this->func (i);
arg_struct.o = this->func (i);
// Cube a "struct" in an any ...
CORBA::Any arg_any;
CORBA::Any * ret_any;
arg_any <<= arg_struct;
{
ACE_FUNCTION_TIMEPROBE (CUBIT_CLIENT_CUBE_ANY_STRUCT_START);
ret_any = this->cubit_->cube_any_struct (arg_any
ACE_ENV_ARG_PARAMETER);
}
ACE_TRY_CHECK;
*ret_any >>= ret_struct;
if (TAO_debug_level > 2)
{
ACE_DEBUG ((LM_DEBUG,
"cube any struct ..."));
}
arg_struct.l = arg_struct.l * arg_struct.l * arg_struct.l;
arg_struct.s = arg_struct.s * arg_struct.s * arg_struct.s;
arg_struct.o = arg_struct.o * arg_struct.o * arg_struct.o;
if (arg_struct.l != ret_struct->l
|| arg_struct.s != ret_struct->s
|| arg_struct.o != ret_struct->o)
{
ACE_ERROR ((LM_ERROR, "** cube_any_struct ERROR -- %d should be %d\n",
ret_struct->l, arg_struct.l));
this->error_count_++;
}
delete ret_any;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"from cube_any_struct");
this->error_count_++;
}
ACE_ENDTRY;
ACE_CHECK;
}
void
Cubit_Client::print_stats (const char *call_name,
ACE_Profile_Timer::ACE_Elapsed_Time &elapsed_time)
{
ACE_DEBUG ((LM_DEBUG,
"%s:\n",
call_name));
if (this->quiet_)
{
return;
}
if (!this->quiet_)
{
if (this->call_count_ > 0 && this->error_count_ == 0)
{
#if defined (ACE_LACKS_FLOATING_POINT)
// elapsed_time.real_time is in units of microseconds.
const u_int calls_per_sec =
this->call_count_ * 1000000u / elapsed_time.real_time;
ACE_DEBUG ((LM_DEBUG,
"\treal_time\t= %u ms,\n"
"\t%u calls/second\n",
elapsed_time.real_time / 1000u,
calls_per_sec));
#else /* ! ACE_LACKS_FLOATING_POINT */
// elapsed_time.real_time is in units of seconds.
double calls_per_sec =
this->call_count_ / elapsed_time.real_time;
ACE_DEBUG ((LM_DEBUG,
"\treal_time\t= %0.06f ms, \n\t"
"user_time\t= %0.06f ms, \n\t"
"system_time\t= %0.06f ms\n"
"\t%0.00f calls/second\n",
elapsed_time.real_time < 0.0 ? 0.0
: elapsed_time.real_time * ACE_ONE_SECOND_IN_MSECS,
elapsed_time.user_time < 0.0 ? 0.0
: elapsed_time.user_time * ACE_ONE_SECOND_IN_MSECS,
elapsed_time.system_time < 0.0 ? 0.0
: elapsed_time.system_time * ACE_ONE_SECOND_IN_MSECS,
calls_per_sec < 0.0 ? 0.0 : calls_per_sec));
#endif /* ! ACE_LACKS_FLOATING_POINT */
}
else
{
ACE_ERROR ((LM_ERROR,
"\tNo time stats printed."
" Call count zero or error ocurred.\n"));
}
}
ACE_DEBUG ((LM_DEBUG,
"\t%d calls, %d errors\n",
this->call_count_,
this->error_count_));
}
// Execute client example code.
int
Cubit_Client::run ()
{
u_int i;
ACE_Profile_Timer timer;
ACE_Profile_Timer::ACE_Elapsed_Time elapsed_time;
// ACE_Time_Value before;
// Show the results one type at a time.
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
// VOID
if (this->check_enabled (TAO_ENABLE_CUBIT_VOID))
{
this->call_count_ = 0;
this->error_count_ = 0;
timer.start ();
for (i = 0; i < this->loop_count_; ++i)
{
this->cube_void (i
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
timer.stop ();
timer.elapsed_time (elapsed_time);
this->print_stats ("cube_void",
elapsed_time);
}
// SHORT
if (this->check_enabled (TAO_ENABLE_CUBIT_SHORT))
{
this->call_count_ = 0;
this->error_count_ = 0;
timer.start ();
for (i = 0; i < this->loop_count_; ++i)
{
this->cube_short (i
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
timer.stop ();
timer.elapsed_time (elapsed_time);
this->print_stats ("cube_short",
elapsed_time);
}
// OCTET
if (this->check_enabled (TAO_ENABLE_CUBIT_OCTET))
{
this->call_count_ = 0;
this->error_count_ = 0;
timer.start ();
for (i = 0; i < this->loop_count_; ++i)
{
this->cube_octet (i
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
timer.stop ();
timer.elapsed_time (elapsed_time);
this->print_stats ("cube_octet",
elapsed_time);
}
// LONG
if (this->check_enabled (TAO_ENABLE_CUBIT_LONG))
{
this->call_count_ = 0;
this->error_count_ = 0;
timer.start ();
for (i = 0; i < this->loop_count_; ++i)
{
this->cube_long (i
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
timer.stop ();
timer.elapsed_time (elapsed_time);
this->print_stats ("cube_long",
elapsed_time);
}
// STRUCT
if (this->check_enabled (TAO_ENABLE_CUBIT_STRUCT))
{
this->call_count_ = 0;
this->error_count_ = 0;
timer.start ();
for (i = 0; i < this->loop_count_; ++i)
{
this->cube_struct (i
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
timer.stop ();
timer.elapsed_time (elapsed_time);
this->print_stats ("cube_struct",
elapsed_time);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -