1 #include "Grid_Client_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Read_Buffer.h"
4 #include "ace/streams.h"
5 #include "ace/OS_NS_unistd.h"
7 // This is the interface program that accesses the remote object
10 Grid_Client_i::Grid_Client_i ()
22 Grid_Client_i::~Grid_Client_i ()
28 Grid_Client_i::parse_args (int argc
,
31 // Parses some of the options that are specific to this example
32 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("df:nk:xw:h:p:q:v:"));
35 while ((c
= get_opts ()) != -1)
38 case 'p': // A horizontal position of the grid where
39 // the value is stored
40 setx_
= (CORBA::UShort
) ACE_OS::atoi (get_opts
.opt_arg ());
42 case 'q': // A vertical position of the grid where a
44 sety_
= (CORBA::UShort
) ACE_OS::atoi (get_opts
.opt_arg ());
47 width_
= (CORBA::UShort
) ACE_OS::atoi (get_opts
.opt_arg ());
50 height_
= (CORBA::UShort
) ACE_OS::atoi (get_opts
.opt_arg ());
53 value_
= (CORBA::UShort
) ACE_OS::atoi (get_opts
.opt_arg ());
58 setx_
= Grid::DEFAULT_LOCATION
;
60 sety_
= Grid::DEFAULT_LOCATION
;
62 value_
= Grid::DEFAULT_VALUE
;
67 Grid_Client_i::run (const char *name
,
71 // Initialize the client.
72 if (client_
.init (name
, argc
, argv
) == -1)
75 if (this->parse_args (argc
, argv
) == -1)
81 Grid_var grid
= client_
->make_grid (width_
,
85 ACE_TEXT ("(%P|%t) Made the grid successfully\n")));
87 // Set a value on the grid
93 ACE_TEXT ("(%P|%t) Setting a value for the grid\n")));
95 CORBA::Long ret_val
= grid
->get (setx_
,
98 ACE_ASSERT (ret_val
== value_
);
100 ACE_DEBUG ((LM_DEBUG
,
101 ACE_TEXT ("(%P|%t) Changing grid's width from %i to 5\n"),
106 ret_val
= grid
->get (setx_
,
109 ACE_ASSERT (ret_val
== value_
);
111 ACE_DEBUG ((LM_DEBUG
,
112 ACE_TEXT ("(%P|%t) Changing grid's height from %d to 5\n"),
117 ret_val
= grid
->get (setx_
,
120 ACE_ASSERT (ret_val
== value_
);
122 ACE_DEBUG ((LM_DEBUG
,
123 ACE_TEXT ("(%P|%t) Destroing the grid\n")));
129 ACE_DEBUG ((LM_DEBUG
,
130 ACE_TEXT ("(%P|%t) Accessing the grid out of range\n")));
135 catch (const Grid::RANGE_ERROR
&)
140 if (client_
.do_shutdown () == 1)
141 client_
->shutdown ();
143 ACE_UNUSED_ARG (ret_val
);
145 catch (const CORBA::Exception
& ex
)
147 ex
._tao_print_exception ("Exception in Grid_Client_i::run:");