summaryrefslogtreecommitdiff
path: root/TAO/tests/Cubit/TAO/DII_Cubit/clnt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/tests/Cubit/TAO/DII_Cubit/clnt.cpp')
-rw-r--r--TAO/tests/Cubit/TAO/DII_Cubit/clnt.cpp656
1 files changed, 0 insertions, 656 deletions
diff --git a/TAO/tests/Cubit/TAO/DII_Cubit/clnt.cpp b/TAO/tests/Cubit/TAO/DII_Cubit/clnt.cpp
deleted file mode 100644
index 5bb1e2dc995..00000000000
--- a/TAO/tests/Cubit/TAO/DII_Cubit/clnt.cpp
+++ /dev/null
@@ -1,656 +0,0 @@
-// $Id$
-
-// ============================================================================
-//
-// = LIBRARY
-// TAO/tests/DII_Cubit
-//
-// = FILENAME
-// clnt.cpp
-//
-// = DESCRIPTION
-// This class implements a simple "cube" CORBA client for the Cubit
-// example using stubs generated by the TAO ORB IDL compiler.
-//
-// = AUTHORS
-// Andy Gokhale, Sumedh Mungee, and Sergio Flores-Gaitan
-//
-// ============================================================================
-#include "ace/Profile_Timer.h"
-#include "ace/Get_Opt.h"
-#include "tao/corba.h"
-#include "cubitC.h"
-#include "clnt.h"
-
-// Constructor.
-
-Cubit_Client::Cubit_Client (void)
- : loop_count_ (250),
- exit_later_ (0),
- objref_ (CORBA::Object::_nil ()),
- cubit_ (Cubit::_nil ()),
- orb_ptr_ (0),
- call_count_ (0),
- error_count_ (0),
- cubit_key_ ("key00"),
- hostname_ (ACE_DEFAULT_SERVER_HOST),
- portnum_ (TAO_DEFAULT_SERVER_PORT)
-{
-}
-
-// destructor
-
-Cubit_Client::~Cubit_Client (void)
-{
- // Free resources
- CORBA::release (this->cubit_);
- CORBA::release (this->objref_);
- CORBA::release (this->orb_ptr_);
-}
-
-// Simple function that returns the substraction of 117 from the
-// parameter.
-
-int
-Cubit_Client::func (u_int i)
-{
- return i - 117;
-}
-
-// Parses the command line arguments and returns an error status.
-
-int
-Cubit_Client::parse_args (void)
-{
- ACE_Get_Opt opts (argc_, argv_, "dn:k:h:p:x");
- int c;
-
- while ((c = opts ()) != -1)
- switch (c)
- {
- case 'd': // debug flag
- TAO_debug_level++;
- break;
- case 'n': // loop count
- loop_count_ = (u_int) ACE_OS::atoi (opts.optarg);
- break;
- case 'h':
- hostname_ = ACE_OS::strdup (opts.optarg);
- break;
- case 'p':
- portnum_ = ACE_OS::atoi (opts.optarg);
- break;
- case 'k': // stringified objref
- cubit_key_ = ACE_OS::strdup (opts.optarg);
- break;
- case 'x':
- exit_later_++;
- break;
- case '?':
- default:
- ACE_ERROR_RETURN ((LM_ERROR,
- "usage: %s"
- " [-d]"
- " [-n loopcount]"
- " [-k cubit-obj-ref-key]"
- " [-h hostname]"
- " [-p port]"
- " [-x]"
- "\n", argv_ [0]
- ), -1);
- }
-
- return 0; // Indicates successful parsing of command line
-}
-
-void
-Cubit_Client::cube_union_stub (void)
-{
- this->cubit_ = Cubit::_narrow (this->objref_);
-
- Cubit_oneof u, *r;
-
- this->call_count_++;
-
- u._disc = e_2nd;
- u.l = 3;
-
- // Cube a "union" ...
- r = this->cubit_->Cubit_cube_union (u, this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("from cube_union");
- this->error_count_++;
- }
- else
- {
- dmsg ("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_++;
- }
-
- delete r;
- }
-
- this->call_count_++;
-
- u._disc = e_5th;
-#if 0
- u.cm.l = this->func (i);
- u.cm.s = this->func (i);
- u.cm.o = this->func (i);
-#endif
-
- u.cm.l = 7;
- u.cm.s = 5;
- u.cm.o = 3;
-
- // Cube another "union" which uses the default arm ...
- r = this->cubit_->Cubit_cube_union (u, this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("from cube_union");
- this->error_count_++;
- }
- else
- {
- dmsg ("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_++;
- }
-
- delete r;
- }
-}
-
-void
-Cubit_Client::cube_union_dii (void)
-{
- // Create the request ...
- CORBA::Request_ptr req;
-
- this->call_count_++;
-
- req = this->objref_->_request ((CORBA::String) "cube_union", this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->error_count_++;
-
- this->env_.print_exception ("cube_union_dii request create");
- return;
- }
-
- // ... initialise the argument list and result ...
- Cubit_oneof u, *r;
-
- u._disc = e_3rd;
- u.cm.l = 5;
- u.cm.s = -7;
- u.cm.o = 3;
-
- CORBA::Any tmp_arg (TC_Cubit_oneof, &u, CORBA::B_FALSE);
-
- req->arguments ()->add_value (0, tmp_arg, CORBA::ARG_IN, this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->error_count_++;
- this->env_.print_exception ("cube_union_dii request arg add");
- CORBA::release (req);
- return;
- }
-
- req->result ()->value ()->replace (TC_Cubit_oneof, 0, CORBA::B_TRUE, this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->error_count_++;
- this->env_.print_exception ("cube_union_dii result type");
- CORBA::release (req);
- return;
- }
-
- // Make the invocation, verify the result.
-
- req->invoke ();
-
- if (req->env ()->exception () != 0)
- {
- this->error_count_++;
- req->env ()->print_exception ("cube_union_dii invoke");
- CORBA::release (req);
- return;
- }
-
- r = (Cubit_oneof *) req->result ()->value ()->value ();
-
- if (r->cm.o != 27 || r->cm.l != 125 || r->cm.s != -343)
- {
- this->error_count_++;
- ACE_ERROR ((LM_ERROR, "cube_union_dii -- bad results\n"));
- }
- else
- dmsg ("cube_union_dii ... success!!");
-
- CORBA::release (req);
-}
-
-// Cube an octet
-
-void
-Cubit_Client::cube_octet (int i)
-{
- CORBA::Octet arg_octet = this->func (i);
-
- // Cube an octet.
- CORBA::Octet ret_octet = this->cubit_->Cubit_cube_octet (arg_octet, this->env_);
-
- this->call_count_++;
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("from cube_octet");
- this->error_count_++;
- }
- else
- {
- dmsg2 ("cube octet: %d --> %d\n", arg_octet, ret_octet);
- arg_octet = arg_octet * arg_octet * arg_octet;
- if (arg_octet != ret_octet) {
- ACE_DEBUG ((LM_DEBUG,
- "** cube_octet (%d) ERROR (--> %d)\n",
- (CORBA::Octet) this->func (i),
- ret_octet));
- this->error_count_++;
- }
- }
-}
-
-
-// calculate the cube from a long
-
-void
-Cubit_Client::cube_long (int i)
-{
- CORBA::Long arg_long = this->func (i);
-
- // Cube a long.
- CORBA::Long ret_long = this->cubit_->Cubit_cube_long (arg_long, this->env_);
-
- this->call_count_++;
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("from cube_long");
- this->error_count_++;
- }
- else
- {
- dmsg2 ("cube 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_long (%ld) ERROR (--> %ld)\n",
- (CORBA::Long) this->func (i),
- ret_long));
- this->error_count_++;
- }
- }
-}
-
-// Cube a short.
-
-void
-Cubit_Client::cube_short (int i)
-{
- CORBA::Short arg_short = this->func (i);
- // Cube a short.
- CORBA::Short ret_short = cubit_->Cubit_cube_short (arg_short, this->env_);
-
- this->call_count_++;
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("from cube_short");
- this->error_count_++;
- }
- else
- {
- dmsg2 ("cube short: %d --> %d\n",
- arg_short,
- ret_short);
- arg_short = arg_short * arg_short * arg_short;
-
- if (arg_short != ret_short)
- {
- ACE_ERROR ((LM_ERROR, "** cube_short (%d) ERROR (--> %d)\n",
- (CORBA::Short) this->func (i),
- ret_short));
- this->error_count_++;
- }
- }
-}
-
-// Cube the numbers in a struct
-
-void
-Cubit_Client::cube_struct (int i)
-{
- 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" ...
- ret_struct = this->cubit_->Cubit_cube_struct (arg_struct, this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("from cube_struct");
- this->error_count_++;
- }
- else
- {
- dmsg ("cube 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_struct ERROR\n"));
- this->error_count_++;
- }
- }
- delete ret_struct;
-}
-
-int
-Cubit_Client::init (int argc, char **argv)
-{
- this->argc_ = argc;
- this->argv_ = argv;
-
- // Parse command line and verify parameters.
- if (this->parse_args () == -1)
- return -1;
-
- // construct the TAO ior for the Cubit object reference
- ACE_OS::sprintf (this->buf_,
- "iiop:1.0//%s:%d/%s",
- this->hostname_,
- this->portnum_,
- this->cubit_key_);
-
- // Retrieve the ORB.
- this->orb_ptr_ = CORBA::ORB_init (this->argc_,
- this->argv_,
- "internet",
- this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("ORB initialization");
- return -1;
- }
-
- this->objref_ = this->orb_ptr_->string_to_object ((CORBA::String) this->buf_,
- this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("string2object");
- return 1;
- }
-
- if (CORBA::is_nil (this->objref_) == CORBA::B_TRUE)
- ACE_ERROR_RETURN ((LM_ERROR,
- "%s: must identify non-null target objref\n",
- this->argv_ [0]),
- -1);
-
- // Narrow the CORBA::Object reference to the stub object, checking
- // the type along the way using _is_a.
- this->cubit_ = Cubit::_narrow (this->objref_);
-
- if (this->cubit_ == 0)
- ACE_ERROR_RETURN ((LM_ERROR,
- " (%P|%t) Unable to narrow object reference to a Cubit_ptr.\n"),
- -1);
-
- return 0;
-}
-
-// Simple test for DII: call "cube_struct".
-
-void
-Cubit_Client::cube_struct_dii (void)
-{
- // Create the request ...
-
- CORBA::Request_ptr req =
- this->objref_->_request ((CORBA::String) "cube_struct", this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("DII request create");
- return;
- }
-
- // ... initialise the argument list and result ...
- Cubit_Many arg, *result;
-
- arg.o = 3;
- arg.l = 5;
- arg.s = -7;
-
- CORBA::Any tmp_arg (TC_Cubit_Many, &arg, CORBA::B_FALSE);
-
- req->arguments ()->add_value (0, tmp_arg, CORBA::ARG_IN, this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("DII request arg add");
- CORBA::release (req);
- return;
- }
-
- req->result ()->value ()->replace (TC_Cubit_Many, 0, CORBA::B_TRUE, this->env_);
-
- if (this->env_.exception () != 0)
- {
- this->env_.print_exception ("DII request result type");
- CORBA::release (req);
- return;
- }
-
- // Make the invocation, verify the result
-
- this->call_count_++;
- req->invoke ();
-
- if (req->env ()->exception () != 0)
- {
- req->env ()->print_exception ("DII invoke");
- CORBA::release (req);
- return;
- }
-
- result = (Cubit_Many *) req->result ()->value ()->value ();
-
- if (result->o != 27 || result->l != 125 || result->s != -343)
- ACE_ERROR ((LM_ERROR, "DII cube_struct -- bad results\n"));
- else
- dmsg ("DII cube_struct ... success!!");
-
- CORBA::release (req);
-}
-
-// prints time statistics
-
-void
-Cubit_Client::print_stats (const char *call_name, ACE_Profile_Timer::ACE_Elapsed_Time &elapsed_time)
-{
- double tmp;
-
- ACE_DEBUG ((LM_DEBUG,
- "%s:\n",
- call_name));
-
- if (this->call_count_ > 0 && this->error_count_ == 0)
- {
- tmp = 1000 / elapsed_time.real_time;
-
- elapsed_time.real_time *= ACE_ONE_SECOND_IN_MSECS;
- elapsed_time.user_time *= ACE_ONE_SECOND_IN_MSECS;
- elapsed_time.system_time *= ACE_ONE_SECOND_IN_MSECS;
-
- elapsed_time.real_time /= this->call_count_;
- elapsed_time.user_time /= this->call_count_;
- elapsed_time.system_time /= this->call_count_;
-
- tmp = 1000 / 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,
- elapsed_time.user_time < 0.0? 0.0:elapsed_time.user_time,
- elapsed_time.system_time < 0.0? 0.0:elapsed_time.system_time,
- tmp < 0.0? 0.0 : tmp));
- }
- 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 (void)
-{
- u_int i;
-
- ACE_Profile_Timer timer;
- ACE_Profile_Timer::ACE_Elapsed_Time elapsed_time;
-
- // ACE_Time_Value before;
-
- // We start an ACE_Profile_Timer here...
- timer.start ();
-
- // Make the calls in a loop.
- for (i = 0; i < this->loop_count_; i++)
- {
- this->cube_short (i);
- this->cube_octet (i);
- this->cube_long (i);
- this->cube_struct (i);
- }
-
- // stop the timer.
- timer.stop ();
-
- timer.elapsed_time (elapsed_time);
- // compute call average call time.
- this->print_stats ("cube average call", elapsed_time);
-
- // Simple test for DII: call "cube_struct". (It's not timed since
- // the copious mallocation of DII would bias numbers against typical
- // stub-based calls).
- this->call_count_ = 0;
- this->error_count_ = 0;
-
- timer.start ();
- // Make the calls in a loop.
- for (i = 0; i < this->loop_count_; i++)
- {
- this->cube_struct_dii ();
- }
- timer.stop ();
-
- timer.elapsed_time (elapsed_time);
- // compute call average call time.
- this->print_stats ("cube_struct_dii call", elapsed_time);
-
- this->call_count_ = 0;
- this->error_count_ = 0;
-
- timer.start ();
- // Make the calls in a loop.
- for (i = 0; i < this->loop_count_; i++)
- {
- this->cube_union_stub ();
- }
- timer.stop ();
-
- timer.elapsed_time (elapsed_time);
- // compute call average call time.
- this->print_stats ("cube_union_stub call", elapsed_time);
-
- this->call_count_ = 0;
- this->error_count_ = 0;
-
- timer.start ();
- // Make the calls in a loop.
- for (i = 0; i < this->loop_count_; i++)
- {
- this->cube_union_dii ();
- }
- timer.stop ();
-
- timer.elapsed_time (elapsed_time);
- // compute call average call time.
- this->print_stats ("cube_union_dii call", elapsed_time);
-
- if (this->exit_later_)
- {
- this->cubit_->Cubit_please_exit (this->env_);
- dexc (this->env_, "server, please ACE_OS::exit");
- }
-
- return this->error_count_ == 0 ? 0 : 1;
-}
-
-
-// This function runs the test.
-
-int
-main (int argc, char **argv)
-{
- Cubit_Client cubit_client;
-
- if (cubit_client.init (argc, argv) == -1)
- return 1;
- else
- return cubit_client.run ();
-}