Skip to content

Commit

Permalink
Thread improvement, user transfer log improvement, discovering one bug
Browse files Browse the repository at this point in the history
  • Loading branch information
alphaonex86 committed Jan 26, 2012
1 parent 439a569 commit 341127c
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 50 deletions.
1 change: 1 addition & 0 deletions AuthPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ AuthPlugin::AuthPlugin(QObject * parent) :
stopIt=false;
//set sem to 1
sem.release();
moveToThread(this);
}

AuthPlugin::~AuthPlugin()
Expand Down
6 changes: 6 additions & 0 deletions Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()!="")
Expand All @@ -30,14 +31,19 @@ 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%")));
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"));

log.openLogs();

connect(options,SIGNAL(newOptionValue(QString,QString,QVariant)), this, SLOT(newOptionValue(QString,QString,QVariant)));
}

void Core::newCopy(quint32 orderId,QStringList protocolsUsedForTheSources,QStringList sources)
Expand Down
3 changes: 1 addition & 2 deletions EventDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 77 additions & 17 deletions LogThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,66 @@

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<QPair<QString, QVariant> > 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()
{
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();
Expand All @@ -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)
Expand All @@ -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();
}

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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();
}
1 change: 1 addition & 0 deletions LogThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private slots:
QFile log;
QString replaceBaseVar(QString text);
QMutex mutex;
bool sync;
protected:
void run();
};
Expand Down
14 changes: 14 additions & 0 deletions OptionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
}
2 changes: 2 additions & 0 deletions OptionDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 48 additions & 19 deletions OptionDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
<number>4</number>
</property>
<widget class="QWidget" name="stackedWidgetGeneral">
<layout class="QVBoxLayout" name="verticalLayout_10">
Expand Down Expand Up @@ -575,6 +575,19 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxLog_sync">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>This write directly the file when it receive the new entry, but it can produce 50% of lost of performance</string>
</property>
<property name="text">
<string>Synchronized log</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxLog_transfer">
<property name="enabled">
Expand Down Expand Up @@ -674,12 +687,12 @@
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>300</x>
<y>12</y>
<x>449</x>
<y>42</y>
</hint>
<hint type="destinationlabel">
<x>292</x>
<y>7</y>
<x>502</x>
<y>10</y>
</hint>
</hints>
</connection>
Expand Down Expand Up @@ -726,8 +739,8 @@
<y>21</y>
</hint>
<hint type="destinationlabel">
<x>372</x>
<y>77</y>
<x>582</x>
<y>105</y>
</hint>
</hints>
</connection>
Expand All @@ -742,8 +755,8 @@
<y>25</y>
</hint>
<hint type="destinationlabel">
<x>347</x>
<y>123</y>
<x>557</x>
<y>156</y>
</hint>
</hints>
</connection>
Expand All @@ -754,12 +767,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>327</x>
<y>74</y>
<x>537</x>
<y>105</y>
</hint>
<hint type="destinationlabel">
<x>323</x>
<y>93</y>
<x>533</x>
<y>131</y>
</hint>
</hints>
</connection>
Expand All @@ -770,12 +783,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>291</x>
<y>127</y>
<x>501</x>
<y>156</y>
</hint>
<hint type="destinationlabel">
<x>291</x>
<y>160</y>
<x>501</x>
<y>182</y>
</hint>
</hints>
</connection>
Expand All @@ -790,8 +803,24 @@
<y>15</y>
</hint>
<hint type="destinationlabel">
<x>246</x>
<y>179</y>
<x>456</x>
<y>207</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkBox_Log</sender>
<signal>toggled(bool)</signal>
<receiver>checkBoxLog_sync</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>334</x>
<y>12</y>
</hint>
<hint type="destinationlabel">
<x>304</x>
<y>69</y>
</hint>
</hints>
</connection>
Expand Down
Loading

0 comments on commit 341127c

Please sign in to comment.