9 #ifndef RAD_MAL_PUBLISHER_HPP
10 #define RAD_MAL_PUBLISHER_HPP
15 #include <mal/Cii.hpp>
16 #include <mal/Mal.hpp>
17 #include <mal/utility/LoadMal.hpp>
34 template <
typename TOPIC_TYPE>
44 const std::optional<elt::mal::Mal::Properties> mal_properties = {})
48 m_publisher = elt::mal::CiiFactory::getInstance().getPublisher<TOPIC_TYPE>(
49 elt::mal::Uri(uri), elt::mal::ps::qos::QoS::DEFAULT,
50 mal_properties ? *mal_properties : elt::mal::Mal::Properties());
54 elt::mal::CiiFactory& factory = elt::mal::CiiFactory::getInstance();
56 elt::mal::Mal::Properties mal_properties;
57 auto mal_instance = elt::mal::loadMal(malType, mal_properties);
59 auto uri = elt::mal::Uri(uriStr);
60 std::string scheme = uri.scheme().to_string();
61 factory.registerMal(scheme, mal_instance);
63 m_publisher = factory.getPublisher<TOPIC_TYPE>(uri, elt::mal::ps::qos::QoS::DEFAULT, mal_properties);
64 if (m_publisher ==
nullptr) {
65 throw std::runtime_error(
"Cannot create publisher");
68 auto topicInstance = m_publisher->createDataEntity();
69 if (topicInstance ==
nullptr) {
70 throw std::runtime_error(
"Publisher cannot create data entity");
73 m_instance_publisher = m_publisher->createInstancePublisher(*topicInstance);
74 if (m_instance_publisher ==
nullptr) {
75 throw std::runtime_error(
"Publisher cannot create instance publisher");
79 auto sample = m_instance_publisher->createDataEntity();
80 if (sample ==
nullptr) {
81 throw std::runtime_error(
"Instance publisher cannot create data entity");
98 return m_publisher->createDataEntity();
108 m_publisher->publish(topic,
109 std::chrono::milliseconds(0) );
116 std::unique_ptr<elt::mal::ps::Publisher<TOPIC_TYPE>> m_publisher;
#define RAD_ASSERTPTR(a)
Definition: assert.hpp:19
Definition: publisher.hpp:35
Publisher(const elt::mal::Uri &uri, const std::optional< elt::mal::Mal::Properties > mal_properties={})
Definition: publisher.hpp:43
Publisher & operator=(const Publisher &)=delete
Publisher(const Publisher &)=delete
~Publisher()
Definition: publisher.hpp:89
std::shared_ptr< TOPIC_TYPE > CreateTopic() const
Definition: publisher.hpp:96
void Publish(const TOPIC_TYPE &topic)
Definition: publisher.hpp:106
#define RAD_TRACE(logger)
Definition: logger.hpp:24
Definition: actionsApp.cpp:20
log4cplus::Logger & GetLogger()
Definition: logger.cpp:70