Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Event / lib / Consumer.h
blob31ba5063eba523215a3e788961fba6983c909cc9
1 /* -*- C++ -*- */
2 //=============================================================================
3 /**
4 * @file Consumer.h
6 * @author Carlos O'Ryan (coryan@cs.wustl.edu)
7 */
8 //=============================================================================
11 #ifndef EC_CONSUMER_H
12 #define EC_CONSUMER_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/OS_NS_time.h"
23 #include "ace/High_Res_Timer.h"
25 /**
26 * @class EC_Consumer
28 * @brief Simple consumer object to implement EC tests.
30 * This class is a consumer of events.
31 * The class is just a helper to simplify common tasks in EC
32 * tests, such as subscribing for a range of events, disconnecting
33 * from the EC, informing the driver of shutdown messages, etc.
34 * There are several ways to connect and disconnect this class,
35 * and it is up to the driver program to use the right one.
37 class EC_Test_Export EC_Consumer : public POA_RtecEventComm::PushConsumer
39 public:
40 /// Constructor
41 EC_Consumer (EC_Driver* driver, void* cookie);
43 /// The driver program can build the QoS attributes and obtain the
44 /// ConsumerAdmin, we do the rest.
45 virtual void connect (
46 RtecEventChannelAdmin::ConsumerAdmin_ptr consumer_admin,
47 const RtecEventChannelAdmin::ConsumerQOS& qos,
48 int shutdown_event_type);
50 /**
51 * The driver program can build the QoS attributes and we use
52 * whatevet supplier_proxy we already have (useful for reconnection
53 * tests).
55 virtual void connect (
56 const RtecEventChannelAdmin::ConsumerQOS& qos,
57 int shutdown_event_type);
59 /// returns 0 if it is not connected
60 virtual int connected (void) const;
62 /// The application can invoke this method to disconnect from the EC
63 /// and deactivate this class.
64 void disconnect (void);
66 /// The application is shutting down, deactivate the consumer.
67 void shutdown (void);
69 /// Accumulate our statistics to the totals.
70 void accumulate (ACE_Throughput_Stats& throughput) const;
72 /// Printout the statistics
73 virtual void dump_results (
74 const ACE_TCHAR* name,
75 ACE_High_Res_Timer::global_scale_factor_type global_scale_factor);
77 // = The RtecEventComm::PushConsumer methods
79 /// The skeleton methods.
80 virtual void push (const RtecEventComm::EventSet& events);
81 virtual void disconnect_push_consumer (void);
83 private:
84 /// The main driver for the test.
85 EC_Driver* driver_;
87 /// A magic cookie passed by the driver that we pass back in our
88 /// callbacks.
89 void* cookie_;
91 /// We talk to the EC using this proxy.
92 RtecEventChannelAdmin::ProxyPushSupplier_var supplier_proxy_;
94 /// Protect internal state
95 TAO_SYNCH_MUTEX lock_;
97 /// The timestamp for the first message received
98 ACE_hrtime_t throughput_start_;
100 /// Used for reporting stats
101 ACE_Throughput_Stats throughput_;
103 /// The number of push() calls
104 int push_count_;
106 /// The type used to indicate shutdown
107 int shutdown_event_type_;
109 /// Is the consumer active in the POA?
110 int is_active_;
112 /// Cache the object reference to speed up connect/disconnect calls.
113 RtecEventComm::PushConsumer_var myself_;
116 #endif /* ECT_CONSUMER_H */