summaryrefslogtreecommitdiff
path: root/TAO/Benchmark/benchmark/marshal_options.cpp
blob: 2473032f5daf3f4b8347e1499ac70fc545f045aa (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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// ============================================================================
//
// = LIBRARY
//    CORBA Benchmark
// 
// = FILENAME
//    marshal_options.cpp
//
// = AUTHOR
//    Aniruddha Gokhale
// 
// ============================================================================

#include "benchmark/marshal_options.h"
#include "ace/Get_Opt.h"

#if !defined (__ACE_INLINE__)
#include "benchmark/marshal_options.i"
#endif /* __ACE_INLINE__ */

static char *usage_string = 
"Marshal_Test available options: \n\
-d                      : set debug ON \n\
-D                      : set TCP NO DELAY on \n\
-n <service name>       : set the service name\n\
-s <snd sock bufsize>   : set sender sock buf \n\
-r <rcv sock bufsize>   : set recv sock buf \n\
-h <hostname>           : hostname to listen/connect \n\
-p <portnum>            : port num to listen \n\
-i <iters>              : number of iters \n\
-R <ROLE>               : s(ender)/r(eceiver) \n\
-T <datatype>           : s(hort)/l(ong)/d(ouble)/o(ctet)/c(har)/\n\
                          S(truct)/U(nion)/A(ny)/(se)Q/R(ecursive)\n\
-P <policy>             : S(II/SI)/D(II/SI) depending on role \n\
-I <CORBA impl>         : O(rbix)/V(isiBroker)/T(AO)\n\
-o <obj name>           : obj to bind to \n\
-f <filename>           : filename to store results \n\
";

int
CORBA_Marshal_Options::Usage (void)
{
  ACE_DEBUG ((LM_DEBUG, "%s\n", usage_string));
  return -1;
}

int
CORBA_Marshal_Options::parse_args (int argc, char *argv [])
{
  int c; // option letter used
  ACE_Get_Opt get_opt (argc, argv, "dDn:s:r:h:p:i:R:T:P:I:o:f:");

  //  ACE_DEBUG ((LM_DEBUG, "CORBA_Marshal_Options::parse_args\n"));

  while ((c = get_opt ()) != -1)
    {
      switch (c)
	{
	case 'd': // debug
	  this->debug (1);
	  break;
	case 'D': // TCP NODELAY
	  this->disable_nagle (1);
	  break;
	case 'n':
	  this->service_name (get_opt.optarg);
	  break;
	case 's': // sender socket size
	  this->snd_socket_queue_size (ACE_OS::atoi (get_opt.optarg));
	  break;
	case 'r': // receive socket size
	  this->rcv_socket_queue_size (ACE_OS::atoi (get_opt.optarg));
	  break;
	case 'h': // hostname
	  this->hostname (ACE_OS::strdup (get_opt.optarg));
	  break;
	case 'p': // port number
	  this->port (ACE_OS::atoi (get_opt.optarg));
	  break;
	case 'i': // port number
	  this->iterations (ACE_OS::atoi (get_opt.optarg));
	  break;
	case 'R': // role
	  switch (*get_opt.optarg)
	    {
	    case 'S': // sender
	    case 's': // sender
	      this->role (SENDER);
	      break;
	    case 'R': // receiver
	    case 'r': // receiver
	      this->role (RECEIVER);
	      break;
	    default:
	      return this->Usage ();
	    }
	  break;
	case 'T': // data type to test
	  switch (*get_opt.optarg)
	    {
	    case 's': // short
	      this->data_type (SHORT);
	      break;
	    case 'd': // double
	      this->data_type (DOUBLE);
	      break;
	    case 'o': // octet
	      this->data_type (OCTET);
	      break;
	    case 'c': // char
	      this->data_type (CHAR);
	      break;
	    case 'S': // Struct
	      this->data_type (STRUCT);
	      break;
	    case 'U': // Union
	      this->data_type (UNION);
	      break;
	    case 'A': // Any
	      this->data_type (ANY);
	      break;
	    case 'Q': // Sequence
	      this->data_type (SEQUENCE);
	      break;
	    case 'R': // Recursive
	      this->data_type (RECURSIVE);
	      break;
	    case 'l': // long, also the default
	    default:
	      this->data_type (LONG);
	      break;
	    }
	  break;
	case 'P': // policy
	  switch (*get_opt.optarg)
	    {
	    case 'S':
	    case 's':
	      this->policy (STATIC);
	      break;
	    case 'D':
	    case 'd':
	      this->policy (DYNAMIC);
	      break;
	    default:
	      return this->Usage ();
	    }
	  break;
	case 'I': // impl
	  switch (*get_opt.optarg)
	    {
	    case 'O': // Orbix
	      this->proxy_type (ORBIX);
	      break;
	    case 'V': // VisiBroker
	      this->proxy_type (VISIBROKER);
	      break;
	    case 'T': // TAO
	      this->proxy_type (TAO);
	      break;
	    }
	  break;
	case 'o': // obj name
	  this->object_name (ACE_OS::strdup (get_opt.optarg));
	  break;
	case 'f': // file name to save results
	  this->filename (ACE_OS::strdup (get_opt.optarg));
	  break;
	default:  // error
	  return this->Usage ();
	}
    }
  return 0;
}

int
CORBA_Marshal_Options::orb_init_args (int &argc, char *argv [])
{
  char buffer [200];

  argc = 0;
  switch (this->proxy_type_)
    {
    case ORBIX:
      break;
    case VISIBROKER:
      {
	ACE_OS::memset (buffer, '\0', 200);
	if (snd_socket_queue_size_ > 0)
	  {
	    ACE_OS::sprintf (buffer, "-ORBsendbufsize %d", snd_socket_queue_size_);
	    orb_init_args_ += ACE_CString (buffer);
	    argc ++;
	  }

	ACE_OS::memset (buffer, '\0', 200);
	if (rcv_socket_queue_size_ > 0)
	  {
	    ACE_OS::sprintf (buffer, "-ORBrcvbufsize %d", rcv_socket_queue_size_);
	    orb_init_args_ += ACE_CString (buffer);
	    argc ++;
	  }
      }
      break;
    case TAO:
      break;
    }
  ACE_OS::memset (buffer, '\0', 200);
  ACE_OS::memcpy (buffer, boa_init_args_.rep (), boa_init_args_.length ());
  return 0;
}

static char buffer [20][200];

int
CORBA_Marshal_Options::boa_init_args (int &argc, char *argv [])
{
  argc = 0;
  switch (this->proxy_type_)
    {
    case ORBIX:
      break;
    case VISIBROKER:
      {
	ACE_OS::memset (buffer[argc], '\0', 200);
	if (snd_socket_queue_size_ > 0)
	  {
	    ACE_OS::sprintf (buffer[argc], "-OAsendbufsize %d", snd_socket_queue_size_);
	    //	    boa_init_args_ += ACE_CString (buffer[argc]);
	    argc ++;
	  }
	ACE_OS::memset (buffer[argc], '\0', 200);
	if (rcv_socket_queue_size_ > 0)
	  {
	    ACE_OS::sprintf (buffer[argc], "-OArcvbufsize %d", rcv_socket_queue_size_);
	    //	    boa_init_args_ += ACE_CString (buffer[argc]);
	    argc ++;
	  }
	ACE_OS::memset (buffer[argc], '\0', 200);
	if (port_ > 0)
	  {
	    ACE_OS::sprintf (buffer[argc], "-OAport %d", port_);
	    //	    boa_init_args_ += ACE_CString (buffer[argc]);
	    argc ++;
	  }
	ACE_OS::memset (buffer[argc], '\0', 200);
	if (hostname_ != 0 && role_ == RECEIVER)
	  {
	    ACE_OS::sprintf (buffer[argc], "-OAipaddr %s", hostname_);
	    //	    boa_init_args_ += ACE_CString (buffer[argc]);
	    argc ++;
	  }
      }
      break;
    case TAO:
      {
	ACE_OS::memset (buffer[argc], '\0', 200);
	if (port_ > 0)
	  {
	    ACE_OS::sprintf (buffer[argc], "-OAport %d", port_);
	    //	    boa_init_args_ += ACE_CString (buffer);
	    argc ++;
	  }
	ACE_OS::memset (buffer[argc], '\0', 200);
	if (hostname_ != 0 && role_ == RECEIVER)
	  {
	    ACE_OS::sprintf (buffer[argc], "-OAhostname %s", hostname_);
	    //	    boa_init_args_ += ACE_CString (buffer);
	    argc ++;
	  }
      }
      break;
    }
  //  ACE_OS::memset (buffer, '\0', 200);
  //  ACE_OS::memcpy (buffer, boa_init_args_.rep (), boa_init_args_.length ());
  return 0;
}