mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-04-30 22:54:38 +02:00
add documentation for Task and ConcurrentTask
This commit is contained in:
parent
7d2da19418
commit
ca6d66970e
@ -43,6 +43,10 @@
|
|||||||
|
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Runs a list of tasks concurrently (according to `max_concurrent` parameter).
|
||||||
|
* Behaviour is the same as regular Task (e.g. starts using start())
|
||||||
|
*/
|
||||||
class ConcurrentTask : public Task {
|
class ConcurrentTask : public Task {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@ -59,6 +63,7 @@ class ConcurrentTask : public Task {
|
|||||||
inline auto isMultiStep() const -> bool override { return totalSize() > 1; }
|
inline auto isMultiStep() const -> bool override { return totalSize() > 1; }
|
||||||
auto getStepProgress() const -> TaskStepProgressList override;
|
auto getStepProgress() const -> TaskStepProgressList override;
|
||||||
|
|
||||||
|
//! Adds a task to execute in this ConcurrentTask
|
||||||
void addTask(Task::Ptr task);
|
void addTask(Task::Ptr task);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -79,6 +79,13 @@ Q_DECLARE_METATYPE(TaskStepProgress)
|
|||||||
|
|
||||||
using TaskStepProgressList = QList<std::shared_ptr<TaskStepProgress>>;
|
using TaskStepProgressList = QList<std::shared_ptr<TaskStepProgress>>;
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Represents a task that has to be done.
|
||||||
|
* To create a task, you need to subclass this class, implement the executeTask() method and call
|
||||||
|
* emitSucceeded() or emitFailed() when the task is done.
|
||||||
|
* the caller needs to call start() to start the task.
|
||||||
|
*/
|
||||||
class Task : public QObject, public QRunnable {
|
class Task : public QObject, public QRunnable {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@ -130,9 +137,10 @@ class Task : public QObject, public QRunnable {
|
|||||||
signals:
|
signals:
|
||||||
void started();
|
void started();
|
||||||
void progress(qint64 current, qint64 total);
|
void progress(qint64 current, qint64 total);
|
||||||
|
//! called when a task has eother succeeded, aborted or failed.
|
||||||
void finished();
|
void finished();
|
||||||
void succeeded();
|
void succeeded(); // called when a task has succeeded
|
||||||
void aborted();
|
void aborted(); // called when a task has been aborted by calling abort()
|
||||||
void failed(QString reason);
|
void failed(QString reason);
|
||||||
void status(QString status);
|
void status(QString status);
|
||||||
void details(QString details);
|
void details(QString details);
|
||||||
@ -146,6 +154,7 @@ class Task : public QObject, public QRunnable {
|
|||||||
// QRunnable's interface
|
// QRunnable's interface
|
||||||
void run() override { start(); }
|
void run() override { start(); }
|
||||||
|
|
||||||
|
// used by the task caller to start the task
|
||||||
virtual void start();
|
virtual void start();
|
||||||
virtual bool abort()
|
virtual bool abort()
|
||||||
{
|
{
|
||||||
@ -161,11 +170,17 @@ class Task : public QObject, public QRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/*!
|
||||||
|
* The task subclass must implement this method. This method is called to start to run the task.
|
||||||
|
* The task is not finished when this method returns. the subclass must manually call emitSucceeded() or emitFailed() instead.
|
||||||
|
*/
|
||||||
virtual void executeTask() = 0;
|
virtual void executeTask() = 0;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
|
//! The Task subclass must call this method when the task has succeeded
|
||||||
virtual void emitSucceeded();
|
virtual void emitSucceeded();
|
||||||
virtual void emitAborted();
|
virtual void emitAborted();
|
||||||
|
//! The Task subclass must call this method when the task has failed
|
||||||
virtual void emitFailed(QString reason = "");
|
virtual void emitFailed(QString reason = "");
|
||||||
|
|
||||||
virtual void propagateStepProgress(TaskStepProgress const& task_progress);
|
virtual void propagateStepProgress(TaskStepProgress const& task_progress);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user