Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor AnySubscriptionCallback and add/deprecate callback signatures (
ros2#1598) * refactor AnySubscriptionCallback to... use std::variant and make the dispatch functions constexpr, avoiding runtime dispatching. Also, deprecate the std::function<void (std::shared_ptr<MessageT>)> signature, as it is unsafe to share one shared_ptr when multiple subscriptions take it, because they could mutate MessageT while others are using it. So you'd have to make a copy for each subscription, which is no different than the std::unique_ptr<MessageT> signature or the user making their own copy in a shared_ptr from the const MessageT & signature or the std::shared_ptr<const MessageT> signature. Added a std::function<void (const std::shared_ptr<const MessageT> &)> signature to go along side the existing std::function<void (std::shared_ptr<const MessageT>)> signature. Removed redundant 'const' before pass-by-value signatures, e.g. std::function<void (const shared_ptr<const MessageT>)> became std::function<void (shared_ptr<const MessageT>)>. This will not affect API or any users using the old style. Signed-off-by: William Woodall <[email protected]> * fix use of std::bind, free functions, etc. using new function_traits::as_std_function<> Signed-off-by: William Woodall <[email protected]> * fix use of const MessageT & callbacks by fixing subscriptin_traits Signed-off-by: William Woodall <[email protected]> * fix deprecation warnings Signed-off-by: William Woodall <[email protected]> * use target_compile_features to require c++17 for downstream users of rclcpp Signed-off-by: William Woodall <[email protected]> * uncrustify Signed-off-by: William Woodall <[email protected]> * cpplint Signed-off-by: William Woodall <[email protected]> * use target_compile_features(... cxx_std_17) Signed-off-by: William Woodall <[email protected]> * Keep both std::shared_ptr<const MessageT> and const std::shared_ptr<const MessageT> & signatures. The const std::shared_ptr<const MessageT> & signature is being kept because it can be more flexible and efficient than std::shared_ptr<const MessageT>, but costs realtively little to support. The std::shared_ptr<const MessageT> signature is being kept because we want to avoid deprecating it and causing disruption, and because it is convenient to write, and in most cases will not materially impact the performance. Signed-off-by: William Woodall <[email protected]> * defer deprecation of the shared_ptr<MessageT> sub callbacks Signed-off-by: William Woodall <[email protected]> * fix unused variable warning Signed-off-by: William Woodall <[email protected]> * small fixups to AnySubscriptionCallback Signed-off-by: William Woodall <[email protected]> * add check for unset AnySubscriptionCallback in dispatch methods Signed-off-by: William Woodall <[email protected]> * update dispatch methods to handle all scenarios Signed-off-by: William Woodall <[email protected]> * updated tests for AnySubscriptionCallback, include full parameterized i/o matrix Signed-off-by: William Woodall <[email protected]> * fixup test with changed assumption Signed-off-by: William Woodall <[email protected]> * remove use of std::unary_function, which was removed in c++17 Signed-off-by: William Woodall <[email protected]> * silence c++17 warnings on windows for now Signed-off-by: William Woodall <[email protected]>
- Loading branch information