summaryrefslogtreecommitdiff
path: root/TAO/local/tests/Latency.h
blob: 275da3af55b91454181822636b105ceee6eb77c9 (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
/* -*- C++ -*- */
// $Id$
//
// ============================================================================
//
// = LIBRARY
//    ACE Event Service Benchmarks
// 
// = FILENAME
//    Latency.h
//
// = AUTHOR
//    David Levine (levine@cs.wustl.edu) and
//    Tim Harrison (harrison@cs.wustl.edu)
//
// = DESCRIPTION
//
// ============================================================================

#if !defined (LATENCY_H)
#define LATENCY_H

#include "ace/SString.h"
#include "RtecEventChannelAdminC.h"
#include "RtecEventCommS.h"

class Latency_Consumer : public POA_RtecEventComm::PushConsumer
// = TITLE
//    Latency Consumer
//
// = DESCRIPTION
//    Simple example of a consumer that registers for supplier
//    notifications.
{
public:
  Latency_Consumer (const int measure_jitter = 0);
  // Construction.  The default of not measuring jitter provides
  // a "null" push routine, for measuring aggregate timing.

  int open_consumer (RtecEventChannelAdmin::EventChannel_ptr ec,
		     const char *my_name);
  // Uses the name server to obtain a reference to the <supplier_name>
  // and registers with channel to receive notifications from the
  // supplier.  Also registers to receive shutdown messages from the
  // supplier.  Stores <my_name> for printing out messages.  Returns 0
  // on success, -1 on failure.

  virtual void disconnect_push_consumer (CORBA::Environment &);
  // The channel is disconnecting.

  void entry_point (const char*);
  const char *entry_point () const;

  void print_stats () /* const */;
  // Print timing statistics.

// (not protected to allow short-circuiting) protected:
  virtual void push (const RtecEventComm::EventSet &events,
		     CORBA::Environment &);
  // If the <events>[0] is a notification, prints out the data from
  // the supplier.  If its a shutdown message, the consumer
  // disconnects from the channel.

protected:
  void shutdown (void);
  // Disconnect from the Event Service.

  // = Event channel adminstration references.
  RtecEventChannelAdmin::EventChannel_var channel_admin_;
  RtecEventChannelAdmin::ConsumerAdmin_ptr consumer_admin_;
  RtecEventChannelAdmin::ProxyPushSupplier_ptr suppliers_;

private:
  RtecScheduler::handle_t rt_info_;

  int measure_jitter_;

  ACE_Time_Value min_latency_;
  ACE_Time_Value max_latency_;
  ACE_Time_Value total_latency_;
  u_long total_pushes_;
  // Registers and counters for keeping track of latency statistics.

  ACE_CString entry_point_;
};

// ************************************************************

class Latency_Supplier
// = TITLE
//    Latency Supplier
//
// = DESCRIPTION
//    Generates event nofications and a shutdown message.
{
public:

  //
  // This class provides IS-A Consumer and Supplier of events. But
  // inheritance from two skeleton classes is non-complaint (or at
  // least won't work with TAO). We use smaller implementation classes
  // that delegate on Latency_Supplier to do the job.
  //
  class Supplier : public POA_RtecEventComm::PushSupplier {
  public:
    virtual void disconnect_push_supplier (CORBA::Environment &);
    // The channel is disconnecting.

  private:
    Supplier (Latency_Supplier* impl);
    friend class Latency_Supplier;

  private:
    Latency_Supplier* impl_;
  };

  class Consumer : public POA_RtecEventComm::PushConsumer {
  public:
    virtual void push (const RtecEventComm::EventSet &events,
		       CORBA::Environment &);
    // The channel pushed some events to us.

    virtual void disconnect_push_consumer (CORBA::Environment &);
    // The channel is disconnecting.

  private:
    Consumer (Latency_Supplier* impl);
    friend class Latency_Supplier;

  private:
    Latency_Supplier* impl_;
  };

  Latency_Supplier (const u_int total_messages,
		    CORBA::Long supplier_id,
                    const int timestamp = 0);
  // Construction.  Requires the total number of messages to be
  // sent.  If the timestamp flag is enabled, then events are
  // timestamped, e.g., for use in measuring jitter.

  ~Latency_Supplier (void);
  
  int open_supplier (RtecEventChannelAdmin::EventChannel_ptr event_channel,
		     const char *name, int master);
  // Registers with the name server under the given <name>.  Also
  // connects to the Event Channel as a supplier of notifications and
  // shutdown messages.  If <master> != 0, then the supplier will
  // destroy the channel upon shutting down. Returns 0 on success, -1
  // on failure.

  void disconnect_push_supplier (CORBA::Environment &);
  // The channel is disconnecting.

  void disconnect_push_consumer (CORBA::Environment &);
  // The channel is disconnecting.

  void push (const RtecEventComm::EventSet &events,
	     CORBA::Environment &);
  // Takes a timestamp and then pushes event_ to all consumers, either
  // directly, or via a channel.

  int start_generating_events (void);
  // Called when the supplier should start generating events.
  // Registers with the Event Channel to receive timeouts every .25
  // seconds.  Will generate some number of events and then send a
  // shutdown message.  Returns 0 on success, -1 on failure.

  void entry_point (const char *);
  const char *entry_point () const;

  void print_stats () /* const */;
  // Print timing statistics.

protected:

  void shutdown (void);
  // Disconnect from the Event Service.

  // = Event Channel adminstration references.
  RtecEventChannelAdmin::EventChannel_var channel_admin_;
  RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin_;
  RtecEventChannelAdmin::ProxyPushConsumer_var consumers_;
  RtecEventChannelAdmin::SupplierAdmin_var supplier_admin_;
  RtecEventChannelAdmin::ProxyPushSupplier_var suppliers_;

private:
  RtecScheduler::handle_t rt_info_;

  u_int total_messages_;
  // How many events to push before ending the test.

  CORBA::Long supplier_id_;
  // Our supplier ID.

  int timestamp_;
  // Flag indicating whether or not to timestamp outgoing events.

  u_int total_sent_;
  // How many events we've pushed.

  ACE_Time_Value test_start_time_;
  ACE_Time_Value test_stop_time_;
  // Start/stop times, marking the time period when events are
  // sent to consumers.

  int master_;

  ACE_CString entry_point_;

  Supplier* supplier_;
  Consumer* consumer_;
};

void Latency_Consumer::entry_point(const char* s)
{
  entry_point_ = s;
}

const char* Latency_Consumer::entry_point (void) const
{
  return entry_point_.fast_rep ();
}

void Latency_Supplier::entry_point(const char* s)
{
  entry_point_ = s;
}

const char* Latency_Supplier::entry_point (void) const
{
  return entry_point_.fast_rep ();
}

#endif /* LATENCY_H */