republish.cpp
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 
37 #include <pluginlib/class_loader.h>
38 
39 int main(int argc, char** argv)
40 {
41  ros::init(argc, argv, "image_republisher", ros::init_options::AnonymousName);
42  if (argc < 2) {
43  printf("Usage: %s in_transport in:=<in_base_topic> [out_transport] out:=<out_base_topic>\n", argv[0]);
44  return 0;
45  }
46  ros::NodeHandle nh;
47  std::string in_topic = nh.resolveName("in");
48  std::string in_transport = argv[1];
49  std::string out_topic = nh.resolveName("out");
50 
53 
54  if (argc < 3) {
55  // Use all available transports for output
56  image_transport::Publisher pub = it.advertise(out_topic, 1);
57 
58  // Use Publisher::publish as the subscriber callback
59  typedef void (image_transport::Publisher::*PublishMemFn)(const sensor_msgs::ImageConstPtr&) const;
60  PublishMemFn pub_mem_fn = &image_transport::Publisher::publish;
61  sub = it.subscribe(in_topic, 1, boost::bind(pub_mem_fn, &pub, _1), ros::VoidPtr(), in_transport);
62 
63  ros::spin();
64  }
65  else {
66  // Use one specific transport for output
67  std::string out_transport = argv[2];
68 
69  // Load transport plugin
70  typedef image_transport::PublisherPlugin Plugin;
71  pluginlib::ClassLoader<Plugin> loader("image_transport", "image_transport::PublisherPlugin");
72  std::string lookup_name = Plugin::getLookupName(out_transport);
73  boost::shared_ptr<Plugin> pub( loader.createInstance(lookup_name) );
74  pub->advertise(nh, out_topic, 1, image_transport::SubscriberStatusCallback(),
76 
77  // Use PublisherPlugin::publish as the subscriber callback
78  typedef void (Plugin::*PublishMemFn)(const sensor_msgs::ImageConstPtr&) const;
79  PublishMemFn pub_mem_fn = &Plugin::publish;
80  sub = it.subscribe(in_topic, 1, boost::bind(pub_mem_fn, pub.get(), _1), pub, in_transport);
81 
82  ros::spin();
83  }
84 
85  return 0;
86 }
Manages advertisements of multiple transport options on an Image topic.
Definition: publisher.h:64
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
Subscribe to an image topic, version for arbitrary boost::function object.
std::string resolveName(const std::string &name, bool remap=true) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
Advertise an image topic, simple version.
boost::function< void(const SingleSubscriberPublisher &)> SubscriberStatusCallback
Manages a subscription callback on a specific topic that can be interpreted as an Image topic...
Definition: subscriber.h:62
ROSCPP_DECL void spin(Spinner &spinner)
void publish(const sensor_msgs::Image &message) const
Publish an image on the topics associated with this Publisher.
Definition: publisher.cpp:156
int main(int argc, char **argv)
Definition: republish.cpp:39
Advertise and subscribe to image topics.
Base class for plugins to Publisher.


image_transport
Author(s): Patrick Mihelich
autogenerated on Sat Apr 4 2020 03:14:58