1 #include "airplane_client_i.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Read_Buffer.h"
9 Airplane_Client_i::Airplane_Client_i ()
12 server_key_ (ACE::strnew (ACE_TEXT("key0"))),
14 server_ (Paper_Airplane_Server::_nil ())
19 // Parses the command line arguments and returns an error status.
22 Airplane_Client_i::parse_args ()
24 ACE_Get_Opt
get_opts (argc_
, argv_
, ACE_TEXT("dn:k:"));
27 while ((c
= get_opts ()) != -1)
30 case 'd': // debug flag
33 case 'n': // loop count
34 this->loop_count_
= (u_int
) ACE_OS::atoi (get_opts
.opt_arg ());
36 case 'k': // ior provide on command line
37 delete [] this->server_key_
;
38 this->server_key_
= ACE::strnew (get_opts
.opt_arg ());
42 ACE_ERROR_RETURN ((LM_ERROR
,
46 " [-k server-obj-key]"
52 // Indicates successful parsing of command line.
56 // Retreives <count> paper airplanes from the server.
59 Airplane_Client_i::get_planes (size_t count
)
62 for (size_t i
= 0; i
< count
; i
++)
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");
82 // Execute client example code.
85 Airplane_Client_i::run ()
87 return this->get_planes (this->loop_count_
);
90 Airplane_Client_i::~Airplane_Client_i ()
93 CORBA::release (this->server_
);
95 delete [] this->server_key_
;
100 Airplane_Client_i::init (int argc
, ACE_TCHAR
**argv
)
108 this->orb_
= CORBA::ORB_init (this->argc_
,
112 // Parse command line and verify parameters.
113 if (this->parse_args () == -1)
116 if (this->server_key_
== 0)
117 ACE_ERROR_RETURN ((LM_ERROR
,
118 "%s: no server key specified\n",
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");