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
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _ROS_SERVICE_CLIENT_H_
00036 #define _ROS_SERVICE_CLIENT_H_
00037
00038 #include "rosserial_msgs/TopicInfo.h"
00039
00040 #include "publisher.h"
00041 #include "subscriber.h"
00042
00043 namespace ros {
00044
00045 template<typename MReq , typename MRes>
00046 class ServiceClient : public Subscriber_ {
00047 public:
00048 ServiceClient(const char* topic_name) :
00049 pub(topic_name, &req, rosserial_msgs::TopicInfo::ID_SERVICE_CLIENT + rosserial_msgs::TopicInfo::ID_PUBLISHER)
00050 {
00051 this->topic_ = topic_name;
00052 this->waiting = true;
00053 }
00054
00055 virtual void call(const MReq & request, MRes & response)
00056 {
00057 if(!pub.nh_->connected()) return;
00058 ret = &response;
00059 waiting = true;
00060 pub.publish(&request);
00061 while(waiting && pub.nh_->connected())
00062 if(pub.nh_->spinOnce() < 0) break;
00063 }
00064
00065
00066 virtual void callback(unsigned char *data){
00067 ret->deserialize(data);
00068 waiting = false;
00069 }
00070 virtual const char * getMsgType(){ return this->resp.getType(); }
00071 virtual const char * getMsgMD5(){ return this->resp.getMD5(); }
00072 virtual int getEndpointType(){ return rosserial_msgs::TopicInfo::ID_SERVICE_CLIENT + rosserial_msgs::TopicInfo::ID_SUBSCRIBER; }
00073
00074 MReq req;
00075 MRes resp;
00076 MRes * ret;
00077 bool waiting;
00078 Publisher pub;
00079 };
00080
00081 }
00082
00083 #endif