src
libros
subscriber.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2009, Willow Garage, Inc.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
6
* * Redistributions of source code must retain the above copyright notice,
7
* this list of conditions and the following disclaimer.
8
* * Redistributions in binary form must reproduce the above copyright
9
* notice, this list of conditions and the following disclaimer in the
10
* documentation and/or other materials provided with the distribution.
11
* * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
12
* contributors may be used to endorse or promote products derived from
13
* this software without specific prior written permission.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
* POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#include "
ros/subscriber.h
"
29
#include "
ros/node_handle.h
"
30
#include "
ros/topic_manager.h
"
31
32
namespace
ros
33
{
34
35
Subscriber::Impl::Impl
()
36
: unsubscribed_(false)
37
{ }
38
39
Subscriber::Impl::~Impl
()
40
{
41
ROS_DEBUG
(
"Subscriber on '%s' deregistering callbacks."
,
topic_
.c_str());
42
unsubscribe
();
43
}
44
45
bool
Subscriber::Impl::isValid
()
const
46
{
47
return
!
unsubscribed_
;
48
}
49
50
void
Subscriber::Impl::unsubscribe
()
51
{
52
if
(!
unsubscribed_
)
53
{
54
unsubscribed_
=
true
;
55
TopicManager::instance
()->unsubscribe(
topic_
,
helper_
);
56
node_handle_
.reset();
57
helper_
.reset();
58
}
59
}
60
61
Subscriber::Subscriber
(
const
std::string& topic,
const
NodeHandle
& node_handle,
62
const
SubscriptionCallbackHelperPtr
& helper)
63
:
impl_
(
boost
::make_shared<
Impl
>())
64
{
65
impl_
->topic_ = topic;
66
impl_
->node_handle_ = boost::make_shared<NodeHandle>(node_handle);
67
impl_
->helper_ = helper;
68
}
69
70
Subscriber::Subscriber
(
const
Subscriber
& rhs)
71
{
72
impl_
= rhs.
impl_
;
73
}
74
75
Subscriber::~Subscriber
()
76
{
77
}
78
79
void
Subscriber::shutdown
()
80
{
81
if
(
impl_
)
82
{
83
impl_
->unsubscribe();
84
}
85
}
86
87
std::string
Subscriber::getTopic
()
const
88
{
89
if
(
impl_
)
90
{
91
return
impl_
->topic_;
92
}
93
94
return
std::string();
95
}
96
97
uint32_t
Subscriber::getNumPublishers
()
const
98
{
99
if
(
impl_
&&
impl_
->isValid())
100
{
101
return
TopicManager::instance
()->getNumPublishers(
impl_
->topic_);
102
}
103
104
return
0;
105
}
106
107
}
// namespace ros
ros::Subscriber::Impl::isValid
bool isValid() const
Definition:
subscriber.cpp:45
ros::Subscriber
Manages an subscription callback on a specific topic.
Definition:
subscriber.h:46
ros::Subscriber::getTopic
std::string getTopic() const
Definition:
subscriber.cpp:87
boost
subscriber.h
ros::Subscriber::Impl::helper_
SubscriptionCallbackHelperPtr helper_
Definition:
subscriber.h:105
ros::Subscriber::Impl::Impl
Impl()
Definition:
subscriber.cpp:35
ros::Subscriber::shutdown
void shutdown()
Unsubscribe the callback associated with this Subscriber.
Definition:
subscriber.cpp:79
ros::Subscriber::getNumPublishers
uint32_t getNumPublishers() const
Returns the number of publishers this subscriber is connected to.
Definition:
subscriber.cpp:97
ros::Subscriber::Subscriber
Subscriber()
Definition:
subscriber.h:49
ros::Subscriber::impl_
ImplPtr impl_
Definition:
subscriber.h:111
ros::Subscriber::~Subscriber
~Subscriber()
Definition:
subscriber.cpp:75
ros::Subscriber::Impl::unsubscribed_
bool unsubscribed_
Definition:
subscriber.h:106
boost::shared_ptr< SubscriptionCallbackHelper >
ros::Subscriber::Impl::~Impl
~Impl()
Definition:
subscriber.cpp:39
ros::Subscriber::Impl
Definition:
subscriber.h:94
node_handle.h
ros::NodeHandle
roscpp's interface for creating subscribers, publishers, etc.
Definition:
node_handle.h:87
ros
topic_manager.h
ros::Subscriber::Impl::topic_
std::string topic_
Definition:
subscriber.h:103
ros::Subscriber::Impl::node_handle_
NodeHandlePtr node_handle_
Definition:
subscriber.h:104
ros::Subscriber::Impl::unsubscribe
void unsubscribe()
Definition:
subscriber.cpp:50
ros::TopicManager::instance
static const TopicManagerPtr & instance()
Definition:
topic_manager.cpp:56
ROS_DEBUG
#define ROS_DEBUG(...)
roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Feb 28 2022 23:33:27