Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _ROS_SERVICE_CLIENT_H_
00019 #define _ROS_SERVICE_CLIENT_H_
00020
00021 #include "rosserial_msgs/TopicInfo.h"
00022
00023 #include "publisher.h"
00024 #include "subscriber.h"
00025
00026 namespace ros {
00027
00028 template<typename MReq , typename MRes>
00029 class ServiceClient : public Subscriber_ {
00030 public:
00031 ServiceClient(const char* topic_name) :
00032 pub(topic_name, &req, rosserial_msgs::TopicInfo::ID_SERVICE_CLIENT + rosserial_msgs::TopicInfo::ID_PUBLISHER)
00033 {
00034 this->topic_ = topic_name;
00035 this->waiting = true;
00036 }
00037
00038 virtual void call(const MReq & request, MRes & response)
00039 {
00040 if(!pub.nh_->connected()) return;
00041 ret = &response;
00042 waiting = true;
00043 pub.publish(&request);
00044 while(waiting && pub.nh_->connected())
00045 if(pub.nh_->spinOnce() < 0) break;
00046 }
00047
00048
00049 virtual void callback(unsigned char *data){
00050 ret->deserialize(data);
00051 waiting = false;
00052 }
00053 virtual const char * getMsgType(){ return this->resp.getType(); }
00054 virtual const char * getMsgMD5(){ return this->resp.getMD5(); }
00055 virtual int getEndpointType(){ return rosserial_msgs::TopicInfo::ID_SERVICE_CLIENT + rosserial_msgs::TopicInfo::ID_SUBSCRIBER; }
00056
00057 MReq req;
00058 MRes resp;
00059 MRes * ret;
00060 bool waiting;
00061 Publisher pub;
00062 };
00063
00064 }
00065
00066 #endif