-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcondworker.cpp
More file actions
58 lines (50 loc) · 1.59 KB
/
condworker.cpp
File metadata and controls
58 lines (50 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "condworker.h"
#include "condinterface.h"
#include <QDebug>
#include <QApplication>
CondWorker::CondWorker(CondInterface* interface, QObject* parent)
: QObject(parent), condInterface(interface) {
connect(condInterface, &CondInterface::measurementReceived,
this, &CondWorker::onResponseReceived);
}
void CondWorker::initialize() {
timeoutTimer = new QTimer(this);
timeoutTimer->setSingleShot(true);
timeoutTimer->setInterval(3000);
connect(timeoutTimer, &QTimer::timeout, this, [this]() {
qWarning() << "Command timed out!";
processing = false;
processNext();
});
}
void CondWorker::enqueueCommand(const QString &command) {
//qDebug() << "enqueueCommand running in thread:" << QThread::currentThread() << command;
//qDebug() << "condWorker lives in thread:" << this->thread();
commandQueue.enqueue(command);
if (commandQueue.length() > 1)
{
qWarning() << "CondWorker commands accumulating! Queue total: " << commandQueue.length();
}
if (!processing) {
processNext();
}
}
void CondWorker::processNext() {
//qDebug() << "Processing next!";
if (commandQueue.isEmpty()) {
//qDebug() << "nothing to process";
processing = false;
return;
}
QString cmd = commandQueue.dequeue();
//qDebug()<<"CondWorker returning command"<<cmd;
emit condCommandReady(cmd);
processing = true;
timeoutTimer->start();
}
void CondWorker::onResponseReceived(CondReading response) {
Q_UNUSED(response)
timeoutTimer->stop();
processing = false;
processNext();
}