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