forked from ros2/rclcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ros2#23 from alsora/asoragna/cleanup-and-test
Asoragna/cleanup and test
- Loading branch information
Showing
13 changed files
with
285 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2020 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RCLCPP__EXECUTORS__EVENT_WAITABLE_HPP_ | ||
#define RCLCPP__EXECUTORS__EVENT_WAITABLE_HPP_ | ||
|
||
#include "rclcpp/waitable.hpp" | ||
|
||
namespace rclcpp | ||
{ | ||
namespace executors | ||
{ | ||
|
||
/** | ||
* @brief This class provides a wrapper around the waitable object, that is | ||
* meant to be used with the EventsExecutor. | ||
* The waitset related methods are stubbed out as they should not be called. | ||
* Nodes who want to implement a custom EventWaitable, can derive from this class and override | ||
* the execute function. | ||
*/ | ||
class EventWaitable : public rclcpp::Waitable | ||
{ | ||
public: | ||
RCLCPP_SMART_PTR_DEFINITIONS(EventWaitable) | ||
|
||
// Constructor | ||
RCLCPP_PUBLIC | ||
EventWaitable() = default; | ||
|
||
// Destructor | ||
RCLCPP_PUBLIC | ||
virtual ~EventWaitable() = default; | ||
|
||
// Executing an EventWaitable is a no-op. | ||
// Derive from this class to implement execute function. | ||
RCLCPP_PUBLIC | ||
virtual void | ||
execute() = 0; | ||
|
||
// Stub API: not used by EventsExecutor | ||
RCLCPP_PUBLIC | ||
bool | ||
is_ready(rcl_wait_set_t * wait_set) final | ||
{ | ||
(void)wait_set; | ||
throw std::runtime_error("EventWaitable can't be checked if it's ready"); | ||
return false; | ||
} | ||
|
||
// Stub API: not used by EventsExecutor | ||
RCLCPP_PUBLIC | ||
bool | ||
add_to_wait_set(rcl_wait_set_t * wait_set) final | ||
{ | ||
(void)wait_set; | ||
throw std::runtime_error("EventWaitable can't be added to a wait_set"); | ||
return false; | ||
} | ||
}; | ||
|
||
} // namespace executors | ||
} // namespace rclcpp | ||
|
||
#endif // RCLCPP__EXECUTORS__EVENT_WAITABLE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
rclcpp/include/rclcpp/executors/events_executor_notify_waitable.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2020 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RCLCPP__EXECUTORS__EVENTS_EXECUTOR_NOTIFY_WAITABLE_HPP_ | ||
#define RCLCPP__EXECUTORS__EVENTS_EXECUTOR_NOTIFY_WAITABLE_HPP_ | ||
|
||
#include <list> | ||
|
||
#include "rcl/guard_condition.h" | ||
#include "rclcpp/executors/event_waitable.hpp" | ||
|
||
namespace rclcpp | ||
{ | ||
namespace executors | ||
{ | ||
|
||
/** | ||
* @brief This class provides an EventWaitable that allows to | ||
* wake up an EventsExecutor when a guard condition is notified. | ||
*/ | ||
class EventsExecutorNotifyWaitable final : public EventWaitable | ||
{ | ||
public: | ||
RCLCPP_SMART_PTR_DEFINITIONS(EventsExecutorNotifyWaitable) | ||
|
||
// Constructor | ||
RCLCPP_PUBLIC | ||
EventsExecutorNotifyWaitable() = default; | ||
|
||
// Destructor | ||
RCLCPP_PUBLIC | ||
virtual ~EventsExecutorNotifyWaitable() | ||
{ | ||
if (on_destruction_callback_) { | ||
on_destruction_callback_(this); | ||
} | ||
} | ||
|
||
// The function is a no-op, since we only care of waking up the executor | ||
RCLCPP_PUBLIC | ||
void | ||
execute() override | ||
{} | ||
|
||
RCLCPP_PUBLIC | ||
void | ||
add_guard_condition(rcl_guard_condition_t * guard_condition) | ||
{ | ||
notify_guard_conditions_.push_back(guard_condition); | ||
} | ||
|
||
RCLCPP_PUBLIC | ||
void | ||
set_events_executor_callback( | ||
const rclcpp::executors::EventsExecutor * executor, | ||
ExecutorEventCallback executor_callback) const override | ||
{ | ||
for (auto gc : notify_guard_conditions_) { | ||
rcl_ret_t ret = rcl_guard_condition_set_events_executor_callback( | ||
executor, | ||
executor_callback, | ||
this, | ||
gc, | ||
false); | ||
|
||
if (RCL_RET_OK != ret) { | ||
throw std::runtime_error("Couldn't set guard condition callback"); | ||
} | ||
} | ||
} | ||
|
||
private: | ||
std::list<rcl_guard_condition_t *> notify_guard_conditions_; | ||
}; | ||
|
||
} // namespace executors | ||
} // namespace rclcpp | ||
|
||
#endif // RCLCPP__EXECUTORS__EVENTS_EXECUTOR_NOTIFY_WAITABLE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.