From 61e2a380b97a27d605021f5c19accd4fc8f08c34 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Mon, 9 Jun 2014 13:35:52 +0400 Subject: [PATCH] add support of multithreading to all functions of dataengine --- sources/ext-sysmon/extsysmon.cpp | 508 ++++++++++++++++++------------- sources/ext-sysmon/extsysmon.h | 32 +- 2 files changed, 310 insertions(+), 230 deletions(-) diff --git a/sources/ext-sysmon/extsysmon.cpp b/sources/ext-sysmon/extsysmon.cpp index 819c654..3f40892 100644 --- a/sources/ext-sysmon/extsysmon.cpp +++ b/sources/ext-sysmon/extsysmon.cpp @@ -143,17 +143,49 @@ void ExtendedSysMon::readConfiguration() } confFile.close(); configuration = updateConfiguration(rawConfig); - setCustomProcesses(); + setProcesses(); } -void ExtendedSysMon::setCustomProcesses() +void ExtendedSysMon::setProcesses() { - if (debug) qDebug() << "[DE]" << "[setCustomProcesses]"; + if (debug) qDebug() << "[DE]" << "[setProcesses]"; + // custom for (int i=0; istart(QString("bash -c \"") + cmd + QString("\"")); + processes[QString("custom")][number]->start(QString("bash -c \"") + cmd + QString("\"")); } void ExtendedSysMon::setCustomCmd() { if (debug) qDebug() << "[DE]" << "[setCustomCmd]"; - for (int i=0; itoUnicode(customProcesses[i]->readAllStandardOutput()).trimmed(); + value = QTextCodec::codecForMib(106)->toUnicode(processes[QString("custom")][i]->readAllStandardOutput()).trimmed(); if (!value.isEmpty()) { - if (debug) qDebug() << "[DE]" << "[setCustomCmd]" << ":" << "Found output for cmd" << i; + if (debug) qDebug() << "[DE]" << "[setCustomCmd]" << ":" << "Found data for cmd" << i; if (debug) qDebug() << "[DE]" << "[setCustomCmd]" << ":" << "Return" << value; QString source = QString("custom"); QString key = QString("custom") + QString::number(i); @@ -243,129 +275,192 @@ void ExtendedSysMon::setCustomCmd() } -float ExtendedSysMon::getGpu(const QString device) +void ExtendedSysMon::getGpu(const QString device) { if (debug) qDebug() << "[DE]" << "[getGpu]"; if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Run function with device" << device; - float gpu = 0.0; if ((device != QString("nvidia")) && (device != QString("ati"))) - return gpu; - QProcess command; - QString qoutput; + return; if (device == QString("nvidia")) { QString cmd = QString("nvidia-smi -q -d UTILIZATION"); if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Run cmd" << cmd; - command.start(cmd); - command.waitForFinished(-1); - if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Cmd returns" << command.exitCode(); - qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); + processes[QString("gpu")][0]->start(cmd); + } + else if (device == QString("ati")) { + QString cmd = QString("aticonfig --od-getclocks"); + if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Run cmd" << cmd; + processes[QString("gpu")][0]->start(cmd); + } +} + + +void ExtendedSysMon::setGpu() +{ + if (debug) qDebug() << "[DE]" << "[setGpu]"; + float value = 0.0; + QString qoutput; + if (configuration[QString("GPUDEV")] == QString("nvidia")) { + qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("gpu")][0]->readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); + else if (configuration[QString("GPUDEV")] == QString("ati")) { + qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("gpu")][0]->readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); - for (int i=0; istart(cmd); } else if (device == QString("ati")) { QString cmd = QString("aticonfig --od-gettemperature"); if (debug) qDebug() << "[DE]" << "[getGpuTemp]" << ":" << "Run cmd" << cmd; - command.start(cmd); - command.waitForFinished(-1); - if (debug) qDebug() << "[DE]" << "[getGpuTemp]" << ":" << "Cmd returns" << command.exitCode(); - qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); + processes[QString("gputemp")][0]->start(cmd); + } +} + + +void ExtendedSysMon::setGpuTemp() +{ + if (debug) qDebug() << "[DE]" << "[setGpuTemp]"; + float value = 0.0; + QString qoutput; + if (configuration[QString("GPUDEV")] == QString("nvidia")) { + qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("gputemp")][0]->readAllStandardOutput()); + for (int i=0; itoUnicode(processes[QString("gputemp")][0]->readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()).trimmed(); - if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) { - QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts)[2]; - temp.remove(QChar(0260)).remove(QChar('C')); - hddTemp = temp.toFloat(); - } - if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Return" << hddTemp; - return hddTemp; + processes[QString("hddtemp")][number]->start(cmd + QString(" ") + device); } -QStringList ExtendedSysMon::getPlayerInfo(const QString playerName, - const QString mpdAddress, - const QString mpdPort) +void ExtendedSysMon::setHddTemp() +{ + if (debug) qDebug() << "[DE]" << "[setHddTemp]"; + float value = 0.0; + QString qoutput = QString(""); + for (int i=0; itoUnicode(processes[QString("hddtemp")][i]->readAllStandardOutput()).trimmed(); + if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) { + QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts)[2]; + temp.remove(QChar(0260)).remove(QChar('C')); + value = temp.toFloat(); + if (debug) qDebug() << "[DE]" << "[setHddTemp]" << ":" << "Found data for cmd" << i; + if (debug) qDebug() << "[DE]" << "[setHddTemp]" << ":" << "Return" << value; + QString source = QString("hddtemp"); + QString key = configuration[QString("HDDDEV")].split(QChar(','), QString::SkipEmptyParts)[i]; + setData(source, key, value); + } + } +} + + +void ExtendedSysMon::getPlayerInfo(const QString playerName, + const QString mpdAddress, + const QString mpdPort) { if (debug) qDebug() << "[DE]" << "[getPlayerInfo]"; if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run function with player" << playerName; if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run function with MPD parameters" << mpdAddress + QString(":") + mpdPort; + QString cmd; + if (playerName == QString("amarok")) { + // amarok + cmd = QString("qdbus org.kde.amarok /Player GetMetadata"); + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; + processes[QString("player")][0]->start(cmd); + cmd = QString("qdbus org.kde.amarok /Player PositionGet"); + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; + processes[QString("player")][1]->start(cmd); + } + else if (playerName == QString("clementine")) { + // clementine + cmd = QString("qdbus org.mpris.clementine /Player GetMetadata"); + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; + processes[QString("player")][0]->start(cmd); + cmd = QString("qdbus org.mpris.clementine /Player PositionGet"); + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; + processes[QString("player")][1]->start(cmd); + } + else if (playerName == QString("mpd")) { + // mpd + cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl --connect-timeout 1 -fsm 3 telnet://") + + mpdAddress + QString(":") + mpdPort + QString("\""); + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; + processes[QString("player")][0]->start(cmd); + } + else if (playerName == QString("qmmp")) { + // qmmp + cmd = QString("qmmp --status"); + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; + processes[QString("player")][0]->start(cmd); + } +} + + +void ExtendedSysMon::setPlayer() +{ + if (debug) qDebug() << "[DE]" << "[setPlayer]"; + QString playerName = configuration[QString("PLAYER")]; + QString qoutput = QString(""); + QString qstr = QString(""); QStringList info; // album info.append(QString("unknown")); @@ -377,85 +472,64 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName, info.append(QString("0")); // title info.append(QString("unknown")); - QProcess command; - QString cmd; - QString qoutput = QString(""); - QString qstr; if (playerName == QString("amarok")) { - // amarok - cmd = QString("qdbus org.kde.amarok /Player GetMetadata"); - if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; - command.start(cmd); - command.waitForFinished(-1); - if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Cmd returns" << command.exitCode(); - qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); - for (int i=0; i 1) { - if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("album")) - info[0] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("artist")) - info[1] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("time")) - info[3] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("title")) - info[4] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("player")][0]->readAllStandardOutput()); + if (!qoutput.isEmpty()) { + if (debug) qDebug() << "[DE]" << "[setPlayer]" << ":" << "Found data for cmd" << 0; + for (int i=0; i 1) { + if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("album")) + info[0] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("artist")) + info[1] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("time")) + info[3] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("title")) + info[4] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + } } } - cmd = QString("qdbus org.kde.amarok /Player PositionGet"); - if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; - command.start(cmd); - command.waitForFinished(-1); - if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Cmd returns" << command.exitCode(); - qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); - for (int i=0; itoUnicode(processes[QString("player")][1]->readAllStandardOutput()); + if (!qoutput.isEmpty()) { + if (debug) qDebug() << "[DE]" << "[setPlayer]" << ":" << "Found data for cmd" << 1; + for (int i=0; itoUnicode(command.readAllStandardOutput()); - for (int i=0; i 1) { - if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("album")) - info[0] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("artist")) - info[1] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("time")) - info[3] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("title")) - info[4] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("player")][0]->readAllStandardOutput()); + if (!qoutput.isEmpty()) { + if (debug) qDebug() << "[DE]" << "[setPlayer]" << ":" << "Found data for cmd" << 0; + for (int i=0; i 1) { + if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("album")) + info[0] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("artist")) + info[1] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("time")) + info[3] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("title")) + info[4] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + } } } - cmd = QString("qdbus org.mpris.clementine /Player PositionGet"); - if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; - command.start(cmd); - command.waitForFinished(-1); - if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Cmd returns" << command.exitCode(); - qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); - for (int i=0; itoUnicode(processes[QString("player")][1]->readAllStandardOutput()); + if (!qoutput.isEmpty()) { + if (debug) qDebug() << "[DE]" << "[setPlayer]" << ":" << "Found data for cmd" << 1; + for (int i=0; itoUnicode(command.readAllStandardOutput()); + qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("player")][0]->readAllStandardOutput()); for (int i=0; i 1) { @@ -473,13 +547,7 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName, } } else if (playerName == QString("qmmp")) { - // qmmp - cmd = QString("qmmp --status"); - if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; - command.start(cmd); - command.waitForFinished(-1); - if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Cmd returns" << command.exitCode(); - qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); + qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("player")][0]->readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()).trimmed(); - for (int i=0; istart(cmd); cmd = QString("ps -e --no-headers -o command"); if (debug) qDebug() << "[DE]" << "[getPsStats]" << ":" << "Run cmd" << cmd; - command.start(cmd); - command.waitForFinished(-1); - if (debug) qDebug() << "[DE]" << "[getPsStats]" << ":" << "Cmd returns" << command.exitCode(); - qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed(); - int psTotal = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); - psStats.append(QString::number(psTotal)); - if (debug) qDebug() << "[DE]" << "[getPsStats]" << ":" << "Return" << psStats; - return psStats; + processes[QString("ps")][1]->start(cmd); } -int ExtendedSysMon::getUpgradeInfo(const QString pkgCommand, const int pkgNull) +void ExtendedSysMon::setPs() +{ + if (debug) qDebug() << "[DE]" << "[setPs]"; + QString qoutput = QString(""); + for (int i=0; itoUnicode(processes[QString("ps")][i]->readAllStandardOutput()).trimmed(); + if (!qoutput.isEmpty()) { + if (debug) qDebug() << "[DE]" << "[setPs]" << ":" << "Found data for cmd" << i; + if (i == 0) { + // pscount && ps + QStringList psList; + for (int i=0; itoUnicode(command.readAllStandardOutput()).trimmed(); - count = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); - if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Return" << (count - pkgNull); - return (count - pkgNull); + processes[QString("pkg")][number]->start(cmd); +} + + +void ExtendedSysMon::setUpgradeInfo() +{ + if (debug) qDebug() << "[DE]" << "[setUpgradeInfo]"; + int pkgNull = 0; + int value = 0; + QString qoutput = QString(""); + for (int i=0; itoUnicode(processes[QString("pkg")][i]->readAllStandardOutput()).trimmed(); + if (!qoutput.isEmpty()) { + if (debug) qDebug() << "[DE]" << "[setUpgradeInfo]" << ":" << "Found data for cmd" << i; + pkgNull = configuration[QString("PKGNULL")].split(QString(","), QString::SkipEmptyParts)[i].toInt(); + value = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); + if (debug) qDebug() << "[DE]" << "[setUpgradeInfo]" << ":" << "Return" << value; + QString source = QString("pkg"); + QString key = QString("pkgCount") + QString::number(i); + setData(source, key, value - pkgNull); + } + } } @@ -578,55 +676,29 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) } } else if (source == QString("gpu")) { - key = QString("GPU"); - float value = getGpu(configuration[QString("GPUDEV")]); - setData(source, key, value); + getGpu(configuration[QString("GPUDEV")]); } else if (source == QString("gputemp")) { - key = QString("GPUTemp"); - float value = getGpuTemp(configuration[QString("GPUDEV")]); - setData(source, key, value); + getGpuTemp(configuration[QString("GPUDEV")]); } else if (source == QString("hddtemp")) { QStringList deviceList = configuration[QString("HDDDEV")].split(QChar(','), QString::SkipEmptyParts); for (int i=0; i customProcesses; + QMap > processes; // configuration QMap configuration; bool debug; @@ -58,7 +66,7 @@ private: QString getAllHdd(); QString getAutoGpu(); void readConfiguration(); - void setCustomProcesses(); + void setProcesses(); QMap updateConfiguration(const QMap rawConfig); };