aboutsummaryrefslogtreecommitdiff
path: root/jobs/basejob.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-10-02 12:16:36 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-10-02 12:20:33 +0900
commitb2c9daabc2e8b89e1108211d8c9badf1bac66640 (patch)
treef2a7ba70eacc8c69e2741ae1af47eeb5887bb396 /jobs/basejob.cpp
parentb469f1c9ab7603a297b1c0082d804312cabbd550 (diff)
downloadlibquotient-b2c9daabc2e8b89e1108211d8c9badf1bac66640.tar.gz
libquotient-b2c9daabc2e8b89e1108211d8c9badf1bac66640.zip
All jobs: Drop ConnectionData parameter from the constructor
Having to pass ConnectionData to each and every job class was nothing but boilerplate since the very beginning. Removing it required to prepend BaseJob::start() with ConnectionData-setting code, and to provide a way to alter the request configuration depending on the (late-coming) ConnectionData object. This is a new responsibility of BaseJob::start(); the previous BaseJob::start() contents have moved to BaseJob::sendRequest() (which is now invoked on retries, instead of start()).
Diffstat (limited to 'jobs/basejob.cpp')
-rw-r--r--jobs/basejob.cpp38
1 files changed, 26 insertions, 12 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index ea1a7158..240192d9 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -24,7 +24,7 @@
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QtCore/QTimer>
-#include <QtCore/QStringBuilder>
+//#include <QtCore/QStringBuilder>
#include <array>
@@ -45,16 +45,15 @@ class BaseJob::Private
public:
// Using an idiom from clang-tidy:
// http://clang.llvm.org/extra/clang-tidy/checks/modernize-pass-by-value.html
- Private(const ConnectionData* c, HttpVerb v,
- QString endpoint, QUrlQuery q, Data data, bool nt)
- : connection(c), verb(v), apiEndpoint(std::move(endpoint))
+ Private(HttpVerb v, QString endpoint, QUrlQuery q, Data data, bool nt)
+ : verb(v), apiEndpoint(std::move(endpoint))
, requestQuery(std::move(q)), requestData(std::move(data))
, needsToken(nt)
{ }
void sendRequest();
- const ConnectionData* connection;
+ const ConnectionData* connection = nullptr;
// Contents for the network request
HttpVerb verb;
@@ -80,16 +79,15 @@ inline QDebug operator<<(QDebug dbg, const BaseJob* j)
return dbg << j->objectName();
}
-BaseJob::BaseJob(const ConnectionData* connection, HttpVerb verb,
- const QString& name, const QString& endpoint,
+BaseJob::BaseJob(HttpVerb verb, const QString& name, const QString& endpoint,
const Query& query, const Data& data, bool needsToken)
- : d(new Private(connection, verb, endpoint, query, data, needsToken))
+ : d(new Private(verb, endpoint, query, data, needsToken))
{
setObjectName(name);
d->timer.setSingleShot(true);
connect (&d->timer, &QTimer::timeout, this, &BaseJob::timeout);
d->retryTimer.setSingleShot(true);
- connect (&d->retryTimer, &QTimer::timeout, this, &BaseJob::start);
+ connect (&d->retryTimer, &QTimer::timeout, this, &BaseJob::sendRequest);
}
BaseJob::~BaseJob()
@@ -98,9 +96,14 @@ BaseJob::~BaseJob()
qCDebug(d->logCat) << this << "destroyed";
}
-const ConnectionData* BaseJob::connection() const
+const QString& BaseJob::apiEndpoint() const
{
- return d->connection;
+ return d->apiEndpoint;
+}
+
+void BaseJob::setApiEndpoint(const QString& apiEndpoint)
+{
+ d->apiEndpoint = apiEndpoint;
}
const QUrlQuery& BaseJob::query() const
@@ -155,7 +158,18 @@ void BaseJob::Private::sendRequest()
}
}
-void BaseJob::start()
+void BaseJob::beforeStart(const ConnectionData* connData)
+{
+}
+
+void BaseJob::start(const ConnectionData* connData)
+{
+ d->connection = connData;
+ beforeStart(connData);
+ sendRequest();
+}
+
+void BaseJob::sendRequest()
{
emit aboutToStart();
d->retryTimer.stop(); // In case we were counting down at the moment