summaryrefslogtreecommitdiff
path: root/TAO/examples/Persistent_Grid/Persistent_Client_i.cpp
blob: dd4a4e14d90bc7106f0879555a76dc9d8e86ddc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "Persistent_Client.h"
#include "ace/Get_Opt.h"
#include "ace/Read_Buffer.h"

// This is the interface program that accesses the remote object

// Constructor.
Persistent_Client_i::Persistent_Client_i ()
  : height_ (0),
    width_ (0)
{
  //no-op
}

//Destructor.
Persistent_Client_i::~Persistent_Client_i ()
{
  //no-op
}

int
Persistent_Client_i::parse_args (int argc,
                                 ACE_TCHAR *argv[])
{
  // Parses some of the options that are specific to this example
  ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("dk:f:xw:h:r"));

  int c = 0;
  while ((c = get_opts ()) != -1)
    {
      switch (c)
      {
      case 'w':
        this->width_ = (u_int) ACE_OS::atoi (get_opts.opt_arg ());
        break;
      case 'h':
        this->height_ = (u_int) ACE_OS::atoi (get_opts.opt_arg ());
        break;
      case 'r':
        this->remove_ = 1;
        break;
      }
    }

  return 0;
}

int
Persistent_Client_i::run (const char *name,
                          int argc,
                          ACE_TCHAR *argv[])
{
  // Initialize the client.
  if (client.init (name, argc, argv) == -1)
    return -1;

  if (this->parse_args (argc, argv) == -1)
    return -1;


  try
    {
      // Make the Grid.
      Grid_ptr grid = client->make_grid (width_,
                                         height_);

      ACE_DEBUG ((LM_DEBUG,
                  "(%P|%t) Made the grid successfully\n"));


      for (CORBA::Short index_ = 0; index_ < height_; index_++)
        {
          for (CORBA::Short ctr = 0; ctr < width_; ctr++)
            {
              CORBA::Long ret_val = grid->get (index_,
                                               ctr);

              ACE_DEBUG ((LM_DEBUG,
                          "Grid value [%d][%d] =  %d\n",index_, ctr,ret_val));
            }
        }

      if (client.shutdown () == 1) {
        client->shutdown ();
      }

      if (this->remove_ == 1) {
        client->cleanup ();
      }
    }
  catch (const CORBA::UserException& range_ex)
    {
      range_ex._tao_print_exception ("\tFrom get and set grid");
      return -1;
    }
  catch (const CORBA::SystemException& memex)
    {
      memex._tao_print_exception ("Cannot make grid as Memory exhausted");
      return -1;
    }

  return 0;
}