MeVisLabToolboxReference
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

List of all members.

Public Types

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

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)

Protected Member Functions

Task * typedTask () const
 get access to the typed task value

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 destoyed, 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

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

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

Definition at line 47 of file mlTypedBackgroundTaskHandle.h.

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

Definition at line 49 of file mlTypedBackgroundTaskHandle.h.


Member Function Documentation

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;
  BackgroundTaskManager::self().runTask(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);

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().

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().

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().

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().

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().

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().

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

Definition at line 51 of file mlTypedBackgroundTaskHandle.h.

template<typename Task >
Task* ml::TypedBackgroundTaskHandle< Task >::typedTask ( ) const [inline, protected]

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: