Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BuiltInTopicTest for safety profile #2274

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
122 changes: 56 additions & 66 deletions tests/DCPS/BuiltInTopicTest/DataReaderListener.cpp
@@ -1,25 +1,31 @@
// -*- C++ -*-
//
#include "DataReaderListener.h"

#include "MessengerTypeSupportC.h"
#include "MessengerTypeSupportImpl.h"

#include "tests/Utils/ExceptionStreams.h"

#include <dds/DCPS/Service_Participant.h>
#include "dds/DCPS/BuiltInTopicUtils.h"
#include <dds/DCPS/BuiltInTopicUtils.h>
#include <dds/DCPS/SafetyProfileStreams.h>
#include <dds/DdsDcpsCoreTypeSupportImpl.h>

#include <ace/streams.h>

#include <iostream>
#include "tests/Utils/ExceptionStreams.h"
#include <dds/DdsDcpsCoreTypeSupportImpl.h>

using namespace std;

DataReaderListenerImpl::DataReaderListenerImpl()
: num_reads_(0),
publication_handle_ (::DDS::HANDLE_NIL),
post_restart_publication_handle_ (::DDS::HANDLE_NIL)
publication_handle_(::DDS::HANDLE_NIL),
post_restart_publication_handle_(::DDS::HANDLE_NIL)
{
}

DataReaderListenerImpl::~DataReaderListenerImpl ()
DataReaderListenerImpl::~DataReaderListenerImpl()
{
}

Expand All @@ -29,81 +35,70 @@ void DataReaderListenerImpl::on_data_available(DDS::DataReader_ptr reader)

try {
::Messenger::MessageDataReader_var message_dr = ::Messenger::MessageDataReader::_narrow(reader);
if (CORBA::is_nil (message_dr.in ())) {
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListener: read: _narrow failed.\n")));
if (CORBA::is_nil(message_dr.in())) {
ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) DataReaderListener: read: _narrow failed.\n")));
exit(1);
}

Messenger::Message message;
DDS::SampleInfo si ;
DDS::ReturnCode_t status = message_dr->take_next_sample(message, si) ;
DDS::SampleInfo si;
DDS::ReturnCode_t status = message_dr->take_next_sample(message, si);

if (status == DDS::RETCODE_OK) {

if (si.valid_data)
{
if (si.publication_handle == ::DDS::HANDLE_NIL
|| (si.publication_handle != this->publication_handle_
&& si.publication_handle != this->post_restart_publication_handle_))
{
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListener: ERROR: publication_handle validate failed.\n")));
if (si.valid_data) {
if (si.publication_handle == ::DDS::HANDLE_NIL ||
(si.publication_handle != this->publication_handle_ &&
si.publication_handle != this->post_restart_publication_handle_)) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) DataReaderListener: ERROR: publication_handle validate failed.\n")));
exit(1);
}

ACE_DEBUG((LM_DEBUG, ACE_TEXT(
"(%P|%t) DataReaderListener: Message count = %i\n"), message.count));
}
else if (si.instance_state == DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE)
{
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) DataReaderListener: Message count = %i\n"), message.count));

} else if (si.instance_state == DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) instance is disposed\n")));
}
else if (si.instance_state == DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE)
{
} else if (si.instance_state == DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) instance is unregistered\n")));
}
} else if (status == DDS::RETCODE_NO_DATA) {
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListener: ERROR: reader received DDS::RETCODE_NO_DATA!\n")));
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) DataReaderListener: ERROR: reader received DDS::RETCODE_NO_DATA!\n")));
} else {
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListener: ERROR: read Message: Error: %i\n"), status));
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) DataReaderListener: ERROR: read Message: Error: %C\n"),
OpenDDS::DCPS::retcode_to_string(status)));
}
} catch (CORBA::Exception& e) {
e._tao_print_exception(
"DataReaderListener: Exception caught in read:", stderr);
e._tao_print_exception("DataReaderListener: Exception caught in read:", stderr);
exit(1);
}
}

void DataReaderListenerImpl::on_requested_deadline_missed (
DDS::DataReader_ptr,
const DDS::RequestedDeadlineMissedStatus &)
void DataReaderListenerImpl::on_requested_deadline_missed(DDS::DataReader_ptr,
const DDS::RequestedDeadlineMissedStatus&)
{
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_requested_deadline_missed\n")));
}

void DataReaderListenerImpl::on_requested_incompatible_qos (
DDS::DataReader_ptr,
const DDS::RequestedIncompatibleQosStatus &)
void DataReaderListenerImpl::on_requested_incompatible_qos(DDS::DataReader_ptr,
const DDS::RequestedIncompatibleQosStatus&)
{
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_requested_incompatible_qos\n")));
}

void DataReaderListenerImpl::on_liveliness_changed (
DDS::DataReader_ptr,
const DDS::LivelinessChangedStatus &)
void DataReaderListenerImpl::on_liveliness_changed(DDS::DataReader_ptr,
const DDS::LivelinessChangedStatus&)
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_liveliness_changed\n")));
}

void DataReaderListenerImpl::on_subscription_matched (
DDS::DataReader_ptr,
const DDS::SubscriptionMatchedStatus & status)
void DataReaderListenerImpl::on_subscription_matched(DDS::DataReader_ptr,
const DDS::SubscriptionMatchedStatus& status)
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_subscription_matched handle=%i\n"),
Expand Down Expand Up @@ -143,7 +138,7 @@ bool DataReaderListenerImpl::read_bit_instance()
case DDS::RETCODE_OK:
ACE_DEBUG((LM_DEBUG, ACE_TEXT(
"(%P|%t) read bit instance returned ok\n")));
return false;
return true;
case DDS::RETCODE_NO_DATA:
ACE_ERROR((LM_WARNING, ACE_TEXT(
"(%P|%t) read bit instance returned no data\n")));
Expand All @@ -154,59 +149,54 @@ bool DataReaderListenerImpl::read_bit_instance()
break;
default:
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) ERROR read bit instance returned %i\n"), ret));
return true;
"(%P|%t) ERROR read bit instance returned %C\n"),
OpenDDS::DCPS::retcode_to_string(ret)));
return false;
}
ACE_OS::sleep(ACE_Time_Value(0, 100000));
}

ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) ERROR read bit instance: giving up after retries\n")));
return true;
return false;
}

void DataReaderListenerImpl::on_sample_rejected(
DDS::DataReader_ptr,
const DDS::SampleRejectedStatus&)
void DataReaderListenerImpl::on_sample_rejected(DDS::DataReader_ptr,
const DDS::SampleRejectedStatus&)
{
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_sample_rejected\n")));
}

void DataReaderListenerImpl::on_sample_lost(
DDS::DataReader_ptr,
void DataReaderListenerImpl::on_sample_lost(DDS::DataReader_ptr,
const DDS::SampleLostStatus&)
{
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_sample_lost\n")));
}

void DataReaderListenerImpl::on_subscription_disconnected (
DDS::DataReader_ptr,
const ::OpenDDS::DCPS::SubscriptionDisconnectedStatus &)
void DataReaderListenerImpl::on_subscription_disconnected(DDS::DataReader_ptr,
const ::OpenDDS::DCPS::SubscriptionDisconnectedStatus&)
{
ACE_ERROR((LM_WARNING, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_subscription_disconnected\n")));
}

void DataReaderListenerImpl::on_subscription_reconnected (
DDS::DataReader_ptr,
const ::OpenDDS::DCPS::SubscriptionReconnectedStatus &)
void DataReaderListenerImpl::on_subscription_reconnected(DDS::DataReader_ptr,
const ::OpenDDS::DCPS::SubscriptionReconnectedStatus&)
{
ACE_ERROR((LM_WARNING, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_subscription_reconnected\n")));
}

void DataReaderListenerImpl::on_subscription_lost (
DDS::DataReader_ptr,
const ::OpenDDS::DCPS::SubscriptionLostStatus &)
void DataReaderListenerImpl::on_subscription_lost(DDS::DataReader_ptr,
const ::OpenDDS::DCPS::SubscriptionLostStatus&)
{
ACE_ERROR((LM_WARNING, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_subscription_lost\n")));
}

void DataReaderListenerImpl::set_builtin_datareader (
DDS::DataReader_ptr builtin)
void DataReaderListenerImpl::set_builtin_datareader(DDS::DataReader_ptr builtin)
{
builtin_ = DDS::DataReader::_duplicate(builtin);
}
43 changes: 21 additions & 22 deletions tests/DCPS/BuiltInTopicTest/DataReaderListener.h
Expand Up @@ -11,28 +11,27 @@
#endif /* ACE_LACKS_PRAGMA_ONCE */

class DataReaderListenerImpl
: public virtual OpenDDS::DCPS::LocalObject<DDS::DataReaderListener>
{
: public virtual OpenDDS::DCPS::LocalObject<DDS::DataReaderListener> {
public:
DataReaderListenerImpl ();
DataReaderListenerImpl();

virtual ~DataReaderListenerImpl (void);
virtual ~DataReaderListenerImpl(void);

virtual void on_requested_deadline_missed (
virtual void on_requested_deadline_missed(
DDS::DataReader_ptr reader,
const DDS::RequestedDeadlineMissedStatus & status);
const DDS::RequestedDeadlineMissedStatus& status);

virtual void on_requested_incompatible_qos (
virtual void on_requested_incompatible_qos(
DDS::DataReader_ptr reader,
const DDS::RequestedIncompatibleQosStatus & status);
const DDS::RequestedIncompatibleQosStatus& status);

virtual void on_liveliness_changed (
virtual void on_liveliness_changed(
DDS::DataReader_ptr reader,
const DDS::LivelinessChangedStatus & status);
const DDS::LivelinessChangedStatus& status);

virtual void on_subscription_matched (
virtual void on_subscription_matched(
DDS::DataReader_ptr reader,
const DDS::SubscriptionMatchedStatus & status);
const DDS::SubscriptionMatchedStatus& status);

virtual void on_sample_rejected(
DDS::DataReader_ptr reader,
Expand All @@ -45,33 +44,33 @@ class DataReaderListenerImpl
DDS::DataReader_ptr reader,
const DDS::SampleLostStatus& status);

virtual void on_subscription_disconnected (
virtual void on_subscription_disconnected(
DDS::DataReader_ptr reader,
const ::OpenDDS::DCPS::SubscriptionDisconnectedStatus & status);
const ::OpenDDS::DCPS::SubscriptionDisconnectedStatus& status);

virtual void on_subscription_reconnected (
virtual void on_subscription_reconnected(
DDS::DataReader_ptr reader,
const ::OpenDDS::DCPS::SubscriptionReconnectedStatus & status);
const ::OpenDDS::DCPS::SubscriptionReconnectedStatus& status);

virtual void on_subscription_lost (
virtual void on_subscription_lost(
DDS::DataReader_ptr reader,
const ::OpenDDS::DCPS::SubscriptionLostStatus & status);
const ::OpenDDS::DCPS::SubscriptionLostStatus& status);

long num_reads() const {
return num_reads_;
}

void set_builtin_datareader (DDS::DataReader_ptr builtin);
void set_builtin_datareader(DDS::DataReader_ptr builtin);

bool read_bit_instance();

private:

DDS::DataReader_var reader_;
long num_reads_;
DDS::DataReader_var reader_;
long num_reads_;
::DDS::InstanceHandle_t publication_handle_;
::DDS::InstanceHandle_t post_restart_publication_handle_;
DDS::DataReader_var builtin_;
DDS::DataReader_var builtin_;
};

#endif /* DATAREADER_LISTENER_IMPL */