aggregator.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 
00039 #ifndef DIAGNOSTIC_AGGREGATOR_H
00040 #define DIAGNOSTIC_AGGREGATOR_H
00041 
00042 #include <ros/ros.h>
00043 #include <string>
00044 #include <map>
00045 #include <vector>
00046 #include <set>
00047 #include <boost/shared_ptr.hpp>
00048 #include <boost/thread/mutex.hpp>
00049 #include <bondcpp/bond.h>
00050 #include <diagnostic_msgs/DiagnosticArray.h>
00051 #include <diagnostic_msgs/DiagnosticStatus.h>
00052 #include <diagnostic_msgs/KeyValue.h>
00053 #include <diagnostic_msgs/AddDiagnostics.h>
00054 #include "XmlRpcValue.h"
00055 #include "diagnostic_aggregator/analyzer.h"
00056 #include "diagnostic_aggregator/analyzer_group.h"
00057 #include "diagnostic_aggregator/status_item.h"
00058 #include "diagnostic_aggregator/other_analyzer.h"
00059 
00060 
00061 namespace diagnostic_aggregator {
00062 
00105 class Aggregator
00106 { 
00107 public:
00111   Aggregator();
00112 
00113   ~Aggregator();
00114 
00118   void publishData();
00119 
00123   bool ok() const { return n_.ok(); }
00124 
00128   double getPubRate() const { return pub_rate_; }
00129 
00130 private:
00131   ros::NodeHandle n_;
00132   ros::ServiceServer add_srv_; 
00133   ros::Subscriber diag_sub_; 
00134   ros::Publisher agg_pub_;  
00135   ros::Publisher toplevel_state_pub_;  
00136   boost::mutex mutex_;
00137   double pub_rate_;
00138 
00142   void diagCallback(const diagnostic_msgs::DiagnosticArray::ConstPtr& diag_msg);
00143 
00150   bool addDiagnostics(diagnostic_msgs::AddDiagnostics::Request &req,
00151                       diagnostic_msgs::AddDiagnostics::Response &res);
00152 
00153   AnalyzerGroup* analyzer_group_;
00154 
00155   OtherAnalyzer* other_analyzer_;
00156 
00157   std::vector<boost::shared_ptr<bond::Bond> > bonds_; 
00159   /*
00160    *!\brief called when a bond between the aggregator and a node is broken
00161    *
00162    * Modifies the contents of added_analyzers_ and analyzer_group, removing the
00163    * diagnostics that had been brought up by that bond.
00164    *!\param bond_id The bond id (namespace) from which the analyzer was created
00165    *!\param analyzer Shared pointer to the analyzer group that was added
00166    */
00167   void bondBroken(std::string bond_id,
00168                   boost::shared_ptr<Analyzer> analyzer);
00169 
00170   /*
00171    *!\brief called when a bond is formed between the aggregator and a node.
00172    * Actually adds the analyzergroup to the main analyzer group. Before this
00173    * function is called, the added diagnostics will not be analyzed by the
00174    * aggregator.
00175    *!\param group Shared pointer to the analyzer group that is to be added,
00176    *  which was created in the addDiagnostics function
00177    */
00178   void bondFormed(boost::shared_ptr<Analyzer> group);
00179 
00180   std::string base_path_; 
00182   std::set<std::string> ros_warnings_;  
00184   /*
00185    *!\brief Checks timestamp of message, and warns if timestamp is 0 (not set)
00186    */
00187   void checkTimestamp(const diagnostic_msgs::DiagnosticArray::ConstPtr& diag_msg);
00188 
00189 };
00190 
00191 /*
00192  *!\brief Functor for checking whether a bond has the same ID as the given string
00193  */
00194 struct BondIDMatch
00195 {
00196   BondIDMatch(const std::string s) : s(s) {}
00197   bool operator()(const boost::shared_ptr<bond::Bond>& b){ return s == b->getId(); }
00198   const std::string s;
00199 };
00200 
00201 }
00202 
00203 #endif // DIAGNOSTIC_AGGREGATOR_H


diagnostic_aggregator
Author(s): Kevin Watts, Brice Rebsamen
autogenerated on Tue Mar 26 2019 03:09:36