summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/EC_Basic/EC_Basic.h
blob: 5ffa770d18ec44943b7cec4c2c24d7b75f9a45d2 (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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/* -*- C++ -*- */
// $Id$
//
// ============================================================================
//
// = TITLE
//   A simple test for the Event Channel.
//
// = DESCRIPTION
//   This test exercises the basic features of the EC, such as
//   filtering, correlation, timeouts, etc.
//   The test creates a colocated EC, some suppliers, some consumers
//   and exercises each feature, one at a time.
//
// ============================================================================

#ifndef EC_BASIC_H
#define EC_BASIC_H

#include "ace/SString.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/High_Res_Timer.h"
#include "orbsvcs/RtecEventChannelAdminC.h"
#include "orbsvcs/RtecEventCommS.h"
#include "orbsvcs/Channel_Clients_T.h"

class ECB_Driver
{
  //
  // = TITLE
  //   A class to control the tests.
  //
  // = DESCRIPTION
  //   This class creates multiple tests and runs them in sequence,
  //   providing proper environment for each one (the event channel,
  //   the ORB configuration, etc.
  //
public:
  ECB_Driver (void);

  int run (int argc, char* argv[]);
  // Run the test.

private:
  int shutdown (CORBA::Environment&);
  // Called when the main thread is about to shutdown.

  int parse_args (int argc, char* argv[]);
  // parse the command line arguments

  void dump_results (void);
  // Dump the results to the standard output.

private:
  const char* pid_filename_;
  // The name of a file where the process stores its pid

  ACE_hrtime_t test_start_;
  ACE_hrtime_t test_stop_;
  // Measure the test elapsed time as well as mark the beginning of
  // the frames.

  CORBA::ORB_var orb_;
  // The ORB, so we can shut it down.
};

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

class ECB_Test
{
  // = TITLE
  //   The base class for all the tests.
  //
  // = DESCRIPTION
  //   All the tests inherit from this class, it is used by the
  //   consumer and suppliers as callbacks.
  //
public:
  virtual ~ECB_Test (void);
  // Destructor

  virtual void push (int consumer_number,
                     const RtecEventComm::EventSet& events,
                     CORBA::Environment &_env) = 0;
  // The callback from the Consumer....
};

class ECB_Consumer : public POA_RtecEventComm::PushConsumer
{
public:
  // = TITLE
  //   The consumers for all the tests.
  //
  // = DESCRIPTION
  //   To simplify each test implementation a generic consumer class
  //   is provided.
  //   It dispatches the events back to a Base_Test.
  //
  ECB_Consumer (ECB_Test* test,
                int consumer_id);

  void open (const char* name,
             RtecEventChannelAdmin::EventChannel_ptr event_channel,
             RtecScheduler::Scheduler_ptr scheduler,
             CORBA::Environment& _env);
  // This method connects the consumer to the EC.

  void close (CORBA::Environment &_env);
  // Disconnect from the EC.

  RtecScheduler::handle_t rt_info (void) const;
  // The RT_Info for this object

  void connect (const RtecEventChannelAdmin::ConsumerQOS& qos,
                CORBA::Environment &_env);
  void disconnect (CORBA::Environment &_env);
  // Disconnect from the supplier, but do not forget about it or close
  // it.

  // = The POA_RtecEventComm::PushComsumer methods.
  virtual void push (const RtecEventComm::EventSet& events,
                     CORBA::Environment &_env);
  virtual void disconnect_push_consumer (CORBA::Environment &);

private:
  ECB_Test* test_;
  // To callback.

  int consumer_id_;
  // So we can give our identity back to the test.

  RtecScheduler::handle_t rt_info_;
  // The handle for our RT_Info description.

  RtecEventChannelAdmin::ProxyPushSupplier_var supplier_proxy_;
  // We talk to the EC using this proxy.

  RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin_;
  // We talk to the EC using this proxy.
};

class ECB_Supplier : public POA_RtecEventComm::PushSupplier
{
public:
  // = TITLE
  //   Implement one of the consumers in this test.
  //
  ECB_Supplier (ECB_Test* test,
                int supplier_id);
  // We generate an id based on the name....

  void open (const char* name,
             RtecEventChannelAdmin::EventChannel_ptr event_channel,
             RtecScheduler::Scheduler_ptr scheduler,
             CORBA::Environment& _env);
  // This method connects the supplier to the EC.

  void close (CORBA::Environment &_env);
  // Disconnect from the EC.

  RtecScheduler::handle_t rt_info (void) const;
  // The RT_Info for this object

  void connect (const RtecEventChannelAdmin::SupplierQOS& qos,
                CORBA::Environment &_env);
  void disconnect (CORBA::Environment &_env);
  // Disconnect from the EC, but do not forget about it or close
  // it.

  void send_event (RtecEventComm::EventSet& events,
                   CORBA::Environment &_env);
  // Send one event, the supplier provides the SourceID

  // = The POA_RtecEventComm::PushSupplier methods.
  virtual void disconnect_push_supplier (CORBA::Environment &);

private:
  ECB_Test* test_;
  // To callback.

  int supplier_id_;
  // This is NOT the supplier ID for the EC, just a number for the

  RtecScheduler::handle_t rt_info_;
  // The handle for our RT_Info description.

  RtecEventChannelAdmin::ProxyPushConsumer_var consumer_proxy_;
  // We talk to the EC using this proxy.

  RtecEventChannelAdmin::SupplierAdmin_var supplier_admin_;
  // We talk to the EC using this proxy.
};

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

// @@ TODO WE may need to split each test to its own file, but only
// once the number of tests justifies that change.

class ECB_SupplierID_Test : public ECB_Test
{
  //
  // = TITLE
  //   Verifies that multiple suppliers can have the same ID.
  //
  // = DESCRIPTION
  //   This class creates two consumers and two suppliers, the
  //   suppliers connect with the same ID, but send out different
  //   events. The consumers subscribe by supplier ID.
  //
  //   The test executes several phases (see the enum below).
  //
  // = TODO
  //   The test could be more flexible, but functionality is more
  //   important than flexiblitity.
  //
public:
  ECB_SupplierID_Test (void);

  enum
  {
    PHASE_0, // Verifies filtering for two suppliers with the same ID
    PHASE_1, // Disconnect one of the suppliers
    PHASE_2, // Reconnect the supplier
    PHASE_3, // Disconnect a consumer
    PHASE_4, // Reconnect the consumer
    PHASE_5, // Disconnect both consumers
    PHASE_6, // Reconnect both consumers
    PHASE_7, // Disconnect both suppliers and reconnect them
    PHASE_END // To check that no events are received after the test ends.
  };

  enum
  {
    EVENTS_SENT = 10, // How many events we send on each test
    SUPPLIER_ID = 1
  };

  void run (CORBA::ORB_ptr orb,
            RtecEventChannelAdmin::EventChannel_ptr event_channel,
            RtecScheduler::Scheduler_ptr scheduler,
            CORBA::Environment& _env);
  // Start the test.

  int dump_results (void);
  // Print out the results, returns -1 if an error was detected.

  virtual void push (int consumer_id,
                     const RtecEventComm::EventSet& events,
                     CORBA::Environment &_env);
  // The callback from the Consumer....


private:
  ECB_Consumer consumer0_;
  ECB_Consumer consumer1_;
  // The consumers...

  ECB_Supplier supplier0_;
  ECB_Supplier supplier1_;
  // The suppliers...

  CORBA::ULong event_count_[ECB_SupplierID_Test::PHASE_END + 1];
  // Count the correctly received events.

  CORBA::ULong error_count_[ECB_SupplierID_Test::PHASE_END + 1];
  // Store the number of errors for each phase.

  int phase_;
  // Keep track of the test we are running...
};

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

class ECB_Correlation_Test : public ECB_Test
{
  //
  // = TITLE
  //   Verifies that correlation works.
  //
  // = DESCRIPTION
  //   This class creates one consumers and two suppliers, the
  //   consumer subscribe for several event correlations.
  //   The correlations are satisfied in several different ways by
  //   both suppliers (see below).by:
  //
  // = TODO
  //
public:
  ECB_Correlation_Test (void);

  enum
  {
    PHASE_0, // One supplier sends A the other sends B
    PHASE_1, // Both suppliers send event A and B (in a single event)
    PHASE_2, // Both suppliers alternate A and B
    PHASE_3, // One supplier sends A the other sends A and B (in a
             // single event)
    PHASE_4, // One supplier sends A the other alternates A and B
    PHASE_5, // Both suppliers send A
    PHASE_END // To check that no events are received after the test ends.
  };

  enum
  {
    EVENTS_SENT = 10, // How many events we send on each test
    EVENT_A = 100, // The event "A"
    EVENT_B = 200, // The event "B"
    SUPPLIER_ID_0 = 100, // The supplier ID for supplier0
    SUPPLIER_ID_1 = 200  // The supplier ID for supplier1
  };

  void run (CORBA::ORB_ptr orb,
            RtecEventChannelAdmin::EventChannel_ptr event_channel,
            RtecScheduler::Scheduler_ptr scheduler,
            CORBA::Environment& _env);
  // Start the test.

  int dump_results (void);
  // Print out the results, returns -1 if an error was detected.

  virtual void push (int consumer_id,
                     const RtecEventComm::EventSet& events,
                     CORBA::Environment &_env);
  // The callback from the Consumer....

private:
  ECB_Consumer consumer_;
  // The consumer...

  ECB_Supplier supplier0_;
  ECB_Supplier supplier1_;
  // The suppliers...

  CORBA::ULong event_count_[ECB_Correlation_Test::PHASE_END + 1];
  // Count the correctly received events.

  CORBA::ULong error_count_[ECB_Correlation_Test::PHASE_END + 1];
  // Store the number of errors for each phase.

  int phase_;
  // Keep track of the test we are running...
};

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

#if defined (__ACE_INLINE__)
#include "EC_Basic.i"
#endif /* __ACE_INLINE__ */

#endif /* EC_BASIC_H */