Check callback arity and enable/disable compatible/incompatible versions of create_service. Workaround for http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2132 in Windows
This commit is contained in:
parent
b401c2fc33
commit
2367549a50
2 changed files with 49 additions and 12 deletions
|
@ -46,6 +46,24 @@ class Executor;
|
||||||
namespace node
|
namespace node
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// TODO: add support for functors, std::function, lambdas and object members
|
||||||
|
template<typename FunctionT>
|
||||||
|
struct function_traits;
|
||||||
|
|
||||||
|
template<typename ReturnTypeT, typename ... Args>
|
||||||
|
struct function_traits<ReturnTypeT(Args ...)>
|
||||||
|
{
|
||||||
|
static constexpr std::size_t arity = sizeof ... (Args);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename ReturnTypeT, typename ... Args>
|
||||||
|
struct function_traits<ReturnTypeT (*)(Args ...)>: public function_traits<ReturnTypeT(Args ...)>
|
||||||
|
{};
|
||||||
|
|
||||||
|
template<typename FunctorT, size_t arity, typename ReturnTypeT>
|
||||||
|
struct function_arity : std::enable_if<function_traits<FunctorT>::arity == arity, ReturnTypeT>
|
||||||
|
{};
|
||||||
|
|
||||||
/* ROS Node Interface.
|
/* ROS Node Interface.
|
||||||
*
|
*
|
||||||
* This is the single point of entry for creating publishers and subscribers.
|
* This is the single point of entry for creating publishers and subscribers.
|
||||||
|
@ -109,19 +127,27 @@ public:
|
||||||
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr);
|
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr);
|
||||||
|
|
||||||
/* Create and return a Service. */
|
/* Create and return a Service. */
|
||||||
template<typename ServiceT>
|
template<typename ServiceT, typename FunctorT>
|
||||||
typename rclcpp::service::Service<ServiceT>::SharedPtr
|
typename function_arity<
|
||||||
|
FunctorT,
|
||||||
|
2,
|
||||||
|
typename rclcpp::service::Service<ServiceT>::SharedPtr
|
||||||
|
>::type
|
||||||
create_service(
|
create_service(
|
||||||
const std::string & service_name,
|
const std::string & service_name,
|
||||||
typename rclcpp::service::Service<ServiceT>::CallbackType callback,
|
FunctorT functor,
|
||||||
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr);
|
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr);
|
||||||
|
|
||||||
/* Create and return a Service. */
|
/* Create and return a Service. */
|
||||||
template<typename ServiceT>
|
template<typename ServiceT, typename FunctorT>
|
||||||
typename rclcpp::service::Service<ServiceT>::SharedPtr
|
typename function_arity<
|
||||||
|
FunctorT,
|
||||||
|
3,
|
||||||
|
typename rclcpp::service::Service<ServiceT>::SharedPtr
|
||||||
|
>::type
|
||||||
create_service(
|
create_service(
|
||||||
const std::string & service_name,
|
const std::string & service_name,
|
||||||
typename rclcpp::service::Service<ServiceT>::CallbackWithHeaderType callback_with_header,
|
FunctorT functor,
|
||||||
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr);
|
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -182,13 +182,18 @@ Node::create_client(
|
||||||
return cli;
|
return cli;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ServiceT>
|
template<typename ServiceT, typename FunctorT>
|
||||||
typename service::Service<ServiceT>::SharedPtr
|
typename function_arity<
|
||||||
|
FunctorT,
|
||||||
|
2,
|
||||||
|
typename rclcpp::service::Service<ServiceT>::SharedPtr
|
||||||
|
>::type
|
||||||
Node::create_service(
|
Node::create_service(
|
||||||
const std::string & service_name,
|
const std::string & service_name,
|
||||||
typename rclcpp::service::Service<ServiceT>::CallbackType callback,
|
FunctorT functor,
|
||||||
rclcpp::callback_group::CallbackGroup::SharedPtr group)
|
rclcpp::callback_group::CallbackGroup::SharedPtr group)
|
||||||
{
|
{
|
||||||
|
typename rclcpp::service::Service<ServiceT>::CallbackType callback = functor;
|
||||||
using rosidl_generator_cpp::get_service_type_support_handle;
|
using rosidl_generator_cpp::get_service_type_support_handle;
|
||||||
auto service_type_support_handle =
|
auto service_type_support_handle =
|
||||||
get_service_type_support_handle<ServiceT>();
|
get_service_type_support_handle<ServiceT>();
|
||||||
|
@ -205,13 +210,19 @@ Node::create_service(
|
||||||
return serv;
|
return serv;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ServiceT>
|
template<typename ServiceT, typename FunctorT>
|
||||||
typename service::Service<ServiceT>::SharedPtr
|
typename function_arity<
|
||||||
|
FunctorT,
|
||||||
|
3,
|
||||||
|
typename rclcpp::service::Service<ServiceT>::SharedPtr
|
||||||
|
>::type
|
||||||
Node::create_service(
|
Node::create_service(
|
||||||
const std::string & service_name,
|
const std::string & service_name,
|
||||||
typename rclcpp::service::Service<ServiceT>::CallbackWithHeaderType callback_with_header,
|
FunctorT functor,
|
||||||
rclcpp::callback_group::CallbackGroup::SharedPtr group)
|
rclcpp::callback_group::CallbackGroup::SharedPtr group)
|
||||||
{
|
{
|
||||||
|
typename rclcpp::service::Service<ServiceT>::CallbackWithHeaderType callback_with_header =
|
||||||
|
functor;
|
||||||
using rosidl_generator_cpp::get_service_type_support_handle;
|
using rosidl_generator_cpp::get_service_type_support_handle;
|
||||||
auto service_type_support_handle =
|
auto service_type_support_handle =
|
||||||
get_service_type_support_handle<ServiceT>();
|
get_service_type_support_handle<ServiceT>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue