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_SUBSCRIBER_H_
00019 #define ROS_SUBSCRIBER_H_
00020
00021 #include "rosserial_msgs/TopicInfo.h"
00022
00023 namespace ros {
00024
00025
00026 class Subscriber_
00027 {
00028 public:
00029 virtual void callback(unsigned char *data)=0;
00030 virtual int getEndpointType()=0;
00031
00032
00033 int id_;
00034
00035 virtual const char * getMsgType()=0;
00036 virtual const char * getMsgMD5()=0;
00037 const char * topic_;
00038 };
00039
00040
00041
00042 template<typename MsgT>
00043 class Subscriber: public Subscriber_{
00044 public:
00045 typedef void(*CallbackT)(const MsgT&);
00046 MsgT msg;
00047
00048 Subscriber(const char * topic_name, CallbackT cb, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER) :
00049 cb_(cb),
00050 endpoint_(endpoint)
00051 {
00052 topic_ = topic_name;
00053 };
00054
00055 virtual void callback(unsigned char* data){
00056 msg.deserialize(data);
00057 this->cb_(msg);
00058 }
00059
00060 virtual const char * getMsgType(){ return this->msg.getType(); }
00061 virtual const char * getMsgMD5(){ return this->msg.getMD5(); }
00062 virtual int getEndpointType(){ return endpoint_; }
00063
00064 private:
00065 CallbackT cb_;
00066 int endpoint_;
00067 };
00068
00069 }
00070
00071 #endif