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 
36  : unsubscribed_(false)
37  { }
38 
40  {
41  ROS_DEBUG("Subscriber on '%s' deregistering callbacks.", topic_.c_str());
42  unsubscribe();
43  }
44 
46  {
47  return !unsubscribed_;
48  }
49 
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 
71  {
72  impl_ = rhs.impl_;
73  }
74 
76  {
77  }
78 
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 
98  {
99  if (impl_ && impl_->isValid())
100  {
101  return TopicManager::instance()->getNumPublishers(impl_->topic_);
102  }
103 
104  return 0;
105  }
106 
107 } // namespace ros
Manages an subscription callback on a specific topic.
Definition: subscriber.h:46
SubscriptionCallbackHelperPtr helper_
Definition: subscriber.h:104
void shutdown()
Unsubscribe the callback associated with this Subscriber.
Definition: subscriber.cpp:79
bool isValid() const
Definition: subscriber.cpp:45
roscpp&#39;s interface for creating subscribers, publishers, etc.
Definition: node_handle.h:87
uint32_t getNumPublishers() const
Returns the number of publishers this subscriber is connected to.
Definition: subscriber.cpp:97
std::string getTopic() const
Definition: subscriber.cpp:87
std::string topic_
Definition: subscriber.h:102
NodeHandlePtr node_handle_
Definition: subscriber.h:103
static const TopicManagerPtr & instance()
#define ROS_DEBUG(...)


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Sun Feb 3 2019 03:29:54