3#include <rclcpp/logging.hpp>
5#include "modulo_core/communication/PublisherInterface.hpp"
7#include <rclcpp_lifecycle/lifecycle_publisher.hpp>
18template<
typename PubT,
typename MsgT>
53 void publish(
const MsgT& message)
const;
59 std::shared_ptr<PublisherInterface>
63 std::shared_ptr<PubT> publisher_;
68template<
typename PubT,
typename MsgT>
72template<
typename PubT,
typename MsgT>
74 this->publisher_.reset();
77template<
typename PubT,
typename MsgT>
79 if constexpr (std::derived_from<PubT, rclcpp_lifecycle::LifecyclePublisher<MsgT>>) {
80 if (this->publisher_ ==
nullptr) {
84 this->publisher_->on_activate();
85 }
catch (
const std::exception& ex) {
91template<
typename PubT,
typename MsgT>
93 if constexpr (std::derived_from<PubT, rclcpp_lifecycle::LifecyclePublisher<MsgT>>) {
94 if (this->publisher_ ==
nullptr) {
98 this->publisher_->on_deactivate();
99 }
catch (
const std::exception& ex) {
105template<
typename PubT,
typename MsgT>
109 if (this->message_pair_ ==
nullptr) {
112 publish(this->message_pair_->write<MsgT, MsgT>());
121template<
typename PubT,
typename MsgT>
123 if (this->publisher_ ==
nullptr) {
127 this->publisher_->publish(message);
128 }
catch (
const std::exception& ex) {
133template<
typename PubT,
typename MsgT>
134inline std::shared_ptr<PublisherInterface>
136 std::shared_ptr<PublisherInterface> publisher_interface;
138 publisher_interface = std::shared_ptr<PublisherInterface>(this->shared_from_this());
139 }
catch (
const std::exception& ex) {
142 publisher_interface->set_message_pair(message_pair);
143 return publisher_interface;
The PublisherHandler handles different types of ROS publishers to activate, deactivate and publish da...
virtual void activate() override
Activate ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointer.
void publish() override
Publish the data stored in the message pair through the ROS publisher of a derived PublisherHandler i...
std::shared_ptr< PublisherInterface > create_publisher_interface(const std::shared_ptr< MessagePairInterface > &message_pair)
Create a PublisherInterface instance from the current PublisherHandler.
~PublisherHandler() override
Destructor to explicitly reset the publisher pointer.
PublisherHandler(PublisherType type, std::shared_ptr< PubT > publisher)
Constructor with the publisher type and the pointer to the ROS publisher.
virtual void deactivate() override
Deactivate ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointe...
Interface class to enable non-templated activating/deactivating/publishing of ROS publishers from der...
virtual void publish()
Publish the data stored in the message pair through the ROS publisher of a derived PublisherHandler i...
std::shared_ptr< MessagePairInterface > message_pair_
The pointer to the stored MessagePair instance.
A base class for all core exceptions.
An exception class to notify that a certain pointer is null.
Modulo Core communication module for handling messages on publication and subscription interfaces.
PublisherType
Enum of supported ROS publisher types for the PublisherInterface.