29 #ifndef SWRI_ROSCPP_TOPIC_SERVICE_CLIENT_H_    30 #define SWRI_ROSCPP_TOPIC_SERVICE_CLIENT_H_    34 #include <boost/thread/mutex.hpp>    35 #include <boost/uuid/random_generator.hpp>    36 #include <boost/uuid/uuid_io.hpp>    42 template<
class MReq, 
class MRes>
    65                 const std::string &service,
    66                 const std::string &client_name = 
"")
    69     boost::uuids::random_generator gen;
    70     boost::uuids::uuid u = gen();
    71     std::string random_str = boost::uuids::to_string(u);
    74     service_name_ = rservice;
    76     request_pub_ = nh.
advertise<MReq>(rservice + 
"/request", 10);
    80   bool call(MReq& request, MRes& response)
    82     boost::mutex::scoped_lock scoped_lock(request_lock_);
    87     request.srv_header.sender = 
name_;
    97         ROS_ERROR(
"Topic service timeout exceeded");
   105     while (!response_ && 
ros::Time::now() - request.srv_header.stamp < timeout_)
   116       return response.srv_header.result;
   139     ROS_DEBUG(
"Got response for %s with sequence %i",
   140              message->srv_header.sender.c_str(), message->srv_header.sequence);
   142     if (message->srv_header.sender != name_)
   144       ROS_DEBUG(
"Got response from another client, ignoring..");
   148     if (message->srv_header.sequence != sequence_)
   150       ROS_WARN(
"Got wrong sequence number, ignoring..");
   151       ROS_DEBUG(
"message seq:%i vs current seq: %i", message->srv_header.sequence, sequence_);
   172 #endif  // SWRI_ROSCPP_TOPIC_SERVICE_SERVER_H_ 
void publish(const boost::shared_ptr< M > &message) const 
void response_callback(const boost::shared_ptr< MRes > &message)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool call(MReq &request, MRes &response)
ros::Subscriber response_sub_
std::string resolveName(const std::string &name, bool remap=true) const 
ROSCPP_DECL const std::string & getName()
boost::shared_ptr< MRes > response_
ros::Publisher request_pub_
void initialize(ros::NodeHandle &nh, const std::string &service, const std::string &client_name="")
uint32_t getNumPublishers() const 
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::string service_name_
uint32_t getNumSubscribers() const 
void setLogCalls(bool enable)
boost::mutex request_lock_
ROSCPP_DECL void spinOnce()