* limit messages queue to ideal thread count

* move from QtScript to QJSEngine (first is deprecated since 5.6)
* drop unneeded includes in headers
* some changes inside queue managing
This commit is contained in:
arcan1s 2015-09-17 01:10:55 +03:00
parent 646e897058
commit 24eb548bb3
10 changed files with 64 additions and 52 deletions

View File

@ -29,7 +29,7 @@ option(BUILD_FUTURE "Build with the features which will be marked as stable late
option(BUILD_PLASMOIDS "Build plasmoids" ON)
option(BUILD_DEB_PACKAGE "Build deb package" OFF)
option(BUILD_RPM_PACKAGE "Build rpm package" OFF)
set(QUEUE_LIMIT 10 CACHE INTEGER "Limit data queue to this value")
set(QUEUE_LIMIT 0 CACHE INTEGER "Limit data queue to this value")
# flags
if(CMAKE_COMPILER_IS_GNUCXX)

View File

@ -20,7 +20,6 @@
#define AWACTIONS_H
#include <QObject>
#include <QVariant>
class QNetworkReply;

View File

@ -34,8 +34,8 @@ AWDataAggregator::AWDataAggregator(QObject *parent)
initScene();
connect(this, SIGNAL(const updateData(QHash<QString, QString>)),
this, SLOT(const dataUpdate(QHash<QString, QString>)));
connect(this, SIGNAL(updateData(const QHash<QString, QString>)),
this, SLOT(dataUpdate(const QHash<QString, QString>)));
}

View File

@ -21,10 +21,8 @@
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QHash>
#include <QObject>
#include <QPixmap>
#include <QVariant>
class AWDataAggregator : public QObject

View File

@ -20,12 +20,11 @@
#include <QtConcurrent/QtConcurrent>
#include <QDir>
#include <QInputDialog>
#include <QJSEngine>
#include <QNetworkInterface>
#include <QRegExp>
#include <QScriptEngine>
#include <QSettings>
#include <QStandardPaths>
#include <QThread>
#include "awdebug.h"
#include "awkeysaggregator.h"
@ -584,16 +583,16 @@ void AWKeys::calculateValues()
// lambdas
foreach(QString key, m_foundLambdas)
values[key] = [this](QString key) {
QScriptEngine engine;
QJSEngine engine;
// apply $this values
key.replace(QString("$this"), values[key]);
foreach(QString lambdaKey, m_foundKeys)
key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]);
qCInfo(LOG_AW) << "Expression" << key;
QScriptValue result = engine.evaluate(key);
if (engine.hasUncaughtException()) {
int line = engine.uncaughtExceptionLineNumber();
qCWarning(LOG_AW) << "Uncaught exception at line" << line << ":" << result.toString();
QJSValue result = engine.evaluate(key);
if (result.isError()) {
qCWarning(LOG_AW) << "Uncaught exception at line" << result.property("lineNumber").toInt()
<< ":" << result.toString();
return QString();
} else
return result.toString();
@ -646,8 +645,7 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data)
{
#ifdef BUILD_FUTURE
// check if data stream is locked
lock = ((lock) && (queue > 0));
if (lock) return;
// if ((lock = ((lock) && (queue > 0)))) return;
#endif /* BUILD_FUTURE */
qCDebug(LOG_AW);
@ -658,9 +656,11 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data)
if (sourceName == QString("update")) return emit(needToBeUpdated());
// drop if limits are reached
if (++queue > QUEUE_LIMIT) {
qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << QUEUE_LIMIT << ", lock";
lock = true;
// qDebug() << ++queue;
// if (queue > queueLimit) {
if (++queue > queueLimit) {
qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << queueLimit;
// lock = true;
return;
}
@ -681,5 +681,9 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data)
});
}
// volatile float n = 1.0;
// for (volatile float i=1.0; i<100000.0; i++)
// n *= i;
// qDebug() << queue-- << queueLimit;
queue--;
}

View File

@ -19,11 +19,11 @@
#ifndef AWKEYS_H
#define AWKEYS_H
#include <QHash>
#include <QObject>
#include <QVariant>
#include <QThread>
#include "extitemaggregator.h"
#include "version.h"
class AWDataAggregator;
@ -75,20 +75,27 @@ private:
void calculateValues();
QString parsePattern(QString pattern) const;
void setDataBySource(const QString sourceName, const QVariantMap data);
// objects
AWKeysAggregator *aggregator = nullptr;
AWDataAggregator *dataAggregator = nullptr;
bool m_wrapNewLines = false;
ExtItemAggregator<GraphicalItem> *graphicalItems = nullptr;
ExtItemAggregator<ExtQuotes> *extQuotes = nullptr;
ExtItemAggregator<ExtScript> *extScripts = nullptr;
ExtItemAggregator<ExtUpgrade> *extUpgrade = nullptr;
ExtItemAggregator<ExtWeather> *extWeather = nullptr;
// variables
QHash<QString, QStringList> m_devices;
QStringList m_foundBars, m_foundKeys, m_foundLambdas;
QString m_pattern;
QHash<QString, QString> values;
bool m_wrapNewLines = false;
// queue and stream lock properties
bool lock = false;
int queue = 0;
QString m_pattern;
QStringList m_foundBars, m_foundKeys, m_foundLambdas;
QHash<QString, QString> values;
QHash<QString, QStringList> m_devices;
// queue limit. It may be configured by using QUEUE_LIMIT cmake limit flag.
// In other hand since I'm using global thread pool, it makes sense to limit
// queue by QThread::idealThreadCount() value
const int queueLimit = QUEUE_LIMIT == 0 ? QThread::idealThreadCount() : QUEUE_LIMIT;
};

View File

@ -19,8 +19,8 @@
#ifndef AWKEYSAGGREGATOR_H
#define AWKEYSAGGREGATOR_H
#include <QHash>
#include <QObject>
#include <QVariant>
#include "version.h"

View File

@ -57,6 +57,7 @@ DPAdds::~DPAdds()
}
// HACK: since QML could not use QLoggingCategory I need this hack
bool DPAdds::isDebugEnabled() const
{
qCDebug(LOG_DP);
@ -99,11 +100,13 @@ QString DPAdds::toolTipImage(const int desktop) const
{
qCDebug(LOG_DP);
qCDebug(LOG_DP) << "Desktop" << desktop;
if (tooltipType == QString("none")) return QString();
// drop if no tooltip required
if (m_tooltipType == QString("none")) return QString();
// prepare
DesktopWindowsInfo info = getInfoByDesktop(desktop);
if (tooltipType == QString("names")) {
// special tooltip format for names
if (m_tooltipType == QString("names")) {
QStringList windowList;
std::for_each(info.windowsData.cbegin(), info.windowsData.cend(),
[&windowList](WindowData data) { windowList.append(data.name); });
@ -130,10 +133,10 @@ QString DPAdds::toolTipImage(const int desktop) const
info.desktop.width() + 2.0 * margin, 0);
toolTipScene->addLine(info.desktop.width() + 2.0 * margin, 0, 0, 0);
if (tooltipType == QString("contours")) {
if (m_tooltipType == QString("contours")) {
QPen pen = QPen();
pen.setWidthF(2.0 * info.desktop.width() / 400.0);
pen.setColor(QColor(tooltipColor));
pen.setColor(QColor(m_tooltipColor));
foreach(WindowData data, info.windowsData) {
QRect rect = data.rect;
toolTipScene->addLine(rect.left() + margin, rect.bottom() + margin,
@ -145,14 +148,14 @@ QString DPAdds::toolTipImage(const int desktop) const
toolTipScene->addLine(rect.right() + margin, rect.bottom() + margin,
rect.left() + margin, rect.bottom() + margin, pen);
}
} else if (tooltipType == QString("clean")) {
} else if (m_tooltipType == QString("clean")) {
QScreen *screen = QGuiApplication::primaryScreen();
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
[&toolTipScene, &screen](WindowData data) {
QPixmap desktop = screen->grabWindow(data.id);
toolTipScene->addPixmap(desktop)->setOffset(data.rect.left(), data.rect.top());
});
} else if (tooltipType == QString("windows")) {
} else if (m_tooltipType == QString("windows")) {
QScreen *screen = QGuiApplication::primaryScreen();
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
[&toolTipScene, &screen](WindowData data) {
@ -166,7 +169,7 @@ QString DPAdds::toolTipImage(const int desktop) const
});
}
QPixmap image = toolTipView->grab().scaledToWidth(tooltipWidth);
QPixmap image = toolTipView->grab().scaledToWidth(m_tooltipWidth);
QByteArray byteArray;
QBuffer buffer(&byteArray);
image.save(&buffer, "PNG");
@ -199,7 +202,7 @@ void DPAdds::setMark(const QString newMark)
qCDebug(LOG_DP);
qCDebug(LOG_DP) << "Mark" << newMark;
mark = newMark;
m_mark = newMark;
}
@ -208,9 +211,9 @@ void DPAdds::setToolTipData(const QVariantMap tooltipData)
qCDebug(LOG_DP);
qCDebug(LOG_DP) << "Data" << tooltipData;
tooltipColor = tooltipData[QString("tooltipColor")].toString();
tooltipType = tooltipData[QString("tooltipType")].toString();
tooltipWidth = tooltipData[QString("tooltipWidth")].toInt();
m_tooltipColor = tooltipData[QString("tooltipColor")].toString();
m_tooltipType = tooltipData[QString("tooltipType")].toString();
m_tooltipWidth = tooltipData[QString("tooltipWidth")].toInt();
}
@ -221,9 +224,9 @@ QString DPAdds::valueByKey(const QString key, int desktop) const
qCDebug(LOG_DP) << "Desktop number" << desktop;
if (desktop == -1) desktop = currentDesktop();
QString currentMark = currentDesktop() == desktop ? mark : QString("");
QString currentMark = currentDesktop() == desktop ? m_mark : QString("");
if (key == QString("mark"))
return QString("%1").arg(currentMark, mark.count(), QLatin1Char(' '))
return QString("%1").arg(currentMark, m_mark.count(), QLatin1Char(' '))
.replace(QString(" "), QString("&nbsp;"));
else if (key == QString("name"))
return KWindowSystem::desktopName(desktop).replace(QString(" "), QString("&nbsp;"));
@ -236,6 +239,7 @@ QString DPAdds::valueByKey(const QString key, int desktop) const
}
// HACK: this method uses variables from version.h
QString DPAdds::getAboutText(const QString type) const
{
qCDebug(LOG_DP);
@ -294,6 +298,7 @@ QVariantMap DPAdds::getFont(const QVariantMap defaultFont) const
}
// to avoid additional object definition this method is static
void DPAdds::sendNotification(const QString eventId, const QString message)
{
qCDebug(LOG_DP);
@ -305,6 +310,7 @@ void DPAdds::sendNotification(const QString eventId, const QString message)
}
// slot for mouse click
void DPAdds::setCurrentDesktop(const int desktop) const
{
qCDebug(LOG_DP);

View File

@ -19,11 +19,9 @@
#ifndef DPADDS_H
#define DPADDS_H
#include <Plasma/Containment>
#include <QMap>
#include <QObject>
#include <QVariant>
// ui library required by WId definition
#include <QGuiApplication>
#include <QRect>
class DPAdds : public QObject
@ -71,10 +69,10 @@ public slots:
private:
DesktopWindowsInfo getInfoByDesktop(const int desktop) const;
// variables
int tooltipWidth = 200;
QString mark = QString("*");
QString tooltipColor = QString("#000000");
QString tooltipType = QString("none");
int m_tooltipWidth = 200;
QString m_mark = QString("*");
QString m_tooltipColor = QString("#000000");
QString m_tooltipType = QString("none");
};

View File

@ -2,18 +2,18 @@
find_package(Gettext REQUIRED)
# main qt libraries
find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Script Qml Widgets)
find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets)
add_definitions(
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
${Qt5Script_DEFINITIONS} ${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
)
set(Qt_INCLUDE
${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}
${Qt5Script_INCLUDE_DIRS} ${Qt5Qml_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}
${Qt5Qml_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}
)
set(Qt_LIBRARIES
${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES}
${Qt5Script_LIBRARIES} ${Qt5Qml_LIBRARIES} ${Qt5Widgets_LIBRARIES}
${Qt5Qml_LIBRARIES} ${Qt5Widgets_LIBRARIES}
)
# kf5 libraries