Class GenericSubscription

Inheritance Relationships

Base Type

Class Documentation

class GenericSubscription : public rclcpp::SubscriptionBase

Subscription for serialized messages whose type is not known at compile time.

Since the type is not known at compile time, this is not a template, and the dynamic library containing type support information has to be identified and loaded based on the type name.

It does not support intra-process handling.

Public Functions

template<typename AllocatorT = std::allocator<void>>
inline GenericSubscription(rclcpp::node_interfaces::NodeBaseInterface *node_base, const std::shared_ptr<rcpputils::SharedLibrary> ts_lib, const std::string &topic_name, const std::string &topic_type, const rclcpp::QoS &qos, std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)> callback, const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT> &options)

Constructor.

In order to properly subscribe to a topic, this subscription needs to be added to the node_topic_interface of the node passed into this constructor.

See also

rclcpp::Node::create_generic_subscription() or rclcpp::create_generic_subscription() for creating an instance of this class and adding it to the node_topic_interface.

Parameters:
  • node_base – Pointer to parent node’s NodeBaseInterface

  • ts_lib – Type support library, needs to correspond to topic_type

  • topic_name – Topic name

  • topic_type – Topic type

  • qos – QoS settings

  • callback – Callback for new messages of serialized form

  • options – Subscription options. Not all subscription options are currently respected, the only relevant options for this subscription are event_callbacks, use_default_callbacks, ignore_local_publications, and callback_group.

virtual ~GenericSubscription() = default
virtual std::shared_ptr<void> create_message() override

Borrow a new message.

Returns:

Shared pointer to the fresh message.

virtual std::shared_ptr<rclcpp::SerializedMessage> create_serialized_message() override

Borrow a new serialized message.

Returns:

Shared pointer to a rcl_message_serialized_t.

virtual void handle_message(std::shared_ptr<void> &message, const rclcpp::MessageInfo &message_info) override

Cast the message to a rclcpp::SerializedMessage and call the callback.

virtual void handle_serialized_message(const std::shared_ptr<rclcpp::SerializedMessage> &serialized_message, const rclcpp::MessageInfo &message_info) override

Handle dispatching rclcpp::SerializedMessage to user callback.

virtual void handle_loaned_message(void *loaned_message, const rclcpp::MessageInfo &message_info) override

This function is currently not implemented.

virtual void return_message(std::shared_ptr<void> &message) override

Return the message borrowed in create_message.

Parameters:

message[in] Shared pointer to the returned message.

virtual void return_serialized_message(std::shared_ptr<rclcpp::SerializedMessage> &message) override

Return the message borrowed in create_serialized_message.

Parameters:

message[in] Shared pointer to the returned message.

virtual rclcpp::dynamic_typesupport::DynamicMessageType::SharedPtr get_shared_dynamic_message_type() override
virtual rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr get_shared_dynamic_message() override
virtual rclcpp::dynamic_typesupport::DynamicSerializationSupport::SharedPtr get_shared_dynamic_serialization_support() override
virtual rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr create_dynamic_message() override

Borrow a new serialized message (this clones!)

Returns:

Shared pointer to a rclcpp::dynamic_typesupport::DynamicMessage.

virtual void return_dynamic_message(rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr &message) override
virtual void handle_dynamic_message(const rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr &message, const rclcpp::MessageInfo &message_info) override