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

stop sound and ack in server handler errors

parent 4d2c9d59
...@@ -51,23 +51,19 @@ void AlarmTreeWidget::refresh(const CuData &v) { ...@@ -51,23 +51,19 @@ void AlarmTreeWidget::refresh(const CuData &v) {
QString src = QuString(v, "src"); QString src = QuString(v, "src");
QString dev = src.section('/', 0, src.count('/') - 1); QString dev = src.section('/', 0, src.count('/') - 1);
bool empty = QuString(v, "msg").contains(QRegularExpression("cannot\\s+extract")); bool empty = QuString(v, "msg").contains(QRegularExpression("cannot\\s+extract"));
printf("\e[1;31mempty is %d msg is %s\e[0m\n", empty, vtoc2(v, "msg"));
printf("\e[1;33m%s\e[0m\n", datos(v));
bool err = v["err"].toBool() && !empty; bool err = v["err"].toBool() && !empty;
if(empty)
printf("\e[1;34mAlarmTreeWidget::refresh: attribute %s is empty <<<<<<<<<<<<<<<< \e[0m\n", qstoc(src));
QStringList data; QStringList data;
setToolTip(QuString(v, "msg")); setToolTip(QuString(v, "msg"));
// error: err flag is true and message is not of type "cannot extract data..." // error: err flag is true and message is not of type "cannot extract data..."
// only AlarmType adds an entry for each error // only AlarmType adds an entry for each error
if (err && m_type == AlarmType) { if (err && m_type == AlarmType) {
data << m_gen_error_item(v); data << m_gen_error_item(v);
// perr("%s: %s\n", qstoc(src), datos(v)); if(!m_src_err_map.contains(src))
m_src_err.insert(src); m_src_err_map.insert(src, SrvErrNew|SrvErrUnack); // true: new
} }
else { else {
if(m_src_err.contains(src)) { if(m_src_err_map.contains(src)) {
m_src_err.remove(src); m_src_err_map.remove(src);
src_fixed = src; src_fixed = src;
} }
data = QuStringList(v, "value"); data = QuStringList(v, "value");
...@@ -172,6 +168,16 @@ int AlarmTreeWidget::countAlarmed() const { ...@@ -172,6 +168,16 @@ int AlarmTreeWidget::countAlarmed() const {
return cnt; return cnt;
} }
void AlarmTreeWidget::setServerErrNotNew(const QString &errdev) {
if(m_src_err_map.contains(errdev))
m_src_err_map[errdev] &= ~SrvErrNew;
}
void AlarmTreeWidget::setServerErrAck(const QString &n) {
if(m_src_err_map.contains(n))
m_src_err_map[n] &= ~SrvErrUnack;
}
void AlarmTreeWidget::contextMenuEvent(QContextMenuEvent *e) void AlarmTreeWidget::contextMenuEvent(QContextMenuEvent *e)
{ {
bool silenceAvail = true; bool silenceAvail = true;
...@@ -242,10 +248,14 @@ void AlarmTreeWidget::m_insert_item(const QString& src, const QStringList &list, ...@@ -242,10 +248,14 @@ void AlarmTreeWidget::m_insert_item(const QString& src, const QStringList &list,
QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const { QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const {
QStringList l; QStringList l;
QDateTime dt = QDateTime::currentDateTime(); QDateTime dt = QDateTime::currentDateTime();
QString dev = QuString(da, "src"), msg = QuString(da, "msg"); QString dev, src = QuString(da, "src"), msg = QuString(da, "msg");
dev = dev.section('/', 0, dev.count('/') - 1); dev = src.section('/', 0, dev.count('/') - 1);
l << QString::number(dt.toSecsSinceEpoch()) << "-" << dev << "ERROR" << "NACK" << "high" << "-1" << "gr_handler" qDebug() << __PRETTY_FUNCTION__ << m_src_err_map;
<< "Alarm server error: " + msg.replace("\n", " ") << "NEW"; bool _new = ((m_src_err_map[src] & (SrvErrNew | SrvErrUnack)) == (SrvErrNew | SrvErrUnack));
printf("\e[1;36mAlarmTreeWidget::m_gen_error_item %d & %d\e[0m\n", m_src_err_map[src] , (SrvErrNew | SrvErrUnack));
l << QString::number(dt.toSecsSinceEpoch()) << "-" << src << "ERROR" << (m_src_err_map[src] & SrvErrUnack ? "UNACK" : "ACK") << "high" << "-1" << "gr_handler"
<< "Alarm server error: " + msg.replace("\n", " ") << (_new ? "NEW" : " ");
qDebug() << __PRETTY_FUNCTION__ << l;
return l.join("\t"); return l.join("\t");
} }
......
#ifndef ALARM_TREE_WIDGET_H #ifndef ALARM_TREE_WIDGET_H
#define ALARM_TREE_WIDGET_H #define ALARM_TREE_WIDGET_H
#include "filter.h" #include "filter.h"
...@@ -17,12 +17,15 @@ class AlarmTreeWidget : public QTreeWidget ...@@ -17,12 +17,15 @@ class AlarmTreeWidget : public QTreeWidget
public: public:
enum Type {AlarmType, DisabledAlarmType }; enum Type {AlarmType, DisabledAlarmType };
enum Columns { DATET, MICROSEC, ALARM, STATUS, ACK, LEVEL, SILENCED, DEVICE, MESSAGE, COLUMN_COUNT }; enum Columns { DATET, MICROSEC, ALARM, STATUS, ACK, LEVEL, SILENCED, DEVICE, MESSAGE, COLUMN_COUNT };
enum SrvErrState { SrvErrNew = 0x1, SrvErrUnack = 0x2 };
AlarmTreeWidget(QWidget *parent); AlarmTreeWidget(QWidget *parent);
void setType(Type t); void setType(Type t);
int findPos(time_t ts, const QString& pri, const QString &status); int findPos(time_t ts, const QString& pri, const QString &status);
int countAll() const; int countAll() const;
int countAlarmed() const; int countAlarmed() const;
void setServerErrNotNew(const QString& errdev);
void setServerErrAck(const QString& n);
public slots: public slots:
void refresh(const CuData &v); void refresh(const CuData &v);
...@@ -55,7 +58,7 @@ private: ...@@ -55,7 +58,7 @@ private:
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; QMap<QString, int> m_src_err_map;
QString m_make_key(const QString& alarm, const QString& handler) const; QString m_make_key(const QString& alarm, const QString& handler) const;
Type m_type; Type m_type;
......
...@@ -124,7 +124,7 @@ void AlarmTreeWidgetItem::update(const QStringList &fields) ...@@ -124,7 +124,7 @@ void AlarmTreeWidgetItem::update(const QStringList &fields)
setBackground(SilencedMin, c); setBackground(SilencedMin, c);
mHasMutedIcon = true; mHasMutedIcon = true;
} }
else if(mHasMutedIcon && silenced < 0) else if(mHasMutedIcon && silenced <= 0)
{ {
mHasMutedIcon = false; mHasMutedIcon = false;
setIcon(SilencedMin, mNullIcon); setIcon(SilencedMin, mNullIcon);
......
...@@ -5,62 +5,85 @@ ...@@ -5,62 +5,85 @@
#include <AlarmTreeWidget.h> #include <AlarmTreeWidget.h>
#include <AlarmTreeWidgetItem.h> #include <AlarmTreeWidgetItem.h>
#include <quwriter.h> #include <quwriter.h>
#include <QtDebug>
Acmd::Acmd() { Acmd::Acmd() {
} }
void Acmd::ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool& fpoo) { // ack alarms
// if a selected element represents a server error (not a true alarm), then do not operate on it
// and store the name into errdevs
void Acmd::ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool& fpoo, QStringList &errdevs) {
QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all); QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all);
foreach(const QString& dev, map.uniqueKeys()) { foreach(const QString& dev, map.uniqueKeys()) {
QuWriter *w = new QuWriter(nullptr, cup, fpoo); QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev); const QStringList &alarms = map.values(dev);
w->setAutoDestroy(true); if(alarms.size() != 1 || alarms[0].count('/') != 3) { // exclude "Alarm server error"
w->setTarget(QString("%1->Ack").arg(dev)); w->setAutoDestroy(true);
printf("AckCmd.ack: executing %s (%s)\n", qstoc(w->target()), qstoc(alarms.join(","))); w->setTarget(QString("%1->Ack").arg(dev));
w->execute(alarms); w->execute(alarms);
/* stop new */ /* stop new */
QuWriter *stopNewWriter = new QuWriter(nullptr, cup, fpoo); QuWriter *stopNewWriter = new QuWriter(nullptr, cup, fpoo);
stopNewWriter->setAutoDestroy(true); stopNewWriter->setAutoDestroy(true);
stopNewWriter->setTarget(dev + "->StopNew"); stopNewWriter->setTarget(dev + "->StopNew");
stopNewWriter->execute(); stopNewWriter->execute();
}
else
errdevs << alarms[0];
} }
} }
void Acmd::silence(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo) { // silence alarms
// if a selected element represents a server error (not a true alarm), then do not operate on it
// and store the name into errdevs
void Acmd::silence(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo, QStringList &errdevs) {
QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all); QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all);
foreach(const QString& dev, map.uniqueKeys()) { foreach(const QString& dev, map.uniqueKeys()) {
QuWriter *w = new QuWriter(nullptr, cup, fpoo); QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev); const QStringList &alarms = map.values(dev);
w->setAutoDestroy(true); if(alarms.size() != 1 || alarms[0].count('/') != 3) { // exclude "Alarm server error"
w->setTarget(dev + "->Silence"); w->setAutoDestroy(true);
printf("AckCmd.ack: executing %s (%s)\n", qstoc(w->target()), qstoc(alarms.join(","))); w->setTarget(dev + "->Silence");
w->execute(alarms); w->execute(alarms);
}
else
errdevs << alarms[0];
} }
} }
// enable selected alarms
//
void Acmd::enable(const QTreeWidget *tw, CumbiaPool *cup, const CuControlsFactoryPool &fpoo) { void Acmd::enable(const QTreeWidget *tw, CumbiaPool *cup, const CuControlsFactoryPool &fpoo) {
QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, false); QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, false);
foreach(const QString& dev, map.uniqueKeys()) { foreach(const QString& dev, map.uniqueKeys()) {
QuWriter *w = new QuWriter(nullptr, cup, fpoo); QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev); const QStringList &alarms = map.values(dev);
w->setAutoDestroy(true); if(alarms.size() != 1 || alarms[0].count('/') != 3) { // exclude "Alarm server error"
w->setTarget(dev + "->Enable"); w->setAutoDestroy(true);
printf("AckCmd.ack: executing %s (%s)\n", qstoc(w->target()), qstoc(alarms.join(","))); w->setTarget(dev + "->Enable");
w->execute(alarms); w->execute(alarms);
}
} }
} }
void Acmd::stop_new(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo) { // stop new alarms
// if a selected element represents a server error (not a true alarm), then do not operate on it
// and store the name into errdevs
void Acmd::stop_new(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo,
QStringList &errdevs) {
QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all); QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all);
foreach(const QString& dev, map.uniqueKeys()) { foreach(const QString& dev, map.uniqueKeys()) { // exclude "Alarm server error"
QuWriter *w = new QuWriter(nullptr, cup, fpoo); QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev); const QStringList &alarms = map.values(dev);
w->setAutoDestroy(true); if(alarms.size() != 1 || alarms[0].count('/') != 3) {
w->setTarget(dev + "->StopNew"); w->setAutoDestroy(true);
printf("AckCmd.stop_new: executing %s\n", qstoc(w->target())); w->setTarget(dev + "->StopNew");
w->execute(alarms); w->execute(alarms);
}
else
errdevs << alarms[0];
} }
} }
......
...@@ -11,9 +11,9 @@ class Acmd ...@@ -11,9 +11,9 @@ class Acmd
{ {
public: public:
Acmd(); Acmd();
void ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo); void ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo, QStringList& errdevs);
void silence(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo); void silence(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo, QStringList &errdevs);
void stop_new(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo); void stop_new(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo, QStringList &errdevs);
void enable(const QTreeWidget *tw, CumbiaPool *cup, const CuControlsFactoryPool &fpoo); void enable(const QTreeWidget *tw, CumbiaPool *cup, const CuControlsFactoryPool &fpoo);
private: private:
QMultiMap<QString, QString> m_getDevAlarmMap(const QTreeWidget *tw, bool all) const; QMultiMap<QString, QString> m_getDevAlarmMap(const QTreeWidget *tw, bool all) const;
......
...@@ -226,7 +226,10 @@ QList<QTreeWidgetItem *> Alarm::mGetSelectedItems() ...@@ -226,7 +226,10 @@ QList<QTreeWidgetItem *> Alarm::mGetSelectedItems()
void Alarm::silence() void Alarm::silence()
{ {
Acmd acmd; Acmd acmd;
acmd.silence(ui->treeWidgetAlarms, false, cu_pool, m_ctrl_factory_pool); QStringList errdevs; // list of "server error" devs
acmd.silence(ui->treeWidgetAlarms, false, cu_pool, m_ctrl_factory_pool, errdevs);
foreach(const QString& ed, errdevs)
ui->treeWidgetAlarms->setServerErrNotNew(ed);
sound->stop(); sound->stop();
} }
...@@ -250,18 +253,31 @@ void Alarm::openUrl(const QString &u) const { ...@@ -250,18 +253,31 @@ void Alarm::openUrl(const QString &u) const {
void Alarm::stopSound() { void Alarm::stopSound() {
Acmd acmd; Acmd acmd;
acmd.stop_new(ui->treeWidgetAlarms, true, cu_pool, m_ctrl_factory_pool); QStringList errdevs; // list of "server error" devs
acmd.stop_new(ui->treeWidgetAlarms, true, cu_pool, m_ctrl_factory_pool, errdevs);
foreach(const QString& ed, errdevs)
ui->treeWidgetAlarms->setServerErrNotNew(ed);
sound->stop(); sound->stop();
} }
void Alarm::ack() { void Alarm::ack() {
Acmd acmd; Acmd acmd;
acmd.ack(ui->treeWidgetAlarms, false, cu_pool, m_ctrl_factory_pool); QStringList errdevs; // list of "server error" devs
acmd.ack(ui->treeWidgetAlarms, false, cu_pool, m_ctrl_factory_pool, errdevs);
foreach(const QString& ed, errdevs) {
ui->treeWidgetAlarms->setServerErrNotNew(ed);
ui->treeWidgetAlarms->setServerErrAck(ed);
}
} }
void Alarm::ackAll() { void Alarm::ackAll() {
Acmd acmd; Acmd acmd;
acmd.ack(ui->treeWidgetAlarms, true, cu_pool, m_ctrl_factory_pool); QStringList errdevs; // list of "server error" devs
acmd.ack(ui->treeWidgetAlarms, true, cu_pool, m_ctrl_factory_pool, errdevs);
foreach(const QString& ed, errdevs) {
ui->treeWidgetAlarms->setServerErrNotNew(ed);
ui->treeWidgetAlarms->setServerErrAck(ed);
}
} }
void Alarm::onInfoListViewVisibilityChange(bool vis) { void Alarm::onInfoListViewVisibilityChange(bool vis) {
......
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