Skip to content

Commit

Permalink
Fix CallbackWrapper class for the Rolling release
Browse files Browse the repository at this point in the history
* change to get building with latest rclcpp
* implement pure virtual waitable functions as in ros2/system_tests#548
* uncrustify fixes
Author: Henry Moore <[email protected]>
  • Loading branch information
svwilliams committed Sep 18, 2024
1 parent ff41ec0 commit 0476592
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions fuse_core/include/fuse_core/callback_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class CallbackAdapter : public rclcpp::Waitable
/**
* @brief tell the CallbackGroup that this waitable is ready to execute anything
*/
bool is_ready(rcl_wait_set_t * wait_set) override;
bool is_ready(rcl_wait_set_t const & wait_set) override;


/**
Expand All @@ -175,18 +175,25 @@ class CallbackAdapter : public rclcpp::Waitable
waitable_ptr = std::make_shared<CallbackWrapper>();
node->get_node_waitables_interface()->add_waitable(waitable_ptr, (rclcpp::CallbackGroup::SharedPtr) nullptr);
*/
void add_to_wait_set(rcl_wait_set_t * wait_set) override;
void add_to_wait_set(rcl_wait_set_t & wait_set) override;

std::shared_ptr<void> take_data() override;

void execute(std::shared_ptr<void> & data) override;
void execute(std::shared_ptr<void> const & data) override;

void addCallback(const std::shared_ptr<CallbackWrapperBase> & callback);

void addCallback(std::shared_ptr<CallbackWrapperBase> && callback);

void removeAllCallbacks();

void set_on_ready_callback(std::function<void(size_t, int)>) override {}
void clear_on_ready_callback() override {}
std::shared_ptr<void> take_data_by_entity_id(size_t) override
{
return nullptr;
}

private:
rcl_guard_condition_t gc_; //!< guard condition to drive the waitable

Expand Down
8 changes: 4 additions & 4 deletions fuse_core/src/callback_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ size_t CallbackAdapter::get_number_of_ready_guard_conditions() {return 1;}
/**
* @brief tell the CallbackGroup that this waitable is ready to execute anything
*/
bool CallbackAdapter::is_ready(rcl_wait_set_t * wait_set)
bool CallbackAdapter::is_ready(rcl_wait_set_t const & wait_set)
{
(void) wait_set;
return !callback_queue_.empty();
Expand All @@ -71,9 +71,9 @@ bool CallbackAdapter::is_ready(rcl_wait_set_t * wait_set)
waitable_ptr = std::make_shared<CallbackAdapter>();
node->get_node_waitables_interface()->add_waitable(waitable_ptr, (rclcpp::CallbackGroup::SharedPtr) nullptr);
*/
void CallbackAdapter::add_to_wait_set(rcl_wait_set_t * wait_set)
void CallbackAdapter::add_to_wait_set(rcl_wait_set_t & wait_set)
{
if (RCL_RET_OK != rcl_wait_set_add_guard_condition(wait_set, &gc_, NULL)) {
if (RCL_RET_OK != rcl_wait_set_add_guard_condition(&wait_set, &gc_, NULL)) {
RCLCPP_WARN(rclcpp::get_logger("fuse"), "Could not add callback waitable to wait set.");
}
}
Expand Down Expand Up @@ -107,7 +107,7 @@ std::shared_ptr<void> CallbackAdapter::take_data()
* @brief hook that allows the rclcpp::waitables interface to run the next callback
*
*/
void CallbackAdapter::execute(std::shared_ptr<void> & data)
void CallbackAdapter::execute(std::shared_ptr<void> const & data)
{
if (!data) {
throw std::runtime_error("'data' is empty");
Expand Down

0 comments on commit 0476592

Please sign in to comment.