mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-04 09:25:52 +00:00
drop code oriented on the stream lock in parallel updates
This fact caused by the qt signal-slot implementation. Even if slots code is going into parallel they will be called in the main app thread. And also it is used inside KF5 dataengine implementation, so I'm affraid that it could not be optimized w\o backend rewriting
This commit is contained in:
@ -69,9 +69,9 @@ QString AWDataAggregator::htmlImage(const QPixmap source) const
|
||||
QBuffer buffer(&byteArray);
|
||||
source.save(&buffer, "PNG");
|
||||
|
||||
return byteArray.isEmpty() ? QString()
|
||||
: QString("<img src=\"data:image/png;base64,%1\"/>").
|
||||
arg(QString(byteArray.toBase64()));
|
||||
return byteArray.isEmpty()
|
||||
? QString()
|
||||
: QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,8 +19,6 @@
|
||||
|
||||
#include <Plasma/DataEngineConsumer>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awkeys.h"
|
||||
|
||||
@ -30,16 +28,8 @@ AWDataEngineAggregator::AWDataEngineAggregator(QObject *parent, const int interv
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
// timer events
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(true);
|
||||
|
||||
setInterval(interval);
|
||||
initDataEngines();
|
||||
connectVisualization();
|
||||
|
||||
connect(this, SIGNAL(startTimer()), m_timer, SLOT(start()));
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(connectVisualization()));
|
||||
}
|
||||
|
||||
|
||||
@ -48,7 +38,6 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
m_dataEngines.clear();
|
||||
if (m_timer != nullptr) delete m_timer;
|
||||
}
|
||||
|
||||
|
||||
@ -58,33 +47,6 @@ void AWDataEngineAggregator::setInterval(const int _interval)
|
||||
qCDebug(LOG_AW) << "Interval" << _interval;
|
||||
|
||||
m_interval = _interval;
|
||||
m_timer->setInterval(5 * _interval);
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::connectVisualization()
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
// reconnectSources();
|
||||
connect(this, SIGNAL(updateData(QString, QVariant, QString )),
|
||||
parent(), SLOT(dataUpdated(QString, QVariant, QString)));
|
||||
|
||||
return static_cast<AWKeys *>(parent())->unlock();
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::disconnectVisualization()
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
disconnect(this, SIGNAL(updateData(QString, QVariant, QString)),
|
||||
parent(), SLOT(dataUpdated(QString, QVariant, QString)));
|
||||
// m_dataEngines.clear();
|
||||
|
||||
// HACK run timer in the main thread since a timer could not be started from
|
||||
// the different thread
|
||||
return emit(startTimer());
|
||||
}
|
||||
|
||||
|
||||
@ -119,8 +81,9 @@ void AWDataEngineAggregator::dataUpdated(const QString sourceName, const Plasma:
|
||||
// HACK "deep copy" of data to avoid plasma crash on Data object destruction
|
||||
QString units = data[QString("units")].toString();
|
||||
// HACK workaround for time values which are stored in the different path
|
||||
QVariant value = sourceName == QString("Local") ? data[QString("DateTime")]
|
||||
: data[QString("value")];
|
||||
QVariant value = sourceName == QString("Local")
|
||||
? data[QString("DateTime")]
|
||||
: data[QString("value")];
|
||||
|
||||
emit(updateData(sourceName, value, units));
|
||||
}
|
||||
@ -141,4 +104,7 @@ void AWDataEngineAggregator::initDataEngines()
|
||||
static_cast<AWKeys *>(parent())->addDevice(source);
|
||||
m_dataEngines[QString("systemmonitor")]->connectSource(source, this, m_interval);
|
||||
});
|
||||
|
||||
connect(this, SIGNAL(updateData(QString, QVariant, QString)),
|
||||
parent(), SLOT(dataUpdated(QString, QVariant, QString)));
|
||||
}
|
||||
|
@ -23,8 +23,6 @@
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class QTimer;
|
||||
|
||||
class AWDataEngineAggregator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -37,13 +35,9 @@ public:
|
||||
void setInterval(const int _interval);
|
||||
|
||||
signals:
|
||||
void startTimer();
|
||||
void updateData(const QString sourceName, const QVariant value, const QString units);
|
||||
|
||||
public slots:
|
||||
// additional methods to control this and visualization
|
||||
void connectVisualization();
|
||||
void disconnectVisualization();
|
||||
void dropSource(const QString source);
|
||||
void reconnectSources();
|
||||
// data engines operations
|
||||
@ -55,7 +49,6 @@ private:
|
||||
void initDataEngines();
|
||||
QHash<QString, Plasma::DataEngine *> m_dataEngines;
|
||||
int m_interval;
|
||||
QTimer *m_timer = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
@ -49,7 +49,6 @@ AWKeys::AWKeys(QObject *parent)
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
// thread pool
|
||||
m_queueLimit = 2 * QThread::idealThreadCount();
|
||||
m_threadPool = new QThreadPool(this);
|
||||
#endif /* BUILD_FUTURE */
|
||||
|
||||
@ -81,15 +80,6 @@ AWKeys::~AWKeys()
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::unlock()
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
qCWarning(LOG_AW) << "Unm_lock stream";
|
||||
m_lock = false;
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
@ -115,9 +105,7 @@ void AWKeys::initKeys(const QString currentPattern, const int interval, const in
|
||||
} else
|
||||
dataEngineAggregator->setInterval(interval);
|
||||
#ifdef BUILD_FUTURE
|
||||
int rawLimit = limit == 0 ? QThread::idealThreadCount() : limit;
|
||||
m_queueLimit = 2 * rawLimit;
|
||||
m_threadPool->setMaxThreadCount(rawLimit);
|
||||
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount() : limit);
|
||||
#endif /* BUILD_FUTURE */
|
||||
updateCache();
|
||||
|
||||
@ -177,7 +165,7 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
// uptime
|
||||
allKeys.append(QString("uptime"));
|
||||
allKeys.append(QString("cuptime"));
|
||||
// cpucm_lock & cpu
|
||||
// cpuclock & cpu
|
||||
for (int i=QThread::idealThreadCount()-1; i>=0; i--) {
|
||||
allKeys.append(QString("cpucl%1").arg(i));
|
||||
allKeys.append(QString("cpu%1").arg(i));
|
||||
@ -410,8 +398,6 @@ void AWKeys::dataUpdated(const QString sourceName, const QVariant value, const Q
|
||||
qCDebug(LOG_AW) << "Source" << sourceName;
|
||||
qCDebug(LOG_AW) << "Data" << value << units;
|
||||
|
||||
if (m_lock)
|
||||
return;
|
||||
if (sourceName == QString("update"))
|
||||
return emit(needToBeUpdated());
|
||||
|
||||
@ -714,15 +700,6 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariant value, con
|
||||
qCDebug(LOG_AW) << "Source" << sourceName;
|
||||
qCDebug(LOG_AW) << "Data" << value << units;
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
// drop if limits are reached
|
||||
if (++m_queue > m_queueLimit) {
|
||||
qCWarning(LOG_AW) << "Messages m_queue" << m_queue-- << "more than limits" << m_queueLimit;
|
||||
m_lock = true;
|
||||
return dataEngineAggregator->disconnectVisualization();
|
||||
}
|
||||
#endif /* BUILD_FUTURE */
|
||||
|
||||
// first list init
|
||||
QStringList tags = aggregator->keysFromSource(sourceName);
|
||||
if (tags.isEmpty())
|
||||
@ -733,14 +710,14 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariant value, con
|
||||
qCDebug(LOG_AW) << "Source" << sourceName << "not found";
|
||||
emit(dropSourceFromDataengine(sourceName));
|
||||
} else {
|
||||
#ifdef BUILD_FUTURE
|
||||
m_mutex.lock();
|
||||
#endif /* BUILD_FUTURE */
|
||||
std::for_each(tags.cbegin(), tags.cend(), [this, value](const QString tag) {
|
||||
values[tag] = aggregator->formater(value, tag);
|
||||
});
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
m_queue--;
|
||||
m_mutex.unlock();
|
||||
#endif /* BUILD_FUTURE */
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,6 @@ public:
|
||||
const int limit);
|
||||
Q_INVOKABLE void setAggregatorProperty(const QString key, const QVariant value);
|
||||
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
|
||||
Q_INVOKABLE void unlock();
|
||||
Q_INVOKABLE void updateCache();
|
||||
// keys
|
||||
Q_INVOKABLE QStringList dictKeys(const bool sorted = false,
|
||||
@ -95,11 +94,9 @@ private:
|
||||
QString m_pattern;
|
||||
QHash<QString, QString> values;
|
||||
bool m_wrapNewLines = false;
|
||||
// queue and stream lock properties
|
||||
// multithread features
|
||||
QThreadPool *m_threadPool = nullptr;
|
||||
QMutex m_mutex;
|
||||
int m_queueLimit, m_queue = 0;
|
||||
bool m_lock = true;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user