Commit a4088b9d authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

alarm entry for alarm attrribute error

parent 44f6ce87
......@@ -148,21 +148,27 @@ void AlarmTreeWidget::refresh(const CuData &v) {
QString ts = QDateTime::fromSecsSinceEpoch(d).toString("HH:mm:ss");
ts += QString("+%1").arg(d - static_cast<int>(d));
QString src = QuString(v, "src");
QString dev = src.section('/', 0, src.count('/') - 1);
bool err = v["err"].toBool();
QStringList data = QuStringList(v, "value");
QStringList data;
setToolTip(QuString(v, "msg"));
/* remove the filter */
if (err) {
src = src.section('/', 0, src.count('/') - 1);
data = m_gen_error_item(v);
src = dev;
data << m_gen_error_item(v);
perr("%s: %s\n", qstoc(src), qstoc(toolTip()));
m_dev_err.insert(dev);
printf("\e[1;31mAlarmTreeWidget::refresh: src \e[1;33m%s\e[1;31m is in ERRROR\e[0m\n", qstoc(src));
}
else {
m_dev_err.remove(dev);
data = QuStringList(v, "value");
}
int scrollBarPos;
QStringList fields;
QStringList alrnames;
AlarmTreeWidgetItem* item = NULL;
data = QuStringList(v, "value");
QStringList high, medium, low, lowest, unknown_level;
// group by level in order to sort view
foreach(QString row, data) {
......@@ -197,9 +203,9 @@ void AlarmTreeWidget::refresh(const CuData &v) {
if(!item) /* create a new item */ {
index = findPos(fields[0].toUInt(), fields[AlarmTreeWidgetItem::Level], fields[AlarmTreeWidgetItem::Status]);
m_insert_item(src, fields, index);
// printf("\e[1;33m%s \e[1;34m%s - number of tabs %d -- index %d\e[0m\n",
// qstoc(QDateTime::fromTime_t(fields.first().toUInt()).toString()),
// qstoc(data[i]), data[i].count("\t"), index);
// printf("\e[1;33m%s \e[1;34m%s - number of tabs %d -- index %d\e[0m\n",
// qstoc(QDateTime::fromTime_t(fields.first().toUInt()).toString()),
// qstoc(data[i]), data[i].count("\t"), index);
}
else /* update fields of existing items */
item->update(fields);
......@@ -218,21 +224,20 @@ void AlarmTreeWidget::refresh(const CuData &v) {
/* remove stale items */
QSet<QString> stale = oldset - alsrcset;
m_remove_stale_items(stale);
}
}
int AlarmTreeWidget::findPos(time_t ts, const QString &pri, const QString& status) {
int i = 0, prio = m_pri_to_int(pri), stat = m_status_to_int(status);
// printf("findPos called with ts %ld, pri %d\n", ts, prio);
// printf("findPos called with ts %ld, pri %d\n", ts, prio);
while(i < topLevelItemCount() && topLevelItem(i)->data(AlarmTreeWidgetItem::Status, Qt::UserRole).toInt() > stat) {
// printf("1st pri %d pri %d --> i %d\n", prio, topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt(), i);
// printf("1st pri %d pri %d --> i %d\n", prio, topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt(), i);
i++;
}
while(i < topLevelItemCount() && topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt() > prio
&& topLevelItem(i)->data(AlarmTreeWidgetItem::Status, Qt::UserRole).toInt() == stat) {
// printf("1st pri %d pri %d --> i %d\n", prio, topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt(), i);
// printf("1st pri %d pri %d --> i %d\n", prio, topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt(), i);
i++;
}
// i points to the first item with same pri or to the very last item in the view
......@@ -240,7 +245,7 @@ int AlarmTreeWidget::findPos(time_t ts, const QString &pri, const QString& statu
while(i < topLevelItemCount() && topLevelItem(i)->data(AlarmTreeWidgetItem::DateTime, Qt::UserRole).toUInt() > ts
&& topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt() == prio
&& topLevelItem(i)->data(AlarmTreeWidgetItem::Status, Qt::UserRole).toInt() == stat) {
// printf("1st ts %u item ts %u --> i %d\n", ts, topLevelItem(i)->data(AlarmTreeWidgetItem::DateTime, Qt::UserRole).toUInt(), i);
// printf("1st ts %u item ts %u --> i %d\n", ts, topLevelItem(i)->data(AlarmTreeWidgetItem::DateTime, Qt::UserRole).toUInt(), i);
i++;
}
return i;
......@@ -306,13 +311,14 @@ void AlarmTreeWidget::m_insert_item(const QString& src, const QStringList &list,
mItemHash.insert(fields.at(AlarmTreeWidgetItem::Alarm), item);
}
QStringList AlarmTreeWidget::m_gen_error_item(const CuData &da) const {
QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const {
QStringList l;
QDateTime dt = QDateTime::currentDateTime();
QString dev = QuString(da, "src");
QString dev = QuString(da, "src"), msg = QuString(da, "msg");
dev = dev.section('/', 0, dev.count('/') - 1);
l << dt.toString() << "-" << dev << "ERROR" << "NACK" << "1" << "high" << "-1" << "gr_handler" << QuString(da, "msg");
return l;
l << QString::number(dt.toSecsSinceEpoch()) << "-" << dev << "ERROR" << "NACK" << "1" << "high" << "-1" << "gr_handler"
<< msg.replace("\n", " ") << "NEW";
return l.join("\t");
}
......
......@@ -49,11 +49,12 @@ private:
int m_status_to_int(const QString& stat);
void m_remove_stale_items(const QSet<QString> stale_names);
void m_insert_item(const QString &src, const QStringList &list, int index);
QStringList m_gen_error_item(const CuData& da) const;
QString m_gen_error_item(const CuData& da) const;
bool _filter_enabled;
QHash<QString, AlarmTreeWidgetItem*> mItemHash;
QHash<QString, QSet<QString> >mSrcAlarmHash;
QSet<QString> m_dev_err;
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