#pragma once #include "ddkit/access/TopicPool.hpp" #include "ddkit/access/Topic.hpp" #include "ddkit/access/Dispatcher.hpp" #include "ddkit/access/Reader.hpp" #include "ddkit/utils/string.hpp" #include namespace ddkit { namespace access { class TopicPoolRead final { public: TopicPoolRead( Participant& participant, const IQosStrategyPtr& qosStrategy, const ITopicStrategyPtr& topicStrategy, std::shared_ptr dispatcher); ~TopicPoolRead(); // create Topic and Reader and register function for beeing callbacked by given dispatcher // (a second callback may be given for reading disposes as well) // todo name is historical, could be createReader template void createTopicRead(std::function func, std::function funcDispose = nullptr) { DDKIT_LOG_TRACE; std::unique_lock lock(m_mutex); std::string topicName = m_topicPool.getTopicName(); std::shared_ptr> topic = m_topicPool.topic(); if(!topic) { ddkit::log::error() << "TopicPoolRead::createTopicRead: no topic in topic pool."; return; } if(topic->hasReader()) { ddkit::log::error() << "TopicPoolRead::createTopicRead: Reader (" << topicName << ") already exists."; return; } QosPattern qosPattern = m_topicPool.qosPattern(topic->typeName()); dds::sub::qos::DataReaderQos dataReaderQos = qosPattern.qosRead(); dds::sub::qos::SubscriberQos subQos = qosPattern.qosSub(); auto reader = std::make_shared>(m_dispatcher, topic, dataReaderQos, subQos, func, funcDispose); topic->setReader(reader); } // to be able to call with member-function-callbacks as well - transform to std::function // - this is used in ldm/test-context so far, no dispose-callback used here so far ... template void createTopicRead(void (U::*funcPtr)(T const&), U& u) { DDKIT_LOG_TRACE; createTopicRead(std::bind(funcPtr, &u, std::placeholders::_1)); } bool hasReaders(); void closeReaders(); void unloadReaders(); private: std::recursive_mutex m_mutex; TopicPool m_topicPool; std::shared_ptr m_dispatcher; // no copying TopicPoolRead(TopicPoolRead const&) = delete; TopicPoolRead(TopicPoolRead&&) = delete; void operator=(TopicPoolRead const&) = delete; }; } // namespace access } // namespace ddkit