1 #include "nestea_client_i.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Read_Buffer.h"
9 Nestea_Client_i::Nestea_Client_i ()
12 , server_key_ (ACE::strnew (ACE_TEXT("key0")))
13 , server_ (Nestea_Bookshelf::_nil ())
14 , shutdown_server_(false)
19 // Parses the command line arguments and returns an error status.
22 Nestea_Client_i::parse_args ()
24 ACE_Get_Opt
get_opts (argc_
, argv_
, ACE_TEXT("dsn:k:"));
27 while ((c
= get_opts ()) != -1)
30 case 'd': // debug flag
33 case 'k': // ior provide on command line
34 delete [] this->server_key_
;
35 this->server_key_
= ACE::strnew (get_opts
.opt_arg ());
37 case 's': // shutdown server before exiting
38 this->shutdown_server_
= true;
42 ACE_ERROR_RETURN ((LM_ERROR
,
47 " [-k server-object-key]"
53 // Indicates successful parsing of command line.
57 // Execute client example code.
60 Nestea_Client_i::run ()
62 this->server_
->drink (40);
63 this->server_
->drink (100);
65 CORBA::String_var praise
= this->server_
->get_praise ();
66 ACE_DEBUG ((LM_DEBUG
, "Cans: %d\n"
68 this->server_
->bookshelf_size (),
71 this->server_
->drink (500);
72 this->server_
->crush (200);
74 praise
= this->server_
->get_praise ();
75 ACE_DEBUG ((LM_DEBUG
, "Cans: %d\n"
77 this->server_
->bookshelf_size (),
86 Nestea_Client_i::~Nestea_Client_i ()
89 CORBA::release (this->server_
);
91 delete [] this->server_key_
;
96 Nestea_Client_i::init (int argc
, ACE_TCHAR
**argv
)
104 this->orb_
= CORBA::ORB_init (this->argc_
,
108 // Parse command line and verify parameters.
109 if (this->parse_args () == -1)
112 if (this->server_key_
== 0)
113 ACE_ERROR_RETURN ((LM_ERROR
,
114 "%s: no server key specified\n",
118 CORBA::Object_var server_object
=
119 this->orb_
->string_to_object (this->server_key_
);
121 this->server_
= Nestea_Bookshelf::_narrow (server_object
.in());
123 if (CORBA::is_nil (server_object
.in ()))
124 ACE_ERROR_RETURN ((LM_ERROR
,
125 "Error: invalid server key <%s>\n", this->server_key_
), -1);
127 catch (const CORBA::Exception
& ex
)
129 ex
._tao_print_exception ("Nestea_Client_i::init");