1#ifndef MRS_LIB_INTERNAL_COROUTINE_CALLBACK_HELPERS_HPP_
2#define MRS_LIB_INTERNAL_COROUTINE_CALLBACK_HELPERS_HPP_
9#include <rclcpp/callback_group.hpp>
10#include <rclcpp/logger.hpp>
11#include <rclcpp/logging.hpp>
13#include "mrs_lib/coro/runners.hpp"
17namespace mrs_lib::internal
30 inline bool is_callback_group_coro_compatible(
const std::shared_ptr<rclcpp::CallbackGroup>& callback_group)
32 if (callback_group !=
nullptr)
34 return callback_group->type() == rclcpp::CallbackGroupType::Reentrant;
51 inline void require_callback_group_coro_compatible(
const std::shared_ptr<rclcpp::CallbackGroup>& callback_group)
53 if (!is_callback_group_coro_compatible(callback_group))
55 std::string msg =
"Coroutine callbacks must be used with reentrant callback group.";
56 RCLCPP_ERROR(rclcpp::get_logger(
"mrs_lib"),
"%s", msg.c_str());
57 throw std::logic_error(std::move(msg));
65 template <
typename... Args>
66 requires((!std::is_reference_v<Args>) && ...)
67 auto get_detached_coro_callback_launcher(
CoroCallback<
void(Args...)> callback, std::shared_ptr<rclcpp::CallbackGroup> callback_group)
69 require_callback_group_coro_compatible(callback_group);
73 template <
typename... Args>
74 requires((!std::is_reference_v<Args>) && ...)
75 auto get_detached_coro_callback_launcher(
CoroCallback<
void(Args...)> callback, NoCallbackGroupTag)
77 return std::function([callback](Args... args) { coro::internal::start_task(callback, std::forward<Args>(args)...); });
Base template for CoroCallback.
Definition callback.hpp:166
CoroCallback(auto, mrs_lib::Task< R >(*)(Params...) noexcept(Noexcept), Args &&...) -> CoroCallback< internal::CallbackSignatureT< R, meta::TypeList< Params... >, meta::TypeList< Args... > > >
Deduction guide for free functions.
Definition coroutine_callback_helpers.hpp:62