aboutsummaryrefslogtreecommitdiff
path: root/jobs/basejob.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'jobs/basejob.cpp')
-rw-r--r--jobs/basejob.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index f5de75f4..77f90596 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -17,16 +17,15 @@
*/
#include "basejob.h"
-#include "util.h"
-#include <array>
+#include "connectiondata.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QtCore/QTimer>
-#include "../connectiondata.h"
+#include <array>
using namespace QMatrixClient;
@@ -49,10 +48,10 @@ class BaseJob::Private
QString endpoint, QUrlQuery q, Data data, bool nt)
: connection(c), verb(v), apiEndpoint(std::move(endpoint))
, requestQuery(std::move(q)), requestData(std::move(data))
- , needsToken(nt), reply(nullptr), status(NoError)
+ , needsToken(nt)
{ }
- inline void sendRequest();
+ void sendRequest();
const ConnectionData* connection;
@@ -64,13 +63,15 @@ class BaseJob::Private
bool needsToken;
QScopedPointer<QNetworkReply, NetworkReplyDeleter> reply;
- Status status;
+ Status status = NoError;
QTimer timer;
QTimer retryTimer;
size_t maxRetries = 3;
size_t retriesTaken = 0;
+
+ LoggingCategory logCat = JOBS;
};
inline QDebug operator<<(QDebug dbg, const BaseJob* j)
@@ -88,13 +89,13 @@ BaseJob::BaseJob(const ConnectionData* connection, HttpVerb verb,
connect (&d->timer, &QTimer::timeout, this, &BaseJob::timeout);
d->retryTimer.setSingleShot(true);
connect (&d->retryTimer, &QTimer::timeout, this, &BaseJob::start);
- qCDebug(JOBS) << this << "created";
+ qCDebug(d->logCat) << this << "created";
}
BaseJob::~BaseJob()
{
stop();
- qCDebug(JOBS) << this << "destroyed";
+ qCDebug(d->logCat) << this << "destroyed";
}
const ConnectionData* BaseJob::connection() const
@@ -176,7 +177,7 @@ void BaseJob::gotReply()
BaseJob::Status BaseJob::checkReply(QNetworkReply* reply) const
{
if (reply->error() != QNetworkReply::NoError)
- qCDebug(JOBS) << this << "returned" << reply->error();
+ qCDebug(d->logCat) << this << "returned" << reply->error();
switch( reply->error() )
{
case QNetworkReply::NoError:
@@ -219,11 +220,11 @@ void BaseJob::stop()
d->timer.stop();
if (!d->reply)
{
- qCWarning(JOBS) << this << "stopped with empty network reply";
+ qCWarning(d->logCat) << this << "stopped with empty network reply";
}
else if (d->reply->isRunning())
{
- qCWarning(JOBS) << this << "stopped without ready network reply";
+ qCWarning(d->logCat) << this << "stopped without ready network reply";
d->reply->disconnect(this); // Ignore whatever comes from the reply
d->reply->abort();
}
@@ -237,7 +238,7 @@ void BaseJob::finishJob()
{
const auto retryInterval = getNextRetryInterval();
++d->retriesTaken;
- qCWarning(JOBS) << this << "will take retry" << d->retriesTaken
+ qCWarning(d->logCat) << this << "will take retry" << d->retriesTaken
<< "in" << retryInterval/1000 << "s";
d->retryTimer.start(retryInterval);
emit retryScheduled(d->retriesTaken, retryInterval);
@@ -303,7 +304,8 @@ void BaseJob::setStatus(Status s)
d->status = s;
if (!s.good())
{
- qCWarning(JOBS) << this << "status" << s.code << ":" << s.message;
+ qCWarning(d->logCat) << this << "status" << s.code
+ << ":" << s.message;
}
}
@@ -326,7 +328,13 @@ void BaseJob::timeout()
void BaseJob::sslErrors(const QList<QSslError>& errors)
{
foreach (const QSslError &error, errors) {
- qCWarning(JOBS) << "SSL ERROR" << error.errorString();
+ qCWarning(d->logCat) << "SSL ERROR" << error.errorString();
}
d->reply->ignoreSslErrors(); // TODO: insecure! should prompt user first
}
+
+void BaseJob::setLoggingCategory(LoggingCategory lcf)
+{
+ d->logCat = lcf;
+}
+