Move the update job in a new file named discoveryphase

"Discovery" is a better name than "update"
This commit is contained in:
Olivier Goffart 2014-08-11 17:47:16 +02:00
parent aa85e875bd
commit 1f1eb933d1
5 changed files with 76 additions and 34 deletions

View File

@ -87,6 +87,7 @@ set(libsync_SRCS
mirall/clientproxy.cpp
mirall/cookiejar.cpp
mirall/syncfilestatus.cpp
mirall/discoveryphase.cpp
creds/dummycredentials.cpp
creds/abstractcredentials.cpp
creds/credentialsfactory.cpp

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) by Olivier Goffart <ogoffart@woboq.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "discoveryphase.h"
void DiscoveryJob::start() {
csync_set_log_callback(_log_callback);
csync_set_log_level(_log_level);
csync_set_log_userdata(_log_userdata);
emit finished(csync_update(_csync_ctx));
deleteLater();
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) by Olivier Goffart <ogoffart@woboq.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#pragma once
#include <QObject>
#include <csync.h>
/**
* The Discovery Phase was once called "update" phase in csync therms.
* Its goal is to look at the files in one of the remote and check comared to the db
* if the files are new, or changed.
*/
class DiscoveryJob : public QObject {
Q_OBJECT
CSYNC *_csync_ctx;
csync_log_callback _log_callback;
int _log_level;
void* _log_userdata;
Q_INVOKABLE void start();
public:
explicit DiscoveryJob(CSYNC *ctx, QObject* parent = 0)
: QObject(parent), _csync_ctx(ctx) {
// We need to forward the log property as csync uses thread local
// and updates run in another thread
_log_callback = csync_get_log_callback();
_log_level = csync_get_log_level();
_log_userdata = csync_get_log_userdata();
}
signals:
void finished(int result);
};

View File

@ -19,6 +19,7 @@
#include "owncloudpropagator.h"
#include "syncjournaldb.h"
#include "syncjournalfilerecord.h"
#include "discoveryphase.h"
#include "creds/abstractcredentials.h"
#include "csync_util.h"
@ -529,21 +530,21 @@ void SyncEngine::startSync()
_stopWatch.start();
qDebug() << "#### Update start #################################################### >>";
qDebug() << "#### Discovery start #################################################### >>";
UpdateJob *job = new UpdateJob(_csync_ctx);
DiscoveryJob *job = new DiscoveryJob(_csync_ctx);
job->moveToThread(&_thread);
connect(job, SIGNAL(finished(int)), this, SLOT(slotUpdateFinished(int)));
connect(job, SIGNAL(finished(int)), this, SLOT(slotDiscoveryJobFinished(int)));
QMetaObject::invokeMethod(job, "start", Qt::QueuedConnection);
}
void SyncEngine::slotUpdateFinished(int updateResult)
void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
{
if (updateResult < 0 ) {
if (discoveryResult < 0 ) {
handleSyncError(_csync_ctx, "csync_update");
return;
}
qDebug() << "<<#### Update end #################################################### " << _stopWatch.addLapTime(QLatin1String("Update Finished"));
qDebug() << "<<#### Discovery end #################################################### " << _stopWatch.addLapTime(QLatin1String("Discovery Finished"));
if( csync_reconcile(_csync_ctx) < 0 ) {
handleSyncError(_csync_ctx, "csync_reconcile");

View File

@ -88,7 +88,7 @@ private slots:
void slotFinished();
void slotProgress(const SyncFileItem& item, quint64 curent);
void slotAdjustTotalTransmissionSize(qint64 change);
void slotUpdateFinished(int updateResult);
void slotDiscoveryJobFinished(int updateResult);
private:
void handleSyncError(CSYNC *ctx, const char *state);
@ -142,33 +142,6 @@ private:
};
class UpdateJob : public QObject {
Q_OBJECT
CSYNC *_csync_ctx;
csync_log_callback _log_callback;
int _log_level;
void* _log_userdata;
Q_INVOKABLE void start() {
csync_set_log_callback(_log_callback);
csync_set_log_level(_log_level);
csync_set_log_userdata(_log_userdata);
emit finished(csync_update(_csync_ctx));
deleteLater();
}
public:
explicit UpdateJob(CSYNC *ctx, QObject* parent = 0)
: QObject(parent), _csync_ctx(ctx) {
// We need to forward the log property as csync uses thread local
// and updates run in another thread
_log_callback = csync_get_log_callback();
_log_level = csync_get_log_level();
_log_userdata = csync_get_log_userdata();
}
signals:
void finished(int result);
};
}
#endif // CSYNCTHREAD_H