Line data Source code
1 :
2 : #include "ErrorHandler/MsgAnalyzerDlg.h"
3 : #include "ErrorHandler/MessageAnalyzer/ma_participants.h"
4 : #include "ErrorHandler/MsgBox.h"
5 :
6 : #include <cetlib/filepath_maker.h>
7 :
8 : #include <QtCore/QDateTime>
9 : #include <QtCore/QSettings>
10 : #include <QtCore/QTimer>
11 :
12 : #include <QtWidgets/QFileDialog>
13 : #include <QtWidgets/QMenu>
14 : #include <QtWidgets/QMessageBox>
15 :
16 : #include <memory>
17 :
18 : using fhicl::ParameterSet;
19 : using namespace novadaq::errorhandler;
20 :
21 : static ParameterSet
22 0 : read_conf(std::string const fname)
23 : {
24 0 : TLOG(TLVL_DEBUG) << "message analyzer configuration file: "
25 0 : << fname;
26 :
27 0 : ParameterSet pset;
28 : try
29 : {
30 : // it throws when the file is not parsable
31 0 : cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH");
32 0 : pset = fhicl::ParameterSet::make(fname, lookup_policy);
33 0 : }
34 0 : catch (cet::exception const &ex)
35 : {
36 0 : TLOG(TLVL_ERROR) << "Unable to load configuration file " << fname << ": " << ex.explain_self();
37 0 : }
38 :
39 0 : return pset;
40 0 : }
41 :
42 0 : MsgAnalyzerDlg::MsgAnalyzerDlg(std::string const &cfgfile, int partition, QDialog *parent)
43 : : QDialog(parent)
44 0 : , pset(read_conf(cfgfile))
45 0 : , engine(pset)
46 0 : , receiver(pset.get<fhicl::ParameterSet>("receivers", fhicl::ParameterSet()))
47 0 : , map()
48 0 : , nmsgs(0)
49 0 : , rule_size(0)
50 0 : , cond_size(0)
51 0 : , rule_idx_map()
52 0 : , cond_idx_map()
53 0 : , rule_display(DESCRIPTION)
54 0 : , cond_display(DESCRIPTION)
55 0 : , map_lock()
56 0 : , sig_mapper(this)
57 0 : , context_menu(new QMenu(this))
58 0 : , rule_act_menu(new QMenu(this))
59 0 : , cond_act_menu(new QMenu(this))
60 0 : , list_item(NULL)
61 0 : , aow_any(false)
62 0 : , aoe_any(false)
63 0 : , e_aow()
64 0 : , e_aoe()
65 : {
66 0 : setupUi(this);
67 0 : this->setWindowTitle("artdaq Message Analyzer, Partition " + QString::number(partition));
68 :
69 0 : connect(&engine, SIGNAL(alarm(QString const &, QString const &)), this, SLOT(onNewAlarm(QString const &, QString const &)));
70 :
71 0 : connect(&engine, SIGNAL(match(QString const &)), this, SLOT(onConditionMatch(QString const &)));
72 :
73 0 : connect(btnReset, SIGNAL(clicked()), this, SLOT(reset()));
74 0 : connect(btnExit, SIGNAL(clicked()), this, SLOT(exit()));
75 :
76 0 : connect(&receiver, SIGNAL(newMessage(qt_mf_msg const &)), this, SLOT(onNewMsg(qt_mf_msg const &)));
77 0 : connect(&receiver, SIGNAL(newMessage(qt_mf_msg const &)), &engine, SLOT(feed(qt_mf_msg const &)));
78 :
79 0 : connect(lwMain, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(onNodeClicked(QListWidgetItem *)));
80 0 : connect(lwDCM, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(onNodeClicked(QListWidgetItem *)));
81 0 : connect(lwBN, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(onNodeClicked(QListWidgetItem *)));
82 :
83 0 : connect(rbRuleDesc, SIGNAL(toggled(bool)), this, SLOT(onRuleDesc(bool)));
84 0 : connect(rbCondDesc, SIGNAL(toggled(bool)), this, SLOT(onCondDesc(bool)));
85 :
86 0 : connect(&sig_mapper, SIGNAL(mapped(int)), this, SLOT(reset_rule(int)));
87 0 : connect(&sig_mapper, SIGNAL(mapped(QString)), this, SLOT(reset_rule(QString)));
88 :
89 : // node status panel context menu
90 0 : connect(lwDCM, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(show_dcm_context_menu(const QPoint &)));
91 0 : connect(lwBN, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(show_evb_context_menu(const QPoint &)));
92 0 : connect(lwMain, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(show_main_context_menu(const QPoint &)));
93 :
94 0 : act_reset = new QAction("Reset", 0);
95 0 : context_menu->addAction(act_reset);
96 :
97 0 : context_menu->addSeparator();
98 :
99 0 : act_warning = new QAction("Alarm on warning", 0);
100 0 : act_warning->setCheckable(true);
101 0 : context_menu->addAction(act_warning);
102 :
103 0 : act_error = new QAction("Alarm on error", 0);
104 0 : act_error->setCheckable(true);
105 0 : context_menu->addAction(act_error);
106 :
107 : // context menu action trigger
108 0 : connect(act_reset, SIGNAL(triggered()), this, SLOT(context_menu_reset()));
109 0 : connect(act_warning, SIGNAL(triggered()), this, SLOT(context_menu_warning()));
110 0 : connect(act_error, SIGNAL(triggered()), this, SLOT(context_menu_error()));
111 :
112 : // rule action menu
113 0 : act_rule_enable = new QAction("Enable selections", 0);
114 0 : act_rule_disable = new QAction("Disable selections", 0);
115 0 : act_rule_reset = new QAction("Reset selections", 0);
116 :
117 0 : rule_act_menu->addAction(act_rule_enable);
118 0 : rule_act_menu->addAction(act_rule_disable);
119 0 : rule_act_menu->addSeparator();
120 0 : rule_act_menu->addAction(act_rule_reset);
121 :
122 0 : btnRuleAct->setMenu(rule_act_menu);
123 :
124 : // rule action menu trigger
125 0 : connect(act_rule_enable, SIGNAL(triggered()), this, SLOT(rule_enable()));
126 0 : connect(act_rule_disable, SIGNAL(triggered()), this, SLOT(rule_disable()));
127 0 : connect(act_rule_reset, SIGNAL(triggered()), this, SLOT(rule_reset_selection()));
128 :
129 : // Node Status configuration
130 0 : initNodeStatus();
131 :
132 : // init rule engine tables
133 0 : initRuleEngineTable();
134 0 : initParticipants();
135 :
136 : // system message
137 0 : QString msg("Loaded rule engine configuration from '");
138 0 : msg.append(cfgfile.c_str()).append("'");
139 0 : publishMessage(MSG_SYSTEM, msg);
140 :
141 : // handshake
142 : #if 0
143 : if( engine.is_EHS() )
144 : {
145 : qtdds.setHandshakeResponse("0");
146 : QVector<QString> res = qtdds.handshake();
147 :
148 : for(int i=0; i<res.size(); ++i)
149 : publishMessage( MSG_SYSTEM, res[i] );
150 :
151 : qtdds.setHandshakeResponse("1");
152 : }
153 : #endif
154 :
155 : // conclude
156 0 : publishMessage(MSG_SYSTEM, "Rule engine initialization completed.");
157 0 : receiver.start();
158 0 : }
159 :
160 0 : MsgAnalyzerDlg::~MsgAnalyzerDlg()
161 : {
162 0 : receiver.stop();
163 0 : }
164 :
165 0 : void MsgAnalyzerDlg::initNodeStatus()
166 : {
167 0 : ParameterSet null_pset;
168 0 : ParameterSet node = pset.get<ParameterSet>("node_status", null_pset);
169 :
170 0 : std::vector<std::string> null_strings;
171 :
172 0 : std::vector<std::string> aow = node.get<std::vector<std::string>>("alarm_on_first_warning", null_strings);
173 0 : std::vector<std::string> aoe = node.get<std::vector<std::string>>("alarm_on_first_error", null_strings);
174 :
175 0 : for (size_t i = 0; i < aow.size(); ++i)
176 : {
177 0 : if (aow[i] == "*")
178 : {
179 0 : aow_any = true;
180 0 : break;
181 : }
182 :
183 0 : e_aow.push_back(regex_t(aow[i]));
184 : }
185 :
186 0 : for (size_t i = 0; i < aoe.size(); ++i)
187 : {
188 0 : if (aoe[i] == "*")
189 : {
190 0 : aoe_any = true;
191 0 : break;
192 : }
193 :
194 0 : e_aoe.push_back(regex_t(aoe[i]));
195 : }
196 0 : }
197 :
198 0 : bool MsgAnalyzerDlg::check_node_aow(std::string const &key)
199 : {
200 0 : if (aow_any) return true;
201 :
202 0 : for (size_t i = 0; i < e_aow.size(); ++i)
203 : {
204 0 : if (boost::regex_match(key, what_, e_aow[i])) return true;
205 : }
206 :
207 0 : return false;
208 : }
209 :
210 0 : bool MsgAnalyzerDlg::check_node_aoe(std::string const &key)
211 : {
212 0 : if (aoe_any) return true;
213 :
214 0 : for (size_t i = 0; i < e_aoe.size(); ++i)
215 : {
216 0 : if (boost::regex_match(key, what_, e_aoe[i])) return true;
217 : }
218 :
219 0 : return false;
220 : }
221 :
222 0 : void MsgAnalyzerDlg::onNewMsg(qt_mf_msg const &mfmsg)
223 : {
224 : // basic message filtering according to the host and app
225 0 : std::string key;
226 0 : node_type_t type = get_source_from_msg(key, mfmsg);
227 :
228 : QListWidget *lw;
229 0 : if (type == UserCode)
230 0 : lw = lwDCM;
231 0 : else if (type == External)
232 0 : lw = lwBN;
233 : else
234 0 : lw = lwMain;
235 :
236 0 : node_status status = NORMAL;
237 :
238 0 : map_lock.lock();
239 : {
240 0 : map_t::iterator it = map.find(key);
241 :
242 0 : if (it == map.end()) // first msg from the key
243 : {
244 0 : bool aow = check_node_aow(key);
245 0 : bool aoe = check_node_aoe(key);
246 :
247 0 : NodeInfo *ni = new NodeInfo(type, key, lw, aow, aoe);
248 0 : status = ni->push_msg(mfmsg);
249 0 : map.insert(std::make_pair(key, ni));
250 : }
251 : else // found existing key
252 : {
253 0 : status = it->second->push_msg(mfmsg);
254 : }
255 :
256 0 : ++nmsgs;
257 0 : lcdMsgs->display(nmsgs);
258 : }
259 0 : map_lock.unlock();
260 :
261 0 : if (status == FIRST_WARNING)
262 : {
263 0 : QString str = QString(key.c_str())
264 0 : .append(" has issued a warning message:\n")
265 0 : .append(mfmsg.text(true));
266 0 : publishMessage(MSG_WARNING, str);
267 0 : }
268 0 : else if (status == FIRST_ERROR)
269 : {
270 0 : QString str = QString(key.c_str())
271 0 : .append(" has issued an error message:\n")
272 0 : .append(mfmsg.text(true));
273 0 : publishMessage(MSG_ERROR, str);
274 0 : }
275 0 : }
276 :
277 0 : void MsgAnalyzerDlg::publishMessage(message_type_t type, QString const &msg) const
278 : {
279 0 : QString txt;
280 :
281 0 : txt.append(QDateTime::currentDateTime().toString("[MM/dd/yyyy h:m:ss ap] "));
282 0 : txt.append(get_message_type_str(type).c_str())
283 0 : .append(":\n")
284 0 : .append(msg)
285 0 : .append("\n");
286 :
287 0 : QListWidgetItem *lwi = new QListWidgetItem(txt);
288 :
289 0 : switch (type)
290 : {
291 0 : case MSG_SYSTEM:
292 0 : lwi->setForeground(QBrush(Qt::blue));
293 0 : break;
294 0 : case MSG_ERROR:
295 0 : lwi->setForeground(QBrush(Qt::red));
296 0 : break;
297 0 : case MSG_WARNING:
298 0 : lwi->setForeground(QBrush(Qt::magenta));
299 0 : break;
300 0 : default:
301 0 : lwi->setForeground(QBrush(Qt::darkGreen));
302 : }
303 :
304 0 : lwAlerts->insertItem(0, lwi);
305 0 : }
306 :
307 0 : void MsgAnalyzerDlg::onNewAlarm(QString const &rule_name, QString const &msg)
308 : {
309 0 : publishMessage(MSG_ERROR, msg);
310 :
311 0 : std::map<QString, int>::const_iterator it = rule_idx_map.find(rule_name);
312 :
313 0 : if (it == rule_idx_map.end())
314 0 : throw std::runtime_error("MsgAnalyzerDlg::onNewAlarm() rule name '" + std::string(rule_name.toUtf8().constData()) + "' not found");
315 :
316 0 : int alarms = engine.rule_alarm_count(it->first);
317 0 : twRules->item(it->second, 2)->setText(QString("x ").append(QString::number(alarms)));
318 :
319 0 : QBrush brush(QColor(255, 200, 200));
320 :
321 0 : twRules->item(it->second, 0)->setBackground(brush);
322 0 : twRules->item(it->second, 1)->setBackground(brush);
323 0 : twRules->item(it->second, 2)->setBackground(brush);
324 :
325 0 : QPushButton *btn = new QPushButton("Rst");
326 0 : btn->setFixedSize(62, 20);
327 :
328 0 : twRules->setCellWidget(it->second, 3, btn);
329 :
330 0 : sig_mapper.setMapping(btn, it->second);
331 0 : connect(btn, SIGNAL(clicked()), &sig_mapper, SLOT(map()));
332 0 : }
333 :
334 0 : void MsgAnalyzerDlg::onConditionMatch(QString const &cond_name)
335 : {
336 0 : std::map<QString, int>::const_iterator it = cond_idx_map.find(cond_name);
337 :
338 0 : if (it == cond_idx_map.end())
339 0 : throw std::runtime_error("MsgAnalyzerDlg::onConditionMatch() name '" + std::string(cond_name.toUtf8().constData()) + "' not found");
340 :
341 0 : int msg_count = engine.cond_msg_count(cond_name);
342 0 : twConds->item(it->second, 3)->setText(QString::number(msg_count));
343 :
344 0 : if (msg_count == 1)
345 : {
346 : // paint blue when first message captured
347 0 : QBrush brush(QColor(230, 230, 255));
348 0 : twConds->item(it->second, 0)->setBackground(brush);
349 0 : twConds->item(it->second, 1)->setBackground(brush);
350 0 : twConds->item(it->second, 2)->setBackground(brush);
351 0 : twConds->item(it->second, 3)->setBackground(brush);
352 0 : }
353 0 : }
354 :
355 0 : void MsgAnalyzerDlg::onNewSysMsg(sev_code_t, QString const &)
356 : {
357 0 : }
358 :
359 0 : void MsgAnalyzerDlg::show_dcm_context_menu(QPoint const &pos)
360 : {
361 0 : show_context_menu(pos, lwDCM);
362 0 : }
363 :
364 0 : void MsgAnalyzerDlg::show_evb_context_menu(QPoint const &pos)
365 : {
366 0 : show_context_menu(pos, lwBN);
367 0 : }
368 :
369 0 : void MsgAnalyzerDlg::show_main_context_menu(QPoint const &pos)
370 : {
371 0 : show_context_menu(pos, lwMain);
372 0 : }
373 :
374 0 : void MsgAnalyzerDlg::show_context_menu(QPoint const &pos, QListWidget *list)
375 : {
376 0 : list_item = list->itemAt(pos);
377 :
378 0 : if (list_item != NULL)
379 : {
380 0 : QVariant v = list_item->data(Qt::UserRole);
381 0 : NodeInfo *ni = (NodeInfo *)v.value<void *>();
382 :
383 0 : act_warning->setChecked(ni->alarm_on_warning());
384 0 : act_error->setChecked(ni->alarm_on_error());
385 :
386 0 : context_menu->exec(QCursor::pos());
387 0 : }
388 0 : }
389 :
390 0 : void MsgAnalyzerDlg::context_menu_reset()
391 : {
392 0 : QVariant v = list_item->data(Qt::UserRole);
393 0 : NodeInfo *ni = (NodeInfo *)v.value<void *>();
394 :
395 0 : ni->reset();
396 0 : }
397 :
398 0 : void MsgAnalyzerDlg::context_menu_warning()
399 : {
400 0 : bool flag = act_warning->isChecked();
401 :
402 0 : QVariant v = list_item->data(Qt::UserRole);
403 0 : NodeInfo *ni = (NodeInfo *)v.value<void *>();
404 :
405 0 : ni->set_alarm_on_warning(flag);
406 0 : }
407 :
408 0 : void MsgAnalyzerDlg::context_menu_error()
409 : {
410 0 : bool flag = act_error->isChecked();
411 :
412 0 : QVariant v = list_item->data(Qt::UserRole);
413 0 : NodeInfo *ni = (NodeInfo *)v.value<void *>();
414 :
415 0 : ni->set_alarm_on_error(flag);
416 0 : }
417 :
418 0 : void MsgAnalyzerDlg::onEstablishPartition(int /*partition*/)
419 : {
420 0 : reset_node_status();
421 0 : reset_rule_engine();
422 :
423 0 : publishMessage(MSG_SYSTEM, "Message Analyzer has been reset");
424 0 : publishMessage(MSG_SYSTEM, "Partition established.");
425 0 : }
426 :
427 0 : void MsgAnalyzerDlg::reset_node_status()
428 : {
429 0 : map_lock.lock();
430 : {
431 0 : for (int i = lwMain->count(); i > 0; --i)
432 0 : delete lwMain->takeItem(i - 1);
433 :
434 0 : for (int i = lwBN->count(); i > 0; --i)
435 0 : delete lwBN->takeItem(i - 1);
436 :
437 0 : for (int i = lwDCM->count(); i > 0; --i)
438 0 : delete lwDCM->takeItem(i - 1);
439 :
440 0 : for (map_t::iterator it = map.begin(); it != map.end(); ++it)
441 0 : delete it->second;
442 :
443 0 : map.clear();
444 :
445 0 : nmsgs = 0;
446 0 : lcdMsgs->display(nmsgs);
447 : }
448 0 : map_lock.unlock();
449 0 : }
450 :
451 0 : void MsgAnalyzerDlg::reset_rule_engine()
452 : {
453 0 : std::map<QString, int>::const_iterator it;
454 :
455 : // reset conds
456 0 : for (it = cond_idx_map.begin(); it != cond_idx_map.end(); ++it)
457 : {
458 0 : twConds->item(it->second, 3)->setText("0");
459 :
460 0 : QBrush brush(QColor(255, 255, 255));
461 0 : twConds->item(it->second, 0)->setBackground(brush);
462 0 : twConds->item(it->second, 1)->setBackground(brush);
463 0 : twConds->item(it->second, 2)->setBackground(brush);
464 0 : twConds->item(it->second, 3)->setBackground(brush);
465 0 : }
466 :
467 : // reset rules
468 0 : for (it = rule_idx_map.begin(); it != rule_idx_map.end(); ++it)
469 : {
470 0 : twRules->item(it->second, 2)->setText("");
471 :
472 0 : QBrush brush(QColor(255, 255, 255));
473 0 : twRules->item(it->second, 0)->setBackground(brush);
474 0 : twRules->item(it->second, 1)->setBackground(brush);
475 0 : twRules->item(it->second, 2)->setBackground(brush);
476 :
477 0 : QWidget *temp = new QWidget();
478 0 : twRules->setCellWidget(it->second, 3, temp);
479 0 : }
480 :
481 : // reset engine
482 0 : engine.reset();
483 0 : }
484 :
485 0 : void MsgAnalyzerDlg::reset()
486 : {
487 0 : int ret = QMessageBox::warning(this, "MsgAnalyzer", "Are you sure you erase all messages and reset the MsgAnalyzer?", QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Cancel);
488 :
489 0 : if (ret == QMessageBox::Cancel) return;
490 :
491 0 : reset_node_status();
492 0 : reset_rule_engine();
493 :
494 0 : publishMessage(MSG_SYSTEM, "Message Analyzer has been reset");
495 : }
496 :
497 0 : void MsgAnalyzerDlg::exit()
498 : {
499 0 : int ret = QMessageBox::warning(this, "MsgAnalyzer", "Are you sure you wish to close MsgAnalyzer?", QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Cancel);
500 :
501 0 : if (ret == QMessageBox::Cancel) return;
502 :
503 0 : close();
504 : }
505 :
506 0 : void MsgAnalyzerDlg::closeEvent(QCloseEvent *event)
507 : {
508 0 : QSettings settings("artdaq", "MsgAnalyzer");
509 0 : settings.setValue("geometry", saveGeometry());
510 0 : QDialog::closeEvent(event);
511 0 : }
512 :
513 0 : void MsgAnalyzerDlg::rule_enable()
514 : {
515 0 : std::map<QString, int>::const_iterator it = rule_idx_map.begin();
516 0 : for (; it != rule_idx_map.end(); ++it)
517 : {
518 0 : if (twRules->item(it->second, 0)->checkState() == Qt::Checked)
519 : {
520 : // enable rule
521 0 : engine.enable_rule(it->first, true);
522 :
523 : // uncheck selection
524 0 : twRules->item(it->second, 0)->setCheckState(Qt::Unchecked);
525 :
526 : // paint foreground to black
527 0 : QBrush black(QColor(0, 0, 0));
528 0 : twRules->item(it->second, 0)->setForeground(black);
529 0 : twRules->item(it->second, 1)->setForeground(black);
530 0 : twRules->item(it->second, 2)->setForeground(black);
531 0 : twRules->cellWidget(it->second, 3)->setEnabled(true);
532 :
533 0 : int alarms = engine.rule_alarm_count(it->first);
534 :
535 0 : if (alarms == 0)
536 0 : twRules->item(it->second, 2)->setText("");
537 : else
538 0 : twRules->item(it->second, 2)->setText(QString("x ").append(QString::number(alarms)));
539 0 : }
540 : }
541 0 : }
542 :
543 0 : void MsgAnalyzerDlg::rule_disable()
544 : {
545 0 : std::map<QString, int>::const_iterator it = rule_idx_map.begin();
546 0 : for (; it != rule_idx_map.end(); ++it)
547 : {
548 0 : if (twRules->item(it->second, 0)->checkState() == Qt::Checked)
549 : {
550 : // disable rule
551 0 : engine.enable_rule(it->first, false);
552 :
553 : // uncheck selection
554 0 : twRules->item(it->second, 0)->setCheckState(Qt::Unchecked);
555 :
556 : // paint foreground to grey
557 0 : twRules->item(it->second, 2)->setText("Disabled");
558 :
559 0 : QBrush brush(QColor(200, 200, 200));
560 0 : twRules->item(it->second, 0)->setForeground(brush);
561 0 : twRules->item(it->second, 1)->setForeground(brush);
562 0 : twRules->item(it->second, 2)->setForeground(brush);
563 0 : twRules->cellWidget(it->second, 3)->setEnabled(false);
564 0 : }
565 : }
566 0 : }
567 :
568 0 : void MsgAnalyzerDlg::rule_reset_selection()
569 : {
570 0 : std::map<QString, int>::const_iterator it = rule_idx_map.begin();
571 0 : for (; it != rule_idx_map.end(); ++it)
572 : {
573 0 : if (twRules->item(it->second, 0)->checkState() == Qt::Checked)
574 : {
575 : // reset rule
576 0 : reset_rule(it->second);
577 :
578 : // uncheck selection
579 0 : twRules->item(it->second, 0)->setCheckState(Qt::Unchecked);
580 : }
581 : }
582 0 : }
583 :
584 : // make one that works with a QString
585 0 : void MsgAnalyzerDlg::reset_rule(QString name)
586 : {
587 0 : std::map<QString, int>::const_iterator it = rule_idx_map.find(name);
588 0 : this->reset_rule(it->second);
589 :
590 0 : twRules->item(it->second, 0)->setCheckState(Qt::Unchecked);
591 0 : return;
592 : }
593 :
594 : // called by individual reset button of rules
595 : // currently not in use
596 0 : void MsgAnalyzerDlg::reset_rule(int idx)
597 : {
598 0 : QString rule_name = twRules->item(idx, 0)->text();
599 :
600 0 : engine.reset_rule(rule_name);
601 :
602 : // paint background
603 0 : QBrush brush(QColor(255, 255, 255));
604 0 : twRules->item(idx, 0)->setBackground(brush);
605 0 : twRules->item(idx, 1)->setBackground(brush);
606 0 : twRules->item(idx, 2)->setBackground(brush);
607 :
608 : // status column
609 0 : twRules->item(idx, 2)->setText("");
610 :
611 : // remove reset button
612 0 : QWidget *temp = new QWidget();
613 0 : twRules->setCellWidget(idx, 3, temp);
614 :
615 : // repaint affected conditions
616 0 : QVector<QString> cond_names = engine.rule_cond_names(rule_name);
617 0 : for (int i = 0; i < cond_names.size(); ++i)
618 : {
619 0 : std::map<QString, int>::const_iterator it = cond_idx_map.find(cond_names[i]);
620 :
621 0 : if (it != cond_idx_map.end())
622 : {
623 0 : QBrush brush(QColor(255, 255, 255));
624 0 : twConds->item(it->second, 0)->setBackground(brush);
625 0 : twConds->item(it->second, 1)->setBackground(brush);
626 0 : twConds->item(it->second, 2)->setBackground(brush);
627 0 : twConds->item(it->second, 3)->setBackground(brush);
628 :
629 0 : twConds->item(it->second, 3)->setText("0");
630 0 : }
631 : }
632 :
633 0 : publishMessage(MSG_SYSTEM, "reset rule " + twRules->item(idx, 0)->text());
634 0 : }
635 :
636 0 : void MsgAnalyzerDlg::onNodeClicked(QListWidgetItem *item)
637 : {
638 0 : QVariant v = item->data(Qt::UserRole);
639 0 : NodeInfo *ni = (NodeInfo *)v.value<void *>();
640 :
641 0 : MsgBox msgbox(QString(ni->key_string().c_str()), *ni);
642 0 : msgbox.exec();
643 0 : }
644 :
645 0 : void MsgAnalyzerDlg::initRuleEngineTable()
646 : {
647 0 : twRules->setColumnWidth(0, 100);
648 0 : twRules->setColumnWidth(1, 320);
649 0 : twRules->setColumnWidth(2, 70);
650 0 : twRules->setColumnWidth(3, 62);
651 :
652 0 : rule_size = engine.rule_size();
653 0 : twRules->setRowCount(rule_size);
654 :
655 0 : rbRuleDesc->setChecked(true);
656 0 : rbRuleExpr->setChecked(false);
657 :
658 0 : QVector<QString> rule_names = engine.rule_names();
659 :
660 : // reset button for each rule has been commented out
661 0 : for (size_t i = 0; i < rule_size; ++i)
662 : {
663 0 : twRules->setRowHeight(i, 20);
664 0 : QString name = rule_names[i];
665 0 : QTableWidgetItem *iname = new QTableWidgetItem(name);
666 0 : QTableWidgetItem *iexpr = new QTableWidgetItem();
667 0 : QTableWidgetItem *istat = new QTableWidgetItem();
668 0 : QWidget *itemp = new QWidget();
669 :
670 0 : iname->setCheckState(Qt::Unchecked);
671 0 : istat->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
672 :
673 0 : twRules->setItem(i, 0, iname);
674 0 : twRules->setItem(i, 1, iexpr);
675 0 : twRules->setItem(i, 2, istat);
676 0 : twRules->setCellWidget(i, 3, itemp);
677 :
678 0 : rule_idx_map.insert(std::make_pair(name, i));
679 0 : }
680 :
681 : // display descriptions or expressions?
682 0 : updateRuleDisplay();
683 :
684 0 : twConds->setColumnWidth(0, 100);
685 0 : twConds->setColumnWidth(1, 90);
686 0 : twConds->setColumnWidth(2, 320);
687 0 : twConds->setColumnWidth(3, 42);
688 :
689 0 : cond_size = engine.cond_size();
690 0 : twConds->setRowCount(cond_size);
691 :
692 0 : rbCondDesc->setChecked(true);
693 0 : rbCondRegx->setChecked(false);
694 :
695 0 : QVector<QString> cond_names = engine.cond_names();
696 :
697 0 : for (size_t i = 0; i < cond_size; ++i)
698 : {
699 0 : twConds->setRowHeight(i, 20);
700 0 : QString name = cond_names[i];
701 0 : QTableWidgetItem *iname = new QTableWidgetItem(name);
702 0 : QTableWidgetItem *ifrom = new QTableWidgetItem(engine.cond_sources(name));
703 0 : QTableWidgetItem *iregex = new QTableWidgetItem();
704 0 : QTableWidgetItem *icount = new QTableWidgetItem("0");
705 :
706 0 : iname->setCheckState(Qt::Unchecked);
707 0 : icount->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
708 :
709 0 : twConds->setItem(i, 0, iname);
710 0 : twConds->setItem(i, 1, ifrom);
711 0 : twConds->setItem(i, 2, iregex);
712 0 : twConds->setItem(i, 3, icount);
713 :
714 0 : cond_idx_map.insert(std::make_pair(name, i));
715 0 : }
716 :
717 0 : updateCondDisplay();
718 0 : }
719 :
720 0 : void MsgAnalyzerDlg::updateRuleDisplay()
721 : {
722 0 : std::map<QString, int>::const_iterator it = rule_idx_map.begin();
723 :
724 0 : for (; it != rule_idx_map.end(); ++it)
725 : {
726 0 : QString txt = (rule_display == DESCRIPTION)
727 0 : ? engine.rule_description(it->first)
728 0 : : engine.rule_expr(it->first);
729 :
730 0 : twRules->item(it->second, 1)->setText(txt);
731 0 : }
732 0 : }
733 :
734 0 : void MsgAnalyzerDlg::updateCondDisplay()
735 : {
736 0 : std::map<QString, int>::const_iterator it = cond_idx_map.begin();
737 :
738 0 : for (; it != cond_idx_map.end(); ++it)
739 : {
740 0 : QString txt = (cond_display == DESCRIPTION)
741 0 : ? engine.cond_description(it->first)
742 0 : : engine.cond_regex(it->first);
743 :
744 0 : twConds->item(it->second, 2)->setText(txt);
745 0 : }
746 0 : }
747 :
748 0 : void MsgAnalyzerDlg::initParticipants()
749 : {
750 0 : ma_participants &p = ma_participants::instance();
751 :
752 : // remove existing participants
753 0 : p.reset();
754 :
755 : // hardcoded participants and groups :
756 : // p.add_group( group_name, # of participants )
757 0 : p.add_group("dcm", 8);
758 0 : p.add_group("bn", 8);
759 0 : }
760 :
761 0 : void MsgAnalyzerDlg::onSetParticipants(QVector<QString> const &dcm, QVector<QString> const &bnevb)
762 : {
763 0 : ma_participants &p = ma_participants::instance();
764 :
765 0 : p.reset();
766 :
767 0 : p.add_group("dcm", dcm.size());
768 0 : p.add_group("bnevb", bnevb.size());
769 :
770 0 : publishMessage(MSG_SYSTEM, "Initialized participants with " + QString(dcm.size()) + "dcm(s) and " + QString(bnevb.size()) + "bnevb(s)");
771 0 : }
|