72 lines
2.3 KiB
C++
Executable File
72 lines
2.3 KiB
C++
Executable File
|
|
|
|
#pragma once
|
|
|
|
#include "pub_sub_base.h"
|
|
|
|
#include <DDS/Generic/dynamic_data_reader.h>
|
|
#include <DDS/DTC/generic_dtc_impl.h>
|
|
#include <DDS/Generic/topic_description.h>
|
|
#include <rti/core/ListenerBinder.hpp>
|
|
|
|
namespace NGL
|
|
{
|
|
class INGLLogger;
|
|
}
|
|
|
|
namespace DDSConnector
|
|
{
|
|
class DDSCONNECTOR_EXPORT Subscriber : public PubSubBase
|
|
{
|
|
|
|
public:
|
|
Subscriber(const dds::domain::DomainParticipant &domainParticipant, const std::string &partition, bool bUseSubscriberListener = true);
|
|
virtual ~Subscriber();
|
|
|
|
dds::sub::Subscriber getDdsSubscriber() const { return m_ddsSubscriber; }
|
|
DDSGeneric::SubscriberListener *getSubscriberListener() { return m_subscriberListener; }
|
|
|
|
template <typename DTC_TYPE>
|
|
DTC_TYPE *create(std::function<void(const typename DTC_TYPE::TopicTypeRead &, DataModification modType)> cb)
|
|
{
|
|
DTC_TYPE* dtc = new DTC_TYPE;
|
|
if (!dtc->create(m_domainParticipant, m_ddsSubscriber, m_subscriberListener))
|
|
{
|
|
delete dtc;
|
|
return nullptr;
|
|
}
|
|
dtc->setSubscriberCallback(cb);
|
|
return dtc;
|
|
}
|
|
|
|
|
|
DTC::Ddtc<DDSGeneric::DynamicDataReader> *create(const std::function<void(const DDSGeneric::DynamicData &, const std::string &, DataModification modType)> &cb,
|
|
const dds::core::xtypes::StructType &structType,
|
|
DDSGeneric::SubscriberListener *listener = nullptr,
|
|
const std::string &specialTopicName = std::string())
|
|
{
|
|
if (!listener)
|
|
listener = getSubscriberListener();
|
|
|
|
DTC::DdtcImpl<DDSGeneric::DynamicDataReader> *ddtc =
|
|
new DTC::DdtcImpl<DDSGeneric::DynamicDataReader>(getDomainParticipant(),
|
|
getDdsSubscriber(),
|
|
listener,
|
|
structType,
|
|
specialTopicName);
|
|
ddtc->setSubscriberCallback(cb);
|
|
return ddtc;
|
|
}
|
|
|
|
protected:
|
|
void initDDS();
|
|
void deleteDDS();
|
|
|
|
protected:
|
|
dds::sub::Subscriber m_ddsSubscriber;
|
|
DDSGeneric::SubscriberListener *m_subscriberListener;
|
|
rti::core::ListenerBinder< dds::sub::Subscriber, dds::sub::SubscriberListener> m_subscriberListenerBinder;
|
|
};
|
|
|
|
}
|