Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / examples / Simple / grid / Grid_Client_i.cpp
blobd9f89666569c24e2e96bfe51bb02ed959f885827
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
9 // Constructor.
10 Grid_Client_i::Grid_Client_i ()
11 : height_ (0),
12 width_ (0),
13 setx_ (0),
14 sety_ (0),
15 value_ (0)
18 //no-op
21 //Destructor.
22 Grid_Client_i::~Grid_Client_i ()
24 //no-op
27 int
28 Grid_Client_i::parse_args (int argc,
29 ACE_TCHAR *argv[])
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:"));
34 int c = 0;
35 while ((c = get_opts ()) != -1)
36 switch (c)
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 ());
41 break;
42 case 'q': // A vertical position of the grid where a
43 // value is stored
44 sety_ = (CORBA::UShort) ACE_OS::atoi (get_opts.opt_arg ());
45 break;
46 case 'w':
47 width_ = (CORBA::UShort) ACE_OS::atoi (get_opts.opt_arg ());
48 break;
49 case 'h':
50 height_ = (CORBA::UShort) ACE_OS::atoi (get_opts.opt_arg ());
51 break;
52 case 'v':
53 value_ = (CORBA::UShort) ACE_OS::atoi (get_opts.opt_arg ());
54 break;
57 if (setx_ == 0)
58 setx_ = Grid::DEFAULT_LOCATION;
59 if (sety_ == 0)
60 sety_ = Grid::DEFAULT_LOCATION;
61 if (value_ == 0)
62 value_ = Grid::DEFAULT_VALUE;
63 return 0;
66 int
67 Grid_Client_i::run (const char *name,
68 int argc,
69 ACE_TCHAR *argv[])
71 // Initialize the client.
72 if (client_.init (name, argc, argv) == -1)
73 return -1;
75 if (this->parse_args (argc, argv) == -1)
76 return -1;
78 try
80 // Make the Grid.
81 Grid_var grid = client_->make_grid (width_,
82 height_);
84 ACE_DEBUG ((LM_DEBUG,
85 ACE_TEXT ("(%P|%t) Made the grid successfully\n")));
87 // Set a value on the grid
88 grid->set (setx_,
89 sety_,
90 value_);
92 ACE_DEBUG ((LM_DEBUG,
93 ACE_TEXT ("(%P|%t) Setting a value for the grid\n")));
95 CORBA::Long ret_val = grid->get (setx_,
96 sety_);
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"),
102 width_));
104 grid->width (5);
106 ret_val = grid->get (setx_,
107 sety_);
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"),
113 height_));
115 grid->height (5);
117 ret_val = grid->get (setx_,
118 sety_);
120 ACE_ASSERT (ret_val == value_);
122 ACE_DEBUG ((LM_DEBUG,
123 ACE_TEXT ("(%P|%t) Destroing the grid\n")));
125 grid->destroy ();
129 ACE_DEBUG ((LM_DEBUG,
130 ACE_TEXT ("(%P|%t) Accessing the grid out of range\n")));
132 grid->get (setx_,
133 sety_);
135 catch (const Grid::RANGE_ERROR &)
137 // It's ok.
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:");
148 return -1;
151 return 0;