- NGL_ADD_LIBRARY2: 87 CMakeLists.txt konvertiert für Export-Header Generierung - 44 Export-Header Include-Pfade korrigiert (_export.h) - 81 DDS-Stub-Header generiert (*_dtc.h, *_fts.h, *_dts.h, *_ftc.h) - INGLLogger: Duplikat gelöscht, m_logger Member entfernt, variadische Makros - Q_FUNC_INFO Redefinition behoben (Qt6 definiert bereits) - FATAL_LOG Makro hinzugefügt - InfrastructureManagement DDS-Stubs (ism.hpp, ism_enums.hpp, ism_ftc.h) - FilterManagement DDS-Stubs (flt_ftc.h, flt_dts.h) - AreaEffectSimulation DDS-Stubs (aes.hpp, aes_enums.hpp) - SymbolAppearance Klasse vollständig definiert mit content() Methode - BuildingComponentFilter Klasse definiert mit Copy-Konstruktor - Ftc Factory: nullptr Return (abstract class) - AesFilter Klasse in aes.hpp hinzugefügt - Dtc Klasse in ppm.hpp mit participantChanged Signal - AesType Enum: alle 15 At* Werte definiert - AesEffectState_def: EsReceived hinzugefügt - DataModification Enum: eAdded/eModified/eRemoved - function_reply_object.h → core_types.h Include-Pfad (72 Dateien) - Enum-Class-Streaming Template-Operator in INGLLogger.h - ism_mounting_point.h: QImage → QtGui/QImage, QGuiApplication/QScreen - ism_data_plugin_interface.h: QSet Include, Include-Reihenfolge - QRegExp → QRegularExpression in tpm_js_parser.cpp - .underlying() Aufrufe zu direktem Enum-Vergleich korrigiert - Include-Pfade: aes.hpp in symbol_appearance_settings_impl.h und aes_display_filter_impl.h Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
188 lines
4.4 KiB
C++
Executable File
188 lines
4.4 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Routing Test - main connection handling
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
|
|
#include "connection.h"
|
|
#include "data_writer_task.h"
|
|
|
|
#include <QCoreApplication>
|
|
#include <QElapsedTimer>
|
|
|
|
#include <DDS/DDSConnector/publisher.h>
|
|
#include <DDS/DDSConnector/subscriber.h>
|
|
|
|
|
|
namespace RoutingService
|
|
{
|
|
|
|
Connection::Connection(const dds::domain::DomainParticipant &domainParticipant,
|
|
const std::string &partition,
|
|
const std::vector<TopicDispatcherInterface *> &topicsToRoute,
|
|
const std::string &desc)
|
|
: m_output(nullptr)
|
|
, m_domainParticipant(domainParticipant)
|
|
, m_publisher(new DDSConnector::Publisher(domainParticipant, partition))
|
|
, m_subscriber(new DDSConnector::Subscriber(domainParticipant, partition, false))
|
|
, m_dataWriterTask(nullptr)
|
|
, m_topicsToRoute(topicsToRoute)
|
|
, m_partition(partition)
|
|
, m_description(desc)
|
|
{
|
|
INFO_LOG() << "Create connection: " << partition
|
|
<< ", domain: " << domainParticipant.domain_id()
|
|
<< ", direction: " << m_description
|
|
<< " (" << this << ")";
|
|
}
|
|
|
|
Connection::~Connection()
|
|
{
|
|
setOutput(nullptr);
|
|
shutdown();
|
|
try
|
|
{
|
|
if (m_subscriber)
|
|
m_subscriber->getDdsSubscriber().close();
|
|
}
|
|
catch (const dds::core::Exception &ex)
|
|
{
|
|
ERROR_LOG() << "sub close ex: " << ex.what();
|
|
}
|
|
m_subscriber = nullptr;
|
|
try
|
|
{
|
|
if (m_publisher)
|
|
m_publisher->getDdsPublisher().close();
|
|
}
|
|
catch (const dds::core::Exception &ex)
|
|
{
|
|
ERROR_LOG() << "pub close ex: " << ex.what();
|
|
}
|
|
m_publisher = nullptr;
|
|
m_domainParticipant = nullptr;
|
|
}
|
|
|
|
void Connection::setOutput(Connection *output)
|
|
{
|
|
if (m_output == output)
|
|
return;
|
|
|
|
m_output = output;
|
|
}
|
|
|
|
bool Connection::initialize()
|
|
{
|
|
DEBUG_LOG() << "initialize new connection for " << m_partition
|
|
<< ", direction: " << m_description
|
|
<< " (" << this << ")";
|
|
|
|
if (m_writerThread.valid())
|
|
shutdown();
|
|
|
|
m_dataWriterTask.reset(new DataWriterTask);
|
|
|
|
if (!m_output)
|
|
{
|
|
ERROR_LOG() << "Error initializing connection for " << m_partition
|
|
<< ", direction: " << m_description << " - no output set!";
|
|
return false;
|
|
}
|
|
m_writerThread = std::async(std::launch::async, [this]() { this->m_dataWriterTask->writeSamples();});
|
|
return initTopics();
|
|
}
|
|
|
|
void Connection::shutdown()
|
|
{
|
|
if (m_topicsToRoute.empty())
|
|
return;
|
|
|
|
QElapsedTimer timer;
|
|
timer.start();
|
|
|
|
DEBUG_LOG() << "shutting down connection for " << m_partition
|
|
<< ", direction: " << m_description
|
|
<< " (" << this << "), dwt: " << m_dataWriterTask.get();
|
|
|
|
// inform DataWriterTask about its destruction in the near future
|
|
// it removes it not yet sent samples and does not enqueue new samples
|
|
if (m_dataWriterTask)
|
|
m_dataWriterTask->shutdown();
|
|
|
|
// now remove topics, they don't have outstanding loans since dataWrterTask does
|
|
// not enqueue samples anymore
|
|
for (auto topic : m_topicsToRoute)
|
|
{
|
|
if (timer.elapsed() > 1000)
|
|
{
|
|
QCoreApplication::processEvents(); // for e.g. paceMaker
|
|
timer.start();
|
|
}
|
|
topic->shutdown();
|
|
}
|
|
qDeleteAll(m_topicsToRoute);
|
|
m_topicsToRoute.clear();
|
|
|
|
// now we can wait until the data writer task has finished
|
|
if (m_dataWriterTask)
|
|
{
|
|
m_writerThread.wait();
|
|
m_dataWriterTask = nullptr;
|
|
}
|
|
|
|
}
|
|
|
|
dds::domain::DomainParticipant Connection::domainParticipant() const
|
|
{
|
|
return m_domainParticipant;
|
|
}
|
|
|
|
dds::pub::Publisher Connection::publisher() const
|
|
{
|
|
return m_publisher->getDdsPublisher();
|
|
}
|
|
|
|
dds::sub::Subscriber Connection::subscriber() const
|
|
{
|
|
return m_subscriber->getDdsSubscriber();
|
|
}
|
|
|
|
bool Connection::initTopics()
|
|
{
|
|
DEBUG_LOG() << "Init topics for " << m_partition
|
|
<< ", direction: " << m_description;
|
|
|
|
if (!m_output)
|
|
return false;
|
|
|
|
QElapsedTimer timer;
|
|
timer.start();
|
|
|
|
auto dpOut = m_output->domainParticipant();
|
|
auto pubOut = m_output->publisher();
|
|
|
|
for (auto dp : m_topicsToRoute)
|
|
{
|
|
if (!dp)
|
|
continue;
|
|
if (!dp->init(m_dataWriterTask.get(),
|
|
m_domainParticipant,
|
|
m_subscriber->getDdsSubscriber(),
|
|
dpOut,
|
|
pubOut))
|
|
return false;
|
|
if (timer.elapsed() > 1000)
|
|
{
|
|
QCoreApplication::processEvents(); // for e.g. paceMaker
|
|
timer.start();
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
} // namespace RoutingService
|