Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / Persistent_Grid / Persistent_Client_i.cpp
blob6073083f88f8fd059b35f37926865fe2888098bb
1 #include "Persistent_Client.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 Persistent_Client_i::Persistent_Client_i (void)
9 : height_ (0),
10 width_ (0)
12 //no-op
15 //Destructor.
16 Persistent_Client_i::~Persistent_Client_i (void)
18 //no-op
21 int
22 Persistent_Client_i::parse_args (int argc,
23 ACE_TCHAR *argv[])
25 // Parses some of the options that are specific to this example
26 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("dk:f:xw:h:r"));
28 int c = 0;
29 while ((c = get_opts ()) != -1)
31 switch (c)
33 case 'w':
34 this->width_ = (u_int) ACE_OS::atoi (get_opts.opt_arg ());
35 break;
36 case 'h':
37 this->height_ = (u_int) ACE_OS::atoi (get_opts.opt_arg ());
38 break;
39 case 'r':
40 this->remove_ = 1;
41 break;
45 return 0;
48 int
49 Persistent_Client_i::run (const char *name,
50 int argc,
51 ACE_TCHAR *argv[])
53 // Initialize the client.
54 if (client.init (name, argc, argv) == -1)
55 return -1;
57 if (this->parse_args (argc, argv) == -1)
58 return -1;
61 try
63 // Make the Grid.
64 Grid_ptr grid = client->make_grid (width_,
65 height_);
67 ACE_DEBUG ((LM_DEBUG,
68 "(%P|%t) Made the grid successfully\n"));
71 for (CORBA::Short index_ = 0; index_ < height_; index_++)
73 for (CORBA::Short ctr = 0; ctr < width_; ctr++)
75 CORBA::Long ret_val = grid->get (index_,
76 ctr);
78 ACE_DEBUG ((LM_DEBUG,
79 "Grid value [%d][%d] = %d\n",index_, ctr,ret_val));
83 if (client.shutdown () == 1) {
84 client->shutdown ();
87 if (this->remove_ == 1) {
88 client->cleanup ();
91 catch (const CORBA::UserException& range_ex)
93 range_ex._tao_print_exception ("\tFrom get and set grid");
94 return -1;
96 catch (const CORBA::SystemException& memex)
98 memex._tao_print_exception ("Cannot make grid as Memory exhausted");
99 return -1;
102 return 0;