Class GenericSubscription
Defined in File generic_subscription.hpp
Inheritance Relationships
Base Type
public rclcpp::SubscriptionBase(Class SubscriptionBase)
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
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, andcallback_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 disable_callbacks() override
Disable callbacks from being called.
This method will block, until any subscription’s callbacks provided during construction currently being executed are finished.
Note
This method also temporary removes the on new message callback and all on new event callbacks from the rmw layer to prevent them from being called. However, this method will not block and wait until the currently executing on_new_[message]event callbacks are finished.
-
virtual void enable_callbacks() override
Enable the callbacks to be called.
This method is thread safe, and provides a safe way to atomically enable the callbacks in a multithreaded environment.
Cast the message to a rclcpp::SerializedMessage and call the callback.
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.
Return the message borrowed in create_message.
- Parameters:
message – [in] Shared pointer to the returned message.
Return the message borrowed in create_serialized_message.
- Parameters:
message – [in] Shared pointer to the returned message.
-
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.