MeVisLab Toolbox Reference
ml::MessagingBackgroundTask Class Reference

#include <mlMessagingBackgroundTask.h>

Inheritance diagram for ml::MessagingBackgroundTask:
ml::BackgroundTask ml::ImagingBackgroundTask ml::ModuleBackgroundTask ml::ProcessAllPagesBackgroundTask ml::RTObjectSaveBackgroundTask

Public Member Functions

 MessagingBackgroundTask (void *ownerArg)
Calling methods on DistantObjects in the GUI thread
template<typename Object, typename Method>
void callMethodOnGUI (const DistantObject< Object > &target, Method method)
template<typename Object, typename Method, typename Arg1>
void callMethodOnGUI (const DistantObject< Object > &target, Method method, const Arg1 &arg1)
template<typename Object, typename Method, typename Arg1, typename Arg2>
void callMethodOnGUI (const DistantObject< Object > &target, Method method, const Arg1 &arg1, const Arg2 &arg2)
template<typename Object, typename Method, typename Arg1, typename Arg2, typename Arg3>
void callMethodOnGUI (const DistantObject< Object > &target, Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
template<typename Object, typename Method, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
void callMethodOnGUI (const DistantObject< Object > &target, Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
template<typename Object, typename Method, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
void callMethodOnGUI (const DistantObject< Object > &target, Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
Public Member Functions inherited from ml::BackgroundTask
 BackgroundTask (void *owner)
virtual ~BackgroundTask ()
virtual void run ()=0
 Method that needs to be reimplemented. This is called from the worker thread.
bool isSynchronous () const
 Checks whether the task is synchronous, which means it is not executed in a different thread.
void setSynchronous (bool flag)
 Sets whether the task is handled synchronously. Call this only in the setup of the task, not while it is already running.
void setSynchronousCancelField (NotifyField *field)
 Sets a cancel field that is used in synchronous mode to check whether cancel was pressed.
Status status () const
void cancel ()
bool isCanceled () const
bool shouldStop ()
void resume ()
void suspend ()
std::string statusString () const
virtual void setStatusString (const std::string &status)
float progress () const
virtual void setProgress (float progress)
void setOwnerWasDeleted ()
bool hasOwner () const
void * owner () const
void waitAndExecuteNextMessage ()
bool executeNextMessage ()
void sendMessageToGUI (BackgroundTaskMessage *message)
void logMessage (const std::string &message)
bool isVerbose () const
 Checks whether task uses verbose logging.
void setVerbose (bool flag)
double runningTime () const
double idleTime () const
void getStatusInformation (BackgroundTaskStatusInformation &info)
MLuint32 taskId () const
 Returns the unique id of this task. The id of a task never changes.
void setTaskFinishedCB (BackgroundTaskFinishedCB *callback, void *userdata)
void addObserver (Observer *observer)
void removeObserver (Observer *observer)

Additional Inherited Members

Public Types inherited from ml::BackgroundTask
enum  Status {
  NotInTaskManager , Queued , Running , Finished ,
  Canceled , Suspended
}
 Defines current status of the task. More...
Protected Member Functions inherited from ml::BackgroundTask
void sendStatusChangedToObservers ()
 Sends the status change to all observers.
void sendStatusStringChangedToObservers ()
 Sends the status string change to all observers.
void sendLogMessageToObservers (const std::string &msg)
 Sends the status string change to all observers.
void addIdleTime (double timeInSecs)
 Adds given timeInSecs as spent idle time.

Detailed Description

MessagingBackgroundTask extends the BackgroundTask with the functionality to call methods on DistantObject instances on the GUI thread to communicate with the GUI (e.g., to send some intermediate result to the GUI).

Definition at line 30 of file mlMessagingBackgroundTask.h.

Constructor & Destructor Documentation

◆ MessagingBackgroundTask()

ml::MessagingBackgroundTask::MessagingBackgroundTask ( void * ownerArg)
inline

Definition at line 35 of file mlMessagingBackgroundTask.h.

References ml::BackgroundTask::BackgroundTask().

Member Function Documentation

◆ callMethodOnGUI() [1/6]

template<typename Object, typename Method>
void ml::MessagingBackgroundTask::callMethodOnGUI ( const DistantObject< Object > & target,
Method method )
inline

callMethodOnGUI() can call any non-static member method on the instance of T that is stored in a DistantObject<T> with up to five 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. The call is sent to the GUI thread and executed there.

The example shows how to send an intermediate Matrix4 result to a MatrixField in the GUI thread:

class MyBackgroundTask {
MyBackgroundTask(void* owner, MatrixField* field)
_field(field) {}
virtual void run() {
...
Matrix4 someIntermediateResult;
...
// Note the &MatrixField::setMat4Value syntax to get a pointer to the member function
callMethodOnGUI(_field, &MatrixField::setMat4Value, someIntermediateResult);
...
}
private:
DistantObject<MatrixField> _field;
};
void * owner() const
Tmat4< MLdouble > Matrix4
The standard 4x4 matrix of type double.
Definition mlMatrix4.h:713

Typically, you will either pass the pointer to your derived Module and store it as a DistantObject, or alternatively, you can pass individual fields and store them in their own DistantObjects.

Definition at line 78 of file mlMessagingBackgroundTask.h.

References ml::DistantObjectAccessor::get(), ml::NewBackgroundTaskMethodCall(), and ml::BackgroundTask::sendMessageToGUI().

◆ callMethodOnGUI() [2/6]

template<typename Object, typename Method, typename Arg1>
void ml::MessagingBackgroundTask::callMethodOnGUI ( const DistantObject< Object > & target,
Method method,
const Arg1 & arg1 )
inline

◆ callMethodOnGUI() [3/6]

template<typename Object, typename Method, typename Arg1, typename Arg2>
void ml::MessagingBackgroundTask::callMethodOnGUI ( const DistantObject< Object > & target,
Method method,
const Arg1 & arg1,
const Arg2 & arg2 )
inline

◆ callMethodOnGUI() [4/6]

template<typename Object, typename Method, typename Arg1, typename Arg2, typename Arg3>
void ml::MessagingBackgroundTask::callMethodOnGUI ( const DistantObject< Object > & target,
Method method,
const Arg1 & arg1,
const Arg2 & arg2,
const Arg3 & arg3 )
inline

◆ callMethodOnGUI() [5/6]

template<typename Object, typename Method, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
void ml::MessagingBackgroundTask::callMethodOnGUI ( const DistantObject< Object > & target,
Method method,
const Arg1 & arg1,
const Arg2 & arg2,
const Arg3 & arg3,
const Arg4 & arg4 )
inline

◆ callMethodOnGUI() [6/6]

template<typename Object, typename Method, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
void ml::MessagingBackgroundTask::callMethodOnGUI ( const DistantObject< Object > & target,
Method method,
const Arg1 & arg1,
const Arg2 & arg2,
const Arg3 & arg3,
const Arg4 & arg4,
const Arg5 & arg5 )
inline

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