optional_diagnosed_publisher.h
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2017, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL SOUTHWEST RESEARCH INSTITUTE BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00030 #ifndef SWRI_ROSCPP_OPTIONAL_DIAGNOSED_PUBLISHER_H_
00031 #define SWRI_ROSCPP_OPTIONAL_DIAGNOSED_PUBLISHER_H_
00032 
00033 #include <diagnostic_updater/publisher.h>
00034 
00035 namespace swri
00036 {
00053   template<class T>
00054   class OptionalDiagnosedPublisher : public diagnostic_updater::DiagnosedPublisher<T>
00055   {
00056   public:
00057     OptionalDiagnosedPublisher(const ros::Publisher& pub,
00058                                diagnostic_updater::Updater& diag,
00059                                const diagnostic_updater::FrequencyStatusParam& freq,
00060                                const diagnostic_updater::TimeStampStatusParam& stamp) :
00061         diagnostic_updater::DiagnosedPublisher<T>(pub, diag, freq, stamp),
00062         is_diagnostic_enabled_(true)
00063     {}
00064 
00065     virtual ~OptionalDiagnosedPublisher()
00066     {}
00067 
00068     virtual void run(diagnostic_updater::DiagnosticStatusWrapper& stat)
00069     {
00070       if (is_diagnostic_enabled_)
00071       {
00072         diagnostic_updater::CompositeDiagnosticTask::run(stat);
00073       }
00074       else
00075       {
00076         diagnostic_updater::DiagnosticStatusWrapper wrapper;
00077         wrapper.level = 0;
00078         wrapper.message = "Diagnostic disabled.";
00079         stat.summary(wrapper);
00080       }
00081     }
00082 
00087     virtual void setEnabled(bool enabled)
00088     {
00089       is_diagnostic_enabled_ = enabled;
00090     }
00091 
00092   private:
00093     bool is_diagnostic_enabled_;
00094   };
00095 }
00096 
00097 #endif


swri_roscpp
Author(s):
autogenerated on Tue Oct 3 2017 03:19:27