From 1f1eb933d19f3bc09ee65ae75aaa3c50a578b3ea Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 11 Aug 2014 17:47:16 +0200 Subject: [PATCH] Move the update job in a new file named discoveryphase "Discovery" is a better name than "update" --- src/CMakeLists.txt | 1 + src/mirall/discoveryphase.cpp | 23 ++++++++++++++++++ src/mirall/discoveryphase.h | 44 +++++++++++++++++++++++++++++++++++ src/mirall/syncengine.cpp | 13 ++++++----- src/mirall/syncengine.h | 29 +---------------------- 5 files changed, 76 insertions(+), 34 deletions(-) create mode 100644 src/mirall/discoveryphase.cpp create mode 100644 src/mirall/discoveryphase.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d4e66bcf4..9acb275007 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/mirall/discoveryphase.cpp b/src/mirall/discoveryphase.cpp new file mode 100644 index 0000000000..b1e3d16286 --- /dev/null +++ b/src/mirall/discoveryphase.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) by Olivier Goffart + * + * 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(); +} diff --git a/src/mirall/discoveryphase.h b/src/mirall/discoveryphase.h new file mode 100644 index 0000000000..949794c106 --- /dev/null +++ b/src/mirall/discoveryphase.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) by Olivier Goffart + * + * 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 +#include + +/** + * 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); +}; diff --git a/src/mirall/syncengine.cpp b/src/mirall/syncengine.cpp index 90fa76a0d8..cfff3dedfc 100644 --- a/src/mirall/syncengine.cpp +++ b/src/mirall/syncengine.cpp @@ -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"); diff --git a/src/mirall/syncengine.h b/src/mirall/syncengine.h index 5e44d46b62..ac3df814a3 100644 --- a/src/mirall/syncengine.h +++ b/src/mirall/syncengine.h @@ -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