forked from ros2/rclcpp
-
Notifications
You must be signed in to change notification settings - Fork 3
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 1 commit
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
98 changes: 98 additions & 0 deletions
98
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,98 @@ | ||
| // 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/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 | ||
|
mauropasse marked this conversation as resolved.
|
||
| { | ||
| 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(rmw_listener_event_t event) = 0; | ||
|
mauropasse marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * @brief removes front element from the queue | ||
| * @return iterator | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| void | ||
| pop() = 0; | ||
|
mauropasse marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * @brief gets the front event from the queue | ||
| * @return the front event | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| rmw_listener_event_t | ||
| front() = 0; | ||
|
mauropasse marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * @brief Test whether queue is empty | ||
| * @return true if the queue's size is 0, false otherwise. | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| bool | ||
| empty() = 0; | ||
|
mauropasse marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * @brief gets a queue with all events accumulated on it | ||
| * @return queue with events | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| std::queue<rmw_listener_event_t> | ||
| get_all_events() = 0; | ||
|
mauropasse marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| } // namespace buffers | ||
| } // namespace experimental | ||
| } // namespace rclcpp | ||
|
|
||
| #endif // RCLCPP__EXPERIMENTAL__BUFFERS__EVENTS_QUEUE_HPP_ | ||
116 changes: 116 additions & 0 deletions
116
rclcpp/include/rclcpp/experimental/buffers/performance_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,116 @@ | ||
| // 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__PERFORMANCE_EVENTS_QUEUE_HPP_ | ||
| #define RCLCPP__EXPERIMENTAL__BUFFERS__PERFORMANCE_EVENTS_QUEUE_HPP_ | ||
|
|
||
| #include <queue> | ||
|
|
||
| #include "rclcpp/executors/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 PerformanceEventsQueue : public EventsQueue | ||
|
mauropasse marked this conversation as resolved.
Outdated
|
||
| { | ||
| public: | ||
|
|
||
| using EventQueue = std::queue<rmw_listener_event_t>; | ||
|
mauropasse marked this conversation as resolved.
Outdated
|
||
|
|
||
| RCLCPP_PUBLIC | ||
| ~PerformanceEventsQueue() = default; | ||
|
|
||
| /** | ||
| * @brief push event into the queue | ||
| * @param event The event to push into the queue | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| void | ||
| push(rmw_listener_event_t event) | ||
| { | ||
| event_queue_.push(event); | ||
| } | ||
|
|
||
| /** | ||
| * @brief removes front element from the queue | ||
| * @return iterator | ||
| */ | ||
| 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() | ||
| { | ||
| 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() | ||
| { | ||
| return event_queue_.empty(); | ||
| } | ||
|
|
||
| /** | ||
| * @brief gets a queue with all events on it | ||
| * @return queue with events | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| EventQueue | ||
| get_all_events() | ||
| { | ||
| EventQueue local_queue; | ||
| std::swap(event_queue_, local_queue); | ||
| return local_queue; | ||
| } | ||
|
|
||
| private: | ||
| EventQueue event_queue_; | ||
| }; | ||
|
|
||
| } // namespace buffers | ||
| } // namespace experimental | ||
| } // namespace rclcpp | ||
|
|
||
|
|
||
| #endif // RCLCPP__EXPERIMENTAL__BUFFERS__PERFORMANCE_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
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.