simple_subscriber_plugin.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2009, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 #ifndef IMAGE_TRANSPORT_SIMPLE_SUBSCRIBER_PLUGIN_H
36 #define IMAGE_TRANSPORT_SIMPLE_SUBSCRIBER_PLUGIN_H
37 
39 #include <boost/scoped_ptr.hpp>
40 
41 namespace image_transport {
42 
61 template <class M>
63 {
64 public:
66 
67  virtual std::string getTopic() const
68  {
69  if (simple_impl_) return simple_impl_->sub_.getTopic();
70  return std::string();
71  }
72 
73  virtual uint32_t getNumPublishers() const
74  {
75  if (simple_impl_) return simple_impl_->sub_.getNumPublishers();
76  return 0;
77  }
78 
79  virtual void shutdown()
80  {
81  if (simple_impl_) simple_impl_->sub_.shutdown();
82  }
83 
84 protected:
91  virtual void internalCallback(const typename M::ConstPtr& message, const Callback& user_cb) = 0;
92 
98  virtual std::string getTopicToSubscribe(const std::string& base_topic) const
99  {
100  return base_topic + "/" + getTransportName();
101  }
102 
103  virtual void subscribeImpl(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size,
104  const Callback& callback, const ros::VoidPtr& tracked_object,
105  const TransportHints& transport_hints)
106  {
107  // Push each group of transport-specific parameters into a separate sub-namespace
108  ros::NodeHandle param_nh(transport_hints.getParameterNH(), getTransportName());
109  simple_impl_.reset(new SimpleSubscriberPluginImpl(param_nh));
110 
111  simple_impl_->sub_ = nh.subscribe<M>(getTopicToSubscribe(base_topic), queue_size,
112  boost::bind(&SimpleSubscriberPlugin::internalCallback, this, _1, callback),
113  tracked_object, transport_hints.getRosHints());
114  }
115 
119  const ros::NodeHandle& nh() const
120  {
121  return simple_impl_->param_nh_;
122  }
123 
124 private:
126  {
128  : param_nh_(nh)
129  {
130  }
131 
134  };
135 
136  boost::scoped_ptr<SimpleSubscriberPluginImpl> simple_impl_;
137 };
138 
139 } //namespace image_transport
140 
141 #endif
Base class for plugins to Subscriber.
virtual std::string getTransportName() const =0
Get a string identifier for the transport provided by this plugin.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
boost::function< void(const sensor_msgs::ImageConstPtr &)> Callback
const ros::NodeHandle & nh() const
Returns the ros::NodeHandle to be used for parameter lookup.
const ros::NodeHandle & getParameterNH() const
virtual std::string getTopicToSubscribe(const std::string &base_topic) const
Return the communication topic name for a given base topic.
virtual uint32_t getNumPublishers() const
Returns the number of publishers this subscriber is connected to.
Base class to simplify implementing most plugins to Subscriber.
boost::scoped_ptr< SimpleSubscriberPluginImpl > simple_impl_
virtual void internalCallback(const typename M::ConstPtr &message, const Callback &user_cb)=0
Process a message. Must be implemented by the subclass.
Stores transport settings for an image topic subscription.
const ros::TransportHints & getRosHints() const
virtual void shutdown()
Unsubscribe the callback associated with this SubscriberPlugin.
virtual void subscribeImpl(ros::NodeHandle &nh, const std::string &base_topic, uint32_t queue_size, const Callback &callback, const ros::VoidPtr &tracked_object, const TransportHints &transport_hints)
Subscribe to an image transport topic. Must be implemented by the subclass.
virtual std::string getTopic() const
Get the transport-specific communication topic.


image_transport
Author(s): Patrick Mihelich
autogenerated on Mon Feb 28 2022 22:31:45