summaryrefslogtreecommitdiff
path: root/daemon/uploadmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/uploadmanager.cpp')
-rw-r--r--daemon/uploadmanager.cpp49
1 files changed, 25 insertions, 24 deletions
diff --git a/daemon/uploadmanager.cpp b/daemon/uploadmanager.cpp
index 5976fe6..b379880 100644
--- a/daemon/uploadmanager.cpp
+++ b/daemon/uploadmanager.cpp
@@ -7,12 +7,13 @@ static const int CHUNK_SIZE = 2000;
using std::function;
UploadManager::UploadManager(WatchConnector *watch, QObject *parent) :
- QObject(parent), watch(watch), _lastUploadId(0), _state(StateNotStarted)
+ QObject(parent), l(metaObject()->className()), watch(watch),
+ _lastUploadId(0), _state(StateNotStarted)
{
watch->setEndpointHandler(WatchConnector::watchPUTBYTES,
[this](const QByteArray &msg) {
if (_pending.empty()) {
- logger()->warn() << "putbytes message, but queue is empty!";
+ qCWarning(l) << "putbytes message, but queue is empty!";
return false;
}
handleMessage(msg);
@@ -40,7 +41,7 @@ uint UploadManager::upload(WatchConnector::UploadType type, int index, const QSt
upload.progressCallback = progressCallback;
if (upload.remaining <= 0) {
- logger()->warn() << "upload is empty";
+ qCWarning(l) << "upload is empty";
if (errorCallback) {
errorCallback(-1);
return -1;
@@ -75,13 +76,13 @@ uint UploadManager::uploadFile(const QString &filename, QIODevice *device, Succe
void UploadManager::cancel(uint id, int code)
{
if (_pending.empty()) {
- logger()->warn() << "cannot cancel, empty queue";
+ qCWarning(l) << "cannot cancel, empty queue";
return;
}
if (id == _pending.head().id) {
PendingUpload upload = _pending.dequeue();
- logger()->debug() << "aborting current upload" << id << "(code:" << code << ")";
+ qCDebug(l) << "aborting current upload" << id << "(code:" << code << ")";
if (_state != StateNotStarted && _state != StateWaitForToken && _state != StateComplete) {
QByteArray msg;
@@ -89,7 +90,7 @@ void UploadManager::cancel(uint id, int code)
p.write<quint8>(WatchConnector::putbytesABORT);
p.write<quint32>(_token);
- logger()->debug() << "sending abort for upload" << id;
+ qCDebug(l) << "sending abort for upload" << id;
watch->sendMessage(WatchConnector::watchPUTBYTES, msg);
}
@@ -107,7 +108,7 @@ void UploadManager::cancel(uint id, int code)
} else {
for (int i = 1; i < _pending.size(); ++i) {
if (_pending[i].id == id) {
- logger()->debug() << "cancelling upload" << id << "(code:" << code << ")";
+ qCDebug(l) << "cancelling upload" << id << "(code:" << code << ")";
if (_pending[i].errorCallback) {
_pending[i].errorCallback(code);
}
@@ -115,7 +116,7 @@ void UploadManager::cancel(uint id, int code)
return;
}
}
- logger()->warn() << "cannot cancel, id" << id << "not found";
+ qCWarning(l) << "cannot cancel, id" << id << "not found";
}
}
@@ -135,7 +136,7 @@ void UploadManager::startNextUpload()
p.writeCString(upload.filename);
}
- logger()->debug() << "starting new upload, size:" << upload.remaining << ", type:" << upload.type << ", slot:" << upload.index;
+ qCDebug(l) << "starting new upload, size:" << upload.remaining << ", type:" << upload.type << ", slot:" << upload.index;
_state = StateWaitForToken;
watch->sendMessage(WatchConnector::watchPUTBYTES, msg);
@@ -150,7 +151,7 @@ void UploadManager::handleMessage(const QByteArray &msg)
int status = u.read<quint8>();
if (u.bad() || status != 1) {
- logger()->warn() << "upload" << upload.id << "got error code=" << status;
+ qCWarning(l) << "upload" << upload.id << "got error code=" << status;
cancel(upload.id, status);
return;
}
@@ -158,14 +159,14 @@ void UploadManager::handleMessage(const QByteArray &msg)
quint32 recv_token = u.read<quint32>();
if (u.bad()) {
- logger()->warn() << "upload" << upload.id << ": could not read the token";
+ qCWarning(l) << "upload" << upload.id << ": could not read the token";
cancel(upload.id, -1);
return;
}
if (_state != StateNotStarted && _state != StateWaitForToken && _state != StateComplete) {
if (recv_token != _token) {
- logger()->warn() << "upload" << upload.id << ": invalid token";
+ qCWarning(l) << "upload" << upload.id << ": invalid token";
cancel(upload.id, -1);
return;
}
@@ -173,16 +174,16 @@ void UploadManager::handleMessage(const QByteArray &msg)
switch (_state) {
case StateNotStarted:
- logger()->warn() << "got packet when upload is not started";
+ qCWarning(l) << "got packet when upload is not started";
break;
case StateWaitForToken:
- logger()->debug() << "token received";
+ qCDebug(l) << "token received";
_token = recv_token;
_state = StateInProgress;
/* fallthrough */
case StateInProgress:
- logger()->debug() << "moving to the next chunk";
+ qCDebug(l) << "moving to the next chunk";
if (upload.progressCallback) {
// Report that the previous chunk has been succesfully uploaded
upload.progressCallback(1.0 - (qreal(upload.remaining) / upload.size));
@@ -193,7 +194,7 @@ void UploadManager::handleMessage(const QByteArray &msg)
return;
}
} else {
- logger()->debug() << "no additional chunks, commit";
+ qCDebug(l) << "no additional chunks, commit";
_state = StateCommit;
if (!commit(upload)) {
cancel(upload.id, -1);
@@ -202,7 +203,7 @@ void UploadManager::handleMessage(const QByteArray &msg)
}
break;
case StateCommit:
- logger()->debug() << "commited succesfully";
+ qCDebug(l) << "commited succesfully";
if (upload.progressCallback) {
// Report that all chunks have been succesfully uploaded
upload.progressCallback(1.0);
@@ -214,7 +215,7 @@ void UploadManager::handleMessage(const QByteArray &msg)
}
break;
case StateComplete:
- logger()->debug() << "upload" << upload.id << "succesful, invoking callback";
+ qCDebug(l) << "upload" << upload.id << "succesful, invoking callback";
if (upload.successCallback) {
upload.successCallback();
}
@@ -226,7 +227,7 @@ void UploadManager::handleMessage(const QByteArray &msg)
}
break;
default:
- logger()->warn() << "received message in wrong state";
+ qCWarning(l) << "received message in wrong state";
break;
}
}
@@ -237,7 +238,7 @@ bool UploadManager::uploadNextChunk(PendingUpload &upload)
if (upload.remaining < CHUNK_SIZE && chunk.size() < upload.remaining) {
// Short read!
- logger()->warn() << "short read during upload" << upload.id;
+ qCWarning(l) << "short read during upload" << upload.id;
return false;
}
@@ -251,14 +252,14 @@ bool UploadManager::uploadNextChunk(PendingUpload &upload)
p.write<quint32>(chunk.size());
msg.append(chunk);
- logger()->debug() << "sending a chunk of" << chunk.size() << "bytes";
+ qCDebug(l) << "sending a chunk of" << chunk.size() << "bytes";
watch->sendMessage(WatchConnector::watchPUTBYTES, msg);
upload.remaining -= chunk.size();
upload.crc.addData(chunk);
- logger()->debug() << "remaining" << upload.remaining << "/" << upload.size << "bytes";
+ qCDebug(l) << "remaining" << upload.remaining << "/" << upload.size << "bytes";
return true;
}
@@ -274,7 +275,7 @@ bool UploadManager::commit(PendingUpload &upload)
p.write<quint32>(_token);
p.write<quint32>(upload.crc.result());
- logger()->debug() << "commiting upload" << upload.id
+ qCDebug(l) << "commiting upload" << upload.id
<< "with crc" << qPrintable(QString("0x%1").arg(upload.crc.result(), 0, 16));
watch->sendMessage(WatchConnector::watchPUTBYTES, msg);
@@ -291,7 +292,7 @@ bool UploadManager::complete(PendingUpload &upload)
p.write<quint8>(WatchConnector::putbytesCOMPLETE);
p.write<quint32>(_token);
- logger()->debug() << "completing upload" << upload.id;
+ qCDebug(l) << "completing upload" << upload.id;
watch->sendMessage(WatchConnector::watchPUTBYTES, msg);