1 #include "nestea_client_i.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Read_Buffer.h"
10 Nestea_Client_i::Nestea_Client_i (void)
13 , server_key_ (ACE::strnew (ACE_TEXT("key0")))
14 , server_ (Nestea_Bookshelf::_nil ())
15 , shutdown_server_(false)
20 // Parses the command line arguments and returns an error status.
23 Nestea_Client_i::parse_args (void)
25 ACE_Get_Opt
get_opts (argc_
, argv_
, ACE_TEXT("dsn:k:"));
28 while ((c
= get_opts ()) != -1)
31 case 'd': // debug flag
34 case 'k': // ior provide on command line
35 delete [] this->server_key_
;
36 this->server_key_
= ACE::strnew (get_opts
.opt_arg ());
38 case 's': // shutdown server before exiting
39 this->shutdown_server_
= true;
43 ACE_ERROR_RETURN ((LM_ERROR
,
48 " [-k server-object-key]"
54 // Indicates successful parsing of command line.
58 // Execute client example code.
61 Nestea_Client_i::run ()
63 this->server_
->drink (40);
64 this->server_
->drink (100);
66 CORBA::String_var praise
= this->server_
->get_praise ();
67 ACE_DEBUG ((LM_DEBUG
, "Cans: %d\n"
69 this->server_
->bookshelf_size (),
72 this->server_
->drink (500);
73 this->server_
->crush (200);
75 praise
= this->server_
->get_praise ();
76 ACE_DEBUG ((LM_DEBUG
, "Cans: %d\n"
78 this->server_
->bookshelf_size (),
87 Nestea_Client_i::~Nestea_Client_i (void)
90 CORBA::release (this->server_
);
92 delete [] this->server_key_
;
97 Nestea_Client_i::init (int argc
, ACE_TCHAR
**argv
)
105 this->orb_
= CORBA::ORB_init (this->argc_
,
109 // Parse command line and verify parameters.
110 if (this->parse_args () == -1)
113 if (this->server_key_
== 0)
114 ACE_ERROR_RETURN ((LM_ERROR
,
115 "%s: no server key specified\n",
119 CORBA::Object_var server_object
=
120 this->orb_
->string_to_object (this->server_key_
);
122 this->server_
= Nestea_Bookshelf::_narrow (server_object
.in());
124 if (CORBA::is_nil (server_object
.in ()))
125 ACE_ERROR_RETURN ((LM_ERROR
,
126 "Error: invalid server key <%s>\n", this->server_key_
), -1);
128 catch (const CORBA::Exception
& ex
)
130 ex
._tao_print_exception ("Nestea_Client_i::init");