summaryrefslogtreecommitdiff
path: root/TAO/docs/tutorials/Quoter/RT_Event_Service/Stock_Consumer.cpp
blob: ce03e9caca01ac7940824cf00645633f8fb3c845 (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
//
// $Id$
//

#include "Stock_Consumer.h"
#include "QuoterC.h"

Stock_Consumer::Stock_Consumer ()
{
}

void
Stock_Consumer::connect (RtecEventChannelAdmin::EventChannel_ptr event_channel,
                         const RtecEventChannelAdmin::ConsumerQOS &subscriptions)
{
  RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
    event_channel->for_consumers ();

  this->supplier_proxy_ =
    consumer_admin->obtain_push_supplier ();

  RtecEventComm::PushConsumer_var myself = this->_this ();
  this->supplier_proxy_->connect_push_consumer (myself.in (),
                                                subscriptions);
}

void
Stock_Consumer::disconnect ()
{
  // Do not receive any more events...
  this->supplier_proxy_->disconnect_push_supplier ();
}

void
Stock_Consumer::push (const RtecEventComm::EventSet &data,
                      CORBA::Environment &)
  throw (CORBA::SystemException)
{
  for (CORBA::ULong i = 0; i != data.length (); ++i) {
    const RtecEventComm::Event &e = data[i];

    Quoter::Event *event;
    if ((e.data.any_value >>= event) == 0)
      continue; // Invalid event

    cout << "The new price for one stock in \""
         << event->full_name.in ()
         << "\" (" << event->symbol.in ()
         << ") is " << event->price << endl;
  }
}

void
Stock_Consumer::disconnect_push_consumer (CORBA::Environment &)
    throw (CORBA::SystemException)
{
  this->supplier_proxy_ =
    RtecEventChannelAdmin::ProxyPushSupplier::_nil ();
}