diff options
author | Simon Rettberg | 2022-06-22 16:44:30 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-06-22 16:44:30 +0200 |
commit | 880fbb84acf853be8ac0c5a23ff0475e8ce6dff0 (patch) | |
tree | 5869e19b02f5698ed7c47cf9a8240fc46e37bc71 /src/consoleworker.cpp | |
parent | Set maximum to ~120MB/s, about matches theoretical maximum of GBit NIC (diff) | |
download | speedcheck-880fbb84acf853be8ac0c5a23ff0475e8ce6dff0.tar.gz speedcheck-880fbb84acf853be8ac0c5a23ff0475e8ce6dff0.tar.xz speedcheck-880fbb84acf853be8ac0c5a23ff0475e8ce6dff0.zip |
Add --console mode, to be used remotely
Diffstat (limited to 'src/consoleworker.cpp')
-rw-r--r-- | src/consoleworker.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/consoleworker.cpp b/src/consoleworker.cpp new file mode 100644 index 0000000..a869725 --- /dev/null +++ b/src/consoleworker.cpp @@ -0,0 +1,66 @@ +#include "consoleworker.h" +#include "copythread.h" +#include "datasource/cpuload.h" +#include "datasource/networkspeed.h" + +#include <QFile> +#include <QCoreApplication> +#include <cstdio> + +ConsoleWorker::ConsoleWorker(QString fileName) : + _thread(nullptr), + _fileName(fileName), + _networkSource(nullptr) +{ + _timer.setInterval(200); + connect(&_timer, &QTimer::timeout, this, &ConsoleWorker::updateTimer); + QTimer::singleShot(1, [this]() { + QFile *file = new QFile(_fileName); + if (!file->open(QIODevice::ReadOnly)) { + puts(tr("Could not open %1 for reading.").arg(_fileName).toLocal8Bit().constData()); + return; + } + _networkSource = new NetworkSpeed(); + _thread = new CopyThread(file, this); + connect(_thread, &CopyThread::logMessage, this, &ConsoleWorker::logMessage, Qt::QueuedConnection); + connect(_thread, &CopyThread::finished, this, &ConsoleWorker::testFinished, Qt::QueuedConnection); + _timer.start(); + _thread->start(); + }); +} + +ConsoleWorker::~ConsoleWorker() +{ + delete _networkSource; +} + +void ConsoleWorker::logMessage(CopyThread::LogMessageId msgId, QString message) +{ + if (msgId == CopyThread::TestRandomStart) { + printf("+SEQ"); + } else if (msgId == CopyThread::TestFinished) { + printf("+RND"); + } + if (msgId == CopyThread::TestRandomStart || msgId == CopyThread::TestFinished) { + for (int i : _series) { + printf(",%i", i); + } + putchar('\n'); + } + _series.clear(); + puts(message.toLocal8Bit().constData()); +} + +void ConsoleWorker::testFinished() +{ + _timer.stop(); + delete _thread; + _thread = NULL; + QCoreApplication::instance()->quit(); +} + +void ConsoleWorker::updateTimer() +{ + int i = (int)_networkSource->read(); + _series.append(i); +} |