22 #include "rcl/error_handling.h"
25 #include "rmw/impl/cpp/demangle.hpp"
27 #include "rclcpp/detail/cpp_callback_trampoline.hpp"
28 #include "rclcpp/event_handler.hpp"
29 #include "rclcpp/exceptions/exceptions.hpp"
30 #include "rclcpp/logging.hpp"
31 #include "rclcpp/timer.hpp"
36 UnsupportedEventTypeException::UnsupportedEventTypeException(
38 const rcl_error_state_t * error_state,
39 const std::string & prefix)
40 : UnsupportedEventTypeException(exceptions::RCLErrorBase(ret, error_state), prefix)
43 UnsupportedEventTypeException::UnsupportedEventTypeException(
44 const exceptions::RCLErrorBase & base_exc,
45 const std::string & prefix)
46 : exceptions::RCLErrorBase(base_exc),
47 std::runtime_error(prefix + (prefix.empty() ?
"" :
": ") + base_exc.formatted_message)
50 EventHandlerBase::~EventHandlerBase()
53 RCUTILS_LOG_ERROR_NAMED(
55 "Error in destruction of rcl event handle: %s", rcl_get_error_string().str);
62 EventHandlerBase::get_number_of_ready_events()
73 exceptions::throw_from_rcl_error(ret,
"Couldn't add event to wait set");
81 return wait_set.
events[wait_set_event_index_] == &event_handle_;
85 EventHandlerBase::set_on_new_event_callback(
86 rcl_event_callback_t callback,
87 const void * user_data)
95 using rclcpp::exceptions::throw_from_rcl_error;
96 throw_from_rcl_error(ret,
"failed to set the on new message callback for Event");
101 EventHandlerBase::set_on_ready_callback(std::function<
void(
size_t,
int)> callback)
104 throw std::invalid_argument(
105 "The callback passed to set_on_ready_callback "
111 [callback,
this](
size_t number_of_events) {
113 callback(number_of_events,
static_cast<int>(EntityType::Event));
114 }
catch (
const std::exception & exception) {
118 "rclcpp::EventHandlerBase@" <<
this <<
119 " caught " << rmw::impl::cpp::demangle(exception) <<
120 " exception in user-provided callback for the 'on ready' callback: " <<
125 "rclcpp::EventHandlerBase@" <<
this <<
126 " caught unhandled exception in user-provided callback " <<
127 "for the 'on ready' callback");
131 std::lock_guard<std::recursive_mutex> lock(on_new_event_callback_mutex_);
136 set_on_new_event_callback(
137 rclcpp::detail::cpp_callback_trampoline<decltype(new_callback),
const void *,
size_t>,
138 static_cast<const void *
>(&new_callback));
141 on_new_event_callback_ = new_callback;
144 set_on_new_event_callback(
145 rclcpp::detail::cpp_callback_trampoline<
146 decltype(on_new_event_callback_),
const void *,
size_t>,
147 static_cast<const void *
>(&on_new_event_callback_));
151 EventHandlerBase::clear_on_ready_callback()
153 std::lock_guard<std::recursive_mutex> lock(on_new_event_callback_mutex_);
154 if (on_new_event_callback_) {
155 set_on_new_event_callback(
nullptr,
nullptr);
156 on_new_event_callback_ =
nullptr;
160 std::vector<std::shared_ptr<rclcpp::TimerBase>>
161 EventHandlerBase::get_timers()
const
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_event_set_callback(const rcl_event_t *event, rcl_event_callback_t callback, const void *user_data)
Set the callback function for the event.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_event_fini(rcl_event_t *event)
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.
Container for subscription's, guard condition's, etc to be waited on.
const rcl_event_t ** events
Storage for event pointers.
#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_event(rcl_wait_set_t *wait_set, const rcl_event_t *event, size_t *index)
Store a pointer to the event in the next empty spot in the set.