Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / EventServices / RTEC_MCast_Federated / EchoEventConsumer_i.cpp
blob7bfaecabd91dc03a6a85096f914f05db2123217b
1 // EchoEventConsumer_i.cpp
2 // Implements a PushConsumer.
4 #include "EchoEventConsumer_i.h"
5 #include "tao/PortableServer/PS_CurrentC.h"
6 #include "ace/OS_NS_stdio.h"
7 #include <sstream>
9 // Constructor duplicates the ORB reference.
10 EchoEventConsumer_i::EchoEventConsumer_i(
11 CORBA::ORB_ptr orb,
12 RtecEventChannelAdmin::ProxyPushSupplier_ptr supplier,
13 int event_limit)
14 : orb_(CORBA::ORB::_duplicate(orb))
15 , supplier_(RtecEventChannelAdmin::ProxyPushSupplier::_duplicate(supplier))
16 , event_limit_(event_limit)
18 // Nothing to do.
21 // Implement the push() operation.
22 void EchoEventConsumer_i::push(const RtecEventComm::EventSet& events)
24 // Loop through the events, looking for shutdown events.
25 for (u_int i = 0; i < events.length (); ++i) {
26 //ACE_OS::printf(".");
27 // Extract event data from the any.
28 const char* eventData;
29 std::ostringstream out;
30 out << "Received event,"
31 << " type: " << events[i].header.type
32 << " source: " << events[i].header.source;
33 if (events[i].data.any_value >>= eventData) {
34 out << " text: " << eventData;
37 ACE_OS::printf("%s\n", out.str().c_str()); // printf is synchronized
39 if (--event_limit_ <= 0) {
40 supplier_->disconnect_push_supplier();
41 orb_->shutdown(0);
45 // Implement the disconnect_push_consumer() operation.
46 void EchoEventConsumer_i::disconnect_push_consumer()
48 // Deactivate this object.
49 CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent");
50 PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in());
51 PortableServer::POA_var poa = current->get_POA();
52 PortableServer::ObjectId_var objectId = current->get_object_id();
53 poa->deactivate_object(objectId.in());