Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/DDS/Generic/generic_data_writer.h
T
berrux-dev 156c2dfcdc Restore legacy @RDE_HEADER@ comment blocks stripped by the Qt6 migration
The migration pipeline dropped the leading @RDE_HEADER@ comment blocks
from 243 target source files (and 2 cmake macros). Restore them
byte-for-byte from the legacy Qt5 tree
(qt5-before/qt5-legatus-legacy): the exact legacy header is re-inserted
at the top of each file (block-comment, '#'-style, line-comment '//'
styles, BOM and surrounding blank lines included). File bodies are
untouched.

Scope: all in-scope target code, unit-test directories excluded.
190 files already kept their legacy header through the migration and
were left as-is; legacy files without an RDE header were not given
one. Special cases: 3 headers sitting after a '#pragma once' line,
1 BOM-prefixed file, 4 '//'-style TetraIF headers. *.grantlee template
files were not in scope and remain untouched.

Verified: every restored file is byte-exact (legacy preamble + original
body) and the ctest baseline is unchanged (20/23 passed, 3 Not Run as
before).
2026-11-15 23:22:04 +01:00

143 lines
4.3 KiB
C++

/**
* @RDE_HEADER@
* * GenericDataWriter (including GenericDataWriterBase)
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
// Include Qt headers FIRST to prevent namespace pollution when RTI DDS headers include Qt
#include <QtCore/QString>
#include <QtCore/QUrl>
#include <QtCore/QFlag>
#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/Topic.hpp>
#include <dds/topic/find.hpp>
namespace DDSGeneric
{
template <typename TOPICTYPE> class GenericDataWriter final
{
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)
{
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;
}
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.has_value())
{
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;
}
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;
}
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;
NGL::INGLLogger& m_logger;
};
} // namespace DDSGeneric