From 0e2808aed1e36771e7092e240a55fca0fb15da39 Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Mon, 18 Nov 2024 17:43:57 +0100 Subject: [PATCH] Background thread for import. Improve progress bar for import. Signed-off-by: Alexander Wenzel --- commander/main.cpp | 8 +- qdlt/qdltimporter.cpp | 226 ++++++++++++++++++++++-------------------- qdlt/qdltimporter.h | 31 ++++-- src/mainwindow.cpp | 201 +++++++++++++++++++------------------ src/mainwindow.h | 2 + 5 files changed, 249 insertions(+), 219 deletions(-) diff --git a/commander/main.cpp b/commander/main.cpp index 565c189e..aee24253 100644 --- a/commander/main.cpp +++ b/commander/main.cpp @@ -68,8 +68,8 @@ int main(int argc, char *argv[]) for ( const auto& i : mf4Files ) { qDebug() << "Import MF4 File:" << i; - QDltImporter importer; - importer.dltIpcFromMF4(outputfile,i,0,false); + QDltImporter importer(&outputfile); + importer.dltIpcFromMF4(i); } // load PCAP files QStringList pcapFiles = opt.getPcapFiles(); @@ -78,8 +78,8 @@ int main(int argc, char *argv[]) for ( const auto& i : pcapFiles ) { qDebug() << "Import PCAP File:" << i; - QDltImporter importer; - importer.dltIpcFromPCAP(outputfile,i,0,false); + QDltImporter importer(&outputfile); + importer.dltIpcFromPCAP(i); } } diff --git a/qdlt/qdltimporter.cpp b/qdlt/qdltimporter.cpp index 3838f0fc..76f96038 100644 --- a/qdlt/qdltimporter.cpp +++ b/qdlt/qdltimporter.cpp @@ -25,10 +25,18 @@ extern "C" { #include "qdltmsg.h" #include "qdltimporter.h" -QDltImporter::QDltImporter(QObject *parent) : - QObject(parent) +QDltImporter::QDltImporter(QFile *outputfile, QStringList fileNames, QObject *parent) : + QThread(parent) { + this->outputfile = outputfile; + this->fileNames = fileNames; +} +QDltImporter::QDltImporter(QFile *outputfile, QString fileName,QObject *parent) : + QThread(parent) +{ + this->outputfile = outputfile; + fileNames.append(fileName); } QDltImporter::~QDltImporter() @@ -36,11 +44,21 @@ QDltImporter::~QDltImporter() } -void QDltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *parent,bool silent) +void QDltImporter::run() { - Q_UNUSED(silent) - Q_UNUSED(parent) + QString result; + for ( const auto& i : fileNames ) + { + if(i.endsWith(".mf4",Qt::CaseInsensitive)) + dltIpcFromMF4(i); + else if (i.endsWith(".pcap",Qt::CaseInsensitive)) + dltIpcFromPCAP(i); + } + emit resultReady(result); +} +void QDltImporter::dltIpcFromPCAP(QString fileName) +{ counterRecords = 0; counterRecordsDLT = 0; counterRecordsIPC = 0; @@ -53,9 +71,9 @@ void QDltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *pa return; /* open output file */ - if(!outputfile.open(QIODevice::WriteOnly|QIODevice::Append)) + if(!outputfile->open(QIODevice::WriteOnly|QIODevice::Append)) { - qDebug() << "Failed opening WriteOnly" << outputfile.fileName(); + qDebug() << "Failed opening WriteOnly" << outputfile->fileName(); } int progressCounter = 1; @@ -69,7 +87,7 @@ void QDltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *pa if(inputfile.read((char*)&globalHeader,sizeof(pcap_hdr_t))!=sizeof(pcap_hdr_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromPCAP:" << "Cannot open file" << fileName; return; } @@ -90,7 +108,7 @@ void QDltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *pa if(record.length() != recordHeader.incl_len) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromPCAP: PCAP file not complete!"; qDebug() << "fromPCAP:" << "Size Error: Cannot read Record"; return; @@ -101,29 +119,29 @@ void QDltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *pa if(record.size()<(qsizetype)(pos+2)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "dltFromPCAP:" << "Size Error: Cannot read Record"; return; } quint16 etherType = (((quint16)record.at(pos))<<8)|((quint16)(record.at(pos+1)&0xff)); pos+=2; - if(!dltFromEthernetFrame(outputfile,record,pos,etherType,recordHeader.ts_sec,recordHeader.ts_usec)) + if(!dltFromEthernetFrame(record,pos,etherType,recordHeader.ts_sec,recordHeader.ts_usec)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromPCAP:" << "Size Error: Cannot read Ethernet Frame"; return; } - if(!ipcFromEthernetFrame(outputfile,record,pos,etherType,recordHeader.ts_sec,recordHeader.ts_usec)) + if(!ipcFromEthernetFrame(record,pos,etherType,recordHeader.ts_sec,recordHeader.ts_usec)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromPCAP:" << "Size Error: Cannot read Ethernet Frame"; return; } } inputfile.close(); - outputfile.close(); + outputfile->close(); emit progress("",3,100); @@ -136,11 +154,8 @@ void QDltImporter::dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *pa qDebug() << "fromPCAP: Import finished"; } -void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *parent,bool silent) +void QDltImporter::dltIpcFromMF4(QString fileName) { - Q_UNUSED(silent) - Q_UNUSED(parent) - counterRecords = 0; counterRecordsDLT = 0; counterRecordsIPC = 0; @@ -158,9 +173,9 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par } /* open output file */ - if(!outputfile.open(QIODevice::WriteOnly|QIODevice::Append)) + if(!outputfile->open(QIODevice::WriteOnly|QIODevice::Append)) { - qDebug() << "Failed opening WriteOnly" << outputfile.fileName(); + qDebug() << "Failed opening WriteOnly" << outputfile->fileName(); } int progressCounter = 1; @@ -171,7 +186,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&mdfIdblock,sizeof(mdf_idblock_t))!=sizeof(mdf_idblock_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot reard Id Block"; return; } @@ -184,7 +199,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&mdfHeader,sizeof(mdf_hdr_t))!=sizeof(mdf_hdr_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read mdf header"; return; } @@ -196,7 +211,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&hdBlockLinks,sizeof(mdf_hdblocklinks_t))!=sizeof(mdf_hdblocklinks_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read HD Block"; return; } @@ -208,7 +223,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&mdfDgHeader,sizeof(mdf_hdr_t))!=sizeof(mdf_hdr_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot reard DG Block"; return; } @@ -218,7 +233,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&mdfDgBlockLinks,sizeof(mdf_dgblocklinks_t))!=sizeof(mdf_dgblocklinks_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot reard DG Block"; return; } @@ -231,7 +246,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&mdfCgHeader,sizeof(mdf_hdr_t))!=sizeof(mdf_hdr_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot reard CG Block"; return; } @@ -242,7 +257,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&mdfCgBlockLinks,sizeof(mdf_cgblocklinks_t))!=sizeof(mdf_cgblocklinks_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot reard CG Block"; return; } @@ -262,7 +277,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par { qDebug() << "fromMF4:" << "Size Error: Cannot reard CN Block"; inputfile.close(); - outputfile.close(); + outputfile->close(); return; } if(mdfCnHeader.id[0]=='#' && mdfCnHeader.id[1]=='#' && mdfCnHeader.id[2]=='C' && mdfCnHeader.id[3]=='N') @@ -272,7 +287,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&mdfChBlockLinks,sizeof(mdf_cnblocklinks_t))!=sizeof(mdf_cnblocklinks_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot reard CN Block"; return; } @@ -282,7 +297,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&mdfTxHeader,sizeof(mdf_hdr_t))!=sizeof(mdf_hdr_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot reard Tx Block"; return; } @@ -295,7 +310,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(cnNameReadLength != cnNameLength ) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read cn name"; return; } @@ -322,7 +337,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&mdfHeader,sizeof(mdf_hdr_t))!=sizeof(mdf_hdr_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4: Cannot read datalist header"; return; } @@ -334,7 +349,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&addressOfDataBlock,sizeof(quint64))!=sizeof(quint64)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4: Cannot read datablock address"; return; } @@ -342,7 +357,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&mdfHeader,sizeof(mdf_hdr_t))!=sizeof(mdf_hdr_t)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4: Cannot read datablock header"; return; } @@ -380,7 +395,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&recordId,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } @@ -395,7 +410,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&lengthVLSD,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } @@ -410,63 +425,63 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)ðFrame.timeStamp,sizeof(quint64))!=sizeof(quint64)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.asynchronous,sizeof(quint8))!=sizeof(quint8)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.source,6)!=6) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.destination,6)!=6) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.etherType,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.crc,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.receivedDataByteCount,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.dataLength,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.dataBytes,sizeof(quint64))!=sizeof(quint64)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } @@ -474,18 +489,18 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par { int pos = 0; quint64 time = hdBlockLinks.start_time_ns+ethFrame.timeStamp+(hdBlockLinks.hd_tz_offset_min+hdBlockLinks.hd_dst_offset_min)*60*1000000000; - if(!dltFromEthernetFrame(outputfile,recordData,pos,ethFrame.etherType,time/1000000000,time%1000000000/1000)) + if(!dltFromEthernetFrame(recordData,pos,ethFrame.etherType,time/1000000000,time%1000000000/1000)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4: ERROR:" << "Size Error: Cannot read Ethernet Frame"; return; } pos = 0; - if(!ipcFromEthernetFrame(outputfile,recordData,pos,ethFrame.etherType,time/1000000000,time%1000000000/1000)) + if(!ipcFromEthernetFrame(recordData,pos,ethFrame.etherType,time/1000000000,time%1000000000/1000)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4: ERROR:" << "Size Error: Cannot read Ethernet Frame"; return; } @@ -499,70 +514,70 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)ðFrame.timeStamp,sizeof(quint64))!=sizeof(quint64)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.asynchronous,sizeof(quint8))!=sizeof(quint8)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.source,6)!=6) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.destination,6)!=6) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.etherType,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.crc,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.receivedDataByteCount,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.beaconTimeStamp,sizeof(quint64))!=sizeof(quint64)) // TODO: Beacon Time Stamp { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.dataLength,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)ðFrame.dataBytes,sizeof(quint64))!=sizeof(quint64)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } @@ -570,18 +585,18 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par { int pos = 0; quint64 time = hdBlockLinks.start_time_ns+ethFrame.timeStamp+(hdBlockLinks.hd_tz_offset_min+hdBlockLinks.hd_dst_offset_min)*60*1000000000; - if(!dltFromEthernetFrame(outputfile,recordData,pos,ethFrame.etherType,time/1000000000,time%1000000000/1000)) + if(!dltFromEthernetFrame(recordData,pos,ethFrame.etherType,time/1000000000,time%1000000000/1000)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4: ERROR:" << "Size Error: Cannot read Ethernet Frame"; return; } pos = 0; - if(!ipcFromEthernetFrame(outputfile,recordData,pos,ethFrame.etherType,time/1000000000,time%1000000000/1000)) + if(!ipcFromEthernetFrame(recordData,pos,ethFrame.etherType,time/1000000000,time%1000000000/1000)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4: ERROR:" << "Size Error: Cannot read Ethernet Frame"; return; } @@ -595,49 +610,49 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&dltFrameBlock.timeStamp,sizeof(quint64))!=sizeof(quint64)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&dltFrameBlock.asynchronous,sizeof(quint8))!=sizeof(quint8)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&dltFrameBlock.currentFragmentNumber,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&dltFrameBlock.lastFragmentNumber,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&dltFrameBlock.ecuId,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&dltFrameBlock.dataLength,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&dltFrameBlock.dataBytes,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } @@ -645,10 +660,10 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par { int pos = 0; quint64 time = hdBlockLinks.start_time_ns+dltFrameBlock.timeStamp+(hdBlockLinks.hd_tz_offset_min+hdBlockLinks.hd_dst_offset_min)*60*1000000000; - if(!dltFrame(outputfile,recordData,pos,time/1000000000,time%1000000000/1000)) + if(!dltFrame(recordData,pos,time/1000000000,time%1000000000/1000)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4: ERROR:" << "Size Error: Cannot read DLTFrame"; return; } @@ -662,73 +677,73 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par if(inputfile.read((char*)&plpRaw.timeStamp,sizeof(quint64))!=sizeof(quint64)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&plpRaw.asynchronous,sizeof(quint8))!=sizeof(quint8)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&plpRaw.probeId,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&plpRaw.msgType,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&plpRaw.probeFlags,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&plpRaw.dataFlags,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&plpRaw.dataCounter,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&plpRaw.dataLength,sizeof(quint16))!=sizeof(quint16)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(inputfile.read((char*)&plpRaw.dataBytes,sizeof(quint32))!=sizeof(quint32)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4:" << "Size Error: Cannot read Record"; return; } if(!recordData.isEmpty()) { quint64 time = hdBlockLinks.start_time_ns+plpRaw.timeStamp+(hdBlockLinks.hd_tz_offset_min+hdBlockLinks.hd_dst_offset_min)*60*1000000000; - if(!ipcFromPlpRaw(&plpRaw,outputfile,recordData,time/1000000000,time%1000000000/1000)) + if(!ipcFromPlpRaw(&plpRaw,recordData,time/1000000000,time%1000000000/1000)) { inputfile.close(); - outputfile.close(); + outputfile->close(); qDebug() << "fromMF4: ERROR:" << "Size Error: Cannot read Ethernet Frame"; return; } @@ -753,7 +768,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par } inputfile.close(); - outputfile.close(); + outputfile->close(); emit progress("",3,100); @@ -766,7 +781,7 @@ void QDltImporter::dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *par qDebug() << "fromMF4: Import finished"; } -bool QDltImporter::ipcFromEthernetFrame(QFile &outputfile,QByteArray &record,int pos,quint16 etherType,quint32 sec,quint32 usec) +bool QDltImporter::ipcFromEthernetFrame(QByteArray &record,int pos,quint16 etherType,quint32 sec,quint32 usec) { if(etherType==0x9100 || etherType==0x88a8) { @@ -893,7 +908,7 @@ bool QDltImporter::ipcFromEthernetFrame(QFile &outputfile,QByteArray &record,int // write DLT message msg.getMsg(payload,false); - writeDLTMessageToFile(outputfile,payload,0,0,0,sec,usec); + writeDLTMessageToFile(payload,0,0,0,sec,usec); } pos += qFromBigEndian(plpHeaderData->length); @@ -904,7 +919,7 @@ bool QDltImporter::ipcFromEthernetFrame(QFile &outputfile,QByteArray &record,int return true; } -bool QDltImporter::ipcFromPlpRaw(mdf_plpRaw_t *plpRaw, QFile &outputfile,QByteArray &record,quint32 sec,quint32 usec) +bool QDltImporter::ipcFromPlpRaw(mdf_plpRaw_t *plpRaw,QByteArray &record,quint32 sec,quint32 usec) { bool startOfSegment = plpRaw->probeFlags & 0x2; if(startOfSegment) @@ -991,7 +1006,7 @@ bool QDltImporter::ipcFromPlpRaw(mdf_plpRaw_t *plpRaw, QFile &outputfile,QByteAr // write DLT message msg.getMsg(payload,false); - writeDLTMessageToFile(outputfile,payload,0,0,0,sec,usec); + writeDLTMessageToFile(payload,0,0,0,sec,usec); } } @@ -999,7 +1014,7 @@ bool QDltImporter::ipcFromPlpRaw(mdf_plpRaw_t *plpRaw, QFile &outputfile,QByteAr return true; } -bool QDltImporter::dltFrame(QFile &outputfile,QByteArray &record,int pos,quint32 sec,quint32 usec) +bool QDltImporter::dltFrame(QByteArray &record,int pos,quint32 sec,quint32 usec) { counterRecordsDLT++; // Now read the DLT Messages @@ -1015,7 +1030,7 @@ bool QDltImporter::dltFrame(QFile &outputfile,QByteArray &record,int pos,quint32 { // DLT message found, write it with storage header QByteArray empty; - writeDLTMessageToFile(outputfile,empty,dataPtr,sizeMsg,0,sec,usec); + writeDLTMessageToFile(empty,dataPtr,sizeMsg,0,sec,usec); counterDLTMessages++; //totalBytesRcvd+=sizeMsg; @@ -1039,7 +1054,7 @@ bool QDltImporter::dltFrame(QFile &outputfile,QByteArray &record,int pos,quint32 } -bool QDltImporter::dltFromEthernetFrame(QFile &outputfile,QByteArray &record,int pos,quint16 etherType,quint32 sec,quint32 usec) +bool QDltImporter::dltFromEthernetFrame(QByteArray &record,int pos,quint16 etherType,quint32 sec,quint32 usec) { if(etherType==0x9100 || etherType==0x88a8) { @@ -1095,7 +1110,7 @@ bool QDltImporter::dltFromEthernetFrame(QFile &outputfile,QByteArray &record,int } quint16 etherType2 = (((quint16)record.at(pos))<<8)|((quint16)(record.at(pos+1)&0xff)); pos+=2; - if(!dltFromEthernetFrame(outputfile,record,pos,etherType2,sec,usec)) // TODO: Use time from PLP instead + if(!dltFromEthernetFrame(record,pos,etherType2,sec,usec)) // TODO: Use time from PLP instead { qDebug() << "dltFromEthernetFrame:" << "Size Error: Cannot read Ethernet Frame"; return false; @@ -1143,7 +1158,7 @@ bool QDltImporter::dltFromEthernetFrame(QFile &outputfile,QByteArray &record,int if(destPort==3490||destPort==3489) { pos+=6; - dltFrame(outputfile,record,pos,sec,usec); + dltFrame(record,pos,sec,usec); } } else @@ -1164,7 +1179,7 @@ bool QDltImporter::dltFromEthernetFrame(QFile &outputfile,QByteArray &record,int if(destPort==3490||destPort==3489) { pos+=6; - dltFrame(outputfile,segmentBufferUDP,pos,sec,usec); + dltFrame(segmentBufferUDP,pos,sec,usec); } segmentBufferUDP.clear(); } @@ -1179,7 +1194,7 @@ bool QDltImporter::dltFromEthernetFrame(QFile &outputfile,QByteArray &record,int return true; } -void QDltImporter::writeDLTMessageToFile(QFile &outputfile,QByteArray &bufferHeader,char* bufferPayload,quint32 bufferPayloadSize,QString ecuId,quint32 sec,quint32 usec) +void QDltImporter::writeDLTMessageToFile(QByteArray &bufferHeader,char* bufferPayload,quint32 bufferPayloadSize,QString ecuId,quint32 sec,quint32 usec) { DltStorageHeader str; @@ -1217,25 +1232,24 @@ void QDltImporter::writeDLTMessageToFile(QFile &outputfile,QByteArray &bufferHea //if(!ecuitem || !ecuitem->getWriteDLTv2StorageHeader()) { // write version 1 storage header - outputfile.write((char*)&str,sizeof(DltStorageHeader)); + outputfile->write((char*)&str,sizeof(DltStorageHeader)); } /*else { // write version 2 storage header - outputfile.write((char*)"DLT",3); + outputfile->write((char*)"DLT",3); quint8 version = 2; - outputfile.write((char*)&version,1); + outputfile->write((char*)&version,1); quint32 nanoseconds = str.microseconds * 1000ul; // not in big endian format - outputfile.write((char*)&nanoseconds,4); + outputfile->write((char*)&nanoseconds,4); quint64 seconds = (quint64) str.seconds; // not in big endian format - outputfile.write(((char*)&seconds),5); + outputfile->write(((char*)&seconds),5); quint8 length; length = ecuitem->id.length(); - outputfile.write((char*)&length,1); - outputfile.write(ecuitem->id.toLatin1(),ecuitem->id.length()); + outputfile->write((char*)&length,1); + outputfile->write(ecuitem->id.toLatin1(),ecuitem->id.length()); }*/ - outputfile.write(bufferHeader); - outputfile.write(bufferPayload,bufferPayloadSize); + outputfile->write(bufferHeader); + outputfile->write(bufferPayload,bufferPayloadSize); } - diff --git a/qdlt/qdltimporter.h b/qdlt/qdltimporter.h index d21d5117..395e4c88 100644 --- a/qdlt/qdltimporter.h +++ b/qdlt/qdltimporter.h @@ -2,6 +2,8 @@ #define QDLTIMPORTER_H #include +#include +#include #include "export_rules.h" #include "qfile.h" @@ -152,26 +154,31 @@ typedef struct mdf_hdr { quint64 link_count; /* number of links in link section */ } PACKED mdf_hdr_t; -class QDLT_EXPORT QDltImporter : public QObject +class QDLT_EXPORT QDltImporter : public QThread { Q_OBJECT public: - explicit QDltImporter(QObject *parent=0); + explicit QDltImporter(QFile *outputfile, QStringList fileNames ,QObject *parent=0); + explicit QDltImporter(QFile *outputfile, QString fileName = "",QObject *parent=0); ~QDltImporter(); - void dltIpcFromPCAP(QFile &outputfile,QString fileName,QWidget *parent,bool silent); - void dltIpcFromMF4(QFile &outputfile,QString fileName,QWidget *parent,bool silent); + void run() override; -private: + void dltIpcFromPCAP(QString fileName); + void dltIpcFromMF4(QString fileName); - bool dltFrame(QFile &outputfile,QByteArray &record,int pos,quint32 sec = 0,quint32 usec = 0); - bool dltFromEthernetFrame(QFile &outputfile,QByteArray &record,int pos,quint16 etherType,quint32 sec = 0,quint32 usec = 0); - bool ipcFromEthernetFrame(QFile &outputfile,QByteArray &record,int pos,quint16 etherType,quint32 sec = 0,quint32 usec = 0); - bool ipcFromPlpRaw(mdf_plpRaw_t *plpRaw, QFile &outputfile,QByteArray &record,quint32 sec = 0,quint32 usec = 0); + void setOutputfile(QFile *newOutputfile); - void writeDLTMessageToFile(QFile &outputfile,QByteArray &bufferHeader,char* bufferPayload,quint32 bufferPayloadSize,QString ecuId,quint32 sec = 0,quint32 usec = 0); + private: + + bool dltFrame(QByteArray &record,int pos,quint32 sec = 0,quint32 usec = 0); + bool dltFromEthernetFrame(QByteArray &record,int pos,quint16 etherType,quint32 sec = 0,quint32 usec = 0); + bool ipcFromEthernetFrame(QByteArray &record,int pos,quint16 etherType,quint32 sec = 0,quint32 usec = 0); + bool ipcFromPlpRaw(mdf_plpRaw_t *plpRaw, QByteArray &record,quint32 sec = 0,quint32 usec = 0); + + void writeDLTMessageToFile(QByteArray &bufferHeader,char* bufferPayload,quint32 bufferPayloadSize,QString ecuId,quint32 sec = 0,quint32 usec = 0); mdf_idblock_t mdfIdblock; mdf_hdblocklinks_t hdBlockLinks; @@ -189,9 +196,13 @@ class QDLT_EXPORT QDltImporter : public QObject QMap channelGroupLength; QMap channelGroupName; + QFile *outputfile; + QStringList fileNames; + signals: void progress(QString name,int status, int progress); + void resultReady(const QString &s); }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9af503d4..48450307 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -841,9 +841,11 @@ void MainWindow::initFileHandling() if(!QDltOptManager::getInstance()->getPcapFiles().isEmpty()) { qDebug() << "### Import PCAP files"; - QDltImporter importer; for ( const auto& filename : QDltOptManager::getInstance()->getPcapFiles() ) - importer.dltIpcFromPCAP(outputfile,filename,this,QDltOptManager::getInstance()->issilentMode()); + { + QDltImporter importer(&outputfile); + importer.dltIpcFromPCAP(filename); + } if(QDltOptManager::getInstance()->isCommandlineMode()) // if dlt viewer started as converter or with plugin option load file non multithreaded reloadLogFile(false,false); @@ -856,9 +858,11 @@ void MainWindow::initFileHandling() if(!QDltOptManager::getInstance()->getMf4Files().isEmpty()) { qDebug() << "### Import MF4 files"; - QDltImporter importer; for ( const auto& filename : QDltOptManager::getInstance()->getMf4Files() ) - importer.dltIpcFromMF4(outputfile,filename,this,QDltOptManager::getInstance()->issilentMode()); + { + QDltImporter importer(&outputfile); + importer.dltIpcFromMF4(filename); + } if(QDltOptManager::getInstance()->isCommandlineMode()) // if dlt viewer started as converter or with plugin option load file non multithreaded reloadLogFile(false,false); @@ -1126,7 +1130,6 @@ void MainWindow::on_action_menuFile_Open_triggered() /* change DLT file working directory */ workingDirectory.setDltDirectory(QFileInfo(fileNames[0]).absolutePath()); - QDltImporter importer; QStringList dltFileNames,pcapFileNames,mf4FileNames; for ( const auto& i : fileNames ) @@ -1146,24 +1149,22 @@ void MainWindow::on_action_menuFile_Open_triggered() else if(dltFileNames.isEmpty()&&!pcapFileNames.isEmpty()&&mf4FileNames.isEmpty()) { on_action_menuFile_Clear_triggered(); - for ( const auto& i : pcapFileNames ) - { - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromPCAP(outputfile,i,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - } - reloadLogFile(); + QDltImporter *importerThread = new QDltImporter(&outputfile,pcapFileNames); + connect(importerThread, &QDltImporter::progress, this, &MainWindow::progress); + connect(importerThread, &QDltImporter::resultReady, this, &MainWindow::handleImportResults); + connect(importerThread, &QDltImporter::finished, importerThread, &QObject::deleteLater); + statusProgressBar->show(); + importerThread->start(); } else if(dltFileNames.isEmpty()&&pcapFileNames.isEmpty()&&!mf4FileNames.isEmpty()) { on_action_menuFile_Clear_triggered(); - for ( const auto& i : mf4FileNames ) - { - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromMF4(outputfile,i,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - } - reloadLogFile(); + QDltImporter *importerThread = new QDltImporter(&outputfile,mf4FileNames); + connect(importerThread, &QDltImporter::progress, this, &MainWindow::progress); + connect(importerThread, &QDltImporter::resultReady, this, &MainWindow::handleImportResults); + connect(importerThread, &QDltImporter::finished, importerThread, &QObject::deleteLater); + statusProgressBar->show(); + importerThread->start(); } else { @@ -1505,27 +1506,25 @@ void MainWindow::on_actionAppend_triggered() /* change DLT file working directory */ workingDirectory.setDltDirectory(QFileInfo(fileNames[0]).absolutePath()); - QDltImporter importer; - + QStringList importFilenames; for ( const auto& i : fileNames ) { if(i.endsWith(".dlt",Qt::CaseInsensitive)) appendDltFile(i); else if(i.endsWith(".pcap",Qt::CaseInsensitive)) - { - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromPCAP(outputfile,i,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - } + importFilenames.append(i); else if(i.endsWith(".mf4",Qt::CaseInsensitive)) - { - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromMF4(outputfile,i,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - } + importFilenames.append(i); + } + if(!importFilenames.isEmpty()) + { + QDltImporter *importerThread = new QDltImporter(&outputfile,importFilenames); + connect(importerThread, &QDltImporter::progress, this, &MainWindow::progress); + connect(importerThread, &QDltImporter::resultReady, this, &MainWindow::handleImportResults); + connect(importerThread, &QDltImporter::finished, importerThread, &QObject::deleteLater); + statusProgressBar->show(); + importerThread->start(); } - - reloadLogFile(); } void MainWindow::mark_unmark_lines() @@ -1879,7 +1878,7 @@ void MainWindow::on_action_menuFile_Clear_triggered() openFileNames = QStringList(fn); isDltFileReadOnly = false; statusFilename->setMinimumWidth(statusFilename->width()); // just works to show default tmp file + location in status line - reloadLogFile(); + reloadLogFile(false,false); outputfile.close(); // open later again when writing } else @@ -7296,26 +7295,22 @@ void MainWindow::on_exploreView_customContextMenuRequested(QPoint pos) else if(dltFileNames.isEmpty()&&!pcapFileNames.isEmpty()&&mf4FileNames.isEmpty()&&dlfFileNames.isEmpty()) { on_action_menuFile_Clear_triggered(); - for ( const auto& i : pcapFileNames ) - { - QDltImporter importer; - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromPCAP(outputfile,i,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - } - reloadLogFile(); + QDltImporter *importerThread = new QDltImporter(&outputfile,pcapFileNames); + connect(importerThread, &QDltImporter::progress, this, &MainWindow::progress); + connect(importerThread, &QDltImporter::resultReady, this, &MainWindow::handleImportResults); + connect(importerThread, &QDltImporter::finished, importerThread, &QObject::deleteLater); + statusProgressBar->show(); + importerThread->start(); } else if(dltFileNames.isEmpty()&&pcapFileNames.isEmpty()&&!mf4FileNames.isEmpty()&&dlfFileNames.isEmpty()) { on_action_menuFile_Clear_triggered(); - for ( const auto& i : mf4FileNames ) - { - QDltImporter importer; - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromMF4(outputfile,i,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - } - reloadLogFile(); + QDltImporter *importerThread = new QDltImporter(&outputfile,mf4FileNames); + connect(importerThread, &QDltImporter::progress, this, &MainWindow::progress); + connect(importerThread, &QDltImporter::resultReady, this, &MainWindow::handleImportResults); + connect(importerThread, &QDltImporter::finished, importerThread, &QObject::deleteLater); + statusProgressBar->show(); + importerThread->start(); } else if(dltFileNames.isEmpty()&&pcapFileNames.isEmpty()&&mf4FileNames.isEmpty()&&!dlfFileNames.isEmpty()) { @@ -7345,7 +7340,7 @@ void MainWindow::on_exploreView_customContextMenuRequested(QPoint pos) connect(action, &QAction::triggered, this, [this, indexes](){ QStringList pathsList; auto selectedIndexes = indexes; - QDltImporter importer; + QStringList importFilenames; for (auto &index : selectedIndexes) { if (0 == index.column()) @@ -7354,22 +7349,22 @@ void MainWindow::on_exploreView_customContextMenuRequested(QPoint pos) if(i.endsWith(".dlt",Qt::CaseInsensitive)) appendDltFile(i); else if(i.endsWith(".pcap",Qt::CaseInsensitive)) - { - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromPCAP(outputfile,i,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - } + importFilenames.append(i); else if(i.endsWith(".mf4",Qt::CaseInsensitive)) - { - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromMF4(outputfile,i,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - } + importFilenames.append(i); else if(i.endsWith(".dlf",Qt::CaseInsensitive)) openDlfFile(i,false); } } - reloadLogFile(); + if(!importFilenames.isEmpty()) + { + QDltImporter *importerThread = new QDltImporter(&outputfile,importFilenames); + connect(importerThread, &QDltImporter::progress, this, &MainWindow::progress); + connect(importerThread, &QDltImporter::resultReady, this, &MainWindow::handleImportResults); + connect(importerThread, &QDltImporter::finished, importerThread, &QObject::deleteLater); + statusProgressBar->show(); + importerThread->start(); + } }); menu.addAction(action); @@ -7420,24 +7415,24 @@ void MainWindow::on_exploreView_customContextMenuRequested(QPoint pos) QStringList files; QDirIterator it_sh(path, QStringList() << "*.pcap" << "*.mf4", QDir::Files, QDirIterator::Subdirectories); - QDltImporter importer; + QStringList importFilenames; while (it_sh.hasNext()) { QString i = it_sh.next(); if (i.endsWith(".pcap",Qt::CaseInsensitive)) - { - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromPCAP(outputfile,i,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - } + importFilenames.append(i); else if (i.endsWith(".mf4",Qt::CaseInsensitive)) - { - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromMF4(outputfile,i,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - } + importFilenames.append(i); + } + if(!importFilenames.isEmpty()) + { + QDltImporter *importerThread = new QDltImporter(&outputfile,importFilenames); + connect(importerThread, &QDltImporter::progress, this, &MainWindow::progress); + connect(importerThread, &QDltImporter::resultReady, this, &MainWindow::handleImportResults); + connect(importerThread, &QDltImporter::finished, importerThread, &QObject::deleteLater); + statusProgressBar->show(); + importerThread->start(); } - reloadLogFile(); }); menu.addAction(action); @@ -7615,6 +7610,7 @@ void MainWindow::dropEvent(QDropEvent *event) if (event->mimeData()->hasUrls()) { + QStringList importFilenames; for(int num = 0;nummimeData()->urls().size();num++) { QUrl url = event->mimeData()->urls()[num]; @@ -7636,23 +7632,9 @@ void MainWindow::dropEvent(QDropEvent *event) openDlfFile(filename,true); } else if(filename.endsWith(".pcap", Qt::CaseInsensitive)) - { - /* Filter file dropped */ - QDltImporter importer; - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromPCAP(outputfile,filename,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - reloadLogFile(); - } + importFilenames.append(filename); else if(filename.endsWith(".mf4", Qt::CaseInsensitive)) - { - /* Filter file dropped */ - QDltImporter importer; - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromMF4(outputfile,filename,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - reloadLogFile(); - } + importFilenames.append(filename); else { /* ask for active decoder plugin to load configuration */ @@ -7711,6 +7693,15 @@ void MainWindow::dropEvent(QDropEvent *event) } } } + if(!importFilenames.isEmpty()) + { + QDltImporter *importerThread = new QDltImporter(&outputfile,importFilenames); + connect(importerThread, &QDltImporter::progress, this, &MainWindow::progress); + connect(importerThread, &QDltImporter::resultReady, this, &MainWindow::handleImportResults); + connect(importerThread, &QDltImporter::finished, importerThread, &QObject::deleteLater); + statusProgressBar->show(); + importerThread->start(); + } if(!filenames.isEmpty()) { /* DLT log file dropped */ @@ -8476,7 +8467,6 @@ void MainWindow::on_exploreView_activated(const QModelIndex &index) auto result = std::find_if(ext.begin(), ext.end(), [&path](const QString &el){return path.toLower().endsWith(el);}); - QDltImporter importer; switch(result - ext.begin()) { case 0: /* this represents index in "ext" list */ @@ -8490,16 +8480,24 @@ void MainWindow::on_exploreView_activated(const QModelIndex &index) openDlpFile(path); break; case 3: - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromPCAP(outputfile,path,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - reloadLogFile(); + { + QDltImporter *importerThread = new QDltImporter(&outputfile,path); + connect(importerThread, &QDltImporter::progress, this, &MainWindow::progress); + connect(importerThread, &QDltImporter::resultReady, this, &MainWindow::handleImportResults); + connect(importerThread, &QDltImporter::finished, importerThread, &QObject::deleteLater); + statusProgressBar->show(); + importerThread->start(); + } break; case 4: - connect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - importer.dltIpcFromMF4(outputfile,path,this,false); - disconnect(&importer,SIGNAL(progress(QString,int,int)),this,SLOT(progress(QString,int,int))); - reloadLogFile(); + { + QDltImporter *importerThread = new QDltImporter(&outputfile,path); + connect(importerThread, &QDltImporter::progress, this, &MainWindow::progress); + connect(importerThread, &QDltImporter::resultReady, this, &MainWindow::handleImportResults); + connect(importerThread, &QDltImporter::finished, importerThread, &QObject::deleteLater); + statusProgressBar->show(); + importerThread->start(); + } break; default: break; @@ -8554,3 +8552,8 @@ void MainWindow::on_lineEditFilterEnd_textChanged(const QString &arg1) applyConfigEnabled(true); } +void MainWindow::handleImportResults(const QString &) +{ + statusProgressBar->hide(); + reloadLogFile(); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index a6121bb4..a10b83f8 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -609,6 +609,8 @@ public slots: void onAddActionToHistory(); void onSearchProgressChanged(bool isInProgress); + void handleImportResults(const QString &); + public: /* Project configuration containing ECU/APP/Context/Filter/Plugin configuration */