summaryrefslogtreecommitdiff
path: root/TAO/tests/CSD_Strategy_Tests/TP_Test_1/ClientApp.cpp
blob: d51dfbda1b1b70e454e3920947e2f7bcfcb01200 (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
// $Id$
#include "ClientApp.h"
#include "Foo_A_ClientEngine.h"
#include "AppHelper.h"
#include "TestAppExceptionC.h"
#include "ace/Get_Opt.h"
#include "ace/Log_Msg.h"


ClientApp::ClientApp()
  : TestAppBase("TP_Test_1_Client")
{
}


ClientApp::~ClientApp()
{
}


int
ClientApp::run_i(int argc, char* argv[] ACE_ENV_ARG_DECL)
{
  // Initialize the ORB before parsing our own args.
  CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "" ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Parse the command-line args for this application.
  // * Returns -1 if problems are encountered.
  // * Returns 1 if the usage statement was explicitly requested.
  // * Returns 0 otherwise.
  int result = this->parse_args(argc, argv);
  if (result != 0)
    {
      return result;
    }
  // Convert the IOR string to a Foo_A object reference.
  Foo_A_var foo = RefHelper<Foo_A>::string_to_ref(orb.in(),
                                                  this->ior_.c_str()
                                                  ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Create the appropriate client "engine" object.
  Foo_A_ClientEngine engine(foo.in());

  // Execute the client algorithm
  result = engine.execute(ACE_ENV_SINGLE_ARG_PARAMETER) ? 0 : -1;
  ACE_CHECK_RETURN (-1);

  return result;
}


int
ClientApp::parse_args(int argc, char* argv[])
{
  ACE_Get_Opt get_opts(argc, argv, "i:");

  int c;

  while ((c = get_opts()) != -1)
    {
      switch (c)
      {
        case 'i':
          this->ior_ = get_opts.opt_arg();
          break;

        case '?':
          ACE_DEBUG((LM_DEBUG,
                     "(%P|%t) usage:  %s -i <ior_string>\n",
                     argv[0]));
          return 1;

        default:
          ACE_ERROR((LM_ERROR,
                     "(%P|%t) usage:  %s -i <ior_string>\n",
                     argv[0]));
          return -1;
      }
    }

  return 0;
}