Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/DDS/DDSConnector/publisher.cpp
T
berrux-dev cfe15c72c4 Merge story/release-validation-scope
Bring the validation-scope line (in-tree Jenkins CI copy, lcov coverage
wiring, step-by-step release-scope README, TetraIF unit tests, the
LogView runtime icon/resource fix, Dockerfile, rpmbuild and the
new_docker_build.sh driver with the DEB output path) on top of the
XmlPatterns branch pruned to the Release 2 scope.

Conflict policy:
- Out-of-scope targets/modules: keep the prune (deletion wins).
- In-scope files that validation had deleted: restored from
  story/release-2-cleanup (the Release 2 closure, with the
  pruned-module guards).
- In-scope sources carrying migration work: XmlPatterns versions
  (Qt XmlPatterns rework on QDomDocument, DDS member and logger
  fixes, first-build fixes).
- Scope-aware CMakeLists (top level, PluginInterfaces, LtsWidgets)
  and .envrc: story/release-2-cleanup / ours versions.
2026-11-16 18:49:14 +01:00

116 lines
2.8 KiB
C++
Executable File

/**
* @RDE_HEADER@
*
* Publisher
* Uses DTSs to publish data
*
* $Id$
* $HeadURL$
* $Author$
*/
#include "publisher.h"
#include "pub_sub_base_p.h"
#include <dds/pub/AnyDataWriter.hpp>
#include <rti/core/xtypes/DynamicDataImpl.hpp>
#include <Lts/DDS/QosProfile/DDS_DefaultQos.h>
#include <NGLLogger/INGLLogger.h>
namespace DDSConnector
{
Publisher::Publisher(const dds::domain::DomainParticipant &domainParticipant, const std::string &partition)
: PubSubBase(domainParticipant, partition, "DDSConnector.Publisher")
, m_ddsPublisher(nullptr)
{
Q_ASSERT(domainParticipant != nullptr);
initDDS();
}
Publisher::~Publisher()
{
try
{
deleteDDS();
} catch (...)
{}
}
void Publisher::initDDS()
{
if (m_partitions.empty())
return;
if (m_logger.isDebugEnabled()) {
DEBUG_LOG(m_logger) << "Publisher (DataWriter) Qos: ";
dds::core::QosProvider qosProvider = dds::core::QosProvider::Default();
DDS::QosProfile::print(qosProvider.datawriter_qos(), m_logger);
}
dds::pub::qos::PublisherQos publisherQos = m_domainParticipant.default_publisher_qos();
rti::core::policy::EntityName entityName;
entityName.name(std::string("Pub ") + m_partitions.front());
publisherQos << entityName;
DEBUG_LOG(m_logger) << "Publish data on partition " << m_partitions.front();
m_ddsPublisher = dds::pub::Publisher(m_domainParticipant, publisherQos);
enableBatchedWriter(false);
updatePartitionQoS(m_ddsPublisher);
}
void Publisher::enableBatchedWriter(bool bEnable)
{
dds::pub::qos::DataWriterQos dwQos = m_ddsPublisher.default_datawriter_qos();
auto batch = (bEnable ? rti::core::policy::Batch::Enabled() : rti::core::policy::Batch::Disabled());
if (bEnable)
{
batch.max_data_bytes(64 * 1024);
batch.max_flush_delay(dds::core::Duration::from_millisecs(10));
}
dwQos << batch;
m_ddsPublisher.default_datawriter_qos(dwQos);
}
void Publisher::deleteDDS()
{
qDeleteAll(m_dtsMap);
qDeleteAll(m_dynamicTypeMap);
m_ddsPublisher = nullptr;
}
bool Publisher::write(const dds::core::xtypes::DynamicData &data, const std::string &topicName)
{
DEBUG_LOG(m_logger) << "Publish dynamic data for topic (" << topicName << ")";
try
{
dds::pub::AnyDataWriter* anyWriter = m_dynamicTypeMap.value(topicName);
if (anyWriter == nullptr)
{
dds::topic::Topic<dds::core::xtypes::DynamicData> topic(m_domainParticipant, topicName, data.type());
auto writer = dds::pub::DataWriter<dds::core::xtypes::DynamicData>(m_ddsPublisher, topic);
anyWriter = new dds::pub::AnyDataWriter(writer);
m_dynamicTypeMap.insert(topicName, anyWriter);
}
anyWriter->get<dds::core::xtypes::DynamicData>().write(data);
}
catch ( ... )
{
ERROR_LOG(m_logger) << "Failed to publish data for topic (" << topicName << ")";
return false;
}
return true;
}
}