ROS 2 rclcpp + rcl - humble
humble
ROS 2 C++ Client Library with ROS Client Library
|
Public Types | |
enum class | EntityType : std::size_t { Subscription } |
Public Member Functions | |
RCLCPP_PUBLIC | SubscriptionIntraProcessBase (rclcpp::Context::SharedPtr context, const std::string &topic_name, const rclcpp::QoS &qos_profile) |
RCLCPP_PUBLIC size_t | get_number_of_ready_guard_conditions () override |
Get the number of ready guard_conditions. More... | |
RCLCPP_PUBLIC void | add_to_wait_set (rcl_wait_set_t *wait_set) override |
Add the Waitable to a wait set. More... | |
bool | is_ready (rcl_wait_set_t *wait_set) override=0 |
Check if the Waitable is ready. More... | |
std::shared_ptr< void > | take_data () override=0 |
Take the data so that it can be consumed with execute . More... | |
std::shared_ptr< void > | take_data_by_entity_id (size_t id) override |
Take the data so that it can be consumed with execute . More... | |
void | execute (std::shared_ptr< void > &data) override=0 |
Execute data that is passed in. More... | |
virtual bool | use_take_shared_method () const =0 |
RCLCPP_PUBLIC const char * | get_topic_name () const |
RCLCPP_PUBLIC QoS | get_actual_qos () const |
void | set_on_ready_callback (std::function< void(size_t, int)> callback) override |
Set a callback to be called when each new message arrives. More... | |
void | clear_on_ready_callback () override |
Unset the callback registered for new messages, if any. | |
![]() | |
virtual RCLCPP_PUBLIC size_t | get_number_of_ready_subscriptions () |
Get the number of ready subscriptions. More... | |
virtual RCLCPP_PUBLIC size_t | get_number_of_ready_timers () |
Get the number of ready timers. More... | |
virtual RCLCPP_PUBLIC size_t | get_number_of_ready_clients () |
Get the number of ready clients. More... | |
virtual RCLCPP_PUBLIC size_t | get_number_of_ready_events () |
Get the number of ready events. More... | |
virtual RCLCPP_PUBLIC size_t | get_number_of_ready_services () |
Get the number of ready services. More... | |
RCLCPP_PUBLIC bool | exchange_in_use_by_wait_set_state (bool in_use_state) |
Exchange the "in use by wait set" state for this timer. More... | |
Protected Member Functions | |
virtual void | trigger_guard_condition ()=0 |
void | invoke_on_new_message () |
Protected Attributes | |
std::recursive_mutex | callback_mutex_ |
std::function< void(size_t)> | on_new_message_callback_ {nullptr} |
size_t | unread_count_ {0} |
rclcpp::GuardCondition | gc_ |
Definition at line 36 of file subscription_intra_process_base.hpp.
|
overridevirtual |
Add the Waitable to a wait set.
[in] | wait_set | A handle to the wait set to add the Waitable to. |
rclcpp::execptions::RCLError | from rcl_wait_set_add_*() |
Implements rclcpp::Waitable.
Definition at line 26 of file subscription_intra_process_base.cpp.
|
overridepure virtual |
Execute data that is passed in.
Before calling this method, the Waitable should be added to a wait set, waited on, and then updated - and the take_data
method should be called.
Example usage:
Implements rclcpp::Waitable.
Implemented in rclcpp::experimental::SubscriptionIntraProcess< MessageT, SubscribedType, SubscribedTypeAlloc, SubscribedTypeDeleter, ROSMessageType, Alloc >.
|
inlineoverridevirtual |
Get the number of ready guard_conditions.
Returns a value of 0 by default. This should be overridden if the Waitable contains one or more guard_conditions.
Reimplemented from rclcpp::Waitable.
Definition at line 59 of file subscription_intra_process_base.hpp.
|
overridepure virtual |
Check if the Waitable is ready.
The input wait set should be the same that was used in a previously call to add_to_wait_set()
. The wait set should also have been previously waited on with rcl_wait()
.
[in] | wait_set | A handle to the wait set the Waitable was previously added to and that has been waited on. |
true
if the Waitable is ready, false
otherwise. Implements rclcpp::Waitable.
Implemented in rclcpp::experimental::SubscriptionIntraProcessBuffer< SubscribedType, Alloc, Deleter, ROSMessageType >, and rclcpp::experimental::SubscriptionIntraProcessBuffer< SubscribedType, std::allocator< SubscribedType >, std::default_delete< SubscribedType >, SubscribedType >.
|
inlineoverridevirtual |
Set a callback to be called when each new message arrives.
The callback receives a size_t which is the number of messages received since the last time this callback was called. Normally this is 1, but can be > 1 if messages were received before any callback was set.
The callback also receives an int identifier argument. This is needed because a Waitable may be composed of several distinct entities, such as subscriptions, services, etc. The application should provide a generic callback function that will be then forwarded by the waitable to all of its entities. Before forwarding, a different value for the identifier argument will be bound to the function. This implies that the provided callback can use the identifier to behave differently depending on which entity triggered the waitable to become ready.
Calling it again will clear any previously set callback.
An exception will be thrown if the callback is not callable.
This function is thread-safe.
If you want more information available in the callback, like the subscription or other information, you may use a lambda with captures or std::bind.
[in] | callback | functor to be called when a new message is received. |
Reimplemented from rclcpp::Waitable.
Definition at line 122 of file subscription_intra_process_base.hpp.
References rclcpp::QoS::depth(), rclcpp::get_logger(), and rclcpp::QoS::history().
|
overridepure virtual |
Take the data so that it can be consumed with execute
.
NOTE: take_data is a partial fix to a larger design issue with the multithreaded executor. This method is likely to be removed when a more permanent fix is implemented. A longterm fix is currently being discussed here: https://github.com/ros2/rclcpp/pull/1276
This method takes the data from the underlying data structure and writes it to the void shared pointer data
that is passed into the method. The data
can then be executed with the execute
method.
Before calling this method, the Waitable should be added to a wait set, waited on, and then updated.
Example usage:
Implements rclcpp::Waitable.
Implemented in rclcpp::experimental::SubscriptionIntraProcess< MessageT, SubscribedType, SubscribedTypeAlloc, SubscribedTypeDeleter, ROSMessageType, Alloc >.
Referenced by take_data_by_entity_id().
|
inlineoverridevirtual |
Take the data so that it can be consumed with execute
.
This function allows to specify an entity ID to take the data from. Entity IDs are identifiers that can be defined by waitable-derived classes that are composed of several distinct entities. The main use-case is in conjunction with the listener APIs.
[in] | id | the id of the entity from which to take |
Reimplemented from rclcpp::Waitable.
Definition at line 72 of file subscription_intra_process_base.hpp.
References take_data().