summaryrefslogtreecommitdiff
path: root/TAO/IIOP/tests/Cubit/Orbix/client/client.cpp
blob: fcf45bdf706922187efadbd8c372fb21b666ed11 (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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//**************************************************************************
//
// NAME :   client.C 
// DESCRIPTION:  
//
// Client for the Cubit example
//
//****************************************************************************

#include "ace/OS.h"
#include "ace/Get_Opt.h"
#include "cubit.h"

int LOOP_COUNT;
char SERVER_HOST [1024];

inline int func (unsigned i) { return i - 117; }
void run_tests (Cubit_var, int);

// = TITLE
//     Parses the command line arguments and returns an error status
//
// = DESCRIPTION
//     This method parses the command line arguments
int parse_args(int argc, char *argv[])
{
  ACE_OS::strcpy (SERVER_HOST, "localhost");
  ACE_Get_Opt opts (argc, argv, "dh:n:O:x");
  int			c;
  
  while ((c = opts ()) != -1)
    switch (c) {
    case 'h':
      ACE_OS::strcpy (SERVER_HOST, opts.optarg);
      continue;
    case 'd':  // debug flag
      continue;
      
    case 'n':			// loop count
      LOOP_COUNT = (unsigned) ACE_OS::atoi (opts.optarg);
      continue;
      
    case 'O':			// stringified objref
      continue;
      
    case 'x':
      continue;
      
    case '?':
    default:
      ACE_OS::fprintf (stderr, "usage:  %s"
                       " [-d]"
                       " [-n loopcount]"
                       " [-h SERVER_HOST]"
                       " [-x]"
                       "\n", argv [0]
                       );
      return 1;
    }
  
  return 0;  // Indicates successful parsing of command line
}


//
// Mainline
//
int
main (int argc, char *argv[])
{
  if (parse_args (argc, argv) != 0)
    return -1;

  Cubit_var cb;
  // cout << "attempting to contact server at host " << SERVER_HOST << '\n' ;
 
  //
  // Initialise client's binding to an
  // arbitrary cubit server (at some host)
  // 
  TRY {
    cb = Cubit::_bind ("", SERVER_HOST, IT_X);
  }
  CATCHANY {
    cerr << "Binding failed: " << IT_X;
  }
  ENDTRY;
  
  run_tests (cb, LOOP_COUNT);
  return 0;
}


void
run_tests (Cubit_var cb, int loop_count) 
{
    //
  // Make the calls in a loop.
  //
  unsigned i;
  unsigned call_count, error_count;

  call_count = 0;
  error_count = 0;

  ACE_Time_Value before, after;

  before = ACE_OS::gettimeofday();
  
  //
  // Cube an octet.
  //
  
  for (i = 0; i < loop_count; i++)
    {

      call_count++;

      CORBA::Octet arg_octet = func (i), ret_octet;

      TRY {
      ret_octet = cb->cube_octet (arg_octet);
      } 
      CATCHANY {
        cerr << "Call failed: " << IT_X;
        error_count++;
      } 
      ENDTRY;
      arg_octet = arg_octet * arg_octet * arg_octet;
      if (arg_octet != ret_octet) {
        ACE_OS::printf ("** cube_octet(%d)  (--> %d)\n", arg_octet , ret_octet);
        error_count++;
      }
    
  
  //
  // Cube a short.
  //
      call_count++;

      CORBA::Short arg_short = func (i), ret_short;

      TRY {
      ret_short = cb->cube_short (arg_short);
      } 
      CATCHANY {
        cerr << "Call failed: " << IT_X;
        error_count++;
      } 
      ENDTRY;
      arg_short = arg_short * arg_short * arg_short;
      if (arg_short != ret_short) {
        ACE_OS::printf ("** cube_short(%d)  (--> %d)\n", arg_short , ret_short);
        error_count++;
      }

  //
  // Cube a long.
  //
  
      call_count++;

      CORBA::Long arg_long = func (i), ret_long;

      TRY {
      ret_long = cb->cube_long (arg_long);
      } 
      CATCHANY {
        cerr << "Call failed: " << IT_X;
      } 
      ENDTRY;
      arg_long = arg_long * arg_long * arg_long;
      if (arg_long != ret_long) {
        ACE_OS::printf ("** cube_long(%d)  (--> %d)\n", arg_long , ret_long);
        error_count++;
      }


      //
      // Cube a "struct" ...
      //
      Cubit::Many	arg_struct, ret_struct;
      
       call_count++;
       
       arg_struct.l = func (i);
       arg_struct.s = func (i);
       arg_struct.o = func (i);
       
       TRY {
         ret_struct = cb->cube_struct (arg_struct);
       }
       CATCHANY {
         cerr << "Call failed: " << IT_X;
         error_count++;
       } 
       ENDTRY;
       arg_struct.l = arg_struct.l  * arg_struct.l  * arg_struct.l ;
       arg_struct.s = arg_struct.s  * arg_struct.s  * arg_struct.s ;
       arg_struct.o = arg_struct.o  * arg_struct.o  * arg_struct.o ;
       
       if (arg_struct.l  != ret_struct.l 
           || arg_struct.s  != ret_struct.s 
           || arg_struct.o  != ret_struct.o )
         {
           cerr << "** cube_struct ERROR\n";
           error_count++;
         }
    }
    
  
  after = ACE_OS::gettimeofday();
  
  if (call_count > 0) 
    {
      if (error_count == 0)
        {
          ACE_Time_Value diff = after - before;
          unsigned long	us = diff.sec() * 1000 * 1000 + diff.usec();
          
          us /= call_count;
          
          if (us > 0)
            ACE_OS::printf ("cube average call ACE_OS::time\t= %ld.%.03ldms, \t"
                            "%ld calls/second\n",
                            us / 1000, us % 1000,
                            1000000L / us);
        }
      
      ACE_OS::printf ("%d calls, %d errors\n", call_count, error_count);
    }
}