68 lines
1.4 KiB
C++
Executable File
68 lines
1.4 KiB
C++
Executable File
|
|
|
|
#pragma once
|
|
|
|
#include <QtCore/QMap>
|
|
#include <NGLLogger/INGLLogger.h>
|
|
#include <DDS/DTS/generic_dts_impl.h>
|
|
#include <DDS/Generic/generic_data_writer.h>
|
|
|
|
#include "pub_sub_base.h"
|
|
|
|
namespace DDSConnector
|
|
{
|
|
class DDSCONNECTOR_EXPORT Publisher : public PubSubBase
|
|
{
|
|
public:
|
|
Publisher(const dds::domain::DomainParticipant &domainParticipant, const std::string &partition);
|
|
~Publisher();
|
|
|
|
void enableBatchedWriter(bool bEnable);
|
|
dds::pub::Publisher getDdsPublisher() const { return m_ddsPublisher; }
|
|
|
|
|
|
template <typename T>
|
|
bool write(const T &data)
|
|
{
|
|
using myDWO = DDSGeneric::GenericDataWriter<T>;
|
|
using myDTS = DTS::GenericDtsImpl< myDWO >;
|
|
|
|
std::string dwoType = DDS::topic_type_name<T>::value();
|
|
DEBUG_LOG(m_logger) << "dwoType = " << dwoType;
|
|
|
|
myDTS *dts = static_cast<myDTS *>(m_dtsMap.value(dwoType));
|
|
if (dts == nullptr)
|
|
{
|
|
dts = new myDTS(m_domainParticipant, m_ddsPublisher);
|
|
m_dtsMap.insert(dwoType, dts);
|
|
}
|
|
|
|
return dts->write(data);
|
|
}
|
|
|
|
|
|
bool write(const dds::core::xtypes::DynamicData &data)
|
|
{
|
|
return write(data, data.type().name());
|
|
}
|
|
|
|
bool write(const dds::core::xtypes::DynamicData &data, const std::string &topicName);
|
|
|
|
|
|
protected:
|
|
void initDDS();
|
|
void deleteDDS();
|
|
|
|
protected:
|
|
dds::pub::Publisher m_ddsPublisher;
|
|
|
|
|
|
QMap<std::string, DTS::Base*> m_dtsMap;
|
|
|
|
|
|
|
|
QMap<std::string, dds::pub::AnyDataWriter*> m_dynamicTypeMap;
|
|
};
|
|
|
|
}
|