summaryrefslogtreecommitdiff
path: root/CIAO/tests/Bug_2130_Regression/SEC_CheckPoint/controller.cpp
blob: 44ceea6235f99dbf17712d190f1a9f941326c2ad (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//$Id$


/**
 * @file controller.cpp
 *
 * This program interact with a TSEC_CheckPoint component, using its supported
 * interface "ISessionService"
 */


//-------------------------------------------------------------------
// Includes
//-------------------------------------------------------------------

#include "ace/streams.h"
#include "ace/Get_Opt.h"

#include "TSEC_CheckPointC.h"


//-------------------------------------------------------------------
// Defines
//-------------------------------------------------------------------

#define SEPARATION_LINE "----------------------------------------" \
                        "----------------------------------------\n"

#define TESTCASE_NOT_DEFINED             0
#define TESTCASE_ACQUIRE_RELEASE_SESSION 1
#define TESTCASE_CREATE_DESTROY_SESSION  2


//-------------------------------------------------------------------
// Statics
//-------------------------------------------------------------------

static int         _testcase           = TESTCASE_NOT_DEFINED;
static int         _loop               = 0;
static int         _ident              = 1;
static const char* _sessionService_ior = 0;


//-------------------------------------------------------------------
// Function
//-------------------------------------------------------------------

int
parse_args
(
  int   argc,
  char* argv[]
)
{
  ACE_Get_Opt get_opts( argc, argv, "i:k:l:t:" );
  int c;

  while( ( c = get_opts() ) != -1 )
  {
    switch( c )
    {
      case 'i':
         _ident = ACE_OS::atoi( get_opts.opt_arg() );
         break;

      case 'k':
        _sessionService_ior = get_opts.opt_arg();
        break;

      case 'l':
        _loop = ACE_OS::atoi( get_opts.opt_arg() );
        break;

      case 't':
        _testcase = ACE_OS::atoi( get_opts.opt_arg() );
        break;

      case '?':  // display help for use of the server.
      default:
        ACE_ERROR_RETURN( ( LM_ERROR,
                            "usage:  %s\n"
                            "-i <Ident> (default is 1)\n"
                            "-k <TSEC_CheckPoint IOR> (default is file://TSEC_CheckPoint.ior)\n"
                            "-t <testcase number> (default is 1)\n"
                            "\n",
                            argv[0] ),
                            -1 );
      break;
    }
  }

  if ( _sessionService_ior == 0 )
  {
    _sessionService_ior = "file://TSEC_CheckPoint.ior";
  }

  if( _testcase == 0 )
  {
    _testcase = TESTCASE_ACQUIRE_RELEASE_SESSION;
  }

  return 0;
}


//-------------------------------------------------------------------
// Function
//-------------------------------------------------------------------

int
ACE_TMAIN
(
  int   argc,
  ACE_TCHAR* argv[]
)
{
  try
  {
    // Initialize orb
    CORBA::ORB_var orb =
                        CORBA::ORB_init( argc, argv);

    if( parse_args( argc, argv ) != 0 )
    {
      return -1;
    }

    CORBA::Object_var obj = orb->string_to_object( _sessionService_ior
 );

    ENW::ISessionService_var sessionService =
               ENW::ISessionService::_narrow (obj.in () );

    if( CORBA::is_nil( sessionService.in() ) )
    {
      ACE_ERROR_RETURN( ( LM_ERROR,
                          "Unable to acquire 'SessionService' objref\n" ),
                          -1 );
    }

    ACE_DEBUG( ( LM_DEBUG, SEPARATION_LINE ) );

    for( int i = 0; i < _loop; ++i )
    {
      switch( _testcase )
      {
        case TESTCASE_ACQUIRE_RELEASE_SESSION:
          {
            ACE_DEBUG( ( LM_DEBUG, "(%P|%t@%T) Executing testcase acquire release session...[running]\n" ) );

            ENW::TSession_var session = sessionService->acquireSession( _ident );
            //CORBA::Long ident = session->getIdent();
            sessionService->releaseSession( _ident, session.in () );

            ACE_DEBUG( ( LM_DEBUG, "(%P|%t@%T) Executing testcase acquire release session...[ready]\n" ) );
          }

          break;

        case TESTCASE_CREATE_DESTROY_SESSION:
          {
            ACE_DEBUG( ( LM_DEBUG, "(%P|%t@%T) Executing testcase create destroy session...[running]\n" ) );

            ENW::TSession_var session = sessionService->createSession();
            CORBA::Long ident = session->getIdent();
            ACE_DEBUG(( LM_DEBUG, "(%P|%t@%T) Ident: %d\n", ident ) );

            if( !sessionService->destroySession( session.in () ) )
            {
              ACE_DEBUG( ( LM_DEBUG, "(%P|%t@%T) Executing testcase create destroy session...[ERROR]\n" ) );
            }

            ACE_DEBUG( ( LM_DEBUG, "(%P|%t@%T) Executing testcase create destroy session...[ready]\n" ) );
          }

          break;

        default:
          ACE_DEBUG( ( LM_DEBUG, "(%P|%t@%T) Testcase is undefined!\n" ) );
          break;

      }
    }

    orb->destroy( );
  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception ("Who is the culprit \n");
    cerr << "Uncaught CORBA exception" << endl;

    return 1;
  }

  return 0;
}