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.
[rclcpp] add WaitSet class and modify entities to work without execut…
…or (ros2#1047) * add rclcpp::GuardCondition wrapping rcl_guard_condition_t Signed-off-by: William Woodall <[email protected]> * WIP second wait set refactor, just guard conditions so far Signed-off-by: William Woodall <[email protected]> * fix typo Signed-off-by: William Woodall <[email protected]> * removing a question/todo, I think this is fine as is Signed-off-by: William Woodall <[email protected]> * added subscriptions and waitable to wait sets Signed-off-by: William Woodall <[email protected]> * improve usability with subscriptions and wait sets Signed-off-by: William Woodall <[email protected]> * adding take to subscription so it can be used without the executor Signed-off-by: William Woodall <[email protected]> * add rclcpp::MessageInfo to replace use of rmw_message_info_t Signed-off-by: William Woodall <[email protected]> * refactor Subscription and Executor so they can be used separately Signed-off-by: William Woodall <[email protected]> * style and cpplint Signed-off-by: William Woodall <[email protected]> * fixup take_serialized() and add tests for it Signed-off-by: William Woodall <[email protected]> * add support for client and service to wait set Signed-off-by: William Woodall <[email protected]> * fix typo Signed-off-by: William Woodall <[email protected]> * fix typo Signed-off-by: William Woodall <[email protected]> * fix review comment Signed-off-by: William Woodall <[email protected]> * add thread-safe wait set policy Signed-off-by: William Woodall <[email protected]> * add check for use with multiple wait set Signed-off-by: William Woodall <[email protected]> * fixup visibility macro usage Signed-off-by: William Woodall <[email protected]> * remove vestigial test case Signed-off-by: William Woodall <[email protected]> * move visibility macro fixes Signed-off-by: William Woodall <[email protected]> * remove vestigial TODO Signed-off-by: William Woodall <[email protected]>
- Loading branch information
Showing
37 changed files
with
4,511 additions
and
139 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
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
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,100 @@ | ||
// 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__GUARD_CONDITION_HPP_ | ||
#define RCLCPP__GUARD_CONDITION_HPP_ | ||
|
||
#include <atomic> | ||
|
||
#include "rcl/guard_condition.h" | ||
|
||
#include "rclcpp/context.hpp" | ||
#include "rclcpp/contexts/default_context.hpp" | ||
#include "rclcpp/macros.hpp" | ||
#include "rclcpp/visibility_control.hpp" | ||
|
||
namespace rclcpp | ||
{ | ||
|
||
/// A condition that can be waited on in a single wait set and asynchronously triggered. | ||
class GuardCondition | ||
{ | ||
public: | ||
RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(GuardCondition) | ||
|
||
// TODO(wjwwood): support custom allocator, maybe restrict to polymorphic allocator | ||
/// Construct the guard condition, optionally specifying which Context to use. | ||
/** | ||
* \param[in] context Optional custom context to be used. | ||
* Defaults to using the global default context singleton. | ||
* Shared ownership of the context is held with the guard condition until | ||
* destruction. | ||
* \throws std::invalid_argument if the context is nullptr. | ||
* \throws rclcpp::exceptions::RCLError based exceptions when underlying | ||
* rcl functions fail. | ||
*/ | ||
RCLCPP_PUBLIC | ||
explicit GuardCondition( | ||
rclcpp::Context::SharedPtr context = | ||
rclcpp::contexts::default_context::get_global_default_context()); | ||
|
||
RCLCPP_PUBLIC | ||
virtual | ||
~GuardCondition(); | ||
|
||
/// Return the context used when creating this guard condition. | ||
RCLCPP_PUBLIC | ||
rclcpp::Context::SharedPtr | ||
get_context() const; | ||
|
||
/// Return the underlying rcl guard condition structure. | ||
RCLCPP_PUBLIC | ||
const rcl_guard_condition_t & | ||
get_rcl_guard_condition() const; | ||
|
||
/// Notify the wait set waiting on this condition, if any, that the condition had been met. | ||
/** | ||
* This function is thread-safe, and may be called concurrently with waiting | ||
* on this guard condition in a wait set. | ||
* | ||
* \throws rclcpp::exceptions::RCLError based exceptions when underlying | ||
* rcl functions fail. | ||
*/ | ||
RCLCPP_PUBLIC | ||
void | ||
trigger(); | ||
|
||
/// Exchange the "in use by wait set" state for this guard condition. | ||
/** | ||
* This is used to ensure this guard condition is not used by multiple | ||
* wait sets at the same time. | ||
* | ||
* \param[in] in_use_state the new state to exchange into the state, true | ||
* indicates it is now in use by a wait set, and false is that it is no | ||
* longer in use by a wait set. | ||
* \returns the previous state. | ||
*/ | ||
RCLCPP_PUBLIC | ||
bool | ||
exchange_in_use_by_wait_set_state(bool in_use_state); | ||
|
||
protected: | ||
rclcpp::Context::SharedPtr context_; | ||
rcl_guard_condition_t rcl_guard_condition_; | ||
std::atomic<bool> in_use_by_wait_set_{false}; | ||
}; | ||
|
||
} // namespace rclcpp | ||
|
||
#endif // RCLCPP__GUARD_CONDITION_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,52 @@ | ||
// 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__MESSAGE_INFO_HPP_ | ||
#define RCLCPP__MESSAGE_INFO_HPP_ | ||
|
||
#include "rmw/types.h" | ||
|
||
#include "rclcpp/visibility_control.hpp" | ||
|
||
namespace rclcpp | ||
{ | ||
|
||
/// Additional meta data about messages taken from subscriptions. | ||
class RCLCPP_PUBLIC MessageInfo | ||
{ | ||
public: | ||
/// Default empty constructor. | ||
MessageInfo() = default; | ||
|
||
/// Conversion constructor, which is intentionally not marked as explicit. | ||
// cppcheck-suppress noExplicitConstructor | ||
MessageInfo(const rmw_message_info_t & rmw_message_info); // NOLINT(runtime/explicit) | ||
|
||
virtual ~MessageInfo(); | ||
|
||
/// Return the message info as the underlying rmw message info type. | ||
const rmw_message_info_t & | ||
get_rmw_message_info() const; | ||
|
||
/// Return the message info as the underlying rmw message info type. | ||
rmw_message_info_t & | ||
get_rmw_message_info(); | ||
|
||
private: | ||
rmw_message_info_t rmw_message_info_; | ||
}; | ||
|
||
} // namespace rclcpp | ||
|
||
#endif // RCLCPP__MESSAGE_INFO_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
Oops, something went wrong.