summaryrefslogtreecommitdiff
path: root/TAO/tests/Cubit/TAO/MT_Cubit/Task_Client.h
blob: 70c58134bd62b79428a7a674c6a5218ddbd7f45d (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
// ============================================================================
//
// = LIBRARY
//    TAO/tests
//
// = FILENAME
//    Task_Client.h
//
// = AUTHOR
//    Andy Gokhale, Sumedh Mungee and Sergio Flores-Gaitan
//
// ============================================================================

#if !defined (TASK_CLIENT_H)
#define TASK_CLIENT_H

#include <math.h>

#include "ace/Synch.h"
#include "ace/Task.h"
#include "ace/Thread_Manager.h"
#include "ace/Get_Opt.h"
#include "ace/Profile_Timer.h"
#include "ace/ARGV.h"

#include "orbsvcs/CosNamingC.h"
#include "cubitC.h"

#if !defined (ACE_HAS_THREADS)
class NOOP_ACE_Barrier
{
public:
  NOOP_ACE_Barrier (int ) {}
  void wait (void) {}
};
#define ACE_Barrier NOOP_ACE_Barrier
#endif /* ACE_HAS_THREADS */

static CORBA::String key = CORBA::String ("Cubit");

// Arbitrary generator used by the client to create the numbers to be
// cubed.
inline int func (unsigned i) { return i - 117; }

// The various datatypes which the client and the server can exchange. 
enum Cubit_Datatypes 
{
  CB_OCTET,
  CB_SHORT,
  CB_LONG,
  CB_STRUCT
};

const int CB_40HZ_CONSUMER = 0;
const int CB_20HZ_CONSUMER = 1;    
const int CB_10HZ_CONSUMER = 2;    
const int CB_5HZ_CONSUMER = 3;    
const int CB_1HZ_CONSUMER = 4;

const int CB_40HZ_CONSUMER_RATE = 40;
const int CB_20HZ_CONSUMER_RATE = 20;
const int CB_10HZ_CONSUMER_RATE = 10;
const int CB_5HZ_CONSUMER_RATE = 5;
const int CB_1HZ_CONSUMER_RATE = 1;

const int CB_HIGH_PRIORITY_RATE = 20;
const int CB_LOW_PRIORITY_RATE = 10;

class Task_State
  // = TITLE
  //     Maintains state common to multiple Cubit clients

  // = DESCRIPTION
  //     This class maintains state which is common to the potentially
  //     multiple concurrent clients. 


{
public:
  ACE_Barrier *barrier_;
  // Barrier for the multiple clients to synchronize after
  // binding to the servants.

  Task_State (int argc, char **argv);
  // Constructor. Takes the command line arguments, which are
  // later passed into ORB_init

  u_int start_count_;
  // keeps a count of the number of clients started.. This
  // count also serves as a thread-id. The first thread created
  // gets an ID of 0, then 1, and so on..

  u_int loop_count_;
  // number of times to loop, making calls..

  u_int thread_count_;
  // number of concurrent clients to create..

  u_int base_port_;
  // this is the port at which the high priority servant is
  // listening.. lower priority ports begin at base_port_ + 1

  char server_host_ [1024];
  // Server hostname

  double *latency_;
  // Array to store the latency for every client, indexed by
  // thread-id.

  int *ave_latency_;
  // Int array to store the latencies

  Cubit_Datatypes datatype_;
  // Which datatype to use to make the calls

#if defined (ACE_HAS_THREADS)
  ACE_Thread_Mutex lock_;
  // lock to protect access to this object
#endif /* ACE_HAS_THREADS */

  int argc_;
  char **argv_;
  // command line arguments

  u_int thread_per_rate_;
  // Flag for the thread_per_rate test

  double **global_jitter_array_;
  // this array stores the latency seen by each client for each
  // request, to be used later to compute jitter

  char * factory_ior_;
  // Object reference string for the cubit factory.

  u_int shutdown_;
  // flag that indicates if we are going to call the shutdown methos for the servant

  u_int oneway_;
  // flag that indicates if we are going to use oneway calls instead of two-way
};

class Client : public ACE_Task<ACE_SYNCH>
  // = TITLE
  //     The Cubit client. 
{
public:
  Client (Task_State *ts);
  // constructor, with a pointer to the common task state.

  virtual int svc (void);
  // the thread function

  double get_high_priority_latency (void);
  double get_low_priority_latency (void);
  double get_high_priority_jitter (void);
  double get_low_priority_jitter (void);
  int get_latency (u_int thread_id);
  // accessors to get the various measured quantities


private:

  int run_tests (Cubit_ptr, 
                 unsigned int, 
                 unsigned int, 
                 Cubit_Datatypes, 
                 double frequency);
  // makes the calls to the servant

  void put_latency (double *jitter, 
                    double latency, 
                    unsigned int);
  // Records the latencies in the Task_State

  void put_ave_latency (int latency, unsigned int);
  // Records the latencies in the Task_State 

  int parse_args (int, char **);
  // parses the arguments

  Task_State *ts_;
  // pointer to shared state
  
  CosNaming::NamingContext_var naming_context_;
  // Object reference to the naming service

  CosNaming::NamingContext_var mt_cubit_context_;
  // Object reference to the cubit context "MT_Cubit"
};

#endif /* !defined (TASK_CLIENT_H) */