17 #include "rclcpp/guard_condition.hpp"
19 #include "rclcpp/exceptions.hpp"
20 #include "rclcpp/logging.hpp"
26 rclcpp::Context::SharedPtr context,
31 throw std::invalid_argument(
"context argument unexpectedly nullptr");
34 &this->rcl_guard_condition_,
35 context_->get_rcl_context().get(),
36 guard_condition_options);
38 rclcpp::exceptions::throw_from_rcl_error(ret,
"failed to create guard condition");
42 GuardCondition::~GuardCondition()
47 rclcpp::exceptions::throw_from_rcl_error(ret);
48 }
catch (
const std::exception & exception) {
51 "failed to finalize guard condition: %s", exception.what());
56 rclcpp::Context::SharedPtr
65 return rcl_guard_condition_;
71 return rcl_guard_condition_;
77 std::lock_guard<std::recursive_mutex> lock(reentrant_mutex_);
79 if (on_trigger_callback_) {
80 on_trigger_callback_(1);
84 rclcpp::exceptions::throw_from_rcl_error(ret);
93 return in_use_by_wait_set_.exchange(in_use_state);
99 std::lock_guard<std::recursive_mutex> lock(reentrant_mutex_);
102 if (wait_set != wait_set_) {
103 throw std::runtime_error(
"guard condition has already been added to a wait set.");
106 wait_set_ = wait_set;
111 rclcpp::exceptions::throw_from_rcl_error(
112 ret,
"failed to add guard condition to wait set");
117 GuardCondition::set_on_trigger_callback(std::function<
void(
size_t)> callback)
119 std::lock_guard<std::recursive_mutex> lock(reentrant_mutex_);
122 on_trigger_callback_ = callback;
125 callback(unread_count_);
131 on_trigger_callback_ =
nullptr;
RCLCPP_PUBLIC void trigger()
Notify the wait set waiting on this condition, if any, that the condition had been met.
RCLCPP_PUBLIC rcl_guard_condition_t & get_rcl_guard_condition()
Return the underlying rcl guard condition structure.
RCLCPP_PUBLIC void add_to_wait_set(rcl_wait_set_t *wait_set)
Adds the guard condition to a waitset.
RCLCPP_PUBLIC bool exchange_in_use_by_wait_set_state(bool in_use_state)
Exchange the "in use by wait set" state for this guard condition.
RCLCPP_PUBLIC rclcpp::Context::SharedPtr get_context() const
Return the context used when creating this guard condition.
RCLCPP_PUBLIC GuardCondition(rclcpp::Context::SharedPtr context=rclcpp::contexts::get_global_default_context(), rcl_guard_condition_options_t guard_condition_options=rcl_guard_condition_get_default_options())
Construct the guard condition, optionally specifying which Context to use.
RCL_PUBLIC RCL_WARN_UNUSED rcl_guard_condition_t rcl_get_zero_initialized_guard_condition(void)
Return a rcl_guard_condition_t struct with members set to NULL.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_trigger_guard_condition(rcl_guard_condition_t *guard_condition)
Trigger a rcl guard condition.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_guard_condition_init(rcl_guard_condition_t *guard_condition, rcl_context_t *context, const rcl_guard_condition_options_t options)
Initialize a rcl guard_condition.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_guard_condition_fini(rcl_guard_condition_t *guard_condition)
Finalize a rcl_guard_condition_t.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCLCPP_PUBLIC Logger get_logger(const std::string &name)
Return a named logger.
Options available for a rcl guard condition.
Handle for a rcl guard condition.
Container for subscription's, guard condition's, etc to be waited on.
#define RCL_RET_OK
Success return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_wait_set_add_guard_condition(rcl_wait_set_t *wait_set, const rcl_guard_condition_t *guard_condition, size_t *index)
Store a pointer to the guard condition in the next empty spot in the set.