9 #ifndef RAD_MAL_PUBLISHER_HPP
10 #define RAD_MAL_PUBLISHER_HPP
12 #include <rad/assert.hpp>
13 #include <rad/logger.hpp>
15 #include <mal/Cii.hpp>
16 #include <mal/Mal.hpp>
17 #include <mal/utility/LoadMal.hpp>
32 template <
typename TOPIC_TYPE>
42 const std::optional<elt::mal::Mal::Properties> mal_properties = {})
46 m_publisher = elt::mal::CiiFactory::getInstance().getPublisher<TOPIC_TYPE>(
47 elt::mal::Uri(uri), elt::mal::ps::qos::QoS::DEFAULT,
48 mal_properties ? *mal_properties : elt::mal::Mal::Properties());
52 elt::mal::CiiFactory& factory = elt::mal::CiiFactory::getInstance();
54 elt::mal::Mal::Properties mal_properties;
55 auto mal_instance = elt::mal::loadMal(malType, mal_properties);
57 auto uri = elt::mal::Uri(uriStr);
58 std::string scheme = uri.scheme().to_string();
59 factory.registerMal(scheme, mal_instance);
61 m_publisher = factory.getPublisher<TOPIC_TYPE>(uri, elt::mal::ps::qos::QoS::DEFAULT, mal_properties);
62 if (m_publisher ==
nullptr) {
63 throw std::runtime_error(
"Cannot create publisher");
66 auto topicInstance = m_publisher->createDataEntity();
67 if (topicInstance ==
nullptr) {
68 throw std::runtime_error(
"Publisher cannot create data entity");
71 m_instance_publisher = m_publisher->createInstancePublisher(*topicInstance);
72 if (m_instance_publisher ==
nullptr) {
73 throw std::runtime_error(
"Publisher cannot create instance publisher");
77 auto sample = m_instance_publisher->createDataEntity();
78 if (sample ==
nullptr) {
79 throw std::runtime_error(
"Instance publisher cannot create data entity");
96 return m_publisher->createDataEntity();
106 m_publisher->publish(topic,
107 std::chrono::milliseconds(0) );
114 std::unique_ptr<elt::mal::ps::Publisher<TOPIC_TYPE>> m_publisher;
121 #endif // RAD_MAL_SUBSCRIBER_HPP
log4cplus::Logger & GetLogger()
Definition: logger.cpp:43
void Publish(const TOPIC_TYPE &topic)
Definition: publisher.hpp:104
#define RAD_ASSERTPTR(a)
Definition: assert.hpp:19
Publisher & operator=(const Publisher &)=delete
Publisher(const elt::mal::Uri &uri, const std::optional< elt::mal::Mal::Properties > mal_properties={})
Definition: publisher.hpp:41
Definition: publisher.hpp:33
std::shared_ptr< TOPIC_TYPE > CreateTopic() const
Definition: publisher.hpp:94
#define RAD_TRACE(logger)
Definition: logger.hpp:19
~Publisher()
Definition: publisher.hpp:87