Kanzi 4.1.0
kanzi::TaskDispatcher Class Reference

Task dispatcher. More...

#include <kanzi/core.ui/task_dispatcher/task_dispatcher.hpp>

Public Types

using Task
 Task is a callback that is dispatched by TaskDispatcher and executed on a specific UI thread.
 

Public Member Functions

void cleanUpTasks ()
 Clean up tasks until no tasks remain.
 
size_t executeTasks ()
 Executes the tasks that have been dispatched to the UI thread.
 
NativeEventHandle getNativeEventHandle ()
 Returns the native handle that can be used to wait for available tasks.
 
KZ_NO_DISCARD bool isEmpty () const
 Indicates whether the task dispatcher does not contain pending tasks.
 
KZ_NO_DISCARD bool isQuitting () const
 Indicates whether the task dispatcher is quitting.
 
void notifyTasksAvailable ()
 Notifies this class that tasks are available.
 
void notifyTasksConsumed ()
 Notifies this class that tasks have been consumed.
 
TaskDispatcheroperator= (const TaskDispatcher &)=delete
 Copy assignment operator.
 
TaskDispatcheroperator= (TaskDispatcher &&) noexcept=delete
 Move assignment operator.
 
void setDomain (Domain *domain)
 Setter for domain.
 
void setQuitting (bool flag)
 Set the quitting flag state.
 
void submit (Task task)
 Submits a task for execution in the UI thread.
 
 TaskDispatcher ()
 Constructor.
 
 TaskDispatcher (const TaskDispatcher &)=delete
 Copy constructor.
 
 TaskDispatcher (TaskDispatcher &&) noexcept=delete
 Move constructor.
 
 ~TaskDispatcher ()
 Destructor.
 

Detailed Description

Task dispatcher.

You can use TaskDispatcher to schedule execution of callbacks to the UI thread. You can access Kanzi UI objects only on the thread that you create them on. You can wrap code that accesses UI objects with tasks and submit them from any thread to the TaskDispatcher. The UI thread will execute these tasks during its main loop.

Since
Kanzi 4.1.0 Merged TaskDispatcherBase and moved to this header file.

Member Typedef Documentation

◆ Task

Task is a callback that is dispatched by TaskDispatcher and executed on a specific UI thread.

Constructor & Destructor Documentation

◆ TaskDispatcher() [1/3]

kanzi::TaskDispatcher::TaskDispatcher ( )
explicit

Constructor.

◆ ~TaskDispatcher()

kanzi::TaskDispatcher::~TaskDispatcher ( )

Destructor.

◆ TaskDispatcher() [2/3]

kanzi::TaskDispatcher::TaskDispatcher ( const TaskDispatcher & )
delete

Copy constructor.

◆ TaskDispatcher() [3/3]

kanzi::TaskDispatcher::TaskDispatcher ( TaskDispatcher && )
deletenoexcept

Move constructor.

Member Function Documentation

◆ operator=() [1/2]

TaskDispatcher & kanzi::TaskDispatcher::operator= ( const TaskDispatcher & )
delete

Copy assignment operator.

◆ operator=() [2/2]

TaskDispatcher & kanzi::TaskDispatcher::operator= ( TaskDispatcher && )
deletenoexcept

Move assignment operator.

◆ submit()

void kanzi::TaskDispatcher::submit ( Task task)

Submits a task for execution in the UI thread.

The task will be dispatched to and executed on the UI thread that this task dispatcher belongs to. All submitted tasks are executed sequentially in the order that they were received. You can call this function from any thread. Tasks may submit new tasks during their execution. Tasks submitted by executing tasks are queued for execution during the next frame. This means that tasks may safely submit themselves without risk for infinite loops.

◆ executeTasks()

size_t kanzi::TaskDispatcher::executeTasks ( )

Executes the tasks that have been dispatched to the UI thread.

Tasks will be removed from the task queue after execution. New tasks submitted during the execution will be queued for execution by the next call to this function. Kanzi calls this function automatically. Custom code may not attempt to call this function. This function can only be called from the UI thread that this dispatcher belongs to. No guarantee of exception safety; both the function itself and the tasks it executes may throw exceptions. Calling this function from a thread other than the one this dispatcher belongs to will throw a logic_error exception. Calling this function while it is still executing tasks will throw a logic_error exception.

Returns
Number of tasks that were executed.

◆ cleanUpTasks()

void kanzi::TaskDispatcher::cleanUpTasks ( )

Clean up tasks until no tasks remain.

Sets the quitting flag, that the tasks can use to check if new tasks should be posted.

◆ isEmpty()

KZ_NO_DISCARD bool kanzi::TaskDispatcher::isEmpty ( ) const

Indicates whether the task dispatcher does not contain pending tasks.

◆ notifyTasksAvailable()

void kanzi::TaskDispatcher::notifyTasksAvailable ( )

Notifies this class that tasks are available.

This is an internal function.

◆ notifyTasksConsumed()

void kanzi::TaskDispatcher::notifyTasksConsumed ( )

Notifies this class that tasks have been consumed.

This is an internal function.

◆ setDomain()

void kanzi::TaskDispatcher::setDomain ( Domain * domain)

Setter for domain.

Parameters
domainPointer to domain

◆ isQuitting()

KZ_NO_DISCARD bool kanzi::TaskDispatcher::isQuitting ( ) const

Indicates whether the task dispatcher is quitting.

This flag is set before the emptying of the task queue begins.

Returns
True if quitting, false if not.

◆ setQuitting()

void kanzi::TaskDispatcher::setQuitting ( bool flag)

Set the quitting flag state.

Called by the system before emptying the task dispatcher.

Parameters
flagNew quitting flag state.

◆ getNativeEventHandle()

NativeEventHandle kanzi::TaskDispatcher::getNativeEventHandle ( )

Returns the native handle that can be used to wait for available tasks.

This is an internal function.


The documentation for this class was generated from the following file: