MeVisLab Toolbox Reference
ml::BackgroundTaskManager Class Reference

The BackgroundTaskManager is the central singleton that manages running background tasks. More...

#include <mlBackgroundTaskManager.h>

Classes

class  Observer
 Abstract interface to observe the BackgroundTaskManager. More...

Public Member Functions

BackgroundTaskHandle runTask (BackgroundTask *task)
int totalTaskCount ()
void getStatusInformation (std::vector< BackgroundTaskStatusInformation > &infos)
 Gets a snapshot of the state of all background tasks, representing the consistent status at the time of calling this function.
void sendMessageToGUI (BackgroundTaskMessage *message)
void sendMessageToTask (BackgroundTask *task, BackgroundTaskMessage *message)
bool hasSynchronousTask () const
 Returns true if the manager is currently processing a synchronous task.
bool processPendingMessages ()
void cancelPendingRequestsForTask (BackgroundTask *task)
 Cancels pending requests for a given task.
void removeMessagesForReceiver (BackgroundTaskMessageReceiver *receiver)
 Removes all messages for receiver from the GUI message queue.
void addObserver (Observer *observer)
 Adds an observer (the ownership stays with the caller).
void removeObserver (Observer *observer)
 Removes an observer (the ownership stays with the caller).
PageRequestProcessorgetPageRequestProcessor ()
 Returns instance of the page request processor (TODO: this will probably move into the ML host!).
void setBackgroundTaskScheduleProcessPendingMessagesCB (BackgroundTaskScheduleProcessPendingMessagesCB *cb, void *userData)
void getBackgroundTaskScheduleProcessPendingMessagesCB (BackgroundTaskScheduleProcessPendingMessagesCB **cb, void **userData)
 Gets the currently set callback.
bool supportsAsynchronousTasks ()

Static Public Member Functions

static BackgroundTaskManager & self ()
 Returns the global singleton.
static void init ()
 Initializes the background task manager.
static void cleanup ()
 Cleans up the background task manager.
static bool ensureGUIThread ()
 Returns true if the current thread is the GUI thread.
static bool ensureWorkerThread ()

Protected Member Functions

MLuint32 getUniqueTaskId ()
void sendTaskAdded (BackgroundTask *task)
 Sends a task that is added to the observers.
void sendTaskRemoved (BackgroundTask *task)
 Sends a task that is removed from the observers.
void sendTaskStatusUpdated ()
 Sends that a task's status is updated to the observers.
void removeTaskFromQueueAndSendTaskFinished (BackgroundTask *task)
 Removes a task if it was queued.
BackgroundTaskwaitForTask ()
 Waits for a new task and returns the new task from the queue.
void sendTaskFinishedMessage (BackgroundTask *task)
 Called by worker threads when a task is finished.

Friends

struct BackgroundTaskManagerWorkerFunc
class BackgroundTaskFinishedMessage
class BackgroundTask
class BackgroundTaskManagerPrivate

Detailed Description

The BackgroundTaskManager is the central singleton that manages running background tasks.

Definition at line 53 of file mlBackgroundTaskManager.h.

Member Function Documentation

◆ addObserver()

void ml::BackgroundTaskManager::addObserver ( Observer * observer)

Adds an observer (the ownership stays with the caller).

◆ cancelPendingRequestsForTask()

void ml::BackgroundTaskManager::cancelPendingRequestsForTask ( BackgroundTask * task)

Cancels pending requests for a given task.

References BackgroundTask.

◆ cleanup()

void ml::BackgroundTaskManager::cleanup ( )
static

Cleans up the background task manager.

◆ ensureGUIThread()

bool ml::BackgroundTaskManager::ensureGUIThread ( )
static

Returns true if the current thread is the GUI thread.

Referenced by ml::UnprotectedMainThreadCommunicator::call().

◆ ensureWorkerThread()

bool ml::BackgroundTaskManager::ensureWorkerThread ( )
static

Returns true if the current thread is not the GUI thread and is thus a worker thread. Note: in synchronous mode, this will always return true. Do not use it to decide on the code path; use ensureGUIThread instead.

◆ getBackgroundTaskScheduleProcessPendingMessagesCB()

void ml::BackgroundTaskManager::getBackgroundTaskScheduleProcessPendingMessagesCB ( BackgroundTaskScheduleProcessPendingMessagesCB ** cb,
void ** userData )

Gets the currently set callback.

◆ getPageRequestProcessor()

PageRequestProcessor & ml::BackgroundTaskManager::getPageRequestProcessor ( )

Returns instance of the page request processor (TODO: this will probably move into the ML host!).

◆ getStatusInformation()

void ml::BackgroundTaskManager::getStatusInformation ( std::vector< BackgroundTaskStatusInformation > & infos)

Gets a snapshot of the state of all background tasks, representing the consistent status at the time of calling this function.

◆ getUniqueTaskId()

MLuint32 ml::BackgroundTaskManager::getUniqueTaskId ( )
protected

Returns new unique id of a task. This is thread-safe.

◆ hasSynchronousTask()

bool ml::BackgroundTaskManager::hasSynchronousTask ( ) const
inline

Returns true if the manager is currently processing a synchronous task.

Definition at line 96 of file mlBackgroundTaskManager.h.

◆ init()

void ml::BackgroundTaskManager::init ( )
static

Initializes the background task manager.

◆ processPendingMessages()

bool ml::BackgroundTaskManager::processPendingMessages ( )

Processes all pending messages (will not block and may only be called from the GUI thread, typically from an idle timer). Returns whether more work is available.

◆ removeMessagesForReceiver()

void ml::BackgroundTaskManager::removeMessagesForReceiver ( BackgroundTaskMessageReceiver * receiver)

Removes all messages for receiver from the GUI message queue.

◆ removeObserver()

void ml::BackgroundTaskManager::removeObserver ( Observer * observer)

Removes an observer (the ownership stays with the caller).

◆ removeTaskFromQueueAndSendTaskFinished()

void ml::BackgroundTaskManager::removeTaskFromQueueAndSendTaskFinished ( BackgroundTask * task)
protected

Removes a task if it was queued.

References BackgroundTask.

◆ runTask()

BackgroundTaskHandle ml::BackgroundTaskManager::runTask ( BackgroundTask * task)

Runs the given task. The ownership of the task is transfered to the task manager. Do not delete the task yourself! Only call this from the GUI thread!

References BackgroundTask.

◆ self()

◆ sendMessageToGUI()

void ml::BackgroundTaskManager::sendMessageToGUI ( BackgroundTaskMessage * message)

Sends the given message asynchronously to the GUI thread. The message ownership is passed to the manager. Do not delete it yourself!

◆ sendMessageToTask()

void ml::BackgroundTaskManager::sendMessageToTask ( BackgroundTask * task,
BackgroundTaskMessage * message )

Sends the given message asynchronously to the worker thread of the task. The message ownership is passed to the manager. Do not delete it yourself!

References BackgroundTask.

◆ sendTaskAdded()

void ml::BackgroundTaskManager::sendTaskAdded ( BackgroundTask * task)
protected

Sends a task that is added to the observers.

References BackgroundTask.

◆ sendTaskFinishedMessage()

void ml::BackgroundTaskManager::sendTaskFinishedMessage ( BackgroundTask * task)
protected

Called by worker threads when a task is finished.

References BackgroundTask.

◆ sendTaskRemoved()

void ml::BackgroundTaskManager::sendTaskRemoved ( BackgroundTask * task)
protected

Sends a task that is removed from the observers.

References BackgroundTask.

◆ sendTaskStatusUpdated()

void ml::BackgroundTaskManager::sendTaskStatusUpdated ( )
protected

Sends that a task's status is updated to the observers.

◆ setBackgroundTaskScheduleProcessPendingMessagesCB()

void ml::BackgroundTaskManager::setBackgroundTaskScheduleProcessPendingMessagesCB ( BackgroundTaskScheduleProcessPendingMessagesCB * cb,
void * userData )

Sets the callback that will be called from any worker thread when a call of processPendingMessages() on the GUI thread is required. It needs to be thread-safe and should cause a call to processPendingMessages() in the GUI thread, ideally from within an idle timer to avoid blocking the GUI. If this callback is not installed, the BackgroundTaskManager will only run synchronous tasks. It should be set up in the early initialization phase of an application. Note: you must not change this while an asynchronous background task is running!

◆ supportsAsynchronousTasks()

bool ml::BackgroundTaskManager::supportsAsynchronousTasks ( )

Returns whether asynchronous tasks are supported, which is the case if setBackgroundTaskScheduleProcessPendingMessagesCB was called with a non-NULL callback.

◆ totalTaskCount()

int ml::BackgroundTaskManager::totalTaskCount ( )

Returns the number of queued and running tasks. This is only valid in the GUI thread.

◆ waitForTask()

BackgroundTask * ml::BackgroundTaskManager::waitForTask ( )
protected

Waits for a new task and returns the new task from the queue.

References BackgroundTask.

◆ BackgroundTask

◆ BackgroundTaskFinishedMessage

friend class BackgroundTaskFinishedMessage
friend

Definition at line 161 of file mlBackgroundTaskManager.h.

References BackgroundTaskFinishedMessage.

Referenced by BackgroundTaskFinishedMessage.

◆ BackgroundTaskManagerPrivate

friend class BackgroundTaskManagerPrivate
friend

Definition at line 199 of file mlBackgroundTaskManager.h.

References BackgroundTaskManagerPrivate.

Referenced by BackgroundTaskManagerPrivate.

◆ BackgroundTaskManagerWorkerFunc

friend struct BackgroundTaskManagerWorkerFunc
friend

Definition at line 160 of file mlBackgroundTaskManager.h.

References BackgroundTaskManagerWorkerFunc.

Referenced by BackgroundTaskManagerWorkerFunc.


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