summaryrefslogtreecommitdiff
path: root/dds_io_sub/DataReaderListener.cpp
blob: f10345117bcf0d6b502c5e835e75801f7f7241fe (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
// -*- C++ -*-
//
// $Id: DataReaderListener.cpp 889 2007-06-29 21:55:06Z johnc $
#include "DataReaderListener.h"
#include "PortTypeSupportC.h"
#include "PortTypeSupportImpl.h"
#include <dds/DCPS/Service_Participant.h>
#include <ace/streams.h>

using namespace IOTest;

// Implementation skeleton constructor
DataReaderListenerImpl::DataReaderListenerImpl()
{
}

// Implementation skeleton destructor
DataReaderListenerImpl::~DataReaderListenerImpl ()
{
}

void DataReaderListenerImpl::on_data_available(DDS::DataReader_ptr reader)
  throw (CORBA::SystemException)
{

  try {
	  
//	fprintf(stderr, "1\n"); fflush(stderr);  
	  
    ::IOTest::PortDataReader_var port_dr = ::IOTest::PortDataReader::_narrow(reader);
    if (CORBA::is_nil (port_dr.in ())) {
      cerr << "read: _narrow failed." << endl;
      exit(1);
    }
    
//  fprintf(stderr, "2\n"); fflush(stderr);

    IOTest::Port port_obj;
    DDS::SampleInfo si ;
    DDS::ReturnCode_t status = port_dr->take_next_sample(port_obj, si) ;

//  fprintf(stderr, "3\n"); fflush(stderr);
    
    if (status == DDS::RETCODE_OK) {
//      cout << "Port: no:     = " << port_obj.no << endl
//           << "      value:  = " << port_obj.value   << endl;
//      cout << "  sample_rank = " << si.sample_rank << endl;
      
      if(port_obj.no == 1)
    	  io.set(port_obj.value);
      
    } else if (status == DDS::RETCODE_NO_DATA) {
      cerr << "ERROR: reader received DDS::RETCODE_NO_DATA!" << endl;
    } else {
      cerr << "ERROR: read Message: Error: " <<  status << endl;
    }
  } catch (CORBA::Exception& e) {
    cerr << "Exception caught in read:" << endl << e << endl;
    exit(1);
  }
}

void DataReaderListenerImpl::on_requested_deadline_missed (
    DDS::DataReader_ptr,
    const DDS::RequestedDeadlineMissedStatus &)
  throw (CORBA::SystemException)
{
  cerr << "DataReaderListenerImpl::on_requested_deadline_missed" << endl;
}

void DataReaderListenerImpl::on_requested_incompatible_qos (
    DDS::DataReader_ptr,
    const DDS::RequestedIncompatibleQosStatus &)
  throw (CORBA::SystemException)
{
  cerr << "DataReaderListenerImpl::on_requested_incompatible_qos" << endl;
}

void DataReaderListenerImpl::on_liveliness_changed (
    DDS::DataReader_ptr,
    const DDS::LivelinessChangedStatus &)
  throw (CORBA::SystemException)
{
  cerr << "DataReaderListenerImpl::on_liveliness_changed" << endl;
}

void DataReaderListenerImpl::on_subscription_match (
    DDS::DataReader_ptr,
    const DDS::SubscriptionMatchStatus &)
  throw (CORBA::SystemException)
{
  cerr << "DataReaderListenerImpl::on_subscription_match" << endl;
}

void DataReaderListenerImpl::on_sample_rejected(
    DDS::DataReader_ptr,
    const DDS::SampleRejectedStatus&)
  throw (CORBA::SystemException)
{
  cerr << "DataReaderListenerImpl::on_sample_rejected" << endl;
}

void DataReaderListenerImpl::on_sample_lost(
  DDS::DataReader_ptr,
  const DDS::SampleLostStatus&)
  throw (CORBA::SystemException)
{
  cerr << "DataReaderListenerImpl::on_sample_lost" << endl;
}