Pass request header to callbacks

This commit is contained in:
Esteve Fernandez 2015-04-20 13:22:54 -07:00
parent 0c0bb8a186
commit b938bd691a
3 changed files with 6 additions and 8 deletions

View file

@ -113,9 +113,7 @@ public:
typename rclcpp::service::Service<ServiceT>::SharedPtr typename rclcpp::service::Service<ServiceT>::SharedPtr
create_service( create_service(
std::string service_name, std::string service_name,
std::function<void( typename rclcpp::service::Service<ServiceT>::CallbackType callback,
const std::shared_ptr<typename ServiceT::Request> &,
std::shared_ptr<typename ServiceT::Response> &)> callback,
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr); rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr);
private: private:

View file

@ -186,8 +186,7 @@ template<typename ServiceT>
typename service::Service<ServiceT>::SharedPtr typename service::Service<ServiceT>::SharedPtr
Node::create_service( Node::create_service(
std::string service_name, std::string service_name,
std::function<void(const std::shared_ptr<typename ServiceT::Request> &, typename rclcpp::service::Service<ServiceT>::CallbackType callback,
std::shared_ptr<typename ServiceT::Response> &)> callback,
rclcpp::callback_group::CallbackGroup::SharedPtr group) rclcpp::callback_group::CallbackGroup::SharedPtr group)
{ {
using rosidl_generator_cpp::get_service_type_support_handle; using rosidl_generator_cpp::get_service_type_support_handle;

View file

@ -86,8 +86,9 @@ class Service : public ServiceBase
{ {
public: public:
typedef std::function< typedef std::function<
void (const std::shared_ptr<typename ServiceT::Request> &, void (const std::shared_ptr<rmw_request_id_t> &,
std::shared_ptr<typename ServiceT::Response> &)> CallbackType; const std::shared_ptr<typename ServiceT::Request> &,
std::shared_ptr<typename ServiceT::Response> &)> CallbackType;
RCLCPP_MAKE_SHARED_DEFINITIONS(Service); RCLCPP_MAKE_SHARED_DEFINITIONS(Service);
Service( Service(
@ -114,7 +115,7 @@ public:
auto typed_request = std::static_pointer_cast<typename ServiceT::Request>(request); auto typed_request = std::static_pointer_cast<typename ServiceT::Request>(request);
auto typed_request_header = std::static_pointer_cast<rmw_request_id_t>(request_header); auto typed_request_header = std::static_pointer_cast<rmw_request_id_t>(request_header);
auto response = std::shared_ptr<typename ServiceT::Response>(new typename ServiceT::Response); auto response = std::shared_ptr<typename ServiceT::Response>(new typename ServiceT::Response);
callback_(typed_request, response); callback_(typed_request_header, typed_request, response);
send_response(typed_request_header, response); send_response(typed_request_header, response);
} }