Skip to content

Commit

Permalink
Do not freeze UI when populating ECU tree
Browse files Browse the repository at this point in the history
Run ecu populating code in a separate thread

Additionally:
- Fix couple of warnings
- Minor cleanup of dead code
- Const-correctness for a couple of funcs

Signed-off-by: Viktor Kopp <[email protected]>
  • Loading branch information
vifactor committed Nov 22, 2024
1 parent 02da750 commit 3f51d3f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
10 changes: 1 addition & 9 deletions src/dltfileindexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ bool DltFileIndexer::index(int num)
quint8 version=1;
qint64 lengthOffset=2;
qint64 storageLength=0;
int iPercent =0;
errors_in_file = 0;
char *data = new char[DLT_FILE_INDEXER_SEG_SIZE];

Expand Down Expand Up @@ -378,7 +377,6 @@ bool DltFileIndexer::indexFilter(QStringList filenames)
{
QSharedPointer<QDltMsg> msg;
QDltFilterList filterList;
QTime time;
quint64 ix = 0;
unsigned int iPercent = 0;

Expand Down Expand Up @@ -429,12 +427,6 @@ bool DltFileIndexer::indexFilter(QStringList filenames)
return true;
}

unsigned int modvalue = dltFile->size()/20;
if (modvalue == 0) // avoid divison by zero
{
modvalue = 1;
}

// Initialise progress bar
emit(progressText(QString("CFI %1/%2").arg(currentRun).arg(maxRun)));
emit(progressMax(100));
Expand Down Expand Up @@ -470,7 +462,7 @@ bool DltFileIndexer::indexFilter(QStringList filenames)
qDebug() << "Create filter index: Start";

/* init fileprogress */
int progressCounter = 1;
unsigned int progressCounter = 1;
emit progress(0);

// Start reading messages
Expand Down
2 changes: 1 addition & 1 deletion src/dltfileindexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class DltFileIndexer : public QThread
// get index of all messages
QVector<qint64> getIndexAll() { return indexAllList; }
QVector<qint64> getIndexFilters() { return indexFilterList; }
QList<int> getGetLogInfoList() { return getLogInfoList; }
const QList<int>& getGetLogInfoList() { return getLogInfoList; }

// let worker thread append to getLogInfoList
void appendToGetLogInfoList(int value);
Expand Down
35 changes: 21 additions & 14 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#include <QTemporaryFile>
#include <QtEndian>

#include <QThreadPool>

/**
* From QDlt.
* Must be a "C" include to interpret the imports correctly
Expand Down Expand Up @@ -685,8 +687,8 @@ void MainWindow::initFileHandling()
ui->checkBoxSortByTimestamp->setEnabled(ui->filtersEnabled->isChecked());
ui->checkBoxSortByTimestamp->setChecked(QDltSettingsManager::getInstance()->value("startup/sortByTimestampEnabled", false).toBool());
ui->checkBoxFilterRange->setEnabled(ui->filtersEnabled->isChecked());
ui->lineEditFilterStart->setEnabled(ui->checkBoxFilterRange->isChecked() & ui->filtersEnabled->isChecked());
ui->lineEditFilterEnd->setEnabled(ui->checkBoxFilterRange->isChecked() & ui->filtersEnabled->isChecked());
ui->lineEditFilterStart->setEnabled(ui->checkBoxFilterRange->isChecked() && ui->filtersEnabled->isChecked());
ui->lineEditFilterEnd->setEnabled(ui->checkBoxFilterRange->isChecked() && ui->filtersEnabled->isChecked());

/* Process Project */
if(QDltOptManager::getInstance()->isProjectFile())
Expand Down Expand Up @@ -1012,6 +1014,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
settingsDlg->writeSettings(this);
if(true == isSearchOngoing)
{
qDebug() << "Ignoring close event";
event->ignore();
}
else if(settings->tempCloseWithoutAsking || outputfile.size() == 0)
Expand Down Expand Up @@ -1895,7 +1898,7 @@ void MainWindow::on_action_menuFile_Clear_triggered()
return;
}

void MainWindow::contextLoadingFile(QDltMsg &msg)
void MainWindow::contextLoadingFile(const QDltMsg &msg)
{
/* analyse message, check if DLT control message response */
if ( (msg.getType()==QDltMsg::DltTypeControl) && (msg.getSubtype()==QDltMsg::DltControlResponse))
Expand Down Expand Up @@ -1931,7 +1934,7 @@ void MainWindow::contextLoadingFile(QDltMsg &msg)

}

controlMessage_ReceiveControlMessage(ecuitemFound,msg);
controlMessage_ReceiveControlMessage(ecuitemFound, msg);
}
}

Expand Down Expand Up @@ -2060,15 +2063,19 @@ void MainWindow::reloadLogFileFinishFilter()
// process getLogInfoMessages
if(( dltIndexer->getMode() == DltFileIndexer::modeIndexAndFilter) && settings->updateContextLoadingFile)
{
QList<int> list = dltIndexer->getGetLogInfoList();
QDltMsg msg;
qDebug() << "Populating ECUs tree";
isSearchOngoing = true;
QThreadPool::globalInstance()->start([this] {
const QList<int>& msgIndexList = dltIndexer->getGetLogInfoList();

// FIXME: this is slow operation running in the main loop
for(int num=0;num<list.size();num++)
{
if(qfile.getMsg(list[num],msg))
contextLoadingFile(msg);
}
QDltMsg msg;
for (const auto msgIndex : msgIndexList) {
if (qfile.getMsg(msgIndex, msg))
contextLoadingFile(msg);
}
isSearchOngoing = false;
});
qDebug() << "Populating ECUs end.";
}

// reconnect ecus again
Expand Down Expand Up @@ -4461,7 +4468,7 @@ void MainWindow::onSearchresultsTableSelectionChanged(const QItemSelection & sel
}
}

void MainWindow::controlMessage_ReceiveControlMessage(EcuItem *ecuitem, QDltMsg &msg)
void MainWindow::controlMessage_ReceiveControlMessage(EcuItem *ecuitem, const QDltMsg &msg)
{
const char *ptr;
int32_t length;
Expand Down Expand Up @@ -6399,7 +6406,7 @@ void MainWindow::updatePlugin(PluginItem *item)
}
}

void MainWindow::versionString(QDltMsg &msg)
void MainWindow::versionString(const QDltMsg &msg)
{
// get the version string from the version message
// Skip the ServiceID, Status and Length bytes and start from the String containing the ECU Software Version
Expand Down
7 changes: 3 additions & 4 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class MainWindow : public QMainWindow
void controlMessage_SetTimingPackets(EcuItem* ecuitem, bool enable);
void controlMessage_GetSoftwareVersion(EcuItem* ecuitem);
void controlMessage_GetLogInfo(EcuItem* ecuitem);
void controlMessage_ReceiveControlMessage(EcuItem *ecuitem,QDltMsg &msg);
void controlMessage_ReceiveControlMessage(EcuItem *ecuitem, const QDltMsg &msg);
void controlMessage_SetContext(EcuItem *ecuitem, QString apid, QString ctid,QString ctdescription,int log_level,int trace_status);
void controlMessage_SetApplication(EcuItem *ecuitem, QString apid, QString appdescription);
void controlMessage_Marker();
Expand All @@ -286,8 +286,8 @@ class MainWindow : public QMainWindow
void updatePluginsECUList();
void updatePlugins();
void updatePlugin(PluginItem *item);
void contextLoadingFile(QDltMsg &msg);
void versionString(QDltMsg &msg);
void contextLoadingFile(const QDltMsg &msg);
void versionString(const QDltMsg &msg);
void pluginsAutoload(QString version);

void connectECU(EcuItem *ecuitem,bool force = false);
Expand Down Expand Up @@ -633,7 +633,6 @@ public slots:

signals:
void dltFileLoaded(const QStringList& paths);

};

#endif // MAINWINDOW_H

0 comments on commit 3f51d3f

Please sign in to comment.