Line data Source code
1 : #ifndef MSGVIEWERDLG_H
2 : #define MSGVIEWERDLG_H
3 :
4 : #include "mfextensions/Extensions/suppress.hh"
5 : #include "mfextensions/Extensions/throttle.hh"
6 : #include "mfextensions/Receivers/ReceiverManager.hh"
7 : #include "mfextensions/Receivers/qt_mf_msg.hh"
8 : #include "ui_msgviewerdlgui.h"
9 :
10 : #include <QtCore/QMutex>
11 : #include <QtCore/QTimer>
12 :
13 : #include <boost/regex.hpp>
14 :
15 : #include <list>
16 : #include <map>
17 : #include <string>
18 : #include <vector>
19 :
20 : namespace fhicl {
21 : class ParameterSet;
22 : }
23 :
24 : /// <summary>
25 : /// Message Viewer Dialog Window
26 : /// </summary>
27 : class msgViewerDlg : public QDialog, private Ui::MsgViewerDlg
28 : {
29 0 : Q_OBJECT
30 :
31 : public:
32 : /**
33 : * \brief Message Viewer Dialog Constructor
34 : * \param conf Configuration filename (fhicl document)
35 : * \param parent Parent Qt window
36 : */
37 : msgViewerDlg(std::string const& conf, QDialog* parent = nullptr);
38 :
39 : virtual ~msgViewerDlg();
40 :
41 : public slots:
42 :
43 : /// Pause message receiving
44 : void pause();
45 :
46 : /// Exit the program
47 : void exit();
48 :
49 : /// Clear the message buffer
50 : void clear();
51 :
52 : /// Switch to/from Short message mode
53 : void shortMode();
54 :
55 : /// Change the severity threshold
56 : void changeSeverity(int sev);
57 :
58 : protected:
59 : /**
60 : * \brief Perform actions on window close
61 : * \param event QCloseEvent data
62 : */
63 : void closeEvent(QCloseEvent* event);
64 :
65 : private slots:
66 :
67 : void onNewMsg(msg_ptr_t const& mfmsg);
68 :
69 : void setFilter();
70 :
71 : void renderMode();
72 :
73 : void setSevError();
74 :
75 : void setSevWarning();
76 :
77 : void setSevInfo();
78 :
79 : void setSevDebug();
80 :
81 : void searchMsg();
82 :
83 : void searchClear();
84 :
85 : void setSuppression(QAction* act);
86 :
87 : void setThrottling(QAction* act);
88 :
89 : void tabWidgetCurrentChanged(int newTab);
90 :
91 : void tabCloseRequested(int tabIndex);
92 :
93 : void scrollToBottom();
94 :
95 : //---------------------------------------------------------------------------
96 :
97 : private:
98 : msgViewerDlg(msgViewerDlg const&) = delete;
99 : msgViewerDlg(msgViewerDlg&&) = delete;
100 : msgViewerDlg& operator=(msgViewerDlg const&) = delete;
101 : msgViewerDlg& operator=(msgViewerDlg&&) = delete;
102 :
103 : // Display all messages stored in the buffer
104 : void displayMsgs(int display);
105 :
106 : void UpdateTextAreaDisplay(QStringList const& texts, QPlainTextEdit* widget);
107 :
108 : void updateDisplays();
109 :
110 : void trim_msg_pool();
111 :
112 : // test if the message is suppressed or throttled
113 : bool msg_throttled(msg_ptr_t const& mfmsg);
114 :
115 : void update_index(msg_ptr_t const& msg);
116 :
117 : // Update the list. Returns true if there's a change in the selection
118 : // before and after the update. e.g., the selected entry has been deleted
119 : // during the process of updateMap(); otherwise it returns a false.
120 : bool updateList(QListWidget* lw, msgs_map_t const& map);
121 :
122 : void displayMsg(msg_ptr_t const& msg, int display);
123 :
124 : void readSettings();
125 :
126 : void writeSettings();
127 :
128 : void parseConf(fhicl::ParameterSet const& conf);
129 :
130 : QStringList toQStringList(QList<QListWidgetItem*> in);
131 :
132 : msgs_t list_intersect(msgs_t const& l1, msgs_t const& l2);
133 :
134 : //---------------------------------------------------------------------------
135 :
136 : private:
137 : bool paused;
138 : bool shortMode_;
139 :
140 : // # of received messages
141 : int nMsgs;
142 : int nSupMsgs; // suppressed msgs
143 : int nThrMsgs; // throttled msgs
144 : int nFilters;
145 : size_t maxMsgs; // Maximum number of messages to store
146 : size_t maxDeletedMsgs; // Maximum number of deleted messages to display
147 : int nDeleted;
148 :
149 : // Rendering messages in speed mode or full mode
150 : bool simpleRender;
151 :
152 : // suppression regex
153 : std::vector<suppress> e_sup_host;
154 : std::vector<suppress> e_sup_app;
155 : std::vector<suppress> e_sup_cat;
156 :
157 : // throttling regex
158 : std::vector<throttle> e_thr_host;
159 : std::vector<throttle> e_thr_app;
160 : std::vector<throttle> e_thr_cat;
161 :
162 : // search string
163 : QString searchStr;
164 :
165 : // msg pool storing the formatted text body
166 : mutable std::mutex msg_pool_mutex_;
167 : msgs_t msg_pool_;
168 :
169 : // map of a key to a list of msg iters
170 : mutable std::mutex msg_classification_mutex_;
171 : msgs_map_t host_msgs_;
172 : msgs_map_t cat_msgs_;
173 : msgs_map_t app_msgs_;
174 :
175 : // context menu for "suppression" and "throttling" button
176 : QMenu* sup_menu;
177 : QMenu* thr_menu;
178 :
179 : // Receiver Plugin Manager
180 : mfviewer::ReceiverManager receivers_;
181 :
182 : mutable std::mutex filter_mutex_;
183 : struct MsgFilterDisplay
184 : {
185 : int nDisplayMsgs;
186 : int nDisplayedDeletedMsgs;
187 : msgs_t msgs;
188 : QStringList hostFilter;
189 : QStringList appFilter;
190 : QStringList catFilter;
191 : QString filterExpression;
192 : QPlainTextEdit* txtDisplay;
193 :
194 : // severity threshold
195 : sev_code_t sevThresh;
196 : };
197 : std::vector<MsgFilterDisplay> msgFilters_;
198 : };
199 :
200 : enum list_mask_t
201 : {
202 : LIST_APP = 0x01,
203 : LIST_CAT = 0x02,
204 : LIST_HOST = 0x04
205 : };
206 :
207 : #endif
|