subscriber.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef ROS_SUBSCRIBER_H_
19 #define ROS_SUBSCRIBER_H_
20 
22 
23 namespace ros {
24 
25  /* Base class for objects subscribers. */
27  {
28  public:
29  virtual void callback(unsigned char *data)=0;
30  virtual int getEndpointType()=0;
31 
32  // id_ is set by NodeHandle when we advertise
33  int id_;
34 
35  virtual const char * getMsgType()=0;
36  virtual const char * getMsgMD5()=0;
37  const char * topic_;
38  };
39 
40 
41  /* Actual subscriber, templated on message type. */
42  template<typename MsgT>
43  class Subscriber: public Subscriber_{
44  public:
45  typedef void(*CallbackT)(const MsgT&);
46  MsgT msg;
47 
48  Subscriber(const char * topic_name, CallbackT cb, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER) :
49  cb_(cb),
50  endpoint_(endpoint)
51  {
52  topic_ = topic_name;
53  };
54 
55  virtual void callback(unsigned char* data){
56  msg.deserialize(data);
57  this->cb_(msg);
58  }
59 
60  virtual const char * getMsgType(){ return this->msg.getType(); }
61  virtual const char * getMsgMD5(){ return this->msg.getMD5(); }
62  virtual int getEndpointType(){ return endpoint_; }
63 
64  private:
65  CallbackT cb_;
66  int endpoint_;
67  };
68 
69 }
70 
71 #endif
msg
data
virtual void callback(unsigned char *data)=0
virtual int getEndpointType()=0
virtual const char * getMsgMD5()=0
const char * topic_
Definition: subscriber.h:37
virtual const char * getMsgType()=0


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57