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>
62 class SimpleSubscriberPlugin : public SubscriberPlugin
63 {
64 public:
65  virtual ~SimpleSubscriberPlugin() {}
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, boost::placeholders::_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:
125  struct SimpleSubscriberPluginImpl
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
image_transport::SimpleSubscriberPlugin::SimpleSubscriberPluginImpl::param_nh_
const ros::NodeHandle param_nh_
Definition: simple_subscriber_plugin.h:196
image_transport::SubscriberPlugin::getTransportName
virtual std::string getTransportName() const =0
Get a string identifier for the transport provided by this plugin.
image_transport::SimpleSubscriberPlugin::simple_impl_
boost::scoped_ptr< SimpleSubscriberPluginImpl > simple_impl_
Definition: simple_subscriber_plugin.h:200
boost::shared_ptr< void >
image_transport::SimpleSubscriberPlugin::shutdown
virtual void shutdown()
Unsubscribe the callback associated with this SubscriberPlugin.
Definition: simple_subscriber_plugin.h:143
image_transport::SubscriberPlugin::Callback
boost::function< void(const sensor_msgs::ImageConstPtr &)> Callback
Definition: subscriber_plugin.h:115
subscriber_plugin.h
image_transport::SimpleSubscriberPlugin::subscribeImpl
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.
Definition: simple_subscriber_plugin.h:167
image_transport::SimpleSubscriberPlugin::getNumPublishers
virtual uint32_t getNumPublishers() const
Returns the number of publishers this subscriber is connected to.
Definition: simple_subscriber_plugin.h:137
image_transport::SimpleSubscriberPlugin::SimpleSubscriberPluginImpl::SimpleSubscriberPluginImpl
SimpleSubscriberPluginImpl(const ros::NodeHandle &nh)
Definition: simple_subscriber_plugin.h:191
image_transport::SimpleSubscriberPlugin::getTopic
virtual std::string getTopic() const
Get the transport-specific communication topic.
Definition: simple_subscriber_plugin.h:131
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
image_transport::SimpleSubscriberPlugin::SimpleSubscriberPluginImpl::sub_
ros::Subscriber sub_
Definition: simple_subscriber_plugin.h:197
image_transport::SimpleSubscriberPlugin::nh
const ros::NodeHandle & nh() const
Returns the ros::NodeHandle to be used for parameter lookup.
Definition: simple_subscriber_plugin.h:183
image_transport
Definition: camera_common.h:41
image_transport::SimpleSubscriberPlugin::internalCallback
virtual void internalCallback(const typename M::ConstPtr &message, const Callback &user_cb)=0
Process a message. Must be implemented by the subclass.
image_transport::SimpleSubscriberPlugin::~SimpleSubscriberPlugin
virtual ~SimpleSubscriberPlugin()
Definition: simple_subscriber_plugin.h:129
ros::NodeHandle
ros::Subscriber
image_transport::SimpleSubscriberPlugin::getTopicToSubscribe
virtual std::string getTopicToSubscribe(const std::string &base_topic) const
Return the communication topic name for a given base topic.
Definition: simple_subscriber_plugin.h:162


image_transport
Author(s): Patrick Mihelich
autogenerated on Sat Jan 20 2024 03:14:50