HttpRequest: passing references in signals (#20782)

old-commit-hash: ad57cd3759
commatwo_master
Dean Lee 4 years ago committed by GitHub
parent 3f4ee3fd1d
commit ee9280d9d3
  1. 4
      selfdrive/ui/qt/api.cc
  2. 10
      selfdrive/ui/qt/api.hpp
  3. 2
      selfdrive/ui/qt/request_repeater.cc
  4. 2
      selfdrive/ui/qt/request_repeater.hpp
  5. 7
      selfdrive/ui/qt/widgets/drive_stats.cc
  6. 2
      selfdrive/ui/qt/widgets/drive_stats.hpp
  7. 12
      selfdrive/ui/qt/widgets/setup.cc
  8. 6
      selfdrive/ui/qt/widgets/setup.hpp

@ -72,7 +72,7 @@ QString CommaApi::create_jwt(QVector<QPair<QString, QJsonValue>> payloads, int e
}
HttpRequest::HttpRequest(QObject *parent, QString requestURL, const QString &cache_key, bool create_jwt_) : cache_key(cache_key), create_jwt(create_jwt_), QObject(parent) {
HttpRequest::HttpRequest(QObject *parent, const QString &requestURL, const QString &cache_key, bool create_jwt_) : cache_key(cache_key), create_jwt(create_jwt_), QObject(parent) {
networkAccessManager = new QNetworkAccessManager(this);
reply = NULL;
@ -90,7 +90,7 @@ HttpRequest::HttpRequest(QObject *parent, QString requestURL, const QString &cac
}
}
void HttpRequest::sendRequest(QString requestURL){
void HttpRequest::sendRequest(const QString &requestURL){
QString token;
if(create_jwt) {
token = CommaApi::create_jwt();

@ -33,9 +33,9 @@ class HttpRequest : public QObject {
Q_OBJECT
public:
explicit HttpRequest(QObject* parent, QString requestURL, const QString &cache_key = "", bool create_jwt_ = true);
explicit HttpRequest(QObject* parent, const QString &requestURL, const QString &cache_key = "", bool create_jwt_ = true);
QNetworkReply *reply;
void sendRequest(QString requestURL);
void sendRequest(const QString &requestURL);
private:
QNetworkAccessManager *networkAccessManager;
@ -48,7 +48,7 @@ private slots:
void requestFinished();
signals:
void receivedResponse(QString response);
void failedResponse(QString errorString);
void timeoutResponse(QString errorString);
void receivedResponse(const QString &response);
void failedResponse(const QString &errorString);
void timeoutResponse(const QString &errorString);
};

@ -1,6 +1,6 @@
#include "request_repeater.hpp"
RequestRepeater::RequestRepeater(QObject *parent, QString requestURL, const QString &cacheKey,
RequestRepeater::RequestRepeater(QObject *parent, const QString &requestURL, const QString &cacheKey,
int period) : HttpRequest(parent, requestURL, cacheKey) {
timer = new QTimer(this);
timer->setTimerType(Qt::VeryCoarseTimer);

@ -3,7 +3,7 @@
class RequestRepeater : public HttpRequest {
public:
RequestRepeater(QObject *parent, QString requestURL, const QString &cacheKey = "", int period = 0);
RequestRepeater(QObject *parent, const QString &requestURL, const QString &cacheKey = "", int period = 0);
private:
QTimer *timer;

@ -22,9 +22,8 @@ static QLayout* build_stat_layout(QLabel** metric, const QString& name) {
return layout;
}
void DriveStats::parseResponse(QString response) {
response = response.trimmed();
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
void DriveStats::parseResponse(const QString& response) {
QJsonDocument doc = QJsonDocument::fromJson(response.trimmed().toUtf8());
if (doc.isNull()) {
qDebug() << "JSON Parse failed on getting past drives statistics";
return;
@ -66,5 +65,5 @@ DriveStats::DriveStats(QWidget* parent) : QWidget(parent) {
QString dongleId = QString::fromStdString(Params().get("DongleId"));
QString url = "https://api.commadotai.com/v1.1/devices/" + dongleId + "/stats";
RequestRepeater *repeater = new RequestRepeater(this, url, "ApiCache_DriveStats", 13);
QObject::connect(repeater, SIGNAL(receivedResponse(QString)), this, SLOT(parseResponse(QString)));
QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &DriveStats::parseResponse);
}

@ -14,5 +14,5 @@ private:
} all_, week_;
private slots:
void parseResponse(QString response);
void parseResponse(const QString &response);
};

@ -105,10 +105,10 @@ PrimeUserWidget::PrimeUserWidget(QWidget* parent) : QWidget(parent) {
QString url = "https://api.commadotai.com/v1/devices/" + dongleId + "/owner";
RequestRepeater *repeater = new RequestRepeater(this, url, "ApiCache_Owner", 6);
QObject::connect(repeater, SIGNAL(receivedResponse(QString)), this, SLOT(replyFinished(QString)));
QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &PrimeUserWidget::replyFinished);
}
void PrimeUserWidget::replyFinished(QString response) {
void PrimeUserWidget::replyFinished(const QString &response) {
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
if (doc.isNull()) {
qDebug() << "JSON Parse failed on getting username and points";
@ -238,12 +238,12 @@ SetupWidget::SetupWidget(QWidget* parent) : QFrame(parent) {
QString url = "https://api.commadotai.com/v1.1/devices/" + dongleId + "/";
RequestRepeater* repeater = new RequestRepeater(this, url, "ApiCache_Device", 5);
QObject::connect(repeater, SIGNAL(receivedResponse(QString)), this, SLOT(replyFinished(QString)));
QObject::connect(repeater, SIGNAL(failedResponse(QString)), this, SLOT(parseError(QString)));
QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &SetupWidget::replyFinished);
QObject::connect(repeater, &RequestRepeater::failedResponse, this, &SetupWidget::parseError);
hide(); // Only show when first request comes back
}
void SetupWidget::parseError(QString response) {
void SetupWidget::parseError(const QString &response) {
show();
showQr = false;
mainLayout->setCurrentIndex(0);
@ -254,7 +254,7 @@ void SetupWidget::showQrCode(){
mainLayout->setCurrentIndex(1);
}
void SetupWidget::replyFinished(QString response) {
void SetupWidget::replyFinished(const QString &response) {
show();
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
if (doc.isNull()) {

@ -33,7 +33,7 @@ private:
CommaApi* api;
private slots:
void replyFinished(QString response);
void replyFinished(const QString &response);
};
class PrimeAdWidget : public QWidget {
@ -56,7 +56,7 @@ private:
bool showQr = false;
private slots:
void parseError(QString response);
void replyFinished(QString response);
void parseError(const QString &response);
void replyFinished(const QString &response);
void showQrCode();
};

Loading…
Cancel
Save