return back stream lock which will be disabled from qml by the timer. In

other case there is possibe plasma crash
This commit is contained in:
arcan1s 2015-09-26 03:23:10 +03:00
parent ab2a444c84
commit 92ce241742
6 changed files with 50 additions and 32 deletions

View File

@ -63,6 +63,8 @@ Item {
"notify": plasmoid.configuration.notify "notify": plasmoid.configuration.notify
} }
signal connectPlugin
signal disconnectPlugin
signal dropSource(string sourceName) signal dropSource(string sourceName)
signal needTextUpdate(string newText) signal needTextUpdate(string newText)
signal needToolTipUpdate(string newText) signal needToolTipUpdate(string newText)
@ -87,11 +89,6 @@ Item {
connectedSources: systemmonitorDE.sources connectedSources: systemmonitorDE.sources
interval: plasmoid.configuration.interval interval: plasmoid.configuration.interval
onNewData: {
if (debug) console.debug("Update source", sourceName)
awKeys.dataUpdateReceived(sourceName, data)
}
onSourceAdded: { onSourceAdded: {
if (debug) console.debug("Source", source) if (debug) console.debug("Source", source)
awKeys.addDevice(source) awKeys.addDevice(source)
@ -103,11 +100,6 @@ Item {
engine: "extsysmon" engine: "extsysmon"
connectedSources: extsysmonDE.sources connectedSources: extsysmonDE.sources
interval: plasmoid.configuration.interval interval: plasmoid.configuration.interval
onNewData: {
if (debug) console.debug("Update source", sourceName)
awKeys.dataUpdateReceived(sourceName, data)
}
} }
PlasmaCore.DataSource { PlasmaCore.DataSource {
@ -115,11 +107,6 @@ Item {
engine: "time" engine: "time"
connectedSources: ["Local"] connectedSources: ["Local"]
interval: 1000 interval: 1000
onNewData: {
if (debug) console.debug("Update source", sourceName)
awKeys.dataUpdateReceived(sourceName, data)
}
} }
@ -173,6 +160,12 @@ Item {
} }
} }
Timer {
id: timer
interval: 5 * plasmoid.configuration.interval
onTriggered: connectPlugin()
}
Component.onCompleted: { Component.onCompleted: {
if (debug) console.debug() if (debug) console.debug()
@ -184,13 +177,35 @@ Item {
// init submodule // init submodule
Plasmoid.userConfiguringChanged(false) Plasmoid.userConfiguringChanged(false)
// connect data // connect data
awKeys.disconnectPlugin.connect(disconnectPlugin)
awKeys.dropSourceFromDataengine.connect(dropSource) awKeys.dropSourceFromDataengine.connect(dropSource)
awKeys.needTextToBeUpdated.connect(needTextUpdate) awKeys.needTextToBeUpdated.connect(needTextUpdate)
awKeys.needToolTipToBeUpdated.connect(needToolTipUpdate) awKeys.needToolTipToBeUpdated.connect(needToolTipUpdate)
connectPlugin()
// check updates if required // check updates if required
if (plasmoid.configuration.checkUpdates) return awActions.checkUpdates(false) if (plasmoid.configuration.checkUpdates) return awActions.checkUpdates(false)
} }
onConnectPlugin: {
if (debug) console.debug()
systemmonitorDE.newData.connect(awKeys.dataUpdateReceived)
extsysmonDE.newData.connect(awKeys.dataUpdateReceived)
timeDE.newData.connect(awKeys.dataUpdateReceived)
return awKeys.unlock()
}
onDisconnectPlugin: {
if (debug) console.debug()
systemmonitorDE.newData.disconnect(awKeys.dataUpdateReceived)
extsysmonDE.newData.disconnect(awKeys.dataUpdateReceived)
timeDE.newData.disconnect(awKeys.dataUpdateReceived)
return timer.start()
}
onDropSource: { onDropSource: {
if (debug) console.debug() if (debug) console.debug()
if (debug) console.debug("Source", sourceName) if (debug) console.debug("Source", sourceName)

View File

@ -31,9 +31,8 @@
#include "awdebug.h" #include "awdebug.h"
AWDataAggregator::AWDataAggregator(QObject *parent, QThreadPool *pThreadPool) AWDataAggregator::AWDataAggregator(QObject *parent)
: QObject(parent), : QObject(parent)
threadPool(pThreadPool)
{ {
qCDebug(LOG_AW); qCDebug(LOG_AW);
// required by signals // required by signals
@ -86,6 +85,7 @@ void AWDataAggregator::setParameters(QVariantMap settings)
m_enablePopup = configuration[QString("notify")].toBool(); m_enablePopup = configuration[QString("notify")].toBool();
counts = 0;
counts += configuration[QString("cpuTooltip")].toInt(); counts += configuration[QString("cpuTooltip")].toInt();
counts += configuration[QString("cpuclTooltip")].toInt(); counts += configuration[QString("cpuclTooltip")].toInt();
counts += configuration[QString("memTooltip")].toInt(); counts += configuration[QString("memTooltip")].toInt();
@ -103,6 +103,7 @@ void AWDataAggregator::setParameters(QVariantMap settings)
boundaries[QString("upTooltip")] = 1.0; boundaries[QString("upTooltip")] = 1.0;
boundaries[QString("batTooltip")] = 100.0; boundaries[QString("batTooltip")] = 100.0;
requiredKeys.clear();
if (configuration[QString("cpuTooltip")].toBool()) requiredKeys.append(QString("cpuTooltip")); if (configuration[QString("cpuTooltip")].toBool()) requiredKeys.append(QString("cpuTooltip"));
if (configuration[QString("cpuclTooltip")].toBool()) requiredKeys.append(QString("cpuclTooltip")); if (configuration[QString("cpuclTooltip")].toBool()) requiredKeys.append(QString("cpuclTooltip"));
if (configuration[QString("memTooltip")].toBool()) requiredKeys.append(QString("memTooltip")); if (configuration[QString("memTooltip")].toBool()) requiredKeys.append(QString("memTooltip"));
@ -161,13 +162,7 @@ void AWDataAggregator::dataUpdate(const QHash<QString, QString> values)
{ {
qCDebug(LOG_AW); qCDebug(LOG_AW);
#ifdef BUILD_FUTURE
QtConcurrent::run(threadPool, [this, values]() {
setData(values);
});
#else /* BUILD_FUTURE */
setData(values); setData(values);
#endif /* BUILD_FUTURE */
emit(toolTipPainted(htmlImage(tooltipImage()))); emit(toolTipPainted(htmlImage(tooltipImage())));
} }

View File

@ -33,7 +33,7 @@ class AWDataAggregator : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit AWDataAggregator(QObject *parent = nullptr, QThreadPool *pThreadPool = nullptr); explicit AWDataAggregator(QObject *parent = nullptr);
virtual ~AWDataAggregator(); virtual ~AWDataAggregator();
QList<float> getData(const QString key) const; QList<float> getData(const QString key) const;
QString htmlImage(const QPixmap source) const; QString htmlImage(const QPixmap source) const;
@ -70,7 +70,6 @@ private:
QHash<QString, QList<float>> data; QHash<QString, QList<float>> data;
bool m_enablePopup = false; bool m_enablePopup = false;
QStringList requiredKeys; QStringList requiredKeys;
QThreadPool *threadPool = nullptr;
}; };

View File

@ -50,11 +50,10 @@ AWKeys::AWKeys(QObject *parent)
// thread pool // thread pool
queueLimit = QThread::idealThreadCount(); queueLimit = QThread::idealThreadCount();
threadPool = new QThreadPool(this); threadPool = new QThreadPool(this);
threadPool->setMaxThreadCount(queueLimit);
#endif /* BUILD_FUTURE */ #endif /* BUILD_FUTURE */
aggregator = new AWKeysAggregator(this); aggregator = new AWKeysAggregator(this);
dataAggregator = new AWDataAggregator(this, threadPool); dataAggregator = new AWDataAggregator(this);
// transfer signal from AWDataAggregator object to QML ui // transfer signal from AWDataAggregator object to QML ui
connect(dataAggregator, SIGNAL(toolTipPainted(const QString)), connect(dataAggregator, SIGNAL(toolTipPainted(const QString)),
this, SIGNAL(needToolTipToBeUpdated(const QString))); this, SIGNAL(needToolTipToBeUpdated(const QString)));
@ -126,6 +125,14 @@ void AWKeys::setWrapNewLines(const bool wrap)
} }
void AWKeys::unlock()
{
qCDebug(LOG_AW);
lock = false;
}
void AWKeys::addDevice(const QString source) void AWKeys::addDevice(const QString source)
{ {
qCDebug(LOG_AW); qCDebug(LOG_AW);
@ -324,12 +331,11 @@ void AWKeys::dataUpdateReceived(const QString sourceName, const QVariantMap data
qCDebug(LOG_AW) << "Source" << sourceName; qCDebug(LOG_AW) << "Source" << sourceName;
qCDebug(LOG_AW) << "Data" << data; qCDebug(LOG_AW) << "Data" << data;
// we will update text even if queue limit is reached if (lock) return;
if (sourceName == QString("update")) return emit(needToBeUpdated()); if (sourceName == QString("update")) return emit(needToBeUpdated());
#ifdef BUILD_FUTURE #ifdef BUILD_FUTURE
// run concurrent data update // run concurrent data update
if ((lock = ((lock) && (queue > 0)))) return;
QtConcurrent::run(threadPool, [this, sourceName, data]() { QtConcurrent::run(threadPool, [this, sourceName, data]() {
return setDataBySource(sourceName, data); return setDataBySource(sourceName, data);
}); });
@ -682,6 +688,7 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data)
if (++queue > queueLimit) { if (++queue > queueLimit) {
qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << queueLimit; qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << queueLimit;
lock = true; lock = true;
emit(disconnectPlugin());
return; return;
} }
#endif /* BUILD_FUTURE */ #endif /* BUILD_FUTURE */

View File

@ -45,6 +45,7 @@ public:
Q_INVOKABLE void initKeys(const QString currentPattern, const int limit); Q_INVOKABLE void initKeys(const QString currentPattern, const int limit);
Q_INVOKABLE void setAggregatorProperty(const QString key, const QVariant value); Q_INVOKABLE void setAggregatorProperty(const QString key, const QVariant value);
Q_INVOKABLE void setWrapNewLines(const bool wrap = false); Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
Q_INVOKABLE void unlock();
// keys // keys
Q_INVOKABLE void addDevice(const QString source); Q_INVOKABLE void addDevice(const QString source);
Q_INVOKABLE QStringList dictKeys(const bool sorted = false, Q_INVOKABLE QStringList dictKeys(const bool sorted = false,
@ -58,6 +59,7 @@ public:
Q_INVOKABLE void editItem(const QString type); Q_INVOKABLE void editItem(const QString type);
signals: signals:
void disconnectPlugin() const;
void dropSourceFromDataengine(const QString source); void dropSourceFromDataengine(const QString source);
void needTextToBeUpdated(const QString newText) const; void needTextToBeUpdated(const QString newText) const;
void needToolTipToBeUpdated(const QString newText) const; void needToolTipToBeUpdated(const QString newText) const;
@ -89,8 +91,8 @@ private:
QHash<QString, QString> values; QHash<QString, QString> values;
bool m_wrapNewLines = false; bool m_wrapNewLines = false;
// queue and stream lock properties // queue and stream lock properties
bool lock = false;
QThreadPool *threadPool = nullptr; QThreadPool *threadPool = nullptr;
bool lock = true;
int queueLimit, queue = 0; int queueLimit, queue = 0;
}; };