Cleanup remove system for background tasks we were not using anymore.

This commit is contained in:
eelke 2022-01-16 18:51:43 +01:00
parent 04e69bbaa4
commit 50bf4588ce
7 changed files with 0 additions and 133 deletions

View file

@ -1,20 +0,0 @@
#ifndef CONTROLLABLETASK_H
#define CONTROLLABLETASK_H
/** From answer by Hatter
*
* https://stackoverflow.com/questions/5423058/qfuture-that-can-be-cancelled-and-report-progress
*/
//#include "TaskControl.h"
class TaskControl;
template <class T>
class ControllableTask
{
public:
using Result = T;
virtual ~ControllableTask() {}
virtual Result run(TaskControl& control) = 0;
};
#endif // CONTROLLABLETASK_H

View file

@ -1,57 +0,0 @@
#ifndef RUNCONTROLLABLETASK_H
#define RUNCONTROLLABLETASK_H
/** From answer by Hatter
*
* https://stackoverflow.com/questions/5423058/qfuture-that-can-be-cancelled-and-report-progress
*/
#include <QFutureInterface>
#include <QRunnable>
#include <QThreadPool>
#include "ControllableTask.h"
#include "TaskControl.h"
template <typename T>
class RunControllableTask : public QFutureInterface<T> , public QRunnable
{
public:
RunControllableTask(ControllableTask<T>* tsk) : task(tsk) { }
virtual ~RunControllableTask() { delete task; }
QFuture<T> start()
{
this->setRunnable(this);
this->reportStarted();
QFuture<T> future = this->future();
QThreadPool::globalInstance()->start(this, /*m_priority*/ 0);
return future;
}
void run()
{
if (this->isCanceled()) {
this->reportFinished();
return;
}
TaskControl control(this);
try {
result = this->task->run(control);
if (!this->isCanceled()) {
this->reportResult(result);
}
} catch (QException &e) {
QFutureInterfaceBase::reportException(e);
} catch (...) {
QUnhandledException ex;
QFutureInterfaceBase::reportException(ex);
}
this->reportFinished();
}
private:
T result;
ControllableTask<T> *task;
};
#endif // RUNCONTROLLABLETASK_H

View file

@ -1,18 +0,0 @@
#ifndef TASKCONTROL_H
#define TASKCONTROL_H
/** From answer by Hatter
*
* https://stackoverflow.com/questions/5423058/qfuture-that-can-be-cancelled-and-report-progress
*/
#include <QFutureInterfaceBase>
class TaskControl {
public:
TaskControl(QFutureInterfaceBase *f) : fu(f) { }
bool shouldRun() const { return !fu->isCanceled(); }
private:
QFutureInterfaceBase *fu;
};
#endif // TASKCONTROL_H

View file

@ -1,32 +0,0 @@
#ifndef TASKEXECUTOR_H
#define TASKEXECUTOR_H
/* From answer by Hatter
*
* https://stackoverflow.com/questions/5423058/qfuture-that-can-be-cancelled-and-report-progress
*/
#include "ControllableTask.h"
#include "RunControllableTask.h"
#include <QFuture>
/**
* @brief The TaskExecutor class
*
* The user should sublass ControllableTask, implement background routine which checks sometimes
* method shouldRun() of TaskControl instance passed to run(TaskControl&) and then use it like:
*
* QFututre<int> futureValue = TaskExecutor::run(new SomeControllableTask(inputForThatTask));
*
* Then she may cancel it by calling futureValue.cancel(), bearing in mind that cancellation is
* graceful and not immediate.
*
*/
class TaskExecutor {
public:
template <class T>
static QFuture<T> run(ControllableTask<T>* task) {
return (new RunControllableTask<T>(task))->start();
}
};
#endif // TASKEXECUTOR_H

View file

@ -46,10 +46,6 @@ HEADERS += PasswordManager.h \
Expected.h \
ExplainTreeModelItem.h \
json/json.h \
TaskControl.h \
ControllableTask.h \
RunControllableTask.h \
TaskExecutor.h \
SqlParser.h \
SqlAstNode.h \
SqlAstSelectList.h \

View file

@ -6,7 +6,6 @@
#include "catalog/PgDatabaseCatalog.h"
#include "ConnectionController.h"
#include "MasterController.h"
#include "TaskExecutor.h"
#include <QAction>
#include <QApplication>
#include <QtConcurrent>

View file

@ -5,7 +5,6 @@
#include "CatalogInspector.h"
#include "OpenDatabase.h"
#include "Pgsql_Connection.h"
#include "ControllableTask.h"
#include "IDatabaseWindow.h"
#include <QMainWindow>
#include <memory>