TaskAdapter Class

template <typename Task, typename Deleter = std::default_delete<Task>> class Tasking::TaskAdapter

A class template for implementing custom task adapters. More...

Header: #include <solutions/tasking/tasktree.h>
Inherits: Tasking::TaskInterface

Note: All functions in this class are reentrant.

Protected Functions

Task *task()
const Task *task() const

Detailed Description

The TaskAdapter class template is responsible for creating a task of the Task type, starting it, and reporting success or an error when the task is finished. It also associates the adapter with a given Task type.

Reimplement this class with the actual Task type to adapt the task's interface into the general TaskTree's interface for managing the Task instances.

Each subclass needs to provide a public default constructor, implement the start() method, and emit the done() signal when the task is finished. Use task() to access the associated 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:

// Defines actual worker
class Worker {...};

// Adapts Worker's interface to work with task tree
class WorkerTaskAdapter : public TaskAdapter<Worker> {...};

// Defines WorkerTask as a new custom task type to be placed inside Group items
using WorkerTask = CustomTask<WorkerTaskAdapter>;

Optionally, you may pass a custom Deleter for the associated Task as a second template parameter of your TaskAdapter subclass. When the Deleter parameter is omitted, the std::default_delete<Task> is used by default. The custom Deleter is useful when the destructor of the running Task may potentially block the caller thread. Instead of blocking, the custom deleter may move the running task into a separate thread and implement the blocking destruction there. In this way, the fast destruction (seen from the caller thread) of the running task with a blocking destructor may be achieved.

For more information on implementing the custom task adapters, refer to Task Adapters.

See also start(), done(), and task().

Member Function Documentation

[protected] TaskAdapter::TaskAdapter()

Creates a task adapter for the given Task type.

Internally, it creates an instance of Task, which is accessible via the task() method. The optionally provided Deleter is used instead of the Task destructor. When Deleter is omitted, the std::default_delete<Task> is used by default.

See also task().

[protected] Task *TaskAdapter::task()

Returns the pointer to the associated Task instance.

[protected] const Task *TaskAdapter::task() const

This is an overloaded function.

Returns the const pointer to the associated Task instance.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.