client
ros_lib
ros
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
21
#include "
rosserial_msgs/TopicInfo.h
"
22
23
namespace
ros
{
24
25
/* Base class for objects subscribers. */
26
class
Subscriber_
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
msg
ros::Subscriber_::topic_
const char * topic_
Definition:
subscriber.h:37
ros
data
data
ros::Subscriber_
Definition:
subscriber.h:26
ros::Subscriber::Subscriber
Subscriber()
gpio_status.cb
list cb
Definition:
gpio_status.py:30
ros::Subscriber_::callback
virtual void callback(unsigned char *data)=0
ros::Subscriber_::getMsgMD5
virtual const char * getMsgMD5()=0
ros::Subscriber_::getMsgType
virtual const char * getMsgType()=0
ros::Subscriber
Definition:
subscriber.h:43
TopicInfo.h
ros::Subscriber_::getEndpointType
virtual int getEndpointType()=0
rosserial_msgs::TopicInfo::ID_SUBSCRIBER
@ ID_SUBSCRIBER
Definition:
TopicInfo.h:38
ros::Subscriber_::id_
int id_
Definition:
subscriber.h:33
cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Fri Aug 2 2024 09:40:57