Modulo 5.0.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
modulo_core::communication::SubscriptionHandler< MsgT > Class Template Reference

The SubscriptionHandler handles different types of ROS subscriptions to receive data from those subscriptions. More...

#include <SubscriptionHandler.hpp>

Inheritance diagram for modulo_core::communication::SubscriptionHandler< MsgT >:
modulo_core::communication::SubscriptionInterface

Public Member Functions

 SubscriptionHandler (std::shared_ptr< MessagePairInterface > message_pair=nullptr, const rclcpp::Logger &logger=rclcpp::get_logger("SubscriptionHandler"))
 Constructor with the message pair.
 
 ~SubscriptionHandler () override
 Destructor to explicitly reset the subscription pointer.
 
std::shared_ptr< rclcpp::Subscription< MsgT > > get_subscription () const
 Getter of the ROS subscription.
 
void set_subscription (const std::shared_ptr< rclcpp::Subscription< MsgT > > &subscription)
 Setter of the ROS subscription.
 
void set_user_callback (const std::function< void()> &user_callback)
 Setter of a user callback function to be executed after the subscription callback.
 
std::function< void(const std::shared_ptr< MsgT >)> get_callback ()
 Get a callback function that will be associated with the ROS subscription to receive and translate messages.
 
std::function< void(const std::shared_ptr< MsgT >)> get_callback (const std::function< void()> &user_callback)
 Get a callback function that will be associated with the ROS subscription to receive and translate messages.
 
std::shared_ptr< SubscriptionInterfacecreate_subscription_interface (const std::shared_ptr< rclcpp::Subscription< MsgT > > &subscription)
 Create a SubscriptionInterface pointer through an instance of a SubscriptionHandler by providing a ROS subscription.
 
- Public Member Functions inherited from modulo_core::communication::SubscriptionInterface
 SubscriptionInterface (std::shared_ptr< MessagePairInterface > message_pair=nullptr)
 Constructor with the message pair.
 
 SubscriptionInterface (const SubscriptionInterface &subscription)=default
 Copy constructor from another SubscriptionInterface.
 
virtual ~SubscriptionInterface ()=default
 Default virtual destructor.
 
template<typename MsgT >
std::shared_ptr< SubscriptionHandler< MsgT > > get_handler (bool validate_pointer=true)
 Get a pointer to a derived SubscriptionHandler instance from a SubscriptionInterface pointer.
 
std::shared_ptr< MessagePairInterfaceget_message_pair () const
 Get the pointer to the message pair of the SubscriptionInterface.
 
void set_message_pair (const std::shared_ptr< MessagePairInterface > &message_pair)
 Set the pointer to the message pair of the SubscriptionInterface.
 

Additional Inherited Members

- Protected Attributes inherited from modulo_core::communication::SubscriptionInterface
std::shared_ptr< MessagePairInterfacemessage_pair_
 The pointer to the stored MessagePair instance.
 

Detailed Description

template<typename MsgT>
class modulo_core::communication::SubscriptionHandler< MsgT >

The SubscriptionHandler handles different types of ROS subscriptions to receive data from those subscriptions.

Template Parameters
MsgTThe ROS message type of the ROS subscription

Definition at line 15 of file SubscriptionHandler.hpp.

Constructor & Destructor Documentation

◆ SubscriptionHandler()

template<typename MsgT >
modulo_core::communication::SubscriptionHandler< MsgT >::SubscriptionHandler ( std::shared_ptr< MessagePairInterface message_pair = nullptr,
const rclcpp::Logger &  logger = rclcpp::get_logger("SubscriptionHandler< MsgT >") 
)
explicit

Constructor with the message pair.

Parameters
message_pairThe pointer to the message pair with the data that should be updated through the subscription
loggerAn optional ROS logger to do logging from the subscription callback

Definition at line 102 of file SubscriptionHandler.hpp.

◆ ~SubscriptionHandler()

template<typename MsgT >
modulo_core::communication::SubscriptionHandler< MsgT >::~SubscriptionHandler ( )
override

Destructor to explicitly reset the subscription pointer.

Definition at line 107 of file SubscriptionHandler.hpp.

Member Function Documentation

◆ create_subscription_interface()

template<typename MsgT >
std::shared_ptr< SubscriptionInterface > modulo_core::communication::SubscriptionHandler< MsgT >::create_subscription_interface ( const std::shared_ptr< rclcpp::Subscription< MsgT > > &  subscription)

Create a SubscriptionInterface pointer through an instance of a SubscriptionHandler by providing a ROS subscription.

This throws a NullPointerException if the ROS subscription is null.

See also
SubscriptionHandler::set_subscription
Parameters
subscriptionThe ROS subscription
Returns
The resulting SubscriptionInterface pointer

Definition at line 158 of file SubscriptionHandler.hpp.

◆ get_callback() [1/2]

template<typename MsgT >
std::function< void(const std::shared_ptr< MsgT >)> modulo_core::communication::SubscriptionHandler< MsgT >::get_callback ( )
inline

Get a callback function that will be associated with the ROS subscription to receive and translate messages.

Definition at line 125 of file SubscriptionHandler.hpp.

◆ get_callback() [2/2]

template<typename MsgT >
std::function< void(const std::shared_ptr< MsgT >)> modulo_core::communication::SubscriptionHandler< MsgT >::get_callback ( const std::function< void()> &  user_callback)

Get a callback function that will be associated with the ROS subscription to receive and translate messages.

This variant also takes a user callback function to execute after the message is received and translated.

Parameters
user_callbackVoid callback function for additional logic after the message is received and translated.

Definition at line 152 of file SubscriptionHandler.hpp.

◆ get_subscription()

template<typename MsgT >
std::shared_ptr< rclcpp::Subscription< MsgT > > modulo_core::communication::SubscriptionHandler< MsgT >::get_subscription ( ) const

Getter of the ROS subscription.

Definition at line 112 of file SubscriptionHandler.hpp.

◆ set_subscription()

template<typename MsgT >
void modulo_core::communication::SubscriptionHandler< MsgT >::set_subscription ( const std::shared_ptr< rclcpp::Subscription< MsgT > > &  subscription)

Setter of the ROS subscription.

Parameters
subscriptionThe ROS subscription
Exceptions
modulo_core::exceptions::NullPointerExceptionif the provided subscription pointer is null

Definition at line 117 of file SubscriptionHandler.hpp.

◆ set_user_callback()

template<typename MsgT >
void modulo_core::communication::SubscriptionHandler< MsgT >::set_user_callback ( const std::function< void()> &  user_callback)

Setter of a user callback function to be executed after the subscription callback.

Parameters
user_callbackThe ser callback function

Definition at line 146 of file SubscriptionHandler.hpp.


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