publisher.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 // Author: Blaise Gassend
00036 #ifndef __DIAGNOSTIC_UPDATER__DRIVER_H__
00037 #define __DIAGNOSTIC_UPDATER__DRIVER_H__
00038 
00039 #include <ros/publisher.h>
00040 #include <ros/subscription.h>
00041 #include <diagnostic_updater/update_functions.h>
00042 
00043 namespace diagnostic_updater
00044 {
00045      
00055 class HeaderlessTopicDiagnostic : public CompositeDiagnosticTask
00056 {
00057 public:
00070         HeaderlessTopicDiagnostic(
00071       std::string name,
00072       diagnostic_updater::Updater &diag,
00073       const diagnostic_updater::FrequencyStatusParam &freq) :
00074     CompositeDiagnosticTask(name + " topic status"), 
00075     freq_(freq)
00076   {
00077     addTask(&freq_);
00078     diag.add(*this);
00079   }
00080 
00081   virtual ~HeaderlessTopicDiagnostic()
00082   {}
00083   
00088   virtual void tick()
00089   {
00090     freq_.tick();
00091   }
00092   
00097   virtual void clear_window()
00098   {
00099     freq_.clear();
00100   }
00101 
00102 private:
00103   diagnostic_updater::FrequencyStatus freq_;
00104 };
00105 
00111 class TopicDiagnostic : public HeaderlessTopicDiagnostic
00112 {
00113 public:
00129   TopicDiagnostic(
00130       std::string name,
00131       diagnostic_updater::Updater &diag,
00132       const diagnostic_updater::FrequencyStatusParam &freq,
00133       const diagnostic_updater::TimeStampStatusParam &stamp) : 
00134     HeaderlessTopicDiagnostic(name, diag, freq), 
00135     stamp_(stamp)
00136   {
00137     addTask(&stamp_);
00138   }
00139   
00140   virtual ~TopicDiagnostic()
00141   {}
00142   
00148         virtual void tick() { ROS_FATAL("tick(void) has been called on a TopicDiagnostic. This is never correct. Use tick(ros::Time &) instead."); }
00149 
00156   virtual void tick(const ros::Time &stamp)
00157   {
00158     stamp_.tick(stamp);
00159     HeaderlessTopicDiagnostic::tick();
00160   }
00161   
00162 private:
00163   TimeStampStatus stamp_;
00164 };
00165 
00173 template<class T>
00174 class DiagnosedPublisher : public TopicDiagnostic
00175 {
00176 public:
00192   DiagnosedPublisher(const ros::Publisher &pub,
00193       diagnostic_updater::Updater &diag, 
00194       const diagnostic_updater::FrequencyStatusParam &freq, 
00195       const diagnostic_updater::TimeStampStatusParam &stamp) : 
00196     TopicDiagnostic(pub.getTopic(), diag, freq, stamp),
00197     publisher_(pub)
00198   {}
00199 
00200   virtual ~DiagnosedPublisher()
00201   {}
00202   
00209         virtual void publish(const boost::shared_ptr<T>& message) {
00210                 tick(message->header.stamp); publisher_.publish(message); }
00211  
00218         virtual void publish(const T& message) { tick(message.header.stamp);
00219                 publisher_.publish(message); }
00220 
00224   ros::Publisher getPublisher() const
00225   {
00226     return publisher_;
00227   }
00228 
00232   void setPublisher(ros::Publisher pub)
00233   {
00234     publisher_ = pub;
00235   }
00236 
00237 private:
00238   ros::Publisher publisher_;
00239 };
00240 
00241 };
00242 
00243 #endif


diagnostic_updater
Author(s): Kevin Watts, Brice Rebsamen , Jeremy Leibs, Blaise Gassend
autogenerated on Tue Mar 26 2019 03:09:44