00001 // ***************************************************************************** 00002 // 00003 // Copyright (c) 2015, 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 00021 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00023 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00024 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00027 // DAMAGE. 00028 // 00029 // ***************************************************************************** 00030 00031 #ifndef SWRI_CONSOLE_LOG_DATABASE_H_ 00032 #define SWRI_CONSOLE_LOG_DATABASE_H_ 00033 00034 #include <QObject> 00035 #include <QAbstractListModel> 00036 #include <QStringList> 00037 #include <rosgraph_msgs/Log.h> 00038 #include <deque> 00039 #include <ros/time.h> 00040 00041 namespace swri_console 00042 { 00043 struct LogEntry 00044 { 00045 ros::Time stamp; 00046 uint8_t level; 00047 std::string node; 00048 std::string file; 00049 std::string function; 00050 uint32_t line; 00051 QStringList text; 00052 uint32_t seq; 00053 }; 00054 00055 class LogDatabase : public QObject 00056 { 00057 Q_OBJECT 00058 00059 public: 00060 LogDatabase(); 00061 ~LogDatabase(); 00062 00063 void clear(); 00064 const std::deque<LogEntry>& log() { return log_; } 00065 const ros::Time& minTime() const { return min_time_; } 00066 00067 const std::map<std::string, size_t>& messageCounts() const { return msg_counts_; } 00068 00069 Q_SIGNALS: 00070 void databaseCleared(); 00071 void messagesAdded(); 00072 void minTimeUpdated(); 00073 00074 public Q_SLOTS: 00075 void queueMessage(const rosgraph_msgs::LogConstPtr msg); 00076 void processQueue(); 00077 00078 private: 00079 std::map<std::string, size_t> msg_counts_; 00080 std::deque<LogEntry> log_; 00081 std::deque<LogEntry> new_msgs_; 00082 00083 ros::Time min_time_; 00084 }; // class LogDatabase 00085 } // namespace swri_console 00086 #endif // SWRI_CONSOLE_LOG_DATABASE_H_