Check callback argument types
This commit is contained in:
parent
1181daf81e
commit
814f4101db
2 changed files with 42 additions and 43 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
#include <rclcpp/callback_group.hpp>
|
#include <rclcpp/callback_group.hpp>
|
||||||
#include <rclcpp/client.hpp>
|
#include <rclcpp/client.hpp>
|
||||||
|
@ -54,16 +55,15 @@ template<typename ReturnTypeT, typename ... Args>
|
||||||
struct function_traits<ReturnTypeT(Args ...)>
|
struct function_traits<ReturnTypeT(Args ...)>
|
||||||
{
|
{
|
||||||
static constexpr std::size_t arity = sizeof ... (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>
|
template<typename ReturnTypeT, typename ... Args>
|
||||||
struct function_traits<ReturnTypeT (*)(Args ...)>: public function_traits<ReturnTypeT(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.
|
||||||
|
@ -160,24 +160,54 @@ private:
|
||||||
rclcpp::callback_group::CallbackGroup::SharedPtr group);
|
rclcpp::callback_group::CallbackGroup::SharedPtr group);
|
||||||
|
|
||||||
template<typename ServiceT, typename FunctorT>
|
template<typename ServiceT, typename FunctorT>
|
||||||
typename function_arity<
|
typename std::enable_if<
|
||||||
FunctorT,
|
function_traits<FunctorT>::arity == 2 &&
|
||||||
2,
|
std::is_same<
|
||||||
|
typename function_traits<FunctorT>::template argument_type<0>,
|
||||||
|
typename std::shared_ptr<typename ServiceT::Request>
|
||||||
|
>::value &&
|
||||||
|
std::is_same<
|
||||||
|
typename function_traits<FunctorT>::template argument_type<1>,
|
||||||
|
typename std::shared_ptr<typename ServiceT::Response>
|
||||||
|
>::value,
|
||||||
typename rclcpp::service::Service<ServiceT>::SharedPtr>::type
|
typename rclcpp::service::Service<ServiceT>::SharedPtr>::type
|
||||||
create_service_internal(
|
create_service_internal(
|
||||||
rmw_service_t * service_handle,
|
rmw_service_t * service_handle,
|
||||||
const std::string & service_name,
|
const std::string & service_name,
|
||||||
FunctorT callback);
|
FunctorT callback)
|
||||||
|
{
|
||||||
|
typename rclcpp::service::Service<ServiceT>::CallbackType callback_without_header =
|
||||||
|
callback;
|
||||||
|
return service::Service<ServiceT>::make_shared(
|
||||||
|
service_handle, service_name, callback_without_header);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename ServiceT, typename FunctorT>
|
template<typename ServiceT, typename FunctorT>
|
||||||
typename function_arity<
|
typename std::enable_if<
|
||||||
FunctorT,
|
function_traits<FunctorT>::arity == 3 &&
|
||||||
3,
|
std::is_same<
|
||||||
|
typename function_traits<FunctorT>::template argument_type<0>,
|
||||||
|
std::shared_ptr<rmw_request_id_t>
|
||||||
|
>::value &&
|
||||||
|
std::is_same<
|
||||||
|
typename function_traits<FunctorT>::template argument_type<1>,
|
||||||
|
typename std::shared_ptr<typename ServiceT::Request>
|
||||||
|
>::value &&
|
||||||
|
std::is_same<
|
||||||
|
typename function_traits<FunctorT>::template argument_type<2>,
|
||||||
|
typename std::shared_ptr<typename ServiceT::Response>
|
||||||
|
>::value,
|
||||||
typename rclcpp::service::Service<ServiceT>::SharedPtr>::type
|
typename rclcpp::service::Service<ServiceT>::SharedPtr>::type
|
||||||
create_service_internal(
|
create_service_internal(
|
||||||
rmw_service_t * service_handle,
|
rmw_service_t * service_handle,
|
||||||
const std::string & service_name,
|
const std::string & service_name,
|
||||||
FunctorT callback);
|
FunctorT callback)
|
||||||
|
{
|
||||||
|
typename rclcpp::service::Service<ServiceT>::CallbackWithHeaderType callback_with_header =
|
||||||
|
callback;
|
||||||
|
return service::Service<ServiceT>::make_shared(
|
||||||
|
service_handle, service_name, callback_with_header);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace node */
|
} /* namespace node */
|
||||||
|
|
|
@ -212,35 +212,4 @@ Node::create_service(
|
||||||
return serv;
|
return serv;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ServiceT, typename FunctorT>
|
|
||||||
typename function_arity<
|
|
||||||
FunctorT,
|
|
||||||
2,
|
|
||||||
typename rclcpp::service::Service<ServiceT>::SharedPtr>::type
|
|
||||||
Node::create_service_internal(
|
|
||||||
rmw_service_t * service_handle,
|
|
||||||
const std::string & service_name,
|
|
||||||
FunctorT callback)
|
|
||||||
{
|
|
||||||
typename rclcpp::service::Service<ServiceT>::CallbackType callback_without_header = callback;
|
|
||||||
return service::Service<ServiceT>::make_shared(
|
|
||||||
service_handle, service_name, callback_without_header);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename ServiceT, typename FunctorT>
|
|
||||||
typename function_arity<
|
|
||||||
FunctorT,
|
|
||||||
3,
|
|
||||||
typename rclcpp::service::Service<ServiceT>::SharedPtr>::type
|
|
||||||
Node::create_service_internal(
|
|
||||||
rmw_service_t * service_handle,
|
|
||||||
const std::string & service_name,
|
|
||||||
FunctorT callback)
|
|
||||||
{
|
|
||||||
typename rclcpp::service::Service<ServiceT>::CallbackWithHeaderType callback_with_header =
|
|
||||||
callback;
|
|
||||||
return service::Service<ServiceT>::make_shared(
|
|
||||||
service_handle, service_name, callback_with_header);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* RCLCPP_RCLCPP_NODE_IMPL_HPP_ */
|
#endif /* RCLCPP_RCLCPP_NODE_IMPL_HPP_ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue