Template Class WaitResult
Defined in File wait_result.hpp
Class Documentation
-
template<class WaitSetT>
class WaitResult Interface for introspecting a wait set after waiting on it.
This class:
provides the result of waiting, i.e. ready, timeout, or empty, and
holds the ownership of the entities of the wait set, if needed, and
provides the necessary information for iterating over the wait set.
This class is only valid as long as the wait set which created it is valid, and it must be deleted before the wait set is deleted, as it contains a back reference to the wait set.
An instance of this, which is returned from rclcpp::WaitSetTemplate::wait(), will cause the wait set to keep ownership of the entities because it only holds a reference to the sequences of them, rather than taking a copy. Also, in the thread-safe case, an instance of this will cause the wait set, to block calls which modify the sequences of the entities, e.g. add/remove guard condition or subscription methods.
- Template Parameters:
WaitSetT – The wait set type which created this class.
Public Functions
-
inline WaitResultKind kind() const
Return the kind of the WaitResult.
-
inline const WaitSetT &get_wait_set() const
Return the rcl wait set.
- Throws:
std::runtime_error – if the class cannot access wait set when the result was not ready
- Returns:
const rcl wait set.
-
inline WaitSetT &get_wait_set()
Return the rcl wait set.
- Throws:
std::runtime_error – if the class cannot access wait set when the result was not ready
- Returns:
rcl wait set.
-
inline WaitResult(WaitResult &&other) noexcept
-
inline ~WaitResult()
-
inline std::pair<std::shared_ptr<rclcpp::TimerBase>, size_t> peek_next_ready_timer(size_t start_index = 0)
Get the next ready timer and its index in the wait result, but do not clear it.
The returned timer is not cleared automatically, as it the case with the other next_ready_*()-like functions. Instead, this function returns the timer and the index that identifies it in the wait result, so that it can be cleared (marked as taken or used) in a separate step with clear_timer_with_index(). This is necessary in some multi-threaded executor implementations.
If the timer is not cleared using the index, subsequent calls to this function will return the same timer.
If there is no ready timer, then nullptr will be returned and the index will be invalid and should not be used.
- Parameters:
start_index – [in] index at which to start searching for the next ready timer in the wait result. If the start_index is out of bounds for the list of timers in the wait result, then {nullptr, start_index} will be returned. Defaults to 0.
- Returns:
next ready timer pointer and its index in the wait result, or {nullptr, start_index} if none was found.
-
inline void clear_timer_with_index(size_t index)
Clear the timer at the given index.
Clearing a timer from the wait result prevents it from being returned by the peek_next_ready_timer() on subsequent calls.
The index should come from the peek_next_ready_timer() function, and should only be used with this function if the timer pointer was valid.
- Throws:
std::out_of_range – if the given index is out of range
-
inline std::shared_ptr<rclcpp::SubscriptionBase> next_ready_subscription()
Get the next ready subscription, clearing it from the wait result.
-
inline std::shared_ptr<rclcpp::ServiceBase> next_ready_service()
Get the next ready service, clearing it from the wait result.
-
inline std::shared_ptr<rclcpp::ClientBase> next_ready_client()
Get the next ready client, clearing it from the wait result.
Public Static Functions
-
static inline WaitResult from_ready_wait_result_kind(WaitSetT &wait_set)
Create WaitResult from a “ready” result.
- Parameters:
wait_set – [in] A reference to the wait set, which this class will keep for the duration of its lifetime.
- Returns:
a WaitResult from a “ready” result.
-
static inline WaitResult from_timeout_wait_result_kind()
Create WaitResult from a “timeout” result.
-
static inline WaitResult from_empty_wait_result_kind()
Create WaitResult from a “empty” result.