Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / Persistent_Grid / Grid_Client_i.cpp
blobddc3bae71cfc777884ded84da39453fb687c27ed
1 #include "Grid_Client_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Read_Buffer.h"
5 // This is the interface program that accesses the remote object
7 // Constructor.
8 Grid_Client_i::Grid_Client_i (void)
9 : height_ (0),
10 width_ (0),
11 setx_ (0),
12 sety_ (0),
13 value_ (0)
16 //no-op
19 //Destructor.
20 Grid_Client_i::~Grid_Client_i (void)
22 //no-op
25 int
26 Grid_Client_i::parse_args (int argc,
27 ACE_TCHAR *argv[])
29 // Parses some of the options that are specific to this example
30 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("df:nk:xw:h:v:"));
32 int c = 0;
33 while ((c = get_opts ()) != -1)
34 switch (c)
36 case 'w':
37 this->width_ = (u_int) ACE_OS::atoi (get_opts.opt_arg ());
38 break;
39 case 'h':
40 this->height_ = (u_int) ACE_OS::atoi (get_opts.opt_arg ());
41 break;
42 case 'v':
43 this->value_ = (u_int) ACE_OS::atoi (get_opts.opt_arg ());
44 break;
47 if (width_ == 0 )
48 width_ = Grid::DEFAULT_SIZE;
49 if (height_ == 0 )
50 height_ = Grid::DEFAULT_SIZE;
51 if (value_ == 0 )
52 value_ = Grid::DEFAULT_VALUE;
53 return 0;
56 int
57 Grid_Client_i::run (const char *name,
58 int argc,
59 ACE_TCHAR *argv[])
61 // Initialize the client.
62 if (client.init (name, argc, argv) == -1)
63 return -1;
65 if (this->parse_args (argc, argv) == -1)
66 return -1;
69 try
71 // Make the Grid.
73 Grid_ptr grid = client->make_grid (width_,
74 height_);
76 ACE_DEBUG ((LM_DEBUG,
77 "(%P|%t) Made the grid successfully\n"));
79 for (CORBA::Short index_ = 0; index_ < width_; index_++)
81 for (CORBA::Short ctr = 0; ctr < height_; ctr++)
83 ACE_DEBUG ((LM_DEBUG,
84 "Grid value [%d][%d] = %d\n",index_, ctr,value_+ctr));
85 // Set a value on the grid
86 grid->set (index_,
87 ctr,
88 (value_ + ctr));
93 ACE_DEBUG ((LM_DEBUG,
94 "(%P|%t) Setting a value for the grid\n"));
97 if (client.shutdown () == 1) {
98 client->shutdown ();
102 catch (const CORBA::UserException& range_ex)
104 range_ex._tao_print_exception ("\tFrom get and set grid");
105 return -1;
107 catch (const CORBA::SystemException& memex)
109 memex._tao_print_exception ("Cannot make grid as Memory exhausted");
110 return -1;
113 return 0;