Modulo 5.0.0
|
Interface class to enable non-templated activating/deactivating/publishing of ROS publishers from derived PublisherHandler instances through dynamic down-casting. More...
#include <PublisherInterface.hpp>
Public Member Functions | |
PublisherInterface (PublisherType type, std::shared_ptr< MessagePairInterface > message_pair=nullptr) | |
Constructor with the message type and message pair. | |
PublisherInterface (const PublisherInterface &publisher)=default | |
Copy constructor from another PublisherInterface. | |
virtual | ~PublisherInterface ()=default |
Default virtual destructor. | |
template<typename PubT , typename MsgT > | |
std::shared_ptr< PublisherHandler< PubT, MsgT > > | get_handler (bool validate_pointer=true) |
Get a pointer to a derived PublisherHandler instance from a PublisherInterface pointer. | |
virtual void | activate () |
Activate ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointer. | |
virtual void | deactivate () |
Deactivate ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointer. | |
virtual void | publish () |
Publish the data stored in the message pair through the ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointer. | |
std::shared_ptr< MessagePairInterface > | get_message_pair () const |
Get the pointer to the message pair of the PublisherInterface. | |
void | set_message_pair (const std::shared_ptr< MessagePairInterface > &message_pair) |
Set the pointer to the message pair of the PublisherInterface. | |
PublisherType | get_type () const |
Get the type of the publisher interface. | |
Protected Attributes | |
std::shared_ptr< MessagePairInterface > | message_pair_ |
The pointer to the stored MessagePair instance. | |
Interface class to enable non-templated activating/deactivating/publishing of ROS publishers from derived PublisherHandler instances through dynamic down-casting.
Definition at line 20 of file PublisherInterface.hpp.
|
explicit |
Constructor with the message type and message pair.
type | The type of the publisher interface |
message_pair | The message pair with the data to be published |
Definition at line 17 of file PublisherInterface.cpp.
|
virtual |
Activate ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointer.
This throws an InvalidPointerCastException if the PublisherInterface does not point to a valid PublisherHandler instance or if the type of the message pair does not match the type of the PublisherHandler instance.
modulo_core::exceptions::NullPointerException | if the message pair pointer is null |
Reimplemented in modulo_core::communication::PublisherHandler< PubT, MsgT >.
Definition at line 20 of file PublisherInterface.cpp.
|
virtual |
Deactivate ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointer.
This throws an InvalidPointerCastException if the PublisherInterface does not point to a valid PublisherHandler instance or if the type of the message pair does not match the type of the PublisherHandler instance.
modulo_core::exceptions::NullPointerException | if the message pair pointer is null |
Reimplemented in modulo_core::communication::PublisherHandler< PubT, MsgT >.
Definition at line 25 of file PublisherInterface.cpp.
|
inline |
Get a pointer to a derived PublisherHandler instance from a PublisherInterface pointer.
If a PublisherInterface pointer is used to address a derived PublisherHandler instance, this method will return a pointer to that derived instance through dynamic down-casting. The downcast will fail if the base PublisherInterface object has no reference count (if the object is not owned by any pointer), or if the derived object is not a correctly typed instance of a PublisherHandler. By default, an InvalidPointerCastException is thrown when the downcast fails. If this validation is disabled by setting the validate_pointer flag to false, it will not throw an exception and instead return a null pointer.
PubT | The ROS publisher type |
MsgT | The ROS message type |
modulo_core::exceptions::InvalidPointerException | if the base PublisherInterface object has no reference count and validate_pointer is set to true |
modulo_core::exceptions::InvalidPointerCastException | if the derived object from the dynamic down-casting is not a correctly typed instance of a PublisherHandler |
validate_pointer | If true, throw an exception when down-casting fails |
Definition at line 130 of file PublisherInterface.hpp.
std::shared_ptr< MessagePairInterface > modulo_core::communication::PublisherInterface::get_message_pair | ( | ) | const |
Get the pointer to the message pair of the PublisherInterface.
Definition at line 78 of file PublisherInterface.cpp.
PublisherType modulo_core::communication::PublisherInterface::get_type | ( | ) | const |
Get the type of the publisher interface.
Definition at line 89 of file PublisherInterface.cpp.
|
virtual |
Publish the data stored in the message pair through the ROS publisher of a derived PublisherHandler instance through the PublisherInterface pointer.
This throws an InvalidPointerCastException if the PublisherInterface does not point to a valid PublisherHandler instance or if the type of the message pair does not match the type of the PublisherHandler instance.
modulo_core::exceptions::CoreException | if the publishing failed for some reason (translation, null pointer, pointer cast, ...) |
Reimplemented in modulo_core::communication::PublisherHandler< PubT, MsgT >.
Definition at line 30 of file PublisherInterface.cpp.
void modulo_core::communication::PublisherInterface::set_message_pair | ( | const std::shared_ptr< MessagePairInterface > & | message_pair | ) |
Set the pointer to the message pair of the PublisherInterface.
modulo_core::exceptions::NullPointerException | if the provided message pair pointer is null |
Definition at line 82 of file PublisherInterface.cpp.
|
protected |
The pointer to the stored MessagePair instance.
Definition at line 110 of file PublisherInterface.hpp.