#pragma once #include "generic_dts.h" #include #include namespace DTS { template class GenericDtsImpl final : public GenericDts { public: using DataWriterObject = DWO_OBJECT; using TopicType = typename DWO_OBJECT::TopicType; using DataWriter = typename dds::pub::DataWriter; GenericDtsImpl(const dds::domain::DomainParticipant &domainParticipant, const dds::pub::Publisher &ddsPublisher, const std::string &topicName = DDS::Helper::getShortTopicName(DDS::topic_type_name::value())) : m_dataWriterObject(new DataWriterObject()) , m_logger(DDS::getLogger(DDS::topic_type_name::value(), DDS::DataType::DATA_TOPIC_SERVER)) { Q_ASSERT(domainParticipant != nullptr); Q_ASSERT(ddsPublisher != nullptr); m_dataWriterObject->create(domainParticipant, ddsPublisher, topicName); } ~GenericDtsImpl() { delete m_dataWriterObject; } bool write(const TopicType &data, const dds::core::optional &si = dds::core::optional()) override final { DEBUG_LOG(m_logger) << "IN write (" << DDS::topic_type_name::value() << ")"; if (!m_dataWriterObject) return false; if (!m_dataWriterObject->write(data, si)) { ERROR_LOG(m_logger) << "Error writing for " << DDS::topic_type_name::value(); return false; } DEBUG_LOG(m_logger) << "TopicData (" << DDS::topic_type_name::value() << ") written"; return true; } bool remove(const TopicType &data, bool errorMsgIfNotExists = true) override final { DEBUG_LOG(m_logger) << "IN remove (" << DDS::topic_type_name::value() << ")"; if (!m_dataWriterObject) return false; if (!m_dataWriterObject->remove(data, errorMsgIfNotExists)) { if (errorMsgIfNotExists) ERROR_LOG(m_logger) << "Error removing for " << DDS::topic_type_name::value(); return false; } DEBUG_LOG(m_logger) << "TopicData (" << DDS::topic_type_name::value() << ") removed"; return true; } private: DataWriterObject *m_dataWriterObject; NGL::INGLLogger &m_logger; }; }