You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
33 lines
1.1 KiB
#include "selfdrive/ui/qt/request_repeater.h"
|
|
|
|
RequestRepeater::RequestRepeater(QObject *parent, const QString &requestURL, const QString &cacheKey,
|
|
int period) : HttpRequest(parent, requestURL) {
|
|
timer = new QTimer(this);
|
|
timer->setTimerType(Qt::VeryCoarseTimer);
|
|
QObject::connect(timer, &QTimer::timeout, [=]() {
|
|
if (!QUIState::ui_state.scene.started && QUIState::ui_state.awake && reply == NULL) {
|
|
sendRequest(requestURL);
|
|
}
|
|
});
|
|
|
|
timer->start(period * 1000);
|
|
|
|
if (!cacheKey.isEmpty()) {
|
|
prevResp = QString::fromStdString(params.get(cacheKey.toStdString()));
|
|
if (!prevResp.isEmpty()) {
|
|
QTimer::singleShot(0, [=]() { emit receivedResponse(prevResp); });
|
|
}
|
|
QObject::connect(this, &HttpRequest::receivedResponse, [=](const QString &resp) {
|
|
if (resp != prevResp) {
|
|
params.put(cacheKey.toStdString(), resp.toStdString());
|
|
prevResp = resp;
|
|
}
|
|
});
|
|
QObject::connect(this, &HttpRequest::failedResponse, [=](const QString &err) {
|
|
if (!prevResp.isEmpty()) {
|
|
params.remove(cacheKey.toStdString());
|
|
prevResp = "";
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|