-
Notifications
You must be signed in to change notification settings - Fork 499
add content-filtered-topic interfaces #1561
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
Changes from all commits
424a981
0444bd2
1a57ae5
3c94995
f2460fa
323b919
95a4428
0124396
4dc661b
771e5a0
0bf1f52
b044aa2
43c59e8
e72216e
88320c9
98e3872
307b8d4
e37c626
e965be7
556215b
7b362b5
1b232ae
50068a7
98f2f66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.12) | |
|
|
||
| project(rclcpp) | ||
|
|
||
| option(DEFINE_CONTENT_FILTER "Content filter feature support" ON) | ||
| if(DEFINE_CONTENT_FILTER) | ||
| add_definitions(-DCONTENT_FILTER_ENABLE) | ||
| endif() | ||
|
|
||
|
Comment on lines
+5
to
+9
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this will be always on as ROS 2 rclcpp library, but user explicitly enable this when they want to use ContentFitleredTopic, otherwise build fails. my understanding correct? @wjwwood could we have feedback on this, if this is what we want?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wjwwood friendly ping.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this doesn't really help much, particularly if we don't have equivalent flags in rcl/rmw.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @ivanpauno mentioned, this isn't really accomplishing what we wanted, so let's just remove it and provide access to CFT uniformly for now. We'll just have to document the known issues. |
||
| find_package(Threads REQUIRED) | ||
|
|
||
| find_package(ament_cmake_ros REQUIRED) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| #include "rclcpp/qos.hpp" | ||
| #include "rclcpp/qos_event.hpp" | ||
| #include "rclcpp/serialized_message.hpp" | ||
| #include "rclcpp/subscription_content_filter_options.hpp" | ||
| #include "rclcpp/type_support_decl.hpp" | ||
| #include "rclcpp/visibility_control.hpp" | ||
|
|
||
|
|
@@ -491,6 +492,42 @@ class SubscriptionBase : public std::enable_shared_from_this<SubscriptionBase> | |
| event_handlers_[event_type]->clear_on_ready_callback(); | ||
| } | ||
|
|
||
| #ifdef CONTENT_FILTER_ENABLE | ||
| /// Check if content filtered topic feature of the subscription instance is enabled. | ||
| /** | ||
| * \return boolean flag indicating if the content filtered topic of this subscription is enabled. | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| bool | ||
| is_cft_enabled() const; | ||
|
|
||
| /// Set the filter expression and expression parameters for the subscription. | ||
fujitatomoya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * \param[in] filter_expression A filter expression to set. | ||
| * \sa ContentFilterOptions::filter_expression | ||
| * An empty string ("") will clear the content filter setting of the subscription. | ||
| * \param[in] expression_parameters Array of expression parameters to set. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The size of the vector have a limitation which is described in Do we need to describe this limitation here ?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we do, since this would be the 1st place for user application.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used the '\sa ContentFilterOptions::expression_parameters' for |
||
| * \sa ContentFilterOptions::expression_parameters | ||
| * \throws RCLBadAlloc if memory cannot be allocated | ||
| * \throws RCLError if an unexpect error occurs | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| void | ||
| set_content_filter( | ||
| const std::string & filter_expression, | ||
| const std::vector<std::string> & expression_parameters = {}); | ||
|
|
||
| /// Get the filter expression and expression parameters for the subscription. | ||
| /** | ||
| * \return rclcpp::ContentFilterOptions The content filter options to get. | ||
| * \throws RCLBadAlloc if memory cannot be allocated | ||
| * \throws RCLError if an unexpect error occurs | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| rclcpp::ContentFilterOptions | ||
| get_content_filter() const; | ||
| #endif // CONTENT_FILTER_ENABLE | ||
|
|
||
| protected: | ||
| template<typename EventCallbackT> | ||
| void | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright 2022 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__SUBSCRIPTION_CONTENT_FILTER_OPTIONS_HPP_ | ||
| #define RCLCPP__SUBSCRIPTION_CONTENT_FILTER_OPTIONS_HPP_ | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace rclcpp | ||
| { | ||
|
|
||
| /// Options to configure content filtered topic in the subscription. | ||
| struct ContentFilterOptions | ||
| { | ||
| /// Filter expression is similar to the WHERE part of an SQL clause. | ||
| std::string filter_expression; | ||
| /** | ||
| * Expression parameters is the tokens placeholder ‘parameters’ (i.e., "%n" tokens begin from 0) | ||
| * in the filter_expression. The maximum expression_parameters size is 100. | ||
| */ | ||
| std::vector<std::string> expression_parameters; | ||
| }; | ||
|
|
||
| } // namespace rclcpp | ||
|
|
||
| #endif // RCLCPP__SUBSCRIPTION_CONTENT_FILTER_OPTIONS_HPP_ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ | |
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| #include "rcpputils/scope_exit.hpp" | ||
|
|
||
| #include "rclcpp/exceptions.hpp" | ||
| #include "rclcpp/expand_topic_or_service_name.hpp" | ||
| #include "rclcpp/experimental/intra_process_manager.hpp" | ||
|
|
@@ -354,3 +356,93 @@ SubscriptionBase::set_on_new_message_callback( | |
| throw_from_rcl_error(ret, "failed to set the on new message callback for subscription"); | ||
| } | ||
| } | ||
|
|
||
| #ifdef CONTENT_FILTER_ENABLE | ||
| bool | ||
| SubscriptionBase::is_cft_enabled() const | ||
| { | ||
| return rcl_subscription_is_cft_enabled(subscription_handle_.get()); | ||
| } | ||
|
|
||
| void | ||
| SubscriptionBase::set_content_filter( | ||
| const std::string & filter_expression, | ||
| const std::vector<std::string> & expression_parameters) | ||
| { | ||
| rcl_subscription_content_filter_options_t options = | ||
| rcl_get_zero_initialized_subscription_content_filter_options(); | ||
|
|
||
| std::vector<const char *> cstrings = | ||
| get_c_vector_string(expression_parameters); | ||
| rcl_ret_t ret = rcl_subscription_content_filter_options_init( | ||
| subscription_handle_.get(), | ||
| get_c_string(filter_expression), | ||
| cstrings.size(), | ||
| cstrings.data(), | ||
| &options); | ||
| if (RCL_RET_OK != ret) { | ||
| rclcpp::exceptions::throw_from_rcl_error( | ||
| ret, "failed to init subscription content_filtered_topic option"); | ||
| } | ||
| RCPPUTILS_SCOPE_EXIT( | ||
| { | ||
| rcl_ret_t ret = rcl_subscription_content_filter_options_fini( | ||
| subscription_handle_.get(), &options); | ||
| if (RCL_RET_OK != ret) { | ||
| RCLCPP_ERROR( | ||
| rclcpp::get_logger("rclcpp"), | ||
| "Failed to fini subscription content_filtered_topic option: %s", | ||
| rcl_get_error_string().str); | ||
| rcl_reset_error(); | ||
| } | ||
| }); | ||
|
|
||
| ret = rcl_subscription_set_content_filter( | ||
| subscription_handle_.get(), | ||
| &options); | ||
|
|
||
| if (RCL_RET_OK != ret) { | ||
| rclcpp::exceptions::throw_from_rcl_error(ret, "failed to set cft expression parameters"); | ||
| } | ||
| } | ||
|
|
||
| rclcpp::ContentFilterOptions | ||
| SubscriptionBase::get_content_filter() const | ||
| { | ||
| rclcpp::ContentFilterOptions ret_options; | ||
| rcl_subscription_content_filter_options_t options = | ||
| rcl_get_zero_initialized_subscription_content_filter_options(); | ||
|
|
||
| rcl_ret_t ret = rcl_subscription_get_content_filter( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could cache in |
||
| subscription_handle_.get(), | ||
| &options); | ||
|
|
||
| if (RCL_RET_OK != ret) { | ||
| rclcpp::exceptions::throw_from_rcl_error(ret, "failed to get cft expression parameters"); | ||
| } | ||
|
|
||
| RCPPUTILS_SCOPE_EXIT( | ||
| { | ||
| rcl_ret_t ret = rcl_subscription_content_filter_options_fini( | ||
| subscription_handle_.get(), &options); | ||
| if (RCL_RET_OK != ret) { | ||
| RCLCPP_ERROR( | ||
| rclcpp::get_logger("rclcpp"), | ||
| "Failed to fini subscription content_filtered_topic option: %s", | ||
| rcl_get_error_string().str); | ||
| rcl_reset_error(); | ||
| } | ||
| }); | ||
|
|
||
| rmw_subscription_content_filter_options_t & content_filter_options = | ||
| options.rmw_subscription_content_filter_options; | ||
| ret_options.filter_expression = content_filter_options.filter_expression; | ||
|
|
||
| for (size_t i = 0; i < content_filter_options.expression_parameters.size; ++i) { | ||
| ret_options.expression_parameters.push_back( | ||
| content_filter_options.expression_parameters.data[i]); | ||
| } | ||
|
|
||
| return ret_options; | ||
| } | ||
| #endif // CONTENT_FILTER_ENABLE | ||
Uh oh!
There was an error while loading. Please reload this page.