TaskTree: Adapt docs to the recent changes

The registration macros got removed recently.

Change-Id: I69fe5a898d6d975b66a79e64e5e9425960745772
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
Jarek Kobus
2023-08-18 07:48:34 +02:00
parent 8277e2f7d9
commit bb59dfd636

View File

@@ -105,6 +105,19 @@ private:
implement the start() method, and emit the done() signal when the task is finished. implement the start() method, and emit the done() signal when the task is finished.
Use task() to access the associated \c Task instance. Use task() to access the associated \c Task instance.
To use your task adapter inside the task tree, create an alias to the
Tasking::CustomTask template passing your task adapter as a template parameter:
\code
// Defines actual worker
class Worker {...};
// Adapts Worker's interface to work with task tree
class WorkerTaskAdapter : public TaskAdapter<Worker> {...};
// Defines WorkerTask as a new task tree element
using WorkerTask = CustomTask<WorkerTaskAdapter>;
\endcode
For more information on implementing the custom task adapters, refer to \l {Task Adapters}. For more information on implementing the custom task adapters, refer to \l {Task Adapters}.
\sa start(), done(), task() \sa start(), done(), task()
@@ -333,8 +346,8 @@ private:
The CustomTask class template is used inside TaskTree for describing custom task items. The CustomTask class template is used inside TaskTree for describing custom task items.
Custom task names are aliased with unique names inside the \l Tasking namespace Custom task names are aliased with unique names using the CustomTask template
via the TASKING_DECLARE_TASK or TASKING_DECLARE_TEMPLATE_TASK macros. with a given TaskAdapter subclass as a template parameter.
For example, \c ConcurrentCallTask<T> is an alias to the CustomTask that is defined For example, \c ConcurrentCallTask<T> is an alias to the CustomTask that is defined
to work with \c ConcurrentCall<T> as an associated task class. to work with \c ConcurrentCall<T> as an associated task class.
The following table contains all the built-in tasks and their associated task classes: The following table contains all the built-in tasks and their associated task classes:
@@ -501,26 +514,6 @@ private:
\sa onSetup() \sa onSetup()
*/ */
/*!
\macro TASKING_DECLARE_TASK(CustomTaskName, TaskAdapterClass)
\relates Tasking
Registers the new custom task type under a \a CustomTaskName name inside the
Tasking namespace for the passed \a TaskAdapterClass adapter class.
For more information on implementing the custom task adapters, refer to \l {Task Adapters}.
*/
/*!
\macro TASKING_DECLARE_TEMPLATE_TASK(CustomTaskName, TaskAdapterClass)
\relates Tasking
Registers the new custom task template type under a \a CustomTaskName name inside the
Tasking namespace for the passed \a TaskAdapterClass adapter class template.
For more information on implementing the custom task adapters, refer to \l {Task Adapters}.
*/
/*! /*!
\enum Tasking::WorkflowPolicy \enum Tasking::WorkflowPolicy
@@ -2156,10 +2149,10 @@ void TaskNode::invokeEndHandler(bool success)
asynchronous task: asynchronous task:
\code \code
class TimeoutTaskAdapter : public Tasking::TaskAdapter<QTimer> class TimerTaskAdapter : public TaskAdapter<QTimer>
{ {
public: public:
TimeoutTaskAdapter() { TimerTaskAdapter() {
task()->setSingleShot(true); task()->setSingleShot(true);
task()->setInterval(1000); task()->setInterval(1000);
connect(task(), &QTimer::timeout, this, [this] { emit done(true); }); connect(task(), &QTimer::timeout, this, [this] { emit done(true); });
@@ -2168,7 +2161,7 @@ void TaskNode::invokeEndHandler(bool success)
void start() final { task()->start(); } void start() final { task()->start(); }
}; };
TASKING_DECLARE_TASK(TimeoutTask, TimeoutTaskAdapter); using TimerTask = CustomTask<TimerTaskAdapter>;
\endcode \endcode
You must derive the custom adapter from the TaskAdapter class template You must derive the custom adapter from the TaskAdapter class template
@@ -2177,28 +2170,27 @@ void TaskNode::invokeEndHandler(bool success)
later as an argument to the task's handlers. The instance of this class later as an argument to the task's handlers. The instance of this class
parameter automatically becomes a member of the TaskAdapter template, and is parameter automatically becomes a member of the TaskAdapter template, and is
accessible through the TaskAdapter::task() method. The constructor accessible through the TaskAdapter::task() method. The constructor
of TimeoutTaskAdapter initially configures the QTimer object and connects of TimerTaskAdapter initially configures the QTimer object and connects
to the QTimer::timeout signal. When the signal is triggered, TimeoutTaskAdapter to the QTimer::timeout signal. When the signal is triggered, TimerTaskAdapter
emits the \c done(true) signal to inform the task tree that the task finished emits the \c done(true) signal to inform the task tree that the task finished
successfully. If it emits \c done(false), the task finished with an error. successfully. If it emits \c done(false), the task finished with an error.
The TaskAdapter::start() method starts the timer. The TaskAdapter::start() method starts the timer.
To make QTimer accessible inside TaskTree under the \e TimeoutTask name, To make QTimer accessible inside TaskTree under the \e TimerTask name,
register it with TASKING_DECLARE_TASK(TimeoutTask, TimeoutTaskAdapter). define TimerTask to be an alias to the Tasking::CustomTask<TimerTaskAdapter>.
TimeoutTask becomes a new task type inside Tasking namespace, using TimeoutTaskAdapter. TimerTask becomes a new task type, using TimerTaskAdapter.
The new task type is now registered, and you can use it in TaskTree: The new task type is now registered, and you can use it in TaskTree:
\code \code
const auto onTimeoutSetup = [](QTimer &task) { const auto onTimerSetup = [](QTimer &task) {
task.setInterval(2000); task.setInterval(2000);
}; };
const auto onTimeoutDone = [](const QTimer &task) { const auto onTimerDone = [](const QTimer &task) {
qDebug() << "timeout triggered"; qDebug() << "timer triggered";
}; };
const Group root { const Group root {
TimeoutTask(onTimeoutSetup, onTimeoutDone) TimerTask(onTimerSetup, onTimerDone)
}; };
\endcode \endcode