Let the compiler deduce the appropriate Service constructor to use

This commit is contained in:
Esteve Fernandez 2015-04-29 17:40:38 -07:00
parent db0238c7e2
commit ad3f5da3a5
2 changed files with 6 additions and 52 deletions

View file

@ -127,25 +127,11 @@ 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, typename FunctorT> template<typename ServiceT, typename F>
typename function_arity< typename rclcpp::service::Service<ServiceT>::SharedPtr
FunctorT,
2,
typename rclcpp::service::Service<ServiceT>::SharedPtr>::type
create_service( create_service(
const std::string & service_name, const std::string & service_name,
FunctorT functor, F callback,
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr);
/* Create and return a Service. */
template<typename ServiceT, typename FunctorT>
typename function_arity<
FunctorT,
3,
typename rclcpp::service::Service<ServiceT>::SharedPtr>::type
create_service(
const std::string & service_name,
FunctorT functor,
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr); rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr);
private: private:

View file

@ -182,17 +182,13 @@ Node::create_client(
return cli; return cli;
} }
template<typename ServiceT, typename FunctorT> template<typename ServiceT, typename F>
typename function_arity< typename rclcpp::service::Service<ServiceT>::SharedPtr
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,
FunctorT functor, F callback,
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>();
@ -209,34 +205,6 @@ Node::create_service(
return serv; return serv;
} }
template<typename ServiceT, typename FunctorT>
typename function_arity<
FunctorT,
3,
typename rclcpp::service::Service<ServiceT>::SharedPtr>::type
Node::create_service(
const std::string & service_name,
FunctorT functor,
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;
auto service_type_support_handle =
get_service_type_support_handle<ServiceT>();
rmw_service_t * service_handle = rmw_create_service(
this->node_handle_, service_type_support_handle, service_name.c_str());
auto serv = service::Service<ServiceT>::make_shared(
service_handle,
service_name,
callback_with_header);
auto serv_base_ptr = std::dynamic_pointer_cast<service::ServiceBase>(serv);
register_service(service_name, serv_base_ptr, group);
return serv;
}
void void
Node::register_service( Node::register_service(
const std::string & service_name, const std::string & service_name,