summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Event/lib/Supplier.h
blob: b2d5dcc1bfad5cd65b12996ca3cd44804cbbc078 (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
/* -*- C++ -*- */
// $Id$
//
// ============================================================================
//
// = LIBRARY
//   ORBSVCS Real-time Event Channel testsuite
//
// = FILENAME
//   Supplier
//
// = AUTHOR
//   Carlos O'Ryan (coryan@cs.wustl.edu)
//
// ============================================================================

#ifndef EC_SUPPLIER_H
#define EC_SUPPLIER_H

#include "Driver.h"

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

#include "orbsvcs/RtecEventCommS.h"
#include "orbsvcs/RtecEventChannelAdminC.h"
#include "ace/Task.h"

class EC_Test_Export EC_Supplier : public POA_RtecEventComm::PushSupplier
{
  //
  // = TITLE
  //   Simple supplier object to implement EC tests.
  //
  // = DESCRIPTION
  //   This class is a supplier of events.
  //   The class is just a helper to simplify common tasks in EC
  //   tests, such as subscribing for a range of events, disconnecting
  //   from the EC, informing the driver of shutdown messages, etc.
  //
  //   There are several ways to connect and disconnect this class,
  //   and it is up to the driver program to use the right one.
  //
  //   The driver can request that to this class to send a new event,
  //   a new shutdown event or to become "active" and send a number of
  //   events at a certain rate.
  //
public:
  EC_Supplier (EC_Driver *driver,
               void* supplier_cookie);
  // Constructor, specifies the types of events to send.
  // Notice that the user can connect to the EC using other
  // publications, this is useful for filtering tests.

  void send_event (int event_number,
                   CORBA::Environment& ACE_TRY_ENV);
  // The types of the event is chosen by the driver, based on the
  // cookie and the <event_number>

  void send_event (const RtecEventComm::EventSet& event,
                   CORBA::Environment& ACE_TRY_ENV);
  // Send <event> to the EC.

  void send_event (int event_number,
                   const RtecEventComm::Event& event);
  // Set the event type and source in <event>

  void send_shutdown (CORBA::Environment& ACE_TRY_ENV);
  // Send a shutdown event.

  virtual void connect (
        RtecEventChannelAdmin::SupplierAdmin_ptr supplier_admin,
        const RtecEventChannelAdmin::SupplierQOS& qos,
        int shutdown_event_type,
        CORBA::Environment& ACE_TRY_ENV);
  // Connect using a <supplier_admin> and publications (<qos>)
  // computed by the user

  virtual void connect (
        const RtecEventChannelAdmin::SupplierQOS& qos,
        int shutdown_event_type,
        CORBA::Environment& ACE_TRY_ENV);
  // Connect using the current consumer_proxy (useful for reconnect test)

  void disconnect (CORBA::Environment &ACE_TRY_ENV);
  // Disconnect from the EC, also deactivates the object

  void shutdown (CORBA::Environment &ACE_TRY_ENV);
  // Disconnect from the EC, also deactivates the object

  virtual void dump_results (const char* name);
  // Dump the results...

  void accumulate (EC_Driver::Throughput_Stats& stats) const;
  // Add our statistics to <stats>

  void event_type (int event_number,
                   RtecEventComm::Event& event);
  // Return an event type to push....

  // = The PushSupplier methods
  virtual void disconnect_push_supplier (CORBA::Environment &)
    ACE_THROW_SPEC ((CORBA::SystemException));

private:
  EC_Driver *driver_;
  // Class we forward to.

  void* cookie_;
  // Magic cookie provided by the supplier to identify ourselves

  ACE_SYNCH_MUTEX lock_;
  // Protect the internal state

  int push_count_;
  // Count the number of push() calls

  RtecEventChannelAdmin::ProxyPushConsumer_var consumer_proxy_;
  // We talk to the EC (as a supplier) using this proxy.

  EC_Driver::Throughput_Stats throughput_;
  // Measure the elapsed time spent while sending the events.

  int burst_count_;
  int burst_size_;
  int payload_size_;
  int burst_pause_;

  int shutdown_event_type_;
  // The test data.

  RtecEventChannelAdmin::SupplierQOS qos_;
  // The publications, used to select the events.

  int is_active_;
  // Is the supplier active in the POA?
};

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

class EC_Supplier_Task : public ACE_Task_Base
{
  //
public:
  EC_Supplier_Task (EC_Supplier* supplier,
                    EC_Driver* driver,
                    void* cookie,
                    int burst_count,
                    int burst_size,
                    int burst_pause,
                    int payload_size,
                    int shutdown_event_type,
                    ACE_Thread_Manager* thr_mgr = 0);
  // Constructor

  virtual int svc (void);
  // The svc call

private:
  EC_Supplier* supplier_;
  // The supplier

  EC_Driver* driver_;
  // The driver program

  void* cookie_;
  // The magic cookie assigned to the supplier

  int burst_count_;
  // Number of events "bursts"

  int burst_size_;
  // The number of events in a "burst", i.e. between two calls to
  // sleep.

  int burst_pause_;
  // The sleep time (in usecs) between each burst

  int payload_size_;
  // The size of the payload in each event.

  int shutdown_event_type_;
  // Define the shutdown event, invoked at the end of the loop.
};

#endif /* EC_SUPPLIER_H */