summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Notify/Ordering/Notify_Sequence_Push_Consumer.cpp
blob: dac3fe97703f8116d2ac08f74ba335a3d67bedc4 (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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// $Id$

#include "Notify_Sequence_Push_Consumer.h"
#include "orbsvcs/TimeBaseC.h"
#include "common.h"

Notify_Sequence_Push_Consumer::Notify_Sequence_Push_Consumer (
                                            const char* name,
                                            CORBA::Short policy,
                                            unsigned int low,
                                            unsigned int high,
                                            CORBA::Boolean& done)
 : name_ (name),
   order_policy_ (policy),
   low_ (low),
   high_ (high),
   count_ (0),
   done_ (done)
{
}


void
Notify_Sequence_Push_Consumer::connect (
                CosNotifyChannelAdmin::ConsumerAdmin_ptr consumer_admin
                TAO_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  CosNotifyComm::SequencePushConsumer_var objref =
    this->_this (TAO_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  CosNotifyChannelAdmin::ProxySupplier_var proxysupplier =
    consumer_admin->obtain_notification_push_supplier (
      CosNotifyChannelAdmin::SEQUENCE_EVENT,
      proxy_supplier_id_
      TAO_ENV_ARG_PARAMETER);
  ACE_CHECK;

  this->proxy_supplier_ =
    CosNotifyChannelAdmin::SequenceProxyPushSupplier::_narrow (
      proxysupplier.in () TAO_ENV_ARG_PARAMETER);
  ACE_CHECK;

  CosNotification::QoSProperties properties (3);
  properties.length (3);
  properties[0].name = CORBA::string_dup (CosNotification::MaximumBatchSize);
  properties[0].value <<= (CORBA::Long)5;
  properties[1].name = CORBA::string_dup (CosNotification::PacingInterval);
  properties[1].value <<= (TimeBase::TimeT)4;
  properties[2].name = CORBA::string_dup (CosNotification::OrderPolicy);
  properties[2].value <<= this->order_policy_;

  this->proxy_supplier_->set_qos (properties);
  this->proxy_supplier_->connect_sequence_push_consumer (objref.in ()
                                                         TAO_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // give ownership to POA
  this->_remove_ref ();
}


void
Notify_Sequence_Push_Consumer::push_structured_events (
                          const CosNotification::EventBatch& events
                          TAO_ENV_ARG_DECL_NOT_USED /*TAO_ENV_SINGLE_ARG_PARAMETER*/)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  static long previous = 0;
  static CORBA::Boolean first = 1;
  // Since the Notification Service begins to dispatch before all the
  // events are queued, the first 2 events are not in the "expected"
  // order.
  static const unsigned int expected_out_of_order = 2 * 4;

  if (this->count_ >= expected_out_of_order)
    {
      CORBA::ULong length = events.length ();

      ACE_DEBUG ((LM_DEBUG, "Received %u events:\n", length));

      for (CORBA::ULong e = 0; e < length; e++)
        {
          CORBA::ULong hlength = events[e].header.variable_header.length ();
          for (CORBA::ULong hi = 0; hi < hlength; hi++)
            {
              ACE_DEBUG ((LM_DEBUG,
                          "%s = %s\n",
                          (const char*)events[e].header.variable_header[hi].name,
                          Any_String (events[e].header.variable_header[hi].value)));
              if (this->order_policy_ == CosNotification::PriorityOrder)
                {
                  if (ACE_OS::strcmp (
                          events[e].header.variable_header[hi].name, "Priority") == 0)
                    {
                      CORBA::Short current;
                      events[e].header.variable_header[hi].value >>= current;
                      if (first)
                        {
                          first = 0;
                        }
                      else
                        {
                          if (current >
                              ACE_static_cast (CORBA::Short, previous))
                            {
                              this->done_ = 1;
                              ACE_ERROR ((LM_ERROR,
                                          ACE_TEXT ("ERROR: Priority Ordering failed\n")));
                            }
                        }
                      previous = ACE_static_cast (long, current);
                    }
                }
              else if (this->order_policy_ == CosNotification::DeadlineOrder)
                {
                  if (ACE_OS::strcmp (
                          events[e].header.variable_header[hi].name, "Timeout") == 0)
                    {
                      TimeBase::TimeT current;
                      events[e].header.variable_header[hi].value >>= current;
                      if (first)
                        {
                          first = 0;
                        }
                      else
                        {
                          if (current <
                              ACE_static_cast (TimeBase::TimeT, previous))
                            {
                              this->done_ = 1;
                              ACE_ERROR ((LM_ERROR,
                                          ACE_TEXT ("ERROR: Deadline Ordering failed\n")));
                            }
                        }
# if defined (ACE_CONFIG_WIN32_H)
                      previous = ACE_static_cast (long, current);
# else
                      // Convert ACE_ULong_Long to 32-bit integer
                      previous = (current / 1);
# endif /* ACE_CONFIG_WIN32_H */
                    }
                }
            }

          CORBA::ULong flength = events[e].filterable_data.length ();
          for (CORBA::ULong i = 0; i < flength; i++)
            {
              ACE_DEBUG ((LM_DEBUG,
                          "%s = %s\n",
                          (const char*)events[e].filterable_data[i].name,
                          Any_String (events[e].filterable_data[i].value)));
              if (this->order_policy_ == CosNotification::FifoOrder)
                {
                  if (ACE_OS::strcmp (events[e].filterable_data[i].name, "enum") == 0)
                    {
                      CORBA::ULong current;
                      events[e].filterable_data[i].value >>= current;
                      if (first)
                        {
                          first = 0;
                        }
                      else
                        {
                          if (current <
                              ACE_static_cast (CORBA::ULong, previous))
                            {
                              this->done_ = 1;
                              ACE_ERROR ((LM_ERROR,
                                          ACE_TEXT ("ERROR: FIFO Ordering failed.\n")));
                            }
                        }
                      previous = ACE_static_cast (long, current);
                    }
                }
            }
        }
      ACE_DEBUG ((LM_DEBUG,
                  "-------------------------\n"));
    }

  this->count_++;
  if (this->count_ > this->high_)
    {
      this->done_ = 2;
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Sequence Consumer (%P|%t): ERROR: too "
                            "many events received.\n")));
    }
  else if (this->count_ == this->low_)
    {
      this->done_ = 1;
    }
  else
    {
      ACE_OS::sleep (1);
    }
}