Cleanup remove system for background tasks we were not using anymore.
This commit is contained in:
parent
04e69bbaa4
commit
50bf4588ce
7 changed files with 0 additions and 133 deletions
|
|
@ -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
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -46,10 +46,6 @@ HEADERS += PasswordManager.h \
|
||||||
Expected.h \
|
Expected.h \
|
||||||
ExplainTreeModelItem.h \
|
ExplainTreeModelItem.h \
|
||||||
json/json.h \
|
json/json.h \
|
||||||
TaskControl.h \
|
|
||||||
ControllableTask.h \
|
|
||||||
RunControllableTask.h \
|
|
||||||
TaskExecutor.h \
|
|
||||||
SqlParser.h \
|
SqlParser.h \
|
||||||
SqlAstNode.h \
|
SqlAstNode.h \
|
||||||
SqlAstSelectList.h \
|
SqlAstSelectList.h \
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
#include "catalog/PgDatabaseCatalog.h"
|
#include "catalog/PgDatabaseCatalog.h"
|
||||||
#include "ConnectionController.h"
|
#include "ConnectionController.h"
|
||||||
#include "MasterController.h"
|
#include "MasterController.h"
|
||||||
#include "TaskExecutor.h"
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include "CatalogInspector.h"
|
#include "CatalogInspector.h"
|
||||||
#include "OpenDatabase.h"
|
#include "OpenDatabase.h"
|
||||||
#include "Pgsql_Connection.h"
|
#include "Pgsql_Connection.h"
|
||||||
#include "ControllableTask.h"
|
|
||||||
#include "IDatabaseWindow.h"
|
#include "IDatabaseWindow.h"
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue