forked from ros2/rclcpp
-
Notifications
You must be signed in to change notification settings - Fork 2
Add events queue abstract class and implem #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
irobot-ros
merged 9 commits into
irobot-ros:irobot/add-events-executor
from
mauropasse:mauro/add-events-queue-class-2
Feb 8, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a9bfc77
Add events queue abstract class and implem
5b568fb
Apply PR suggestions
f73cbdd
Fix ctests
9c5f037
EntitiesCollector not needed on events_queue
780af84
Add BoundedEventsQueue
0317e77
Add unit tests for Simple and Bounded queues
5780ccf
Set size limit in constructor
6fb2463
Test all events queue APIs
c4ac6f9
Remove BoundedQueue, not ready yet for this
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
109 changes: 109 additions & 0 deletions
109
rclcpp/include/rclcpp/experimental/buffers/events_queue.hpp
This file contains hidden or 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,109 @@ | ||
| // Copyright 2021 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__EXPERIMENTAL__BUFFERS__EVENTS_QUEUE_HPP_ | ||
| #define RCLCPP__EXPERIMENTAL__BUFFERS__EVENTS_QUEUE_HPP_ | ||
|
|
||
| #include <queue> | ||
|
|
||
| #include "rclcpp/executors/events_executor_entities_collector.hpp" | ||
| #include "rclcpp/macros.hpp" | ||
|
|
||
| #include "rmw/listener_event_types.h" | ||
|
|
||
| namespace rclcpp | ||
| { | ||
| namespace experimental | ||
| { | ||
| namespace buffers | ||
| { | ||
|
|
||
| /** | ||
| * @brief This abstract class is intended to be used as | ||
| * a wrapper around a queue. The derived classes should chose | ||
| * which container to use and the strategies for push and prune | ||
| * events from the queue. | ||
| */ | ||
| class EventsQueue | ||
| { | ||
| public: | ||
| RCLCPP_SMART_PTR_DEFINITIONS(EventsQueue) | ||
|
|
||
| /** | ||
| * @brief Destruct the object. | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual ~EventsQueue() = default; | ||
|
|
||
| /** | ||
| * @brief push event into the queue | ||
| * @param event The event to push into the queue | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| void | ||
| push(const rmw_listener_event_t & event) = 0; | ||
|
|
||
| /** | ||
| * @brief removes front element from the queue | ||
| * The element removed is the "oldest" element in the queue whose | ||
| * value can be retrieved by calling member front(). | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| void | ||
| pop() = 0; | ||
mauropasse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * @brief gets the front event from the queue | ||
| * @return the front event | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| rmw_listener_event_t | ||
| front() const = 0; | ||
|
|
||
| /** | ||
| * @brief Test whether queue is empty | ||
| * @return true if the queue's size is 0, false otherwise. | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| bool | ||
| empty() const = 0; | ||
|
|
||
| /** | ||
| * @brief Initializes the queue | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| void | ||
| init() = 0; | ||
|
|
||
| /** | ||
| * @brief gets a queue with all events accumulated on it since | ||
| * the last call. The member queue is empty when the call returns. | ||
| * @return queue with events | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| std::queue<rmw_listener_event_t> | ||
| get_all_events() = 0; | ||
mauropasse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| } // namespace buffers | ||
| } // namespace experimental | ||
| } // namespace rclcpp | ||
|
|
||
| #endif // RCLCPP__EXPERIMENTAL__BUFFERS__EVENTS_QUEUE_HPP_ | ||
130 changes: 130 additions & 0 deletions
130
rclcpp/include/rclcpp/experimental/buffers/simple_events_queue.hpp
This file contains hidden or 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,130 @@ | ||
| // Copyright 2021 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__EXPERIMENTAL__BUFFERS__SIMPLE_EVENTS_QUEUE_HPP_ | ||
| #define RCLCPP__EXPERIMENTAL__BUFFERS__SIMPLE_EVENTS_QUEUE_HPP_ | ||
|
|
||
| #include <queue> | ||
| #include <utility> | ||
|
|
||
| #include "rclcpp/experimental/buffers/events_queue.hpp" | ||
|
|
||
| namespace rclcpp | ||
| { | ||
| namespace experimental | ||
| { | ||
| namespace buffers | ||
| { | ||
|
|
||
| /** | ||
| * @brief This class provides a simple queue implementation | ||
| * based on a std::queue. As the objective is having a CPU peformant | ||
| * queue, it does not performs any checks about the size of | ||
| * the queue, so the queue size could grow unbounded. | ||
| * It does not implement any pruning mechanisms. | ||
| */ | ||
| class SimpleEventsQueue : public EventsQueue | ||
| { | ||
| public: | ||
| RCLCPP_PUBLIC | ||
| ~SimpleEventsQueue() = default; | ||
|
|
||
| /** | ||
| * @brief push event into the queue | ||
| * @param event The event to push into the queue | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| void | ||
| push(const rmw_listener_event_t & event) | ||
| { | ||
| event_queue_.push(event); | ||
| } | ||
|
|
||
| /** | ||
| * @brief removes front element from the queue | ||
| * The element removed is the "oldest" element in the queue whose | ||
| * value can be retrieved by calling member front(). | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| void | ||
| pop() | ||
| { | ||
| event_queue_.pop(); | ||
| } | ||
|
|
||
| /** | ||
| * @brief gets the front event from the queue | ||
| * @return the front event | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| rmw_listener_event_t | ||
| front() const | ||
| { | ||
| return event_queue_.front(); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Test whether queue is empty | ||
| * @return true if the queue's size is 0, false otherwise. | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| bool | ||
| empty() const | ||
| { | ||
| return event_queue_.empty(); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Initializes the queue | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| void | ||
| init() | ||
| { | ||
| // Make sure the queue is empty when we start | ||
| std::queue<rmw_listener_event_t> local_queue; | ||
| std::swap(event_queue_, local_queue); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @brief gets a queue with all events accumulated on it since | ||
| * the last call. The member queue is empty when the call returns. | ||
| * @return std::queue with events | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| std::queue<rmw_listener_event_t> | ||
| get_all_events() | ||
| { | ||
| std::queue<rmw_listener_event_t> local_queue; | ||
| std::swap(event_queue_, local_queue); | ||
| return local_queue; | ||
| } | ||
|
|
||
| private: | ||
| std::queue<rmw_listener_event_t> event_queue_; | ||
| }; | ||
|
|
||
| } // namespace buffers | ||
| } // namespace experimental | ||
| } // namespace rclcpp | ||
|
|
||
|
|
||
| #endif // RCLCPP__EXPERIMENTAL__BUFFERS__SIMPLE_EVENTS_QUEUE_HPP_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.