Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / orbsvcs / tests / Event / lib / Counting_Consumer.cpp
blobe68c91f2a2a161624c2c55b584ab1e00a15cdee3
1 #include "Counting_Consumer.h"
4 EC_Counting_Consumer::EC_Counting_Consumer (const char* name)
5 : event_count (0),
6 disconnect_count (0),
7 name_ (name)
11 void
12 EC_Counting_Consumer::connect (RtecEventChannelAdmin::ConsumerAdmin_ptr consumer_admin,
13 const RtecEventChannelAdmin::ConsumerQOS &qos)
15 // The canonical protocol to connect to the EC
17 RtecEventComm::PushConsumer_var consumer =
18 this->_this ();
20 if (CORBA::is_nil (this->supplier_proxy_.in ()))
22 this->supplier_proxy_ =
23 consumer_admin->obtain_push_supplier ();
26 this->supplier_proxy_->connect_push_consumer (consumer.in (),
27 qos);
30 void
31 EC_Counting_Consumer::disconnect ()
33 if (!CORBA::is_nil (this->supplier_proxy_.in ()))
35 this->supplier_proxy_->disconnect_push_supplier ();
36 this->supplier_proxy_ =
37 RtecEventChannelAdmin::ProxyPushSupplier::_nil ();
39 this->deactivate ();
42 void
43 EC_Counting_Consumer::deactivate ()
45 PortableServer::POA_var consumer_poa =
46 this->_default_POA ();
47 PortableServer::ObjectId_var consumer_id =
48 consumer_poa->servant_to_id (this);
49 consumer_poa->deactivate_object (consumer_id.in ());
52 void
53 EC_Counting_Consumer::dump_results (int expected_count, int tolerance)
55 int diff = this->event_count - expected_count;
56 if (diff > tolerance || diff < -tolerance)
58 ACE_DEBUG ((LM_DEBUG,
59 "ERROR - %s unexpected number of events <%d> instead of <%d>\n",
60 this->name_,
61 this->event_count,
62 expected_count));
64 else
66 ACE_DEBUG ((LM_DEBUG,
67 "%s - number of events <%d> within margins expected <%d>\n",
68 this->name_,
69 this->event_count,
70 expected_count));
74 void
75 EC_Counting_Consumer::push (const RtecEventComm::EventSet& events)
77 if (events.length () == 0)
79 ACE_DEBUG ((LM_DEBUG,
80 "%s (%P|%t) no events\n", this->name_));
81 return;
84 this->event_count ++;
85 #if 0
86 if (this->event_count % 10 == 0)
88 ACE_DEBUG ((LM_DEBUG,
89 "%s (%P|%t): %d events received\n",
90 this->name_,
91 this->event_count));
93 #endif /* 0 */
96 void
97 EC_Counting_Consumer::disconnect_push_consumer ()
99 this->disconnect_count++;
100 this->supplier_proxy_ =
101 RtecEventChannelAdmin::ProxyPushSupplier::_nil ();