Repository navigation
Add missing API for the intra process demo #98
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
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| // Copyright 2014 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_RCLCPP_ANY_SUBSCRIPTION_CALLBACK_HPP_ | ||
| #define RCLCPP_RCLCPP_ANY_SUBSCRIPTION_CALLBACK_HPP_ | ||
|
|
||
| #include <rclcpp/function_traits.hpp> | ||
|
|
||
| #include <functional> | ||
| #include <memory> | ||
| #include <type_traits> | ||
|
|
||
| #include <rmw/types.h> | ||
|
|
||
| namespace rclcpp | ||
| { | ||
|
|
||
| namespace any_subscription_callback | ||
| { | ||
|
|
||
| template<typename MessageT> | ||
| struct AnySubscriptionCallback | ||
| { | ||
| using SharedPtrCallback = std::function<void(const std::shared_ptr<MessageT> &)>; | ||
| using SharedPtrWithInfoCallback = | ||
| std::function<void(const std::shared_ptr<MessageT> &, const rmw_message_info_t &)>; | ||
| using UniquePtrCallback = std::function<void(std::unique_ptr<MessageT> &)>; | ||
| using UniquePtrWithInfoCallback = | ||
| std::function<void(std::unique_ptr<MessageT> &, const rmw_message_info_t &)>; | ||
|
|
||
| SharedPtrCallback shared_ptr_callback; | ||
| SharedPtrWithInfoCallback shared_ptr_with_info_callback; | ||
| UniquePtrCallback unique_ptr_callback; | ||
| UniquePtrWithInfoCallback unique_ptr_with_info_callback; | ||
|
|
||
| AnySubscriptionCallback() | ||
| : shared_ptr_callback(nullptr), shared_ptr_with_info_callback(nullptr), | ||
| unique_ptr_callback(nullptr), unique_ptr_with_info_callback(nullptr) | ||
| {} | ||
|
|
||
| AnySubscriptionCallback(const AnySubscriptionCallback &) = default; | ||
|
|
||
| template<typename CallbackT, | ||
| typename std::enable_if< | ||
| function_traits<CallbackT>::arity == 1 | ||
| >::type * = nullptr, | ||
| typename std::enable_if< | ||
| std::is_same< | ||
| typename function_traits<CallbackT>::template argument_type<0>, | ||
| typename std::shared_ptr<MessageT> | ||
| >::value | ||
| >::type * = nullptr | ||
| > | ||
| void set(CallbackT callback) | ||
| { | ||
| shared_ptr_callback = callback; | ||
| } | ||
|
|
||
| template<typename CallbackT, | ||
| typename std::enable_if< | ||
| function_traits<CallbackT>::arity == 2 | ||
| >::type * = nullptr, | ||
| typename std::enable_if< | ||
| std::is_same< | ||
| typename function_traits<CallbackT>::template argument_type<0>, | ||
| typename std::shared_ptr<MessageT> | ||
| >::value | ||
| >::type * = nullptr | ||
| > | ||
| void set(CallbackT callback) | ||
| { | ||
| shared_ptr_with_info_callback = callback; | ||
| } | ||
| /* | ||
| template<typename CallbackT, | ||
| typename std::enable_if< | ||
| function_traits<CallbackT>::arity == 1 | ||
| >::type * = nullptr, | ||
| typename std::enable_if< | ||
| std::is_same< | ||
| typename function_traits<CallbackT>::template argument_type<0>, | ||
| typename std::unique_ptr<MessageT> | ||
| >::value | ||
| >::type * = nullptr | ||
| > | ||
| void set(CallbackT callback) | ||
| { | ||
| static_assert(std::is_same< | ||
| typename function_traits<CallbackT>::template argument_type<0>, | ||
| typename std::unique_ptr<MessageT> | ||
| >::value, "Not a unique pointer"); | ||
| unique_ptr_callback = callback; | ||
| } | ||
|
|
||
| template<typename CallbackT, | ||
| typename std::enable_if< | ||
| function_traits<CallbackT>::arity == 2 | ||
| >::type * = nullptr, | ||
| typename std::enable_if< | ||
| std::is_same< | ||
| typename function_traits<CallbackT>::template argument_type<0>, | ||
| typename std::unique_ptr<MessageT> | ||
| >::value | ||
| >::type * = nullptr | ||
| > | ||
| void set(CallbackT callback) | ||
| { | ||
| unique_ptr_with_info_callback = callback; | ||
| } | ||
| */ | ||
| }; | ||
|
|
||
| } /* namespace any_subscription_callback */ | ||
| } /* namespace rclcpp */ | ||
|
|
||
| #endif /* RCLCPP_RCLCPP_ANY_SUBSCRIPTION_CALLBACK_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
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,63 @@ | ||
| // Copyright 2014 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_RCLCPP_FUNCTION_TRAITS_HPP_ | ||
| #define RCLCPP_RCLCPP_FUNCTION_TRAITS_HPP_ | ||
| #include <memory> | ||
|
|
||
| namespace rclcpp | ||
| { | ||
|
|
||
| /* NOTE(esteve): | ||
| * We support service callbacks that can optionally take the request id, | ||
| * which should be possible with two overloaded create_service methods, | ||
| * but unfortunately std::function's constructor on VS2015 is too greedy, | ||
| * so we need a mechanism for checking the arity and the type of each argument | ||
| * in a callback function. | ||
| */ | ||
|
|
||
|
|
||
| template<typename FunctionT> | ||
| struct function_traits | ||
| { | ||
| static constexpr std::size_t arity = | ||
| function_traits<decltype( & FunctionT::operator())>::arity - 1; | ||
|
|
||
|
|
||
| template<std::size_t N> | ||
| using argument_type = | ||
| typename function_traits<decltype( & FunctionT::operator())>::template argument_type<N + 1>; | ||
| }; | ||
|
|
||
| template<typename ReturnTypeT, typename ... Args> | ||
| struct function_traits<ReturnTypeT(Args ...)> | ||
| { | ||
| static constexpr std::size_t arity = sizeof ... (Args); | ||
|
|
||
| template<std::size_t N> | ||
| using argument_type = typename std::tuple_element<N, std::tuple<Args ...>>::type; | ||
| }; | ||
|
|
||
| template<typename ReturnTypeT, typename ... Args> | ||
| struct function_traits<ReturnTypeT (*)(Args ...)>: public function_traits<ReturnTypeT(Args ...)> | ||
| {}; | ||
|
|
||
| template<typename ClassT, typename ReturnTypeT, typename ... Args> | ||
| struct function_traits<ReturnTypeT (ClassT::*)(Args ...) const> | ||
| : public function_traits<ReturnTypeT(ClassT &, Args ...)> | ||
| {}; | ||
|
|
||
| } /* namespace rclcpp */ | ||
|
|
||
| #endif /* RCLCPP_RCLCPP_FUNCTION_TRAITS_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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got the demo to build with this function uncommented by changing https://github.com/ros2/demos/pull/12/files#diff-1c605fc584a4b2a7d84651a92fed1390R26 to:
The reason it doesn't compile is because
1_sis now ambiguous; the 1 could be an int or a double.Even if you remove the definition of operator
"" _sthat takes a double, it doesn't compile with1_sspecified tocreate_wall_timer, because there's no"" _soperator that returns nanoseconds, which is expected bycreate_wall_timer. And adding a function that returns nanoseconds and takes an integer would be ambiguous and also wouldn't compile (as you probably know from writing the functions added torclcpp.hppin this PR).But, overall, I actually think it's fine to disable the
create_wall_timerfunction that's commented out here, because it allows the user to specify times in sub-nanosecond precision, which is hard to achieve on most computing platforms...