diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 778d6285..df04012b 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -6,6 +6,7 @@ #include "utils/TempConfig.h" #include "utils/Configuration.h" +#include "utils/AsyncTask.h" #include "Cutter.h" #include "sdb.h" @@ -71,6 +72,8 @@ CutterCore::CutterCore(QObject *parent) : # endif setConfig("dir.prefix", prefix.absolutePath()); #endif + + asyncTaskManager = new AsyncTaskManager(this); } diff --git a/src/Cutter.h b/src/Cutter.h index 48793c1e..163f2fd9 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -44,6 +44,8 @@ typedef ut64 RVA; */ #define RVA_INVALID RVA_MAX +class AsyncTaskManager; + class RCoreLocked { RCore *core; @@ -528,6 +530,7 @@ private: QString notes; RCore *core_; + AsyncTaskManager *asyncTaskManager; }; class ccClass : public CutterCore diff --git a/src/Cutter.pro b/src/Cutter.pro index 764075dd..cd81399b 100644 --- a/src/Cutter.pro +++ b/src/Cutter.pro @@ -160,7 +160,8 @@ SOURCES += \ utils/JsonTreeItem.cpp \ utils/JsonModel.cpp \ dialogs/VersionInfoDialog.cpp \ - widgets/ZignaturesWidget.cpp + widgets/ZignaturesWidget.cpp \ + utils/AsyncTask.cpp HEADERS += \ Cutter.h \ @@ -235,7 +236,8 @@ HEADERS += \ utils/JsonTreeItem.h \ utils/JsonModel.h \ dialogs/VersionInfoDialog.h \ - widgets/ZignaturesWidget.h + widgets/ZignaturesWidget.h \ + utils/AsyncTask.h FORMS += \ dialogs/AboutDialog.ui \ diff --git a/src/utils/AsyncTask.cpp b/src/utils/AsyncTask.cpp new file mode 100644 index 00000000..f54dd80a --- /dev/null +++ b/src/utils/AsyncTask.cpp @@ -0,0 +1,23 @@ + +#include "AsyncTask.h" + +void AsyncTask::run() +{ + runTask(); + emit finished(); +} + +AsyncTaskManager::AsyncTaskManager(QObject *parent) + : QObject(parent) +{ + threadPool = new QThreadPool(this); +} + +AsyncTaskManager::~AsyncTaskManager() +{ +} + +void AsyncTaskManager::start(AsyncTask *task) +{ + threadPool->start(task); +} diff --git a/src/utils/AsyncTask.h b/src/utils/AsyncTask.h new file mode 100644 index 00000000..700f663f --- /dev/null +++ b/src/utils/AsyncTask.h @@ -0,0 +1,37 @@ + +#ifndef ASYNCTASK_H +#define ASYNCTASK_H + +#include +#include + +class AsyncTask : public QObject, public QRunnable +{ + Q_OBJECT + +public: + void run() override final; + + virtual void runTask() =0; + +signals: + void finished(); +}; + + +class AsyncTaskManager : public QObject +{ + Q_OBJECT + +private: + QThreadPool *threadPool; + +public: + explicit AsyncTaskManager(QObject *parent = nullptr); + ~AsyncTaskManager(); + + void start(AsyncTask *task); +}; + + +#endif //ASYNCTASK_H \ No newline at end of file