Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Event / lib / Driver.h
bloba4594cbf15948471bc92af34cedcec9e5a923838
1 /* -*- C++ -*- */
2 //=============================================================================
3 /**
4 * @file Driver.h
6 * @author Carlos O'Ryan (coryan@cs.wustl.edu)
7 */
8 //=============================================================================
11 #ifndef EC_DRIVER_H
12 #define EC_DRIVER_H
14 #include "ectest_export.h"
16 #if !defined (ACE_LACKS_PRAGMA_ONCE)
17 # pragma once
18 #endif /* ACE_LACKS_PRAGMA_ONCE */
20 #include "orbsvcs/RtecEventChannelAdminS.h"
22 #include "ace/Stats.h"
23 #include "ace/Task.h"
24 #include "ace/Throughput_Stats.h"
26 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
27 class TAO_EC_Event_Channel_Attributes;
28 TAO_END_VERSIONED_NAMESPACE_DECL
30 class TAO_Module_Factory;
31 class EC_Consumer;
32 class EC_Supplier;
34 #define EC_DISABLE_REMOTE_EC
35 #define EC_DISABLE_OLD_EC
37 #if !defined(EC_DISABLE_REMOTE_EC)
38 #include "orbsvcs/CosNamingC.h"
39 #endif
41 /**
42 * @class EC_Driver
44 * @brief Defines the interface of a test driver
46 * Abstract base class for the test driver, this let us implement a
47 * collocated and a non-collocated test, and to write generic
48 * consumers and suppliers that can call back the driver.
50 class EC_Test_Export EC_Driver
52 public:
53 /// Constructor
54 EC_Driver (void);
56 /// Destructor
57 virtual ~EC_Driver (void);
59 /// Flag to indicate in the test should be verbose.
60 int verbose (void) const;
62 /// Execute the test.
63 virtual int run (int argc, ACE_TCHAR* argv[]);
65 /// The initialization section
66 virtual void run_init (int& argc, ACE_TCHAR* argv[]);
68 /// The cleanup section
69 virtual void run_cleanup (void);
71 /// Initialize the ORB and obtain the RootPOA object
72 virtual void initialize_orb_and_poa (int& argc, ACE_TCHAR* argv[]);
74 /// Parse the common command-line arguments for all tests
75 virtual int parse_args (int& argc, ACE_TCHAR* argv[]);
77 /// Print the usage method
78 virtual void print_usage (void);
80 /// Print out the arguments
81 virtual void print_args (void) const;
83 /// Run the test in the real-time class, return -1 on error.
84 virtual int move_to_rt_class (void);
86 /// Construct the EC and its helper objects, also activates the EC in
87 /// the RootPOA.
88 virtual void initialize_ec_impl (void);
90 /// By default connect the consumers and then the suppliers, other
91 /// orders should work too.
92 virtual void connect_clients (void);
94 /// By default disconnect the suppliers and then the consumers, other
95 /// orders should work too.
96 virtual void disconnect_clients (void);
98 /// By default deactivate the suppliers and then the consumers, other
99 /// orders should work too.
100 virtual void shutdown_clients (void);
102 /// Connect all the consumers, by default it lets each consumer
103 /// connect itself.
104 virtual void connect_consumers (void);
106 /// Connect consumer number <i> using the consumer_admin provided.
107 virtual void connect_consumer (
108 RtecEventChannelAdmin::ConsumerAdmin_ptr consumer_admin,
109 int i);
111 /// Build the QoS requirements for consumer <i>
112 virtual void build_consumer_qos (
113 int i,
114 RtecEventChannelAdmin::ConsumerQOS& qos,
115 int& shutdown_event_type);
117 /// Connect all the suppliers, by default it lets each supplier
118 /// connect itself.
119 virtual void connect_suppliers (void);
121 /// Connect supplier number <i> using the supplier_admin provided.
122 virtual void connect_supplier (
123 RtecEventChannelAdmin::SupplierAdmin_ptr supplier_admin,
124 int i);
126 /// Build the QoS requirements for supplier <i>
127 virtual void build_supplier_qos (
128 int i,
129 RtecEventChannelAdmin::SupplierQOS& qos,
130 int& shutdown_event_type);
132 /// Execute the test, by default simply call activate_suppliers()
133 virtual void execute_test (void);
136 * Dump the results, i.e. invoke dump_results on all the suppliers
137 * and consumers, collect the latency and throughput results for
138 * each and print the totals too.
140 virtual void dump_results (void);
142 /// Disconnect all the consumers.
143 virtual void disconnect_consumers (void);
145 /// Disconnect all the suppliers.
146 virtual void disconnect_suppliers (void);
148 /// Deactivate all the consumers.
149 virtual void shutdown_consumers (void);
151 /// Deactivate all the suppliers.
152 virtual void shutdown_suppliers (void);
154 /// Call EC->destroy
155 virtual void destroy_ec (void);
157 /// De-activate the EC (and its helper classes).
158 virtual void deactivate_ec (void);
160 /// Cleanup the resources
161 virtual void cleanup_ec (void);
162 virtual void cleanup_tasks (void);
163 virtual void cleanup_consumers (void);
164 virtual void cleanup_suppliers (void);
166 /// Allow modifications of the default EC attributes
167 virtual void modify_attributes (TAO_EC_Event_Channel_Attributes& attr);
169 /// Returns the index of the consumer for @a cookie
170 virtual int decode_consumer_cookie (void* cookie) const;
172 /// Returns the index of the supplier for @a cookie
173 virtual int decode_supplier_cookie (void* cookie) const;
175 /// One of the consumers in the test has received an event
176 virtual void consumer_push (void* consumer_cookie,
177 const RtecEventComm::EventSet& event);
179 /// One of the consumers has received a shutdown event
180 virtual void consumer_shutdown (void* consumer_cookie);
182 /// One of the consumers in the test has been disconnected from the EC
183 virtual void consumer_disconnect (void* consumer_cookie);
185 /// One of the suppliers in the test has been disconnected from the EC
186 virtual void supplier_disconnect (void* supplier_cookie);
188 #if !defined(EC_DISABLE_REMOTE_EC)
189 /// Obtain the EC from the Naming service
190 virtual void obtain_remote_ec (void);
192 virtual CosNaming::NamingContext_ptr
193 get_naming_context (void);
194 #endif
196 /// Initialize the EC using the new implementation
197 virtual void initialize_new_ec (void);
199 /// Allocate the suppliers and the consumers
200 virtual int allocate_consumers (void);
201 virtual int allocate_suppliers (void);
203 /// Allocate one consumer or supplier
204 virtual EC_Consumer* allocate_consumer (int i);
205 virtual EC_Supplier* allocate_supplier (int i);
207 /// Allocate one task for supplier number <i>
208 virtual int allocate_tasks (void);
209 virtual ACE_Task_Base* allocate_task (int i);
211 /// Activate all the tasks, by default runs each supplier on its
212 /// own thread.
213 virtual void activate_tasks (void);
215 protected:
216 /// The ORB
217 CORBA::ORB_var orb_;
219 /// The Root POA
220 PortableServer::POA_var root_poa_;
222 /// The number of consumers
223 int n_consumers_;
225 /// The consumers
226 EC_Consumer** consumers_;
228 /// The number of suppliers
229 int n_suppliers_;
231 /// The suppliers
232 EC_Supplier** suppliers_;
234 /// The tasks for each supplier
235 ACE_Task_Base** tasks_;
237 /// How many bursts we will send from each supplier.
238 int burst_count_;
240 /// The number of events
241 int burst_size_;
243 /// The size of the payload on each event.
244 int payload_size_;
246 /// The time between each event burst, in microseconds.
247 int burst_pause_;
250 * The consumers subscribe to different sets of events, as follows:
252 * Consumer0: [start , start + count)
253 * Consumer1: [start + 1*shift, start + 1*shift + count)
254 * Consumer2: [start + 2*shift, start + 2*shift + count)
255 * .....
256 * ....
258 * Some sub-tests may choose other configurations, but this is good
259 * for many cases.
261 int consumer_type_start_;
262 int consumer_type_count_;
263 int consumer_type_shift_;
266 * The suppliers generate different sets of events, as follows:
268 * Supplier0: [start , start + count)
269 * Supplier1: [start + 1*shift, start + 1*shift + count)
270 * Supplier2: [start + 2*shift, start + 2*shift + count)
271 * .....
272 * ....
274 * Some sub-tests may choose other configurations, but this is good
275 * for many cases.
277 int supplier_type_start_;
278 int supplier_type_count_;
279 int supplier_type_shift_;
281 /// The name of a file where the process stores its pid
282 const ACE_TCHAR* pid_file_name_;
284 /// Verbosity flag
285 int verbose_;
288 * The flags used to create threads, by default we attempt:
290 * THR_SCHED_FIFO|THR_BOUND|THR_NEW_LWP
292 * but if we don't have enough privileges we fall back to
294 * THR_NEW_LWP
297 int thr_create_flags_;
299 /// Use a remote event channel. If this flag is enabled it
300 /// superseedes any options for the event channel implementation.
301 int use_remote_ec_;
303 /// The name of the remote event service
304 const ACE_TCHAR *event_service_name_;
306 /// The event channel implementation
307 POA_RtecEventChannelAdmin::EventChannel *ec_impl_;
309 /// The event channel object reference
310 RtecEventChannelAdmin::EventChannel_var event_channel_;
314 #if defined (__ACE_INLINE__)
315 #include "Driver.inl"
316 #endif /* __ACE_INLINE__ */
318 #endif /* ECT_CONSUMER_H */