-
Notifications
You must be signed in to change notification settings - Fork 549
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 16 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 |
|---|---|---|
|
|
@@ -491,6 +491,47 @@ 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.
|
||
| /** | ||
| * \param[in] filter_expression An filter expression to set. | ||
|
wjwwood marked this conversation as resolved.
Outdated
|
||
| * \sa SubscriptionOptionsBase::ContentFilterOptions::filter_expression | ||
| * Use empty string ("") can reset (or clear) the content filter setting of a subscription. | ||
|
wjwwood marked this conversation as resolved.
Outdated
|
||
| * \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 SubscriptionOptionsBase::ContentFilterOptions::expression_parameters | ||
| * \throws RCLBadAlloc if memory cannot be allocated | ||
| * \throws RCLError if an unexpect error occurs | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| 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. | ||
| /** | ||
| * \param[out] filter_expression An filter expression to get. | ||
| * \param[out] expression_parameters Array of expression parameters to get. | ||
| * \throws RCLBadAlloc if memory cannot be allocated | ||
| * \throws RCLError if an unexpect error occurs | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| virtual | ||
| void | ||
| get_content_filter( | ||
| std::string & filter_expression, | ||
| std::vector<std::string> & expression_parameters) const; | ||
| #endif // CONTENT_FILTER_ENABLE | ||
|
|
||
| protected: | ||
| template<typename EventCallbackT> | ||
| void | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,22 @@ struct SubscriptionOptionsBase | |
| TopicStatisticsOptions topic_stats_options; | ||
|
|
||
| QosOverridingOptions qos_overriding_options; | ||
|
|
||
| #ifdef CONTENT_FILTER_ENABLE | ||
| /// Options to configure content filtered topic in the subscription. | ||
| struct ContentFilterOptions | ||
|
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 it's better to define this outside |
||
| { | ||
| /// 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 | ||
| */ | ||
| std::vector<std::string> expression_parameters; | ||
| }; | ||
|
|
||
| ContentFilterOptions content_filter_options; | ||
| #endif // CONTENT_FILTER_ENABLE | ||
| }; | ||
|
|
||
| /// Structure containing optional configuration for Subscriptions. | ||
|
|
@@ -123,6 +139,22 @@ struct SubscriptionOptionsWithAllocator : public SubscriptionOptionsBase | |
| rmw_implementation_payload->modify_rmw_subscription_options(result.rmw_subscription_options); | ||
| } | ||
|
|
||
| #ifdef CONTENT_FILTER_ENABLE | ||
| // Copy content_filter_options into rcl_subscription_options. | ||
| if (!content_filter_options.filter_expression.empty()) { | ||
| std::vector<const char *> cstrings = | ||
| get_c_vector_string(content_filter_options.expression_parameters); | ||
| rcl_ret_t ret = rcl_subscription_options_set_content_filter_options( | ||
| get_c_string(content_filter_options.filter_expression), | ||
| cstrings.size(), | ||
| cstrings.data(), | ||
| &result); | ||
| if (RCL_RET_OK != ret) { | ||
| rclcpp::exceptions::throw_from_rcl_error( | ||
| ret, "failed to set content_filter_options"); | ||
| } | ||
| } | ||
| #endif // CONTENT_FILTER_ENABLE | ||
| return result; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -321,6 +321,15 @@ RCLCPP_PUBLIC | |
| const char * | ||
| get_c_string(const std::string & string_in); | ||
|
|
||
| /// Return the std::vector of C string from the given std::vector<std::string>. | ||
| /** | ||
| * \param[in] string_in is a std::string | ||
| * \return the std::vector of C string from the std::vector<std::string> | ||
| */ | ||
| RCLCPP_PUBLIC | ||
| std::vector<const char *> | ||
| get_c_vector_string(const std::vector<std::string> & strings); | ||
|
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. Use |
||
|
|
||
| } // namespace rclcpp | ||
|
|
||
| #endif // RCLCPP__UTILITIES_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,89 @@ 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( | ||||||||||||||
| get_c_string(filter_expression), | ||||||||||||||
| cstrings.size(), | ||||||||||||||
| cstrings.data(), | ||||||||||||||
| &options); | ||||||||||||||
|
ivanpauno marked this conversation as resolved.
|
||||||||||||||
| 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(&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"); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void | ||||||||||||||
| SubscriptionBase::get_content_filter( | ||||||||||||||
| std::string & filter_expression, | ||||||||||||||
| std::vector<std::string> & expression_parameters) const | ||||||||||||||
|
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. Instead of using arguments to get the output, I would rather use
Suggested change
|
||||||||||||||
| { | ||||||||||||||
| 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(&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; | ||||||||||||||
| filter_expression = content_filter_options.filter_expression; | ||||||||||||||
|
|
||||||||||||||
| for (size_t i = 0; i < content_filter_options.expression_parameters.size; ++i) { | ||||||||||||||
| expression_parameters.push_back( | ||||||||||||||
| content_filter_options.expression_parameters.data[i]); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| #endif // CONTENT_FILTER_ENABLE | ||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.