Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / orbsvcs / tests / Event / lib / Supplier.h
blobc7fbce015ee076c2fab3ac8bd3986b0a0033d102
1 /* -*- C++ -*- */
2 //=============================================================================
3 /**
4 * @file Supplier.h
6 * @author Carlos O'Ryan (coryan@cs.wustl.edu)
7 */
8 //=============================================================================
11 #ifndef EC_SUPPLIER_H
12 #define EC_SUPPLIER_H
14 #include "Driver.h"
16 #if !defined (ACE_LACKS_PRAGMA_ONCE)
17 # pragma once
18 #endif /* ACE_LACKS_PRAGMA_ONCE */
20 #include "orbsvcs/RtecEventCommS.h"
21 #include "orbsvcs/RtecEventChannelAdminC.h"
22 #include "ace/Task.h"
23 #include "ace/OS_NS_time.h"
24 #include "ace/High_Res_Timer.h"
26 /**
27 * @class EC_Supplier
29 * @brief Simple supplier object to implement EC tests.
31 * This class is a supplier of events.
32 * The class is just a helper to simplify common tasks in EC
33 * tests, such as subscribing for a range of events, disconnecting
34 * from the EC, informing the driver of shutdown messages, etc.
35 * There are several ways to connect and disconnect this class,
36 * and it is up to the driver program to use the right one.
37 * The driver can request that to this class to send a new event,
38 * a new shutdown event or to become "active" and send a number of
39 * events at a certain rate.
41 class EC_Test_Export EC_Supplier : public POA_RtecEventComm::PushSupplier
43 public:
44 /**
45 * Constructor, specifies the types of events to send.
46 * Notice that the user can connect to the EC using other
47 * publications, this is useful for filtering tests.
49 EC_Supplier (EC_Driver *driver,
50 void* supplier_cookie);
52 /// The types of the event is chosen by the driver, based on the
53 /// cookie and the <event_number>
54 void send_event (int event_number);
56 /// Send <event> to the EC.
57 void send_event (const RtecEventComm::EventSet& event);
59 /// Set the event type and source in <event>
60 void send_event (int event_number,
61 const RtecEventComm::Event& event);
63 /// Send a shutdown event.
64 void send_shutdown ();
66 /// Connect using a <supplier_admin> and publications (<qos>)
67 /// computed by the user
68 virtual void connect (
69 RtecEventChannelAdmin::SupplierAdmin_ptr supplier_admin,
70 const RtecEventChannelAdmin::SupplierQOS& qos,
71 int shutdown_event_type);
73 /// Connect using the current consumer_proxy (useful for reconnect test)
74 virtual void connect (
75 const RtecEventChannelAdmin::SupplierQOS& qos,
76 int shutdown_event_type);
78 /// Disconnect from the EC, also deactivates the object
79 void disconnect ();
81 /// Disconnect from the EC, also deactivates the object
82 void shutdown ();
84 /// Dump the results...
85 virtual void dump_results (
86 const ACE_TCHAR* name,
87 ACE_High_Res_Timer::global_scale_factor_type global_scale_factor);
89 /// Add our statistics to <stats>
90 void accumulate (ACE_Throughput_Stats& stats) const;
92 /// Return an event type to push....
93 void event_type (int event_number,
94 RtecEventComm::Event& event);
96 // = The PushSupplier methods
97 virtual void disconnect_push_supplier ();
99 private:
100 /// Class we forward to.
101 EC_Driver *driver_;
103 /// Magic cookie provided by the supplier to identify ourselves
104 void* cookie_;
106 /// Protect the internal state
107 TAO_SYNCH_MUTEX lock_;
109 /// Count the number of push() calls
110 int push_count_;
112 /// We talk to the EC (as a supplier) using this proxy.
113 RtecEventChannelAdmin::ProxyPushConsumer_var consumer_proxy_;
115 /// The time for the first event sent
116 ACE_hrtime_t throughput_start_;
118 /// Measure the elapsed time spent while sending the events.
119 ACE_Throughput_Stats throughput_;
121 int burst_count_;
122 int burst_size_;
123 int payload_size_;
124 int burst_pause_;
126 /// The test data.
127 int shutdown_event_type_;
129 /// The publications, used to select the events.
130 RtecEventChannelAdmin::SupplierQOS qos_;
132 /// Is the supplier active in the POA?
133 int is_active_;
135 /// Cache the object reference to speed up connect/disconnect calls
136 RtecEventComm::PushSupplier_var myself_;
139 // ****************************************************************
142 * @class EC_Supplier_Task
144 class EC_Supplier_Task : public ACE_Task_Base
146 public:
147 /// Constructor
148 EC_Supplier_Task (EC_Supplier* supplier,
149 EC_Driver* driver,
150 void* cookie,
151 int burst_count,
152 int burst_size,
153 int burst_pause,
154 int payload_size,
155 int shutdown_event_type,
156 ACE_Thread_Manager* thr_mgr = 0);
158 /// The svc call
159 virtual int svc ();
161 private:
162 /// The supplier
163 EC_Supplier* supplier_;
165 /// The driver program
166 EC_Driver* driver_;
168 /// The magic cookie assigned to the supplier
169 void* cookie_;
171 /// Number of events "bursts"
172 int burst_count_;
174 /// The number of events in a "burst", i.e. between two calls to
175 /// sleep.
176 int burst_size_;
178 /// The sleep time (in usecs) between each burst
179 int burst_pause_;
181 /// The size of the payload in each event.
182 int payload_size_;
184 /// Define the shutdown event, invoked at the end of the loop.
185 int shutdown_event_type_;
188 #endif /* EC_SUPPLIER_H */