summaryrefslogtreecommitdiff
path: root/orbsvcs/tests/Event/Mcast/RTEC_MCast_Federated/EchoEventConsumer_i.cpp
blob: 8708015e3d0929f5aecd53fd3cee9e9a5bb07cea (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
// $Id$

// EchoEventConsumer_i.cpp
// Implements a PushConsumer.

#include "EchoEventConsumer_i.h"
#include "tao/PortableServer/PS_CurrentC.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_unistd.h"

#include <sstream>

// Constructor duplicates the ORB reference.
EchoEventConsumer_i::EchoEventConsumer_i(CORBA::ORB_ptr orb, int event_limit)
  : orb_(CORBA::ORB::_duplicate(orb))
  , event_limit_(event_limit)
{
  // Nothing to do.
}

// Implement the push() operation.
void EchoEventConsumer_i::push(const RtecEventComm::EventSet& events)
{
  // Loop through the events, looking for shutdown events.
  for (u_int i = 0; i < events.length (); ++i)
    {
      //ACE_OS::printf(".");
      // Extract event data from the any.
      const char* eventData;
      std::ostringstream out;

#ifndef ACE_LACKS_GETPID
      out << "[" << ACE_OS::getpid();
#endif
      out << "] Received event,"
          << "  type: "   << events[i].header.type
          << "  source: " << events[i].header.source;

#if !defined (TAO_LACKS_EVENT_CHANNEL_ANY)
      if (events[i].data.any_value >>= eventData)
        {
          out << "  text: "   << eventData;
        }
#else
      if (events[i].data.payload.length() > 0)
        {
          out << "  text: " <<
            (const char *)events[i].data.payload.get_buffer();
        }
#endif  /* !TAO_LACKS_EVENT_CHANNEL_ANY */
      ACE_OS::printf("%s\n", out.str().c_str()); // printf is synchronized
    }
  if (--event_limit_ <= 0)
    {
      orb_->shutdown(0);
    }
}

// Implement the disconnect_push_consumer() operation.
void EchoEventConsumer_i::disconnect_push_consumer()
{
  // Deactivate this object.
  CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent");
  PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in());
  PortableServer::POA_var poa = current->get_POA();
  PortableServer::ObjectId_var objectId = current->get_object_id();
  poa->deactivate_object(objectId.in());
}