From 341127cb7250b26d44a8db584586d4011769f810 Mon Sep 17 00:00:00 2001 From: BRULE Herman Date: Thu, 26 Jan 2012 16:39:52 +0100 Subject: [PATCH] Thread improvement, user transfer log improvement, discovering one bug --- AuthPlugin.cpp | 1 + Core.cpp | 6 ++ EventDispatcher.h | 3 +- LogThread.cpp | 94 +++++++++++++++---- LogThread.h | 1 + OptionDialog.cpp | 14 +++ OptionDialog.h | 2 + OptionDialog.ui | 67 +++++++++---- PluginsManager.cpp | 3 +- ResourcesManager.h | 3 +- lib/qt-tar-xz/QXzDecodeThread.cpp | 1 + .../CopyEngine/Ultracopier-0.3/ListThread.cpp | 2 +- plugins/CopyEngine/Ultracopier-0.3/MkPath.cpp | 1 + .../CopyEngine/Ultracopier-0.3/ReadThread.cpp | 12 ++- plugins/CopyEngine/Ultracopier-0.3/RmPath.cpp | 1 + .../Ultracopier-0.3/TransferThread.cpp | 3 + .../Ultracopier-0.3/WriteThread.cpp | 8 +- .../Ultracopier-0.3/informations.xml | 2 +- plugins/CopyEngine/Ultracopier-0.3/options.ui | 2 +- 19 files changed, 176 insertions(+), 50 deletions(-) diff --git a/AuthPlugin.cpp b/AuthPlugin.cpp index 6a053471..b640ad7b 100644 --- a/AuthPlugin.cpp +++ b/AuthPlugin.cpp @@ -16,6 +16,7 @@ AuthPlugin::AuthPlugin(QObject * parent) : stopIt=false; //set sem to 1 sem.release(); + moveToThread(this); } AuthPlugin::~AuthPlugin() diff --git a/Core.cpp b/Core.cpp index a4dcaab9..1622fff9 100644 --- a/Core.cpp +++ b/Core.cpp @@ -20,6 +20,7 @@ Core::Core(CopyEngineManager *copyEngineList) connect(themes, SIGNAL(theThemeNeedBeUnloaded()), this, SLOT(unloadInterface())); connect(themes, SIGNAL(theThemeIsReloaded()), this, SLOT(loadInterface())); connect(&forUpateInformation, SIGNAL(timeout()), this, SLOT(periodiqueSync())); + //load the GUI option QString defaultLogFile=""; if(resources->getWritablePath()!="") @@ -30,6 +31,7 @@ Core::Core(CopyEngineManager *copyEngineList) KeysList.append(qMakePair(QString("transfer"),QVariant(true))); KeysList.append(qMakePair(QString("error"),QVariant(true))); KeysList.append(qMakePair(QString("folder"),QVariant(true))); + KeysList.append(qMakePair(QString("sync"),QVariant(false))); KeysList.append(qMakePair(QString("transfer_format"),QVariant("[%time%] %source% (%size%) %destination%"))); KeysList.append(qMakePair(QString("error_format"),QVariant("[%time%] %path%, %error%"))); KeysList.append(qMakePair(QString("folder_format"),QVariant("[%time%] %operation% %path%"))); @@ -37,7 +39,11 @@ Core::Core(CopyEngineManager *copyEngineList) newOptionValue("Write_log", "transfer", options->getOptionValue("Write_log","transfer")); newOptionValue("Write_log", "error", options->getOptionValue("Write_log","error")); newOptionValue("Write_log", "folder", options->getOptionValue("Write_log","folder")); + newOptionValue("Write_log", "sync", options->getOptionValue("Write_log","sync")); + log.openLogs(); + + connect(options,SIGNAL(newOptionValue(QString,QString,QVariant)), this, SLOT(newOptionValue(QString,QString,QVariant))); } void Core::newCopy(quint32 orderId,QStringList protocolsUsedForTheSources,QStringList sources) diff --git a/EventDispatcher.h b/EventDispatcher.h index ca11bc74..fe63b9cb 100644 --- a/EventDispatcher.h +++ b/EventDispatcher.h @@ -2,8 +2,7 @@ \brief Define the class of the event dispatcher \author alpha_one_x86 \version 0.3 -\date 2010 -\example EventDispatcher.cpp */ +\date 2010 */ #ifndef EVENT_DISPATCHER_H #define EVENT_DISPATCHER_H diff --git a/LogThread.cpp b/LogThread.cpp index cd9131d5..facd08fd 100644 --- a/LogThread.cpp +++ b/LogThread.cpp @@ -4,11 +4,40 @@ LogThread::LogThread() { + sync=false; + /** No here because code need direct access + + //load the GUI option + QString defaultLogFile=""; + if(resources->getWritablePath()!="") + defaultLogFile=resources->getWritablePath()+"ultracopier-files.log"; + QList > KeysList; + KeysList.append(qMakePair(QString("enabled"),QVariant(false))); + KeysList.append(qMakePair(QString("file"),QVariant(defaultLogFile))); + KeysList.append(qMakePair(QString("transfer"),QVariant(true))); + KeysList.append(qMakePair(QString("error"),QVariant(true))); + KeysList.append(qMakePair(QString("folder"),QVariant(true))); + KeysList.append(qMakePair(QString("transfer_format"),QVariant("[%time%] %source% (%size%) %destination%"))); + KeysList.append(qMakePair(QString("error_format"),QVariant("[%time%] %path%, %error%"))); + KeysList.append(qMakePair(QString("folder_format"),QVariant("[%time%] %operation% %path%"))); + options->addOptionGroup("Write_log",KeysList); + newOptionValue("Write_log", "transfer", options->getOptionValue("Write_log","transfer")); + newOptionValue("Write_log", "error", options->getOptionValue("Write_log","error")); + newOptionValue("Write_log", "folder", options->getOptionValue("Write_log","folder")); + newOptionValue("Write_log", "sync", options->getOptionValue("Write_log","sync")); + */ + + connect(options,SIGNAL(newOptionValue(QString,QString,QVariant)), this, SLOT(newOptionValue(QString,QString,QVariant))); + + moveToThread(this); + start(); } LogThread::~LogThread() { closeLogs(); + quit(); + wait(); } void LogThread::openLogs() @@ -16,18 +45,25 @@ void LogThread::openLogs() if(options->getOptionValue("Write_log","enabled").toBool()==false) return; log.setFileName(options->getOptionValue("Write_log","file").toString()); - if(!log.open(QIODevice::WriteOnly)) - QMessageBox::critical(NULL,tr("Error"),tr("Unable to open file to keep the log file, error: %1").arg(log.errorString())); + if(sync) + { + if(!log.open(QIODevice::WriteOnly|QIODevice::Unbuffered)) + QMessageBox::critical(NULL,tr("Error"),tr("Unable to open file to keep the log file, error: %1").arg(log.errorString())); + } + else + { + if(!log.open(QIODevice::WriteOnly)) + QMessageBox::critical(NULL,tr("Error"),tr("Unable to open file to keep the log file, error: %1").arg(log.errorString())); + } newOptionValue("Write_log", "transfer_format", options->getOptionValue("Write_log","transfer_format")); newOptionValue("Write_log", "error_format", options->getOptionValue("Write_log","error_format")); newOptionValue("Write_log", "folder_format", options->getOptionValue("Write_log","folder_format")); + newOptionValue("Write_log", "sync", options->getOptionValue("Write_log","sync")); start(QThread::IdlePriority); } void LogThread::closeLogs() { - quit(); - wait(0); if(log.isOpen() && data.size()>0) log.write(data.toUtf8()); log.close(); @@ -45,9 +81,8 @@ void LogThread::newTransferStart(ItemOfCopyList item) { QMutexLocker lock_mutex(&mutex); data+=text; - if(data.size()>4*1024*1024) - emit newData(); } + emit newData(); } void LogThread::newTransferStop(quint64 id) @@ -68,14 +103,13 @@ void LogThread::error(QString path,quint64 size,QDateTime mtime,QString error) { QMutexLocker lock_mutex(&mutex); data+=text; - if(data.size()>4*1024*1024) - emit newData(); } + emit newData(); } void LogThread::run() { - connect(this,SIGNAL(newData()),this,SLOT(realDataWrite())); + connect(this,SIGNAL(newData()),this,SLOT(realDataWrite()),Qt::QueuedConnection); exec(); } @@ -88,17 +122,45 @@ void LogThread::realDataWrite() currentData=data; data.clear(); } - log.write(currentData.toUtf8()); + if(log.write(currentData.toUtf8())==-1) + { + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("unable to write into transfer log: %1").arg(log.errorString())); + return; + } + if(sync) + { + if(log.isOpen()) + log.flush(); + } } void LogThread::newOptionValue(QString group,QString name,QVariant value) { - if(group=="Write_log" && name=="transfer_format") + if(group!="Write_log") + return; + if(name=="transfer_format") transfer_format=value.toString(); - if(group=="Write_log" && name=="error_format") + if(name=="error_format") error_format=value.toString(); - if(group=="Write_log" && name=="folder_format") + if(name=="folder_format") folder_format=value.toString(); + if(name=="sync") + { + sync=value.toBool(); + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("sync flag is set on: %1").arg(sync)); + if(sync) + { + if(log.isOpen()) + log.flush(); + } + } + if(name=="enabled") + { + if(value.toBool()) + openLogs(); + else + closeLogs(); + } } QString LogThread::replaceBaseVar(QString text) @@ -118,9 +180,8 @@ void LogThread::rmPath(QString path) { QMutexLocker lock_mutex(&mutex); data+=text; - if(data.size()>4*1024*1024) - emit newData(); } + emit newData(); } void LogThread::mkPath(QString path) @@ -134,7 +195,6 @@ void LogThread::mkPath(QString path) { QMutexLocker lock_mutex(&mutex); data+=text; - if(data.size()>4*1024*1024) - emit newData(); } + emit newData(); } diff --git a/LogThread.h b/LogThread.h index 800329ea..dd8d4927 100644 --- a/LogThread.h +++ b/LogThread.h @@ -48,6 +48,7 @@ private slots: QFile log; QString replaceBaseVar(QString text); QMutex mutex; + bool sync; protected: void run(); }; diff --git a/OptionDialog.cpp b/OptionDialog.cpp index c18c5aac..6fd24dda 100755 --- a/OptionDialog.cpp +++ b/OptionDialog.cpp @@ -226,6 +226,7 @@ void OptionDialog::loadOption() newOptionValue("Write_log", "transfer_format", options->getOptionValue("Write_log","transfer_format")); newOptionValue("Write_log", "error_format", options->getOptionValue("Write_log","error_format")); newOptionValue("Write_log", "folder_format", options->getOptionValue("Write_log","folder_format")); + newOptionValue("Write_log", "sync", options->getOptionValue("Write_log","sync")); } on_checkBox_Log_clicked(); if(plugins->getPluginsByCategory(PluginType_SessionLoader).size()>0) @@ -312,6 +313,10 @@ void OptionDialog::newOptionValue(QString group,QString name,QVariant value) { ui->checkBoxLog_transfer->setChecked(value.toBool()); } + else if(name=="sync") + { + ui->checkBoxLog_sync->setChecked(value.toBool()); + } else if(name=="error") { ui->checkBoxLog_error->setChecked(value.toBool()); @@ -659,3 +664,12 @@ void OptionDialog::on_pushButton_clicked() on_lineEditLog_File_editingFinished(); } } + +void OptionDialog::on_checkBoxLog_sync_clicked() +{ + if(plugins->allPluginHaveBeenLoaded()) + { + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start"); + options->setOptionValue("Write_log","sync",ui->checkBoxLog_sync->isChecked()); + } +} diff --git a/OptionDialog.h b/OptionDialog.h index b82b4652..6e4f841b 100755 --- a/OptionDialog.h +++ b/OptionDialog.h @@ -55,6 +55,8 @@ private slots: void on_checkBoxLog_error_clicked(); void on_pushButton_clicked(); void on_checkBoxLog_folder_clicked(); + void on_checkBoxLog_sync_clicked(); + private: Ui::OptionDialog *ui; struct pluginStore diff --git a/OptionDialog.ui b/OptionDialog.ui index bd4a394b..95c625cd 100644 --- a/OptionDialog.ui +++ b/OptionDialog.ui @@ -74,7 +74,7 @@ - 0 + 4 @@ -575,6 +575,19 @@ + + + + false + + + This write directly the file when it receive the new entry, but it can produce 50% of lost of performance + + + Synchronized log + + + @@ -674,12 +687,12 @@ setDisabled(bool) - 300 - 12 + 449 + 42 - 292 - 7 + 502 + 10 @@ -726,8 +739,8 @@ 21 - 372 - 77 + 582 + 105 @@ -742,8 +755,8 @@ 25 - 347 - 123 + 557 + 156 @@ -754,12 +767,12 @@ setEnabled(bool) - 327 - 74 + 537 + 105 - 323 - 93 + 533 + 131 @@ -770,12 +783,12 @@ setEnabled(bool) - 291 - 127 + 501 + 156 - 291 - 160 + 501 + 182 @@ -790,8 +803,24 @@ 15 - 246 - 179 + 456 + 207 + + + + + checkBox_Log + toggled(bool) + checkBoxLog_sync + setEnabled(bool) + + + 334 + 12 + + + 304 + 69 diff --git a/PluginsManager.cpp b/PluginsManager.cpp index 97a7eec0..f4531a04 100644 --- a/PluginsManager.cpp +++ b/PluginsManager.cpp @@ -34,7 +34,8 @@ PluginsManager::PluginsManager() connect(this, SIGNAL(newLanguageLoaded()), &pluginInformationWindows, SLOT(retranslateInformation())); // connect(this, SIGNAL(pluginListingIsfinish()), options,SLOT(setInterfaceValue())); //load the plugins list - this->start(); + /// \bug bug when I put here: moveToThread(this); + start(); } /// \brief Destroy the manager diff --git a/ResourcesManager.h b/ResourcesManager.h index f81e0b88..8b0bfbd8 100644 --- a/ResourcesManager.h +++ b/ResourcesManager.h @@ -2,8 +2,7 @@ \brief Define the class to manage and load the resources linked with the themes \author alpha_one_x86 \version 0.3 -\date 2010 -\example ResourcesManager.cpp */ +\date 2010 */ #ifndef RESOURCES_MANAGER_H #define RESOURCES_MANAGER_H diff --git a/lib/qt-tar-xz/QXzDecodeThread.cpp b/lib/qt-tar-xz/QXzDecodeThread.cpp index e5e1ef16..ba8c38c0 100644 --- a/lib/qt-tar-xz/QXzDecodeThread.cpp +++ b/lib/qt-tar-xz/QXzDecodeThread.cpp @@ -2,6 +2,7 @@ QXzDecodeThread::QXzDecodeThread() { + moveToThread(this); DataToDecode=NULL; error=false; } diff --git a/plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp b/plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp index e1837432..28bb29a5 100644 --- a/plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp +++ b/plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp @@ -532,7 +532,7 @@ bool ListThread::skipInternal(quint64 id) { if(transferThreadList.at(index).id==id) { - ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"skip one transfer"); + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("skip one transfer: %1").arg(id)); transferThreadList.at(index).thread->skip(); return true; } diff --git a/plugins/CopyEngine/Ultracopier-0.3/MkPath.cpp b/plugins/CopyEngine/Ultracopier-0.3/MkPath.cpp index c97e6781..6ce23f44 100644 --- a/plugins/CopyEngine/Ultracopier-0.3/MkPath.cpp +++ b/plugins/CopyEngine/Ultracopier-0.3/MkPath.cpp @@ -5,6 +5,7 @@ MkPath::MkPath() stopIt=false; waitAction=false; setObjectName("MkPath"); + moveToThread(this); start(); } diff --git a/plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp b/plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp index 83ce114e..64b67c04 100644 --- a/plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp +++ b/plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp @@ -66,6 +66,7 @@ QString ReadThread::errorString() void ReadThread::stop() { + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] stop()"); stopIt=true; emit internalStartClose(); } @@ -80,12 +81,14 @@ bool ReadThread::pause() void ReadThread::resume() { - ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] start"); if(putInPause) { + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] start"); putInPause=false; stopIt=false; } + else + return; if(tryStartRead) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"["+QString::number(id)+"] already in try start"); @@ -242,8 +245,11 @@ void ReadThread::internalRead() #endif if(!writeThread->write(blockArray)) { - ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"["+QString::number(id)+"] stopped because the write is stopped: "+QString::number(lastGoodPosition)); - stopIt=true; + if(!stopIt) + { + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"["+QString::number(id)+"] stopped because the write is stopped: "+QString::number(lastGoodPosition)); + stopIt=true; + } } #ifdef ULTRACOPIER_PLUGIN_DEBUG diff --git a/plugins/CopyEngine/Ultracopier-0.3/RmPath.cpp b/plugins/CopyEngine/Ultracopier-0.3/RmPath.cpp index b8e6cea0..ee3a4e56 100644 --- a/plugins/CopyEngine/Ultracopier-0.3/RmPath.cpp +++ b/plugins/CopyEngine/Ultracopier-0.3/RmPath.cpp @@ -5,6 +5,7 @@ RmPath::RmPath() stopIt=false; waitAction=false; setObjectName("RmPath"); + moveToThread(this); start(); } diff --git a/plugins/CopyEngine/Ultracopier-0.3/TransferThread.cpp b/plugins/CopyEngine/Ultracopier-0.3/TransferThread.cpp index 86a91255..493a9cd9 100644 --- a/plugins/CopyEngine/Ultracopier-0.3/TransferThread.cpp +++ b/plugins/CopyEngine/Ultracopier-0.3/TransferThread.cpp @@ -538,7 +538,10 @@ bool TransferThread::checkIfAllIsClosed() return true; } else + { + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] wait self close"); return false; + } } /// \todo found way to retry that's diff --git a/plugins/CopyEngine/Ultracopier-0.3/WriteThread.cpp b/plugins/CopyEngine/Ultracopier-0.3/WriteThread.cpp index eca56d60..383c03df 100644 --- a/plugins/CopyEngine/Ultracopier-0.3/WriteThread.cpp +++ b/plugins/CopyEngine/Ultracopier-0.3/WriteThread.cpp @@ -65,7 +65,7 @@ bool WriteThread::internalOpen() QDir destinationFolder; if(!destinationFolder.exists(destinationInfo.absolutePath())) { - ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"["+QString::number(id)+"] "+QString("Try create the path: %1") + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] "+QString("Try create the path: %1") .arg(destinationInfo.absolutePath())); if(!destinationFolder.mkpath(destinationInfo.absolutePath())) { @@ -163,10 +163,12 @@ bool WriteThread::write(const QByteArray &data) void WriteThread::stop() { + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] stop()"); stopIt=true; freeBlock.release(); - /* useless because stopIt will close all thread - emit internalStartClose();*/ + // useless because stopIt will close all thread, but if thread not runing run it + endIsDetected(); + //emit internalStartClose(); } void WriteThread::flushBuffer() diff --git a/plugins/CopyEngine/Ultracopier-0.3/informations.xml b/plugins/CopyEngine/Ultracopier-0.3/informations.xml index 8d24537f..80c7d5a7 100644 --- a/plugins/CopyEngine/Ultracopier-0.3/informations.xml +++ b/plugins/CopyEngine/Ultracopier-0.3/informations.xml @@ -22,6 +22,6 @@ Ultracopier-0.2 \ No newline at end of file diff --git a/plugins/CopyEngine/Ultracopier-0.3/options.ui b/plugins/CopyEngine/Ultracopier-0.3/options.ui index f2feda37..77bf15a1 100644 --- a/plugins/CopyEngine/Ultracopier-0.3/options.ui +++ b/plugins/CopyEngine/Ultracopier-0.3/options.ui @@ -100,7 +100,7 @@ - When folder colision + When folder collision