Commit 213d3ab4 authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

https://gitlab.elettra.eu/cs/gui/alarm-ng/-/issues/ [200~Handle alarms with...

https://gitlab.elettra.eu/cs/gui/alarm-ng/-/issues/ [200~Handle alarms with same name in different alarm-handler~
parent a27c9029
...@@ -188,20 +188,22 @@ void AlarmTreeWidget::refresh(const CuData &v) { ...@@ -188,20 +188,22 @@ void AlarmTreeWidget::refresh(const CuData &v) {
} }
data = unknown_level + lowest + low + medium + high; data = unknown_level + lowest + low + medium + high;
QString alanam, alkey; // alarm name, alarm key (=src/alarm_name)
int index = 0; int index = 0;
QSet<QString> oldset = mSrcAlarmHash.value(src); // sets of alarms for the given src
QSet<QString> oldset = mSrcAlarmHash.value(src); // save current
QSet<QString>& alsrcset = mSrcAlarmHash[src]; QSet<QString>& alsrcset = mSrcAlarmHash[src]; // modify with new data (see (*) )
alsrcset.clear(); // empty set for src alsrcset.clear(); // empty set for src
/* add items to the tree(s) if not already present */ /* add items to the tree(s) if not already present */
for (int i = data.size() - 1; i >= 0; i--) { for (int i = data.size() - 1; i >= 0; i--) {
fields = data[i].split("\t"); fields = data[i].split("\t");
alanam = fields.at(AlarmTreeWidgetItem::Alarm);
alkey = m_make_key(alanam, src);
/* save current scroll bar value */ /* save current scroll bar value */
scrollBarPos = verticalScrollBar()->value(); scrollBarPos = verticalScrollBar()->value();
/* instead of GROUP information, show DEVICE */ /* instead of GROUP information, show DEVICE */
fields[DEVICE] = dev; fields[DEVICE] = dev;
item = mItemHash.value(alkey);
item = mItemHash.value(fields.at(AlarmTreeWidgetItem::Alarm));
if(!item) /* create a new item */ { if(!item) /* create a new item */ {
index = findPos(fields[0].toUInt(), fields[AlarmTreeWidgetItem::Level], fields[AlarmTreeWidgetItem::Status]); index = findPos(fields[0].toUInt(), fields[AlarmTreeWidgetItem::Level], fields[AlarmTreeWidgetItem::Status]);
m_insert_item(src, fields, index); m_insert_item(src, fields, index);
...@@ -215,17 +217,17 @@ void AlarmTreeWidget::refresh(const CuData &v) { ...@@ -215,17 +217,17 @@ void AlarmTreeWidget::refresh(const CuData &v) {
/* restore scrollbar value */ /* restore scrollbar value */
verticalScrollBar()->setValue(scrollBarPos); verticalScrollBar()->setValue(scrollBarPos);
// add alarm name to set of alarm names for this src // (*) add alarm name to set of alarm names for this src
alsrcset.insert(fields.at(AlarmTreeWidgetItem::Alarm)); alsrcset.insert(alanam); // alsrcset is a reference
// notify new alarm detected. connected to Alarm::beep // notify new alarm detected. connected to Alarm::beep
if(fields.size() > 5 && (fields[3] == "ALARM" || fields[3] == "ERROR") && fields.last() == "NEW") if(fields.size() > 5 && (fields[3] == "ALARM" || fields[3] == "ERROR") && fields.last() == "NEW")
emit newAlarmDetected(); emit newAlarmDetected();
} }
/* remove stale items */ /* remove stale items: alarm names for src */
QSet<QString> stale = oldset - alsrcset; QSet<QString> stale = oldset - alsrcset;
m_remove_stale_items(stale); m_remove_stale_items(stale, src); // works on mItemHash as well as on the tree
} }
...@@ -310,7 +312,7 @@ void AlarmTreeWidget::m_insert_item(const QString& src, const QStringList &list, ...@@ -310,7 +312,7 @@ void AlarmTreeWidget::m_insert_item(const QString& src, const QStringList &list,
item->setNew(isNew); item->setNew(isNew);
} }
/* add the couple identifier/AlarmTreeWidgetItem to the hash */ /* add the couple identifier/AlarmTreeWidgetItem to the hash */
mItemHash.insert(fields.at(AlarmTreeWidgetItem::Alarm), item); mItemHash.insert(m_make_key(fields.at(AlarmTreeWidgetItem::Alarm), src), item);
} }
QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const { QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const {
...@@ -323,12 +325,21 @@ QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const { ...@@ -323,12 +325,21 @@ QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const {
return l.join("\t"); return l.join("\t");
} }
AlarmTreeWidgetItem *AlarmTreeWidget::m_findItem(const QString &alarm, const QString &src) const {
return mItemHash.value(m_make_key(alarm, src));
}
QString AlarmTreeWidget::m_make_key(const QString &alarm, const QString &src) const {
return QString("%1/%2").arg(src).arg(alarm);
}
void AlarmTreeWidget::m_remove_stale_items(const QSet<QString> stale_names) { void AlarmTreeWidget::m_remove_stale_items(const QSet<QString> stale_names, const QString& src) {
foreach(const QString& name, stale_names) { foreach(const QString& name, stale_names) {
AlarmTreeWidgetItem *item = mItemHash.value(name); const QString& key = m_make_key(name, src);
AlarmTreeWidgetItem *item = mItemHash.value(key);
if(item) { if(item) {
mItemHash.remove(name); mItemHash.remove(key);
delete item; delete item;
} }
} }
......
...@@ -47,14 +47,16 @@ protected: ...@@ -47,14 +47,16 @@ protected:
private: private:
int m_pri_to_int(const QString& pri) const; int m_pri_to_int(const QString& pri) const;
int m_status_to_int(const QString& stat); int m_status_to_int(const QString& stat);
void m_remove_stale_items(const QSet<QString> stale_names); void m_remove_stale_items(const QSet<QString> stale_names, const QString& src);
void m_insert_item(const QString &src, const QStringList &list, int index); void m_insert_item(const QString &src, const QStringList &list, int index);
QString m_gen_error_item(const CuData& da) const; QString m_gen_error_item(const CuData& da) const;
AlarmTreeWidgetItem *m_findItem(const QString& alarm, const QString& handler) const;
bool _filter_enabled; bool _filter_enabled;
QHash<QString, AlarmTreeWidgetItem*> mItemHash; QHash<QString, AlarmTreeWidgetItem*> mItemHash;
QHash<QString, QSet<QString> >mSrcAlarmHash; QHash<QString, QSet<QString> >mSrcAlarmHash;
QSet<QString> m_src_err; QSet<QString> m_src_err;
QString m_make_key(const QString& alarm, const QString& handler) const;
Type m_type; Type m_type;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment