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_SUBSCRIBER_PLUGIN_H
36 #define IMAGE_TRANSPORT_SUBSCRIBER_PLUGIN_H
37 
38 #include <ros/ros.h>
39 #include <sensor_msgs/Image.h>
40 #include <boost/noncopyable.hpp>
42 
43 namespace image_transport {
44 
48 class SubscriberPlugin : boost::noncopyable
49 {
50 public:
51  typedef boost::function<void(const sensor_msgs::ImageConstPtr&)> Callback;
52 
53  virtual ~SubscriberPlugin() {}
54 
59  virtual std::string getTransportName() const = 0;
60 
64  void subscribe(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size,
65  const Callback& callback, const ros::VoidPtr& tracked_object = ros::VoidPtr(),
66  const TransportHints& transport_hints = TransportHints())
67  {
68  return subscribeImpl(nh, base_topic, queue_size, callback, tracked_object, transport_hints);
69  }
70 
74  void subscribe(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size,
75  void(*fp)(const sensor_msgs::ImageConstPtr&),
76  const TransportHints& transport_hints = TransportHints())
77  {
78  return subscribe(nh, base_topic, queue_size,
79  boost::function<void(const sensor_msgs::ImageConstPtr&)>(fp),
80  ros::VoidPtr(), transport_hints);
81  }
82 
86  template<class T>
87  void subscribe(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size,
88  void(T::*fp)(const sensor_msgs::ImageConstPtr&), T* obj,
89  const TransportHints& transport_hints = TransportHints())
90  {
91  return subscribe(nh, base_topic, queue_size, boost::bind(fp, obj, _1), ros::VoidPtr(), transport_hints);
92  }
93 
97  template<class T>
98  void subscribe(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size,
99  void(T::*fp)(const sensor_msgs::ImageConstPtr&),
100  const boost::shared_ptr<T>& obj,
101  const TransportHints& transport_hints = TransportHints())
102  {
103  return subscribe(nh, base_topic, queue_size, boost::bind(fp, obj.get(), _1), obj, transport_hints);
104  }
105 
109  virtual std::string getTopic() const = 0;
110 
114  virtual uint32_t getNumPublishers() const = 0;
115 
119  virtual void shutdown() = 0;
120 
125  static std::string getLookupName(const std::string& transport_type)
126  {
127  return "image_transport/" + transport_type + "_sub";
128  }
129 
130 protected:
134  virtual void subscribeImpl(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size,
135  const Callback& callback, const ros::VoidPtr& tracked_object,
136  const TransportHints& transport_hints) = 0;
137 };
138 
139 } //namespace image_transport
140 
141 #endif
Base class for plugins to Subscriber.
void subscribe(ros::NodeHandle &nh, const std::string &base_topic, uint32_t queue_size, void(T::*fp)(const sensor_msgs::ImageConstPtr &), T *obj, const TransportHints &transport_hints=TransportHints())
Subscribe to an image topic, version for class member function with bare pointer. ...
virtual uint32_t getNumPublishers() const =0
Returns the number of publishers this subscriber is connected to.
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)=0
Subscribe to an image transport topic. Must be implemented by the subclass.
void subscribe(ros::NodeHandle &nh, const std::string &base_topic, uint32_t queue_size, void(T::*fp)(const sensor_msgs::ImageConstPtr &), const boost::shared_ptr< T > &obj, const TransportHints &transport_hints=TransportHints())
Subscribe to an image topic, version for class member function with shared_ptr.
virtual std::string getTransportName() const =0
Get a string identifier for the transport provided by this plugin.
boost::function< void(const sensor_msgs::ImageConstPtr &)> Callback
void subscribe(ros::NodeHandle &nh, const std::string &base_topic, uint32_t queue_size, const Callback &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
Subscribe to an image topic, version for arbitrary boost::function object.
static std::string getLookupName(const std::string &transport_type)
Return the lookup name of the SubscriberPlugin associated with a specific transport identifier...
virtual std::string getTopic() const =0
Get the transport-specific communication topic.
virtual void shutdown()=0
Unsubscribe the callback associated with this SubscriberPlugin.
Stores transport settings for an image topic subscription.
void subscribe(ros::NodeHandle &nh, const std::string &base_topic, uint32_t queue_size, void(*fp)(const sensor_msgs::ImageConstPtr &), const TransportHints &transport_hints=TransportHints())
Subscribe to an image topic, version for bare function.


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