summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/CosEvent/lib/Counting_Consumer.h
blob: 39f095099e04f4a58c25013dc9d9192ab9dc3c3d (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
/* -*- C++ -*- */
//=============================================================================
/**
 *  @file   Counting_Consumer.h
 *
 *  $Id$
 *
 *  @author Carlos O'Ryan (coryan@cs.wustl.edu)
 */
//=============================================================================


#ifndef CEC_COUNTING_CONSUMER_H
#define CEC_COUNTING_CONSUMER_H

#include "cectest_export.h"

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

#include "orbsvcs/CosEventCommS.h"
#include "orbsvcs/CosEventChannelAdminC.h"
#include "ace/Task.h"

/**
 * @class CEC_Counting_Consumer
 *
 * @brief Simple consumer object to implement EC tests.
 *
 * This is a simple consumer that counts the events it receives.
 */
class CEC_Test_Export CEC_Counting_Consumer : public POA_CosEventComm::PushConsumer
{
public:
  /// Constructor
  CEC_Counting_Consumer (const char* name);

  /// Simple connect/disconnect methods..
  void connect (CosEventChannelAdmin::ConsumerAdmin_ptr consumer_admin);
  void disconnect (void);

  /// Print out an error message if the event count is too far from the
  /// expected count.
  void dump_results (int expected_count, int tolerance);

  // = The CosEventComm::PushConsumer methods

  /// The skeleton methods.
  virtual void push (const CORBA::Any& events);
  virtual void disconnect_push_consumer (void);

  /// Keep track of the number of events received.
  CORBA::ULong event_count;

  /// Keep track of the number of disconnect calls received.
  CORBA::ULong disconnect_count;

protected:
  /// The proxy
  CosEventChannelAdmin::ProxyPushSupplier_var supplier_proxy_;

  /// The name
  const char* name_;
};

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

/**
 * @class CEC_Pull_Counting_Consumer
 *
 * @brief Simple consumer object to implement EC tests.
 *
 * This is a simple consumer that counts the events it receives.
 */
class CEC_Test_Export CEC_Pull_Counting_Consumer : public POA_CosEventComm::PullConsumer
{
public:
  /// Constructor
  CEC_Pull_Counting_Consumer (const char* name);

  /// Simple connect/disconnect methods..
  void connect (CosEventChannelAdmin::ConsumerAdmin_ptr consumer_admin);
  void disconnect (void);

  /// Print out an error message if the event count is too far from the
  /// expected count.
  void dump_results (int expected_count, int tolerance);

  CORBA::Any *pull (void);
  CORBA::Any *try_pull (CORBA::Boolean_out has_event);

  // = The CosEventComm::PullConsumer methods
  /// The skeleton methods.
  virtual void disconnect_pull_consumer (void);

  /// Keep track of the number of events received.
  CORBA::ULong event_count;

  /// Keep track of the number of disconnect calls received.
  CORBA::ULong disconnect_count;

protected:
  /// The proxy
  CosEventChannelAdmin::ProxyPullSupplier_var supplier_proxy_;

  /// The name
  const char* name_;
};

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

class CEC_Test_Export CEC_Counting_Consumer_Task : public ACE_Task_Base
{
public:
  /// Create the task...
  CEC_Counting_Consumer_Task (CEC_Pull_Counting_Consumer *consumer,
                              int milliseconds = 0);

  // = Check the ACE_Task_Base documentation.
  int svc (void);

  void stop (void);
  CORBA::ULong pull_count (void);

  /// Run a single iteration of the test
  void run (void);

private:
  /// The consumer we are turning into an active object
  CEC_Pull_Counting_Consumer *consumer_;

  /// Set to 1 when the test must stop
  int stop_flag_;

  /// Count the number of pull() calls
  CORBA::ULong pull_count_;

  /// If not zero then pause for <milliseconds> before sending each
  /// event.
  int milliseconds_;

  TAO_SYNCH_MUTEX lock_;
};

#endif /* ECT_CONSUMER_H */