subscriber.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
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   /* Base class for objects subscribers. */
00026   class Subscriber_
00027   {
00028     public:
00029       virtual void callback(unsigned char *data)=0;
00030       virtual int getEndpointType()=0;
00031 
00032       // id_ is set by NodeHandle when we advertise 
00033       int id_;
00034 
00035       virtual const char * getMsgType()=0;
00036       virtual const char * getMsgMD5()=0;
00037       const char * topic_;
00038   };
00039 
00040 
00041   /* Actual subscriber, templated on message type. */
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


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Thu Jun 6 2019 20:43:57