5#include "modulo_core/communication/MessagePair.hpp"
6#include "modulo_core/communication/PublisherType.hpp"
7#include "modulo_core/exceptions.hpp"
12template<
typename PubT,
typename MsgT>
13class PublisherHandler;
57 template<
typename PubT,
typename MsgT>
58 std::shared_ptr<PublisherHandler<PubT, MsgT>>
get_handler(
bool validate_pointer =
true);
95 [[nodiscard]] std::shared_ptr<MessagePairInterface>
get_message_pair()
const;
101 void set_message_pair(
const std::shared_ptr<MessagePairInterface>& message_pair);
123 template<
typename MsgT>
124 void publish(
const MsgT& message);
129template<
typename PubT,
typename MsgT>
131 std::shared_ptr<PublisherHandler<PubT, MsgT>> publisher_ptr;
133 publisher_ptr = std::dynamic_pointer_cast<PublisherHandler<PubT, MsgT>>(this->shared_from_this());
134 }
catch (
const std::exception& ex) {
135 if (validate_pointer) {
139 if (publisher_ptr ==
nullptr && validate_pointer) {
141 "Unable to cast publisher interface to a publisher pointer of requested type");
143 return publisher_ptr;
Interface class to enable non-templated activating/deactivating/publishing of ROS publishers from der...
virtual ~PublisherInterface()=default
Default virtual destructor.
virtual void deactivate()
Deactivate ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointe...
PublisherInterface(const PublisherInterface &publisher)=default
Copy constructor from another PublisherInterface.
PublisherType get_type() const
Get the type of the publisher interface.
virtual void publish()
Publish the data stored in the message pair through the ROS publisher of a derived PublisherHandler i...
std::shared_ptr< MessagePairInterface > get_message_pair() const
Get the pointer to the message pair of the PublisherInterface.
std::shared_ptr< MessagePairInterface > message_pair_
The pointer to the stored MessagePair instance.
std::shared_ptr< PublisherHandler< PubT, MsgT > > get_handler(bool validate_pointer=true)
Get a pointer to a derived PublisherHandler instance from a PublisherInterface pointer.
void set_message_pair(const std::shared_ptr< MessagePairInterface > &message_pair)
Set the pointer to the message pair of the PublisherInterface.
virtual void activate()
Activate ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointer.
An exception class to notify if the result of getting an instance of a derived class through dynamic ...
An exception class to notify if an object has no reference count (if the object is not owned by any p...
Modulo Core communication module for handling messages on publication and subscription interfaces.
PublisherType
Enum of supported ROS publisher types for the PublisherInterface.