28 #ifndef ROSCPP_SERVICE_CLIENT_H 29 #define ROSCPP_SERVICE_CLIENT_H 32 #include "ros/common.h" 46 ServiceClient(
const std::string& service_name,
bool persistent,
const M_string& header_values,
const std::string& service_md5sum);
54 template<
class MReq,
class MRes>
55 bool call(MReq& req, MRes& res)
57 namespace st = service_traits;
64 if (strcmp(st::md5sum(req), st::md5sum(res)))
66 ROS_ERROR(
"The request and response parameters to the service " 67 "call must be autogenerated from the same " 68 "server definition file (.srv). your service call " 69 "for %s appeared to use request/response types " 70 "from different .srv files. (%s vs. %s)", impl_->name_.c_str(), st::md5sum(req), st::md5sum(res));
74 return call(req, res, st::md5sum(req));
80 template<
class Service>
81 bool call(Service& service)
83 namespace st = service_traits;
90 return call(service.request, service.response, st::md5sum(service));
96 template<
typename MReq,
typename MRes>
97 bool call(
const MReq& req, MRes& resp,
const std::string& service_md5sum)
99 namespace ser = serialization;
102 bool ok =
call(ser_req, ser_resp, service_md5sum);
110 ser::deserializeMessage(ser_resp, resp);
112 catch (std::exception& e)
114 deserializeFailed(e);
127 bool isValid()
const;
132 bool isPersistent()
const;
161 std::string getService();
163 operator void*()
const {
return isValid() ? (
void*)1 : (
void*)0; }
166 return impl_ < rhs.
impl_;
171 return impl_ == rhs.
impl_;
176 return impl_ != rhs.
impl_;
185 ROS_ERROR(
"Exception thrown while while deserializing service call: %s", e.what());
194 bool isValid()
const;
std::string service_md5sum_
bool operator!=(const ServiceClient &rhs) const
bool call(const std::string &service_name, MReq &req, MRes &res)
Invoke an RPC service.
bool call(MReq &req, MRes &res)
Call the service aliased by this handle with the specified request/response messages.
std::map< std::string, std::string > M_string
boost::shared_ptr< Impl > ImplPtr
ServiceServerLinkPtr server_link_
void deserializeFailed(const std::exception &e)
roscpp's interface for creating subscribers, publishers, etc.
ROSCPP_DECL bool ok()
Check whether it's time to exit.
bool operator<(const ServiceClient &rhs) const
bool call(const MReq &req, MRes &resp, const std::string &service_md5sum)
Mostly for internal use, the other templated versions of call() just call into this one...
boost::weak_ptr< Impl > ImplWPtr
bool call(Service &service)
Call the service aliased by this handle with the specified service request/response.
Provides a handle-based interface to service client connections.
ROSCPP_DECL void shutdown()
Disconnects everything and unregisters from the master. It is generally not necessary to call this fu...
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
Checks if a service is both advertised and available.
bool operator==(const ServiceClient &rhs) const
boost::shared_ptr< ServiceClient > ServiceClientPtr