MeVisLabToolboxReference
ml::BackgroundTaskManager Class Reference

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

#include <mlBackgroundTaskManager.h>

List of all members.

Classes

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

Public Member Functions

BackgroundTaskHandle runTask (BackgroundTask *task)
 run the given task, the ownership of the task is transfered to the task manager (do NOT delete the task yourself!) (only call from GUI thread!)
int totalTaskCount ()
 returns the number of queued and running tasks (only valid in GUI thread)
void getStatusInformation (std::vector< BackgroundTaskStatusInformation > &infos)
 get a snapshot of the state of all background tasks (which will represent that consistent status at the time of calling this function)
void sendMessageToGUI (BackgroundTaskMessage *message)
 sends the given message asynchronously to the to the GUI thread, the message ownership is passed to the manager, do NOT delete it youself!
void 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 youself!
bool hasSynchronousTask () const
 returns true if the manager is currently processing a synchronous task
bool processPendingMessages ()
 processes all pending messages (will not block and may only be called from the GUI thread, typically from an idle timer).
void cancelPendingRequestsForTask (BackgroundTask *task)
 cancel pending requests for a given task
void addObserver (Observer *observer)
 add an observer (the ownership stays with the caller)
void removeObserver (Observer *observer)
 remove an observer (the ownership stays with the caller)
PageRequestProcessorgetPageRequestProcessor ()
 get instance of the page request processor (TODO: this will probably move into the ML host!)
void setBackgroundTaskScheduleProcessPendingMessagesCB (BackgroundTaskScheduleProcessPendingMessagesCB *cb, void *userData)
 Set the callback that will be called from any worker thread when a call of processPendingMessages() on the GUI thread is required.
void getBackgroundTaskScheduleProcessPendingMessagesCB (BackgroundTaskScheduleProcessPendingMessagesCB **cb, void **userData)
 Get the currently set callback.
bool supportsAsynchronousTasks ()
 Returns if asynchronous tasks are supported (which is the case if setBackgroundTaskScheduleProcessPendingMessagesCB was called with a non-NULL callback.

Static Public Member Functions

static BackgroundTaskManagerself ()
 get the global singleton
static void init ()
 initialize the background task manager
static void cleanup ()
 cleanup the background task manager
static bool ensureGUIThread ()
 returns true if the current thread is the GUI thread
static bool ensureWorkerThread ()
 returns true if the current thread is not the GUI thread (and thus a worker thread) NOTE: in synchronous mode, this will always return true, don't use it to decide on the code path, use ensureGUIThread instead.

Protected Member Functions

MLuint32 getUniqueTaskId ()
 get new unique id of a task (threadsafe)
void sendTaskAdded (BackgroundTask *task)
 send task added to observers
void sendTaskRemoved (BackgroundTask *task)
 send task removed to observers
void sendTaskStatusUpdated ()
 send task status updated to observers
void removeTaskFromQueueAndSendTaskFinished (BackgroundTask *task)
 remove a task if it was queued
BackgroundTaskwaitForTask ()
 waits for a new task, 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 51 of file mlBackgroundTaskManager.h.


Member Function Documentation

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

add an observer (the ownership stays with the caller)

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

cancel pending requests for a given task

static void ml::BackgroundTaskManager::cleanup ( ) [static]

cleanup the background task manager

static bool ml::BackgroundTaskManager::ensureGUIThread ( ) [static]

returns true if the current thread is the GUI thread

static bool ml::BackgroundTaskManager::ensureWorkerThread ( ) [static]

returns true if the current thread is not the GUI thread (and thus a worker thread) NOTE: in synchronous mode, this will always return true, don't use it to decide on the code path, use ensureGUIThread instead.

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

Get the currently set callback.

PageRequestProcessor& ml::BackgroundTaskManager::getPageRequestProcessor ( )

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

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

get a snapshot of the state of all background tasks (which will represent that consistent status at the time of calling this function)

MLuint32 ml::BackgroundTaskManager::getUniqueTaskId ( ) [protected]

get new unique id of a task (threadsafe)

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

returns true if the manager is currently processing a synchronous task

Definition at line 89 of file mlBackgroundTaskManager.h.

static void ml::BackgroundTaskManager::init ( ) [static]

initialize the background task manager

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 if more work is available.

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

remove an observer (the ownership stays with the caller)

void ml::BackgroundTaskManager::removeTaskFromQueueAndSendTaskFinished ( BackgroundTask task) [protected]

remove a task if it was queued

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

run the given task, the ownership of the task is transfered to the task manager (do NOT delete the task yourself!) (only call from GUI thread!)

static BackgroundTaskManager& ml::BackgroundTaskManager::self ( ) [static]

get the global singleton

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

sends the given message asynchronously to the to the GUI thread, the message ownership is passed to the manager, do NOT delete it youself!

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 youself!

void ml::BackgroundTaskManager::sendTaskAdded ( BackgroundTask task) [protected]

send task added to observers

void ml::BackgroundTaskManager::sendTaskFinishedMessage ( BackgroundTask task) [protected]

called by worker threads when a task is finished

void ml::BackgroundTaskManager::sendTaskRemoved ( BackgroundTask task) [protected]

send task removed to observers

void ml::BackgroundTaskManager::sendTaskStatusUpdated ( ) [protected]

send task status updated to observers

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

Set 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 threadsafe and should cause a call to the processPendingMessages() in the GUI thread, best from within an idle timer to not block the GUI. If this callback is not installed, the BackgroundTaskManager will only run synchronous tasks. It should be setup in the early initialization phase of an application. NOTE: you MAY NOT change this while an asynchronous background task is running!!!

bool ml::BackgroundTaskManager::supportsAsynchronousTasks ( )

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

int ml::BackgroundTaskManager::totalTaskCount ( )

returns the number of queued and running tasks (only valid in GUI thread)

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

waits for a new task, returns the new task from the queue


Friends And Related Function Documentation

friend class BackgroundTask [friend]

Definition at line 152 of file mlBackgroundTaskManager.h.

friend class BackgroundTaskFinishedMessage [friend]

Definition at line 151 of file mlBackgroundTaskManager.h.

friend class BackgroundTaskManagerPrivate [friend]

Definition at line 187 of file mlBackgroundTaskManager.h.

friend struct BackgroundTaskManagerWorkerFunc [friend]

Definition at line 150 of file mlBackgroundTaskManager.h.


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