mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
coroutine_callback_helpers.hpp
1#ifndef MRS_LIB_INTERNAL_COROUTINE_CALLBACK_HELPERS_HPP_
2#define MRS_LIB_INTERNAL_COROUTINE_CALLBACK_HELPERS_HPP_
3
4
5#include <rclcpp/callback_group.hpp>
6
7
8namespace mrs_lib::internal
9{
10
21 inline bool is_callback_group_coro_compatible(const std::shared_ptr<rclcpp::CallbackGroup>& callback_group)
22 {
23 return callback_group->type() == rclcpp::CallbackGroupType::Reentrant;
24 }
25
36 inline void require_callback_group_coro_compatible(const std::shared_ptr<rclcpp::CallbackGroup>& callback_group)
37 {
38 if (callback_group == nullptr || callback_group->type() != rclcpp::CallbackGroupType::Reentrant)
39 {
40 std::string msg = "Coroutine callbacks must be used with reentrant callback group.";
41 RCLCPP_ERROR(rclcpp::get_logger("mrs_lib"), "%s", msg.c_str());
42 throw std::logic_error(msg);
43 }
44 }
45
46} // namespace mrs_lib::internal
47
48#endif // MRS_LIB_INTERNAL_COROUTINE_CALLBACK_HELPERS_HPP_