Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/DDS/DDSConnector/dds_connector.h
T
torstenandCopilot ad07345480 Grantlee Templates: Fix namespace resolution for RTI DTC generation
- Changed {{ namespace }}::{{ dt.type }} to ::{{ namespace }}::{{ dt.type }}
  in svc_dtc.h.grantlee, svc_dtc_impl.cpp.grantlee, svc_dtc_impl.h.grantlee
- Ensures absolute namespace resolution for Core::* types
- Fixes MOC/compilation errors for CurrentRunningState, LockedEntity, etc.

- Updated CMakeLists.txt for RTI 7.7.0 detection with DDS_PATH
- Fixed RTI include paths (ndds/hpp and ndds directories)
- Updated Lts/DDS module files for Qt6/RTI 7.7 compatibility

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-31 12:51:26 +02:00

255 lines
7.8 KiB
C++

#pragma once
#include <DDS/Generic/generic_base.h>
#include <Lts/Common/ProjectConfig/project_defines.h>
#include <QtCore/QUrl>
#include <QtCore/QStringList>
#include <ddsconnector_export.h>
#if BUILD_RTI
#include <dds/pub/CoherentSet.hpp>
#include <dds/pub/Publisher.hpp>
#include <dds/sub/Subscriber.hpp>
#endif
class QObject;
namespace DDS
{
namespace QosProfile
{
enum class ConnectionType;
}
} // namespace DDS
namespace DDSGeneric
{
class WaitSetHandler;
class SubscriberListener;
} // namespace DDSGeneric
namespace DDSConnector
{
class Publisher;
class Subscriber;
#if !BUILD_RTI
// Stub types for RTI DDS when BUILD_RTI=OFF
namespace dds { namespace domain { class DomainParticipant; } }
namespace dds { namespace pub { class Publisher; } }
namespace dds { namespace sub { class Subscriber; } }
namespace dds { namespace topic { template<typename T> class Filter; } }
#endif
class DDSCONNECTOR_EXPORT DdsConnector
{
#if BUILD_RTI
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(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(int domainId, IDL::PartitionType defaultPartitionType, int partitionId, int exerciseId,
DDS::QosProfile::ConnectionType connectionType);
virtual ~DdsConnector();
virtual bool init(const QStringList& qosFileList = QStringList());
dds::domain::DomainParticipant getDomainParticipant() const
{
return m_domainParticipant;
}
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);
Subscriber* getSubscriber()
{
return m_subscriber;
}
dds::sub::Subscriber getDdsSubscriber() const;
void setSubscriber(Subscriber* subscriber);
DDSGeneric::SubscriberListener* getSubscriberListener();
const DDSGeneric::WaitSetHandler* getWaitSetHandler() const
{
return m_wsHandler;
}
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);
void initPublisherSubscriber();
void initPublisher();
void initSubscriber();
void initDomainParticipant();
private:
#if BUILD_RTI
void initInternal();
void createWaitSetHandler();
#endif
public:
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;
}
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;
}
#else
// Stub constructor and methods when BUILD_RTI=OFF
DdsConnector() = default;
virtual ~DdsConnector() = default;
// Stub methods
bool init(const QStringList& /*qosFileList*/ = QStringList()) { return false; }
void* getDomainParticipant() const { return nullptr; }
void setDomainParticipant(void* /*participant*/) {}
Publisher* getPublisher() { return nullptr; }
void* getDdsPublisher() const { return nullptr; }
void setPublisher(Publisher* /*publisher*/) {}
void enableBatchedWriter(bool /*bEnable*/) {}
Subscriber* getSubscriber() { return nullptr; }
void* getDdsSubscriber() const { return nullptr; }
void setSubscriber(Subscriber* /*subscriber*/) {}
void* getSubscriberListener() { return nullptr; }
const void* getWaitSetHandler() const { return nullptr; }
int getDomainId() const { return 0; }
int getPartitionType() const { return 0; }
int getPartitionId() const { return 0; }
int getExerciseId() const { return 0; }
std::string getDefaultPartition() const { return ""; }
QUrl getTcpConnectionUrl() const { return QUrl(); }
static std::string getPartitionString(int /*pt*/, int /*partitionId*/ = -1) { return ""; }
void initPublisherSubscriber() {}
void initPublisher() {}
void initSubscriber() {}
void initDomainParticipant() {}
#endif
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;
#if BUILD_RTI
dds::domain::DomainParticipant m_domainParticipant;
#endif
DDSConnector::Publisher* m_publisher;
DDSConnector::Subscriber* m_subscriber;
DDSGeneric::WaitSetHandler* m_wsHandler;
};
#if BUILD_RTI
class CoherentSet
{
public:
explicit CoherentSet(const std::shared_ptr<DdsConnector>& connector) : m_coherentSet(connector->getDdsPublisher())
{
}
private:
dds::pub::CoherentSet m_coherentSet;
};
#else
// Stub CoherentSet when BUILD_RTI=OFF
class CoherentSet
{
public:
explicit CoherentSet(const std::shared_ptr<DdsConnector>& /*connector*/) {}
};
#endif
} // namespace DDSConnector