summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/EC_Basic/EC_Basic.h
blob: fe21abcc1ae3afee6fcdc18bb9ec2d8b743e6e0e (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
/* -*- 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.
//
// ============================================================================

#if !defined (EC_BASIC_H)
#define EC_BASIC_H

#include "ace/SString.h"
#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.
};

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

// @@ 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
{
  //
  // = 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.

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

  class Consumer : public POA_RtecEventComm::PushConsumer
  {
  public:
    // = TITLE
    //   Implement one of the consumers in this test.
    //
    Consumer (ECB_SupplierID_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.

    void connect (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_SupplierID_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 Supplier : public POA_RtecEventComm::PushSupplier
  {
  public:
    // = TITLE
    //   Implement one of the consumers in this test.
    //
    Supplier (ECB_SupplierID_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.

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

    void send_event (CORBA::Environment &_env);
    // Send one event.

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

  private:
    ECB_SupplierID_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.
  };
  
private:
  Consumer consumer0_;
  Consumer consumer1_;
  // The consumers...

  Supplier supplier0_;
  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...
};

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

#endif /* EC_BASIC_H */