Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / ImplRepo / airplane_client_i.cpp
blobe9af2b8fcaba0ee43becc249b578baf7c3bbadf5
1 #include "airplane_client_i.h"
2 #include "tao/debug.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Read_Buffer.h"
5 #include "ace/ACE.h"
8 // Constructor.
9 Airplane_Client_i::Airplane_Client_i ()
10 : argc_ (0),
11 argv_ (0),
12 server_key_ (ACE::strnew (ACE_TEXT("key0"))),
13 loop_count_ (10),
14 server_ (Paper_Airplane_Server::_nil ())
19 // Parses the command line arguments and returns an error status.
21 int
22 Airplane_Client_i::parse_args ()
24 ACE_Get_Opt get_opts (argc_, argv_, ACE_TEXT("dn:k:"));
25 int c;
27 while ((c = get_opts ()) != -1)
28 switch (c)
30 case 'd': // debug flag
31 TAO_debug_level++;
32 break;
33 case 'n': // loop count
34 this->loop_count_ = (u_int) ACE_OS::atoi (get_opts.opt_arg ());
35 break;
36 case 'k': // ior provide on command line
37 delete [] this->server_key_;
38 this->server_key_ = ACE::strnew (get_opts.opt_arg ());
39 break;
40 case '?':
41 default:
42 ACE_ERROR_RETURN ((LM_ERROR,
43 "usage: %s"
44 " [-d]"
45 " [-n loopcount]"
46 " [-k server-obj-key]"
47 "\n",
48 this->argv_ [0]),
49 -1);
52 // Indicates successful parsing of command line.
53 return 0;
56 // Retreives <count> paper airplanes from the server.
58 int
59 Airplane_Client_i::get_planes (size_t count)
61 int rc = 0;
62 for (size_t i = 0; i < count; i++)
64 try
66 CORBA::String_var response =
67 this->server_->get_plane ();
69 ACE_DEBUG ((LM_DEBUG, "Plane %d is %C\n", i, response.in ()));
71 catch (const CORBA::Exception& ex)
73 ACE_ERROR ((LM_ERROR, "Plane %d exception:\n", i));
74 ex._tao_print_exception ("get_planes");
75 rc = 1;
78 return rc;
82 // Execute client example code.
84 int
85 Airplane_Client_i::run ()
87 return this->get_planes (this->loop_count_);
90 Airplane_Client_i::~Airplane_Client_i ()
92 // Free resources
93 CORBA::release (this->server_);
95 delete [] this->server_key_;
99 int
100 Airplane_Client_i::init (int argc, ACE_TCHAR **argv)
102 this->argc_ = argc;
103 this->argv_ = argv;
107 // Retrieve the ORB.
108 this->orb_ = CORBA::ORB_init (this->argc_,
109 this->argv_,
110 "internet");
112 // Parse command line and verify parameters.
113 if (this->parse_args () == -1)
114 return -1;
116 if (this->server_key_ == 0)
117 ACE_ERROR_RETURN ((LM_ERROR,
118 "%s: no server key specified\n",
119 this->argv_[0]),
120 -1);
122 CORBA::Object_var server_object =
123 this->orb_->string_to_object (this->server_key_);
125 this->server_ = Paper_Airplane_Server::_narrow (server_object.in());
127 if (CORBA::is_nil (server_object.in ()))
128 ACE_ERROR_RETURN ((LM_ERROR,
129 "Error: invalid server key <%s>\n", this->server_key_), -1);
131 catch (const CORBA::Exception& ex)
133 ex._tao_print_exception ("Airplane_Client_i::init");
134 return -1;
137 return 0;