From b2c9daabc2e8b89e1108211d8c9badf1bac66640 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 2 Oct 2017 12:16:36 +0900 Subject: 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()). --- jobs/basejob.cpp | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'jobs/basejob.cpp') 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 #include #include -#include +//#include #include @@ -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 -- cgit v1.2.3