simple_subscriber_plugin.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 * 
00004 *  Copyright (c) 2009, Willow Garage, Inc.
00005 *  All rights reserved.
00006 * 
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 * 
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 * 
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 #ifndef IMAGE_TRANSPORT_SIMPLE_SUBSCRIBER_PLUGIN_H
00036 #define IMAGE_TRANSPORT_SIMPLE_SUBSCRIBER_PLUGIN_H
00037 
00038 #include "image_transport/subscriber_plugin.h"
00039 #include <boost/scoped_ptr.hpp>
00040 
00041 namespace image_transport {
00042 
00061 template <class M>
00062 class SimpleSubscriberPlugin : public SubscriberPlugin
00063 {
00064 public:
00065   virtual ~SimpleSubscriberPlugin() {}
00066 
00067   virtual std::string getTopic() const
00068   {
00069     if (simple_impl_) return simple_impl_->sub_.getTopic();
00070     return std::string();
00071   }
00072 
00073   virtual uint32_t getNumPublishers() const
00074   {
00075     if (simple_impl_) return simple_impl_->sub_.getNumPublishers();
00076     return 0;
00077   }
00078 
00079   virtual void shutdown()
00080   {
00081     if (simple_impl_) simple_impl_->sub_.shutdown();
00082   }
00083 
00084 protected:
00091   virtual void internalCallback(const typename M::ConstPtr& message, const Callback& user_cb) = 0;
00092 
00098   virtual std::string getTopicToSubscribe(const std::string& base_topic) const
00099   {
00100     return base_topic + "/" + getTransportName();
00101   }
00102   
00103   virtual void subscribeImpl(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size,
00104                              const Callback& callback, const ros::VoidPtr& tracked_object,
00105                              const TransportHints& transport_hints)
00106   {
00107     // Push each group of transport-specific parameters into a separate sub-namespace
00108     ros::NodeHandle param_nh(transport_hints.getParameterNH(), getTransportName());
00109     simple_impl_.reset(new SimpleSubscriberPluginImpl(param_nh));
00110 
00111     simple_impl_->sub_ = nh.subscribe<M>(getTopicToSubscribe(base_topic), queue_size,
00112                                          boost::bind(&SimpleSubscriberPlugin::internalCallback, this, _1, callback),
00113                                          tracked_object, transport_hints.getRosHints());
00114   }
00115 
00119   const ros::NodeHandle& nh() const
00120   {
00121     return simple_impl_->param_nh_;
00122   }
00123 
00124 private:
00125   struct SimpleSubscriberPluginImpl
00126   {
00127     SimpleSubscriberPluginImpl(const ros::NodeHandle& nh)
00128       : param_nh_(nh)
00129     {
00130     }
00131     
00132     const ros::NodeHandle param_nh_;
00133     ros::Subscriber sub_;
00134   };
00135   
00136   boost::scoped_ptr<SimpleSubscriberPluginImpl> simple_impl_;
00137 };
00138 
00139 } //namespace image_transport
00140 
00141 #endif


image_transport
Author(s): Patrick Mihelich
autogenerated on Tue Jun 6 2017 02:33:36