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) {
QString src = QuString(v, "src");
QString dev = src.section('/', 0, src.count('/') - 1);
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;
if(empty)
printf("\e[1;34mAlarmTreeWidget::refresh: attribute %s is empty <<<<<<<<<<<<<<<< \e[0m\n", qstoc(src));
QStringList data;
setToolTip(QuString(v, "msg"));
// error: err flag is true and message is not of type "cannot extract data..."
// only AlarmType adds an entry for each error
if (err && m_type == AlarmType) {
data << m_gen_error_item(v);
// perr("%s: %s\n", qstoc(src), datos(v));
m_src_err.insert(src);
if(!m_src_err_map.contains(src))
m_src_err_map.insert(src, SrvErrNew|SrvErrUnack); // true: new
}
else {
if(m_src_err.contains(src)) {
m_src_err.remove(src);
if(m_src_err_map.contains(src)) {
m_src_err_map.remove(src);
src_fixed = src;
}
data = QuStringList(v, "value");
......@@ -172,6 +168,16 @@ int AlarmTreeWidget::countAlarmed() const {
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)
{
bool silenceAvail = true;
......@@ -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 {
QStringList l;
QDateTime dt = QDateTime::currentDateTime();
QString dev = QuString(da, "src"), msg = QuString(da, "msg");
dev = dev.section('/', 0, dev.count('/') - 1);
l << QString::number(dt.toSecsSinceEpoch()) << "-" << dev << "ERROR" << "NACK" << "high" << "-1" << "gr_handler"
<< "Alarm server error: " + msg.replace("\n", " ") << "NEW";
QString dev, src = QuString(da, "src"), msg = QuString(da, "msg");
dev = src.section('/', 0, dev.count('/') - 1);
qDebug() << __PRETTY_FUNCTION__ << m_src_err_map;
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");
}
......
#ifndef ALARM_TREE_WIDGET_H
#ifndef ALARM_TREE_WIDGET_H
#define ALARM_TREE_WIDGET_H
#include "filter.h"
......@@ -17,12 +17,15 @@ class AlarmTreeWidget : public QTreeWidget
public:
enum Type {AlarmType, DisabledAlarmType };
enum Columns { DATET, MICROSEC, ALARM, STATUS, ACK, LEVEL, SILENCED, DEVICE, MESSAGE, COLUMN_COUNT };
enum SrvErrState { SrvErrNew = 0x1, SrvErrUnack = 0x2 };
AlarmTreeWidget(QWidget *parent);
void setType(Type t);
int findPos(time_t ts, const QString& pri, const QString &status);
int countAll() const;
int countAlarmed() const;
void setServerErrNotNew(const QString& errdev);
void setServerErrAck(const QString& n);
public slots:
void refresh(const CuData &v);
......@@ -55,7 +58,7 @@ private:
bool _filter_enabled;
QHash<QString, AlarmTreeWidgetItem*> mItemHash;
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;
Type m_type;
......
......@@ -124,7 +124,7 @@ void AlarmTreeWidgetItem::update(const QStringList &fields)
setBackground(SilencedMin, c);
mHasMutedIcon = true;
}
else if(mHasMutedIcon && silenced < 0)
else if(mHasMutedIcon && silenced <= 0)
{
mHasMutedIcon = false;
setIcon(SilencedMin, mNullIcon);
......
......@@ -5,19 +5,23 @@
#include <AlarmTreeWidget.h>
#include <AlarmTreeWidgetItem.h>
#include <quwriter.h>
#include <QtDebug>
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);
foreach(const QString& dev, map.uniqueKeys()) {
QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev);
if(alarms.size() != 1 || alarms[0].count('/') != 3) { // exclude "Alarm server error"
w->setAutoDestroy(true);
w->setTarget(QString("%1->Ack").arg(dev));
printf("AckCmd.ack: executing %s (%s)\n", qstoc(w->target()), qstoc(alarms.join(",")));
w->execute(alarms);
/* stop new */
......@@ -26,42 +30,61 @@ void Acmd::ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControl
stopNewWriter->setTarget(dev + "->StopNew");
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);
foreach(const QString& dev, map.uniqueKeys()) {
QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev);
if(alarms.size() != 1 || alarms[0].count('/') != 3) { // exclude "Alarm server error"
w->setAutoDestroy(true);
w->setTarget(dev + "->Silence");
printf("AckCmd.ack: executing %s (%s)\n", qstoc(w->target()), qstoc(alarms.join(",")));
w->execute(alarms);
}
else
errdevs << alarms[0];
}
}
// enable selected alarms
//
void Acmd::enable(const QTreeWidget *tw, CumbiaPool *cup, const CuControlsFactoryPool &fpoo) {
QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, false);
foreach(const QString& dev, map.uniqueKeys()) {
QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev);
if(alarms.size() != 1 || alarms[0].count('/') != 3) { // exclude "Alarm server error"
w->setAutoDestroy(true);
w->setTarget(dev + "->Enable");
printf("AckCmd.ack: executing %s (%s)\n", qstoc(w->target()), qstoc(alarms.join(",")));
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);
foreach(const QString& dev, map.uniqueKeys()) {
foreach(const QString& dev, map.uniqueKeys()) { // exclude "Alarm server error"
QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev);
if(alarms.size() != 1 || alarms[0].count('/') != 3) {
w->setAutoDestroy(true);
w->setTarget(dev + "->StopNew");
printf("AckCmd.stop_new: executing %s\n", qstoc(w->target()));
w->execute(alarms);
}
else
errdevs << alarms[0];
}
}
QMultiMap<QString, QString> Acmd::m_getDevAlarmMap(const QTreeWidget *tw, bool all) const {
......
......@@ -11,9 +11,9 @@ class Acmd
{
public:
Acmd();
void ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo);
void silence(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo);
void stop_new(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, QStringList &errdevs);
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);
private:
QMultiMap<QString, QString> m_getDevAlarmMap(const QTreeWidget *tw, bool all) const;
......
......@@ -226,7 +226,10 @@ QList<QTreeWidgetItem *> Alarm::mGetSelectedItems()
void Alarm::silence()
{
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();
}
......@@ -250,18 +253,31 @@ void Alarm::openUrl(const QString &u) const {
void Alarm::stopSound() {
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();
}
void Alarm::ack() {
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() {
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) {
......
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