28 #ifndef ROSCPP_SERVICE_MESSAGE_HELPER_H 29 #define ROSCPP_SERVICE_MESSAGE_HELPER_H 32 #include "ros/common.h" 38 #include <boost/type_traits/is_base_of.hpp> 39 #include <boost/utility/enable_if.hpp> 53 return boost::make_shared<M>();
56 template<
typename MReq,
typename MRes>
69 template<
typename MReq,
typename MRes>
77 typedef boost::function<bool(ServiceEvent<RequestType, ResponseType>&)>
CallbackType;
88 , connection_header_(connection_header)
94 const RequestType&
getRequest()
const {
return *request_; }
107 const std::string&
getCallerName()
const {
return (*connection_header_)[
"callerid"]; }
114 template<
typename MReq,
typename MRes>
121 typedef boost::function<bool(RequestType&, ResponseType&)>
CallbackType;
145 template<
typename Spec>
158 const ReqCreateFunction& create_req =
161 static_cast<RequestPtr(*)()
>(defaultServiceCreateFunction<RequestType>),
162 const ResCreateFunction& create_res =
163 static_cast<ResponsePtr(*)()
>(defaultServiceCreateFunction<ResponseType>))
164 : callback_(callback)
165 , create_req_(create_req)
166 , create_res_(create_res)
172 namespace ser = serialization;
173 RequestPtr req(create_req_());
174 ResponsePtr res(create_res_());
176 ser::deserializeMessage(params.
request, *req);
183 params.
response = ser::serializeServiceResponse(ok, *res);
195 #endif // ROSCPP_SERVICE_MESSAGE_HELPER_H boost::shared_ptr< RequestType > RequestPtr
Spec::CallbackType Callback
boost::function< RequestPtr()> ReqCreateFunction
Spec::RequestType RequestType
const std::string & getCallerName() const
Returns the name of the node which called this service.
ResponseType & getResponse() const
Returns a non-const reference to the response.
static bool call(const CallbackType &cb, ServiceSpecCallParams< RequestType, ResponseType > ¶ms)
boost::function< bool(ServiceEvent< RequestType, ResponseType > &)> CallbackType
boost::shared_ptr< ServiceCallbackHelper > ServiceCallbackHelperPtr
boost::shared_ptr< MReq > request
ReqCreateFunction create_req_
boost::function< bool(RequestType &, ResponseType &)> CallbackType
bool call(const std::string &service_name, MReq &req, MRes &res)
Invoke an RPC service.
boost::shared_ptr< M_string > connection_header
boost::shared_ptr< M_string > connection_header
SerializedMessage response
virtual bool call(ServiceCallbackHelperCallParams ¶ms)
Abstract base class used by service servers to deal with concrete message types through a common inte...
ResCreateFunction create_res_
boost::shared_ptr< ResponseType > response_
std::map< std::string, std::string > M_string
SerializedMessage request
const RequestType & getRequest() const
Returns a const-reference to the request.
ROSCPP_DECL bool ok()
Check whether it's time to exit.
Spec::ResponsePtr ResponsePtr
Concrete generic implementation of ServiceCallbackHelper for any normal service type.
boost::shared_ptr< M_string > connection_header_
boost::shared_ptr< RequestType const > request_
boost::shared_ptr< MRes > response
Event type for services, ros::ServiceEvent<MReq, MRes>& can be used in your callback instead of MReq&...
ServiceEvent(const boost::shared_ptr< MReq const > &req, const boost::shared_ptr< MRes > &res, const boost::shared_ptr< M_string > &connection_header)
Spec::RequestPtr RequestPtr
boost::function< ResponsePtr()> ResCreateFunction
boost::shared_ptr< M > defaultServiceCreateFunction()
boost::shared_ptr< ResponseType > ResponsePtr
M_string & getConnectionHeader() const
Returns a reference to the connection header.
static bool call(const CallbackType &cb, ServiceSpecCallParams< RequestType, ResponseType > ¶ms)
Spec::ResponseType ResponseType
boost::shared_ptr< RequestType > RequestPtr
virtual ~ServiceCallbackHelper()
ServiceCallbackHelperT(const Callback &callback, const ReqCreateFunction &create_req=static_cast< RequestPtr(*)()>(defaultServiceCreateFunction< RequestType >), const ResCreateFunction &create_res=static_cast< ResponsePtr(*)()>(defaultServiceCreateFunction< ResponseType >))
boost::shared_ptr< ResponseType > ResponsePtr