From 564b5ddae8102b41aa13f04f85678f21c2e1a76e Mon Sep 17 00:00:00 2001 From: Albert S Date: Thu, 14 Apr 2022 14:58:07 +0200 Subject: [PATCH] shared: Begin FileScanWorker --- shared/filescanworker.cpp | 29 +++++++++++++++++++++++++++++ shared/filescanworker.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 shared/filescanworker.cpp create mode 100644 shared/filescanworker.h diff --git a/shared/filescanworker.cpp b/shared/filescanworker.cpp new file mode 100644 index 0000000..a4fb25d --- /dev/null +++ b/shared/filescanworker.cpp @@ -0,0 +1,29 @@ +#include "filescanworker.h" +#include "logger.h" +FileScanWorker::FileScanWorker(SqliteDbService &db, ConcurrentQueue &queue, int batchsize) +{ + this->dbService = &db; + this->queue = &queue; + this->batchsize = batchsize; +} + +void FileScanWorker::run() +{ + FileSaver saver{*this->dbService}; + auto paths = queue->dequeue(batchsize); + for(QString &path : paths) + { + SaveFileResult sfr; + try + { + sfr = saver.addFile(path); + } + catch(std::runtime_error &e) + { + Logger::error() << e.what(); + sfr = PROCESSFAIL; // well... + } + emit result({path, sfr}); + } + emit finished(); +} diff --git a/shared/filescanworker.h b/shared/filescanworker.h new file mode 100644 index 0000000..58ec691 --- /dev/null +++ b/shared/filescanworker.h @@ -0,0 +1,28 @@ +#ifndef FILESCANWORKER_H +#define FILESCANWORKER_H +#include +#include +#include +#include +#include "paralleldirscanner.h" +#include "filesaver.h" + +typedef std::pair FileScanResult; + +class FileScanWorker : public QObject, public QRunnable +{ + Q_OBJECT + protected: + SqliteDbService *dbService; + ConcurrentQueue *queue; + int batchsize; + + public: + FileScanWorker(SqliteDbService &db, ConcurrentQueue &queue, int batchsize); + void run() override; + signals: + void result(FileScanResult); + void finished(); +}; + +#endif // FILESCANWORKER_H