Apply clang-format to Lts/Common and DTC/enum headers
- Formatted all CodeGen module files (9 files) - Formatted LtsAppDescriptor module files - Formatted LtsAppManager/AppChooser files - Applied clang-format to all DTC and enum headers across modules - Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/) Cosmetic changes only, no functional modifications. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
848 files changed
+89305
-100020
No files matched your search
Executable → Regular
+60
-66
@@ -1,15 +1,14 @@
|
||||
|
||||
|
||||
|
||||
#include "pacemaker.h"
|
||||
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
#include <DDS/DTS/generic_dts.h>
|
||||
#include <DDS/DTS/generic_dts_impl.h>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <DDS/DTS/generic_dts.h>
|
||||
#include <DDS/DTS/generic_dts_impl.h>
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
|
||||
namespace Core
|
||||
{
|
||||
@@ -17,101 +16,96 @@ Pacemaker::Pacemaker(DDSConnector::DdsConnector *ddsConnector)
|
||||
: QObject(nullptr)
|
||||
.getNGLLogger("Core.Pacemaker"))
|
||||
{
|
||||
init(ddsConnector);
|
||||
init(ddsConnector);
|
||||
}
|
||||
|
||||
Pacemaker::~Pacemaker()
|
||||
{
|
||||
m_paceThread->requestInterruption();
|
||||
m_paceThread->quit();
|
||||
m_paceThread->wait();
|
||||
delete m_paceThread;
|
||||
m_publishTimer->deleteLater();
|
||||
delete m_dtsCurrentRunningState;
|
||||
m_paceThread->requestInterruption();
|
||||
m_paceThread->quit();
|
||||
m_paceThread->wait();
|
||||
delete m_paceThread;
|
||||
m_publishTimer->deleteLater();
|
||||
delete m_dtsCurrentRunningState;
|
||||
}
|
||||
|
||||
|
||||
void Pacemaker::setNewState(Core::RunningState newState, const QString &errorString)
|
||||
void Pacemaker::setNewState(Core::RunningState newState, const QString& errorString)
|
||||
{
|
||||
if (QThread::currentThread() == this->thread())
|
||||
setNewStateInternal(newState, errorString);
|
||||
else
|
||||
QTimer::singleShot(0, this, [this, newState, errorString]() { setNewStateInternal(newState, errorString); });
|
||||
if (QThread::currentThread() == this->thread())
|
||||
setNewStateInternal(newState, errorString);
|
||||
else
|
||||
QTimer::singleShot(0, this, [this, newState, errorString]() { setNewStateInternal(newState, errorString); });
|
||||
}
|
||||
|
||||
void Pacemaker::setNewStateInternal(Core::RunningState newState, const QString &errorString)
|
||||
void Pacemaker::setNewStateInternal(Core::RunningState newState, const QString& errorString)
|
||||
{
|
||||
m_state.runningState(newState);
|
||||
if (errorString.isEmpty())
|
||||
m_state.errorString().reset();
|
||||
else
|
||||
m_state.errorString(errorString.toStdString());
|
||||
publishState();
|
||||
m_state.runningState(newState);
|
||||
if (errorString.isEmpty())
|
||||
m_state.errorString().reset();
|
||||
else
|
||||
m_state.errorString(errorString.toStdString());
|
||||
publishState();
|
||||
}
|
||||
|
||||
void Pacemaker::addPort(unsigned short number, Core::PortType portType, const QString &properties)
|
||||
void Pacemaker::addPort(unsigned short number, Core::PortType portType, const QString& properties)
|
||||
{
|
||||
if (QThread::currentThread() == this->thread())
|
||||
addPortInternal(number, portType, properties);
|
||||
else
|
||||
QTimer::singleShot(0, this, [this, number, portType, properties]() { addPortInternal(number, portType, properties); });
|
||||
if (QThread::currentThread() == this->thread())
|
||||
addPortInternal(number, portType, properties);
|
||||
else
|
||||
QTimer::singleShot(0, this,
|
||||
[this, number, portType, properties]() { addPortInternal(number, portType, properties); });
|
||||
}
|
||||
|
||||
void Pacemaker::addPortInternal(unsigned short number, Core::PortType portType,const QString &properties)
|
||||
void Pacemaker::addPortInternal(unsigned short number, Core::PortType portType, const QString& properties)
|
||||
{
|
||||
if (!m_state.ports().is_set())
|
||||
m_state.ports() = std::vector<Core::PortInformation>();
|
||||
m_state.ports().get().push_back(Core::PortInformation(number, portType, properties.toStdString()));
|
||||
if (!m_state.ports().is_set())
|
||||
m_state.ports() = std::vector<Core::PortInformation>();
|
||||
m_state.ports().get().push_back(Core::PortInformation(number, portType, properties.toStdString()));
|
||||
|
||||
publishState();
|
||||
publishState();
|
||||
}
|
||||
|
||||
void Pacemaker::publishState()
|
||||
{
|
||||
if (!m_dtsCurrentRunningState)
|
||||
return;
|
||||
m_dtsCurrentRunningState->write(m_state);
|
||||
if (!m_dtsCurrentRunningState)
|
||||
return;
|
||||
m_dtsCurrentRunningState->write(m_state);
|
||||
}
|
||||
|
||||
void Pacemaker::init(DDSConnector::DdsConnector *ddsConnector)
|
||||
void Pacemaker::init(DDSConnector::DdsConnector* ddsConnector)
|
||||
{
|
||||
m_dtsCurrentRunningState = ddsConnector->createDTS<DTS::CurrentRunningStateImpl>();
|
||||
if (!m_dtsCurrentRunningState)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Can not initialize DTS::CurrentRunningState!";
|
||||
return;
|
||||
}
|
||||
m_state.pid(QCoreApplication::applicationPid());
|
||||
m_state.runningState(Core::RunningState::Starting);
|
||||
m_dtsCurrentRunningState = ddsConnector->createDTS<DTS::CurrentRunningStateImpl>();
|
||||
if (!m_dtsCurrentRunningState)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Can not initialize DTS::CurrentRunningState!";
|
||||
return;
|
||||
}
|
||||
m_state.pid(QCoreApplication::applicationPid());
|
||||
m_state.runningState(Core::RunningState::Starting);
|
||||
|
||||
m_paceThread = new QThread;
|
||||
this->moveToThread(m_paceThread);
|
||||
m_paceThread = new QThread;
|
||||
this->moveToThread(m_paceThread);
|
||||
|
||||
startTimer();
|
||||
publishState();
|
||||
startTimer();
|
||||
publishState();
|
||||
}
|
||||
|
||||
void Pacemaker::startTimer()
|
||||
{
|
||||
if (m_publishTimer)
|
||||
return;
|
||||
if (m_publishTimer)
|
||||
return;
|
||||
|
||||
m_publishTimer = new QTimer();
|
||||
m_publishTimer = new QTimer();
|
||||
|
||||
m_publishTimer->moveToThread(m_paceThread);
|
||||
|
||||
m_publishTimer->moveToThread(m_paceThread);
|
||||
connect(m_publishTimer, &QTimer::timeout, this, &Pacemaker::publishState);
|
||||
|
||||
connect(m_publishTimer, &QTimer::timeout,
|
||||
this, &Pacemaker::publishState);
|
||||
m_publishTimer->setSingleShot(false);
|
||||
m_publishTimer->setInterval(m_publishTimerDelay);
|
||||
connect(m_paceThread, &QThread::started, this, [this]() { m_publishTimer->start(); });
|
||||
|
||||
m_publishTimer->setSingleShot(false);
|
||||
m_publishTimer->setInterval(m_publishTimerDelay);
|
||||
connect(m_paceThread, &QThread::started, this, [this](){
|
||||
m_publishTimer->start();
|
||||
});
|
||||
|
||||
|
||||
m_paceThread->start();
|
||||
m_paceThread->start();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Core
|
||||
Executable → Regular
+31
-29
@@ -1,18 +1,19 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "svccoreclient_export.h"
|
||||
|
||||
#include <DDS/Core/core_dts_types.h>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QThread>
|
||||
#include <DDS/Core/core_dts_types.h>
|
||||
#include "svccoreclient_export.h"
|
||||
|
||||
namespace DDSConnector
|
||||
{
|
||||
class DdsConnector;
|
||||
}
|
||||
class QTimer;
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
@@ -22,37 +23,38 @@ namespace Core
|
||||
{
|
||||
class CORE_CLIENT_EXPORT Pacemaker final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Pacemaker(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector)
|
||||
: Pacemaker(ddsConnector.get())
|
||||
{}
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Pacemaker(const std::shared_ptr<DDSConnector::DdsConnector>& ddsConnector) : Pacemaker(ddsConnector.get())
|
||||
{
|
||||
}
|
||||
|
||||
explicit Pacemaker(DDSConnector::DdsConnector *ddsConnector);
|
||||
~Pacemaker();
|
||||
explicit Pacemaker(DDSConnector::DdsConnector* ddsConnector);
|
||||
~Pacemaker();
|
||||
|
||||
void startTimer();
|
||||
void startTimer();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setNewState(Core::RunningState newState, const QString &errorString = QString());
|
||||
void addPort(unsigned short number, Core::PortType portType, const QString &properties = QStringLiteral(""));
|
||||
public Q_SLOTS:
|
||||
void setNewState(Core::RunningState newState, const QString& errorString = QString());
|
||||
void addPort(unsigned short number, Core::PortType portType, const QString& properties = QStringLiteral(""));
|
||||
|
||||
|
||||
void publishState();
|
||||
void publishState();
|
||||
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
void init(DDSConnector::DdsConnector *ddsConnector);
|
||||
void setNewStateInternal(Core::RunningState newState, const QString &errorString = QString());
|
||||
void addPortInternal(unsigned short number, Core::PortType portType, const QString &properties = QStringLiteral(""));
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
static constexpr const int m_publishTimerDelay = 3000;
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void init(DDSConnector::DdsConnector* ddsConnector);
|
||||
void setNewStateInternal(Core::RunningState newState, const QString& errorString = QString());
|
||||
void addPortInternal(unsigned short number, Core::PortType portType,
|
||||
const QString& properties = QStringLiteral(""));
|
||||
|
||||
CurrentRunningState m_state;
|
||||
QTimer *m_publishTimer = nullptr;
|
||||
QThread *m_paceThread = nullptr;
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
static constexpr const int m_publishTimerDelay = 3000;
|
||||
|
||||
DTS::CurrentRunningStateImpl *m_dtsCurrentRunningState;
|
||||
CurrentRunningState m_state;
|
||||
QTimer* m_publishTimer = nullptr;
|
||||
QThread* m_paceThread = nullptr;
|
||||
|
||||
DTS::CurrentRunningStateImpl* m_dtsCurrentRunningState;
|
||||
};
|
||||
}
|
||||
} // namespace Core
|
||||
Executable → Regular
+144
-175
@@ -1,13 +1,13 @@
|
||||
|
||||
|
||||
|
||||
#include "dds_connector.h"
|
||||
|
||||
#include "publisher.h"
|
||||
#include "subscriber.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <DDS/QosProfile/DDS_DefaultQos.h>
|
||||
#include <DDS/Generic/wait_set_handler.h>
|
||||
#include <DDS/QosProfile/DDS_DefaultQos.h>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace DDSConnector
|
||||
@@ -32,252 +32,221 @@ DdsConnector::DdsConnector(int domainId,
|
||||
, m_wsHandler(nullptr)
|
||||
.getNGLLogger("Common.DDSConnector"))
|
||||
{
|
||||
initInternal();
|
||||
DEBUG_LOG(m_logger) << "DdsConnector ctor: " << m_domainId << "," << m_partitionId << ","<< m_exerciseId << "," << static_cast<int>(m_defaultPartitionType);
|
||||
initInternal();
|
||||
DEBUG_LOG(m_logger) << "DdsConnector ctor: " << m_domainId << "," << m_partitionId << "," << m_exerciseId << ","
|
||||
<< static_cast<int>(m_defaultPartitionType);
|
||||
}
|
||||
|
||||
DdsConnector::DdsConnector(int domainId,
|
||||
IDL::PartitionType defaultPartitionType,
|
||||
int partitionId, int exerciseId,
|
||||
const QUrl &tcpConnectionUrl)
|
||||
: DdsConnector(domainId,
|
||||
nullptr,
|
||||
defaultPartitionType,
|
||||
partitionId,
|
||||
exerciseId,
|
||||
DDS::QosProfile::ConnectionType::Server,
|
||||
tcpConnectionUrl)
|
||||
{}
|
||||
|
||||
DdsConnector::DdsConnector(const dds::domain::DomainParticipant &domainParticipant,
|
||||
IDL::PartitionType defaultPartitionType,
|
||||
int partitionId, int exerciseId,
|
||||
const QUrl &tcpConnectionUrl)
|
||||
: DdsConnector(domainParticipant.domain_id(),
|
||||
domainParticipant,
|
||||
defaultPartitionType,
|
||||
partitionId,
|
||||
exerciseId,
|
||||
DDS::QosProfile::ConnectionType::Server,
|
||||
tcpConnectionUrl)
|
||||
{}
|
||||
|
||||
|
||||
DdsConnector::DdsConnector(const dds::domain::DomainParticipant &domainParticipant,
|
||||
IDL::PartitionType defaultPartitionType,
|
||||
DDS::QosProfile::ConnectionType connectionType,
|
||||
int partitionId,
|
||||
int exerciseId
|
||||
)
|
||||
: DdsConnector(domainParticipant.domain_id(),
|
||||
domainParticipant,
|
||||
defaultPartitionType,
|
||||
partitionId,
|
||||
exerciseId,
|
||||
connectionType,
|
||||
QUrl())
|
||||
{}
|
||||
|
||||
DdsConnector::DdsConnector(int domainId,
|
||||
IDL::PartitionType defaultPartitionType,
|
||||
int partitionId, int exerciseId,
|
||||
DDS::QosProfile::ConnectionType connectionType)
|
||||
: DdsConnector(domainId,
|
||||
nullptr,
|
||||
defaultPartitionType,
|
||||
partitionId,
|
||||
exerciseId,
|
||||
connectionType,
|
||||
QUrl())
|
||||
DdsConnector::DdsConnector(int domainId, IDL::PartitionType defaultPartitionType, int partitionId, int exerciseId,
|
||||
const QUrl& tcpConnectionUrl)
|
||||
: DdsConnector(domainId, nullptr, defaultPartitionType, partitionId, exerciseId,
|
||||
DDS::QosProfile::ConnectionType::Server, tcpConnectionUrl)
|
||||
{
|
||||
Q_ASSERT(connectionType != DDS::QosProfile::ConnectionType::Tcp);
|
||||
}
|
||||
|
||||
DdsConnector::DdsConnector(const dds::domain::DomainParticipant& domainParticipant,
|
||||
IDL::PartitionType defaultPartitionType, int partitionId, int exerciseId,
|
||||
const QUrl& tcpConnectionUrl)
|
||||
: DdsConnector(domainParticipant.domain_id(), domainParticipant, defaultPartitionType, partitionId, exerciseId,
|
||||
DDS::QosProfile::ConnectionType::Server, tcpConnectionUrl)
|
||||
{
|
||||
}
|
||||
|
||||
DdsConnector::DdsConnector(const dds::domain::DomainParticipant& domainParticipant,
|
||||
IDL::PartitionType defaultPartitionType, DDS::QosProfile::ConnectionType connectionType,
|
||||
int partitionId, int exerciseId)
|
||||
: DdsConnector(domainParticipant.domain_id(), domainParticipant, defaultPartitionType, partitionId, exerciseId,
|
||||
connectionType, QUrl())
|
||||
{
|
||||
}
|
||||
|
||||
DdsConnector::DdsConnector(int domainId, IDL::PartitionType defaultPartitionType, int partitionId, int exerciseId,
|
||||
DDS::QosProfile::ConnectionType connectionType)
|
||||
: DdsConnector(domainId, nullptr, defaultPartitionType, partitionId, exerciseId, connectionType, QUrl())
|
||||
{
|
||||
Q_ASSERT(connectionType != DDS::QosProfile::ConnectionType::Tcp);
|
||||
}
|
||||
|
||||
DdsConnector::~DdsConnector()
|
||||
{
|
||||
delete m_subscriber;
|
||||
delete m_publisher;
|
||||
delete m_wsHandler;
|
||||
delete m_subscriber;
|
||||
delete m_publisher;
|
||||
delete m_wsHandler;
|
||||
}
|
||||
|
||||
bool DdsConnector::init(const QStringList &qosFileList)
|
||||
bool DdsConnector::init(const QStringList& qosFileList)
|
||||
{
|
||||
return DDS::QosProfile::setDefault(qosFileList);
|
||||
return DDS::QosProfile::setDefault(qosFileList);
|
||||
}
|
||||
|
||||
QUrl DdsConnector::getTcpConnectionUrl() const
|
||||
{
|
||||
DEBUG_LOG(m_logger) << this << " gettcpConnectionUrl: " << m_tcpConnectionUrl.toString();
|
||||
return m_tcpConnectionUrl;
|
||||
DEBUG_LOG(m_logger) << this << " gettcpConnectionUrl: " << m_tcpConnectionUrl.toString();
|
||||
return m_tcpConnectionUrl;
|
||||
}
|
||||
|
||||
dds::pub::Publisher DdsConnector::getDdsPublisher() const
|
||||
{
|
||||
return m_publisher ? m_publisher->getDdsPublisher() : nullptr;
|
||||
return m_publisher ? m_publisher->getDdsPublisher() : nullptr;
|
||||
}
|
||||
|
||||
dds::sub::Subscriber DdsConnector::getDdsSubscriber() const
|
||||
{
|
||||
return m_subscriber ? m_subscriber->getDdsSubscriber() : nullptr;
|
||||
return m_subscriber ? m_subscriber->getDdsSubscriber() : nullptr;
|
||||
}
|
||||
|
||||
DDSGeneric::SubscriberListener *DdsConnector::getSubscriberListener()
|
||||
DDSGeneric::SubscriberListener* DdsConnector::getSubscriberListener()
|
||||
{
|
||||
return m_subscriber ? m_subscriber->getSubscriberListener() : nullptr;
|
||||
return m_subscriber ? m_subscriber->getSubscriberListener() : nullptr;
|
||||
}
|
||||
|
||||
void DdsConnector::initPublisherSubscriber()
|
||||
{
|
||||
initSubscriber();
|
||||
initPublisher();
|
||||
initSubscriber();
|
||||
initPublisher();
|
||||
}
|
||||
|
||||
void DdsConnector::initPublisher()
|
||||
{
|
||||
if (m_publisher)
|
||||
return;
|
||||
initDomainParticipant();
|
||||
|
||||
setPublisher(new DDSConnector::Publisher(m_domainParticipant, getDefaultPartition()));
|
||||
if (m_publisher)
|
||||
return;
|
||||
initDomainParticipant();
|
||||
|
||||
setPublisher(new DDSConnector::Publisher(m_domainParticipant, getDefaultPartition()));
|
||||
}
|
||||
|
||||
void DdsConnector::initSubscriber()
|
||||
{
|
||||
if (m_subscriber)
|
||||
return;
|
||||
initDomainParticipant();
|
||||
|
||||
setSubscriber(new DDSConnector::Subscriber(m_domainParticipant, getDefaultPartition()));
|
||||
if (m_subscriber)
|
||||
return;
|
||||
initDomainParticipant();
|
||||
|
||||
setSubscriber(new DDSConnector::Subscriber(m_domainParticipant, getDefaultPartition()));
|
||||
}
|
||||
|
||||
void DdsConnector::initDomainParticipant()
|
||||
{
|
||||
if (m_domainParticipant == nullptr)
|
||||
setDomainParticipant(dds::domain::DomainParticipant(m_domainId,
|
||||
DDS::QosProfile::domainParticipantDefault(m_connectionType, m_tcpConnectionUrl)));
|
||||
if (m_domainParticipant == nullptr)
|
||||
setDomainParticipant(dds::domain::DomainParticipant(
|
||||
m_domainId, DDS::QosProfile::domainParticipantDefault(m_connectionType, m_tcpConnectionUrl)));
|
||||
}
|
||||
|
||||
|
||||
std::string DdsConnector::getDefaultPartition() const
|
||||
{
|
||||
return getPartitionString(m_defaultPartitionType, m_partitionId);
|
||||
return getPartitionString(m_defaultPartitionType, m_partitionId);
|
||||
}
|
||||
|
||||
std::string DdsConnector::getPartitionString(IDL::PartitionType pt, int partitionId)
|
||||
{
|
||||
switch (pt)
|
||||
{
|
||||
case IDL::PartitionType::Any:
|
||||
return "*";
|
||||
case IDL::PartitionType::Global:
|
||||
return IDL::exercisePartition(0);
|
||||
case IDL::PartitionType::Exercise:
|
||||
case IDL::PartitionType::AllExercises:
|
||||
return IDL::exercisePartition(partitionId);
|
||||
case IDL::PartitionType::Replay:
|
||||
return IDL::replayPartition(partitionId);
|
||||
}
|
||||
switch (pt)
|
||||
{
|
||||
case IDL::PartitionType::Any:
|
||||
return "*";
|
||||
case IDL::PartitionType::Global:
|
||||
return IDL::exercisePartition(0);
|
||||
case IDL::PartitionType::Exercise:
|
||||
case IDL::PartitionType::AllExercises:
|
||||
return IDL::exercisePartition(partitionId);
|
||||
case IDL::PartitionType::Replay:
|
||||
return IDL::replayPartition(partitionId);
|
||||
}
|
||||
|
||||
NGL::INGLLogger &m_logger = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Common.DDSConnector");
|
||||
ERROR_LOG(m_logger) << "Invalid partition type: " << static_cast<int>(pt);
|
||||
return std::string();
|
||||
NGL::INGLLogger& m_logger = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Common.DDSConnector");
|
||||
ERROR_LOG(m_logger) << "Invalid partition type: " << static_cast<int>(pt);
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void DdsConnector::setDomainParticipant(const dds::domain::DomainParticipant &participant)
|
||||
void DdsConnector::setDomainParticipant(const dds::domain::DomainParticipant& participant)
|
||||
{
|
||||
m_domainParticipant = participant;
|
||||
if (m_domainParticipant == nullptr)
|
||||
return;
|
||||
m_domainParticipant = participant;
|
||||
if (m_domainParticipant == nullptr)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
dds::domain::qos::DomainParticipantQos dpQos(m_domainParticipant.qos());
|
||||
DDS::QosProfile::print(dpQos, m_logger);
|
||||
rti::core::policy::EntityName entityName;
|
||||
entityName.name(qAppName().toStdString() + (" - DP ") + std::to_string(m_domainId));
|
||||
dpQos << entityName;
|
||||
m_domainParticipant.qos(dpQos);
|
||||
m_domainParticipant->default_datareader_qos(DDS::QosProfile::dataReaderDefault(m_connectionType));
|
||||
m_domainParticipant.enable();
|
||||
}
|
||||
catch (const dds::core::Exception &ex)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not enable DomainParticipant: " << ex.what();
|
||||
exit(1);
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
dds::domain::qos::DomainParticipantQos dpQos(m_domainParticipant.qos());
|
||||
DDS::QosProfile::print(dpQos, m_logger);
|
||||
rti::core::policy::EntityName entityName;
|
||||
entityName.name(qAppName().toStdString() + (" - DP ") + std::to_string(m_domainId));
|
||||
dpQos << entityName;
|
||||
m_domainParticipant.qos(dpQos);
|
||||
m_domainParticipant->default_datareader_qos(DDS::QosProfile::dataReaderDefault(m_connectionType));
|
||||
m_domainParticipant.enable();
|
||||
}
|
||||
catch (const dds::core::Exception& ex)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not enable DomainParticipant: " << ex.what();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void DdsConnector::setPublisher(Publisher *publisher)
|
||||
void DdsConnector::setPublisher(Publisher* publisher)
|
||||
{
|
||||
if (m_publisher && publisher != m_publisher)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Trying to set publisher but there is already a publisher set - overwriting!";
|
||||
delete m_publisher;
|
||||
}
|
||||
m_publisher = publisher;
|
||||
if (m_publisher)
|
||||
DDS::QosProfile::print(m_publisher->getDdsPublisher().default_datawriter_qos(), m_logger);
|
||||
if (m_publisher && publisher != m_publisher)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Trying to set publisher but there is already a publisher set - overwriting!";
|
||||
delete m_publisher;
|
||||
}
|
||||
m_publisher = publisher;
|
||||
if (m_publisher)
|
||||
DDS::QosProfile::print(m_publisher->getDdsPublisher().default_datawriter_qos(), m_logger);
|
||||
}
|
||||
|
||||
void DdsConnector::enableBatchedWriter(bool bEnable)
|
||||
{
|
||||
if (m_publisher)
|
||||
m_publisher->enableBatchedWriter(bEnable);
|
||||
if (m_publisher)
|
||||
m_publisher->enableBatchedWriter(bEnable);
|
||||
}
|
||||
|
||||
|
||||
void DdsConnector::setSubscriber(Subscriber *subscriber)
|
||||
void DdsConnector::setSubscriber(Subscriber* subscriber)
|
||||
{
|
||||
if (m_subscriber && subscriber != m_subscriber)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Trying to set subscriber but there is already a subscriber set - overwriting!";
|
||||
delete m_subscriber;
|
||||
}
|
||||
m_subscriber = subscriber;
|
||||
if (m_subscriber)
|
||||
DDS::QosProfile::print(m_subscriber->getDdsSubscriber().default_datareader_qos(), m_logger);
|
||||
if (m_subscriber && subscriber != m_subscriber)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Trying to set subscriber but there is already a subscriber set - overwriting!";
|
||||
delete m_subscriber;
|
||||
}
|
||||
m_subscriber = subscriber;
|
||||
if (m_subscriber)
|
||||
DDS::QosProfile::print(m_subscriber->getDdsSubscriber().default_datareader_qos(), m_logger);
|
||||
}
|
||||
|
||||
void DdsConnector::initInternal()
|
||||
{
|
||||
if (m_tcpConnectionUrl.isValid())
|
||||
{
|
||||
m_connectionType = DDS::QosProfile::ConnectionType::Tcp;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tcpConnectionUrl.clear();
|
||||
if (m_connectionType == DDS::QosProfile::ConnectionType::Tcp)
|
||||
m_connectionType = DDS::QosProfile::ConnectionType::ShmUdp;
|
||||
}
|
||||
if (m_tcpConnectionUrl.isValid())
|
||||
{
|
||||
m_connectionType = DDS::QosProfile::ConnectionType::Tcp;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tcpConnectionUrl.clear();
|
||||
if (m_connectionType == DDS::QosProfile::ConnectionType::Tcp)
|
||||
m_connectionType = DDS::QosProfile::ConnectionType::ShmUdp;
|
||||
}
|
||||
|
||||
if (m_defaultPartitionType == IDL::PartitionType::Any ||
|
||||
m_defaultPartitionType == IDL::PartitionType::AllExercises)
|
||||
m_partitionId = -1;
|
||||
if (m_defaultPartitionType == IDL::PartitionType::Exercise && m_partitionId < 0)
|
||||
WARNING_LOG(m_logger) << "Want to subscribe to an exercise, but no exercise Id is given!";
|
||||
if (m_defaultPartitionType == IDL::PartitionType::Global)
|
||||
{
|
||||
m_partitionId = 0;
|
||||
m_exerciseId = 0;
|
||||
}
|
||||
INFO_LOG(m_logger) << "DDSConnector(" << m_domainId << ") for partition: " << m_partitionId
|
||||
<< " with partition type " << static_cast<int>(m_defaultPartitionType);
|
||||
if (m_defaultPartitionType == IDL::PartitionType::Any || m_defaultPartitionType == IDL::PartitionType::AllExercises)
|
||||
m_partitionId = -1;
|
||||
if (m_defaultPartitionType == IDL::PartitionType::Exercise && m_partitionId < 0)
|
||||
WARNING_LOG(m_logger) << "Want to subscribe to an exercise, but no exercise Id is given!";
|
||||
if (m_defaultPartitionType == IDL::PartitionType::Global)
|
||||
{
|
||||
m_partitionId = 0;
|
||||
m_exerciseId = 0;
|
||||
}
|
||||
INFO_LOG(m_logger) << "DDSConnector(" << m_domainId << ") for partition: " << m_partitionId
|
||||
<< " with partition type " << static_cast<int>(m_defaultPartitionType);
|
||||
|
||||
|
||||
dds::domain::qos::DomainParticipantFactoryQos domainParticipantFactoryQos = dds::domain::DomainParticipant::participant_factory_qos();
|
||||
|
||||
domainParticipantFactoryQos << dds::core::policy::EntityFactory::ManuallyEnable();
|
||||
dds::domain::DomainParticipant::participant_factory_qos(domainParticipantFactoryQos);
|
||||
dds::domain::qos::DomainParticipantFactoryQos domainParticipantFactoryQos =
|
||||
dds::domain::DomainParticipant::participant_factory_qos();
|
||||
|
||||
domainParticipantFactoryQos << dds::core::policy::EntityFactory::ManuallyEnable();
|
||||
dds::domain::DomainParticipant::participant_factory_qos(domainParticipantFactoryQos);
|
||||
}
|
||||
|
||||
|
||||
void DdsConnector::createWaitSetHandler()
|
||||
{
|
||||
if (!m_wsHandler)
|
||||
m_wsHandler = new DDSGeneric::WaitSetHandler;
|
||||
if (!m_wsHandler)
|
||||
m_wsHandler = new DDSGeneric::WaitSetHandler;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace DDSConnector
|
||||
Executable → Regular
+146
-157
@@ -2,33 +2,36 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <DDS/Generic/generic_base.h>
|
||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||
#include <QUrl>
|
||||
#include <QtCore/QStringList>
|
||||
#include <dds/pub/CoherentSet.hpp>
|
||||
#include <dds/pub/Publisher.hpp>
|
||||
#include <dds/sub/Subscriber.hpp>
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||
#include <ddsconnector_export.h>
|
||||
#include <DDS/Generic/generic_base.h>
|
||||
#include <QUrl>
|
||||
|
||||
class QObject;
|
||||
|
||||
namespace DDS
|
||||
{
|
||||
namespace QosProfile
|
||||
{
|
||||
enum class ConnectionType;
|
||||
}
|
||||
}
|
||||
} // namespace DDS
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
namespace DDSGeneric
|
||||
{
|
||||
class WaitSetHandler;
|
||||
class SubscriberListener;
|
||||
}
|
||||
} // namespace DDSGeneric
|
||||
|
||||
namespace DDSConnector
|
||||
{
|
||||
class Publisher;
|
||||
@@ -36,181 +39,167 @@ class Subscriber;
|
||||
|
||||
class DDSCONNECTOR_EXPORT DdsConnector
|
||||
{
|
||||
DdsConnector(int domainId,
|
||||
const dds::domain::DomainParticipant &domainParticipant,
|
||||
IDL::PartitionType defaultPartitionType,
|
||||
int partitionId,
|
||||
int exerciseId,
|
||||
DDS::QosProfile::ConnectionType connectionType,
|
||||
const QUrl &tcpConnectionUrl);
|
||||
public:
|
||||
DdsConnector(const DdsConnector &) = delete;
|
||||
DdsConnector &operator=(const DdsConnector &) = delete;
|
||||
DdsConnector(int domainId, const dds::domain::DomainParticipant& domainParticipant,
|
||||
IDL::PartitionType defaultPartitionType, int partitionId, int exerciseId,
|
||||
DDS::QosProfile::ConnectionType connectionType, const QUrl& tcpConnectionUrl);
|
||||
|
||||
|
||||
public:
|
||||
DdsConnector(const DdsConnector&) = delete;
|
||||
DdsConnector& operator=(const DdsConnector&) = delete;
|
||||
|
||||
DdsConnector(int domainId,
|
||||
IDL::PartitionType defaultPartitionType,
|
||||
int partitionId = 0,
|
||||
int exerciseId = 0,
|
||||
const QUrl &tcpConnectionUrl = QUrl());
|
||||
|
||||
DdsConnector(int domainId, IDL::PartitionType defaultPartitionType, int partitionId = 0, int exerciseId = 0,
|
||||
const QUrl& tcpConnectionUrl = QUrl());
|
||||
|
||||
DdsConnector(const dds::domain::DomainParticipant &domainParticipant,
|
||||
IDL::PartitionType defaultPartitionType,
|
||||
int partitionId = 0,
|
||||
int exerciseId = 0,
|
||||
const QUrl &tcpConnectionUrl = QUrl());
|
||||
DdsConnector(const dds::domain::DomainParticipant& domainParticipant, IDL::PartitionType defaultPartitionType,
|
||||
int partitionId = 0, int exerciseId = 0, const QUrl& tcpConnectionUrl = QUrl());
|
||||
|
||||
DdsConnector(const dds::domain::DomainParticipant &domainParticipant,
|
||||
IDL::PartitionType defaultPartitionType,
|
||||
DDS::QosProfile::ConnectionType connectionType,
|
||||
int partitionId = 0,
|
||||
int exerciseId = 0);
|
||||
DdsConnector(const dds::domain::DomainParticipant& domainParticipant, IDL::PartitionType defaultPartitionType,
|
||||
DDS::QosProfile::ConnectionType connectionType, int partitionId = 0, int exerciseId = 0);
|
||||
|
||||
DdsConnector(int domainId,
|
||||
IDL::PartitionType defaultPartitionType,
|
||||
int partitionId,
|
||||
int exerciseId,
|
||||
DDS::QosProfile::ConnectionType connectionType);
|
||||
DdsConnector(int domainId, IDL::PartitionType defaultPartitionType, int partitionId, int exerciseId,
|
||||
DDS::QosProfile::ConnectionType connectionType);
|
||||
|
||||
virtual ~DdsConnector();
|
||||
virtual ~DdsConnector();
|
||||
|
||||
|
||||
virtual bool init(const QStringList& qosFileList = QStringList());
|
||||
|
||||
virtual bool init(const QStringList &qosFileList = QStringList());
|
||||
dds::domain::DomainParticipant getDomainParticipant() const
|
||||
{
|
||||
return m_domainParticipant;
|
||||
}
|
||||
|
||||
dds::domain::DomainParticipant getDomainParticipant() const { return m_domainParticipant; }
|
||||
void setDomainParticipant(const dds::domain::DomainParticipant &participant);
|
||||
void setDomainParticipant(const dds::domain::DomainParticipant& participant);
|
||||
|
||||
Publisher *getPublisher() { return m_publisher; }
|
||||
dds::pub::Publisher getDdsPublisher() const;
|
||||
void setPublisher(Publisher *publisher);
|
||||
void enableBatchedWriter(bool bEnable);
|
||||
Publisher* getPublisher()
|
||||
{
|
||||
return m_publisher;
|
||||
}
|
||||
|
||||
Subscriber *getSubscriber() { return m_subscriber; }
|
||||
dds::sub::Subscriber getDdsSubscriber() const;
|
||||
void setSubscriber(Subscriber *subscriber);
|
||||
DDSGeneric::SubscriberListener *getSubscriberListener();
|
||||
dds::pub::Publisher getDdsPublisher() const;
|
||||
void setPublisher(Publisher* publisher);
|
||||
void enableBatchedWriter(bool bEnable);
|
||||
|
||||
const DDSGeneric::WaitSetHandler *getWaitSetHandler() const { return m_wsHandler; }
|
||||
Subscriber* getSubscriber()
|
||||
{
|
||||
return m_subscriber;
|
||||
}
|
||||
|
||||
int getDomainId() const { return m_domainId; }
|
||||
IDL::PartitionType getPartitionType() const { return m_defaultPartitionType; }
|
||||
int getPartitionId() const { return m_partitionId; }
|
||||
int getExerciseId() const { return m_exerciseId; }
|
||||
std::string getDefaultPartition() const;
|
||||
QUrl getTcpConnectionUrl() const;
|
||||
static std::string getPartitionString(IDL::PartitionType pt, int partitionId = -1);
|
||||
dds::sub::Subscriber getDdsSubscriber() const;
|
||||
void setSubscriber(Subscriber* subscriber);
|
||||
DDSGeneric::SubscriberListener* getSubscriberListener();
|
||||
|
||||
|
||||
const DDSGeneric::WaitSetHandler* getWaitSetHandler() const
|
||||
{
|
||||
return m_wsHandler;
|
||||
}
|
||||
|
||||
void initPublisherSubscriber();
|
||||
void initPublisher();
|
||||
void initSubscriber();
|
||||
void initDomainParticipant();
|
||||
int getDomainId() const
|
||||
{
|
||||
return m_domainId;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *createDTS(const std::string &topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<typename T::TopicType>::value()))
|
||||
{
|
||||
if (getDomainParticipant() == nullptr ||
|
||||
getDdsPublisher() == nullptr)
|
||||
return nullptr;
|
||||
T *dts = new T(getDomainParticipant(),
|
||||
getDdsPublisher(),
|
||||
topicName);
|
||||
return dts;
|
||||
}
|
||||
IDL::PartitionType getPartitionType() const
|
||||
{
|
||||
return m_defaultPartitionType;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *createDTC(const std::string &topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<typename T::TopicType>::value()))
|
||||
{
|
||||
if (getDomainParticipant() == nullptr ||
|
||||
getDdsSubscriber() == nullptr)
|
||||
return nullptr;
|
||||
T *dtc = new T(getDomainParticipant(),
|
||||
getDdsSubscriber(),
|
||||
getSubscriberListener(),
|
||||
topicName);
|
||||
return dtc;
|
||||
}
|
||||
int getPartitionId() const
|
||||
{
|
||||
return m_partitionId;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *createDTC(const dds::topic::Filter &filter,
|
||||
const std::string &topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<typename T::TopicType>::value()))
|
||||
{
|
||||
if (getDomainParticipant() == nullptr ||
|
||||
getDdsSubscriber() == nullptr)
|
||||
return nullptr;
|
||||
T *dtc = new T(getDomainParticipant(),
|
||||
getDdsSubscriber(),
|
||||
getSubscriberListener(),
|
||||
filter,
|
||||
topicName);
|
||||
return dtc;
|
||||
}
|
||||
int getExerciseId() const
|
||||
{
|
||||
return m_exerciseId;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *createFTS()
|
||||
{
|
||||
if (getDomainParticipant() == nullptr ||
|
||||
getDdsPublisher() == nullptr ||
|
||||
getDdsSubscriber() == nullptr)
|
||||
return nullptr;
|
||||
createWaitSetHandler();
|
||||
T *fts = new T(getDomainParticipant(),
|
||||
getDdsPublisher(),
|
||||
getDdsSubscriber(),
|
||||
m_wsHandler);
|
||||
return fts;
|
||||
}
|
||||
std::string getDefaultPartition() const;
|
||||
QUrl getTcpConnectionUrl() const;
|
||||
static std::string getPartitionString(IDL::PartitionType pt, int partitionId = -1);
|
||||
|
||||
template<typename T>
|
||||
T *createFTC(QObject *objToInform)
|
||||
{
|
||||
if (getDomainParticipant() == nullptr ||
|
||||
getDdsPublisher() == nullptr ||
|
||||
getDdsSubscriber() == nullptr)
|
||||
return nullptr;
|
||||
T *ftc = new T(getDomainParticipant(),
|
||||
getDdsPublisher(),
|
||||
getDdsSubscriber(),
|
||||
objToInform,
|
||||
IDL::toStdString(m_defaultPartitionType),
|
||||
m_partitionId);
|
||||
return ftc;
|
||||
}
|
||||
void initPublisherSubscriber();
|
||||
void initPublisher();
|
||||
void initSubscriber();
|
||||
void initDomainParticipant();
|
||||
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
void initInternal();
|
||||
void createWaitSetHandler();
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
int m_domainId;
|
||||
IDL::PartitionType m_defaultPartitionType;
|
||||
int m_partitionId;
|
||||
int m_exerciseId;
|
||||
template <typename T>
|
||||
T* createDTS(const std::string& topicName =
|
||||
DDS::Helper::getShortTopicName(DDS::topic_type_name<typename T::TopicType>::value()))
|
||||
{
|
||||
if (getDomainParticipant() == nullptr || getDdsPublisher() == nullptr)
|
||||
return nullptr;
|
||||
T* dts = new T(getDomainParticipant(), getDdsPublisher(), topicName);
|
||||
return dts;
|
||||
}
|
||||
|
||||
QUrl m_tcpConnectionUrl;
|
||||
DDS::QosProfile::ConnectionType m_connectionType;
|
||||
dds::domain::DomainParticipant m_domainParticipant;
|
||||
DDSConnector::Publisher *m_publisher;
|
||||
DDSConnector::Subscriber *m_subscriber;
|
||||
DDSGeneric::WaitSetHandler *m_wsHandler;
|
||||
template <typename T>
|
||||
T* createDTC(const std::string& topicName =
|
||||
DDS::Helper::getShortTopicName(DDS::topic_type_name<typename T::TopicType>::value()))
|
||||
{
|
||||
if (getDomainParticipant() == nullptr || getDdsSubscriber() == nullptr)
|
||||
return nullptr;
|
||||
T* dtc = new T(getDomainParticipant(), getDdsSubscriber(), getSubscriberListener(), topicName);
|
||||
return dtc;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* createDTC(const dds::topic::Filter& filter, const std::string& topicName = DDS::Helper::getShortTopicName(
|
||||
DDS::topic_type_name<typename T::TopicType>::value()))
|
||||
{
|
||||
if (getDomainParticipant() == nullptr || getDdsSubscriber() == nullptr)
|
||||
return nullptr;
|
||||
T* dtc = new T(getDomainParticipant(), getDdsSubscriber(), getSubscriberListener(), filter, topicName);
|
||||
return dtc;
|
||||
}
|
||||
|
||||
template <typename T> T* createFTS()
|
||||
{
|
||||
if (getDomainParticipant() == nullptr || getDdsPublisher() == nullptr || getDdsSubscriber() == nullptr)
|
||||
return nullptr;
|
||||
createWaitSetHandler();
|
||||
T* fts = new T(getDomainParticipant(), getDdsPublisher(), getDdsSubscriber(), m_wsHandler);
|
||||
return fts;
|
||||
}
|
||||
|
||||
template <typename T> T* createFTC(QObject* objToInform)
|
||||
{
|
||||
if (getDomainParticipant() == nullptr || getDdsPublisher() == nullptr || getDdsSubscriber() == nullptr)
|
||||
return nullptr;
|
||||
T* ftc = new T(getDomainParticipant(), getDdsPublisher(), getDdsSubscriber(), objToInform,
|
||||
IDL::toStdString(m_defaultPartitionType), m_partitionId);
|
||||
return ftc;
|
||||
}
|
||||
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void initInternal();
|
||||
void createWaitSetHandler();
|
||||
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
int m_domainId;
|
||||
IDL::PartitionType m_defaultPartitionType;
|
||||
int m_partitionId;
|
||||
int m_exerciseId;
|
||||
|
||||
QUrl m_tcpConnectionUrl;
|
||||
DDS::QosProfile::ConnectionType m_connectionType;
|
||||
dds::domain::DomainParticipant m_domainParticipant;
|
||||
DDSConnector::Publisher* m_publisher;
|
||||
DDSConnector::Subscriber* m_subscriber;
|
||||
DDSGeneric::WaitSetHandler* m_wsHandler;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CoherentSet
|
||||
{
|
||||
public:
|
||||
explicit CoherentSet(const std::shared_ptr<DdsConnector> &connector)
|
||||
: m_coherentSet(connector->getDdsPublisher())
|
||||
{}
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
dds::pub::CoherentSet m_coherentSet;
|
||||
public:
|
||||
explicit CoherentSet(const std::shared_ptr<DdsConnector>& connector) : m_coherentSet(connector->getDdsPublisher())
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
dds::pub::CoherentSet m_coherentSet;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace DDSConnector
|
||||
Executable → Regular
+23
-18
@@ -2,11 +2,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dds/domain/DomainParticipant.hpp>
|
||||
#include <ddsconnector_export.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <dds/domain/DomainParticipant.hpp>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
@@ -17,23 +16,29 @@ namespace DDSConnector
|
||||
{
|
||||
class DDSCONNECTOR_EXPORT PubSubBase
|
||||
{
|
||||
protected:
|
||||
NGL::INGLLogger &m_logger;
|
||||
PubSubBase(const dds::domain::DomainParticipant &domainParticipant,
|
||||
const std::string &partition,
|
||||
const char *loggerName);
|
||||
public:
|
||||
virtual ~PubSubBase() = default;
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
PubSubBase(const dds::domain::DomainParticipant& domainParticipant, const std::string& partition,
|
||||
const char* loggerName);
|
||||
|
||||
void setDomainParticipant(const dds::domain::DomainParticipant &domainParticipant) { m_domainParticipant = domainParticipant; }
|
||||
const dds::domain::DomainParticipant &getDomainParticipant() const { return m_domainParticipant; }
|
||||
public:
|
||||
virtual ~PubSubBase() = default;
|
||||
|
||||
protected:
|
||||
template<typename P>
|
||||
void updatePartitionQoS(P &pubSub);
|
||||
void setDomainParticipant(const dds::domain::DomainParticipant& domainParticipant)
|
||||
{
|
||||
m_domainParticipant = domainParticipant;
|
||||
}
|
||||
|
||||
protected:
|
||||
dds::domain::DomainParticipant m_domainParticipant;
|
||||
std::vector<std::string> m_partitions;
|
||||
const dds::domain::DomainParticipant& getDomainParticipant() const
|
||||
{
|
||||
return m_domainParticipant;
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename P> void updatePartitionQoS(P& pubSub);
|
||||
|
||||
protected:
|
||||
dds::domain::DomainParticipant m_domainParticipant;
|
||||
std::vector<std::string> m_partitions;
|
||||
};
|
||||
}
|
||||
} // namespace DDSConnector
|
||||
Executable → Regular
+33
-38
@@ -1,9 +1,7 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <LtsUtilsCore/data_modification_enum.h>
|
||||
|
||||
#include <dds/sub/LoanedSamples.hpp>
|
||||
|
||||
namespace NGLLogger
|
||||
@@ -15,52 +13,49 @@ namespace DTC
|
||||
{
|
||||
class SubscriberListener;
|
||||
|
||||
template <typename DRO_OBJECT, typename SC>
|
||||
class GenericDtcSC
|
||||
template <typename DRO_OBJECT, typename SC> class GenericDtcSC
|
||||
{
|
||||
public:
|
||||
using DataReaderObject = DRO_OBJECT;
|
||||
using SubscriberCallback = SC;
|
||||
using TopicType = typename DRO_OBJECT::TopicType;
|
||||
public:
|
||||
using DataReaderObject = DRO_OBJECT;
|
||||
using SubscriberCallback = SC;
|
||||
using TopicType = typename DRO_OBJECT::TopicType;
|
||||
|
||||
GenericDtcSC() = default;
|
||||
virtual ~GenericDtcSC() = default;
|
||||
GenericDtcSC() = default;
|
||||
virtual ~GenericDtcSC() = default;
|
||||
|
||||
virtual bool setSubscriberCallback(const SubscriberCallback &subscriberCallback) = 0;
|
||||
virtual dds::sub::LoanedSamples<TopicType> readAlive() const = 0;
|
||||
virtual dds::sub::LoanedSamples<TopicType> takeAlive() const = 0;
|
||||
virtual dds::sub::LoanedSamples<TopicType> takeDisposed() const = 0;
|
||||
virtual bool hasSamples() const = 0;
|
||||
virtual DataReaderObject *dataReader() const = 0;
|
||||
virtual bool waitForHistoricalData(int timeoutMSec) = 0;
|
||||
virtual bool setSubscriberCallback(const SubscriberCallback& subscriberCallback) = 0;
|
||||
virtual dds::sub::LoanedSamples<TopicType> readAlive() const = 0;
|
||||
virtual dds::sub::LoanedSamples<TopicType> takeAlive() const = 0;
|
||||
virtual dds::sub::LoanedSamples<TopicType> takeDisposed() const = 0;
|
||||
virtual bool hasSamples() const = 0;
|
||||
virtual DataReaderObject* dataReader() const = 0;
|
||||
virtual bool waitForHistoricalData(int timeoutMSec) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename DRO_OBJECT>
|
||||
template <typename DRO_OBJECT>
|
||||
class GenericDtc
|
||||
: public GenericDtcSC<DRO_OBJECT,
|
||||
std::function<void(const typename DRO_OBJECT::TopicType &, DataModification)> >
|
||||
{};
|
||||
: public GenericDtcSC<DRO_OBJECT, std::function<void(const typename DRO_OBJECT::TopicType&, DataModification)>>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template<typename DRO_OBJECT>
|
||||
template <typename DRO_OBJECT>
|
||||
class GenericDtcSampleInfo
|
||||
: public GenericDtcSC<DRO_OBJECT,
|
||||
std::function<void(const typename DRO_OBJECT::TopicType &, const dds::sub::SampleInfo &)> >
|
||||
{};
|
||||
std::function<void(const typename DRO_OBJECT::TopicType&, const dds::sub::SampleInfo&)>>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template<typename DRO_OBJECT>
|
||||
template <typename DRO_OBJECT>
|
||||
class Ddtc
|
||||
: public GenericDtcSC<DRO_OBJECT,
|
||||
std::function<void(const typename DRO_OBJECT::TopicType &, const std::string &, DataModification)> >
|
||||
{};
|
||||
: public GenericDtcSC<
|
||||
DRO_OBJECT, std::function<void(const typename DRO_OBJECT::TopicType&, const std::string&, DataModification)>>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template<typename DRO_OBJECT>
|
||||
template <typename DRO_OBJECT>
|
||||
class DdtcSampleInfo
|
||||
: public GenericDtcSC<DRO_OBJECT,
|
||||
std::function<void(const typename DRO_OBJECT::TopicType &, const std::string &, const dds::sub::SampleInfo &)> >
|
||||
{};
|
||||
}
|
||||
: public GenericDtcSC<DRO_OBJECT, std::function<void(const typename DRO_OBJECT::TopicType&, const std::string&,
|
||||
const dds::sub::SampleInfo&)>>
|
||||
{
|
||||
};
|
||||
} // namespace DTC
|
||||
Executable → Regular
+240
-257
@@ -1,311 +1,294 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "generic_dtc.h"
|
||||
|
||||
#include <DDS/Generic/generic_data_reader.h>
|
||||
#include <DDS/Generic/subscriber_listener.h>
|
||||
#include <QTimer>
|
||||
|
||||
#include <dds/core/cond/StatusCondition.hpp>
|
||||
#include <dds/core/cond/WaitSet.hpp>
|
||||
|
||||
#include "generic_dtc.h"
|
||||
|
||||
|
||||
namespace DDSGeneric
|
||||
{
|
||||
class DynamicDataReader;
|
||||
}
|
||||
|
||||
namespace DTC
|
||||
{
|
||||
|
||||
template<typename SuperClass>
|
||||
template <typename SuperClass>
|
||||
class GenericDtcImplSubscriberTemplate : public DDSGeneric::SubscriberListenerCallback, public SuperClass
|
||||
{
|
||||
public:
|
||||
using DataReaderObject = typename SuperClass::DataReaderObject;
|
||||
using SubscriberCallback = typename SuperClass::SubscriberCallback;
|
||||
using TopicTypeRead = typename DataReaderObject::TopicType;
|
||||
using TopicTypeSubscribe = typename DataReaderObject::TopicType;
|
||||
using DataReader = typename DataReaderObject::DataReader;
|
||||
public:
|
||||
using DataReaderObject = typename SuperClass::DataReaderObject;
|
||||
using SubscriberCallback = typename SuperClass::SubscriberCallback;
|
||||
using TopicTypeRead = typename DataReaderObject::TopicType;
|
||||
using TopicTypeSubscribe = typename DataReaderObject::TopicType;
|
||||
using DataReader = typename DataReaderObject::DataReader;
|
||||
|
||||
GenericDtcImplSubscriberTemplate(const dds::domain::DomainParticipant &domainParticipant,
|
||||
const dds::sub::Subscriber &ddsSubscriber,
|
||||
DDSGeneric::SubscriberListener *subscriberListener,
|
||||
const std::string &topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<TopicTypeRead>::value()))
|
||||
: m_subscriberListener(subscriberListener)
|
||||
, m_dataReaderObject(new DataReaderObject)
|
||||
, m_subscriberCallback(nullptr)
|
||||
, m_writerState(0)
|
||||
, m_logger(DDS::getLogger(DDS::topic_type_name<TopicTypeRead>::value(), DDS::DataType::DATA_TOPIC_CLIENT))
|
||||
{
|
||||
createInternal(m_dataReaderObject->create(domainParticipant, ddsSubscriber, topicName));
|
||||
}
|
||||
|
||||
GenericDtcImplSubscriberTemplate(const dds::domain::DomainParticipant &domainParticipant,
|
||||
const dds::sub::Subscriber &ddsSubscriber,
|
||||
DDSGeneric::SubscriberListener *subscriberListener,
|
||||
const dds::topic::Filter &filter,
|
||||
const std::string &topicName)
|
||||
: m_subscriberListener(subscriberListener)
|
||||
, m_dataReaderObject(new DataReaderObject)
|
||||
, m_subscriberCallback(nullptr)
|
||||
, m_writerState(0)
|
||||
, m_logger(DDS::getLogger(DDS::topic_type_name<TopicTypeRead>::value(), DDS::DataType::DATA_TOPIC_CLIENT))
|
||||
{
|
||||
createInternal(m_dataReaderObject->create(domainParticipant, ddsSubscriber, topicName, filter));
|
||||
}
|
||||
|
||||
GenericDtcImplSubscriberTemplate(const dds::domain::DomainParticipant &domainParticipant,
|
||||
const dds::sub::Subscriber &ddsSubscriber,
|
||||
DDSGeneric::SubscriberListener *subscriberListener,
|
||||
const dds::core::xtypes::StructType &structType,
|
||||
const std::string &topicName)
|
||||
: m_subscriberListener(subscriberListener)
|
||||
, m_dataReaderObject(new DataReaderObject)
|
||||
, m_subscriberCallback(nullptr)
|
||||
, m_logger(DDS::getLogger(DDS::topic_type_name<TopicTypeRead>::value(), DDS::DataType::DATA_TOPIC_CLIENT))
|
||||
{
|
||||
createInternal(m_dataReaderObject->create(domainParticipant, ddsSubscriber, topicName, structType));
|
||||
}
|
||||
|
||||
~GenericDtcImplSubscriberTemplate()
|
||||
{
|
||||
if (m_dataReaderObject && m_subscriberCallback)
|
||||
m_subscriberListener->removeCallback(m_dataReaderObject->getDataReader(), this);
|
||||
delete m_dataReaderObject;
|
||||
}
|
||||
|
||||
bool setSubscriberCallback(const SubscriberCallback &subscriberCallback) override final
|
||||
{
|
||||
if (m_subscriberCallback)
|
||||
GenericDtcImplSubscriberTemplate(
|
||||
const dds::domain::DomainParticipant& domainParticipant, const dds::sub::Subscriber& ddsSubscriber,
|
||||
DDSGeneric::SubscriberListener* subscriberListener,
|
||||
const std::string& topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<TopicTypeRead>::value()))
|
||||
: m_subscriberListener(subscriberListener), m_dataReaderObject(new DataReaderObject),
|
||||
m_subscriberCallback(nullptr), m_writerState(0),
|
||||
m_logger(DDS::getLogger(DDS::topic_type_name<TopicTypeRead>::value(), DDS::DataType::DATA_TOPIC_CLIENT))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Can not set subscriber callback - already set ...";
|
||||
return false;
|
||||
}
|
||||
if (!m_subscriberListener)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Can not set subscriber callback - no subscriber listener ...";
|
||||
return false;
|
||||
createInternal(m_dataReaderObject->create(domainParticipant, ddsSubscriber, topicName));
|
||||
}
|
||||
|
||||
m_subscriberCallback = subscriberCallback;
|
||||
|
||||
if (!m_dataReaderObject)
|
||||
GenericDtcImplSubscriberTemplate(const dds::domain::DomainParticipant& domainParticipant,
|
||||
const dds::sub::Subscriber& ddsSubscriber,
|
||||
DDSGeneric::SubscriberListener* subscriberListener,
|
||||
const dds::topic::Filter& filter, const std::string& topicName)
|
||||
: m_subscriberListener(subscriberListener), m_dataReaderObject(new DataReaderObject),
|
||||
m_subscriberCallback(nullptr), m_writerState(0),
|
||||
m_logger(DDS::getLogger(DDS::topic_type_name<TopicTypeRead>::value(), DDS::DataType::DATA_TOPIC_CLIENT))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Can not set subscriber callback - no data reader object ...";
|
||||
return false;
|
||||
createInternal(m_dataReaderObject->create(domainParticipant, ddsSubscriber, topicName, filter));
|
||||
}
|
||||
|
||||
m_dataReaderObject->setHaveSubscriberCallback(m_subscriberCallback != nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> readAlive() const override final
|
||||
{
|
||||
if (!m_dataReaderObject)
|
||||
return dds::sub::LoanedSamples<TopicTypeRead>();
|
||||
|
||||
bool bSeenUnreadSamples = false;
|
||||
auto ret = m_dataReaderObject->readAlive(bSeenUnreadSamples);
|
||||
if (bSeenUnreadSamples)
|
||||
QTimer::singleShot(0, this, &GenericDtcImplSubscriberTemplate::unreadSamplesDuringRead);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> takeAlive() const override final
|
||||
{
|
||||
if (!m_dataReaderObject)
|
||||
return dds::sub::LoanedSamples<TopicTypeRead>();
|
||||
|
||||
bool bSeenUnreadSamples = false;
|
||||
auto ret = m_dataReaderObject->takeAlive(bSeenUnreadSamples);
|
||||
if (bSeenUnreadSamples)
|
||||
QTimer::singleShot(0, this, &GenericDtcImplSubscriberTemplate::unreadSamplesDuringRead);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> takeDisposed() const override final
|
||||
{
|
||||
if (!m_dataReaderObject)
|
||||
return dds::sub::LoanedSamples<TopicTypeRead>();
|
||||
|
||||
return m_dataReaderObject->takeDisposed();
|
||||
}
|
||||
|
||||
bool hasSamples() const override final
|
||||
{
|
||||
if (!m_dataReaderObject)
|
||||
return false;
|
||||
|
||||
return m_dataReaderObject->hasSamples();
|
||||
}
|
||||
|
||||
DataReaderObject *dataReader() const override final
|
||||
{
|
||||
return m_dataReaderObject;
|
||||
}
|
||||
|
||||
bool waitForHistoricalData(int timeoutMSec) override
|
||||
{
|
||||
if (m_dataReaderObject == nullptr ||
|
||||
m_dataReaderObject->getDataReader() == nullptr)
|
||||
return false;
|
||||
|
||||
const bool bWaitForever = (timeoutMSec < 0);
|
||||
auto dr = m_dataReaderObject->getDataReader();
|
||||
try
|
||||
GenericDtcImplSubscriberTemplate(const dds::domain::DomainParticipant& domainParticipant,
|
||||
const dds::sub::Subscriber& ddsSubscriber,
|
||||
DDSGeneric::SubscriberListener* subscriberListener,
|
||||
const dds::core::xtypes::StructType& structType, const std::string& topicName)
|
||||
: m_subscriberListener(subscriberListener), m_dataReaderObject(new DataReaderObject),
|
||||
m_subscriberCallback(nullptr),
|
||||
m_logger(DDS::getLogger(DDS::topic_type_name<TopicTypeRead>::value(), DDS::DataType::DATA_TOPIC_CLIENT))
|
||||
{
|
||||
if (dr.subscription_matched_status().current_count() == 0)
|
||||
{
|
||||
dds::core::cond::WaitSet ws;
|
||||
dds::core::cond::StatusCondition cond(dr);
|
||||
cond.enabled_statuses(dds::core::status::StatusMask::subscription_matched());
|
||||
ws.attach_condition(cond);
|
||||
const dds::core::Duration waitTimeout(bWaitForever ? dds::core::Duration::infinite() : dds::core::Duration::from_millisecs(timeoutMSec));
|
||||
const dds::core::cond::WaitSet::ConditionSeq seq(ws.wait(waitTimeout));
|
||||
|
||||
if (seq.empty())
|
||||
return false;
|
||||
}
|
||||
dr.wait_for_historical_data(dds::core::Duration(1));
|
||||
}
|
||||
catch (const dds::core::Exception &)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
void unreadSamplesDuringRead()
|
||||
{
|
||||
droDataAvailable(DDS::topic_type_name<TopicTypeRead>::value(), m_dataReaderObject->topicName());
|
||||
}
|
||||
|
||||
void droDataAvailable(const std::string &topicType, const std::string &topicName) override final
|
||||
{
|
||||
Q_UNUSED(topicType);
|
||||
if (m_writerState.testAndSetRelaxed(1, 0))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Recreate Reader for topic " << topicName
|
||||
<< ", type name " << DDS::topic_type_name<TopicTypeRead>::value();
|
||||
if (m_subscriberListener)
|
||||
m_subscriberListener->removeCallback(m_dataReaderObject->getDataReader(), this);
|
||||
m_dataReaderObject->recreateReader();
|
||||
if (m_subscriberListener)
|
||||
m_subscriberListener->addCallback(m_dataReaderObject->getDataReader(), this);
|
||||
createInternal(m_dataReaderObject->create(domainParticipant, ddsSubscriber, topicName, structType));
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "IN droDataAvailable(), topic name: " << topicName
|
||||
<< ", type name " << DDS::topic_type_name<TopicTypeRead>::value()
|
||||
<< ", this: " << this
|
||||
<< ", m_dataReaderObject: " << m_dataReaderObject
|
||||
<< ", hasSamples: " << (m_dataReaderObject ? m_dataReaderObject->hasSamples() : -1);
|
||||
|
||||
if (m_subscriberListener)
|
||||
m_subscriberListener->enableCallback(m_dataReaderObject->getDataReader(), this);
|
||||
|
||||
if (!m_dataReaderObject || !m_subscriberCallback)
|
||||
return;
|
||||
|
||||
m_dataReaderObject->read(m_subscriberCallback);
|
||||
}
|
||||
|
||||
void noWriterAnymore(const std::string &topicType, const std::string &topicName) override
|
||||
{
|
||||
Q_UNUSED(topicType);
|
||||
Q_UNUSED(topicName);
|
||||
m_writerState = -1;
|
||||
}
|
||||
|
||||
void writerAvailable(const std::string &topicType, const std::string &topicName) override
|
||||
{
|
||||
Q_UNUSED(topicType);
|
||||
Q_UNUSED(topicName);
|
||||
m_writerState.testAndSetRelaxed(-1, 1);
|
||||
}
|
||||
|
||||
bool createInternal(bool droInitOk)
|
||||
{
|
||||
if (!droInitOk)
|
||||
~GenericDtcImplSubscriberTemplate()
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error initializing DRO for type " << DDS::topic_type_name<TopicTypeRead>::value();
|
||||
delete m_dataReaderObject;
|
||||
m_dataReaderObject = nullptr;
|
||||
return false;
|
||||
if (m_dataReaderObject && m_subscriberCallback)
|
||||
m_subscriberListener->removeCallback(m_dataReaderObject->getDataReader(), this);
|
||||
delete m_dataReaderObject;
|
||||
}
|
||||
|
||||
if (m_subscriberListener)
|
||||
bool setSubscriberCallback(const SubscriberCallback& subscriberCallback) override final
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "subscriberListener exists, adding type "
|
||||
<< DDS::topic_type_name<TopicTypeRead>::value();
|
||||
m_subscriberListener->addCallback(m_dataReaderObject->getDataReader(), this);
|
||||
if (m_subscriberCallback)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Can not set subscriber callback - already set ...";
|
||||
return false;
|
||||
}
|
||||
if (!m_subscriberListener)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Can not set subscriber callback - no subscriber listener ...";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_subscriberCallback = subscriberCallback;
|
||||
|
||||
if (!m_dataReaderObject)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Can not set subscriber callback - no data reader object ...";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_dataReaderObject->setHaveSubscriberCallback(m_subscriberCallback != nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> readAlive() const override final
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Cannot add DTC to subscriberListener callback - type: "
|
||||
<< DDS::topic_type_name<TopicTypeRead>::value();
|
||||
if (!m_dataReaderObject)
|
||||
return dds::sub::LoanedSamples<TopicTypeRead>();
|
||||
|
||||
bool bSeenUnreadSamples = false;
|
||||
auto ret = m_dataReaderObject->readAlive(bSeenUnreadSamples);
|
||||
if (bSeenUnreadSamples)
|
||||
QTimer::singleShot(0, this, &GenericDtcImplSubscriberTemplate::unreadSamplesDuringRead);
|
||||
|
||||
return ret;
|
||||
}
|
||||
m_dataReaderObject->setHaveSubscriberCallback(m_subscriberListener != nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
DDSGeneric::SubscriberListener *m_subscriberListener;
|
||||
dds::sub::LoanedSamples<TopicTypeRead> takeAlive() const override final
|
||||
{
|
||||
if (!m_dataReaderObject)
|
||||
return dds::sub::LoanedSamples<TopicTypeRead>();
|
||||
|
||||
|
||||
DataReaderObject *m_dataReaderObject;
|
||||
bool bSeenUnreadSamples = false;
|
||||
auto ret = m_dataReaderObject->takeAlive(bSeenUnreadSamples);
|
||||
if (bSeenUnreadSamples)
|
||||
QTimer::singleShot(0, this, &GenericDtcImplSubscriberTemplate::unreadSamplesDuringRead);
|
||||
|
||||
|
||||
SubscriberCallback m_subscriberCallback;
|
||||
return ret;
|
||||
}
|
||||
|
||||
QAtomicInt m_writerState;
|
||||
dds::sub::LoanedSamples<TopicTypeRead> takeDisposed() const override final
|
||||
{
|
||||
if (!m_dataReaderObject)
|
||||
return dds::sub::LoanedSamples<TopicTypeRead>();
|
||||
|
||||
return m_dataReaderObject->takeDisposed();
|
||||
}
|
||||
|
||||
bool hasSamples() const override final
|
||||
{
|
||||
if (!m_dataReaderObject)
|
||||
return false;
|
||||
|
||||
return m_dataReaderObject->hasSamples();
|
||||
}
|
||||
|
||||
DataReaderObject* dataReader() const override final
|
||||
{
|
||||
return m_dataReaderObject;
|
||||
}
|
||||
|
||||
bool waitForHistoricalData(int timeoutMSec) override
|
||||
{
|
||||
if (m_dataReaderObject == nullptr || m_dataReaderObject->getDataReader() == nullptr)
|
||||
return false;
|
||||
|
||||
const bool bWaitForever = (timeoutMSec < 0);
|
||||
auto dr = m_dataReaderObject->getDataReader();
|
||||
try
|
||||
{
|
||||
if (dr.subscription_matched_status().current_count() == 0)
|
||||
{
|
||||
dds::core::cond::WaitSet ws;
|
||||
dds::core::cond::StatusCondition cond(dr);
|
||||
cond.enabled_statuses(dds::core::status::StatusMask::subscription_matched());
|
||||
ws.attach_condition(cond);
|
||||
const dds::core::Duration waitTimeout(bWaitForever ? dds::core::Duration::infinite()
|
||||
: dds::core::Duration::from_millisecs(timeoutMSec));
|
||||
const dds::core::cond::WaitSet::ConditionSeq seq(ws.wait(waitTimeout));
|
||||
|
||||
if (seq.empty())
|
||||
return false;
|
||||
}
|
||||
dr.wait_for_historical_data(dds::core::Duration(1));
|
||||
}
|
||||
catch (const dds::core::Exception&)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
void unreadSamplesDuringRead()
|
||||
{
|
||||
droDataAvailable(DDS::topic_type_name<TopicTypeRead>::value(), m_dataReaderObject->topicName());
|
||||
}
|
||||
|
||||
void droDataAvailable(const std::string& topicType, const std::string& topicName) override final
|
||||
{
|
||||
Q_UNUSED(topicType);
|
||||
if (m_writerState.testAndSetRelaxed(1, 0))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Recreate Reader for topic " << topicName << ", type name "
|
||||
<< DDS::topic_type_name<TopicTypeRead>::value();
|
||||
if (m_subscriberListener)
|
||||
m_subscriberListener->removeCallback(m_dataReaderObject->getDataReader(), this);
|
||||
m_dataReaderObject->recreateReader();
|
||||
if (m_subscriberListener)
|
||||
m_subscriberListener->addCallback(m_dataReaderObject->getDataReader(), this);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "IN droDataAvailable(), topic name: " << topicName << ", type name "
|
||||
<< DDS::topic_type_name<TopicTypeRead>::value() << ", this: " << this
|
||||
<< ", m_dataReaderObject: " << m_dataReaderObject
|
||||
<< ", hasSamples: " << (m_dataReaderObject ? m_dataReaderObject->hasSamples() : -1);
|
||||
|
||||
if (m_subscriberListener)
|
||||
m_subscriberListener->enableCallback(m_dataReaderObject->getDataReader(), this);
|
||||
|
||||
if (!m_dataReaderObject || !m_subscriberCallback)
|
||||
return;
|
||||
|
||||
m_dataReaderObject->read(m_subscriberCallback);
|
||||
}
|
||||
|
||||
void noWriterAnymore(const std::string& topicType, const std::string& topicName) override
|
||||
{
|
||||
Q_UNUSED(topicType);
|
||||
Q_UNUSED(topicName);
|
||||
m_writerState = -1;
|
||||
}
|
||||
|
||||
void writerAvailable(const std::string& topicType, const std::string& topicName) override
|
||||
{
|
||||
Q_UNUSED(topicType);
|
||||
Q_UNUSED(topicName);
|
||||
m_writerState.testAndSetRelaxed(-1, 1);
|
||||
}
|
||||
|
||||
bool createInternal(bool droInitOk)
|
||||
{
|
||||
if (!droInitOk)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error initializing DRO for type " << DDS::topic_type_name<TopicTypeRead>::value();
|
||||
delete m_dataReaderObject;
|
||||
m_dataReaderObject = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_subscriberListener)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "subscriberListener exists, adding type "
|
||||
<< DDS::topic_type_name<TopicTypeRead>::value();
|
||||
m_subscriberListener->addCallback(m_dataReaderObject->getDataReader(), this);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Cannot add DTC to subscriberListener callback - type: "
|
||||
<< DDS::topic_type_name<TopicTypeRead>::value();
|
||||
}
|
||||
m_dataReaderObject->setHaveSubscriberCallback(m_subscriberListener != nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
DDSGeneric::SubscriberListener* m_subscriberListener;
|
||||
|
||||
DataReaderObject* m_dataReaderObject;
|
||||
|
||||
SubscriberCallback m_subscriberCallback;
|
||||
|
||||
QAtomicInt m_writerState;
|
||||
};
|
||||
|
||||
|
||||
template<typename DRO_OBJECT>
|
||||
class GenericDtcImpl final
|
||||
: public GenericDtcImplSubscriberTemplate<GenericDtc<DRO_OBJECT>>
|
||||
template <typename DRO_OBJECT>
|
||||
class GenericDtcImpl final : public GenericDtcImplSubscriberTemplate<GenericDtc<DRO_OBJECT>>
|
||||
{
|
||||
using BaseClass = GenericDtcImplSubscriberTemplate<GenericDtc<DRO_OBJECT>>;
|
||||
public:
|
||||
using BaseClass::BaseClass;
|
||||
using BaseClass = GenericDtcImplSubscriberTemplate<GenericDtc<DRO_OBJECT>>;
|
||||
|
||||
public:
|
||||
using BaseClass::BaseClass;
|
||||
};
|
||||
|
||||
|
||||
template<typename DRO_OBJECT>
|
||||
class GenericDtcImplSampleInfo final
|
||||
: public GenericDtcImplSubscriberTemplate<GenericDtcSampleInfo<DRO_OBJECT>>
|
||||
template <typename DRO_OBJECT>
|
||||
class GenericDtcImplSampleInfo final : public GenericDtcImplSubscriberTemplate<GenericDtcSampleInfo<DRO_OBJECT>>
|
||||
{
|
||||
using BaseClass = GenericDtcImplSubscriberTemplate<GenericDtcSampleInfo<DRO_OBJECT>>;
|
||||
public:
|
||||
using BaseClass::BaseClass;
|
||||
using BaseClass = GenericDtcImplSubscriberTemplate<GenericDtcSampleInfo<DRO_OBJECT>>;
|
||||
|
||||
public:
|
||||
using BaseClass::BaseClass;
|
||||
};
|
||||
|
||||
|
||||
template<typename DRO_OBJECT>
|
||||
class DdtcImpl final
|
||||
: public GenericDtcImplSubscriberTemplate<Ddtc<DRO_OBJECT>>
|
||||
template <typename DRO_OBJECT> class DdtcImpl final : public GenericDtcImplSubscriberTemplate<Ddtc<DRO_OBJECT>>
|
||||
{
|
||||
using BaseClass = GenericDtcImplSubscriberTemplate<Ddtc<DRO_OBJECT>>;
|
||||
public:
|
||||
using BaseClass::BaseClass;
|
||||
using BaseClass = GenericDtcImplSubscriberTemplate<Ddtc<DRO_OBJECT>>;
|
||||
|
||||
public:
|
||||
using BaseClass::BaseClass;
|
||||
};
|
||||
|
||||
|
||||
template<typename DRO_OBJECT>
|
||||
class DdtcImplSampleInfo final
|
||||
: public GenericDtcImplSubscriberTemplate<DdtcSampleInfo<DRO_OBJECT>>
|
||||
template <typename DRO_OBJECT>
|
||||
class DdtcImplSampleInfo final : public GenericDtcImplSubscriberTemplate<DdtcSampleInfo<DRO_OBJECT>>
|
||||
{
|
||||
using BaseClass = GenericDtcImplSubscriberTemplate<DdtcSampleInfo<DRO_OBJECT>>;
|
||||
public:
|
||||
using BaseClass::BaseClass;
|
||||
using BaseClass = GenericDtcImplSubscriberTemplate<DdtcSampleInfo<DRO_OBJECT>>;
|
||||
|
||||
public:
|
||||
using BaseClass::BaseClass;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace DTC
|
||||
Executable → Regular
+41
-52
@@ -3,85 +3,74 @@
|
||||
#pragma once
|
||||
|
||||
#include "generic_dts.h"
|
||||
|
||||
#include <DDS/Generic/generic_data_writer.h>
|
||||
#include <DDS/Generic/generic_logger.h>
|
||||
|
||||
namespace DTS
|
||||
{
|
||||
template<typename DWO_OBJECT>
|
||||
class GenericDtsImpl final : public GenericDts<typename DWO_OBJECT::TopicType>
|
||||
{
|
||||
template <typename DWO_OBJECT> class GenericDtsImpl final : public GenericDts<typename DWO_OBJECT::TopicType>
|
||||
{
|
||||
public:
|
||||
using DataWriterObject = DWO_OBJECT;
|
||||
using TopicType = typename DWO_OBJECT::TopicType;
|
||||
using DataWriter = typename dds::pub::DataWriter<TopicType>;
|
||||
using TopicType = typename DWO_OBJECT::TopicType;
|
||||
using DataWriter = typename dds::pub::DataWriter<TopicType>;
|
||||
|
||||
GenericDtsImpl(const dds::domain::DomainParticipant &domainParticipant,
|
||||
const dds::pub::Publisher &ddsPublisher,
|
||||
const std::string &topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<TopicType>::value()))
|
||||
: m_dataWriterObject(new DataWriterObject())
|
||||
, m_logger(DDS::getLogger(DDS::topic_type_name<TopicType>::value(), DDS::DataType::DATA_TOPIC_SERVER))
|
||||
GenericDtsImpl(
|
||||
const dds::domain::DomainParticipant& domainParticipant, const dds::pub::Publisher& ddsPublisher,
|
||||
const std::string& topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<TopicType>::value()))
|
||||
: m_dataWriterObject(new DataWriterObject()),
|
||||
m_logger(DDS::getLogger(DDS::topic_type_name<TopicType>::value(), DDS::DataType::DATA_TOPIC_SERVER))
|
||||
{
|
||||
Q_ASSERT(domainParticipant != nullptr);
|
||||
Q_ASSERT(ddsPublisher != nullptr);
|
||||
Q_ASSERT(domainParticipant != nullptr);
|
||||
Q_ASSERT(ddsPublisher != nullptr);
|
||||
|
||||
m_dataWriterObject->create(domainParticipant, ddsPublisher, topicName);
|
||||
m_dataWriterObject->create(domainParticipant, ddsPublisher, topicName);
|
||||
}
|
||||
|
||||
~GenericDtsImpl()
|
||||
{
|
||||
delete m_dataWriterObject;
|
||||
delete m_dataWriterObject;
|
||||
}
|
||||
|
||||
bool write(const TopicType &data,
|
||||
const dds::core::optional<dds::sub::SampleInfo> &si = dds::core::optional<dds::sub::SampleInfo>()) override final
|
||||
bool write(const TopicType& data, const dds::core::optional<dds::sub::SampleInfo>& si =
|
||||
dds::core::optional<dds::sub::SampleInfo>()) override final
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN write ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< ")";
|
||||
DEBUG_LOG(m_logger) << "IN write (" << DDS::topic_type_name<TopicType>::value() << ")";
|
||||
|
||||
if (!m_dataWriterObject)
|
||||
return false;
|
||||
if (!m_dataWriterObject)
|
||||
return false;
|
||||
|
||||
if (!m_dataWriterObject->write(data, si))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error writing for "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "TopicData ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< ") written";
|
||||
if (!m_dataWriterObject->write(data, si))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error writing for " << DDS::topic_type_name<TopicType>::value();
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "TopicData (" << DDS::topic_type_name<TopicType>::value() << ") written";
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool remove(const TopicType &data, bool errorMsgIfNotExists = true) override final
|
||||
bool remove(const TopicType& data, bool errorMsgIfNotExists = true) override final
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN remove ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< ")";
|
||||
DEBUG_LOG(m_logger) << "IN remove (" << DDS::topic_type_name<TopicType>::value() << ")";
|
||||
|
||||
if (!m_dataWriterObject)
|
||||
return false;
|
||||
if (!m_dataWriterObject)
|
||||
return false;
|
||||
|
||||
if (!m_dataWriterObject->remove(data, errorMsgIfNotExists))
|
||||
{
|
||||
if (errorMsgIfNotExists)
|
||||
ERROR_LOG(m_logger) << "Error removing for "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "TopicData ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< ") removed";
|
||||
if (!m_dataWriterObject->remove(data, errorMsgIfNotExists))
|
||||
{
|
||||
if (errorMsgIfNotExists)
|
||||
ERROR_LOG(m_logger) << "Error removing for " << DDS::topic_type_name<TopicType>::value();
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "TopicData (" << DDS::topic_type_name<TopicType>::value() << ") removed";
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
DataWriterObject *m_dataWriterObject;
|
||||
};
|
||||
DataWriterObject* m_dataWriterObject;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace DTS
|
||||
Executable → Regular
+62
-86
@@ -1,19 +1,15 @@
|
||||
|
||||
|
||||
|
||||
#include "data_topic_tests.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
#include <DDS/QosProfile/DDS_DefaultQos.h>
|
||||
#include <DDS/DTS/generic_dts_impl.h>
|
||||
#include <DDS/DTC/generic_dtc_impl.h>
|
||||
#include <DDS/DTS/generic_dts_impl.h>
|
||||
#include <DDS/QosProfile/DDS_DefaultQos.h>
|
||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||
|
||||
#include <QtTest/QTest>
|
||||
#include <QVariant>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QThread>
|
||||
|
||||
#include <QVariant>
|
||||
#include <QtTest/QTest>
|
||||
|
||||
DataTopicTests::DataTopicTests() : m_domainParticipantPub(nullptr)
|
||||
, m_domainParticipantSub(nullptr)
|
||||
@@ -26,129 +22,109 @@ DataTopicTests::DataTopicTests() : m_domainParticipantPub(nullptr)
|
||||
, m_dtcTestPart(nullptr)
|
||||
, m_mainThreadId(QThread::currentThreadId())
|
||||
.getNGLLogger("UnitTests.DataTopicTests")),
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
|
||||
if (!DDS::QosProfile::setDefault())
|
||||
ERROR_LOG(m_logger) << "Error setting default QoS from xml-file ";
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger())
|
||||
{
|
||||
if (!DDS::QosProfile::setDefault())
|
||||
ERROR_LOG(m_logger) << "Error setting default QoS from xml-file ";
|
||||
|
||||
DEBUG_LOG(m_logger) << "Main thread ID is " << m_mainThreadId;
|
||||
DEBUG_LOG(m_logger) << "Main thread ID is " << m_mainThreadId;
|
||||
}
|
||||
|
||||
DataTopicTests::~DataTopicTests()
|
||||
{
|
||||
|
||||
delete m_testPart;
|
||||
|
||||
|
||||
delete m_dtcTestPart;
|
||||
delete m_testPart;
|
||||
|
||||
|
||||
|
||||
delete m_subscriberListener;
|
||||
delete m_dtcTestPart;
|
||||
|
||||
delete m_subscriberListener;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool DataTopicTests::initPublisher()
|
||||
{
|
||||
m_domainParticipantPub =
|
||||
dds::domain::DomainParticipant(m_domainId,
|
||||
DDS::QosProfile::domainParticipantShm());
|
||||
m_domainParticipantPub = dds::domain::DomainParticipant(m_domainId, DDS::QosProfile::domainParticipantShm());
|
||||
|
||||
dds::pub::qos::PublisherQos publisherQos = m_domainParticipantPub.default_publisher_qos();
|
||||
dds::pub::qos::PublisherQos publisherQos = m_domainParticipantPub.default_publisher_qos();
|
||||
|
||||
|
||||
QString partition = QString::fromStdString(IDL::exercisePartition(m_partitionId));
|
||||
QString partition = QString::fromStdString(IDL::exercisePartition(m_partitionId));
|
||||
|
||||
dds::core::policy::Partition partitionQos;
|
||||
partitionQos.name( { partition.toStdString() } );
|
||||
publisherQos << partitionQos;
|
||||
dds::core::policy::Partition partitionQos;
|
||||
partitionQos.name({partition.toStdString()});
|
||||
publisherQos << partitionQos;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Publish on partition " << partition;
|
||||
DEBUG_LOG(m_logger) << "Publish on partition " << partition;
|
||||
|
||||
m_ddsPublisher = dds::pub::Publisher(m_domainParticipantPub, publisherQos);
|
||||
m_testPart = new DTS::TestParticipantImpl(m_domainParticipantPub, m_ddsPublisher);
|
||||
m_ddsPublisher = dds::pub::Publisher(m_domainParticipantPub, publisherQos);
|
||||
m_testPart = new DTS::TestParticipantImpl(m_domainParticipantPub, m_ddsPublisher);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataTopicTests::write(const DdsUnitTests::TestParticipant &data)
|
||||
bool DataTopicTests::write(const DdsUnitTests::TestParticipant& data)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Publish topic TestParticipant ";
|
||||
DEBUG_LOG(m_logger) << "ParticipantId: " << data.location().participantId()
|
||||
<< ", equipNo = " << data.location().equipNo();
|
||||
INFO_LOG(m_logger) << "Publish topic TestParticipant ";
|
||||
DEBUG_LOG(m_logger) << "ParticipantId: " << data.location().participantId()
|
||||
<< ", equipNo = " << data.location().equipNo();
|
||||
|
||||
return m_testPart->write(data);
|
||||
return m_testPart->write(data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool DataTopicTests::initSubscriber()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Initialisation DDS (Subscriber/Reader)";
|
||||
DEBUG_LOG(m_logger) << "Initialisation DDS (Subscriber/Reader)";
|
||||
|
||||
m_domainParticipantSub =
|
||||
dds::domain::DomainParticipant(m_domainId,
|
||||
DDS::QosProfile::domainParticipantShm());
|
||||
m_domainParticipantSub = dds::domain::DomainParticipant(m_domainId, DDS::QosProfile::domainParticipantShm());
|
||||
|
||||
dds::sub::qos::SubscriberQos subscriberQos = m_domainParticipantSub.default_subscriber_qos();
|
||||
dds::sub::qos::SubscriberQos subscriberQos = m_domainParticipantSub.default_subscriber_qos();
|
||||
|
||||
|
||||
dds::core::StringSeq partitions;
|
||||
partitions.reserve(1);
|
||||
for(int partitionId : { 1 } )
|
||||
{
|
||||
partitions.push_back(IDL::exercisePartition(partitionId));
|
||||
}
|
||||
dds::core::StringSeq partitions;
|
||||
partitions.reserve(1);
|
||||
for (int partitionId : {1})
|
||||
{
|
||||
partitions.push_back(IDL::exercisePartition(partitionId));
|
||||
}
|
||||
|
||||
dds::core::policy::Partition partitionQos;
|
||||
partitionQos.name( partitions );
|
||||
subscriberQos << partitionQos;
|
||||
dds::core::policy::Partition partitionQos;
|
||||
partitionQos.name(partitions);
|
||||
subscriberQos << partitionQos;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Initialise DTC::SubscriberListener";
|
||||
m_subscriberListener = new DDSGeneric::SubscriberListener();
|
||||
m_ddsSubscriber = dds::sub::Subscriber(m_domainParticipantSub,
|
||||
subscriberQos,
|
||||
m_subscriberListener,
|
||||
DDSGeneric::SubscriberListener::mask());
|
||||
DEBUG_LOG(m_logger) << "Initialise DTC::SubscriberListener";
|
||||
m_subscriberListener = new DDSGeneric::SubscriberListener();
|
||||
m_ddsSubscriber = dds::sub::Subscriber(m_domainParticipantSub, subscriberQos, m_subscriberListener,
|
||||
DDSGeneric::SubscriberListener::mask());
|
||||
|
||||
|
||||
m_dtcTestPart = new DTC::SampleInfo::TestParticipantImpl(m_domainParticipantSub,
|
||||
m_ddsSubscriber,
|
||||
m_subscriberListener);
|
||||
m_dtcTestPart =
|
||||
new DTC::SampleInfo::TestParticipantImpl(m_domainParticipantSub, m_ddsSubscriber, m_subscriberListener);
|
||||
|
||||
m_dtcTestPart->setSubscriberCallback([this](const DdsUnitTests::TestParticipant &data, const dds::sub::SampleInfo &si) { processData(data, si); } );
|
||||
m_dtcTestPart->setSubscriberCallback(
|
||||
[this](const DdsUnitTests::TestParticipant& data, const dds::sub::SampleInfo& si) { processData(data, si); });
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DataTopicTests::deleteDTC()
|
||||
{
|
||||
delete m_dtcTestPart;
|
||||
m_dtcTestPart = nullptr;
|
||||
delete m_dtcTestPart;
|
||||
m_dtcTestPart = nullptr;
|
||||
}
|
||||
|
||||
void DataTopicTests::deleteSubscriber()
|
||||
{
|
||||
m_ddsSubscriber = nullptr;
|
||||
delete m_subscriberListener;
|
||||
m_subscriberListener = nullptr;
|
||||
m_ddsSubscriber = nullptr;
|
||||
delete m_subscriberListener;
|
||||
m_subscriberListener = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DataTopicTests::processData(const DdsUnitTests::TestParticipant &instance, const dds::sub::SampleInfo &si)
|
||||
void DataTopicTests::processData(const DdsUnitTests::TestParticipant& instance, const dds::sub::SampleInfo& si)
|
||||
{
|
||||
INFO_LOG(m_logger) << "process data in topic TestParticipant, Sampleinfo: " << si.source_timestamp().sec();
|
||||
INFO_LOG(m_logger) << "process data in topic TestParticipant, Sampleinfo: " << si.source_timestamp().sec();
|
||||
|
||||
DEBUG_LOG(m_logger) << "participantId: " << instance.location().participantId();
|
||||
DEBUG_LOG(m_logger) << "equipNo: " << instance.location().equipNo();
|
||||
DEBUG_LOG(m_logger) << "participantId: " << instance.location().participantId();
|
||||
DEBUG_LOG(m_logger) << "equipNo: " << instance.location().equipNo();
|
||||
|
||||
m_receivedParticipantData = instance;
|
||||
m_receivedParticipantData = instance;
|
||||
|
||||
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
||||
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
||||
|
||||
emit testParticipantDataArrived();
|
||||
emit testParticipantDataArrived();
|
||||
}
|
||||
Executable → Regular
+36
-42
@@ -2,64 +2,58 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <DDS/Generic/subscriber_listener.h>
|
||||
|
||||
#include <DdsUnitTests/ddsut_dtc_types.h>
|
||||
#include <DdsUnitTests/ddsut_dts_types.h>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
namespace NGL {
|
||||
class INGLLogger;
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class DataTopicTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataTopicTests();
|
||||
virtual ~DataTopicTests();
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataTopicTests();
|
||||
virtual ~DataTopicTests();
|
||||
|
||||
|
||||
bool initPublisher();
|
||||
bool initSubscriber();
|
||||
bool initPublisher();
|
||||
bool initSubscriber();
|
||||
|
||||
|
||||
bool write(const DdsUnitTests::TestParticipant &data);
|
||||
bool write(const DdsUnitTests::TestParticipant& data);
|
||||
|
||||
|
||||
DdsUnitTests::TestParticipant getReceivedParticipantData() const { return m_receivedParticipantData; }
|
||||
void deleteDTC();
|
||||
void deleteSubscriber();
|
||||
DdsUnitTests::TestParticipant getReceivedParticipantData() const
|
||||
{
|
||||
return m_receivedParticipantData;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
void processData(const DdsUnitTests::TestParticipant &instance, const dds::sub::SampleInfo &si);
|
||||
void deleteDTC();
|
||||
void deleteSubscriber();
|
||||
|
||||
Q_SIGNALS:
|
||||
void testParticipantDataArrived();
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void processData(const DdsUnitTests::TestParticipant& instance, const dds::sub::SampleInfo& si);
|
||||
|
||||
private:
|
||||
dds::domain::DomainParticipant m_domainParticipantPub;
|
||||
dds::domain::DomainParticipant m_domainParticipantSub;
|
||||
int m_domainId;
|
||||
int m_partitionId;
|
||||
Q_SIGNALS:
|
||||
void testParticipantDataArrived();
|
||||
|
||||
|
||||
dds::pub::Publisher m_ddsPublisher;
|
||||
DTS::TestParticipant *m_testPart;
|
||||
private:
|
||||
dds::domain::DomainParticipant m_domainParticipantPub;
|
||||
dds::domain::DomainParticipant m_domainParticipantSub;
|
||||
int m_domainId;
|
||||
int m_partitionId;
|
||||
|
||||
|
||||
dds::sub::Subscriber m_ddsSubscriber;
|
||||
DDSGeneric::SubscriberListener *m_subscriberListener;
|
||||
dds::pub::Publisher m_ddsPublisher;
|
||||
DTS::TestParticipant* m_testPart;
|
||||
|
||||
DTC::SampleInfo::TestParticipant *m_dtcTestPart;
|
||||
dds::sub::Subscriber m_ddsSubscriber;
|
||||
DDSGeneric::SubscriberListener* m_subscriberListener;
|
||||
|
||||
Qt::HANDLE m_mainThreadId;
|
||||
|
||||
DdsUnitTests::TestParticipant m_receivedParticipantData;
|
||||
DTC::SampleInfo::TestParticipant* m_dtcTestPart;
|
||||
|
||||
Qt::HANDLE m_mainThreadId;
|
||||
|
||||
DdsUnitTests::TestParticipant m_receivedParticipantData;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+54
-60
@@ -1,102 +1,96 @@
|
||||
|
||||
|
||||
|
||||
#include "data_topic_tests_main.h"
|
||||
|
||||
#include "data_topic_tests.h"
|
||||
|
||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||
|
||||
#include <QtTest/QTest>
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QtTest/QTest>
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("UnitTests", "log4cxx_ddsUnitTests.props");
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("UnitTests", "log4cxx_ddsUnitTests.props");
|
||||
|
||||
DataTopicTestsMain *tc = new DataTopicTestsMain;
|
||||
DataTopicTestsMain* tc = new DataTopicTestsMain;
|
||||
|
||||
int retCode = QTest::qExec(tc, argc, argv);
|
||||
int retCode = QTest::qExec(tc, argc, argv);
|
||||
|
||||
delete tc;
|
||||
delete tc;
|
||||
|
||||
return retCode;
|
||||
return retCode;
|
||||
}
|
||||
|
||||
DataTopicTestsMain::DataTopicTestsMain()
|
||||
: m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTests.DataTopicTestsMain"))
|
||||
: m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTests.DataTopicTestsMain"))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DataTopicTestsMain::initTestCase()
|
||||
{
|
||||
DEBUG_LOG(m_logger) <<"DataTopicTestsMain: initTestCase";
|
||||
DEBUG_LOG(m_logger) << "DataTopicTestsMain: initTestCase";
|
||||
|
||||
m_dtTest = new DataTopicTests();
|
||||
QVERIFY2(m_dtTest, "Initialisation of DataTopicTest failed");
|
||||
QVERIFY2(m_dtTest->initPublisher(), "Initialisation Publisher failed");
|
||||
QVERIFY2(m_dtTest->initSubscriber(), "Initialisation Subscriber failed");
|
||||
m_dtTest = new DataTopicTests();
|
||||
QVERIFY2(m_dtTest, "Initialisation of DataTopicTest failed");
|
||||
QVERIFY2(m_dtTest->initPublisher(), "Initialisation Publisher failed");
|
||||
QVERIFY2(m_dtTest->initSubscriber(), "Initialisation Subscriber failed");
|
||||
|
||||
m_participantDataArrivedSpy = new QSignalSpy(m_dtTest, &DataTopicTests::testParticipantDataArrived);
|
||||
m_participantDataArrivedSpy = new QSignalSpy(m_dtTest, &DataTopicTests::testParticipantDataArrived);
|
||||
}
|
||||
|
||||
|
||||
void DataTopicTestsMain::publishTestCase()
|
||||
{
|
||||
DEBUG_LOG(m_logger) <<"DataTopicTestsMain: publish TestParticipant";
|
||||
|
||||
m_sentParticipantData.location().participantId(100);
|
||||
m_sentParticipantData.location().equipNo(1010);
|
||||
m_sentParticipantData.testId(100);
|
||||
QVERIFY2(m_dtTest->write(m_sentParticipantData), "Publishing Topic TestParticipant failed");
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "DataTopicTestsMain: publish TestParticipant";
|
||||
|
||||
DEBUG_LOG(m_logger) <<"DataTopicTestsMain: publish ready";
|
||||
m_sentParticipantData.location().participantId(100);
|
||||
m_sentParticipantData.location().equipNo(1010);
|
||||
m_sentParticipantData.testId(100);
|
||||
QVERIFY2(m_dtTest->write(m_sentParticipantData), "Publishing Topic TestParticipant failed");
|
||||
|
||||
DEBUG_LOG(m_logger) << "DataTopicTestsMain: publish ready";
|
||||
}
|
||||
|
||||
|
||||
void DataTopicTestsMain::subscribeTestCase()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN subscribeTestCase";
|
||||
DEBUG_LOG(m_logger) << "IN subscribeTestCase";
|
||||
|
||||
QTRY_COMPARE(m_participantDataArrivedSpy->count(), 1);
|
||||
QTRY_COMPARE(m_participantDataArrivedSpy->count(), 1);
|
||||
|
||||
DdsUnitTests::TestParticipant recvPartiticpant = m_dtTest->getReceivedParticipantData();
|
||||
DdsUnitTests::TestParticipant recvPartiticpant = m_dtTest->getReceivedParticipantData();
|
||||
|
||||
QCOMPARE(recvPartiticpant.location().participantId(), m_sentParticipantData.location().participantId());
|
||||
QCOMPARE(recvPartiticpant.location().equipNo(), m_sentParticipantData.location().equipNo());
|
||||
QCOMPARE(recvPartiticpant.location().participantId(), m_sentParticipantData.location().participantId());
|
||||
QCOMPARE(recvPartiticpant.location().equipNo(), m_sentParticipantData.location().equipNo());
|
||||
}
|
||||
|
||||
|
||||
void DataTopicTestsMain::deleteDataReaderTestCase()
|
||||
{
|
||||
DdsUnitTests::TestParticipant data;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
m_sentParticipantData.id(i);
|
||||
m_dtTest->write(m_sentParticipantData);
|
||||
}
|
||||
m_dtTest->deleteDTC();
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
m_sentParticipantData.id(i);
|
||||
m_dtTest->write(m_sentParticipantData);
|
||||
}
|
||||
m_dtTest->deleteSubscriber();
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
m_sentParticipantData.id(i);
|
||||
m_dtTest->write(m_sentParticipantData);
|
||||
}
|
||||
DdsUnitTests::TestParticipant data;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
m_sentParticipantData.id(i);
|
||||
m_dtTest->write(m_sentParticipantData);
|
||||
}
|
||||
m_dtTest->deleteDTC();
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
m_sentParticipantData.id(i);
|
||||
m_dtTest->write(m_sentParticipantData);
|
||||
}
|
||||
m_dtTest->deleteSubscriber();
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
m_sentParticipantData.id(i);
|
||||
m_dtTest->write(m_sentParticipantData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DataTopicTestsMain::cleanupTestCase()
|
||||
{
|
||||
DEBUG_LOG(m_logger) <<"DataTopicTestsMain: cleanupTestCase";
|
||||
delete m_dtTest; m_dtTest = nullptr;
|
||||
delete m_participantDataArrivedSpy; m_participantDataArrivedSpy = nullptr;
|
||||
DEBUG_LOG(m_logger) << "DataTopicTestsMain: cleanupTestCase";
|
||||
delete m_dtTest;
|
||||
m_dtTest = nullptr;
|
||||
delete m_participantDataArrivedSpy;
|
||||
m_participantDataArrivedSpy = nullptr;
|
||||
}
|
||||
|
||||
Executable → Regular
+17
-18
@@ -2,37 +2,36 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <DdsUnitTests/ddsut_dtc_types.h>
|
||||
#include <QObject>
|
||||
#include <QSignalSpy>
|
||||
#include <DdsUnitTests/ddsut_dtc_types.h>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class DataTopicTests;
|
||||
|
||||
|
||||
class DataTopicTestsMain : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DataTopicTestsMain();
|
||||
public:
|
||||
DataTopicTestsMain();
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void publishTestCase();
|
||||
void subscribeTestCase();
|
||||
void deleteDataReaderTestCase();
|
||||
void cleanupTestCase();
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void publishTestCase();
|
||||
void subscribeTestCase();
|
||||
void deleteDataReaderTestCase();
|
||||
void cleanupTestCase();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
private:
|
||||
DdsUnitTests::TestParticipant m_sentParticipantData;
|
||||
QSignalSpy *m_participantDataArrivedSpy = nullptr;
|
||||
DataTopicTests *m_dtTest = nullptr;
|
||||
private:
|
||||
DdsUnitTests::TestParticipant m_sentParticipantData;
|
||||
QSignalSpy* m_participantDataArrivedSpy = nullptr;
|
||||
DataTopicTests* m_dtTest = nullptr;
|
||||
};
|
||||
Executable → Regular
+151
-167
@@ -1,256 +1,240 @@
|
||||
|
||||
|
||||
|
||||
#include "function_topic_tests.h"
|
||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||
#include <DDS/DDSConnector/subscriber.h>
|
||||
|
||||
#include <DDS/DDSConnector/publisher.h>
|
||||
|
||||
#include <QtTest/QTest>
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <DDS/DDSConnector/subscriber.h>
|
||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <QtTest/QTest>
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("UnitTests", "log4cxx_ddsUnitTests.props");
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("UnitTests", "log4cxx_ddsUnitTests.props");
|
||||
|
||||
FunctionTopicTests *tc = new FunctionTopicTests;
|
||||
FunctionTopicTests* tc = new FunctionTopicTests;
|
||||
|
||||
int retCode = QTest::qExec(tc, argc, argv);
|
||||
int retCode = QTest::qExec(tc, argc, argv);
|
||||
|
||||
delete tc;
|
||||
delete tc;
|
||||
|
||||
return retCode;
|
||||
return retCode;
|
||||
}
|
||||
|
||||
|
||||
FunctionTopicTests::FunctionTopicTests() : m_mainThreadId(QThread::currentThreadId())
|
||||
.getNGLLogger("UnitTests.FunctionTopicTests")),
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
|
||||
qRegisterMetaType<DdsUnitTests::FunctionReply>("DdsUnitTests::FunctionReply");
|
||||
qRegisterMetaType<DdsUnitTests::FunctionReplyWithState>("DdsUnitTests::FunctionReplyWithState");
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger())
|
||||
{
|
||||
qRegisterMetaType<DdsUnitTests::FunctionReply>("DdsUnitTests::FunctionReply");
|
||||
qRegisterMetaType<DdsUnitTests::FunctionReplyWithState>("DdsUnitTests::FunctionReplyWithState");
|
||||
}
|
||||
|
||||
|
||||
void FunctionTopicTests::initTestCase()
|
||||
{
|
||||
DEBUG_LOG(m_logger) <<"FunctionTopicTests: initTestCase";
|
||||
DEBUG_LOG(m_logger) << "FunctionTopicTests: initTestCase";
|
||||
|
||||
const int domainId = 0;
|
||||
const int domainId = 0;
|
||||
|
||||
m_ddsConnectorClient = std::make_shared<DDSConnector::DdsConnector>(domainId, IDL::PartitionType::Global);
|
||||
QVERIFY2(m_ddsConnectorClient->init(), "Initialisation of ddsconnector (Client) failed");
|
||||
m_ddsConnectorClient->initSubscriber();
|
||||
QVERIFY2(m_ddsConnectorClient->getSubscriber(), "Initialisation of Subscriber (DdsConnectorClient) failed");
|
||||
m_ddsConnectorClient->initPublisher();
|
||||
QVERIFY2(m_ddsConnectorClient->getPublisher(), "Initialisation of Publisher (DdsConnectorClient) failed");
|
||||
m_ddsConnectorClient = std::make_shared<DDSConnector::DdsConnector>(domainId, IDL::PartitionType::Global);
|
||||
QVERIFY2(m_ddsConnectorClient->init(), "Initialisation of ddsconnector (Client) failed");
|
||||
m_ddsConnectorClient->initSubscriber();
|
||||
QVERIFY2(m_ddsConnectorClient->getSubscriber(), "Initialisation of Subscriber (DdsConnectorClient) failed");
|
||||
m_ddsConnectorClient->initPublisher();
|
||||
QVERIFY2(m_ddsConnectorClient->getPublisher(), "Initialisation of Publisher (DdsConnectorClient) failed");
|
||||
|
||||
m_ddsConnectorServer = std::make_shared<DDSConnector::DdsConnector>(domainId, IDL::PartitionType::Global);
|
||||
QVERIFY2(m_ddsConnectorServer->init(), "Initialisation of ddsconnector (Server) failed");
|
||||
m_ddsConnectorServer->initSubscriber();
|
||||
QVERIFY2(m_ddsConnectorServer->getSubscriber(), "Initialisation of Subscriber (DdsConnectorServer) failed");
|
||||
m_ddsConnectorServer->initPublisher();
|
||||
QVERIFY2(m_ddsConnectorServer->getPublisher(), "Initialisation of Publisher (DdsConnectorServer) failed");
|
||||
m_ddsConnectorServer = std::make_shared<DDSConnector::DdsConnector>(domainId, IDL::PartitionType::Global);
|
||||
QVERIFY2(m_ddsConnectorServer->init(), "Initialisation of ddsconnector (Server) failed");
|
||||
m_ddsConnectorServer->initSubscriber();
|
||||
QVERIFY2(m_ddsConnectorServer->getSubscriber(), "Initialisation of Subscriber (DdsConnectorServer) failed");
|
||||
m_ddsConnectorServer->initPublisher();
|
||||
QVERIFY2(m_ddsConnectorServer->getPublisher(), "Initialisation of Publisher (DdsConnectorServer) failed");
|
||||
}
|
||||
|
||||
|
||||
void FunctionTopicTests::initFTSTestCase()
|
||||
{
|
||||
m_fts.reset(m_ddsConnectorServer->createFTS<FTS::FunctionTopicTest>());
|
||||
QVERIFY2(m_fts.get(), "Initialisation of FTS Replier failed");
|
||||
m_fts->setSubscriberCallback([this](const rti::core::SampleIdentity &identity, const DdsUnitTests::FunctionRequest &request) { this->onFunctionTopicRequest(identity, request);});
|
||||
|
||||
m_ftsWS.reset(m_ddsConnectorServer->createFTS<FTS::FunctionTopicTestWithState>());
|
||||
QVERIFY2(m_ftsWS.get(), "Initialisation of FTS Replier failed");
|
||||
m_ftsWS->setSubscriberCallback([this](const rti::core::SampleIdentity &identity, const DdsUnitTests::FunctionRequestWithState &request) { this->onFunctionTopicRequest(identity, request);});
|
||||
m_fts.reset(m_ddsConnectorServer->createFTS<FTS::FunctionTopicTest>());
|
||||
QVERIFY2(m_fts.get(), "Initialisation of FTS Replier failed");
|
||||
m_fts->setSubscriberCallback(
|
||||
[this](const rti::core::SampleIdentity& identity, const DdsUnitTests::FunctionRequest& request) {
|
||||
this->onFunctionTopicRequest(identity, request);
|
||||
});
|
||||
|
||||
m_ftsWS.reset(m_ddsConnectorServer->createFTS<FTS::FunctionTopicTestWithState>());
|
||||
QVERIFY2(m_ftsWS.get(), "Initialisation of FTS Replier failed");
|
||||
m_ftsWS->setSubscriberCallback(
|
||||
[this](const rti::core::SampleIdentity& identity, const DdsUnitTests::FunctionRequestWithState& request) {
|
||||
this->onFunctionTopicRequest(identity, request);
|
||||
});
|
||||
}
|
||||
|
||||
void FunctionTopicTests::initFTCTestCase()
|
||||
{
|
||||
m_ftc.reset(m_ddsConnectorClient->createFTC<FTC::FunctionTopicTest>(this));
|
||||
QVERIFY2(m_ftc.get(), "Initialisation of FTC Requester failed");
|
||||
m_ftcWS.reset(m_ddsConnectorClient->createFTC<FTC::FunctionTopicTestWithState>(this));
|
||||
QVERIFY2(m_ftc.get(), "Initialisation of FTC Requester failed");
|
||||
m_ftc.reset(m_ddsConnectorClient->createFTC<FTC::FunctionTopicTest>(this));
|
||||
QVERIFY2(m_ftc.get(), "Initialisation of FTC Requester failed");
|
||||
m_ftcWS.reset(m_ddsConnectorClient->createFTC<FTC::FunctionTopicTestWithState>(this));
|
||||
QVERIFY2(m_ftc.get(), "Initialisation of FTC Requester failed");
|
||||
}
|
||||
|
||||
|
||||
void FunctionTopicTests::requestTestCase1()
|
||||
{
|
||||
|
||||
requestWithState();
|
||||
|
||||
QCOMPARE(m_ddsConnectorServer->getWaitSetHandler()->attachedConditionCount(), 3);
|
||||
requestWithState();
|
||||
|
||||
QCOMPARE(m_ddsConnectorServer->getWaitSetHandler()->attachedConditionCount(), 3);
|
||||
}
|
||||
|
||||
requestWithState();
|
||||
|
||||
QCOMPARE(m_ddsConnectorServer->getWaitSetHandler()->attachedConditionCount(), 3);
|
||||
requestWithState();
|
||||
|
||||
QCOMPARE(m_ddsConnectorServer->getWaitSetHandler()->attachedConditionCount(), 3);
|
||||
}
|
||||
|
||||
void FunctionTopicTests::requestWithState()
|
||||
{
|
||||
|
||||
QSignalSpy spyRequest(this, &FunctionTopicTests::functionTopicRequestFinished);
|
||||
QSignalSpy spyReply(this, &FunctionTopicTests::functionTopicReply);
|
||||
|
||||
DEBUG_LOG(m_logger) <<"FunctionTopicTests: request";
|
||||
QSignalSpy spyRequest(this, &FunctionTopicTests::functionTopicRequestFinished);
|
||||
QSignalSpy spyReply(this, &FunctionTopicTests::functionTopicReply);
|
||||
|
||||
|
||||
DdsUnitTests::FunctionRequestWithState data;
|
||||
DEBUG_LOG(m_logger) << "FunctionTopicTests: request";
|
||||
|
||||
data.id(1);
|
||||
data.info(std::string("Test request"));
|
||||
data.value(1000.0);
|
||||
DdsUnitTests::FunctionRequestWithState data;
|
||||
|
||||
int uniqueId = 0;
|
||||
bool bRet = m_ftcWS->requestDataClassic(data,
|
||||
SLOT(slotRequestedData(DdsUnitTests::FunctionTopicTestWithStateReply,int,bool)),
|
||||
SLOT(slotRequestedDataError(int,int,int)),
|
||||
uniqueId);
|
||||
data.id(1);
|
||||
data.info(std::string("Test request"));
|
||||
data.value(1000.0);
|
||||
|
||||
QVERIFY2(bRet, "Could not request data!");
|
||||
int uniqueId = 0;
|
||||
bool bRet = m_ftcWS->requestDataClassic(
|
||||
data, SLOT(slotRequestedData(DdsUnitTests::FunctionTopicTestWithStateReply, int, bool)),
|
||||
SLOT(slotRequestedDataError(int, int, int)), uniqueId);
|
||||
|
||||
QTRY_COMPARE(spyRequest.count(), 1);
|
||||
QTRY_COMPARE(spyReply.count(), 2);
|
||||
QVERIFY2(bRet, "Could not request data!");
|
||||
|
||||
QTRY_COMPARE(spyRequest.count(), 1);
|
||||
QTRY_COMPARE(spyReply.count(), 2);
|
||||
}
|
||||
|
||||
|
||||
void FunctionTopicTests::requestTestCase2()
|
||||
{
|
||||
|
||||
QSignalSpy spyRequest(this, &FunctionTopicTests::functionTopicRequestFinished);
|
||||
QSignalSpy spyReply(this, &FunctionTopicTests::functionTopicReply);
|
||||
|
||||
DEBUG_LOG(m_logger) <<"FunctionTopicTests: request";
|
||||
QSignalSpy spyRequest(this, &FunctionTopicTests::functionTopicRequestFinished);
|
||||
QSignalSpy spyReply(this, &FunctionTopicTests::functionTopicReply);
|
||||
|
||||
|
||||
DdsUnitTests::FunctionRequest data;
|
||||
DEBUG_LOG(m_logger) << "FunctionTopicTests: request";
|
||||
|
||||
data.id(1);
|
||||
data.info(std::string("Test request"));
|
||||
data.value(1000.0);
|
||||
DdsUnitTests::FunctionRequest data;
|
||||
|
||||
int uniqueId = 0;
|
||||
bool bRet = m_ftc->requestDataClassic(data,
|
||||
SLOT(slotRequestedData(DdsUnitTests::FunctionTopicTestReply,int,bool)),
|
||||
SLOT(slotRequestedDataError(int,int,int)),
|
||||
uniqueId);
|
||||
data.id(1);
|
||||
data.info(std::string("Test request"));
|
||||
data.value(1000.0);
|
||||
|
||||
QVERIFY2(bRet, "Could not request data!");
|
||||
int uniqueId = 0;
|
||||
bool bRet =
|
||||
m_ftc->requestDataClassic(data, SLOT(slotRequestedData(DdsUnitTests::FunctionTopicTestReply, int, bool)),
|
||||
SLOT(slotRequestedDataError(int, int, int)), uniqueId);
|
||||
|
||||
QTRY_COMPARE(spyRequest.count(), 1);
|
||||
QTRY_COMPARE(spyReply.count(), 1);
|
||||
QVERIFY2(bRet, "Could not request data!");
|
||||
|
||||
QTRY_COMPARE(spyRequest.count(), 1);
|
||||
QTRY_COMPARE(spyReply.count(), 1);
|
||||
}
|
||||
|
||||
|
||||
void FunctionTopicTests::cleanupTestCase()
|
||||
{
|
||||
DEBUG_LOG(m_logger) <<"FunctionTopicTests: cleanupTestCase";
|
||||
DEBUG_LOG(m_logger) << "FunctionTopicTests: cleanupTestCase";
|
||||
|
||||
m_fts = nullptr;
|
||||
m_ftc = nullptr;
|
||||
m_ftsWS = nullptr;
|
||||
m_ftcWS = nullptr;
|
||||
m_ddsConnectorServer = nullptr;
|
||||
m_ddsConnectorClient = nullptr;
|
||||
m_fts = nullptr;
|
||||
m_ftc = nullptr;
|
||||
m_ftsWS = nullptr;
|
||||
m_ftcWS = nullptr;
|
||||
m_ddsConnectorServer = nullptr;
|
||||
m_ddsConnectorClient = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void FunctionTopicTests::onFunctionTopicRequest(const rti::core::SampleIdentity &sampleId,
|
||||
const DdsUnitTests::FunctionRequestWithState &request)
|
||||
void FunctionTopicTests::onFunctionTopicRequest(const rti::core::SampleIdentity& sampleId,
|
||||
const DdsUnitTests::FunctionRequestWithState& request)
|
||||
{
|
||||
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
||||
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
||||
|
||||
INFO_LOG(m_logger) << "Got function topic request (with status member)";
|
||||
m_requestTopicWithState = request;
|
||||
QCOMPARE(m_requestTopicWithState.id(), 1);
|
||||
QCOMPARE(m_requestTopicWithState.info().get(), std::string("Test request"));
|
||||
QCOMPARE(m_requestTopicWithState.value(), 1000.0);
|
||||
INFO_LOG(m_logger) << "Got function topic request (with status member)";
|
||||
m_requestTopicWithState = request;
|
||||
QCOMPARE(m_requestTopicWithState.id(), 1);
|
||||
QCOMPARE(m_requestTopicWithState.info().get(), std::string("Test request"));
|
||||
QCOMPARE(m_requestTopicWithState.value(), 1000.0);
|
||||
|
||||
DdsUnitTests::FunctionReplyWithState reply;
|
||||
DdsUnitTests::FunctionReplyWithState reply;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Send sample with status REPLY_COMPLETED";
|
||||
reply.id(1);
|
||||
reply.errorString("Hello");
|
||||
reply.replyState(Core::FtReplyState::Completed);
|
||||
DEBUG_LOG(m_logger) << "Send sample with status REPLY_COMPLETED";
|
||||
reply.id(1);
|
||||
reply.errorString("Hello");
|
||||
reply.replyState(Core::FtReplyState::Completed);
|
||||
|
||||
bool bRet = m_ftsWS->sendReply(sampleId, reply);
|
||||
QVERIFY2(bRet, "Sending Reply failed");
|
||||
bool bRet = m_ftsWS->sendReply(sampleId, reply);
|
||||
QVERIFY2(bRet, "Sending Reply failed");
|
||||
|
||||
emit functionTopicRequestFinished();
|
||||
emit functionTopicRequestFinished();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionTopicTests::onFunctionTopicRequest(const rti::core::SampleIdentity &sampleId,
|
||||
const DdsUnitTests::FunctionRequest &request)
|
||||
void FunctionTopicTests::onFunctionTopicRequest(const rti::core::SampleIdentity& sampleId,
|
||||
const DdsUnitTests::FunctionRequest& request)
|
||||
{
|
||||
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
||||
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
||||
|
||||
INFO_LOG(m_logger) << "Got function topic request (without status member)";
|
||||
INFO_LOG(m_logger) << "Got function topic request (without status member)";
|
||||
|
||||
m_requestTopic = request;
|
||||
m_requestTopic = request;
|
||||
|
||||
DdsUnitTests::FunctionReply reply;
|
||||
DdsUnitTests::FunctionReply reply;
|
||||
|
||||
reply.id(2);
|
||||
reply.errorString("What?");
|
||||
reply.id(2);
|
||||
reply.errorString("What?");
|
||||
|
||||
bool bRet = m_fts->sendReply(sampleId, reply);
|
||||
QVERIFY2(bRet, "Sending Reply failed");
|
||||
bool bRet = m_fts->sendReply(sampleId, reply);
|
||||
QVERIFY2(bRet, "Sending Reply failed");
|
||||
|
||||
emit functionTopicRequestFinished();
|
||||
emit functionTopicRequestFinished();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionTopicTests::slotRequestedData(const DdsUnitTests::FunctionTopicTestWithStateReply &reply,
|
||||
int seqNo, bool bFinished)
|
||||
void FunctionTopicTests::slotRequestedData(const DdsUnitTests::FunctionTopicTestWithStateReply& reply, int seqNo,
|
||||
bool bFinished)
|
||||
{
|
||||
Q_UNUSED(seqNo);
|
||||
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
||||
Q_UNUSED(seqNo);
|
||||
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
||||
|
||||
INFO_LOG(m_logger) << "Got reply from FTS: " << reply.replyState();
|
||||
INFO_LOG(m_logger) << "Got reply from FTS: " << reply.replyState();
|
||||
|
||||
m_replyTopicWithState = reply;
|
||||
m_replyTopicWithState = reply;
|
||||
|
||||
if (m_replyTopicWithState.replyState() == Core::FtReplyState::InProgress)
|
||||
{
|
||||
QVERIFY(!bFinished);
|
||||
QCOMPARE(m_replyTopicWithState.id(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_replyTopicWithState.replyState() == Core::FtReplyState::InProgress)
|
||||
{
|
||||
QVERIFY(!bFinished);
|
||||
QCOMPARE(m_replyTopicWithState.id(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
QVERIFY(bFinished);
|
||||
QCOMPARE(m_replyTopicWithState.id(), 1);
|
||||
QCOMPARE(m_replyTopicWithState.errorString(), std::string("Hello"));
|
||||
QCOMPARE(m_replyTopicWithState.replyState().underlying(), Core::FtReplyState::Completed);
|
||||
}
|
||||
emit functionTopicReply();
|
||||
}
|
||||
|
||||
void FunctionTopicTests::slotRequestedData(const DdsUnitTests::FunctionTopicTestReply& reply, int seqNo, bool bFinished)
|
||||
{
|
||||
Q_UNUSED(seqNo);
|
||||
QVERIFY(bFinished);
|
||||
QCOMPARE(m_replyTopicWithState.id(), 1);
|
||||
QCOMPARE(m_replyTopicWithState.errorString(), std::string("Hello"));
|
||||
QCOMPARE(m_replyTopicWithState.replyState().underlying(), Core::FtReplyState::Completed);
|
||||
}
|
||||
emit functionTopicReply();
|
||||
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
||||
|
||||
m_replyTopic = reply;
|
||||
QCOMPARE(m_replyTopic.id(), 2);
|
||||
QCOMPARE(m_replyTopic.errorString(), std::string("What?"));
|
||||
|
||||
emit functionTopicReply();
|
||||
}
|
||||
|
||||
void FunctionTopicTests::slotRequestedData(const DdsUnitTests::FunctionTopicTestReply &reply,
|
||||
int seqNo, bool bFinished)
|
||||
{
|
||||
Q_UNUSED(seqNo);
|
||||
QVERIFY(bFinished);
|
||||
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
||||
|
||||
m_replyTopic = reply;
|
||||
QCOMPARE(m_replyTopic.id(), 2);
|
||||
QCOMPARE(m_replyTopic.errorString(), std::string("What?"));
|
||||
|
||||
emit functionTopicReply();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionTopicTests::slotRequestedDataError(int reason, int seqNo, int requestId)
|
||||
{
|
||||
Q_UNUSED(seqNo);
|
||||
Q_UNUSED(requestId);
|
||||
QFAIL(qPrintable(QStringLiteral("Error when trying to request data: %1").arg(reason)));
|
||||
Q_UNUSED(seqNo);
|
||||
Q_UNUSED(requestId);
|
||||
QFAIL(qPrintable(QStringLiteral("Error when trying to request data: %1").arg(reason)));
|
||||
}
|
||||
Executable → Regular
+47
-49
@@ -2,72 +2,70 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
#include <DDS/FTC/generic_ftc_impl.h>
|
||||
#include <DDS/FTS/generic_fts_impl.h>
|
||||
#include <DdsUnitTests/ddsut.hpp>
|
||||
#include <DdsUnitTests/ddsut_ftc_types.h>
|
||||
#include <DdsUnitTests/ddsut_fts_types.h>
|
||||
#include <QObject>
|
||||
#include <QSignalSpy>
|
||||
#include <QThread>
|
||||
|
||||
#include <DdsUnitTests/ddsut.hpp>
|
||||
#include <DdsUnitTests/ddsut_ftc_types.h>
|
||||
#include <DdsUnitTests/ddsut_fts_types.h>
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
#include <DDS/FTC/generic_ftc_impl.h>
|
||||
#include <DDS/FTS/generic_fts_impl.h>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class FunctionTopicTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FunctionTopicTests();
|
||||
public:
|
||||
FunctionTopicTests();
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void initFTSTestCase();
|
||||
void initFTCTestCase();
|
||||
void requestTestCase1();
|
||||
void requestTestCase2();
|
||||
void cleanupTestCase();
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void initFTSTestCase();
|
||||
void initFTCTestCase();
|
||||
void requestTestCase1();
|
||||
void requestTestCase2();
|
||||
void cleanupTestCase();
|
||||
|
||||
Q_SIGNALS:
|
||||
void functionTopicRequestFinished();
|
||||
void functionTopicReply();
|
||||
protected Q_SLOTS:
|
||||
|
||||
void slotRequestedData(const DdsUnitTests::FunctionTopicTestReply &reply, int seqNo, bool bFinished);
|
||||
void slotRequestedData(const DdsUnitTests::FunctionTopicTestWithStateReply &reply, int seqNo, bool bFinished);
|
||||
void slotRequestedDataError(int reason, int seqNo, int requestId);
|
||||
|
||||
void onFunctionTopicRequest(const rti::core::SampleIdentity &sampleId,
|
||||
const DdsUnitTests::FunctionRequest &request);
|
||||
void onFunctionTopicRequest(const rti::core::SampleIdentity &sampleId,
|
||||
const DdsUnitTests::FunctionRequestWithState &request);
|
||||
Q_SIGNALS:
|
||||
void functionTopicRequestFinished();
|
||||
void functionTopicReply();
|
||||
protected Q_SLOTS:
|
||||
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
void requestWithState();
|
||||
private:
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
std::unique_ptr<FTS::FunctionTopicTest> m_fts;
|
||||
std::unique_ptr<FTS::FunctionTopicTestWithState> m_ftsWS;
|
||||
|
||||
std::unique_ptr<FTC::FunctionTopicTest> m_ftc;
|
||||
std::unique_ptr<FTC::FunctionTopicTestWithState> m_ftcWS;
|
||||
void slotRequestedData(const DdsUnitTests::FunctionTopicTestReply& reply, int seqNo, bool bFinished);
|
||||
void slotRequestedData(const DdsUnitTests::FunctionTopicTestWithStateReply& reply, int seqNo, bool bFinished);
|
||||
void slotRequestedDataError(int reason, int seqNo, int requestId);
|
||||
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnectorClient;
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnectorServer;
|
||||
void onFunctionTopicRequest(const rti::core::SampleIdentity& sampleId,
|
||||
const DdsUnitTests::FunctionRequest& request);
|
||||
void onFunctionTopicRequest(const rti::core::SampleIdentity& sampleId,
|
||||
const DdsUnitTests::FunctionRequestWithState& request);
|
||||
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void requestWithState();
|
||||
|
||||
DdsUnitTests::FunctionRequest m_requestTopic;
|
||||
DdsUnitTests::FunctionReply m_replyTopic;
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
std::unique_ptr<FTS::FunctionTopicTest> m_fts;
|
||||
std::unique_ptr<FTS::FunctionTopicTestWithState> m_ftsWS;
|
||||
|
||||
DdsUnitTests::FunctionRequestWithState m_requestTopicWithState;
|
||||
DdsUnitTests::FunctionReplyWithState m_replyTopicWithState;
|
||||
std::unique_ptr<FTC::FunctionTopicTest> m_ftc;
|
||||
std::unique_ptr<FTC::FunctionTopicTestWithState> m_ftcWS;
|
||||
|
||||
Qt::HANDLE m_mainThreadId;
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnectorClient;
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnectorServer;
|
||||
|
||||
DdsUnitTests::FunctionRequest m_requestTopic;
|
||||
DdsUnitTests::FunctionReply m_replyTopic;
|
||||
|
||||
DdsUnitTests::FunctionRequestWithState m_requestTopicWithState;
|
||||
DdsUnitTests::FunctionReplyWithState m_replyTopicWithState;
|
||||
|
||||
Qt::HANDLE m_mainThreadId;
|
||||
};
|
||||
Executable → Regular
+146
-153
@@ -1,226 +1,219 @@
|
||||
|
||||
|
||||
|
||||
#include "generic_data_tests.h"
|
||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||
|
||||
#include <DDS/Generic/generic_data_reader.h>
|
||||
#include <DDS/Generic/generic_data_writer.h>
|
||||
|
||||
#include <QtTest/QTest>
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QtTest/QTest>
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("UnitTests", "log4cxx_ddsUnitTests.props");
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("UnitTests", "log4cxx_ddsUnitTests.props");
|
||||
|
||||
GenericDataTests *tc = new GenericDataTests;
|
||||
GenericDataTests* tc = new GenericDataTests;
|
||||
|
||||
int retCode = QTest::qExec(tc, argc, argv);
|
||||
int retCode = QTest::qExec(tc, argc, argv);
|
||||
|
||||
delete tc;
|
||||
delete tc;
|
||||
|
||||
return retCode;
|
||||
return retCode;
|
||||
}
|
||||
|
||||
GenericDataTests::GenericDataTests()
|
||||
: m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTests.GenericDataTests"))
|
||||
: m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTests.GenericDataTests"))
|
||||
{
|
||||
m_spatialData.equipNo(0);
|
||||
m_testPart.location().equipNo(0);
|
||||
m_testPart.location().participantId(0);
|
||||
m_spatialData.equipNo(0);
|
||||
m_testPart.location().equipNo(0);
|
||||
m_testPart.location().participantId(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GenericDataTests::initTestCase()
|
||||
{
|
||||
DEBUG_LOG(m_logger) <<"GenericDataTests: initTestCase";
|
||||
DEBUG_LOG(m_logger) << "GenericDataTests: initTestCase";
|
||||
|
||||
m_init = new Initialisation();
|
||||
m_init = new Initialisation();
|
||||
|
||||
int domainId = 0;
|
||||
int exerciseId = 2;
|
||||
int domainId = 0;
|
||||
int exerciseId = 2;
|
||||
|
||||
QVERIFY2(m_init, "Initialisation failed");
|
||||
QVERIFY2(m_init->initDDS(domainId, exerciseId, Initialisation::USE_PUBLISHER), "Initialisation (Publisher) failed");
|
||||
QVERIFY2(m_init->initDDS(domainId, exerciseId, Initialisation::USE_SUBSCRIBER), "Initialisation (Subscriber) failed");
|
||||
QVERIFY2(m_init, "Initialisation failed");
|
||||
QVERIFY2(m_init->initDDS(domainId, exerciseId, Initialisation::USE_PUBLISHER), "Initialisation (Publisher) failed");
|
||||
QVERIFY2(m_init->initDDS(domainId, exerciseId, Initialisation::USE_SUBSCRIBER),
|
||||
"Initialisation (Subscriber) failed");
|
||||
|
||||
|
||||
QVERIFY2(m_init->getSubscriberListener(), "Initialisation SubscriberListener failed");
|
||||
QVERIFY2(m_init->getSubscriberListener(), "Initialisation SubscriberListener failed");
|
||||
}
|
||||
|
||||
void GenericDataTests::initDRTestCase()
|
||||
{
|
||||
m_dataReader = new DTC::DroTestParticipant;
|
||||
QVERIFY2(m_dataReader, "Initialisation of GenericDataReader(TestParticipant) failed");
|
||||
QVERIFY2(m_dataReader->create(m_init->getDomainParticipantSub(), m_init->getDDSSubscriber()), "Creating DataReader (TestParticipant) failed");
|
||||
m_init->getSubscriberListener()->addCallback(m_dataReader->getDataReader(), this);
|
||||
m_dataReader = new DTC::DroTestParticipant;
|
||||
QVERIFY2(m_dataReader, "Initialisation of GenericDataReader(TestParticipant) failed");
|
||||
QVERIFY2(m_dataReader->create(m_init->getDomainParticipantSub(), m_init->getDDSSubscriber()),
|
||||
"Creating DataReader (TestParticipant) failed");
|
||||
m_init->getSubscriberListener()->addCallback(m_dataReader->getDataReader(), this);
|
||||
|
||||
m_dataReaderSd = new DTC::DroSpatialData;
|
||||
QVERIFY2(m_dataReaderSd, "Initialisation of GenericDataReader(SpatialData) failed");
|
||||
QVERIFY2(m_dataReaderSd->create(m_init->getDomainParticipantSub(), m_init->getDDSSubscriber()), "Creating DataReader (SpatialData) failed");
|
||||
m_init->getSubscriberListener()->addCallback(m_dataReaderSd->getDataReader(), this);
|
||||
m_dataReaderSd = new DTC::DroSpatialData;
|
||||
QVERIFY2(m_dataReaderSd, "Initialisation of GenericDataReader(SpatialData) failed");
|
||||
QVERIFY2(m_dataReaderSd->create(m_init->getDomainParticipantSub(), m_init->getDDSSubscriber()),
|
||||
"Creating DataReader (SpatialData) failed");
|
||||
m_init->getSubscriberListener()->addCallback(m_dataReaderSd->getDataReader(), this);
|
||||
}
|
||||
|
||||
void GenericDataTests::initDWTestCase()
|
||||
{
|
||||
m_dataWriter = new DTS::DwoTestParticipant();
|
||||
QVERIFY2(m_dataWriter, "Initialisation of GenericDataWriter(TestParticipant) failed");
|
||||
QVERIFY2(m_dataWriter->create(m_init->getDomainParticipant(), m_init->getDDSPublisher()), "Creating DataWriter (TestParticipant) failed");
|
||||
m_dataWriter = new DTS::DwoTestParticipant();
|
||||
QVERIFY2(m_dataWriter, "Initialisation of GenericDataWriter(TestParticipant) failed");
|
||||
QVERIFY2(m_dataWriter->create(m_init->getDomainParticipant(), m_init->getDDSPublisher()),
|
||||
"Creating DataWriter (TestParticipant) failed");
|
||||
|
||||
m_dataWriterSd = new DTS::DwoSpatialData();
|
||||
QVERIFY2(m_dataWriterSd, "Initialisation of GenericDataWriter(SpatialData) failed");
|
||||
QVERIFY2(m_dataWriterSd->create(m_init->getDomainParticipant(), m_init->getDDSPublisher()), "Creating DataWriter (SpatialData) failed");
|
||||
m_dataWriterSd = new DTS::DwoSpatialData();
|
||||
QVERIFY2(m_dataWriterSd, "Initialisation of GenericDataWriter(SpatialData) failed");
|
||||
QVERIFY2(m_dataWriterSd->create(m_init->getDomainParticipant(), m_init->getDDSPublisher()),
|
||||
"Creating DataWriter (SpatialData) failed");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GenericDataTests::dataWriterTestCase()
|
||||
{
|
||||
DEBUG_LOG(m_logger) <<"GenericDataTests: dataWriter";
|
||||
DEBUG_LOG(m_logger) << "GenericDataTests: dataWriter";
|
||||
|
||||
|
||||
DdsUnitTests::SpatialData data;
|
||||
DdsUnitTests::SpatialData data;
|
||||
|
||||
data.participantId(100);
|
||||
data.equipNo(999);
|
||||
data.gpsPosition().lon(70000);
|
||||
data.gpsPosition().lat(90000);
|
||||
data.gpsPosition().z(10);
|
||||
data.participantId(100);
|
||||
data.equipNo(999);
|
||||
data.gpsPosition().lon(70000);
|
||||
data.gpsPosition().lat(90000);
|
||||
data.gpsPosition().z(10);
|
||||
|
||||
data.orientation().heave(10);
|
||||
data.orientation().pitch(10);
|
||||
data.orientation().roll(10);
|
||||
data.orientation().heave(10);
|
||||
data.orientation().pitch(10);
|
||||
data.orientation().roll(10);
|
||||
|
||||
data.velocity().x(10);
|
||||
data.velocity().y(2);
|
||||
data.velocity().z(1);
|
||||
data.velocity().x(10);
|
||||
data.velocity().y(2);
|
||||
data.velocity().z(1);
|
||||
|
||||
data.changedAt(11111);
|
||||
data.changedAt(11111);
|
||||
|
||||
QVERIFY2(m_dataWriterSd->write(data), "Publishing Topic (SpatialData) failed");
|
||||
QVERIFY2(m_dataWriterSd->write(data), "Publishing Topic (SpatialData) failed");
|
||||
|
||||
DdsUnitTests::TestParticipant allData;
|
||||
DdsUnitTests::TestParticipant allData;
|
||||
|
||||
allData.name("************************ Name of TestParticpant ***********************");
|
||||
allData.location() = data;
|
||||
allData.id(10000);
|
||||
QVERIFY2(m_dataWriter->write(allData), "Publishing Topic (TestParticipant) failed");
|
||||
allData.id(11000);
|
||||
QVERIFY2(m_dataWriter->write(allData), "Publishing Topic (TestParticipant) failed");
|
||||
allData.id(11100);
|
||||
QVERIFY2(m_dataWriter->write(allData), "Publishing Topic (TestParticipant) failed");
|
||||
allData.id(11110);
|
||||
QVERIFY2(m_dataWriter->write(allData), "Publishing Topic (TestParticipant) failed");
|
||||
allData.name("************************ Name of TestParticpant ***********************");
|
||||
allData.location() = data;
|
||||
allData.id(10000);
|
||||
QVERIFY2(m_dataWriter->write(allData), "Publishing Topic (TestParticipant) failed");
|
||||
allData.id(11000);
|
||||
QVERIFY2(m_dataWriter->write(allData), "Publishing Topic (TestParticipant) failed");
|
||||
allData.id(11100);
|
||||
QVERIFY2(m_dataWriter->write(allData), "Publishing Topic (TestParticipant) failed");
|
||||
allData.id(11110);
|
||||
QVERIFY2(m_dataWriter->write(allData), "Publishing Topic (TestParticipant) failed");
|
||||
|
||||
allData.id(11111);
|
||||
allData.id(11111);
|
||||
|
||||
QVERIFY2(m_dataWriter->write(allData), "Publishing Topic (TestParticipant) failed");
|
||||
QVERIFY2(m_dataWriter->write(allData), "Publishing Topic (TestParticipant) failed");
|
||||
}
|
||||
|
||||
|
||||
void GenericDataTests::dataReaderTestCase()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "GenericDataTests: dataReader";
|
||||
DEBUG_LOG(m_logger) << "GenericDataTests: dataReader";
|
||||
|
||||
|
||||
QTRY_COMPARE(m_spatialData.equipNo(), 999);
|
||||
QCOMPARE(m_spatialData.changedAt(), 11111);
|
||||
|
||||
QTRY_COMPARE(m_testPart.location().equipNo(), 999);
|
||||
QCOMPARE(m_testPart.location().participantId(), 100);
|
||||
QTRY_COMPARE(m_spatialData.equipNo(), 999);
|
||||
QCOMPARE(m_spatialData.changedAt(), 11111);
|
||||
|
||||
bool bSeenUnreadSamples = false;
|
||||
dds::sub::LoanedSamples<DdsUnitTests::TestParticipant> vecTp = m_dataReader->readAlive(bSeenUnreadSamples);
|
||||
INFO_LOG(m_logger) <<"vecTp size: " << vecTp.length();
|
||||
QCOMPARE(vecTp.length(), static_cast<decltype(vecTp.length())>(5));
|
||||
QCOMPARE(vecTp[0].data().id(), 10000);
|
||||
QCOMPARE(vecTp[1].data().id(), 11000);
|
||||
QCOMPARE(vecTp[2].data().id(), 11100);
|
||||
QCOMPARE(vecTp[3].data().id(), 11110);
|
||||
QCOMPARE(vecTp[4].data().id(), 11111);
|
||||
QTRY_COMPARE(m_testPart.location().equipNo(), 999);
|
||||
QCOMPARE(m_testPart.location().participantId(), 100);
|
||||
|
||||
dds::sub::LoanedSamples<DdsUnitTests::TestParticipant> vecTpLoaned = m_dataReader->takeAlive(bSeenUnreadSamples);
|
||||
INFO_LOG(m_logger) <<"vecTpLoaned size: " << vecTp.length();
|
||||
QCOMPARE(vecTpLoaned.length(), static_cast<decltype(vecTpLoaned.length())>(5));
|
||||
QCOMPARE(vecTpLoaned[0].data().id(), 10000);
|
||||
QCOMPARE(vecTpLoaned[1].data().id(), 11000);
|
||||
QCOMPARE(vecTpLoaned[2].data().id(), 11100);
|
||||
QCOMPARE(vecTpLoaned[3].data().id(), 11110);
|
||||
QCOMPARE(vecTpLoaned[4].data().id(), 11111);
|
||||
bool bSeenUnreadSamples = false;
|
||||
dds::sub::LoanedSamples<DdsUnitTests::TestParticipant> vecTp = m_dataReader->readAlive(bSeenUnreadSamples);
|
||||
INFO_LOG(m_logger) << "vecTp size: " << vecTp.length();
|
||||
QCOMPARE(vecTp.length(), static_cast<decltype(vecTp.length())>(5));
|
||||
QCOMPARE(vecTp[0].data().id(), 10000);
|
||||
QCOMPARE(vecTp[1].data().id(), 11000);
|
||||
QCOMPARE(vecTp[2].data().id(), 11100);
|
||||
QCOMPARE(vecTp[3].data().id(), 11110);
|
||||
QCOMPARE(vecTp[4].data().id(), 11111);
|
||||
|
||||
dds::sub::LoanedSamples<DdsUnitTests::TestParticipant> vecTpLoaned = m_dataReader->takeAlive(bSeenUnreadSamples);
|
||||
INFO_LOG(m_logger) << "vecTpLoaned size: " << vecTp.length();
|
||||
QCOMPARE(vecTpLoaned.length(), static_cast<decltype(vecTpLoaned.length())>(5));
|
||||
QCOMPARE(vecTpLoaned[0].data().id(), 10000);
|
||||
QCOMPARE(vecTpLoaned[1].data().id(), 11000);
|
||||
QCOMPARE(vecTpLoaned[2].data().id(), 11100);
|
||||
QCOMPARE(vecTpLoaned[3].data().id(), 11110);
|
||||
QCOMPARE(vecTpLoaned[4].data().id(), 11111);
|
||||
}
|
||||
|
||||
|
||||
void GenericDataTests::deleteDataReaderTestCase()
|
||||
{
|
||||
DdsUnitTests::TestParticipant data;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
data.id(i);
|
||||
m_dataWriter->write(data);
|
||||
}
|
||||
m_init->getSubscriberListener()->removeCallback(m_dataReader->getDataReader(), this);
|
||||
delete m_dataReader;
|
||||
m_dataReader = nullptr;
|
||||
for(int i = 0; i < 1000; ++i)
|
||||
{
|
||||
data.id(i);
|
||||
m_dataWriter->write(data);
|
||||
}
|
||||
DdsUnitTests::TestParticipant data;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
data.id(i);
|
||||
m_dataWriter->write(data);
|
||||
}
|
||||
m_init->getSubscriberListener()->removeCallback(m_dataReader->getDataReader(), this);
|
||||
delete m_dataReader;
|
||||
m_dataReader = nullptr;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
data.id(i);
|
||||
m_dataWriter->write(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GenericDataTests::cleanupTestCase()
|
||||
{
|
||||
DEBUG_LOG(m_logger) <<"GenericDataTests: cleanupTestCase";
|
||||
if (m_dataReader)
|
||||
{
|
||||
m_init->getSubscriberListener()->removeCallback(m_dataReader->getDataReader(), this);
|
||||
delete m_dataReader;
|
||||
}
|
||||
if (m_dataReaderSd)
|
||||
{
|
||||
m_init->getSubscriberListener()->removeCallback(m_dataReaderSd->getDataReader(), this);
|
||||
delete m_dataReaderSd;
|
||||
}
|
||||
m_init->cleanupSubscriberListener();
|
||||
delete m_dataWriter;
|
||||
delete m_dataWriterSd;
|
||||
delete m_init;
|
||||
deleteLater();
|
||||
DEBUG_LOG(m_logger) << "GenericDataTests: cleanupTestCase";
|
||||
if (m_dataReader)
|
||||
{
|
||||
m_init->getSubscriberListener()->removeCallback(m_dataReader->getDataReader(), this);
|
||||
delete m_dataReader;
|
||||
}
|
||||
if (m_dataReaderSd)
|
||||
{
|
||||
m_init->getSubscriberListener()->removeCallback(m_dataReaderSd->getDataReader(), this);
|
||||
delete m_dataReaderSd;
|
||||
}
|
||||
m_init->cleanupSubscriberListener();
|
||||
delete m_dataWriter;
|
||||
delete m_dataWriterSd;
|
||||
delete m_init;
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void GenericDataTests::processData(const DdsUnitTests::SpatialData &data, DataModification modType)
|
||||
void GenericDataTests::processData(const DdsUnitTests::SpatialData& data, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "SpatialData: equipNo = " << data.equipNo() << " modType: " << modType;
|
||||
m_spatialData = data;
|
||||
DEBUG_LOG(m_logger) << "SpatialData: equipNo = " << data.equipNo() << " modType: " << modType;
|
||||
m_spatialData = data;
|
||||
}
|
||||
|
||||
void GenericDataTests::processData(const DdsUnitTests::TestParticipant &data, const dds::sub::SampleInfo &si)
|
||||
void GenericDataTests::processData(const DdsUnitTests::TestParticipant& data, const dds::sub::SampleInfo& si)
|
||||
{
|
||||
Q_UNUSED(si);
|
||||
DEBUG_LOG(m_logger) << "TestParticipant: equipNo = " << data.location().equipNo();
|
||||
m_testPart = data;
|
||||
Q_UNUSED(si);
|
||||
DEBUG_LOG(m_logger) << "TestParticipant: equipNo = " << data.location().equipNo();
|
||||
m_testPart = data;
|
||||
}
|
||||
|
||||
void GenericDataTests::droDataAvailable(const std::string &topicType, const std::string &topicName)
|
||||
void GenericDataTests::droDataAvailable(const std::string& topicType, const std::string& topicName)
|
||||
{
|
||||
Q_UNUSED(topicName)
|
||||
DEBUG_LOG(m_logger) << "IN droDataAvailable: type = " << topicType;
|
||||
if (topicType == "DdsUnitTests::TestParticipant")
|
||||
{
|
||||
m_init->getSubscriberListener()->enableCallback(m_dataReader->getDataReader(), this);
|
||||
m_dataReader->read([this](const DdsUnitTests::TestParticipant &data, const dds::sub::SampleInfo &si) { processData(data, si); });
|
||||
}
|
||||
else if(topicType == "DdsUnitTests::SpatialData")
|
||||
{
|
||||
m_init->getSubscriberListener()->enableCallback(m_dataReaderSd->getDataReader(), this);
|
||||
m_dataReaderSd->read([this](const DdsUnitTests::SpatialData &data, DataModification modType) { processData(data, modType); } );
|
||||
}
|
||||
Q_UNUSED(topicName)
|
||||
DEBUG_LOG(m_logger) << "IN droDataAvailable: type = " << topicType;
|
||||
if (topicType == "DdsUnitTests::TestParticipant")
|
||||
{
|
||||
m_init->getSubscriberListener()->enableCallback(m_dataReader->getDataReader(), this);
|
||||
m_dataReader->read([this](const DdsUnitTests::TestParticipant& data, const dds::sub::SampleInfo& si) {
|
||||
processData(data, si);
|
||||
});
|
||||
}
|
||||
else if (topicType == "DdsUnitTests::SpatialData")
|
||||
{
|
||||
m_init->getSubscriberListener()->enableCallback(m_dataReaderSd->getDataReader(), this);
|
||||
m_dataReaderSd->read(
|
||||
[this](const DdsUnitTests::SpatialData& data, DataModification modType) { processData(data, modType); });
|
||||
}
|
||||
}
|
||||
Executable → Regular
+38
-42
@@ -2,67 +2,63 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "initialisation.h"
|
||||
|
||||
#include <DDS/Generic/subscriber_listener.h>
|
||||
#include <DdsUnitTests/ddsut_dtc_types.h>
|
||||
#include <DdsUnitTests/ddsut_dts_types.h>
|
||||
|
||||
#include <DDS/Generic/subscriber_listener.h>
|
||||
#include <LtsUtilsCore/data_modification_enum.h>
|
||||
#include <QObject>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class GenericDataTests : public DDSGeneric::SubscriberListenerCallback
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GenericDataTests();
|
||||
public:
|
||||
GenericDataTests();
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void initDRTestCase();
|
||||
void initDWTestCase();
|
||||
void dataWriterTestCase();
|
||||
void dataReaderTestCase();
|
||||
void deleteDataReaderTestCase();
|
||||
void cleanupTestCase();
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void initDRTestCase();
|
||||
void initDWTestCase();
|
||||
void dataWriterTestCase();
|
||||
void dataReaderTestCase();
|
||||
void deleteDataReaderTestCase();
|
||||
void cleanupTestCase();
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger &m_logger;
|
||||
void droDataAvailable(const std::string &topicType, const std::string &topicName) override;
|
||||
void noWriterAnymore(const std::string &topicType, const std::string &topicName) override
|
||||
{
|
||||
Q_UNUSED(topicType);
|
||||
Q_UNUSED(topicName);
|
||||
}
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void droDataAvailable(const std::string& topicType, const std::string& topicName) override;
|
||||
|
||||
void writerAvailable(const std::string &topicType, const std::string &topicName) override
|
||||
{
|
||||
Q_UNUSED(topicType);
|
||||
Q_UNUSED(topicName);
|
||||
}
|
||||
void noWriterAnymore(const std::string& topicType, const std::string& topicName) override
|
||||
{
|
||||
Q_UNUSED(topicType);
|
||||
Q_UNUSED(topicName);
|
||||
}
|
||||
|
||||
void processData(const DdsUnitTests::TestParticipant &data, const dds::sub::SampleInfo &si);
|
||||
void processData(const DdsUnitTests::SpatialData &data, DataModification modType);
|
||||
void writerAvailable(const std::string& topicType, const std::string& topicName) override
|
||||
{
|
||||
Q_UNUSED(topicType);
|
||||
Q_UNUSED(topicName);
|
||||
}
|
||||
|
||||
private:
|
||||
Initialisation *m_init = nullptr;
|
||||
void processData(const DdsUnitTests::TestParticipant& data, const dds::sub::SampleInfo& si);
|
||||
void processData(const DdsUnitTests::SpatialData& data, DataModification modType);
|
||||
|
||||
DTS::DwoTestParticipant *m_dataWriter = nullptr;
|
||||
DTC::DroTestParticipant *m_dataReader = nullptr;
|
||||
private:
|
||||
Initialisation* m_init = nullptr;
|
||||
|
||||
DTS::DwoSpatialData *m_dataWriterSd = nullptr;
|
||||
DTC::DroSpatialData *m_dataReaderSd = nullptr;
|
||||
DTS::DwoTestParticipant* m_dataWriter = nullptr;
|
||||
DTC::DroTestParticipant* m_dataReader = nullptr;
|
||||
|
||||
DdsUnitTests::SpatialData m_spatialData;
|
||||
DdsUnitTests::TestParticipant m_testPart;
|
||||
DTS::DwoSpatialData* m_dataWriterSd = nullptr;
|
||||
DTC::DroSpatialData* m_dataReaderSd = nullptr;
|
||||
|
||||
DdsUnitTests::SpatialData m_spatialData;
|
||||
DdsUnitTests::TestParticipant m_testPart;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+47
-58
@@ -2,11 +2,9 @@
|
||||
|
||||
#include "initialisation.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
#include <DDS/QosProfile/DDS_DefaultQos.h>
|
||||
#include <Lts/Common/ProjectConfig/project_defines.h>
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
Initialisation::Initialisation() : m_domainParticipant(nullptr)
|
||||
, m_domainParticipantSub(nullptr)
|
||||
@@ -16,81 +14,72 @@ Initialisation::Initialisation() : m_domainParticipant(nullptr)
|
||||
, m_ddsSubscriber(nullptr)
|
||||
, m_subListener(new DDSGeneric::SubscriberListener)
|
||||
.getNGLLogger("UnitTests.Initialisation")),
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
|
||||
if (!DDS::QosProfile::setDefault())
|
||||
ERROR_LOG(m_logger) << "Error setting default QoS from xml-file ";
|
||||
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger())
|
||||
{
|
||||
if (!DDS::QosProfile::setDefault())
|
||||
ERROR_LOG(m_logger) << "Error setting default QoS from xml-file ";
|
||||
}
|
||||
|
||||
Initialisation::~Initialisation()
|
||||
{
|
||||
cleanupSubscriberListener();
|
||||
m_ddsSubscriber = nullptr;
|
||||
m_ddsPublisher = nullptr;
|
||||
cleanupSubscriberListener();
|
||||
m_ddsSubscriber = nullptr;
|
||||
m_ddsPublisher = nullptr;
|
||||
}
|
||||
|
||||
void Initialisation::cleanupSubscriberListener()
|
||||
{
|
||||
if (m_ddsSubscriber != nullptr && m_subListener != nullptr)
|
||||
{
|
||||
m_ddsSubscriber.listener(nullptr, dds::core::status::StatusMask::none());
|
||||
delete m_subListener;
|
||||
m_subListener = nullptr;
|
||||
}
|
||||
if (m_ddsSubscriber != nullptr && m_subListener != nullptr)
|
||||
{
|
||||
m_ddsSubscriber.listener(nullptr, dds::core::status::StatusMask::none());
|
||||
delete m_subListener;
|
||||
m_subListener = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Initialisation::initDDS(int domainId, int exerciseId, PubSub pubsub)
|
||||
{
|
||||
if (m_domainParticipant == nullptr)
|
||||
m_domainParticipant = dds::domain::DomainParticipant(domainId, DDS::QosProfile::domainParticipantShm());
|
||||
if (m_domainParticipant == nullptr)
|
||||
m_domainParticipant = dds::domain::DomainParticipant(domainId, DDS::QosProfile::domainParticipantShm());
|
||||
|
||||
|
||||
|
||||
if (pubsub == USE_PUBLISHER || pubsub == USE_PUB_SUB)
|
||||
{
|
||||
dds::pub::qos::PublisherQos publisherQos = m_domainParticipant.default_publisher_qos();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Publish on partition " << IDL::exercisePartition(exerciseId);
|
||||
|
||||
|
||||
dds::core::policy::Partition partitionQos;
|
||||
partitionQos.name( { IDL::exercisePartition(exerciseId) } );
|
||||
publisherQos << partitionQos;
|
||||
|
||||
m_ddsPublisher = dds::pub::Publisher(m_domainParticipant,
|
||||
publisherQos);
|
||||
}
|
||||
|
||||
if (pubsub == USE_SUBSCRIBER || pubsub == USE_PUB_SUB)
|
||||
{
|
||||
dds::domain::DomainParticipant domainPart = m_domainParticipant;
|
||||
if ( domainPart == nullptr || m_domainParticipantSub == nullptr)
|
||||
if (pubsub == USE_PUBLISHER || pubsub == USE_PUB_SUB)
|
||||
{
|
||||
m_domainParticipantSub = dds::domain::DomainParticipant(domainId, DDS::QosProfile::domainParticipantShm());
|
||||
domainPart = m_domainParticipantSub;
|
||||
dds::pub::qos::PublisherQos publisherQos = m_domainParticipant.default_publisher_qos();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Publish on partition " << IDL::exercisePartition(exerciseId);
|
||||
|
||||
dds::core::policy::Partition partitionQos;
|
||||
partitionQos.name({IDL::exercisePartition(exerciseId)});
|
||||
publisherQos << partitionQos;
|
||||
|
||||
m_ddsPublisher = dds::pub::Publisher(m_domainParticipant, publisherQos);
|
||||
}
|
||||
|
||||
dds::sub::qos::SubscriberQos subscriberQos = domainPart.default_subscriber_qos();
|
||||
if (pubsub == USE_SUBSCRIBER || pubsub == USE_PUB_SUB)
|
||||
{
|
||||
dds::domain::DomainParticipant domainPart = m_domainParticipant;
|
||||
if (domainPart == nullptr || m_domainParticipantSub == nullptr)
|
||||
{
|
||||
m_domainParticipantSub = dds::domain::DomainParticipant(domainId, DDS::QosProfile::domainParticipantShm());
|
||||
domainPart = m_domainParticipantSub;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Subsribing on partition " << IDL::exercisePartition(exerciseId);
|
||||
dds::sub::qos::SubscriberQos subscriberQos = domainPart.default_subscriber_qos();
|
||||
|
||||
|
||||
dds::core::policy::Partition partitionQos;
|
||||
partitionQos.name( { IDL::exercisePartition(exerciseId) } );
|
||||
subscriberQos << partitionQos;
|
||||
DEBUG_LOG(m_logger) << "Subsribing on partition " << IDL::exercisePartition(exerciseId);
|
||||
|
||||
m_ddsSubscriber = dds::sub::Subscriber(domainPart,
|
||||
subscriberQos,
|
||||
m_subListener,
|
||||
m_subListener->mask());
|
||||
}
|
||||
dds::core::policy::Partition partitionQos;
|
||||
partitionQos.name({IDL::exercisePartition(exerciseId)});
|
||||
subscriberQos << partitionQos;
|
||||
|
||||
if (m_domainId == 0)
|
||||
m_domainId = domainId;
|
||||
m_ddsSubscriber = dds::sub::Subscriber(domainPart, subscriberQos, m_subListener, m_subListener->mask());
|
||||
}
|
||||
|
||||
if (m_exerciseId < 0)
|
||||
m_exerciseId = exerciseId;
|
||||
if (m_domainId == 0)
|
||||
m_domainId = domainId;
|
||||
|
||||
return true;
|
||||
if (m_exerciseId < 0)
|
||||
m_exerciseId = exerciseId;
|
||||
|
||||
return true;
|
||||
}
|
||||
Executable → Regular
+42
-31
@@ -5,43 +5,54 @@
|
||||
#include <DDS/Generic/generic_base.h>
|
||||
#include <DDS/Generic/subscriber_listener.h>
|
||||
|
||||
namespace NGL {
|
||||
class INGLLogger;
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class Initialisation
|
||||
{
|
||||
public:
|
||||
Initialisation();
|
||||
virtual ~Initialisation();
|
||||
public:
|
||||
Initialisation();
|
||||
virtual ~Initialisation();
|
||||
|
||||
enum PubSub
|
||||
{
|
||||
USE_PUBLISHER = 1,
|
||||
USE_SUBSCRIBER = 2,
|
||||
USE_PUB_SUB = 4
|
||||
};
|
||||
enum PubSub { USE_PUBLISHER = 1, USE_SUBSCRIBER = 2, USE_PUB_SUB = 4 };
|
||||
|
||||
|
||||
bool initDDS(int domainId, int exerciseId, PubSub pubsub = USE_PUBLISHER);
|
||||
void cleanupSubscriberListener();
|
||||
bool initDDS(int domainId, int exerciseId, PubSub pubsub = USE_PUBLISHER);
|
||||
void cleanupSubscriberListener();
|
||||
|
||||
dds::domain::DomainParticipant getDomainParticipant() { return m_domainParticipant; }
|
||||
dds::domain::DomainParticipant getDomainParticipantSub() { return m_domainParticipantSub != nullptr ? m_domainParticipantSub : m_domainParticipant; }
|
||||
dds::pub::Publisher getDDSPublisher() { return m_ddsPublisher; }
|
||||
dds::sub::Subscriber getDDSSubscriber() { return m_ddsSubscriber; }
|
||||
DDSGeneric::SubscriberListener *getSubscriberListener() { return m_subListener; }
|
||||
dds::domain::DomainParticipant getDomainParticipant()
|
||||
{
|
||||
return m_domainParticipant;
|
||||
}
|
||||
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
dds::domain::DomainParticipant m_domainParticipant;
|
||||
dds::domain::DomainParticipant m_domainParticipantSub;
|
||||
int m_domainId;
|
||||
int m_exerciseId;
|
||||
dds::pub::Publisher m_ddsPublisher;
|
||||
dds::sub::Subscriber m_ddsSubscriber;
|
||||
DDSGeneric::SubscriberListener *m_subListener;
|
||||
dds::domain::DomainParticipant getDomainParticipantSub()
|
||||
{
|
||||
return m_domainParticipantSub != nullptr ? m_domainParticipantSub : m_domainParticipant;
|
||||
}
|
||||
|
||||
dds::pub::Publisher getDDSPublisher()
|
||||
{
|
||||
return m_ddsPublisher;
|
||||
}
|
||||
|
||||
dds::sub::Subscriber getDDSSubscriber()
|
||||
{
|
||||
return m_ddsSubscriber;
|
||||
}
|
||||
|
||||
DDSGeneric::SubscriberListener* getSubscriberListener()
|
||||
{
|
||||
return m_subListener;
|
||||
}
|
||||
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
dds::domain::DomainParticipant m_domainParticipant;
|
||||
dds::domain::DomainParticipant m_domainParticipantSub;
|
||||
int m_domainId;
|
||||
int m_exerciseId;
|
||||
dds::pub::Publisher m_ddsPublisher;
|
||||
dds::sub::Subscriber m_ddsSubscriber;
|
||||
DDSGeneric::SubscriberListener* m_subListener;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+443
-500
File diff suppressed because it is too large.
Load diff
Executable → Regular
+362
-359
@@ -1,8 +1,8 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <dds/core/cond/GuardCondition.hpp>
|
||||
#include <dds/core/cond/StatusCondition.hpp>
|
||||
#include <dds/core/cond/WaitSet.hpp>
|
||||
@@ -16,266 +16,263 @@
|
||||
#include <dds/topic/find.hpp>
|
||||
#include <rti/pub/WriteParams.hpp>
|
||||
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
namespace connext
|
||||
{
|
||||
|
||||
namespace DebugInfo
|
||||
{
|
||||
inline QByteArray toReadable(const rti::core::Guid &guid)
|
||||
inline QByteArray toReadable(const rti::core::Guid& guid)
|
||||
{
|
||||
const QByteArray str(reinterpret_cast<const char *>(&guid[0]), 16);
|
||||
return str.toHex();
|
||||
}
|
||||
inline QByteArray toReadable(const rti::core::SequenceNumber &seqNo,
|
||||
const rti::core::Guid &guid)
|
||||
{
|
||||
return "SeqNo: " + QByteArray::number(seqNo.value()) +
|
||||
", Guid-DW: " + toReadable(guid);
|
||||
}
|
||||
inline QByteArray toReadable(const rti::core::SampleIdentity &identiy)
|
||||
{
|
||||
return toReadable(identiy.sequence_number(), identiy.writer_guid());
|
||||
}
|
||||
const QByteArray str(reinterpret_cast<const char*>(&guid[0]), 16);
|
||||
return str.toHex();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
dds::topic::Topic<T> getTopic(const dds::domain::DomainParticipant &participant,
|
||||
const std::string &topicName)
|
||||
inline QByteArray toReadable(const rti::core::SequenceNumber& seqNo, const rti::core::Guid& guid)
|
||||
{
|
||||
using DataTopic = dds::topic::Topic<T>;
|
||||
auto ret = dds::topic::find<DataTopic>(participant, topicName);
|
||||
if (ret != nullptr)
|
||||
return ret;
|
||||
return DataTopic(participant, topicName);
|
||||
return "SeqNo: " + QByteArray::number(seqNo.value()) + ", Guid-DW: " + toReadable(guid);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
class SampleBase
|
||||
inline QByteArray toReadable(const rti::core::SampleIdentity& identiy)
|
||||
{
|
||||
protected:
|
||||
SampleBase() = default;
|
||||
virtual ~SampleBase() = default;
|
||||
return toReadable(identiy.sequence_number(), identiy.writer_guid());
|
||||
}
|
||||
} // namespace DebugInfo
|
||||
|
||||
public:
|
||||
void set_data(const T &data)
|
||||
{
|
||||
m_data = data;
|
||||
}
|
||||
T &data()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
const T &data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
protected:
|
||||
T m_data;
|
||||
template <typename T>
|
||||
dds::topic::Topic<T> getTopic(const dds::domain::DomainParticipant& participant, const std::string& topicName)
|
||||
{
|
||||
using DataTopic = dds::topic::Topic<T>;
|
||||
auto ret = dds::topic::find<DataTopic>(participant, topicName);
|
||||
if (ret != nullptr)
|
||||
return ret;
|
||||
return DataTopic(participant, topicName);
|
||||
}
|
||||
|
||||
template <typename T> class SampleBase
|
||||
{
|
||||
protected:
|
||||
SampleBase() = default;
|
||||
virtual ~SampleBase() = default;
|
||||
|
||||
public:
|
||||
void set_data(const T& data)
|
||||
{
|
||||
m_data = data;
|
||||
}
|
||||
|
||||
T& data()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
const T& data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
protected:
|
||||
T m_data;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class WriteSample : public SampleBase<T>
|
||||
template <typename T> class WriteSample : public SampleBase<T>
|
||||
{
|
||||
public:
|
||||
WriteSample() = default;
|
||||
public:
|
||||
WriteSample() = default;
|
||||
|
||||
void set_info(const rti::pub::WriteParams &info)
|
||||
{
|
||||
m_info = info;
|
||||
}
|
||||
rti::pub::WriteParams &info()
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
const rti::pub::WriteParams &info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
void set_info(const rti::pub::WriteParams& info)
|
||||
{
|
||||
m_info = info;
|
||||
}
|
||||
|
||||
private:
|
||||
rti::pub::WriteParams m_info;
|
||||
rti::pub::WriteParams& info()
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
const rti::pub::WriteParams& info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
private:
|
||||
rti::pub::WriteParams m_info;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class WriteSampleRef
|
||||
template <typename T> class WriteSampleRef
|
||||
{
|
||||
public:
|
||||
WriteSampleRef()
|
||||
: m_data_ptr(nullptr)
|
||||
, m_info_ptr(nullptr)
|
||||
{}
|
||||
public:
|
||||
WriteSampleRef() : m_data_ptr(nullptr), m_info_ptr(nullptr) {}
|
||||
|
||||
void set_data(T *data_ptr)
|
||||
{
|
||||
m_data_ptr = data_ptr;
|
||||
}
|
||||
void set_data(T* data_ptr)
|
||||
{
|
||||
m_data_ptr = data_ptr;
|
||||
}
|
||||
|
||||
T &data()
|
||||
{
|
||||
return *m_data_ptr;
|
||||
}
|
||||
T& data()
|
||||
{
|
||||
return *m_data_ptr;
|
||||
}
|
||||
|
||||
void set_info(rti::pub::WriteParams *info_ptr)
|
||||
{
|
||||
m_info_ptr = info_ptr;
|
||||
}
|
||||
void set_info(rti::pub::WriteParams* info_ptr)
|
||||
{
|
||||
m_info_ptr = info_ptr;
|
||||
}
|
||||
|
||||
rti::pub::WriteParams &info()
|
||||
{
|
||||
return *m_info_ptr;
|
||||
}
|
||||
rti::pub::WriteParams& info()
|
||||
{
|
||||
return *m_info_ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
T *m_data_ptr;
|
||||
rti::pub::WriteParams *m_info_ptr;
|
||||
private:
|
||||
T* m_data_ptr;
|
||||
rti::pub::WriteParams* m_info_ptr;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Sample : public SampleBase<T>
|
||||
template <typename T> class Sample : public SampleBase<T>
|
||||
{
|
||||
public:
|
||||
Sample() = default;
|
||||
public:
|
||||
Sample() = default;
|
||||
|
||||
void set_info(const dds::sub::SampleInfo &info)
|
||||
{
|
||||
m_info = info;
|
||||
}
|
||||
dds::sub::SampleInfo &info()
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
const dds::sub::SampleInfo &info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
void set_info(const dds::sub::SampleInfo& info)
|
||||
{
|
||||
m_info = info;
|
||||
}
|
||||
|
||||
void set_identity(const rti::core::SampleIdentity &identity)
|
||||
{
|
||||
m_identity = identity;
|
||||
}
|
||||
dds::sub::SampleInfo& info()
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
const rti::core::SampleIdentity &identity() const
|
||||
{
|
||||
return m_identity;
|
||||
}
|
||||
const dds::sub::SampleInfo& info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
private:
|
||||
dds::sub::SampleInfo m_info;
|
||||
rti::core::SampleIdentity m_identity;
|
||||
void set_identity(const rti::core::SampleIdentity& identity)
|
||||
{
|
||||
m_identity = identity;
|
||||
}
|
||||
|
||||
const rti::core::SampleIdentity& identity() const
|
||||
{
|
||||
return m_identity;
|
||||
}
|
||||
|
||||
private:
|
||||
dds::sub::SampleInfo m_info;
|
||||
rti::core::SampleIdentity m_identity;
|
||||
};
|
||||
|
||||
class RequesterParams
|
||||
{
|
||||
public:
|
||||
explicit RequesterParams(const dds::domain::DomainParticipant &participant)
|
||||
: m_participant(participant)
|
||||
, m_publisher(nullptr)
|
||||
, m_subscriber(nullptr)
|
||||
{}
|
||||
virtual ~RequesterParams() = default;
|
||||
public:
|
||||
explicit RequesterParams(const dds::domain::DomainParticipant& participant)
|
||||
: m_participant(participant), m_publisher(nullptr), m_subscriber(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
const std::string &request_topic_name() const
|
||||
{
|
||||
return m_request_topic_name;
|
||||
}
|
||||
void request_topic_name(const std::string &request_topic_name)
|
||||
{
|
||||
m_request_topic_name = request_topic_name;
|
||||
}
|
||||
virtual ~RequesterParams() = default;
|
||||
|
||||
const std::string &reply_topic_name() const
|
||||
{
|
||||
return m_reply_topic_name;
|
||||
}
|
||||
void reply_topic_name(const std::string &reply_topic_name)
|
||||
{
|
||||
m_reply_topic_name = reply_topic_name;
|
||||
}
|
||||
const std::string& request_topic_name() const
|
||||
{
|
||||
return m_request_topic_name;
|
||||
}
|
||||
|
||||
const dds::domain::DomainParticipant &domainParticipant() const
|
||||
{
|
||||
return m_participant;
|
||||
}
|
||||
void request_topic_name(const std::string& request_topic_name)
|
||||
{
|
||||
m_request_topic_name = request_topic_name;
|
||||
}
|
||||
|
||||
const dds::pub::Publisher &publisher() const
|
||||
{
|
||||
return m_publisher;
|
||||
}
|
||||
void publisher(const dds::pub::Publisher &publisher)
|
||||
{
|
||||
m_publisher = publisher;
|
||||
}
|
||||
const std::string& reply_topic_name() const
|
||||
{
|
||||
return m_reply_topic_name;
|
||||
}
|
||||
|
||||
const dds::sub::Subscriber &subscriber() const
|
||||
{
|
||||
return m_subscriber;
|
||||
}
|
||||
void subscriber(const dds::sub::Subscriber &subscriber)
|
||||
{
|
||||
m_subscriber = subscriber;
|
||||
}
|
||||
void reply_topic_name(const std::string& reply_topic_name)
|
||||
{
|
||||
m_reply_topic_name = reply_topic_name;
|
||||
}
|
||||
|
||||
const dds::pub::qos::DataWriterQos &datawriter_qos() const
|
||||
{
|
||||
return m_datawriter_qos;
|
||||
}
|
||||
void datawriter_qos(const dds::pub::qos::DataWriterQos &datawriter_qos)
|
||||
{
|
||||
m_datawriter_qos = datawriter_qos;
|
||||
}
|
||||
const dds::domain::DomainParticipant& domainParticipant() const
|
||||
{
|
||||
return m_participant;
|
||||
}
|
||||
|
||||
const dds::sub::qos::DataReaderQos &datareader_qos() const
|
||||
{
|
||||
return m_datareader_qos;
|
||||
}
|
||||
void datareader_qos(const dds::sub::qos::DataReaderQos &datareader_qos)
|
||||
{
|
||||
m_datareader_qos = datareader_qos;
|
||||
}
|
||||
const dds::pub::Publisher& publisher() const
|
||||
{
|
||||
return m_publisher;
|
||||
}
|
||||
|
||||
protected:
|
||||
dds::domain::DomainParticipant m_participant;
|
||||
dds::pub::Publisher m_publisher;
|
||||
dds::sub::Subscriber m_subscriber;
|
||||
dds::pub::qos::DataWriterQos m_datawriter_qos;
|
||||
dds::sub::qos::DataReaderQos m_datareader_qos;
|
||||
std::string m_request_topic_name;
|
||||
std::string m_reply_topic_name;
|
||||
void publisher(const dds::pub::Publisher& publisher)
|
||||
{
|
||||
m_publisher = publisher;
|
||||
}
|
||||
|
||||
const dds::sub::Subscriber& subscriber() const
|
||||
{
|
||||
return m_subscriber;
|
||||
}
|
||||
|
||||
void subscriber(const dds::sub::Subscriber& subscriber)
|
||||
{
|
||||
m_subscriber = subscriber;
|
||||
}
|
||||
|
||||
const dds::pub::qos::DataWriterQos& datawriter_qos() const
|
||||
{
|
||||
return m_datawriter_qos;
|
||||
}
|
||||
|
||||
void datawriter_qos(const dds::pub::qos::DataWriterQos& datawriter_qos)
|
||||
{
|
||||
m_datawriter_qos = datawriter_qos;
|
||||
}
|
||||
|
||||
const dds::sub::qos::DataReaderQos& datareader_qos() const
|
||||
{
|
||||
return m_datareader_qos;
|
||||
}
|
||||
|
||||
void datareader_qos(const dds::sub::qos::DataReaderQos& datareader_qos)
|
||||
{
|
||||
m_datareader_qos = datareader_qos;
|
||||
}
|
||||
|
||||
protected:
|
||||
dds::domain::DomainParticipant m_participant;
|
||||
dds::pub::Publisher m_publisher;
|
||||
dds::sub::Subscriber m_subscriber;
|
||||
dds::pub::qos::DataWriterQos m_datawriter_qos;
|
||||
dds::sub::qos::DataReaderQos m_datareader_qos;
|
||||
std::string m_request_topic_name;
|
||||
std::string m_reply_topic_name;
|
||||
};
|
||||
|
||||
template <typename REQUEST, typename REPLY>
|
||||
class ReplierParams : public RequesterParams
|
||||
template <typename REQUEST, typename REPLY> class ReplierParams : public RequesterParams
|
||||
{
|
||||
public:
|
||||
using RequesterParams::RequesterParams;
|
||||
public:
|
||||
using RequesterParams::RequesterParams;
|
||||
};
|
||||
|
||||
template<typename REQUEST, typename REPLY>
|
||||
class ReplyRequestBase
|
||||
template <typename REQUEST, typename REPLY> class ReplyRequestBase
|
||||
{
|
||||
protected:
|
||||
explicit ReplyRequestBase(const connext::RequesterParams &requesterParams)
|
||||
: m_requestTopic(getTopic<REQUEST>(requesterParams.domainParticipant(),
|
||||
requesterParams.request_topic_name()))
|
||||
, m_replyTopic(getTopic<REPLY>(requesterParams.domainParticipant(),
|
||||
requesterParams.reply_topic_name()))
|
||||
{}
|
||||
virtual ~ReplyRequestBase() = default;
|
||||
protected:
|
||||
explicit ReplyRequestBase(const connext::RequesterParams& requesterParams)
|
||||
: m_requestTopic(getTopic<REQUEST>(requesterParams.domainParticipant(), requesterParams.request_topic_name())),
|
||||
m_replyTopic(getTopic<REPLY>(requesterParams.domainParticipant(), requesterParams.reply_topic_name()))
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
dds::topic::Topic<REQUEST> m_requestTopic;
|
||||
dds::topic::Topic<REPLY> m_replyTopic;
|
||||
virtual ~ReplyRequestBase() = default;
|
||||
|
||||
protected:
|
||||
dds::topic::Topic<REQUEST> m_requestTopic;
|
||||
dds::topic::Topic<REPLY> m_replyTopic;
|
||||
};
|
||||
|
||||
template<typename REQUEST, typename REPLY>
|
||||
class Requester final : public ReplyRequestBase<REQUEST, REPLY>
|
||||
template <typename REQUEST, typename REPLY> class Requester final : public ReplyRequestBase<REQUEST, REPLY>
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit Requester(const connext::RequesterParams &requesterParams)
|
||||
: ReplyRequestBase<REQUEST, REPLY>(requesterParams)
|
||||
, m_requesterParams(requesterParams)
|
||||
@@ -284,144 +281,145 @@ public:
|
||||
, m_contentFilteredTopic(nullptr)
|
||||
, m_curInstanceHandle(dds::core::InstanceHandle::nil())
|
||||
.getNGLLogger("connext.requester"))
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void create_contentfilter(bool bNewDataWriter)
|
||||
{
|
||||
|
||||
if (!bNewDataWriter && m_contentFilteredTopic != nullptr)
|
||||
return;
|
||||
|
||||
rti::core::policy::DataWriterProtocol dwp;
|
||||
m_dataWriter.qos() >> dwp;
|
||||
const rti::core::Guid dwGuid = dwp.virtual_guid();
|
||||
const QByteArray writerGuid = DebugInfo::toReadable(dwGuid);
|
||||
const QByteArray filterContent = "@related_sample_identity.writer_guid.value = &hex(" + writerGuid + ")";
|
||||
if (m_contentFilteredTopic == nullptr)
|
||||
{
|
||||
|
||||
const std::string rtName = ReplyRequestBase<REQUEST, REPLY>::m_replyTopic.name();
|
||||
const QByteArray filterName(QByteArray::fromRawData(rtName.c_str(), static_cast<int>(rtName.size())) +
|
||||
QByteArray(" ") + writerGuid);
|
||||
m_contentFilteredTopic = dds::topic::ContentFilteredTopic<REPLY>(ReplyRequestBase<REQUEST, REPLY>::m_replyTopic,
|
||||
filterName.data(),
|
||||
dds::topic::Filter(filterContent.data()));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
m_contentFilteredTopic->filter(dds::topic::Filter(filterContent.data()));
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "content filter for topic "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< " - related_sample_identity should be: "
|
||||
<< writerGuid;
|
||||
|
||||
if (!bNewDataWriter && m_contentFilteredTopic != nullptr)
|
||||
return;
|
||||
|
||||
rti::core::policy::DataWriterProtocol dwp;
|
||||
m_dataWriter.qos() >> dwp;
|
||||
const rti::core::Guid dwGuid = dwp.virtual_guid();
|
||||
const QByteArray writerGuid = DebugInfo::toReadable(dwGuid);
|
||||
const QByteArray filterContent = "@related_sample_identity.writer_guid.value = &hex(" + writerGuid + ")";
|
||||
if (m_contentFilteredTopic == nullptr)
|
||||
{
|
||||
|
||||
const std::string rtName = ReplyRequestBase<REQUEST, REPLY>::m_replyTopic.name();
|
||||
const QByteArray filterName(QByteArray::fromRawData(rtName.c_str(), static_cast<int>(rtName.size())) +
|
||||
QByteArray(" ") + writerGuid);
|
||||
m_contentFilteredTopic =
|
||||
dds::topic::ContentFilteredTopic<REPLY>(ReplyRequestBase<REQUEST, REPLY>::m_replyTopic, filterName.data(),
|
||||
dds::topic::Filter(filterContent.data()));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
m_contentFilteredTopic->filter(dds::topic::Filter(filterContent.data()));
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "content filter for topic " << ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< " - related_sample_identity should be: " << writerGuid;
|
||||
}
|
||||
|
||||
void send_request(connext::WriteSample<REQUEST> &request)
|
||||
void send_request(connext::WriteSample<REQUEST>& request)
|
||||
{
|
||||
bool bNewDataWriter = false;
|
||||
if (m_dataWriter == nullptr)
|
||||
{
|
||||
m_dataWriter = dds::pub::DataWriter<REQUEST>(m_requesterParams.publisher(),
|
||||
ReplyRequestBase<REQUEST, REPLY>::m_requestTopic,
|
||||
m_requesterParams.datawriter_qos());
|
||||
bNewDataWriter = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
bool bNewDataWriter = false;
|
||||
if (m_dataWriter == nullptr)
|
||||
{
|
||||
m_dataWriter = dds::pub::DataWriter<REQUEST>(m_requesterParams.publisher(),
|
||||
ReplyRequestBase<REQUEST, REPLY>::m_requestTopic,
|
||||
m_requesterParams.datawriter_qos());
|
||||
bNewDataWriter = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
create_contentfilter(bNewDataWriter);
|
||||
|
||||
if (m_dataReader == nullptr)
|
||||
{
|
||||
|
||||
m_dataReader = dds::sub::DataReader<REPLY>(m_requesterParams.subscriber(),
|
||||
m_contentFilteredTopic,
|
||||
m_requesterParams.datareader_qos());
|
||||
}
|
||||
create_contentfilter(bNewDataWriter);
|
||||
|
||||
m_curInstanceHandle = m_dataWriter.register_instance(request.data());
|
||||
request.info().replace_automatic_values(true);
|
||||
request.info().identity(rti::core::SampleIdentity::automatic());
|
||||
m_dataWriter->write(request.data(), request.info());
|
||||
if (m_dataReader == nullptr)
|
||||
{
|
||||
|
||||
const rti::core::SampleIdentity currentSampleIdentity = request.info().identity();
|
||||
DEBUG_LOG(m_logger) << "send_request for topic "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", m_currentSampleIdentity: "
|
||||
<< DebugInfo::toReadable(currentSampleIdentity);
|
||||
m_dataReader = dds::sub::DataReader<REPLY>(m_requesterParams.subscriber(), m_contentFilteredTopic,
|
||||
m_requesterParams.datareader_qos());
|
||||
}
|
||||
|
||||
m_curInstanceHandle = m_dataWriter.register_instance(request.data());
|
||||
request.info().replace_automatic_values(true);
|
||||
request.info().identity(rti::core::SampleIdentity::automatic());
|
||||
m_dataWriter->write(request.data(), request.info());
|
||||
|
||||
const rti::core::SampleIdentity currentSampleIdentity = request.info().identity();
|
||||
DEBUG_LOG(m_logger) << "send_request for topic " << ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", m_currentSampleIdentity: " << DebugInfo::toReadable(currentSampleIdentity);
|
||||
}
|
||||
|
||||
bool receive_reply(connext::Sample<REPLY> &reply,
|
||||
const dds::core::Duration &duration)
|
||||
bool receive_reply(connext::Sample<REPLY>& reply, const dds::core::Duration& duration)
|
||||
{
|
||||
auto condition(dds::sub::cond::ReadCondition(m_dataReader, dds::sub::status::SampleState::not_read()));
|
||||
auto condition(dds::sub::cond::ReadCondition(m_dataReader, dds::sub::status::SampleState::not_read()));
|
||||
|
||||
dds::core::cond::WaitSet waitset;
|
||||
waitset.attach_condition(condition);
|
||||
dds::core::cond::WaitSet waitset;
|
||||
waitset.attach_condition(condition);
|
||||
|
||||
bool bRet = false;
|
||||
while (true)
|
||||
{
|
||||
|
||||
if (m_dataReader->take(reply.data(), reply.info()) && reply.info().valid())
|
||||
bool bRet = false;
|
||||
while (true)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "receive_reply for topic "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", SampleIdentity - original publication virtual: "
|
||||
<< DebugInfo::toReadable(reply.info()->original_publication_virtual_sample_identity());
|
||||
|
||||
DEBUG_LOG(m_logger) << "receive_reply for topic "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", SampleIdentity - related original: "
|
||||
<< DebugInfo::toReadable(reply.info()->related_original_publication_virtual_sample_identity());
|
||||
if (m_dataReader->take(reply.data(), reply.info()) && reply.info().valid())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "receive_reply for topic "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", SampleIdentity - original publication virtual: "
|
||||
<< DebugInfo::toReadable(
|
||||
reply.info()->original_publication_virtual_sample_identity());
|
||||
|
||||
|
||||
bRet = true;
|
||||
break;
|
||||
DEBUG_LOG(m_logger) << "receive_reply for topic "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", SampleIdentity - related original: "
|
||||
<< DebugInfo::toReadable(
|
||||
reply.info()->related_original_publication_virtual_sample_identity());
|
||||
|
||||
bRet = true;
|
||||
break;
|
||||
}
|
||||
|
||||
dds::core::cond::WaitSet::ConditionSeq activeConditionsSeq = waitset.wait(duration);
|
||||
if (activeConditionsSeq.empty())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Bailing out!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dds::core::cond::WaitSet::ConditionSeq activeConditionsSeq = waitset.wait(duration);
|
||||
if (activeConditionsSeq.empty())
|
||||
static const rti::core::SampleFlag irs(rti::core::SampleFlag::intermediate_reply_sequence());
|
||||
if ((reply.info()->flag() & irs) == 0)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Bailing out!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const rti::core::SampleFlag irs(rti::core::SampleFlag::intermediate_reply_sequence());
|
||||
if ((reply.info()->flag() & irs) == 0)
|
||||
{
|
||||
if (!m_curInstanceHandle.is_nil())
|
||||
{
|
||||
|
||||
DEBUG_LOG(m_logger) << "Keyed topic - disposing instance: "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name();
|
||||
m_dataWriter.dispose_instance(m_curInstanceHandle);
|
||||
}
|
||||
}
|
||||
if (!m_curInstanceHandle.is_nil())
|
||||
{
|
||||
|
||||
return bRet;
|
||||
DEBUG_LOG(m_logger) << "Keyed topic - disposing instance: "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name();
|
||||
m_dataWriter.dispose_instance(m_curInstanceHandle);
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
dds::pub::DataWriter<REQUEST> get_request_datawriter() const { return m_dataWriter; }
|
||||
dds::sub::DataReader<REPLY> get_request_datareader() const { return m_dataReader; }
|
||||
dds::pub::DataWriter<REQUEST> get_request_datawriter() const
|
||||
{
|
||||
return m_dataWriter;
|
||||
}
|
||||
|
||||
dds::sub::DataReader<REPLY> get_request_datareader() const
|
||||
{
|
||||
return m_dataReader;
|
||||
}
|
||||
|
||||
private:
|
||||
connext::RequesterParams m_requesterParams;
|
||||
connext::RequesterParams m_requesterParams;
|
||||
dds::pub::DataWriter<REQUEST> m_dataWriter;
|
||||
dds::sub::DataReader<REPLY> m_dataReader;
|
||||
dds::sub::DataReader<REPLY> m_dataReader;
|
||||
dds::topic::ContentFilteredTopic<REPLY> m_contentFilteredTopic;
|
||||
dds::core::InstanceHandle m_curInstanceHandle;
|
||||
dds::core::InstanceHandle m_curInstanceHandle;
|
||||
};
|
||||
|
||||
template<typename REQUEST, typename REPLY>
|
||||
class Replier final : public ReplyRequestBase<REQUEST, REPLY>
|
||||
template <typename REQUEST, typename REPLY> class Replier final : public ReplyRequestBase<REQUEST, REPLY>
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit Replier(const connext::ReplierParams<REQUEST, REPLY> &replierParams)
|
||||
: ReplyRequestBase<REQUEST, REPLY>(replierParams)
|
||||
, m_replierParams(replierParams)
|
||||
@@ -432,69 +430,74 @@ public:
|
||||
ReplyRequestBase<REQUEST, REPLY>::m_requestTopic,
|
||||
replierParams.datareader_qos()))
|
||||
.getNGLLogger("connext.replier"))
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void send_reply(connext::WriteSample<REPLY> &reply,
|
||||
const rti::core::SampleIdentity &identity,
|
||||
void send_reply(connext::WriteSample<REPLY>& reply, const rti::core::SampleIdentity& identity,
|
||||
bool bLastSample = true)
|
||||
{
|
||||
connext::WriteSampleRef<REPLY> replyRef;
|
||||
replyRef.set_data(&reply.data());
|
||||
replyRef.set_info(&reply.info());
|
||||
return send_reply(replyRef, identity, bLastSample);
|
||||
connext::WriteSampleRef<REPLY> replyRef;
|
||||
replyRef.set_data(&reply.data());
|
||||
replyRef.set_info(&reply.info());
|
||||
return send_reply(replyRef, identity, bLastSample);
|
||||
}
|
||||
|
||||
void send_reply(connext::WriteSampleRef<REPLY> &reply,
|
||||
const rti::core::SampleIdentity &identity,
|
||||
void send_reply(connext::WriteSampleRef<REPLY>& reply, const rti::core::SampleIdentity& identity,
|
||||
bool bLastSample = true)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "send_reply for topic "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", sampleIdentity: " << DebugInfo::toReadable(identity);
|
||||
DEBUG_LOG(m_logger) << "send_reply for topic " << ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", sampleIdentity: " << DebugInfo::toReadable(identity);
|
||||
|
||||
rti::core::SampleFlag sf = reply.info().flag();
|
||||
if (bLastSample)
|
||||
sf &= ~rti::core::SampleFlag::intermediate_reply_sequence();
|
||||
else
|
||||
sf |= rti::core::SampleFlag::intermediate_reply_sequence();
|
||||
reply.info().flag(sf);
|
||||
reply.info().related_sample_identity(identity);
|
||||
DEBUG_LOG(m_logger) << "send_reply for topic "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", related sampleIdentity: " << DebugInfo::toReadable(reply.info().related_sample_identity());
|
||||
rti::core::SampleFlag sf = reply.info().flag();
|
||||
if (bLastSample)
|
||||
sf &= ~rti::core::SampleFlag::intermediate_reply_sequence();
|
||||
else
|
||||
sf |= rti::core::SampleFlag::intermediate_reply_sequence();
|
||||
reply.info().flag(sf);
|
||||
reply.info().related_sample_identity(identity);
|
||||
DEBUG_LOG(m_logger) << "send_reply for topic " << ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", related sampleIdentity: "
|
||||
<< DebugInfo::toReadable(reply.info().related_sample_identity());
|
||||
|
||||
m_dataWriter->write(reply.data(), reply.info());
|
||||
m_dataWriter->write(reply.data(), reply.info());
|
||||
}
|
||||
|
||||
bool receive_request(connext::Sample<REQUEST> &request)
|
||||
bool receive_request(connext::Sample<REQUEST>& request)
|
||||
{
|
||||
if (!m_dataReader->take(request.data(), request.info()))
|
||||
return false;
|
||||
if (!m_dataReader->take(request.data(), request.info()))
|
||||
return false;
|
||||
|
||||
if (request.info().valid())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "receive_request for topic "
|
||||
<< ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", sampleIdentity publication_virtual_sample_identity: "
|
||||
<< DebugInfo::toReadable(request.info()->publication_virtual_sample_identity())
|
||||
<< ", original_publication_virtual_sample_identity: "
|
||||
<< DebugInfo::toReadable(request.info()->original_publication_virtual_sample_identity())
|
||||
<< ", related_original_publication_virtual_sample_identity: "
|
||||
<< DebugInfo::toReadable(request.info()->related_original_publication_virtual_sample_identity())
|
||||
<< " with timestamp_ " << request.info().source_timestamp().to_millisecs();
|
||||
request.set_identity(request.info()->original_publication_virtual_sample_identity());
|
||||
}
|
||||
if (request.info().valid())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "receive_request for topic " << ReplyRequestBase<REQUEST, REPLY>::m_requestTopic.name()
|
||||
<< ", sampleIdentity publication_virtual_sample_identity: "
|
||||
<< DebugInfo::toReadable(request.info()->publication_virtual_sample_identity())
|
||||
<< ", original_publication_virtual_sample_identity: "
|
||||
<< DebugInfo::toReadable(request.info()->original_publication_virtual_sample_identity())
|
||||
<< ", related_original_publication_virtual_sample_identity: "
|
||||
<< DebugInfo::toReadable(
|
||||
request.info()->related_original_publication_virtual_sample_identity())
|
||||
<< " with timestamp_ " << request.info().source_timestamp().to_millisecs();
|
||||
request.set_identity(request.info()->original_publication_virtual_sample_identity());
|
||||
}
|
||||
|
||||
return request.info().valid();
|
||||
return request.info().valid();
|
||||
}
|
||||
|
||||
dds::pub::DataWriter<REPLY> get_request_datawriter() const { return m_dataWriter; }
|
||||
dds::sub::DataReader<REQUEST> get_request_datareader() const { return m_dataReader; }
|
||||
dds::pub::DataWriter<REPLY> get_request_datawriter() const
|
||||
{
|
||||
return m_dataWriter;
|
||||
}
|
||||
|
||||
dds::sub::DataReader<REQUEST> get_request_datareader() const
|
||||
{
|
||||
return m_dataReader;
|
||||
}
|
||||
|
||||
private:
|
||||
connext::ReplierParams<REQUEST, REPLY> m_replierParams;
|
||||
dds::pub::DataWriter<REPLY> m_dataWriter;
|
||||
dds::sub::DataReader<REQUEST> m_dataReader;
|
||||
dds::pub::DataWriter<REPLY> m_dataWriter;
|
||||
dds::sub::DataReader<REQUEST> m_dataReader;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace connext
|
||||
Executable → Regular
+209
-237
@@ -2,18 +2,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <DDS/Core/core.hpp>
|
||||
|
||||
#include "generic_fts_internal.h"
|
||||
#include "connext.h"
|
||||
#include <DDS/Generic/wait_set_handler.h>
|
||||
#include "generic_fts_internal.h"
|
||||
|
||||
#include <DDS/Core/core.hpp>
|
||||
#include <DDS/Generic/generic_base.h>
|
||||
#include <DDS/Generic/generic_logger.h>
|
||||
|
||||
#include <DDS/Generic/wait_set_handler.h>
|
||||
#include <queue>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
#include <typeinfo>
|
||||
#include <sstream>
|
||||
|
||||
#ifndef tr_lts
|
||||
#define tr_lts(ctx, t) (t)
|
||||
@@ -21,265 +20,238 @@
|
||||
|
||||
namespace FTS
|
||||
{
|
||||
template <class C>
|
||||
class HasStatusFunction
|
||||
template <class C> class HasStatusFunction
|
||||
{
|
||||
template <class T>
|
||||
static std::true_type testSignature(void (T::*)(const Core::FtReplyState&));
|
||||
template <class T> static std::true_type testSignature(void (T::*)(const Core::FtReplyState&));
|
||||
|
||||
template <class T>
|
||||
static decltype(testSignature(&T::replyState)) test(std::nullptr_t);
|
||||
template <class T> static decltype(testSignature(&T::replyState)) test(std::nullptr_t);
|
||||
|
||||
template <class T>
|
||||
static std::false_type test(...);
|
||||
template <class T> static std::false_type test(...);
|
||||
|
||||
public:
|
||||
using type = decltype(test<C>(nullptr));
|
||||
static const bool value = type::value;
|
||||
public:
|
||||
using type = decltype(test<C>(nullptr));
|
||||
static const bool value = type::value;
|
||||
};
|
||||
|
||||
template<typename GENERIC_FTS>
|
||||
struct TopicNames;
|
||||
template <typename GENERIC_FTS> struct TopicNames;
|
||||
|
||||
template<typename TOPICTYPE_REQUEST, typename TOPICTYPE_REPLY, typename DUMMY>
|
||||
class GenericFtsImpl final : public GenericFts<TOPICTYPE_REQUEST,TOPICTYPE_REPLY>
|
||||
, public GenericFtsInternal
|
||||
template <typename TOPICTYPE_REQUEST, typename TOPICTYPE_REPLY, typename DUMMY>
|
||||
class GenericFtsImpl final : public GenericFts<TOPICTYPE_REQUEST, TOPICTYPE_REPLY>, public GenericFtsInternal
|
||||
{
|
||||
public:
|
||||
using RequestTopic = TOPICTYPE_REQUEST;
|
||||
using ReplyTopic = TOPICTYPE_REPLY;
|
||||
using TopicNameHelper = TopicNames<GenericFtsImpl<RequestTopic, ReplyTopic, DUMMY>>;
|
||||
private:
|
||||
using SubscriberCallback = std::function<void(const rti::core::SampleIdentity&, const RequestTopic&)>;
|
||||
public:
|
||||
using RequestTopic = TOPICTYPE_REQUEST;
|
||||
using ReplyTopic = TOPICTYPE_REPLY;
|
||||
using TopicNameHelper = TopicNames<GenericFtsImpl<RequestTopic, ReplyTopic, DUMMY>>;
|
||||
|
||||
template <typename T = ReplyTopic, typename std::enable_if<HasStatusFunction<T>::value, int>::type = 0>
|
||||
void sendReplyState(Core::FtReplyState replyState, const rti::core::SampleIdentity &requestSampleIdentity)
|
||||
{
|
||||
connext::WriteSample<ReplyTopic> reply;
|
||||
reply.data().replyState(replyState);
|
||||
private:
|
||||
using SubscriberCallback = std::function<void(const rti::core::SampleIdentity&, const RequestTopic&)>;
|
||||
|
||||
bool bLastTelegram = ((replyState != Core::FtReplyState_def::InProgress) &&
|
||||
(replyState != Core::FtReplyState_def::NotStarted));
|
||||
m_replier->send_reply(reply, requestSampleIdentity, bLastTelegram);
|
||||
}
|
||||
|
||||
template <typename T = ReplyTopic, typename std::enable_if<!HasStatusFunction<T>::value, int>::type = 0>
|
||||
void sendReplyState(Core::FtReplyState, const rti::core::SampleIdentity &)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template <typename T, typename std::enable_if<HasStatusFunction<T>::value, int>::type = 0>
|
||||
void setReply(T &data, Core::FtReplyState status)
|
||||
{
|
||||
data.replyState(status);
|
||||
}
|
||||
|
||||
template <typename T, typename std::enable_if<!HasStatusFunction<T>::value, int>::type = 0>
|
||||
void setReply(T &, Core::FtReplyState)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
GenericFtsImpl(const dds::domain::DomainParticipant &domainParticipant,
|
||||
const dds::pub::Publisher &ddsPublisher,
|
||||
const dds::sub::Subscriber &ddsSubscriber,
|
||||
DDSGeneric::WaitSetHandler *wsHandler)
|
||||
: GenericFts<RequestTopic,ReplyTopic>()
|
||||
, GenericFtsInternal()
|
||||
, m_wsHandler(wsHandler)
|
||||
, m_subscriberCallback(nullptr)
|
||||
, m_logger(DDS::getLogger(TopicNameHelper::functionTopicName(), DDS::DataType::FUNCTION_TOPIC_SERVER))
|
||||
{
|
||||
Q_ASSERT(domainParticipant != nullptr);
|
||||
Q_ASSERT(ddsPublisher != nullptr);
|
||||
Q_ASSERT(ddsSubscriber != nullptr);
|
||||
Q_ASSERT(wsHandler != nullptr);
|
||||
|
||||
qRegisterMetaType<RequestTopic> (TopicNameHelper::requestTopicTypeName());
|
||||
|
||||
connext::ReplierParams<RequestTopic,ReplyTopic> replierParams(domainParticipant);
|
||||
|
||||
|
||||
|
||||
|
||||
replierParams.request_topic_name(TopicNameHelper::requestTopicName());
|
||||
replierParams.reply_topic_name(TopicNameHelper::replyTopicName());
|
||||
replierParams.publisher(ddsPublisher);
|
||||
replierParams.subscriber(ddsSubscriber);
|
||||
replierParams.datareader_qos(readerQos(m_logger));
|
||||
replierParams.datawriter_qos(writerQos(m_logger));
|
||||
|
||||
|
||||
|
||||
|
||||
m_replier = new connext::Replier<RequestTopic, ReplyTopic>(replierParams);
|
||||
m_readCondition = new dds::sub::cond::ReadCondition(m_replier->get_request_datareader(), dds::sub::status::SampleState::not_read());
|
||||
|
||||
m_wsHandler->attachWaitSet(*m_readCondition, this);
|
||||
}
|
||||
|
||||
~GenericFtsImpl()
|
||||
{
|
||||
m_wsHandler->detachWaitSet(*m_readCondition, this);
|
||||
delete m_readCondition;
|
||||
delete m_replier;
|
||||
}
|
||||
|
||||
bool setSubscriberCallback(const SubscriberCallback &subscriberCallback)
|
||||
{
|
||||
if (m_subscriberCallback)
|
||||
template <typename T = ReplyTopic, typename std::enable_if<HasStatusFunction<T>::value, int>::type = 0>
|
||||
void sendReplyState(Core::FtReplyState replyState, const rti::core::SampleIdentity& requestSampleIdentity)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Can not set subscriber callback - already set ...";
|
||||
return false;
|
||||
connext::WriteSample<ReplyTopic> reply;
|
||||
reply.data().replyState(replyState);
|
||||
|
||||
bool bLastTelegram =
|
||||
((replyState != Core::FtReplyState_def::InProgress) && (replyState != Core::FtReplyState_def::NotStarted));
|
||||
m_replier->send_reply(reply, requestSampleIdentity, bLastTelegram);
|
||||
}
|
||||
|
||||
m_subscriberCallback = subscriberCallback;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool sendReply(const rti::core::SampleIdentity &requestSampleIdentity, const ReplyTopic &replyData) override final
|
||||
{
|
||||
connext::WriteSampleRef<ReplyTopic> reply;
|
||||
rti::pub::WriteParams replyParams;
|
||||
|
||||
reply.set_data(const_cast<ReplyTopic*>(&replyData));
|
||||
reply.set_info(&replyParams);
|
||||
|
||||
m_replier->send_reply(reply, requestSampleIdentity);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool sendReply(const rti::core::SampleIdentity &requestIdentity, const QVector<ReplyTopic> &replyData) override final
|
||||
{
|
||||
DEBUG_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - IN sendReply";
|
||||
|
||||
for(int i = 0; i < replyData.size(); ++i)
|
||||
template <typename T = ReplyTopic, typename std::enable_if<!HasStatusFunction<T>::value, int>::type = 0>
|
||||
void sendReplyState(Core::FtReplyState, const rti::core::SampleIdentity&)
|
||||
{
|
||||
if (HasStatusFunction<ReplyTopic>::value)
|
||||
{
|
||||
ReplyTopic rt = replyData.at(i);
|
||||
setReply(rt, i == replyData.size() - 1 ? Core::FtReplyState::Completed : Core::FtReplyState::InProgress);
|
||||
if (!sendReply(requestIdentity, rt))
|
||||
return false;
|
||||
} else {
|
||||
if (!sendReply(requestIdentity, replyData.at(i)))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void processRequest(const connext::Sample<RequestTopic> &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - processRequest: "
|
||||
<< connext::DebugInfo::toReadable(request.identity());
|
||||
|
||||
qint64 age = qAbs(qint64(request.info().source_timestamp().to_secs()) - time(nullptr));
|
||||
|
||||
if (age > 10)
|
||||
template <typename T, typename std::enable_if<HasStatusFunction<T>::value, int>::type = 0>
|
||||
void setReply(T& data, Core::FtReplyState status)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << request.data();
|
||||
std::string s = ss.str();
|
||||
int slen = s.length();
|
||||
|
||||
static int max_slen = 1024;
|
||||
if (slen > max_slen)
|
||||
{
|
||||
s.resize(max_slen);
|
||||
s.append("...");
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "received a request for topic "
|
||||
<< TopicNameHelper::requestTopicName()
|
||||
<< " but it was outdated - ignoring. "
|
||||
<< " local time: " << (time(nullptr) - 10) << "[s], source timestamp: "
|
||||
<< qint64(request.info().source_timestamp().to_secs())
|
||||
<< "[s], -> age: " << age
|
||||
<< "[s], data: " << s;
|
||||
ReplyTopic rt;
|
||||
rt.errorString(tr_lts("dds", "Topic %1 was outdated and therefore ignored. Does the client time match the server time?"));
|
||||
rt.errorParams({TopicNameHelper::requestTopicName()});
|
||||
sendReply(request.identity(), rt);
|
||||
return;
|
||||
data.replyState(status);
|
||||
}
|
||||
|
||||
sendReplyState(Core::FtReplyState::InProgress, request.identity());
|
||||
|
||||
m_subscriberCallback(request.identity(), request.data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void processRequests() override
|
||||
{
|
||||
DEBUG_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - processRequests";
|
||||
|
||||
while (true)
|
||||
template <typename T, typename std::enable_if<!HasStatusFunction<T>::value, int>::type = 0>
|
||||
void setReply(T&, Core::FtReplyState)
|
||||
{
|
||||
connext::Sample<RequestTopic> request;
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_requestMutex);
|
||||
if (m_requests.empty())
|
||||
}
|
||||
|
||||
public:
|
||||
GenericFtsImpl(const dds::domain::DomainParticipant& domainParticipant, const dds::pub::Publisher& ddsPublisher,
|
||||
const dds::sub::Subscriber& ddsSubscriber, DDSGeneric::WaitSetHandler* wsHandler)
|
||||
: GenericFts<RequestTopic, ReplyTopic>(), GenericFtsInternal(), m_wsHandler(wsHandler),
|
||||
m_subscriberCallback(nullptr),
|
||||
m_logger(DDS::getLogger(TopicNameHelper::functionTopicName(), DDS::DataType::FUNCTION_TOPIC_SERVER))
|
||||
{
|
||||
Q_ASSERT(domainParticipant != nullptr);
|
||||
Q_ASSERT(ddsPublisher != nullptr);
|
||||
Q_ASSERT(ddsSubscriber != nullptr);
|
||||
Q_ASSERT(wsHandler != nullptr);
|
||||
|
||||
qRegisterMetaType<RequestTopic>(TopicNameHelper::requestTopicTypeName());
|
||||
|
||||
connext::ReplierParams<RequestTopic, ReplyTopic> replierParams(domainParticipant);
|
||||
|
||||
replierParams.request_topic_name(TopicNameHelper::requestTopicName());
|
||||
replierParams.reply_topic_name(TopicNameHelper::replyTopicName());
|
||||
replierParams.publisher(ddsPublisher);
|
||||
replierParams.subscriber(ddsSubscriber);
|
||||
replierParams.datareader_qos(readerQos(m_logger));
|
||||
replierParams.datawriter_qos(writerQos(m_logger));
|
||||
|
||||
m_replier = new connext::Replier<RequestTopic, ReplyTopic>(replierParams);
|
||||
m_readCondition = new dds::sub::cond::ReadCondition(m_replier->get_request_datareader(),
|
||||
dds::sub::status::SampleState::not_read());
|
||||
|
||||
m_wsHandler->attachWaitSet(*m_readCondition, this);
|
||||
}
|
||||
|
||||
~GenericFtsImpl()
|
||||
{
|
||||
m_wsHandler->detachWaitSet(*m_readCondition, this);
|
||||
delete m_readCondition;
|
||||
delete m_replier;
|
||||
}
|
||||
|
||||
bool setSubscriberCallback(const SubscriberCallback& subscriberCallback)
|
||||
{
|
||||
if (m_subscriberCallback)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "No more requests";
|
||||
return;
|
||||
WARNING_LOG(m_logger) << "Can not set subscriber callback - already set ...";
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - read one request for ";
|
||||
request = m_requests.front();
|
||||
m_requests.pop();
|
||||
}
|
||||
if (!request.info().valid())
|
||||
{
|
||||
WARNING_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - No valid data";
|
||||
continue;
|
||||
}
|
||||
processRequest(request);
|
||||
}
|
||||
DEBUG_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - processRequests finished";
|
||||
}
|
||||
|
||||
bool enqueueRequests() override
|
||||
{
|
||||
bool bValidDataRead = false;
|
||||
connext::Sample<RequestTopic> request;
|
||||
while (m_replier->receive_request(request))
|
||||
m_subscriberCallback = subscriberCallback;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sendReply(const rti::core::SampleIdentity& requestSampleIdentity, const ReplyTopic& replyData) override final
|
||||
{
|
||||
if (!request.info().valid())
|
||||
continue;
|
||||
bValidDataRead = true;
|
||||
std::lock_guard<std::mutex> l(m_requestMutex);
|
||||
m_requests.push(request);
|
||||
connext::WriteSampleRef<ReplyTopic> reply;
|
||||
rti::pub::WriteParams replyParams;
|
||||
|
||||
reply.set_data(const_cast<ReplyTopic*>(&replyData));
|
||||
reply.set_info(&replyParams);
|
||||
|
||||
m_replier->send_reply(reply, requestSampleIdentity);
|
||||
return true;
|
||||
}
|
||||
return bValidDataRead;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
connext::Replier<RequestTopic, ReplyTopic> *m_replier;
|
||||
dds::sub::cond::ReadCondition *m_readCondition;
|
||||
bool sendReply(const rti::core::SampleIdentity& requestIdentity,
|
||||
const QVector<ReplyTopic>& replyData) override final
|
||||
{
|
||||
DEBUG_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - IN sendReply";
|
||||
|
||||
|
||||
DDSGeneric::WaitSetHandler *m_wsHandler;
|
||||
for (int i = 0; i < replyData.size(); ++i)
|
||||
{
|
||||
if (HasStatusFunction<ReplyTopic>::value)
|
||||
{
|
||||
ReplyTopic rt = replyData.at(i);
|
||||
setReply(rt,
|
||||
i == replyData.size() - 1 ? Core::FtReplyState::Completed : Core::FtReplyState::InProgress);
|
||||
if (!sendReply(requestIdentity, rt))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!sendReply(requestIdentity, replyData.at(i)))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::queue<connext::Sample<RequestTopic>> m_requests;
|
||||
std::mutex m_requestMutex;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
SubscriberCallback m_subscriberCallback;
|
||||
protected:
|
||||
void processRequest(const connext::Sample<RequestTopic>& request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << TopicNameHelper::requestTopicName()
|
||||
<< " - processRequest: " << connext::DebugInfo::toReadable(request.identity());
|
||||
|
||||
qint64 age = qAbs(qint64(request.info().source_timestamp().to_secs()) - time(nullptr));
|
||||
|
||||
if (age > 10)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << request.data();
|
||||
std::string s = ss.str();
|
||||
int slen = s.length();
|
||||
|
||||
static int max_slen = 1024;
|
||||
if (slen > max_slen)
|
||||
{
|
||||
s.resize(max_slen);
|
||||
s.append("...");
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "received a request for topic " << TopicNameHelper::requestTopicName()
|
||||
<< " but it was outdated - ignoring. "
|
||||
<< " local time: " << (time(nullptr) - 10)
|
||||
<< "[s], source timestamp: " << qint64(request.info().source_timestamp().to_secs())
|
||||
<< "[s], -> age: " << age << "[s], data: " << s;
|
||||
ReplyTopic rt;
|
||||
rt.errorString(tr_lts(
|
||||
"dds", "Topic %1 was outdated and therefore ignored. Does the client time match the server time?"));
|
||||
rt.errorParams({TopicNameHelper::requestTopicName()});
|
||||
sendReply(request.identity(), rt);
|
||||
return;
|
||||
}
|
||||
|
||||
sendReplyState(Core::FtReplyState::InProgress, request.identity());
|
||||
|
||||
m_subscriberCallback(request.identity(), request.data());
|
||||
}
|
||||
|
||||
void processRequests() override
|
||||
{
|
||||
DEBUG_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - processRequests";
|
||||
|
||||
while (true)
|
||||
{
|
||||
connext::Sample<RequestTopic> request;
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_requestMutex);
|
||||
if (m_requests.empty())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "No more requests";
|
||||
return;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - read one request for ";
|
||||
request = m_requests.front();
|
||||
m_requests.pop();
|
||||
}
|
||||
if (!request.info().valid())
|
||||
{
|
||||
WARNING_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - No valid data";
|
||||
continue;
|
||||
}
|
||||
processRequest(request);
|
||||
}
|
||||
DEBUG_LOG(m_logger) << TopicNameHelper::requestTopicName() << " - processRequests finished";
|
||||
}
|
||||
|
||||
bool enqueueRequests() override
|
||||
{
|
||||
bool bValidDataRead = false;
|
||||
connext::Sample<RequestTopic> request;
|
||||
while (m_replier->receive_request(request))
|
||||
{
|
||||
if (!request.info().valid())
|
||||
continue;
|
||||
bValidDataRead = true;
|
||||
std::lock_guard<std::mutex> l(m_requestMutex);
|
||||
m_requests.push(request);
|
||||
}
|
||||
return bValidDataRead;
|
||||
}
|
||||
|
||||
private:
|
||||
connext::Replier<RequestTopic, ReplyTopic>* m_replier;
|
||||
dds::sub::cond::ReadCondition* m_readCondition;
|
||||
|
||||
DDSGeneric::WaitSetHandler* m_wsHandler;
|
||||
|
||||
std::queue<connext::Sample<RequestTopic>> m_requests;
|
||||
std::mutex m_requestMutex;
|
||||
|
||||
SubscriberCallback m_subscriberCallback;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace FTS
|
||||
Executable → Regular
+281
-298
@@ -1,353 +1,336 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <DDS/Generic/generic_base.h>
|
||||
#include <DDS/Generic/generic_logger.h>
|
||||
#include <LtsUtilsCore/data_modification_enum.h>
|
||||
#include <dds/core/xtypes/StructType.hpp>
|
||||
#include <dds/sub/DataReader.hpp>
|
||||
#include <dds/sub/LoanedSamples.hpp>
|
||||
#include <dds/sub/SampleInfo.hpp>
|
||||
#include <dds/topic/find.hpp>
|
||||
|
||||
#include <DDS/Generic/generic_base.h>
|
||||
#include <DDS/Generic/generic_logger.h>
|
||||
#include <LtsUtilsCore/data_modification_enum.h>
|
||||
#include <functional>
|
||||
|
||||
namespace DDSGeneric
|
||||
{
|
||||
using StructType = dds::core::xtypes::StructType;
|
||||
using StructType = dds::core::xtypes::StructType;
|
||||
using DynamicData = dds::core::xtypes::DynamicData;
|
||||
|
||||
class DynamicDataReader final
|
||||
{
|
||||
public:
|
||||
public:
|
||||
using TopicType = DynamicData;
|
||||
using DataReader = dds::sub::DataReader<DynamicData>;
|
||||
using DataTopic = dds::topic::Topic<TopicType>;
|
||||
|
||||
using TopicType = DynamicData;
|
||||
using DataReader = dds::sub::DataReader<DynamicData>;
|
||||
using DataTopic = dds::topic::Topic<TopicType>;
|
||||
using SubscriberCallback = std::function<void(const DynamicData&, const std::string&, DataModification)>;
|
||||
using SubscriberCallbackWithSampleInfo =
|
||||
std::function<void(const DynamicData&, const std::string&, const dds::sub::SampleInfo&)>;
|
||||
|
||||
using SubscriberCallback = std::function<void(const DynamicData &, const std::string &, DataModification)>;
|
||||
using SubscriberCallbackWithSampleInfo = std::function<void(const DynamicData &, const std::string &, const dds::sub::SampleInfo &)>;
|
||||
|
||||
DynamicDataReader()
|
||||
: m_dataReader(nullptr)
|
||||
, m_structType(nullptr)
|
||||
, m_ddsTopic(nullptr)
|
||||
, m_bHaveSubscriberCallback(false)
|
||||
, m_logger(DDS::getLogger("DynamicDataReader", DDS::DataType::DYNAMIC_DATA_READER))
|
||||
{}
|
||||
|
||||
~DynamicDataReader()
|
||||
{
|
||||
m_ddsTopic = nullptr;
|
||||
m_dataReader = nullptr;
|
||||
delete m_structType;
|
||||
}
|
||||
|
||||
const DataReader &getDataReader() const { return m_dataReader; }
|
||||
const StructType &getStructType() const { return *m_structType; }
|
||||
|
||||
bool create(const dds::domain::DomainParticipant &domainParticipant,
|
||||
const dds::sub::Subscriber &ddsSubscriber,
|
||||
const std::string &specialTopicName,
|
||||
const StructType &structType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN DynamicDataReader::create ("
|
||||
<< m_structType->name()
|
||||
<< ")";
|
||||
|
||||
if (domainParticipant == nullptr)
|
||||
DynamicDataReader()
|
||||
: m_dataReader(nullptr), m_structType(nullptr), m_ddsTopic(nullptr), m_bHaveSubscriberCallback(false),
|
||||
m_logger(DDS::getLogger("DynamicDataReader", DDS::DataType::DYNAMIC_DATA_READER))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "DomainParticipant does not exist ";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_ddsTopic != nullptr)
|
||||
~DynamicDataReader()
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Type '"
|
||||
<< m_structType->name()
|
||||
<< "' already created";
|
||||
return false;
|
||||
m_ddsTopic = nullptr;
|
||||
m_dataReader = nullptr;
|
||||
delete m_structType;
|
||||
}
|
||||
|
||||
if (structType.has_parent())
|
||||
m_structType = new dds::core::xtypes::StructType(structType.name(), structType.parent(), structType.members());
|
||||
else
|
||||
m_structType = new dds::core::xtypes::StructType(structType.name(), structType.members());
|
||||
|
||||
try
|
||||
const DataReader& getDataReader() const
|
||||
{
|
||||
|
||||
|
||||
const std::string topicName = specialTopicName.empty() ?
|
||||
DDS::Helper::getShortTopicName(m_structType->name()) :
|
||||
specialTopicName;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Creating topic " << topicName << " with type: "
|
||||
<< m_structType->name();
|
||||
|
||||
m_ddsTopic = dds::topic::find<dds::topic::Topic<DynamicData>>(domainParticipant, topicName);
|
||||
if (m_ddsTopic == nullptr)
|
||||
{
|
||||
rti::core::xtypes::DynamicDataTypeSerializationProperty serialization_property;
|
||||
serialization_property.min_size_serialized(0);
|
||||
dds::domain::DomainParticipant dp = domainParticipant;
|
||||
rti::domain::register_type(dp, structType.name(), structType, serialization_property);
|
||||
m_ddsTopic = dds::topic::Topic<DynamicData>(domainParticipant, topicName, structType);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "m_ddsTopic created: " << m_ddsTopic.name();
|
||||
|
||||
if (m_logger.isDebugEnabled())
|
||||
{
|
||||
dds::sub::qos::SubscriberQos subscriberQoS = ddsSubscriber.qos();
|
||||
dds::core::policy::Partition partition = subscriberQoS.policy<dds::core::policy::Partition>();
|
||||
dds::core::StringSeq parititionNames = partition.name();
|
||||
DEBUG_LOG(m_logger) << "Subscribing partitions: " << parititionNames.size();
|
||||
for (const std::string &name : parititionNames)
|
||||
DEBUG_LOG(m_logger) << "SubscriberQoS: partition name = " << name;
|
||||
}
|
||||
|
||||
dds::sub::qos::DataReaderQos dataReaderQos = ddsSubscriber.default_datareader_qos();
|
||||
|
||||
QString typeName = QString::fromStdString(m_structType->name());
|
||||
if (typeName.endsWith(QLatin1String("Request")) || typeName.endsWith(QLatin1String("Reply")))
|
||||
{
|
||||
|
||||
dds::core::policy::Durability readerDurability;
|
||||
dataReaderQos >> readerDurability;
|
||||
readerDurability.kind(dds::core::policy::DurabilityKind_def::VOLATILE);
|
||||
dataReaderQos << readerDurability;
|
||||
}
|
||||
|
||||
m_dataReader = DataReader(ddsSubscriber,
|
||||
m_ddsTopic,
|
||||
dataReaderQos,
|
||||
nullptr ,
|
||||
dds::core::status::StatusMask::all());
|
||||
|
||||
if (m_dataReader == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Creating dataReader for '" << topicName << "' with type: '"
|
||||
<< m_structType->name()
|
||||
<< "' failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
catch (const dds::core::Exception &ex)
|
||||
{
|
||||
ERROR_LOG(m_logger) << ex.what();
|
||||
return false;
|
||||
return m_dataReader;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "dataReader created ("
|
||||
<< m_structType->name()
|
||||
<< ")";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool hasSamples() const
|
||||
{
|
||||
qint64 sampleSize = m_dataReader->datareader_cache_status().sample_count();
|
||||
DEBUG_LOG(m_logger) << "sampleSize = " << sampleSize;
|
||||
return sampleSize > 0;
|
||||
}
|
||||
|
||||
|
||||
dds::sub::LoanedSamples<DynamicData> readAlive(bool &bSeenNewSamples)
|
||||
{
|
||||
dds::sub::LoanedSamples<DynamicData> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::alive()).read();
|
||||
TRACE_LOG(m_logger) << "readAlive for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length()
|
||||
<< ", this: " << this << ", instance handle " << m_dataReader.instance_handle();
|
||||
|
||||
bSeenNewSamples = checkNewSamples(samples);
|
||||
return samples;
|
||||
}
|
||||
|
||||
|
||||
dds::sub::LoanedSamples<DynamicData> takeAlive(bool &bSeenNewSamples)
|
||||
{
|
||||
dds::sub::LoanedSamples<DynamicData> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::alive()).take();
|
||||
TRACE_LOG(m_logger) << "takeAlive for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length()
|
||||
<< ", this: " << this << ", instance handle " << m_dataReader.instance_handle();
|
||||
|
||||
bSeenNewSamples = checkNewSamples(samples);
|
||||
return samples;
|
||||
}
|
||||
|
||||
dds::sub::LoanedSamples<DynamicData> takeDisposed()
|
||||
{
|
||||
dds::sub::LoanedSamples<DynamicData> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::not_alive_disposed()).take();
|
||||
TRACE_LOG(m_logger) << "takeDisposed for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length()
|
||||
<< ", this: " << this << ", instance handle " << m_dataReader.instance_handle();
|
||||
return samples;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
bool read(C callbackFunc)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN read ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< "), this: " << this << ", instance handle " << m_dataReader.instance_handle();
|
||||
|
||||
if (m_dataReader == nullptr || m_ddsTopic == nullptr)
|
||||
const StructType& getStructType() const
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No dataReader initialised ";
|
||||
return false;
|
||||
}
|
||||
if (!isValid(callbackFunc))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No subscriber set for "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
return false;
|
||||
return *m_structType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
dds::sub::LoanedSamples<DynamicData> samples = m_dataReader.select().state(dds::sub::status::DataState::new_data()).read();
|
||||
|
||||
DEBUG_LOG(m_logger) << "got " << samples.length() + m_newSamplesDuringRead.size() << " samples from reader for "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
|
||||
for (const auto &sample : samples)
|
||||
bool create(const dds::domain::DomainParticipant& domainParticipant, const dds::sub::Subscriber& ddsSubscriber,
|
||||
const std::string& specialTopicName, const StructType& structType)
|
||||
{
|
||||
if (sample.info().valid())
|
||||
readData(sample, m_dataReader->topic_name(), callbackFunc);
|
||||
}
|
||||
|
||||
auto copy = m_newSamplesDuringRead;
|
||||
|
||||
m_newSamplesDuringRead.clear();
|
||||
for (auto &sample : copy)
|
||||
{
|
||||
|
||||
readData(rti::sub::LoanedSample<DynamicData>(sample.sample, &sample.info), m_dataReader->topic_name(), callbackFunc);
|
||||
delete sample.sample;
|
||||
DEBUG_LOG(m_logger) << "IN DynamicDataReader::create (" << m_structType->name() << ")";
|
||||
|
||||
if (domainParticipant == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "DomainParticipant does not exist ";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_ddsTopic != nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Type '" << m_structType->name() << "' already created";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (structType.has_parent())
|
||||
m_structType =
|
||||
new dds::core::xtypes::StructType(structType.name(), structType.parent(), structType.members());
|
||||
else
|
||||
m_structType = new dds::core::xtypes::StructType(structType.name(), structType.members());
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
const std::string topicName =
|
||||
specialTopicName.empty() ? DDS::Helper::getShortTopicName(m_structType->name()) : specialTopicName;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Creating topic " << topicName << " with type: " << m_structType->name();
|
||||
|
||||
m_ddsTopic = dds::topic::find<dds::topic::Topic<DynamicData>>(domainParticipant, topicName);
|
||||
if (m_ddsTopic == nullptr)
|
||||
{
|
||||
rti::core::xtypes::DynamicDataTypeSerializationProperty serialization_property;
|
||||
serialization_property.min_size_serialized(0);
|
||||
dds::domain::DomainParticipant dp = domainParticipant;
|
||||
rti::domain::register_type(dp, structType.name(), structType, serialization_property);
|
||||
m_ddsTopic = dds::topic::Topic<DynamicData>(domainParticipant, topicName, structType);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "m_ddsTopic created: " << m_ddsTopic.name();
|
||||
|
||||
if (m_logger.isDebugEnabled())
|
||||
{
|
||||
dds::sub::qos::SubscriberQos subscriberQoS = ddsSubscriber.qos();
|
||||
dds::core::policy::Partition partition = subscriberQoS.policy<dds::core::policy::Partition>();
|
||||
dds::core::StringSeq parititionNames = partition.name();
|
||||
DEBUG_LOG(m_logger) << "Subscribing partitions: " << parititionNames.size();
|
||||
for (const std::string& name : parititionNames)
|
||||
DEBUG_LOG(m_logger) << "SubscriberQoS: partition name = " << name;
|
||||
}
|
||||
|
||||
dds::sub::qos::DataReaderQos dataReaderQos = ddsSubscriber.default_datareader_qos();
|
||||
|
||||
QString typeName = QString::fromStdString(m_structType->name());
|
||||
if (typeName.endsWith(QLatin1String("Request")) || typeName.endsWith(QLatin1String("Reply")))
|
||||
{
|
||||
|
||||
dds::core::policy::Durability readerDurability;
|
||||
dataReaderQos >> readerDurability;
|
||||
readerDurability.kind(dds::core::policy::DurabilityKind_def::VOLATILE);
|
||||
dataReaderQos << readerDurability;
|
||||
}
|
||||
|
||||
m_dataReader =
|
||||
DataReader(ddsSubscriber, m_ddsTopic, dataReaderQos, nullptr, dds::core::status::StatusMask::all());
|
||||
|
||||
if (m_dataReader == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Creating dataReader for '" << topicName << "' with type: '"
|
||||
<< m_structType->name() << "' failed";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const dds::core::Exception& ex)
|
||||
{
|
||||
ERROR_LOG(m_logger) << ex.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "dataReader created (" << m_structType->name() << ")";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return checkDisposedInstances(callbackFunc);
|
||||
}
|
||||
bool hasSamples() const
|
||||
{
|
||||
qint64 sampleSize = m_dataReader->datareader_cache_status().sample_count();
|
||||
DEBUG_LOG(m_logger) << "sampleSize = " << sampleSize;
|
||||
return sampleSize > 0;
|
||||
}
|
||||
|
||||
void setHaveSubscriberCallback(bool bHave)
|
||||
{
|
||||
m_bHaveSubscriberCallback = bHave;
|
||||
}
|
||||
std::string topicName() const
|
||||
{
|
||||
return m_ddsTopic.name();
|
||||
}
|
||||
dds::sub::LoanedSamples<DynamicData> readAlive(bool& bSeenNewSamples)
|
||||
{
|
||||
dds::sub::LoanedSamples<DynamicData> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::alive()).read();
|
||||
TRACE_LOG(m_logger) << "readAlive for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length() << ", this: " << this << ", instance handle "
|
||||
<< m_dataReader.instance_handle();
|
||||
|
||||
void recreateReader()
|
||||
{
|
||||
if (m_dataReader == nullptr)
|
||||
return;
|
||||
m_dataReader = DataReader(m_dataReader.subscriber(), m_ddsTopic);
|
||||
}
|
||||
bSeenNewSamples = checkNewSamples(samples);
|
||||
return samples;
|
||||
}
|
||||
|
||||
private:
|
||||
dds::sub::LoanedSamples<DynamicData> takeAlive(bool& bSeenNewSamples)
|
||||
{
|
||||
dds::sub::LoanedSamples<DynamicData> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::alive()).take();
|
||||
TRACE_LOG(m_logger) << "takeAlive for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length() << ", this: " << this << ", instance handle "
|
||||
<< m_dataReader.instance_handle();
|
||||
|
||||
bSeenNewSamples = checkNewSamples(samples);
|
||||
return samples;
|
||||
}
|
||||
|
||||
dds::sub::LoanedSamples<DynamicData> takeDisposed()
|
||||
{
|
||||
dds::sub::LoanedSamples<DynamicData> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::not_alive_disposed()).take();
|
||||
TRACE_LOG(m_logger) << "takeDisposed for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length() << ", this: " << this << ", instance handle "
|
||||
<< m_dataReader.instance_handle();
|
||||
return samples;
|
||||
}
|
||||
|
||||
template <typename C> bool read(C callbackFunc)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN read (" << DDS::topic_type_name<TopicType>::value() << "), this: " << this
|
||||
<< ", instance handle " << m_dataReader.instance_handle();
|
||||
|
||||
if (m_dataReader == nullptr || m_ddsTopic == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No dataReader initialised ";
|
||||
return false;
|
||||
}
|
||||
if (!isValid(callbackFunc))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No subscriber set for " << DDS::topic_type_name<TopicType>::value();
|
||||
return false;
|
||||
}
|
||||
|
||||
dds::sub::LoanedSamples<DynamicData> samples =
|
||||
m_dataReader.select().state(dds::sub::status::DataState::new_data()).read();
|
||||
|
||||
DEBUG_LOG(m_logger) << "got " << samples.length() + m_newSamplesDuringRead.size() << " samples from reader for "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
|
||||
for (const auto& sample : samples)
|
||||
{
|
||||
if (sample.info().valid())
|
||||
readData(sample, m_dataReader->topic_name(), callbackFunc);
|
||||
}
|
||||
|
||||
auto copy = m_newSamplesDuringRead;
|
||||
|
||||
m_newSamplesDuringRead.clear();
|
||||
for (auto& sample : copy)
|
||||
{
|
||||
|
||||
readData(rti::sub::LoanedSample<DynamicData>(sample.sample, &sample.info), m_dataReader->topic_name(),
|
||||
callbackFunc);
|
||||
delete sample.sample;
|
||||
}
|
||||
|
||||
return checkDisposedInstances(callbackFunc);
|
||||
}
|
||||
|
||||
void setHaveSubscriberCallback(bool bHave)
|
||||
{
|
||||
m_bHaveSubscriberCallback = bHave;
|
||||
}
|
||||
|
||||
std::string topicName() const
|
||||
{
|
||||
return m_ddsTopic.name();
|
||||
}
|
||||
|
||||
void recreateReader()
|
||||
{
|
||||
if (m_dataReader == nullptr)
|
||||
return;
|
||||
m_dataReader = DataReader(m_dataReader.subscriber(), m_ddsTopic);
|
||||
}
|
||||
|
||||
private:
|
||||
#if RTI_DDS_VERSION_MAJOR < 6
|
||||
inline bool checkNewSamples(dds::sub::LoanedSamples<DynamicData> &samples)
|
||||
inline bool checkNewSamples(dds::sub::LoanedSamples<DynamicData>& samples)
|
||||
#else
|
||||
inline bool checkNewSamples(const dds::sub::LoanedSamples<DynamicData> &samples)
|
||||
inline bool checkNewSamples(const dds::sub::LoanedSamples<DynamicData>& samples)
|
||||
#endif
|
||||
{
|
||||
|
||||
if (!m_bHaveSubscriberCallback)
|
||||
return false;
|
||||
|
||||
bool bSeenNewSamples = false;
|
||||
for (const auto &sample : samples)
|
||||
{
|
||||
const dds::sub::status::DataState ds = sample.info()->state();
|
||||
if (ds.view_state() == dds::sub::status::ViewState::new_view() ||
|
||||
ds.sample_state() == dds::sub::status::SampleState::not_read())
|
||||
{
|
||||
SampleStruct ss;
|
||||
ss.sample = new DynamicData(sample.data());
|
||||
ss.info = sample.info();
|
||||
|
||||
m_newSamplesDuringRead.emplace_back(ss);
|
||||
|
||||
bSeenNewSamples = true;
|
||||
}
|
||||
}
|
||||
return bSeenNewSamples;
|
||||
}
|
||||
if (!m_bHaveSubscriberCallback)
|
||||
return false;
|
||||
|
||||
template<typename C>
|
||||
bool checkDisposedInstances(C callbackFunc)
|
||||
{
|
||||
const dds::sub::status::DataState ds(dds::sub::status::SampleState::any(),
|
||||
dds::sub::status::ViewState::any(),
|
||||
dds::sub::status::InstanceState::not_alive_mask());
|
||||
bool bSeenNewSamples = false;
|
||||
for (const auto& sample : samples)
|
||||
{
|
||||
const dds::sub::status::DataState ds = sample.info()->state();
|
||||
if (ds.view_state() == dds::sub::status::ViewState::new_view() ||
|
||||
ds.sample_state() == dds::sub::status::SampleState::not_read())
|
||||
{
|
||||
SampleStruct ss;
|
||||
ss.sample = new DynamicData(sample.data());
|
||||
ss.info = sample.info();
|
||||
|
||||
|
||||
dds::sub::LoanedSamples<DynamicData> samples = m_dataReader.select().state(ds).take();
|
||||
m_newSamplesDuringRead.emplace_back(ss);
|
||||
|
||||
if (samples.length() == 0)
|
||||
return false;
|
||||
|
||||
DEBUG_LOG(m_logger) << "got " << samples.length() << " disposed instances from reader for "
|
||||
<< m_ddsTopic.name();
|
||||
|
||||
for (const auto &sample : samples)
|
||||
{
|
||||
if (sample.info().valid())
|
||||
readData(sample, m_dataReader->topic_name(), callbackFunc);
|
||||
bSeenNewSamples = true;
|
||||
}
|
||||
}
|
||||
return bSeenNewSamples;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
template <typename C> bool checkDisposedInstances(C callbackFunc)
|
||||
{
|
||||
const dds::sub::status::DataState ds(dds::sub::status::SampleState::any(), dds::sub::status::ViewState::any(),
|
||||
dds::sub::status::InstanceState::not_alive_mask());
|
||||
|
||||
static void readData(const rti::sub::LoanedSample<DynamicData> &sample, const std::string &topicName, const SubscriberCallback &callbackFunc)
|
||||
{
|
||||
DataModification modType = DataModification::eModified;
|
||||
const dds::sub::status::DataState ds = sample.info()->state();
|
||||
if (ds.view_state() == dds::sub::status::ViewState::new_view())
|
||||
modType = DataModification::eAdded;
|
||||
if (ds.instance_state() != dds::sub::status::InstanceState::alive())
|
||||
modType = DataModification::eRemoved;
|
||||
|
||||
dds::sub::LoanedSamples<DynamicData> samples = m_dataReader.select().state(ds).take();
|
||||
|
||||
callbackFunc(sample.data(), topicName, modType);
|
||||
}
|
||||
if (samples.length() == 0)
|
||||
return false;
|
||||
|
||||
static void readData(const rti::sub::LoanedSample<DynamicData> &sample, const std::string &topicName, const SubscriberCallbackWithSampleInfo &callbackFunc)
|
||||
{
|
||||
callbackFunc(sample.data(), topicName, sample.info());
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "got " << samples.length() << " disposed instances from reader for "
|
||||
<< m_ddsTopic.name();
|
||||
|
||||
static bool isValid(const SubscriberCallback &callbackFunc)
|
||||
{
|
||||
return callbackFunc != nullptr;
|
||||
}
|
||||
static bool isValid(const SubscriberCallbackWithSampleInfo &callbackFunc)
|
||||
{
|
||||
return callbackFunc != nullptr;
|
||||
}
|
||||
for (const auto& sample : samples)
|
||||
{
|
||||
if (sample.info().valid())
|
||||
readData(sample, m_dataReader->topic_name(), callbackFunc);
|
||||
}
|
||||
|
||||
private:
|
||||
DataReader m_dataReader;
|
||||
StructType *m_structType;
|
||||
DataTopic m_ddsTopic;
|
||||
return true;
|
||||
}
|
||||
|
||||
struct SampleStruct
|
||||
{
|
||||
DynamicData *sample = nullptr;
|
||||
dds::sub::SampleInfo info;
|
||||
};
|
||||
std::vector<SampleStruct> m_newSamplesDuringRead;
|
||||
bool m_bHaveSubscriberCallback;
|
||||
static void readData(const rti::sub::LoanedSample<DynamicData>& sample, const std::string& topicName,
|
||||
const SubscriberCallback& callbackFunc)
|
||||
{
|
||||
DataModification modType = DataModification::eModified;
|
||||
const dds::sub::status::DataState ds = sample.info()->state();
|
||||
if (ds.view_state() == dds::sub::status::ViewState::new_view())
|
||||
modType = DataModification::eAdded;
|
||||
if (ds.instance_state() != dds::sub::status::InstanceState::alive())
|
||||
modType = DataModification::eRemoved;
|
||||
|
||||
callbackFunc(sample.data(), topicName, modType);
|
||||
}
|
||||
|
||||
static void readData(const rti::sub::LoanedSample<DynamicData>& sample, const std::string& topicName,
|
||||
const SubscriberCallbackWithSampleInfo& callbackFunc)
|
||||
{
|
||||
callbackFunc(sample.data(), topicName, sample.info());
|
||||
}
|
||||
|
||||
static bool isValid(const SubscriberCallback& callbackFunc)
|
||||
{
|
||||
return callbackFunc != nullptr;
|
||||
}
|
||||
|
||||
static bool isValid(const SubscriberCallbackWithSampleInfo& callbackFunc)
|
||||
{
|
||||
return callbackFunc != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
DataReader m_dataReader;
|
||||
StructType* m_structType;
|
||||
DataTopic m_ddsTopic;
|
||||
|
||||
struct SampleStruct
|
||||
{
|
||||
DynamicData* sample = nullptr;
|
||||
dds::sub::SampleInfo info;
|
||||
};
|
||||
|
||||
std::vector<SampleStruct> m_newSamplesDuringRead;
|
||||
bool m_bHaveSubscriberCallback;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace DDSGeneric
|
||||
Executable → Regular
+299
-311
@@ -1,381 +1,369 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dds/sub/DataReader.hpp>
|
||||
#include <dds/topic/find.hpp>
|
||||
#include <dds/topic/Topic.hpp>
|
||||
|
||||
#include <DDS/Generic/generic_base.h>
|
||||
#include <DDS/Generic/generic_logger.h>
|
||||
#include <LtsUtilsCore/data_modification_enum.h>
|
||||
#include <dds/sub/DataReader.hpp>
|
||||
#include <dds/topic/Topic.hpp>
|
||||
#include <dds/topic/find.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace DDSGeneric
|
||||
{
|
||||
|
||||
template <typename TOPICTYPE>
|
||||
class GenericDataReader
|
||||
template <typename TOPICTYPE> class GenericDataReader
|
||||
{
|
||||
public:
|
||||
using TopicType = TOPICTYPE;
|
||||
using TopicTypeRead = TOPICTYPE;
|
||||
using DataReader = dds::sub::DataReader<TopicTypeRead>;
|
||||
using DataTopic = dds::topic::Topic<TopicTypeRead>;
|
||||
using DataReaderQos = dds::sub::qos::DataReaderQos;
|
||||
using SubscriberCallback = std::function<void(const TopicTypeRead &, DataModification)>;
|
||||
using SubscriberCallbackWithSampleInfo = std::function<void(const TopicTypeRead &, const dds::sub::SampleInfo &)>;
|
||||
public:
|
||||
using TopicType = TOPICTYPE;
|
||||
using TopicTypeRead = TOPICTYPE;
|
||||
using DataReader = dds::sub::DataReader<TopicTypeRead>;
|
||||
using DataTopic = dds::topic::Topic<TopicTypeRead>;
|
||||
using DataReaderQos = dds::sub::qos::DataReaderQos;
|
||||
using SubscriberCallback = std::function<void(const TopicTypeRead&, DataModification)>;
|
||||
using SubscriberCallbackWithSampleInfo = std::function<void(const TopicTypeRead&, const dds::sub::SampleInfo&)>;
|
||||
|
||||
GenericDataReader()
|
||||
: m_dataReader(nullptr)
|
||||
, m_ddsTopic(nullptr)
|
||||
, m_bHaveSubscriberCallback(false)
|
||||
, m_logger(DDS::getLogger(DDS::topic_type_name<TopicType>::value(), DDS::DataType::DATA_READER))
|
||||
{}
|
||||
|
||||
virtual ~GenericDataReader()
|
||||
{
|
||||
m_ddsTopic = nullptr;
|
||||
m_dataReader = nullptr;
|
||||
}
|
||||
|
||||
DataReader getDataReader() const { return m_dataReader; }
|
||||
|
||||
bool create(const dds::domain::DomainParticipant &domainParticipant,
|
||||
const dds::sub::Subscriber &ddsSubscriber,
|
||||
const std::string &topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<TopicType>::value()),
|
||||
bool bCreateDataReader = true)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN GenericDataReader::create ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< "), this: " << this;
|
||||
|
||||
if (domainParticipant == nullptr)
|
||||
GenericDataReader()
|
||||
: m_dataReader(nullptr), m_ddsTopic(nullptr), m_bHaveSubscriberCallback(false),
|
||||
m_logger(DDS::getLogger(DDS::topic_type_name<TopicType>::value(), DDS::DataType::DATA_READER))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "DomainParticipant does not exist ";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_ddsTopic != nullptr)
|
||||
virtual ~GenericDataReader()
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Type '"
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< "' already created";
|
||||
return false;
|
||||
m_ddsTopic = nullptr;
|
||||
m_dataReader = nullptr;
|
||||
}
|
||||
|
||||
try
|
||||
DataReader getDataReader() const
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Creating read topic " << topicName << " with type: "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
return m_dataReader;
|
||||
}
|
||||
|
||||
m_ddsTopic = dds::topic::find<DataTopic>(domainParticipant, topicName);
|
||||
if (m_ddsTopic == nullptr)
|
||||
m_ddsTopic = DataTopic(domainParticipant, topicName);
|
||||
bool create(const dds::domain::DomainParticipant& domainParticipant, const dds::sub::Subscriber& ddsSubscriber,
|
||||
const std::string& topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<TopicType>::value()),
|
||||
bool bCreateDataReader = true)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN GenericDataReader::create (" << DDS::topic_type_name<TopicType>::value()
|
||||
<< "), this: " << this;
|
||||
|
||||
if (m_logger.isDebugEnabled())
|
||||
{
|
||||
dds::sub::qos::SubscriberQos subscriberQoS = ddsSubscriber.qos();
|
||||
dds::core::policy::Partition partition = subscriberQoS.policy<dds::core::policy::Partition>();
|
||||
dds::core::StringSeq parititionNames = partition.name();
|
||||
DEBUG_LOG(m_logger) << "Subscribing partitions: " << parititionNames.size();
|
||||
for (const std::string &name : parititionNames)
|
||||
DEBUG_LOG(m_logger) << " partition name = " << name;
|
||||
}
|
||||
if (domainParticipant == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "DomainParticipant does not exist ";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_ddsTopic != nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Type '" << DDS::topic_type_name<TopicType>::value() << "' already created";
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Creating read topic " << topicName
|
||||
<< " with type: " << DDS::topic_type_name<TopicType>::value();
|
||||
|
||||
m_ddsTopic = dds::topic::find<DataTopic>(domainParticipant, topicName);
|
||||
if (m_ddsTopic == nullptr)
|
||||
m_ddsTopic = DataTopic(domainParticipant, topicName);
|
||||
|
||||
if (m_logger.isDebugEnabled())
|
||||
{
|
||||
dds::sub::qos::SubscriberQos subscriberQoS = ddsSubscriber.qos();
|
||||
dds::core::policy::Partition partition = subscriberQoS.policy<dds::core::policy::Partition>();
|
||||
dds::core::StringSeq parititionNames = partition.name();
|
||||
DEBUG_LOG(m_logger) << "Subscribing partitions: " << parititionNames.size();
|
||||
for (const std::string& name : parititionNames)
|
||||
DEBUG_LOG(m_logger) << " partition name = " << name;
|
||||
}
|
||||
|
||||
if (bCreateDataReader)
|
||||
{
|
||||
dds::sub::qos::DataReaderQos drQos = domainParticipant->default_datareader_qos();
|
||||
m_dataReader = DataReader(ddsSubscriber, m_ddsTopic, drQos);
|
||||
if (m_dataReader == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Creating dataReader for '" << topicName << "' with type: '"
|
||||
<< DDS::topic_type_name<TopicType>::value() << "' failed";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const dds::core::Exception& ex)
|
||||
{
|
||||
ERROR_LOG(m_logger) << ex.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "dataReader created (" << DDS::topic_type_name<TopicType>::value() << ")";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hasSamples() const
|
||||
{
|
||||
qint64 sampleSize = m_dataReader->datareader_cache_status().sample_count();
|
||||
DEBUG_LOG(m_logger) << "sampleSize = " << sampleSize;
|
||||
return sampleSize > 0;
|
||||
}
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> readAlive(bool& bSeenNewSamples)
|
||||
{
|
||||
dds::sub::LoanedSamples<TopicTypeRead> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::alive()).read();
|
||||
TRACE_LOG(m_logger) << "readAlive for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length() << ", this: " << this << ", instance handle "
|
||||
<< m_dataReader.instance_handle();
|
||||
|
||||
bSeenNewSamples = checkNewSamples(samples);
|
||||
return samples;
|
||||
}
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> takeAlive(bool& bSeenNewSamples)
|
||||
{
|
||||
dds::sub::LoanedSamples<TopicTypeRead> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::alive()).take();
|
||||
TRACE_LOG(m_logger) << "takeAlive for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length() << ", this: " << this << ", instance handle "
|
||||
<< m_dataReader.instance_handle();
|
||||
|
||||
bSeenNewSamples = checkNewSamples(samples);
|
||||
return samples;
|
||||
}
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> takeDisposed()
|
||||
{
|
||||
dds::sub::LoanedSamples<TopicTypeRead> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::not_alive_disposed()).take();
|
||||
TRACE_LOG(m_logger) << "takeDisposed for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length() << ", this: " << this << ", instance handle "
|
||||
<< m_dataReader.instance_handle();
|
||||
return samples;
|
||||
}
|
||||
|
||||
template <typename C> bool read(C callbackFunc)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN read (" << DDS::topic_type_name<TopicType>::value() << "), this: " << this
|
||||
<< ", instance handle " << m_dataReader.instance_handle();
|
||||
|
||||
if (bCreateDataReader)
|
||||
{
|
||||
dds::sub::qos::DataReaderQos drQos = domainParticipant->default_datareader_qos();
|
||||
m_dataReader = DataReader(ddsSubscriber, m_ddsTopic, drQos);
|
||||
if (m_dataReader == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Creating dataReader for '" << topicName << "' with type: '"
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< "' failed";
|
||||
return false;
|
||||
ERROR_LOG(m_logger) << "No dataReader initialised ";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!isValid(callbackFunc))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No subscriber set for " << DDS::topic_type_name<TopicType>::value();
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<SampleStruct> samples;
|
||||
{
|
||||
dds::sub::LoanedSamples<TopicTypeRead> loanedSamples =
|
||||
m_dataReader.select().state(dds::sub::status::DataState::new_data()).read();
|
||||
samples.reserve(loanedSamples.length());
|
||||
for (const auto& sample : loanedSamples)
|
||||
{
|
||||
if (!sample.info().valid())
|
||||
continue;
|
||||
samples.emplace_back(sample.data(), sample.info());
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "got " << samples.size() + m_newSamplesDuringRead.size() << " samples from reader for "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
|
||||
for (const SampleStruct& ss : samples)
|
||||
readData(ss.sample, ss.info, callbackFunc);
|
||||
|
||||
if (!m_newSamplesDuringRead.empty())
|
||||
{
|
||||
std::vector<SampleStruct> copy;
|
||||
std::swap(copy, m_newSamplesDuringRead);
|
||||
|
||||
for (const SampleStruct& ss : copy)
|
||||
readData(ss.sample, ss.info, callbackFunc);
|
||||
}
|
||||
|
||||
return checkDisposedInstances(callbackFunc);
|
||||
}
|
||||
catch (const dds::core::Exception &ex)
|
||||
|
||||
void setHaveSubscriberCallback(bool bHave)
|
||||
{
|
||||
ERROR_LOG(m_logger) << ex.what();
|
||||
return false;
|
||||
m_bHaveSubscriberCallback = bHave;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "dataReader created ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< ")";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool hasSamples() const
|
||||
{
|
||||
qint64 sampleSize = m_dataReader->datareader_cache_status().sample_count();
|
||||
DEBUG_LOG(m_logger) << "sampleSize = " << sampleSize;
|
||||
return sampleSize > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> readAlive(bool &bSeenNewSamples)
|
||||
{
|
||||
dds::sub::LoanedSamples<TopicTypeRead> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::alive()).read();
|
||||
TRACE_LOG(m_logger) << "readAlive for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length()
|
||||
<< ", this: " << this << ", instance handle " << m_dataReader.instance_handle();
|
||||
|
||||
bSeenNewSamples = checkNewSamples(samples);
|
||||
return samples;
|
||||
}
|
||||
|
||||
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> takeAlive(bool &bSeenNewSamples)
|
||||
{
|
||||
dds::sub::LoanedSamples<TopicTypeRead> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::alive()).take();
|
||||
TRACE_LOG(m_logger) << "takeAlive for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length()
|
||||
<< ", this: " << this << ", instance handle " << m_dataReader.instance_handle();
|
||||
|
||||
bSeenNewSamples = checkNewSamples(samples);
|
||||
return samples;
|
||||
}
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> takeDisposed()
|
||||
{
|
||||
dds::sub::LoanedSamples<TopicTypeRead> samples =
|
||||
m_dataReader.select().state(dds::sub::status::InstanceState::not_alive_disposed()).take();
|
||||
TRACE_LOG(m_logger) << "takeDisposed for " << DDS::topic_type_name<TopicType>::value()
|
||||
<< ", count: " << samples.length()
|
||||
<< ", this: " << this << ", instance handle " << m_dataReader.instance_handle();
|
||||
return samples;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
bool read(C callbackFunc)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN read ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< "), this: " << this << ", instance handle " << m_dataReader.instance_handle();
|
||||
|
||||
if (m_dataReader == nullptr)
|
||||
std::string topicName() const
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No dataReader initialised ";
|
||||
return false;
|
||||
return m_ddsTopic.name();
|
||||
}
|
||||
if (!isValid(callbackFunc))
|
||||
|
||||
DataReader dataReader() const
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No subscriber set for "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
return false;
|
||||
return m_dataReader;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<SampleStruct> samples;
|
||||
virtual void recreateReader()
|
||||
{
|
||||
dds::sub::LoanedSamples<TopicTypeRead> loanedSamples = m_dataReader.select().state(dds::sub::status::DataState::new_data()).read();
|
||||
samples.reserve(loanedSamples.length());
|
||||
for (const auto &sample : loanedSamples)
|
||||
{
|
||||
if (!sample.info().valid())
|
||||
continue;
|
||||
samples.emplace_back(sample.data(), sample.info());
|
||||
}
|
||||
if (m_dataReader == nullptr)
|
||||
return;
|
||||
m_dataReader = DataReader(m_dataReader.subscriber(), m_ddsTopic);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "got " << samples.size() + m_newSamplesDuringRead.size() << " samples from reader for "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
|
||||
for (const SampleStruct &ss : samples)
|
||||
readData(ss.sample, ss.info, callbackFunc);
|
||||
|
||||
if (!m_newSamplesDuringRead.empty())
|
||||
{
|
||||
std::vector<SampleStruct> copy;
|
||||
std::swap(copy, m_newSamplesDuringRead);
|
||||
|
||||
|
||||
for (const SampleStruct &ss : copy)
|
||||
readData(ss.sample, ss.info, callbackFunc);
|
||||
}
|
||||
|
||||
return checkDisposedInstances(callbackFunc);
|
||||
}
|
||||
|
||||
void setHaveSubscriberCallback(bool bHave)
|
||||
{
|
||||
m_bHaveSubscriberCallback = bHave;
|
||||
}
|
||||
std::string topicName() const
|
||||
{
|
||||
return m_ddsTopic.name();
|
||||
}
|
||||
|
||||
DataReader dataReader() const { return m_dataReader; }
|
||||
|
||||
virtual void recreateReader()
|
||||
{
|
||||
if (m_dataReader == nullptr)
|
||||
return;
|
||||
m_dataReader = DataReader(m_dataReader.subscriber(), m_ddsTopic);
|
||||
}
|
||||
private:
|
||||
private:
|
||||
#if RTI_DDS_VERSION_MAJOR < 6
|
||||
inline bool checkNewSamples(dds::sub::LoanedSamples<TopicTypeRead> &samples)
|
||||
inline bool checkNewSamples(dds::sub::LoanedSamples<TopicTypeRead>& samples)
|
||||
#else
|
||||
inline bool checkNewSamples(const dds::sub::LoanedSamples<TopicTypeRead> &samples)
|
||||
inline bool checkNewSamples(const dds::sub::LoanedSamples<TopicTypeRead>& samples)
|
||||
#endif
|
||||
{
|
||||
|
||||
if (!m_bHaveSubscriberCallback)
|
||||
return false;
|
||||
|
||||
bool bSeenNewSamples = false;
|
||||
for (const auto &sample : samples)
|
||||
{
|
||||
const dds::sub::status::DataState ds = sample.info()->state();
|
||||
if (ds.view_state() == dds::sub::status::ViewState::new_view() ||
|
||||
ds.sample_state() == dds::sub::status::SampleState::not_read())
|
||||
{
|
||||
|
||||
m_newSamplesDuringRead.emplace_back(sample.data(), sample.info());
|
||||
|
||||
bSeenNewSamples = true;
|
||||
}
|
||||
}
|
||||
return bSeenNewSamples;
|
||||
}
|
||||
if (!m_bHaveSubscriberCallback)
|
||||
return false;
|
||||
|
||||
template<typename C>
|
||||
bool checkDisposedInstances(C callbackFunc)
|
||||
{
|
||||
const dds::sub::status::DataState ds(dds::sub::status::SampleState::any(),
|
||||
dds::sub::status::ViewState::any(),
|
||||
dds::sub::status::InstanceState::not_alive_mask());
|
||||
bool bSeenNewSamples = false;
|
||||
for (const auto& sample : samples)
|
||||
{
|
||||
const dds::sub::status::DataState ds = sample.info()->state();
|
||||
if (ds.view_state() == dds::sub::status::ViewState::new_view() ||
|
||||
ds.sample_state() == dds::sub::status::SampleState::not_read())
|
||||
{
|
||||
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> samples = m_dataReader.select().state(ds).take();
|
||||
m_newSamplesDuringRead.emplace_back(sample.data(), sample.info());
|
||||
|
||||
if (samples.length() == 0)
|
||||
return false;
|
||||
|
||||
DEBUG_LOG(m_logger) << "got " << samples.length() << " disposed instances from reader for "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
|
||||
for (const auto &sample : samples)
|
||||
{
|
||||
if (sample.info().valid())
|
||||
readData(sample.data(), sample.info(), callbackFunc);
|
||||
bSeenNewSamples = true;
|
||||
}
|
||||
}
|
||||
return bSeenNewSamples;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
template <typename C> bool checkDisposedInstances(C callbackFunc)
|
||||
{
|
||||
const dds::sub::status::DataState ds(dds::sub::status::SampleState::any(), dds::sub::status::ViewState::any(),
|
||||
dds::sub::status::InstanceState::not_alive_mask());
|
||||
|
||||
static void readData(const TopicType &sample, const dds::sub::SampleInfo &info, const SubscriberCallback &callbackFunc)
|
||||
{
|
||||
DataModification modType = DataModification::eModified;
|
||||
const dds::sub::status::DataState ds = info.state();
|
||||
if (ds.view_state() == dds::sub::status::ViewState::new_view())
|
||||
modType = DataModification::eAdded;
|
||||
if (ds.instance_state() != dds::sub::status::InstanceState::alive())
|
||||
modType = DataModification::eRemoved;
|
||||
|
||||
dds::sub::LoanedSamples<TopicTypeRead> samples = m_dataReader.select().state(ds).take();
|
||||
|
||||
callbackFunc(sample, modType);
|
||||
}
|
||||
if (samples.length() == 0)
|
||||
return false;
|
||||
|
||||
static void readData(const TopicType &sample, const dds::sub::SampleInfo &info, const SubscriberCallbackWithSampleInfo &callbackFunc)
|
||||
{
|
||||
callbackFunc(sample, info);
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "got " << samples.length() << " disposed instances from reader for "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
|
||||
static bool isValid(const SubscriberCallback &callbackFunc)
|
||||
{
|
||||
return callbackFunc != nullptr;
|
||||
}
|
||||
static bool isValid(const SubscriberCallbackWithSampleInfo &callbackFunc)
|
||||
{
|
||||
return callbackFunc != nullptr;
|
||||
}
|
||||
for (const auto& sample : samples)
|
||||
{
|
||||
if (sample.info().valid())
|
||||
readData(sample.data(), sample.info(), callbackFunc);
|
||||
}
|
||||
|
||||
protected:
|
||||
DataReader m_dataReader;
|
||||
DataReaderQos m_dataReaderQos;
|
||||
return true;
|
||||
}
|
||||
|
||||
DataTopic m_ddsTopic;
|
||||
struct SampleStruct
|
||||
{
|
||||
TopicTypeRead sample;
|
||||
dds::sub::SampleInfo info;
|
||||
static void readData(const TopicType& sample, const dds::sub::SampleInfo& info,
|
||||
const SubscriberCallback& callbackFunc)
|
||||
{
|
||||
DataModification modType = DataModification::eModified;
|
||||
const dds::sub::status::DataState ds = info.state();
|
||||
if (ds.view_state() == dds::sub::status::ViewState::new_view())
|
||||
modType = DataModification::eAdded;
|
||||
if (ds.instance_state() != dds::sub::status::InstanceState::alive())
|
||||
modType = DataModification::eRemoved;
|
||||
|
||||
SampleStruct() = default;
|
||||
SampleStruct(const TopicTypeRead &s, const dds::sub::SampleInfo &i)
|
||||
: sample(s)
|
||||
, info(i)
|
||||
{}
|
||||
};
|
||||
std::vector<SampleStruct> m_newSamplesDuringRead;
|
||||
bool m_bHaveSubscriberCallback;
|
||||
callbackFunc(sample, modType);
|
||||
}
|
||||
|
||||
static void readData(const TopicType& sample, const dds::sub::SampleInfo& info,
|
||||
const SubscriberCallbackWithSampleInfo& callbackFunc)
|
||||
{
|
||||
callbackFunc(sample, info);
|
||||
}
|
||||
|
||||
static bool isValid(const SubscriberCallback& callbackFunc)
|
||||
{
|
||||
return callbackFunc != nullptr;
|
||||
}
|
||||
|
||||
static bool isValid(const SubscriberCallbackWithSampleInfo& callbackFunc)
|
||||
{
|
||||
return callbackFunc != nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
DataReader m_dataReader;
|
||||
DataReaderQos m_dataReaderQos;
|
||||
|
||||
DataTopic m_ddsTopic;
|
||||
|
||||
struct SampleStruct
|
||||
{
|
||||
TopicTypeRead sample;
|
||||
dds::sub::SampleInfo info;
|
||||
|
||||
SampleStruct() = default;
|
||||
|
||||
SampleStruct(const TopicTypeRead& s, const dds::sub::SampleInfo& i) : sample(s), info(i) {}
|
||||
};
|
||||
|
||||
std::vector<SampleStruct> m_newSamplesDuringRead;
|
||||
bool m_bHaveSubscriberCallback;
|
||||
};
|
||||
|
||||
template<typename TOPICTYPE>
|
||||
class GenericDataReaderContentFilter final
|
||||
: public GenericDataReader<TOPICTYPE>
|
||||
template <typename TOPICTYPE> class GenericDataReaderContentFilter final : public GenericDataReader<TOPICTYPE>
|
||||
{
|
||||
using BaseClass = GenericDataReader<TOPICTYPE>;
|
||||
public:
|
||||
using TopicType = TOPICTYPE;
|
||||
using DataReader = dds::sub::DataReader<TopicType>;
|
||||
using BaseClass = GenericDataReader<TOPICTYPE>;
|
||||
|
||||
using BaseClass::BaseClass;
|
||||
public:
|
||||
using TopicType = TOPICTYPE;
|
||||
using DataReader = dds::sub::DataReader<TopicType>;
|
||||
|
||||
bool create(const dds::domain::DomainParticipant &domainParticipant,
|
||||
const dds::sub::Subscriber &ddsSubscriber,
|
||||
const std::string &specialTopicName,
|
||||
const dds::topic::Filter &filter)
|
||||
{
|
||||
if (!BaseClass::create(domainParticipant, ddsSubscriber, specialTopicName, false))
|
||||
return false;
|
||||
m_filter = filter;
|
||||
try
|
||||
using BaseClass::BaseClass;
|
||||
|
||||
bool create(const dds::domain::DomainParticipant& domainParticipant, const dds::sub::Subscriber& ddsSubscriber,
|
||||
const std::string& specialTopicName, const dds::topic::Filter& filter)
|
||||
{
|
||||
qint64 ptr = reinterpret_cast<qint64>(this);
|
||||
const QByteArray name = QByteArray(DDS::topic_type_name<TopicType>::value().c_str())
|
||||
+ "- content filter 0x"
|
||||
+ QByteArray::number(ptr, 16);
|
||||
m_filteredTopic = dds::topic::ContentFilteredTopic<TopicType>(BaseClass::m_ddsTopic, name.data(), m_filter);
|
||||
BaseClass::m_dataReader = DataReader(ddsSubscriber, m_filteredTopic);
|
||||
if (!BaseClass::create(domainParticipant, ddsSubscriber, specialTopicName, false))
|
||||
return false;
|
||||
m_filter = filter;
|
||||
try
|
||||
{
|
||||
qint64 ptr = reinterpret_cast<qint64>(this);
|
||||
const QByteArray name = QByteArray(DDS::topic_type_name<TopicType>::value().c_str()) +
|
||||
"- content filter 0x" + QByteArray::number(ptr, 16);
|
||||
m_filteredTopic = dds::topic::ContentFilteredTopic<TopicType>(BaseClass::m_ddsTopic, name.data(), m_filter);
|
||||
BaseClass::m_dataReader = DataReader(ddsSubscriber, m_filteredTopic);
|
||||
}
|
||||
catch (const dds::core::Exception& ex)
|
||||
{
|
||||
ERROR_LOG(BaseClass::m_logger) << ex.what();
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(BaseClass::m_logger) << "dataReader with filter created (" << DDS::topic_type_name<TopicType>::value()
|
||||
<< ")";
|
||||
return true;
|
||||
}
|
||||
catch (const dds::core::Exception &ex)
|
||||
|
||||
dds::topic::Filter& filter()
|
||||
{
|
||||
ERROR_LOG(BaseClass::m_logger) << ex.what();
|
||||
return false;
|
||||
return m_filter;
|
||||
}
|
||||
DEBUG_LOG(BaseClass::m_logger) << "dataReader with filter created ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< ")";
|
||||
return true;
|
||||
}
|
||||
|
||||
dds::topic::Filter &filter() { return m_filter; }
|
||||
const dds::topic::Filter &filter() const { return m_filter; }
|
||||
const dds::topic::Filter& filter() const
|
||||
{
|
||||
return m_filter;
|
||||
}
|
||||
|
||||
virtual void recreateReader()
|
||||
{
|
||||
if (BaseClass::m_dataReader == nullptr)
|
||||
return;
|
||||
BaseClass::m_dataReader = DataReader(BaseClass::m_dataReader.subscriber(), m_filteredTopic);
|
||||
}
|
||||
virtual void recreateReader()
|
||||
{
|
||||
if (BaseClass::m_dataReader == nullptr)
|
||||
return;
|
||||
BaseClass::m_dataReader = DataReader(BaseClass::m_dataReader.subscriber(), m_filteredTopic);
|
||||
}
|
||||
|
||||
private:
|
||||
dds::topic::ContentFilteredTopic<TopicType> m_filteredTopic = dds::topic::ContentFilteredTopic<TopicType>(nullptr);
|
||||
dds::topic::Filter m_filter = dds::topic::Filter(std::string());
|
||||
private:
|
||||
dds::topic::ContentFilteredTopic<TopicType> m_filteredTopic = dds::topic::ContentFilteredTopic<TopicType>(nullptr);
|
||||
dds::topic::Filter m_filter = dds::topic::Filter(std::string());
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace DDSGeneric
|
||||
Executable → Regular
+101
-112
@@ -1,142 +1,131 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <DDS/Generic/generic_base.h>
|
||||
#include <DDS/Generic/generic_logger.h>
|
||||
#include <dds/pub/DataWriter.hpp>
|
||||
#include <dds/sub/SampleInfo.hpp>
|
||||
#include <dds/topic/find.hpp>
|
||||
#include <dds/topic/Topic.hpp>
|
||||
|
||||
#include <DDS/Generic/generic_logger.h>
|
||||
#include <DDS/Generic/generic_base.h>
|
||||
#include <dds/topic/find.hpp>
|
||||
|
||||
namespace DDSGeneric
|
||||
{
|
||||
|
||||
template <typename TOPICTYPE>
|
||||
class GenericDataWriter final
|
||||
template <typename TOPICTYPE> class GenericDataWriter final
|
||||
{
|
||||
public:
|
||||
using TopicType = TOPICTYPE;
|
||||
using DataWriter = dds::pub::DataWriter<TopicType>;
|
||||
using DataTopic = dds::topic::Topic<TopicType>;
|
||||
public:
|
||||
using TopicType = TOPICTYPE;
|
||||
using DataWriter = dds::pub::DataWriter<TopicType>;
|
||||
using DataTopic = dds::topic::Topic<TopicType>;
|
||||
|
||||
GenericDataWriter()
|
||||
: m_dataWriter(nullptr)
|
||||
, m_ddsTopic(nullptr)
|
||||
, m_logger(DDS::getLogger(DDS::topic_type_name<TopicType>::value(), DDS::DataType::DATA_WRITER))
|
||||
{}
|
||||
|
||||
bool create(const dds::domain::DomainParticipant &participant,
|
||||
const dds::pub::Publisher &ddsPublisher,
|
||||
const std::string &topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<TopicType>::value()))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN GenericDataWriter::create ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< ")";
|
||||
|
||||
if (participant == nullptr)
|
||||
GenericDataWriter()
|
||||
: m_dataWriter(nullptr), m_ddsTopic(nullptr),
|
||||
m_logger(DDS::getLogger(DDS::topic_type_name<TopicType>::value(), DDS::DataType::DATA_WRITER))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Participant not available, aborting. ";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_ddsTopic != nullptr)
|
||||
bool create(const dds::domain::DomainParticipant& participant, const dds::pub::Publisher& ddsPublisher,
|
||||
const std::string& topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name<TopicType>::value()))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Type '"
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< "' already created";
|
||||
return false;
|
||||
DEBUG_LOG(m_logger) << "IN GenericDataWriter::create (" << DDS::topic_type_name<TopicType>::value() << ")";
|
||||
|
||||
if (participant == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Participant not available, aborting. ";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_ddsTopic != nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Type '" << DDS::topic_type_name<TopicType>::value() << "' already created";
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
DEBUG_LOG(m_logger) << "Creating write topic " << topicName
|
||||
<< " with type: " << DDS::topic_type_name<TopicType>::value();
|
||||
|
||||
m_ddsTopic = dds::topic::find<DataTopic>(participant, topicName);
|
||||
if (m_ddsTopic == nullptr)
|
||||
m_ddsTopic = DataTopic(participant, topicName);
|
||||
|
||||
m_dataWriter = DataWriter(ddsPublisher, m_ddsTopic, ddsPublisher.default_datawriter_qos());
|
||||
|
||||
if (m_dataWriter == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Initialisation of " << DDS::topic_type_name<TopicType>::value() << " failed ";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const dds::core::Exception& ex)
|
||||
{
|
||||
ERROR_LOG(m_logger) << ex.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "dataWriter created (" << DDS::topic_type_name<TopicType>::value() << ")";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
DEBUG_LOG(m_logger) << "Creating write topic " << topicName << " with type: "
|
||||
<< DDS::topic_type_name<TopicType>::value();
|
||||
|
||||
m_ddsTopic = dds::topic::find<DataTopic>(participant, topicName);
|
||||
if (m_ddsTopic == nullptr)
|
||||
m_ddsTopic = DataTopic(participant, topicName);
|
||||
|
||||
m_dataWriter = DataWriter(ddsPublisher,
|
||||
m_ddsTopic,
|
||||
ddsPublisher.default_datawriter_qos());
|
||||
|
||||
if (m_dataWriter == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Initialisation of "
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< " failed ";
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
catch ( const dds::core::Exception &ex )
|
||||
bool write(const TopicType& data,
|
||||
const dds::core::optional<dds::sub::SampleInfo>& si = dds::core::optional<dds::sub::SampleInfo>())
|
||||
{
|
||||
ERROR_LOG(m_logger) << ex.what();
|
||||
return false;
|
||||
DEBUG_LOG(m_logger) << "IN write (" << DDS::topic_type_name<TopicType>::value() << ") ";
|
||||
|
||||
if (m_dataWriter == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No dataWriter initialised ";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (si.is_set())
|
||||
{
|
||||
rti::pub::WriteParams writeParams;
|
||||
rti::core::SampleIdentity sampleIdentity(si.get()->source_guid(), si.get()->publication_sequence_number());
|
||||
writeParams.related_sample_identity(sampleIdentity);
|
||||
|
||||
m_dataWriter->write(data, writeParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dataWriter.write(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "dataWriter created ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< ")";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool write(const TopicType &data,
|
||||
const dds::core::optional<dds::sub::SampleInfo> &si = dds::core::optional<dds::sub::SampleInfo>())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN write ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< ") ";
|
||||
|
||||
if (m_dataWriter == nullptr) {
|
||||
ERROR_LOG(m_logger) << "No dataWriter initialised ";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (si.is_set())
|
||||
bool remove(const TopicType& data, bool errorMsgIfNotExists = true)
|
||||
{
|
||||
rti::pub::WriteParams writeParams;
|
||||
rti::core::SampleIdentity sampleIdentity(si.get()->source_guid(), si.get()->publication_sequence_number());
|
||||
writeParams.related_sample_identity(sampleIdentity);
|
||||
DEBUG_LOG(m_logger) << "IN remove (" << DDS::topic_type_name<TopicType>::value() << ") ";
|
||||
|
||||
m_dataWriter->write(data, writeParams);
|
||||
} else {
|
||||
m_dataWriter.write(data);
|
||||
if (m_dataWriter == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "No dataWriter initialised ";
|
||||
return false;
|
||||
}
|
||||
const dds::core::InstanceHandle ih = m_dataWriter.lookup_instance(data);
|
||||
if (ih.is_nil())
|
||||
{
|
||||
if (errorMsgIfNotExists)
|
||||
ERROR_LOG(m_logger) << "Could not find instance for topic " << DDS::topic_type_name<TopicType>::value()
|
||||
<< " for unregistering!";
|
||||
return false;
|
||||
}
|
||||
m_dataWriter.dispose_instance(ih);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool remove(const TopicType &data, bool errorMsgIfNotExists = true)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN remove ("
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< ") ";
|
||||
|
||||
if (m_dataWriter == nullptr) {
|
||||
ERROR_LOG(m_logger) << "No dataWriter initialised ";
|
||||
return false;
|
||||
DataWriter dataWriter() const
|
||||
{
|
||||
return m_dataWriter;
|
||||
}
|
||||
const dds::core::InstanceHandle ih = m_dataWriter.lookup_instance(data);
|
||||
if (ih.is_nil()) {
|
||||
if (errorMsgIfNotExists)
|
||||
ERROR_LOG(m_logger) << "Could not find instance for topic "
|
||||
<< DDS::topic_type_name<TopicType>::value()
|
||||
<< " for unregistering!";
|
||||
return false;
|
||||
}
|
||||
m_dataWriter.dispose_instance(ih);
|
||||
return true;
|
||||
}
|
||||
|
||||
DataWriter dataWriter() const { return m_dataWriter; }
|
||||
|
||||
private:
|
||||
DataWriter m_dataWriter;
|
||||
DataTopic m_ddsTopic;
|
||||
private:
|
||||
DataWriter m_dataWriter;
|
||||
DataTopic m_ddsTopic;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace DDSGeneric
|
||||
Executable → Regular
+128
-147
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
|
||||
#include "subscriber_listener.h"
|
||||
|
||||
#include "generic_base.h"
|
||||
#include "generic_logger.h"
|
||||
|
||||
@@ -9,183 +9,164 @@ namespace DDSGeneric
|
||||
{
|
||||
|
||||
SubscriberListener::SubscriberListener()
|
||||
: m_bPrepareForShutdown(false)
|
||||
, m_logger(DDS::getLogger("SubscriberListener", DDS::DataType::DATA_TOPIC_CLIENT))
|
||||
: m_bPrepareForShutdown(false), m_logger(DDS::getLogger("SubscriberListener", DDS::DataType::DATA_TOPIC_CLIENT))
|
||||
{
|
||||
qRegisterMetaType<std::string>("std::string");
|
||||
DEBUG_LOG(m_logger) << "SubscriberListener initialized, this " << this;
|
||||
qRegisterMetaType<std::string>("std::string");
|
||||
DEBUG_LOG(m_logger) << "SubscriberListener initialized, this " << this;
|
||||
}
|
||||
|
||||
void SubscriberListener::addCallback(const std::string &topicName,
|
||||
const std::string &topicTypeName,
|
||||
const dds::sub::AnyDataReader &dataReader,
|
||||
SubscriberListenerCallback *cb)
|
||||
void SubscriberListener::addCallback(const std::string& topicName, const std::string& topicTypeName,
|
||||
const dds::sub::AnyDataReader& dataReader, SubscriberListenerCallback* cb)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "addSubscriberCallback for " << topicName << ", type " << topicTypeName
|
||||
<< ", cb " << cb << ", this " << this;
|
||||
QWriteLocker l(&m_accessLock);
|
||||
if (m_bPrepareForShutdown)
|
||||
return;
|
||||
m_droCallbacks.insertMulti(std::make_pair(topicName, topicTypeName), fillData(dataReader, cb));
|
||||
}
|
||||
|
||||
void SubscriberListener::removeCallback(const std::string &topicName,
|
||||
const std::string &topicTypeName,
|
||||
const dds::sub::AnyDataReader &dataReader,
|
||||
SubscriberListenerCallback *cb)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN removeSubscriberCallback for " << topicName << ", type " << topicTypeName
|
||||
<< ", cb " << cb << ", this " << this;
|
||||
QWriteLocker l(&m_accessLock);
|
||||
m_droCallbacks.remove(std::make_pair(topicName, topicTypeName), fillData(dataReader, cb));
|
||||
}
|
||||
|
||||
void SubscriberListener::enaDisaCallback(const std::string &topicName,
|
||||
const std::string &topicTypeName,
|
||||
const dds::sub::AnyDataReader &dataReader,
|
||||
SubscriberListenerCallback *cb,
|
||||
bool bEnable)
|
||||
{
|
||||
const std::pair<std::string, std::string> key(std::make_pair(topicName, topicTypeName));
|
||||
const cbData cbDataSearch(fillData(dataReader, cb));
|
||||
bool bFound = false;
|
||||
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "addSubscriberCallback for " << topicName << ", type " << topicTypeName << ", cb " << cb
|
||||
<< ", this " << this;
|
||||
QWriteLocker l(&m_accessLock);
|
||||
if (m_bPrepareForShutdown)
|
||||
return;
|
||||
return;
|
||||
m_droCallbacks.insertMulti(std::make_pair(topicName, topicTypeName), fillData(dataReader, cb));
|
||||
}
|
||||
|
||||
void SubscriberListener::removeCallback(const std::string& topicName, const std::string& topicTypeName,
|
||||
const dds::sub::AnyDataReader& dataReader, SubscriberListenerCallback* cb)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "IN removeSubscriberCallback for " << topicName << ", type " << topicTypeName << ", cb "
|
||||
<< cb << ", this " << this;
|
||||
QWriteLocker l(&m_accessLock);
|
||||
m_droCallbacks.remove(std::make_pair(topicName, topicTypeName), fillData(dataReader, cb));
|
||||
}
|
||||
|
||||
void SubscriberListener::enaDisaCallback(const std::string& topicName, const std::string& topicTypeName,
|
||||
const dds::sub::AnyDataReader& dataReader, SubscriberListenerCallback* cb,
|
||||
bool bEnable)
|
||||
{
|
||||
const std::pair<std::string, std::string> key(std::make_pair(topicName, topicTypeName));
|
||||
const cbData cbDataSearch(fillData(dataReader, cb));
|
||||
bool bFound = false;
|
||||
|
||||
QMultiMap<std::pair<std::string, std::string>, cbData>::iterator cbIt = m_droCallbacks.find(key);
|
||||
for( ; cbIt != m_droCallbacks.end() && cbIt.key() == key; ++cbIt)
|
||||
{
|
||||
const cbData &data = cbIt.value();
|
||||
if (data != cbDataSearch)
|
||||
continue;
|
||||
bFound = true;
|
||||
cbIt.value().enabled = bEnable;
|
||||
break;
|
||||
}
|
||||
}
|
||||
QWriteLocker l(&m_accessLock);
|
||||
if (m_bPrepareForShutdown)
|
||||
return;
|
||||
|
||||
if (!bFound)
|
||||
WARNING_LOG(m_logger) << "Can not " << (bEnable ? "enable" : "disable")
|
||||
<< " callback for " << topicName << ", type " << topicTypeName
|
||||
<< ", cb " << cb << ", this " << this << " - not found!";
|
||||
QMultiMap<std::pair<std::string, std::string>, cbData>::iterator cbIt = m_droCallbacks.find(key);
|
||||
for (; cbIt != m_droCallbacks.end() && cbIt.key() == key; ++cbIt)
|
||||
{
|
||||
const cbData& data = cbIt.value();
|
||||
if (data != cbDataSearch)
|
||||
continue;
|
||||
bFound = true;
|
||||
cbIt.value().enabled = bEnable;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bFound)
|
||||
WARNING_LOG(m_logger) << "Can not " << (bEnable ? "enable" : "disable") << " callback for " << topicName
|
||||
<< ", type " << topicTypeName << ", cb " << cb << ", this " << this << " - not found!";
|
||||
}
|
||||
|
||||
void SubscriberListener::prepareShutdown()
|
||||
{
|
||||
QWriteLocker l(&m_accessLock);
|
||||
m_droCallbacks.clear();
|
||||
m_bPrepareForShutdown = true;
|
||||
QWriteLocker l(&m_accessLock);
|
||||
m_droCallbacks.clear();
|
||||
m_bPrepareForShutdown = true;
|
||||
}
|
||||
|
||||
|
||||
void SubscriberListener::on_data_available(dds::sub::AnyDataReader &reader)
|
||||
void SubscriberListener::on_data_available(dds::sub::AnyDataReader& reader)
|
||||
{
|
||||
|
||||
const std::string &topicName = reader.topic_name();
|
||||
const std::string &topicTypeName = reader.type_name();
|
||||
const std::pair<std::string, std::string> key(std::make_pair(topicName, topicTypeName));
|
||||
|
||||
QReadLocker l(&m_accessLock);
|
||||
if (m_droCallbacks.isEmpty() || m_bPrepareForShutdown)
|
||||
return;
|
||||
DEBUG_LOG(m_logger) << "Data available for " << topicName << ", type " << topicTypeName << ", this " << this;
|
||||
QMultiMap<std::pair<std::string, std::string>, cbData>::iterator cbIt = m_droCallbacks.find(key);
|
||||
const QMultiMap<std::pair<std::string, std::string>, cbData>::iterator cbEnd = m_droCallbacks.end();
|
||||
for( ; cbIt != cbEnd && cbIt.key() == key; ++cbIt)
|
||||
{
|
||||
const cbData &data = cbIt.value();
|
||||
if (data.dataReader != reader)
|
||||
continue;
|
||||
const std::string& topicName = reader.topic_name();
|
||||
const std::string& topicTypeName = reader.type_name();
|
||||
const std::pair<std::string, std::string> key(std::make_pair(topicName, topicTypeName));
|
||||
|
||||
if (!data.enabled)
|
||||
continue;
|
||||
|
||||
if (data.methodToCall.isValid())
|
||||
QReadLocker l(&m_accessLock);
|
||||
if (m_droCallbacks.isEmpty() || m_bPrepareForShutdown)
|
||||
return;
|
||||
DEBUG_LOG(m_logger) << "Data available for " << topicName << ", type " << topicTypeName << ", this " << this;
|
||||
QMultiMap<std::pair<std::string, std::string>, cbData>::iterator cbIt = m_droCallbacks.find(key);
|
||||
const QMultiMap<std::pair<std::string, std::string>, cbData>::iterator cbEnd = m_droCallbacks.end();
|
||||
for (; cbIt != cbEnd && cbIt.key() == key; ++cbIt)
|
||||
{
|
||||
data.methodToCall.invoke(data.cb, Qt::QueuedConnection,
|
||||
Q_ARG(std::string, topicTypeName),
|
||||
Q_ARG(std::string, topicName));
|
||||
cbIt.value().enabled = false;
|
||||
const cbData& data = cbIt.value();
|
||||
if (data.dataReader != reader)
|
||||
continue;
|
||||
|
||||
if (!data.enabled)
|
||||
continue;
|
||||
|
||||
if (data.methodToCall.isValid())
|
||||
{
|
||||
data.methodToCall.invoke(data.cb, Qt::QueuedConnection, Q_ARG(std::string, topicTypeName),
|
||||
Q_ARG(std::string, topicName));
|
||||
cbIt.value().enabled = false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SubscriberListener::on_liveliness_changed(dds::sub::AnyDataReader &reader,
|
||||
const dds::core::status::LivelinessChangedStatus &livelinessStatus)
|
||||
void SubscriberListener::on_liveliness_changed(dds::sub::AnyDataReader& reader,
|
||||
const dds::core::status::LivelinessChangedStatus& livelinessStatus)
|
||||
{
|
||||
const std::string &topicName = reader.topic_name();
|
||||
const std::string &topicTypeName = reader.type_name();
|
||||
|
||||
DEBUG_LOG(m_logger) << "on_liveliness_changed: " << livelinessStatus.alive_count()
|
||||
<< ", " << livelinessStatus.not_alive_count()
|
||||
<< ", " << livelinessStatus.alive_count_change()
|
||||
<< ", " << livelinessStatus.not_alive_count_change()
|
||||
<< " for type " << topicTypeName;
|
||||
const std::string& topicName = reader.topic_name();
|
||||
const std::string& topicTypeName = reader.type_name();
|
||||
|
||||
bool bNewWriters = false;
|
||||
bool bNoWritersAnymore = false;
|
||||
if (livelinessStatus.alive_count() == 0 &&
|
||||
livelinessStatus.alive_count_change() < 0)
|
||||
bNoWritersAnymore = true;
|
||||
if (livelinessStatus.alive_count() != 0 &&
|
||||
livelinessStatus.alive_count_change() == livelinessStatus.alive_count())
|
||||
bNewWriters = true;
|
||||
if (!bNewWriters && !bNoWritersAnymore)
|
||||
return;
|
||||
DEBUG_LOG(m_logger) << "on_liveliness_changed: " << livelinessStatus.alive_count() << ", "
|
||||
<< livelinessStatus.not_alive_count() << ", " << livelinessStatus.alive_count_change() << ", "
|
||||
<< livelinessStatus.not_alive_count_change() << " for type " << topicTypeName;
|
||||
|
||||
QReadLocker l(&m_accessLock);
|
||||
if (m_droCallbacks.isEmpty())
|
||||
return;
|
||||
bool bNewWriters = false;
|
||||
bool bNoWritersAnymore = false;
|
||||
if (livelinessStatus.alive_count() == 0 && livelinessStatus.alive_count_change() < 0)
|
||||
bNoWritersAnymore = true;
|
||||
if (livelinessStatus.alive_count() != 0 && livelinessStatus.alive_count_change() == livelinessStatus.alive_count())
|
||||
bNewWriters = true;
|
||||
if (!bNewWriters && !bNoWritersAnymore)
|
||||
return;
|
||||
|
||||
const std::pair<std::string, std::string> key(std::make_pair(topicName, topicTypeName));
|
||||
QMultiMap<std::pair<std::string, std::string>, cbData>::iterator cbIt = m_droCallbacks.find(key);
|
||||
const QMultiMap<std::pair<std::string, std::string>, cbData>::iterator cbEnd = m_droCallbacks.end();
|
||||
for( ; cbIt != cbEnd && cbIt.key() == key; ++cbIt)
|
||||
{
|
||||
const cbData &data = cbIt.value();
|
||||
if (data.dataReader != reader)
|
||||
continue;
|
||||
QReadLocker l(&m_accessLock);
|
||||
if (m_droCallbacks.isEmpty())
|
||||
return;
|
||||
|
||||
if (bNoWritersAnymore)
|
||||
const std::pair<std::string, std::string> key(std::make_pair(topicName, topicTypeName));
|
||||
QMultiMap<std::pair<std::string, std::string>, cbData>::iterator cbIt = m_droCallbacks.find(key);
|
||||
const QMultiMap<std::pair<std::string, std::string>, cbData>::iterator cbEnd = m_droCallbacks.end();
|
||||
for (; cbIt != cbEnd && cbIt.key() == key; ++cbIt)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "bNoWritersAnymore for " << topicName << ", type " << topicTypeName;
|
||||
data.cb->noWriterAnymore(topicTypeName, topicName);
|
||||
const cbData& data = cbIt.value();
|
||||
if (data.dataReader != reader)
|
||||
continue;
|
||||
|
||||
if (bNoWritersAnymore)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "bNoWritersAnymore for " << topicName << ", type " << topicTypeName;
|
||||
data.cb->noWriterAnymore(topicTypeName, topicName);
|
||||
}
|
||||
else if (bNewWriters)
|
||||
{
|
||||
data.cb->writerAvailable(topicTypeName, topicName);
|
||||
if (!data.enabled)
|
||||
continue;
|
||||
if (data.methodToCall.isValid())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "methodcall is valid for " << topicName << ", type " << topicTypeName;
|
||||
data.methodToCall.invoke(data.cb, Qt::QueuedConnection, Q_ARG(std::string, topicTypeName),
|
||||
Q_ARG(std::string, topicName));
|
||||
cbIt.value().enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (bNewWriters)
|
||||
{
|
||||
data.cb->writerAvailable(topicTypeName, topicName);
|
||||
if (!data.enabled)
|
||||
continue;
|
||||
if (data.methodToCall.isValid())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "methodcall is valid for " << topicName << ", type " << topicTypeName;
|
||||
data.methodToCall.invoke(data.cb, Qt::QueuedConnection,
|
||||
Q_ARG(std::string, topicTypeName),
|
||||
Q_ARG(std::string, topicName));
|
||||
cbIt.value().enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SubscriberListener::cbData SubscriberListener::fillData(const dds::sub::AnyDataReader &dataReader, SubscriberListenerCallback *cb) const
|
||||
SubscriberListener::cbData SubscriberListener::fillData(const dds::sub::AnyDataReader& dataReader,
|
||||
SubscriberListenerCallback* cb) const
|
||||
{
|
||||
|
||||
const char *signal = SIGNAL(droDataAvailable(std::string,std::string));
|
||||
const char *slot = SLOT(droDataAvailable(std::string,std::string));
|
||||
QMetaMethod method = DDS::Helper::getMethod(m_logger,
|
||||
cb,
|
||||
slot,
|
||||
signal);
|
||||
|
||||
|
||||
return cbData(cb, dataReader, method);
|
||||
|
||||
const char* signal = SIGNAL(droDataAvailable(std::string, std::string));
|
||||
const char* slot = SLOT(droDataAvailable(std::string, std::string));
|
||||
QMetaMethod method = DDS::Helper::getMethod(m_logger, cb, slot, signal);
|
||||
|
||||
return cbData(cb, dataReader, method);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace DDSGeneric
|
||||
Executable → Regular
+113
-115
@@ -1,140 +1,138 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ddsgen_export.h>
|
||||
#include <dds/sub/SubscriberListener.hpp>
|
||||
#include <dds/sub/AnyDataReader.hpp>
|
||||
#include <dds/topic/Topic.hpp>
|
||||
#include <QMetaMethod>
|
||||
#include <QReadWriteLock>
|
||||
#include <QObject>
|
||||
#include <QReadWriteLock>
|
||||
#include <dds/sub/AnyDataReader.hpp>
|
||||
#include <dds/sub/SubscriberListener.hpp>
|
||||
#include <dds/topic/Topic.hpp>
|
||||
#include <ddsgen_export.h>
|
||||
|
||||
namespace NGL {
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace DDSGeneric
|
||||
{
|
||||
class DDSGEN_EXPORT SubscriberListenerCallback : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~SubscriberListenerCallback() = default;
|
||||
public Q_SLOTS:
|
||||
|
||||
virtual void droDataAvailable(const std::string &topicType, const std::string &topicName) = 0;
|
||||
|
||||
virtual void noWriterAnymore(const std::string &topicType, const std::string &topicName) = 0;
|
||||
virtual void writerAvailable(const std::string &topicType, const std::string &topicName) = 0;
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~SubscriberListenerCallback() = default;
|
||||
public Q_SLOTS:
|
||||
|
||||
virtual void droDataAvailable(const std::string& topicType, const std::string& topicName) = 0;
|
||||
|
||||
virtual void noWriterAnymore(const std::string& topicType, const std::string& topicName) = 0;
|
||||
virtual void writerAvailable(const std::string& topicType, const std::string& topicName) = 0;
|
||||
};
|
||||
|
||||
class DDSGEN_EXPORT SubscriberListener final : public dds::sub::SubscriberListener
|
||||
{
|
||||
public:
|
||||
SubscriberListener();
|
||||
public:
|
||||
SubscriberListener();
|
||||
|
||||
template<typename TopicType>
|
||||
void addCallback(const dds::sub::DataReader<TopicType> &dataReader,
|
||||
SubscriberListenerCallback *cb)
|
||||
{
|
||||
addCallback(dataReader->topic_name(), dataReader->type_name(), dds::sub::AnyDataReader(dataReader), cb);
|
||||
}
|
||||
template<typename TopicType>
|
||||
void removeCallback(const dds::sub::DataReader<TopicType> &dataReader,
|
||||
SubscriberListenerCallback *cb)
|
||||
{
|
||||
removeCallback(dataReader->topic_name(), dataReader->type_name(), dds::sub::AnyDataReader(dataReader), cb);
|
||||
}
|
||||
|
||||
template<typename TopicType>
|
||||
void enableCallback(const dds::sub::DataReader<TopicType> &dataReader,
|
||||
SubscriberListenerCallback *cb)
|
||||
{
|
||||
enaDisaCallback(dataReader->topic_name(), dataReader->type_name(), dds::sub::AnyDataReader(dataReader), cb, true);
|
||||
}
|
||||
template<typename TopicType>
|
||||
void disableCallback(const dds::sub::DataReader<TopicType> &dataReader,
|
||||
SubscriberListenerCallback *cb)
|
||||
{
|
||||
enaDisaCallback(dataReader->topic_name(), dataReader->type_name(), dds::sub::AnyDataReader(dataReader), cb, false);
|
||||
}
|
||||
|
||||
static dds::core::status::StatusMask mask()
|
||||
{
|
||||
return (dds::core::status::StatusMask::liveliness_changed() | dds::core::status::StatusMask::data_available());
|
||||
}
|
||||
|
||||
void prepareShutdown();
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger &m_logger;
|
||||
void addCallback(const std::string &topicName,
|
||||
const std::string &topicTypeName,
|
||||
const dds::sub::AnyDataReader &dataReader,
|
||||
SubscriberListenerCallback *cb);
|
||||
void removeCallback(const std::string &topicName,
|
||||
const std::string &topicTypeName,
|
||||
const dds::sub::AnyDataReader &dataReader,
|
||||
SubscriberListenerCallback *cb);
|
||||
void enaDisaCallback(const std::string &topicName,
|
||||
const std::string &topicTypeName,
|
||||
const dds::sub::AnyDataReader &dataReader,
|
||||
SubscriberListenerCallback *cb,
|
||||
bool bEnable);
|
||||
|
||||
void on_data_on_readers(dds::sub::Subscriber &) override {}
|
||||
|
||||
void on_liveliness_changed(dds::sub::AnyDataReader &reader,
|
||||
const dds::core::status::LivelinessChangedStatus &livelinessStatus) override;
|
||||
|
||||
void on_requested_deadline_missed(dds::sub::AnyDataReader&,
|
||||
const dds::core::status::RequestedDeadlineMissedStatus&) override {}
|
||||
void on_requested_incompatible_qos(dds::sub::AnyDataReader&,
|
||||
const dds::core::status::RequestedIncompatibleQosStatus&) override {}
|
||||
void on_sample_rejected(dds::sub::AnyDataReader&,
|
||||
const dds::core::status::SampleRejectedStatus&) override {}
|
||||
void on_data_available(dds::sub::AnyDataReader &reader) override;
|
||||
void on_subscription_matched(dds::sub::AnyDataReader&,
|
||||
const dds::core::status::SubscriptionMatchedStatus&) override {}
|
||||
void on_sample_lost(dds::sub::AnyDataReader&,
|
||||
const dds::core::status::SampleLostStatus&) override {}
|
||||
|
||||
private:
|
||||
struct cbData
|
||||
{
|
||||
SubscriberListenerCallback *cb = nullptr;
|
||||
bool enabled = true;
|
||||
dds::sub::AnyDataReader dataReader;
|
||||
QMetaMethod methodToCall;
|
||||
|
||||
bool operator ==(const cbData &o) const
|
||||
template <typename TopicType>
|
||||
void addCallback(const dds::sub::DataReader<TopicType>& dataReader, SubscriberListenerCallback* cb)
|
||||
{
|
||||
|
||||
return cb == o.cb && methodToCall == o.methodToCall && dataReader == o.dataReader;
|
||||
}
|
||||
bool operator !=(const cbData &o) const
|
||||
{
|
||||
return !operator ==(o);
|
||||
addCallback(dataReader->topic_name(), dataReader->type_name(), dds::sub::AnyDataReader(dataReader), cb);
|
||||
}
|
||||
|
||||
cbData(SubscriberListenerCallback *cb_,
|
||||
const dds::sub::AnyDataReader &dataReader_,
|
||||
const QMetaMethod &methodToCall_)
|
||||
: cb(cb_)
|
||||
, enabled(true)
|
||||
, dataReader(dataReader_)
|
||||
, methodToCall(methodToCall_)
|
||||
{}
|
||||
};
|
||||
cbData fillData(const dds::sub::AnyDataReader &dataReader, SubscriberListenerCallback *cb) const;
|
||||
template <typename TopicType>
|
||||
void removeCallback(const dds::sub::DataReader<TopicType>& dataReader, SubscriberListenerCallback* cb)
|
||||
{
|
||||
removeCallback(dataReader->topic_name(), dataReader->type_name(), dds::sub::AnyDataReader(dataReader), cb);
|
||||
}
|
||||
|
||||
QMultiMap<std::pair<std::string, std::string>, cbData> m_droCallbacks;
|
||||
QReadWriteLock m_accessLock;
|
||||
bool m_bPrepareForShutdown;
|
||||
template <typename TopicType>
|
||||
void enableCallback(const dds::sub::DataReader<TopicType>& dataReader, SubscriberListenerCallback* cb)
|
||||
{
|
||||
enaDisaCallback(dataReader->topic_name(), dataReader->type_name(), dds::sub::AnyDataReader(dataReader), cb,
|
||||
true);
|
||||
}
|
||||
|
||||
template <typename TopicType>
|
||||
void disableCallback(const dds::sub::DataReader<TopicType>& dataReader, SubscriberListenerCallback* cb)
|
||||
{
|
||||
enaDisaCallback(dataReader->topic_name(), dataReader->type_name(), dds::sub::AnyDataReader(dataReader), cb,
|
||||
false);
|
||||
}
|
||||
|
||||
static dds::core::status::StatusMask mask()
|
||||
{
|
||||
return (dds::core::status::StatusMask::liveliness_changed() | dds::core::status::StatusMask::data_available());
|
||||
}
|
||||
|
||||
void prepareShutdown();
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void addCallback(const std::string& topicName, const std::string& topicTypeName,
|
||||
const dds::sub::AnyDataReader& dataReader, SubscriberListenerCallback* cb);
|
||||
void removeCallback(const std::string& topicName, const std::string& topicTypeName,
|
||||
const dds::sub::AnyDataReader& dataReader, SubscriberListenerCallback* cb);
|
||||
void enaDisaCallback(const std::string& topicName, const std::string& topicTypeName,
|
||||
const dds::sub::AnyDataReader& dataReader, SubscriberListenerCallback* cb, bool bEnable);
|
||||
|
||||
void on_data_on_readers(dds::sub::Subscriber&) override {}
|
||||
|
||||
void on_liveliness_changed(dds::sub::AnyDataReader& reader,
|
||||
const dds::core::status::LivelinessChangedStatus& livelinessStatus) override;
|
||||
|
||||
void on_requested_deadline_missed(dds::sub::AnyDataReader&,
|
||||
const dds::core::status::RequestedDeadlineMissedStatus&) override
|
||||
{
|
||||
}
|
||||
|
||||
void on_requested_incompatible_qos(dds::sub::AnyDataReader&,
|
||||
const dds::core::status::RequestedIncompatibleQosStatus&) override
|
||||
{
|
||||
}
|
||||
|
||||
void on_sample_rejected(dds::sub::AnyDataReader&, const dds::core::status::SampleRejectedStatus&) override {}
|
||||
|
||||
void on_data_available(dds::sub::AnyDataReader& reader) override;
|
||||
|
||||
void on_subscription_matched(dds::sub::AnyDataReader&, const dds::core::status::SubscriptionMatchedStatus&) override
|
||||
{
|
||||
}
|
||||
|
||||
void on_sample_lost(dds::sub::AnyDataReader&, const dds::core::status::SampleLostStatus&) override {}
|
||||
|
||||
private:
|
||||
struct cbData
|
||||
{
|
||||
SubscriberListenerCallback* cb = nullptr;
|
||||
bool enabled = true;
|
||||
dds::sub::AnyDataReader dataReader;
|
||||
QMetaMethod methodToCall;
|
||||
|
||||
bool operator==(const cbData& o) const
|
||||
{
|
||||
|
||||
return cb == o.cb && methodToCall == o.methodToCall && dataReader == o.dataReader;
|
||||
}
|
||||
|
||||
bool operator!=(const cbData& o) const
|
||||
{
|
||||
return !operator==(o);
|
||||
}
|
||||
|
||||
cbData(SubscriberListenerCallback* cb_, const dds::sub::AnyDataReader& dataReader_,
|
||||
const QMetaMethod& methodToCall_)
|
||||
: cb(cb_), enabled(true), dataReader(dataReader_), methodToCall(methodToCall_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
cbData fillData(const dds::sub::AnyDataReader& dataReader, SubscriberListenerCallback* cb) const;
|
||||
|
||||
QMultiMap<std::pair<std::string, std::string>, cbData> m_droCallbacks;
|
||||
QReadWriteLock m_accessLock;
|
||||
bool m_bPrepareForShutdown;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace DDSGeneric
|
||||
Executable → Regular
+103
-106
@@ -1,147 +1,144 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include "wait_set_handler.h"
|
||||
#include "generic_logger.h"
|
||||
|
||||
#include "generic_base.h"
|
||||
#include "generic_logger.h"
|
||||
|
||||
namespace DDSGeneric
|
||||
{
|
||||
|
||||
WaitSetHandler::WaitSetHandler()
|
||||
: m_logger(DDS::getLogger("WaitSetHandler", DDS::DataType::FUNCTION_TOPIC_SERVER))
|
||||
WaitSetHandler::WaitSetHandler() : m_logger(DDS::getLogger("WaitSetHandler", DDS::DataType::FUNCTION_TOPIC_SERVER))
|
||||
{
|
||||
m_waitSet.attach_condition(m_abortCondition);
|
||||
m_task = std::async(std::launch::async, [this]() { this->waitSetTask();});
|
||||
m_waitSet.attach_condition(m_abortCondition);
|
||||
m_task = std::async(std::launch::async, [this]() { this->waitSetTask(); });
|
||||
}
|
||||
|
||||
WaitSetHandler::~WaitSetHandler()
|
||||
{
|
||||
m_abortCondition.trigger_value(true);
|
||||
m_task.wait();
|
||||
m_abortCondition.trigger_value(true);
|
||||
m_task.wait();
|
||||
}
|
||||
|
||||
bool WaitSetHandler::attachWaitSet(const dds::core::cond::Condition &cond, CallbackInterface *cb)
|
||||
bool WaitSetHandler::attachWaitSet(const dds::core::cond::Condition& cond, CallbackInterface* cb)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "AttachWaitSet with callback " << cb;
|
||||
DEBUG_LOG(m_logger) << "AttachWaitSet with callback " << cb;
|
||||
|
||||
WaitSetData wsd(cond, cb);
|
||||
WaitSetData wsd(cond, cb);
|
||||
|
||||
std::lock_guard<std::mutex> l(m_accessMutex);
|
||||
|
||||
auto it = m_waitSetData.find(wsd.condition->native_condition());
|
||||
if (it != m_waitSetData.end())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Waitset " << cb << " already registered";
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::mutex> l(m_accessMutex);
|
||||
|
||||
m_waitSet.attach_condition(wsd.condition);
|
||||
wsd.enabled = true;
|
||||
wsd.needWaitSetAttach = false;
|
||||
auto it = m_waitSetData.find(wsd.condition->native_condition());
|
||||
if (it != m_waitSetData.end())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Waitset " << cb << " already registered";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_waitSetData.insert(std::make_pair(wsd.condition->native_condition(), wsd));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WaitSetHandler::detachWaitSet(const dds::core::cond::Condition &cond, CallbackInterface *cb)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "DetachWaitSet with callback " << cb;
|
||||
|
||||
WaitSetData wsd(cond, cb);
|
||||
|
||||
std::lock_guard<std::mutex> l(m_accessMutex);
|
||||
|
||||
auto it = m_waitSetData.find(wsd.condition->native_condition());
|
||||
if (it == m_waitSetData.end())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Waitset for " << cb << " not registered";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_waitSet.detach_condition(wsd.condition);
|
||||
m_waitSetData.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WaitSetHandler::enableWaitSet(const dds::core::cond::Condition &cond, CallbackInterface *cb)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "EnableWaitSet with callback " << cb;
|
||||
|
||||
WaitSetData wsd(cond, cb);
|
||||
|
||||
std::lock_guard<std::mutex> l(m_accessMutex);
|
||||
auto it = m_waitSetData.find(wsd.condition->native_condition());
|
||||
if (it == m_waitSetData.end())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not find WaitSetData - cannot enable waitSet for " << cb;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (it->second.needWaitSetAttach)
|
||||
m_waitSet.attach_condition(wsd.condition);
|
||||
it->second.enabled = true;
|
||||
it->second.needWaitSetAttach = false;
|
||||
return true;
|
||||
wsd.enabled = true;
|
||||
wsd.needWaitSetAttach = false;
|
||||
|
||||
m_waitSetData.insert(std::make_pair(wsd.condition->native_condition(), wsd));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WaitSetHandler::disableWaitSet(const dds::core::cond::Condition &cond, CallbackInterface *cb)
|
||||
bool WaitSetHandler::detachWaitSet(const dds::core::cond::Condition& cond, CallbackInterface* cb)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "DisableWaitSet with callback " << cb;
|
||||
DEBUG_LOG(m_logger) << "DetachWaitSet with callback " << cb;
|
||||
|
||||
WaitSetData wsd(cond, cb);
|
||||
WaitSetData wsd(cond, cb);
|
||||
|
||||
std::lock_guard<std::mutex> l(m_accessMutex);
|
||||
auto it = m_waitSetData.find(wsd.condition->native_condition());
|
||||
if (it == m_waitSetData.end())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not find WaitSetData - cannot disable waitSet for " << cb;
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::mutex> l(m_accessMutex);
|
||||
|
||||
m_waitSet.detach_condition(wsd.condition);
|
||||
it->second.enabled = false;
|
||||
it->second.needWaitSetAttach = true;
|
||||
return true;
|
||||
auto it = m_waitSetData.find(wsd.condition->native_condition());
|
||||
if (it == m_waitSetData.end())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Waitset for " << cb << " not registered";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_waitSet.detach_condition(wsd.condition);
|
||||
m_waitSetData.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WaitSetHandler::enableWaitSet(const dds::core::cond::Condition& cond, CallbackInterface* cb)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "EnableWaitSet with callback " << cb;
|
||||
|
||||
WaitSetData wsd(cond, cb);
|
||||
|
||||
std::lock_guard<std::mutex> l(m_accessMutex);
|
||||
auto it = m_waitSetData.find(wsd.condition->native_condition());
|
||||
if (it == m_waitSetData.end())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not find WaitSetData - cannot enable waitSet for " << cb;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (it->second.needWaitSetAttach)
|
||||
m_waitSet.attach_condition(wsd.condition);
|
||||
it->second.enabled = true;
|
||||
it->second.needWaitSetAttach = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WaitSetHandler::disableWaitSet(const dds::core::cond::Condition& cond, CallbackInterface* cb)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "DisableWaitSet with callback " << cb;
|
||||
|
||||
WaitSetData wsd(cond, cb);
|
||||
|
||||
std::lock_guard<std::mutex> l(m_accessMutex);
|
||||
auto it = m_waitSetData.find(wsd.condition->native_condition());
|
||||
if (it == m_waitSetData.end())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not find WaitSetData - cannot disable waitSet for " << cb;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_waitSet.detach_condition(wsd.condition);
|
||||
it->second.enabled = false;
|
||||
it->second.needWaitSetAttach = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
int WaitSetHandler::attachedConditionCount() const
|
||||
{
|
||||
return m_waitSet.conditions().size();
|
||||
return m_waitSet.conditions().size();
|
||||
}
|
||||
|
||||
|
||||
void WaitSetHandler::waitSetTask()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
dds::core::cond::WaitSet::ConditionSeq activeConditionsSeq = m_waitSet.wait();
|
||||
for (const dds::core::cond::Condition &cond : activeConditionsSeq)
|
||||
while (true)
|
||||
{
|
||||
if (cond == m_abortCondition)
|
||||
{
|
||||
m_waitSet->detach_all();
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> l(m_accessMutex);
|
||||
const DDS_Condition *ddsCond = cond->native_condition();
|
||||
auto it = m_waitSetData.lower_bound(ddsCond);
|
||||
while (it != m_waitSetData.end())
|
||||
{
|
||||
WaitSetData &wsd = it->second;
|
||||
if (wsd.enabled)
|
||||
dds::core::cond::WaitSet::ConditionSeq activeConditionsSeq = m_waitSet.wait();
|
||||
for (const dds::core::cond::Condition& cond : activeConditionsSeq)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Condition triggered for " << wsd.callback;
|
||||
wsd.callback->dataAvailable();
|
||||
if (cond == m_abortCondition)
|
||||
{
|
||||
m_waitSet->detach_all();
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> l(m_accessMutex);
|
||||
const DDS_Condition* ddsCond = cond->native_condition();
|
||||
auto it = m_waitSetData.lower_bound(ddsCond);
|
||||
while (it != m_waitSetData.end())
|
||||
{
|
||||
WaitSetData& wsd = it->second;
|
||||
if (wsd.enabled)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Condition triggered for " << wsd.callback;
|
||||
wsd.callback->dataAvailable();
|
||||
}
|
||||
++it;
|
||||
if (it == m_waitSetData.end() || it->first != ddsCond)
|
||||
break;
|
||||
}
|
||||
}
|
||||
++it;
|
||||
if (it == m_waitSetData.end() || it->first != ddsCond)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace DDSGeneric
|
||||
Executable → Regular
+37
-40
@@ -1,15 +1,13 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dds/core/cond/Condition.hpp>
|
||||
#include <dds/core/cond/GuardCondition.hpp>
|
||||
#include <dds/core/cond/WaitSet.hpp>
|
||||
|
||||
#include <ddsgen_export.h>
|
||||
#include <future>
|
||||
#include <map>
|
||||
#include <ddsgen_export.h>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
@@ -20,48 +18,47 @@ namespace DDSGeneric
|
||||
{
|
||||
class DDSGEN_EXPORT WaitSetHandler final
|
||||
{
|
||||
public:
|
||||
class CallbackInterface
|
||||
{
|
||||
public:
|
||||
virtual ~CallbackInterface() = default;
|
||||
virtual void dataAvailable() = 0;
|
||||
};
|
||||
class CallbackInterface
|
||||
{
|
||||
public:
|
||||
virtual ~CallbackInterface() = default;
|
||||
virtual void dataAvailable() = 0;
|
||||
};
|
||||
|
||||
WaitSetHandler();
|
||||
~WaitSetHandler();
|
||||
WaitSetHandler();
|
||||
~WaitSetHandler();
|
||||
|
||||
bool attachWaitSet(const dds::core::cond::Condition &cond, CallbackInterface *cb);
|
||||
bool detachWaitSet(const dds::core::cond::Condition &cond, CallbackInterface *cb);
|
||||
bool enableWaitSet(const dds::core::cond::Condition &cond, CallbackInterface *cb);
|
||||
bool disableWaitSet(const dds::core::cond::Condition &cond, CallbackInterface *cb);
|
||||
bool attachWaitSet(const dds::core::cond::Condition& cond, CallbackInterface* cb);
|
||||
bool detachWaitSet(const dds::core::cond::Condition& cond, CallbackInterface* cb);
|
||||
bool enableWaitSet(const dds::core::cond::Condition& cond, CallbackInterface* cb);
|
||||
bool disableWaitSet(const dds::core::cond::Condition& cond, CallbackInterface* cb);
|
||||
|
||||
int attachedConditionCount() const;
|
||||
int attachedConditionCount() const;
|
||||
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
struct WaitSetData final
|
||||
{
|
||||
dds::core::cond::Condition condition;
|
||||
CallbackInterface *callback = nullptr;
|
||||
bool enabled = true;
|
||||
bool needWaitSetAttach = false;
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
|
||||
WaitSetData(const dds::core::cond::Condition &cond, CallbackInterface *cb)
|
||||
: condition(cond)
|
||||
, callback(cb)
|
||||
{}
|
||||
};
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
void waitSetTask();
|
||||
private:
|
||||
struct WaitSetData final
|
||||
{
|
||||
dds::core::cond::Condition condition;
|
||||
CallbackInterface* callback = nullptr;
|
||||
bool enabled = true;
|
||||
bool needWaitSetAttach = false;
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
dds::core::cond::WaitSet m_waitSet;
|
||||
dds::core::cond::GuardCondition m_abortCondition;
|
||||
std::future<void> m_task;
|
||||
std::mutex m_accessMutex;
|
||||
std::map<const DDS_Condition *, WaitSetData> m_waitSetData;
|
||||
WaitSetData(const dds::core::cond::Condition& cond, CallbackInterface* cb) : condition(cond), callback(cb) {}
|
||||
};
|
||||
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void waitSetTask();
|
||||
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
dds::core::cond::WaitSet m_waitSet;
|
||||
dds::core::cond::GuardCondition m_abortCondition;
|
||||
std::future<void> m_task;
|
||||
std::mutex m_accessMutex;
|
||||
std::map<const DDS_Condition*, WaitSetData> m_waitSetData;
|
||||
};
|
||||
}
|
||||
} // namespace DDSGeneric
|
||||
Executable → Regular
+270
-297
@@ -1,362 +1,335 @@
|
||||
|
||||
|
||||
|
||||
#include <dds/pub/DataWriter.hpp>
|
||||
#include <dds/pub/discovery.hpp>
|
||||
#include <dds/sub/DataReader.hpp>
|
||||
#include <dds/sub/DataReaderListener.hpp>
|
||||
#include <dds/topic/find.hpp>
|
||||
#include <dds/topic/Topic.hpp>
|
||||
|
||||
#include <DDS/Generic/generic_base.h>
|
||||
#include <DDS/QosProfile/DDS_DefaultQos.h>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#include <dds/pub/DataWriter.hpp>
|
||||
#include <dds/pub/discovery.hpp>
|
||||
#include <dds/sub/DataReader.hpp>
|
||||
#include <dds/sub/DataReaderListener.hpp>
|
||||
#include <dds/topic/Topic.hpp>
|
||||
#include <dds/topic/find.hpp>
|
||||
|
||||
namespace DebugInfo
|
||||
{
|
||||
static inline QByteArray toReadable(const rti::core::Guid &guid)
|
||||
static inline QByteArray toReadable(const rti::core::Guid& guid)
|
||||
{
|
||||
return QByteArray(reinterpret_cast<const char *>(&guid[0]), 16).toHex();
|
||||
return QByteArray(reinterpret_cast<const char*>(&guid[0]), 16).toHex();
|
||||
}
|
||||
static inline QByteArray toReadable(const rti::core::SequenceNumber &seqNo,
|
||||
const rti::core::Guid &guid)
|
||||
|
||||
static inline QByteArray toReadable(const rti::core::SequenceNumber& seqNo, const rti::core::Guid& guid)
|
||||
{
|
||||
return "SeqNo: " + QByteArray::number(seqNo.value()) + ", Guid-DW: " + toReadable(guid);
|
||||
return "SeqNo: " + QByteArray::number(seqNo.value()) + ", Guid-DW: " + toReadable(guid);
|
||||
}
|
||||
static inline QByteArray toReadable(const rti::core::SampleIdentity &identiy)
|
||||
|
||||
static inline QByteArray toReadable(const rti::core::SampleIdentity& identiy)
|
||||
{
|
||||
return toReadable(identiy.sequence_number(), identiy.writer_guid());
|
||||
}
|
||||
return toReadable(identiy.sequence_number(), identiy.writer_guid());
|
||||
}
|
||||
} // namespace DebugInfo
|
||||
|
||||
namespace FTS
|
||||
{
|
||||
template<typename GENERIC_FTS>
|
||||
struct TopicNames;
|
||||
template <typename GENERIC_FTS> struct TopicNames;
|
||||
}
|
||||
|
||||
namespace FTC
|
||||
{
|
||||
template<typename GENERIC_FTC>
|
||||
struct TopicNames;
|
||||
template <typename GENERIC_FTC> struct TopicNames;
|
||||
}
|
||||
|
||||
namespace RoutingService
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
static dds::topic::Topic<T> getTopic(const dds::domain::DomainParticipant &participant,
|
||||
const std::string &topicName)
|
||||
template <typename T>
|
||||
static dds::topic::Topic<T> getTopic(const dds::domain::DomainParticipant& participant, const std::string& topicName)
|
||||
{
|
||||
using DataTopic = dds::topic::Topic<T>;
|
||||
auto ret = dds::topic::find<DataTopic>(participant, topicName);
|
||||
if (ret != nullptr)
|
||||
return ret;
|
||||
return DataTopic(participant, topicName);
|
||||
using DataTopic = dds::topic::Topic<T>;
|
||||
auto ret = dds::topic::find<DataTopic>(participant, topicName);
|
||||
if (ret != nullptr)
|
||||
return ret;
|
||||
return DataTopic(participant, topicName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class SampleWriterInterface
|
||||
{
|
||||
public:
|
||||
SampleWriterInterface() = default;
|
||||
virtual ~SampleWriterInterface() = default;
|
||||
public:
|
||||
SampleWriterInterface() = default;
|
||||
virtual ~SampleWriterInterface() = default;
|
||||
|
||||
virtual void writeSamples() = 0;
|
||||
virtual void writeSamples() = 0;
|
||||
|
||||
virtual NGL::INGLLogger &logger() = 0;
|
||||
virtual NGL::INGLLogger& logger() = 0;
|
||||
};
|
||||
|
||||
class DataWriterTaskInterface
|
||||
{
|
||||
public:
|
||||
DataWriterTaskInterface() = default;
|
||||
virtual ~DataWriterTaskInterface() = default;
|
||||
public:
|
||||
DataWriterTaskInterface() = default;
|
||||
virtual ~DataWriterTaskInterface() = default;
|
||||
|
||||
virtual void enqueue(SampleWriterInterface *swi) = 0;
|
||||
virtual void enqueue(SampleWriterInterface* swi) = 0;
|
||||
};
|
||||
|
||||
class TopicDispatcherInterface
|
||||
{
|
||||
public:
|
||||
TopicDispatcherInterface() = default;
|
||||
virtual ~TopicDispatcherInterface() = default;
|
||||
public:
|
||||
TopicDispatcherInterface() = default;
|
||||
virtual ~TopicDispatcherInterface() = default;
|
||||
|
||||
virtual bool init(DataWriterTaskInterface *dwt,
|
||||
const dds::domain::DomainParticipant &dpIn,
|
||||
const dds::sub::Subscriber &subIn,
|
||||
const dds::domain::DomainParticipant &dpOut,
|
||||
const dds::pub::Publisher &pubOut) = 0;
|
||||
virtual void shutdown() = 0;
|
||||
virtual bool init(DataWriterTaskInterface* dwt, const dds::domain::DomainParticipant& dpIn,
|
||||
const dds::sub::Subscriber& subIn, const dds::domain::DomainParticipant& dpOut,
|
||||
const dds::pub::Publisher& pubOut) = 0;
|
||||
virtual void shutdown() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename TOPIC>
|
||||
class SampleWriter final : public SampleWriterInterface
|
||||
template <typename TOPIC> class SampleWriter final : public SampleWriterInterface
|
||||
{
|
||||
public:
|
||||
SampleWriter(dds::sub::LoanedSamples<TOPIC> &&samples,
|
||||
const dds::pub::DataWriter<TOPIC> &dataWriter,
|
||||
bool bWithOriginalIdentity,
|
||||
NGL::INGLLogger &logger)
|
||||
: m_loanedSamples(std::move(samples))
|
||||
, m_dataWriter(dataWriter)
|
||||
, m_bWithOriginalIdentity(bWithOriginalIdentity)
|
||||
, m_logger(logger)
|
||||
{}
|
||||
|
||||
rti::core::SampleIdentity getIdentity(const rti::core::SampleIdentity &identity) const
|
||||
{
|
||||
|
||||
static const auto s_unknownSequenceNumber(rti::core::SequenceNumber::unknown());
|
||||
static const auto s_unknownGui(rti::core::Guid::unknown());
|
||||
static const auto s_unknownSampleIdentity(rti::core::SampleIdentity::unknown());
|
||||
|
||||
if (!m_bWithOriginalIdentity)
|
||||
return s_unknownSampleIdentity;
|
||||
|
||||
if (identity.sequence_number() == s_unknownSequenceNumber)
|
||||
return s_unknownSampleIdentity;
|
||||
if (identity.writer_guid() == s_unknownGui)
|
||||
return s_unknownSampleIdentity;
|
||||
return identity;
|
||||
}
|
||||
|
||||
void writeSamples() override
|
||||
{
|
||||
TRACE_LOG(m_logger) << "Writing samples for " << DDS::topic_type_name<TOPIC>::value()
|
||||
<< ", sample count: " << m_loanedSamples.length();
|
||||
rti::pub::WriteParams writeParams;
|
||||
for (const auto &sample : m_loanedSamples)
|
||||
public:
|
||||
SampleWriter(dds::sub::LoanedSamples<TOPIC>&& samples, const dds::pub::DataWriter<TOPIC>& dataWriter,
|
||||
bool bWithOriginalIdentity, NGL::INGLLogger& logger)
|
||||
: m_loanedSamples(std::move(samples)), m_dataWriter(dataWriter), m_bWithOriginalIdentity(bWithOriginalIdentity),
|
||||
m_logger(logger)
|
||||
{
|
||||
try
|
||||
{
|
||||
writeParams.identity(getIdentity(sample.info()->original_publication_virtual_sample_identity()));
|
||||
writeParams.related_sample_identity(getIdentity(sample.info()->related_original_publication_virtual_sample_identity()));
|
||||
|
||||
|
||||
writeParams.handle(sample.info().instance_handle());
|
||||
writeParams.flag(sample.info()->flag());
|
||||
|
||||
|
||||
|
||||
TRACE_LOG(m_logger) << "identity: " << DebugInfo::toReadable(writeParams.identity())
|
||||
<< ", related_sample_identity: " << DebugInfo::toReadable(writeParams.related_sample_identity());
|
||||
|
||||
const auto &state = sample.info().state();
|
||||
const dds::sub::status::InstanceState &instanceState = state.instance_state();
|
||||
if (instanceState == dds::sub::status::InstanceState::alive())
|
||||
{
|
||||
m_dataWriter->write(sample.data(), writeParams);
|
||||
}
|
||||
else if (instanceState == dds::sub::status::InstanceState::not_alive_disposed())
|
||||
{
|
||||
TRACE_LOG(m_logger) << " - is disposed";
|
||||
m_dataWriter->dispose_instance(writeParams);
|
||||
}
|
||||
else if (instanceState == dds::sub::status::InstanceState::not_alive_no_writers())
|
||||
{
|
||||
TRACE_LOG(m_logger) << " - is unregistered";
|
||||
m_dataWriter->unregister_instance(writeParams);
|
||||
}
|
||||
else
|
||||
WARNING_LOG(m_logger) << "Unknown instance state: " << instanceState;
|
||||
}
|
||||
catch (const dds::core::Exception &ex)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "writeSamples exception: " << ex.what();
|
||||
}
|
||||
}
|
||||
m_dataWriter->flush();
|
||||
}
|
||||
NGL::INGLLogger &logger() override { return m_logger; }
|
||||
private:
|
||||
dds::sub::LoanedSamples<TOPIC> m_loanedSamples;
|
||||
dds::pub::DataWriter<TOPIC> m_dataWriter;
|
||||
bool m_bWithOriginalIdentity;
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class DataTopicListener final : public dds::sub::DataReaderListener<T>
|
||||
{
|
||||
public:
|
||||
using DataReader = dds::sub::DataReader<T>;
|
||||
|
||||
DataTopicListener(DataWriterTaskInterface *dwt,
|
||||
const std::string &topicName,
|
||||
DDS::QosProfile::TopicType topicType,
|
||||
NGL::INGLLogger &logger)
|
||||
: m_dwt(dwt)
|
||||
, m_dataWriter(nullptr)
|
||||
, m_topicName(topicName)
|
||||
, m_topicType(topicType)
|
||||
, m_logger(logger)
|
||||
{}
|
||||
|
||||
bool init(const dds::domain::DomainParticipant &dpOut,
|
||||
const dds::pub::Publisher &pubOut)
|
||||
{
|
||||
if (!m_dwt)
|
||||
return false;
|
||||
DEBUG_LOG(m_logger) << "Creating DataWriter for domain " << dpOut.domain_id();
|
||||
m_dataWriter = dds::pub::DataWriter<T>(pubOut,
|
||||
getTopic<T>(dpOut, m_topicName),
|
||||
DDS::QosProfile::dataWriterDefault(m_topicType));
|
||||
|
||||
|
||||
dds::domain::DomainParticipant &dpOutNonConst = const_cast<dds::domain::DomainParticipant &>(dpOut);
|
||||
dds::pub::ignore(dpOutNonConst, m_dataWriter.instance_handle());
|
||||
return true;
|
||||
}
|
||||
|
||||
void on_data_available(dds::sub::DataReader<T> &reader) override
|
||||
{
|
||||
|
||||
|
||||
TRACE_LOG(m_logger) << "Data available for " << DDS::topic_type_name<T>::value();
|
||||
auto ws = new SampleWriter<T>(reader.take(), m_dataWriter, m_topicType == DDS::QosProfile::TopicType::FunctionTopic, m_logger);
|
||||
m_dwt->enqueue(ws);
|
||||
}
|
||||
|
||||
void on_requested_deadline_missed(dds::sub::DataReader<T> &, const dds::core::status::RequestedDeadlineMissedStatus &) override {}
|
||||
void on_requested_incompatible_qos(dds::sub::DataReader<T> &,
|
||||
const dds::core::status::RequestedIncompatibleQosStatus &) override {}
|
||||
void on_sample_rejected(dds::sub::DataReader<T> &,
|
||||
const dds::core::status::SampleRejectedStatus &) override {}
|
||||
void on_liveliness_changed(dds::sub::DataReader<T> &,
|
||||
const dds::core::status::LivelinessChangedStatus &) override {}
|
||||
void on_subscription_matched(dds::sub::DataReader<T> &,
|
||||
const dds::core::status::SubscriptionMatchedStatus &) override {}
|
||||
void on_sample_lost(dds::sub::DataReader<T> &,
|
||||
const dds::core::status::SampleLostStatus &) override {}
|
||||
|
||||
static dds::core::status::StatusMask mask()
|
||||
{
|
||||
return (dds::core::status::StatusMask::data_available());
|
||||
}
|
||||
|
||||
protected:
|
||||
DataWriterTaskInterface *m_dwt;
|
||||
dds::pub::DataWriter<T> m_dataWriter;
|
||||
std::string m_topicName;
|
||||
DDS::QosProfile::TopicType m_topicType;
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
template<typename TOPIC>
|
||||
class TopicDispatcher : public TopicDispatcherInterface
|
||||
{
|
||||
protected:
|
||||
explicit TopicDispatcher(NGL::INGLLogger &logger, const std::string &topicName, DDS::QosProfile::TopicType topicType)
|
||||
: m_dataReader(nullptr)
|
||||
, m_topicName(topicName)
|
||||
, m_topicType(topicType)
|
||||
, m_logger(logger)
|
||||
{
|
||||
}
|
||||
|
||||
~TopicDispatcher()
|
||||
{
|
||||
shutdown();
|
||||
}
|
||||
|
||||
bool init(DataWriterTaskInterface *dwt,
|
||||
const dds::domain::DomainParticipant &dpIn,
|
||||
const dds::sub::Subscriber &subIn,
|
||||
const dds::domain::DomainParticipant &dpOut,
|
||||
const dds::pub::Publisher &pubOut) override
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Initializing TopicDispatcher " << "(" << this << ")";
|
||||
if (m_dataReader != nullptr)
|
||||
return false;
|
||||
|
||||
m_dataReader = dds::sub::DataReader<TOPIC>(subIn,
|
||||
getTopic<TOPIC>(dpIn, m_topicName),
|
||||
DDS::QosProfile::dataReaderDefault(m_topicType));
|
||||
DEBUG_LOG(m_logger) << "Creating DataReader for domain " << dpIn.domain_id() << ", ptr: " << m_dataReader.delegate().get();
|
||||
|
||||
m_dtl.reset(new DataTopicListener<TOPIC>(dwt, m_topicName, m_topicType, m_logger));
|
||||
|
||||
if (!m_dtl->init(dpOut, pubOut))
|
||||
return false;
|
||||
m_dataReader.listener(m_dtl.get(), DataTopicListener<TOPIC>::mask());
|
||||
return true;
|
||||
}
|
||||
|
||||
void shutdown() override
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Cleaning up TopicDispatcher " << "(" << this << ")";
|
||||
if (m_dataReader != nullptr)
|
||||
rti::core::SampleIdentity getIdentity(const rti::core::SampleIdentity& identity) const
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "shutting down DataReader: " << m_dataReader.delegate().get();
|
||||
m_dataReader.listener(nullptr, dds::core::status::StatusMask::none());
|
||||
try
|
||||
{
|
||||
m_dataReader.close();
|
||||
}
|
||||
catch (const dds::core::Exception &ex)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "topic close ex: " << ex.what();
|
||||
}
|
||||
|
||||
static const auto s_unknownSequenceNumber(rti::core::SequenceNumber::unknown());
|
||||
static const auto s_unknownGui(rti::core::Guid::unknown());
|
||||
static const auto s_unknownSampleIdentity(rti::core::SampleIdentity::unknown());
|
||||
|
||||
if (!m_bWithOriginalIdentity)
|
||||
return s_unknownSampleIdentity;
|
||||
|
||||
if (identity.sequence_number() == s_unknownSequenceNumber)
|
||||
return s_unknownSampleIdentity;
|
||||
if (identity.writer_guid() == s_unknownGui)
|
||||
return s_unknownSampleIdentity;
|
||||
return identity;
|
||||
}
|
||||
|
||||
|
||||
m_dtl = nullptr;
|
||||
|
||||
m_dataReader = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
dds::sub::DataReader<TOPIC> m_dataReader;
|
||||
std::unique_ptr<DataTopicListener<TOPIC>> m_dtl;
|
||||
std::string m_topicName;
|
||||
DDS::QosProfile::TopicType m_topicType;
|
||||
NGL::INGLLogger &m_logger;
|
||||
void writeSamples() override
|
||||
{
|
||||
TRACE_LOG(m_logger) << "Writing samples for " << DDS::topic_type_name<TOPIC>::value()
|
||||
<< ", sample count: " << m_loanedSamples.length();
|
||||
rti::pub::WriteParams writeParams;
|
||||
for (const auto& sample : m_loanedSamples)
|
||||
{
|
||||
try
|
||||
{
|
||||
writeParams.identity(getIdentity(sample.info()->original_publication_virtual_sample_identity()));
|
||||
writeParams.related_sample_identity(
|
||||
getIdentity(sample.info()->related_original_publication_virtual_sample_identity()));
|
||||
|
||||
writeParams.handle(sample.info().instance_handle());
|
||||
writeParams.flag(sample.info()->flag());
|
||||
|
||||
TRACE_LOG(m_logger) << "identity: " << DebugInfo::toReadable(writeParams.identity())
|
||||
<< ", related_sample_identity: "
|
||||
<< DebugInfo::toReadable(writeParams.related_sample_identity());
|
||||
|
||||
const auto& state = sample.info().state();
|
||||
const dds::sub::status::InstanceState& instanceState = state.instance_state();
|
||||
if (instanceState == dds::sub::status::InstanceState::alive())
|
||||
{
|
||||
m_dataWriter->write(sample.data(), writeParams);
|
||||
}
|
||||
else if (instanceState == dds::sub::status::InstanceState::not_alive_disposed())
|
||||
{
|
||||
TRACE_LOG(m_logger) << " - is disposed";
|
||||
m_dataWriter->dispose_instance(writeParams);
|
||||
}
|
||||
else if (instanceState == dds::sub::status::InstanceState::not_alive_no_writers())
|
||||
{
|
||||
TRACE_LOG(m_logger) << " - is unregistered";
|
||||
m_dataWriter->unregister_instance(writeParams);
|
||||
}
|
||||
else
|
||||
WARNING_LOG(m_logger) << "Unknown instance state: " << instanceState;
|
||||
}
|
||||
catch (const dds::core::Exception& ex)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "writeSamples exception: " << ex.what();
|
||||
}
|
||||
}
|
||||
m_dataWriter->flush();
|
||||
}
|
||||
|
||||
NGL::INGLLogger& logger() override
|
||||
{
|
||||
return m_logger;
|
||||
}
|
||||
|
||||
private:
|
||||
dds::sub::LoanedSamples<TOPIC> m_loanedSamples;
|
||||
dds::pub::DataWriter<TOPIC> m_dataWriter;
|
||||
bool m_bWithOriginalIdentity;
|
||||
NGL::INGLLogger& m_logger;
|
||||
};
|
||||
|
||||
|
||||
template<typename TOPIC>
|
||||
class DataTopicDispatcher final : public TopicDispatcher<TOPIC>
|
||||
template <typename T> class DataTopicListener final : public dds::sub::DataReaderListener<T>
|
||||
{
|
||||
public:
|
||||
explicit DataTopicDispatcher(NGL::INGLLogger &logger)
|
||||
: TopicDispatcher<TOPIC>(logger,
|
||||
DDS::Helper::getShortTopicName(dds::topic::topic_type_name<TOPIC>::value()),
|
||||
DDS::QosProfile::TopicType::DataTopic)
|
||||
{}
|
||||
public:
|
||||
using DataReader = dds::sub::DataReader<T>;
|
||||
|
||||
DataTopicListener(DataWriterTaskInterface* dwt, const std::string& topicName, DDS::QosProfile::TopicType topicType,
|
||||
NGL::INGLLogger& logger)
|
||||
: m_dwt(dwt), m_dataWriter(nullptr), m_topicName(topicName), m_topicType(topicType), m_logger(logger)
|
||||
{
|
||||
}
|
||||
|
||||
bool init(const dds::domain::DomainParticipant& dpOut, const dds::pub::Publisher& pubOut)
|
||||
{
|
||||
if (!m_dwt)
|
||||
return false;
|
||||
DEBUG_LOG(m_logger) << "Creating DataWriter for domain " << dpOut.domain_id();
|
||||
m_dataWriter = dds::pub::DataWriter<T>(pubOut, getTopic<T>(dpOut, m_topicName),
|
||||
DDS::QosProfile::dataWriterDefault(m_topicType));
|
||||
|
||||
dds::domain::DomainParticipant& dpOutNonConst = const_cast<dds::domain::DomainParticipant&>(dpOut);
|
||||
dds::pub::ignore(dpOutNonConst, m_dataWriter.instance_handle());
|
||||
return true;
|
||||
}
|
||||
|
||||
void on_data_available(dds::sub::DataReader<T>& reader) override
|
||||
{
|
||||
|
||||
TRACE_LOG(m_logger) << "Data available for " << DDS::topic_type_name<T>::value();
|
||||
auto ws = new SampleWriter<T>(reader.take(), m_dataWriter,
|
||||
m_topicType == DDS::QosProfile::TopicType::FunctionTopic, m_logger);
|
||||
m_dwt->enqueue(ws);
|
||||
}
|
||||
|
||||
void on_requested_deadline_missed(dds::sub::DataReader<T>&,
|
||||
const dds::core::status::RequestedDeadlineMissedStatus&) override
|
||||
{
|
||||
}
|
||||
|
||||
void on_requested_incompatible_qos(dds::sub::DataReader<T>&,
|
||||
const dds::core::status::RequestedIncompatibleQosStatus&) override
|
||||
{
|
||||
}
|
||||
|
||||
void on_sample_rejected(dds::sub::DataReader<T>&, const dds::core::status::SampleRejectedStatus&) override {}
|
||||
|
||||
void on_liveliness_changed(dds::sub::DataReader<T>&, const dds::core::status::LivelinessChangedStatus&) override {}
|
||||
|
||||
void on_subscription_matched(dds::sub::DataReader<T>&, const dds::core::status::SubscriptionMatchedStatus&) override
|
||||
{
|
||||
}
|
||||
|
||||
void on_sample_lost(dds::sub::DataReader<T>&, const dds::core::status::SampleLostStatus&) override {}
|
||||
|
||||
static dds::core::status::StatusMask mask()
|
||||
{
|
||||
return (dds::core::status::StatusMask::data_available());
|
||||
}
|
||||
|
||||
protected:
|
||||
DataWriterTaskInterface* m_dwt;
|
||||
dds::pub::DataWriter<T> m_dataWriter;
|
||||
std::string m_topicName;
|
||||
DDS::QosProfile::TopicType m_topicType;
|
||||
NGL::INGLLogger& m_logger;
|
||||
};
|
||||
|
||||
template <typename TOPIC> class TopicDispatcher : public TopicDispatcherInterface
|
||||
{
|
||||
protected:
|
||||
explicit TopicDispatcher(NGL::INGLLogger& logger, const std::string& topicName,
|
||||
DDS::QosProfile::TopicType topicType)
|
||||
: m_dataReader(nullptr), m_topicName(topicName), m_topicType(topicType), m_logger(logger)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename FTS_TOPIC>
|
||||
~TopicDispatcher()
|
||||
{
|
||||
shutdown();
|
||||
}
|
||||
|
||||
bool init(DataWriterTaskInterface* dwt, const dds::domain::DomainParticipant& dpIn,
|
||||
const dds::sub::Subscriber& subIn, const dds::domain::DomainParticipant& dpOut,
|
||||
const dds::pub::Publisher& pubOut) override
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Initializing TopicDispatcher " << "(" << this << ")";
|
||||
if (m_dataReader != nullptr)
|
||||
return false;
|
||||
|
||||
m_dataReader = dds::sub::DataReader<TOPIC>(subIn, getTopic<TOPIC>(dpIn, m_topicName),
|
||||
DDS::QosProfile::dataReaderDefault(m_topicType));
|
||||
DEBUG_LOG(m_logger) << "Creating DataReader for domain " << dpIn.domain_id()
|
||||
<< ", ptr: " << m_dataReader.delegate().get();
|
||||
|
||||
m_dtl.reset(new DataTopicListener<TOPIC>(dwt, m_topicName, m_topicType, m_logger));
|
||||
|
||||
if (!m_dtl->init(dpOut, pubOut))
|
||||
return false;
|
||||
m_dataReader.listener(m_dtl.get(), DataTopicListener<TOPIC>::mask());
|
||||
return true;
|
||||
}
|
||||
|
||||
void shutdown() override
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Cleaning up TopicDispatcher " << "(" << this << ")";
|
||||
if (m_dataReader != nullptr)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "shutting down DataReader: " << m_dataReader.delegate().get();
|
||||
m_dataReader.listener(nullptr, dds::core::status::StatusMask::none());
|
||||
try
|
||||
{
|
||||
m_dataReader.close();
|
||||
}
|
||||
catch (const dds::core::Exception& ex)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "topic close ex: " << ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
m_dtl = nullptr;
|
||||
|
||||
m_dataReader = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
dds::sub::DataReader<TOPIC> m_dataReader;
|
||||
std::unique_ptr<DataTopicListener<TOPIC>> m_dtl;
|
||||
std::string m_topicName;
|
||||
DDS::QosProfile::TopicType m_topicType;
|
||||
NGL::INGLLogger& m_logger;
|
||||
};
|
||||
|
||||
template <typename TOPIC> class DataTopicDispatcher final : public TopicDispatcher<TOPIC>
|
||||
{
|
||||
public:
|
||||
explicit DataTopicDispatcher(NGL::INGLLogger& logger)
|
||||
: TopicDispatcher<TOPIC>(logger, DDS::Helper::getShortTopicName(dds::topic::topic_type_name<TOPIC>::value()),
|
||||
DDS::QosProfile::TopicType::DataTopic)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FTS_TOPIC>
|
||||
class FunctionTopicReplyDispatcher final : public TopicDispatcher<typename FTS_TOPIC::ReplyTopic>
|
||||
{
|
||||
public:
|
||||
explicit FunctionTopicReplyDispatcher(NGL::INGLLogger &logger)
|
||||
: TopicDispatcher<typename FTS_TOPIC::ReplyTopic>(logger,
|
||||
FTS::TopicNames<FTS_TOPIC>::replyTopicName(),
|
||||
DDS::QosProfile::TopicType::FunctionTopic)
|
||||
{}
|
||||
public:
|
||||
explicit FunctionTopicReplyDispatcher(NGL::INGLLogger& logger)
|
||||
: TopicDispatcher<typename FTS_TOPIC::ReplyTopic>(logger, FTS::TopicNames<FTS_TOPIC>::replyTopicName(),
|
||||
DDS::QosProfile::TopicType::FunctionTopic)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename FTC_TOPIC>
|
||||
template <typename FTC_TOPIC>
|
||||
class FunctionTopicRequestDispatcher final : public TopicDispatcher<typename FTC_TOPIC::RequestTopic>
|
||||
{
|
||||
public:
|
||||
explicit FunctionTopicRequestDispatcher(NGL::INGLLogger &logger)
|
||||
: TopicDispatcher<typename FTC_TOPIC::RequestTopic>(logger,
|
||||
FTC::TopicNames<FTC_TOPIC>::requestTopicName(),
|
||||
DDS::QosProfile::TopicType::FunctionTopic)
|
||||
{}
|
||||
public:
|
||||
explicit FunctionTopicRequestDispatcher(NGL::INGLLogger& logger)
|
||||
: TopicDispatcher<typename FTC_TOPIC::RequestTopic>(logger, FTC::TopicNames<FTC_TOPIC>::requestTopicName(),
|
||||
DDS::QosProfile::TopicType::FunctionTopic)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace RoutingService
|
||||
Reference in new issue
Block a user