publisher_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_PUBLISHER_PLUGIN_H
36 #define IMAGE_TRANSPORT_PUBLISHER_PLUGIN_H
37 
38 #include <ros/ros.h>
39 #include <sensor_msgs/Image.h>
41 
42 namespace image_transport {
43 
47 class PublisherPlugin : boost::noncopyable
48 {
49 public:
50  virtual ~PublisherPlugin() {}
51 
56  virtual std::string getTransportName() const = 0;
57 
61  void advertise(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size,
62  bool latch = true)
63  {
64  advertiseImpl(nh, base_topic, queue_size, SubscriberStatusCallback(),
66  }
67 
71  void advertise(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size,
72  const SubscriberStatusCallback& connect_cb,
73  const SubscriberStatusCallback& disconnect_cb = SubscriberStatusCallback(),
74  const ros::VoidPtr& tracked_object = ros::VoidPtr(), bool latch = true)
75  {
76  advertiseImpl(nh, base_topic, queue_size, connect_cb, disconnect_cb, tracked_object, latch);
77  }
78 
83  virtual uint32_t getNumSubscribers() const = 0;
84 
88  virtual std::string getTopic() const = 0;
89 
93  virtual void publish(const sensor_msgs::Image& message) const = 0;
94 
98  virtual void publish(const sensor_msgs::ImageConstPtr& message) const
99  {
100  publish(*message);
101  }
102 
110  virtual void publish(const sensor_msgs::Image& message, const uint8_t* data) const
111  {
112  sensor_msgs::Image msg;
113  msg.header = message.header;
114  msg.height = message.height;
115  msg.width = message.width;
116  msg.encoding = message.encoding;
117  msg.is_bigendian = message.is_bigendian;
118  msg.step = message.step;
119  msg.data = std::vector<uint8_t>(data, data + msg.step*msg.height);
120 
121  publish(msg);
122  }
123 
127  virtual void shutdown() = 0;
128 
133  static std::string getLookupName(const std::string& transport_name)
134  {
135  return "image_transport/" + transport_name + "_pub";
136  }
137 
138 protected:
142  virtual void advertiseImpl(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size,
143  const SubscriberStatusCallback& connect_cb,
144  const SubscriberStatusCallback& disconnect_cb,
145  const ros::VoidPtr& tracked_object, bool latch) = 0;
146 };
147 
148 } //namespace image_transport
149 
150 #endif
void advertise(ros::NodeHandle &nh, const std::string &base_topic, uint32_t queue_size, const SubscriberStatusCallback &connect_cb, const SubscriberStatusCallback &disconnect_cb=SubscriberStatusCallback(), const ros::VoidPtr &tracked_object=ros::VoidPtr(), bool latch=true)
Advertise a topic with subscriber status callbacks.
virtual uint32_t getNumSubscribers() const =0
Returns the number of subscribers that are currently connected to this PublisherPlugin.
static std::string getLookupName(const std::string &transport_name)
Return the lookup name of the PublisherPlugin associated with a specific transport identifier...
virtual void publish(const sensor_msgs::Image &message) const =0
Publish an image using the transport associated with this PublisherPlugin.
boost::function< void(const SingleSubscriberPublisher &)> SubscriberStatusCallback
virtual void publish(const sensor_msgs::ImageConstPtr &message) const
Publish an image using the transport associated with this PublisherPlugin.
void advertise(ros::NodeHandle &nh, const std::string &base_topic, uint32_t queue_size, bool latch=true)
Advertise a topic, simple version.
virtual std::string getTransportName() const =0
Get a string identifier for the transport provided by this plugin.
virtual void publish(const sensor_msgs::Image &message, const uint8_t *data) const
Publish an image using the transport associated with this PublisherPlugin. This version of the functi...
virtual std::string getTopic() const =0
Returns the communication topic that this PublisherPlugin will publish on.
virtual void shutdown()=0
Shutdown any advertisements associated with this PublisherPlugin.
virtual void advertiseImpl(ros::NodeHandle &nh, const std::string &base_topic, uint32_t queue_size, const SubscriberStatusCallback &connect_cb, const SubscriberStatusCallback &disconnect_cb, const ros::VoidPtr &tracked_object, bool latch)=0
Advertise a topic. Must be implemented by the subclass.
Base class for plugins to Publisher.


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