MeVisLab Toolbox Reference
ml::TypedBackgroundTaskHandle< Task > Class Template Reference

The TypedBackgroundTaskHandle class provides a secure interface to communicate with a running BackgroundTask. More...

#include <mlTypedBackgroundTaskHandle.h>

Inheritance diagram for ml::TypedBackgroundTaskHandle< Task >:
ml::BackgroundTaskHandle

Public Types

typedef Task TaskType
 Typedef to access the type of the stored task. More...
 

Public Member Functions

 TypedBackgroundTaskHandle ()
 
 TypedBackgroundTaskHandle (Task *task)
 
TypedBackgroundTaskHandleoperator= (Task *task)
 
Calling methods on the running task
template<typename Method >
void callMethodOnTask (Method method)
 
template<typename Method , typename Arg1 >
void callMethodOnTask (Method method, const Arg1 &arg1)
 
template<typename Method , typename Arg1 , typename Arg2 >
void callMethodOnTask (Method method, const Arg1 &arg1, const Arg2 &arg2)
 
template<typename Method , typename Arg1 , typename Arg2 , typename Arg3 >
void callMethodOnTask (Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
 
template<typename Method , typename Arg1 , typename Arg2 , typename Arg3 , typename Arg4 >
void callMethodOnTask (Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
 
template<typename Method , typename Arg1 , typename Arg2 , typename Arg3 , typename Arg4 , typename Arg5 >
void callMethodOnTask (Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
 
- Public Member Functions inherited from ml::BackgroundTaskHandle
 BackgroundTaskHandle ()
 
void clear ()
 clears the handle, make sure to call this from the taskFinishedCB of the background task manager More...
 
bool hasTask () const
 check if the handle has a task More...
 
bool hasRunningTask () const
 check if the handle has a task which is not canceled More...
 
bool isCanceled () const
 check if the task was canceled More...
 
void cancel ()
 cancel the running task More...
 
void setOwnerWasDeleted ()
 tell the task that the owner was deleted More...
 

Protected Member Functions

Task * typedTask () const
 get access to the typed task value More...
 
- Protected Member Functions inherited from ml::BackgroundTaskHandle
 BackgroundTaskHandle (BackgroundTask *task)
 

Additional Inherited Members

- Protected Attributes inherited from ml::BackgroundTaskHandle
BackgroundTask_task
 

Detailed Description

template<typename Task>
class ml::TypedBackgroundTaskHandle< Task >

The TypedBackgroundTaskHandle class provides a secure interface to communicate with a running BackgroundTask.

It provides the callMethodOnTask() methods to call a method on the task in the thread the task is running in. It does not provide return values. The handle DOES NOT reset to NULL when the task is destroyed, so the programmer needs to make sure that the clear() method is called when the task is gone. In the case of the BackgroundTaskBaseModule, the correct place to do this is the virtual taskFinished() method. NOTE: Sending method calls to a running task is very seldom needed and requires that the task actively calls executeNextMessage() to process the incoming calls.

Definition at line 41 of file mlTypedBackgroundTaskHandle.h.

Member Typedef Documentation

◆ TaskType

template<typename Task >
typedef Task ml::TypedBackgroundTaskHandle< Task >::TaskType

Typedef to access the type of the stored task.

Definition at line 45 of file mlTypedBackgroundTaskHandle.h.

Constructor & Destructor Documentation

◆ TypedBackgroundTaskHandle() [1/2]

template<typename Task >
ml::TypedBackgroundTaskHandle< Task >::TypedBackgroundTaskHandle ( )
inline

Definition at line 47 of file mlTypedBackgroundTaskHandle.h.

◆ TypedBackgroundTaskHandle() [2/2]

template<typename Task >
ml::TypedBackgroundTaskHandle< Task >::TypedBackgroundTaskHandle ( Task *  task)
inline

Definition at line 49 of file mlTypedBackgroundTaskHandle.h.

Member Function Documentation

◆ callMethodOnTask() [1/6]

template<typename Task >
template<typename Method >
void ml::TypedBackgroundTaskHandle< Task >::callMethodOnTask ( Method  method)
inline

The example below shows how to use the handle. Note that you would typically store the handle as a member variable and would call callMethodOnTask at a much later time to tell the task that something changed.

SomeTask* task = new SomeTask();
TypedBackgroundTaskHandle<SomeTask> handle = task;
...
// Note the &SomeTask::method syntax to get a pointer to the member function
handle.callMethodOnTask(&SomeTask::someMethodWithOneArgument, 42);
handle.callMethodOnTask(&SomeTask::someMethodWithTwoArgument, 42, false);
BackgroundTaskHandle runTask(BackgroundTask *task)
run the given task, the ownership of the task is transfered to the task manager (do NOT delete the ta...
static BackgroundTaskManager & self()
get the global singleton

callMethodOnTask() can call any non-static member method of the task with up to 5 arguments, the arguments are copies so that values that you pass need to be copyable. You should be very careful when you pass pointers since the ownership stays with the caller and you can not easily know when it is safe to delete the pointer.

Definition at line 83 of file mlTypedBackgroundTaskHandle.h.

References ml::NewBackgroundTaskMethodCall().

◆ callMethodOnTask() [2/6]

template<typename Task >
template<typename Method , typename Arg1 >
void ml::TypedBackgroundTaskHandle< Task >::callMethodOnTask ( Method  method,
const Arg1 &  arg1 
)
inline

Definition at line 89 of file mlTypedBackgroundTaskHandle.h.

References ml::NewBackgroundTaskMethodCall().

◆ callMethodOnTask() [3/6]

template<typename Task >
template<typename Method , typename Arg1 , typename Arg2 >
void ml::TypedBackgroundTaskHandle< Task >::callMethodOnTask ( Method  method,
const Arg1 &  arg1,
const Arg2 &  arg2 
)
inline

Definition at line 95 of file mlTypedBackgroundTaskHandle.h.

References ml::NewBackgroundTaskMethodCall().

◆ callMethodOnTask() [4/6]

template<typename Task >
template<typename Method , typename Arg1 , typename Arg2 , typename Arg3 >
void ml::TypedBackgroundTaskHandle< Task >::callMethodOnTask ( Method  method,
const Arg1 &  arg1,
const Arg2 &  arg2,
const Arg3 &  arg3 
)
inline

Definition at line 101 of file mlTypedBackgroundTaskHandle.h.

References ml::NewBackgroundTaskMethodCall().

◆ callMethodOnTask() [5/6]

template<typename Task >
template<typename Method , typename Arg1 , typename Arg2 , typename Arg3 , typename Arg4 >
void ml::TypedBackgroundTaskHandle< Task >::callMethodOnTask ( Method  method,
const Arg1 &  arg1,
const Arg2 &  arg2,
const Arg3 &  arg3,
const Arg4 &  arg4 
)
inline

Definition at line 107 of file mlTypedBackgroundTaskHandle.h.

References ml::NewBackgroundTaskMethodCall().

◆ callMethodOnTask() [6/6]

template<typename Task >
template<typename Method , typename Arg1 , typename Arg2 , typename Arg3 , typename Arg4 , typename Arg5 >
void ml::TypedBackgroundTaskHandle< Task >::callMethodOnTask ( Method  method,
const Arg1 &  arg1,
const Arg2 &  arg2,
const Arg3 &  arg3,
const Arg4 &  arg4,
const Arg5 &  arg5 
)
inline

Definition at line 113 of file mlTypedBackgroundTaskHandle.h.

References ml::NewBackgroundTaskMethodCall().

◆ operator=()

template<typename Task >
TypedBackgroundTaskHandle& ml::TypedBackgroundTaskHandle< Task >::operator= ( Task *  task)
inline

Definition at line 51 of file mlTypedBackgroundTaskHandle.h.

◆ typedTask()

template<typename Task >
Task* ml::TypedBackgroundTaskHandle< Task >::typedTask ( ) const
inlineprotected

get access to the typed task value

Definition at line 122 of file mlTypedBackgroundTaskHandle.h.


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