Modulo 4.2.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
modulo_core::communication::PublisherInterface Class Reference

Interface class to enable non-templated activating/deactivating/publishing of ROS publishers from derived PublisherHandler instances through dynamic down-casting. More...

#include <PublisherInterface.hpp>

Inheritance diagram for modulo_core::communication::PublisherInterface:
modulo_core::communication::PublisherHandler< PubT, MsgT >

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< MessagePairInterfaceget_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< MessagePairInterfacemessage_pair_
 The pointer to the stored MessagePair instance.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PublisherInterface()

modulo_core::communication::PublisherInterface::PublisherInterface ( PublisherType  type,
std::shared_ptr< MessagePairInterface message_pair = nullptr 
)
explicit

Constructor with the message type and message pair.

Parameters
typeThe type of the publisher interface
message_pairThe message pair with the data to be published

Definition at line 17 of file PublisherInterface.cpp.

Member Function Documentation

◆ activate()

void modulo_core::communication::PublisherInterface::activate ( )
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.

See also
PublisherInterface::get_handler
Exceptions
modulo_core::exceptions::NullPointerExceptionif the message pair pointer is null

Reimplemented in modulo_core::communication::PublisherHandler< PubT, MsgT >.

Definition at line 20 of file PublisherInterface.cpp.

◆ deactivate()

void modulo_core::communication::PublisherInterface::deactivate ( )
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.

See also
PublisherInterface::get_handler
Exceptions
modulo_core::exceptions::NullPointerExceptionif the message pair pointer is null

Reimplemented in modulo_core::communication::PublisherHandler< PubT, MsgT >.

Definition at line 25 of file PublisherInterface.cpp.

◆ get_handler()

template<typename PubT , typename MsgT >
std::shared_ptr< PublisherHandler< PubT, MsgT > > modulo_core::communication::PublisherInterface::get_handler ( bool  validate_pointer = true)
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.

Template Parameters
PubTThe ROS publisher type
MsgTThe ROS message type
Exceptions
modulo_core::exceptions::InvalidPointerExceptionif the base PublisherInterface object has no reference count and validate_pointer is set to true
modulo_core::exceptions::InvalidPointerCastExceptionif the derived object from the dynamic down-casting is not a correctly typed instance of a PublisherHandler
Parameters
validate_pointerIf true, throw an exception when down-casting fails
Returns
A pointer to a derived PublisherHandler instance of the desired type, or a null pointer if down-casting failed and validate_pointer was set to false.

Definition at line 130 of file PublisherInterface.hpp.

◆ get_message_pair()

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.

◆ get_type()

PublisherType modulo_core::communication::PublisherInterface::get_type ( ) const

Get the type of the publisher interface.

See also
PublisherType

Definition at line 89 of file PublisherInterface.cpp.

◆ publish()

void modulo_core::communication::PublisherInterface::publish ( )
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.

See also
PublisherInterface::get_handler
Exceptions
modulo_core::exceptions::CoreExceptionif 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.

◆ set_message_pair()

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.

Exceptions
modulo_core::exceptions::NullPointerExceptionif the provided message pair pointer is null

Definition at line 82 of file PublisherInterface.cpp.

Member Data Documentation

◆ message_pair_

std::shared_ptr<MessagePairInterface> modulo_core::communication::PublisherInterface::message_pair_
protected

The pointer to the stored MessagePair instance.

Definition at line 110 of file PublisherInterface.hpp.


The documentation for this class was generated from the following files: