MeVisLab Toolbox Reference
ml::MessagingBackgroundTask Class Reference

MessagingBackgroundTask extends the BackgroundTask with the functionality to call methods on DistantObject instances on the GUI thread to communicate with the GUI (e.g. More...

#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)
 Create a new task with given owner (the owner can be used to associate the task with a given class instance, e.g. More...
 
virtual ~BackgroundTask ()
 
virtual void run ()=0
 run method that needs to be reimplemented (called from worker thread) More...
 
bool isSynchronous () const
 check if task is synchronous (which means it is NOT run in an extra thread) More...
 
void setSynchronous (bool flag)
 set if task is handled synchronous (call this ONLY on setup of the task, not while it is already running) More...
 
void setSynchronousCancelField (NotifyField *field)
 set a cancel field that is used in synchronous mode to check if cancel was pressed More...
 
Status status () const
 returns the status of the task (threadsafe) More...
 
void cancel ()
 cancel the task (sets status to canceled) (threadsafe, typically called from GUI) More...
 
bool isCanceled () const
 check if the task was canceled (threadsafe, typically called from GUI) More...
 
bool shouldStop ()
 returns if the task should stop its work because it has been canceled. More...
 
void resume ()
 resume task after it was suspended (will only do something if current status() is Suspended) (threadsafe) More...
 
void suspend ()
 suspend task, so that it will wait until resume() is called (threadsafe). More...
 
std::string statusString () const
 get current status string (threadsafe) More...
 
virtual void setStatusString (const std::string &status)
 update the status string while processing (from run() method only) More...
 
float progress () const
 get current progress (threadsafe) More...
 
virtual void setProgress (float progress)
 update the progress while processing (from run() method only) More...
 
void setOwnerWasDeleted ()
 tell the task that it's owner was deleted (only call from GUI thread!), this also cancels the task More...
 
bool hasOwner () const
 check if owner was deleted (only call from GUI thread!) More...
 
void * owner () const
 get the owner of the task (only call from GUI thread!) More...
 
void waitAndExecuteNextMessage ()
 execute the next message (waits if no messages are available and processes the first message that is received) NOTE: only call from within run() More...
 
bool executeNextMessage ()
 execute the next message (does not block if no message is available) It returns true if there was a message to process. More...
 
void sendMessageToGUI (BackgroundTaskMessage *message)
 send the message to the GUI (ownership of message is passed to the method) and it sets the sender of the message to this BackgroundTask. More...
 
void logMessage (const std::string &message)
 log a message (only logged if verbose logging is turned on) (threadsafe) More...
 
bool isVerbose () const
 check if task uses verbose logging More...
 
void setVerbose (bool flag)
 set if task uses verbose logging (call this ONLY on setup of the task, not while it is already running) More...
 
double runningTime () const
 returns the running time (in seconds) of the task (after it has finished or canceled, only call from GUI thread) More...
 
double idleTime () const
 returns the idle time (in seconds) of the task (which it e.g. waited for getTile to complete), (after it has finished or canceled, only call from GUI thread) More...
 
void getStatusInformation (BackgroundTaskStatusInformation &info)
 get the complete status information (threadsafe) More...
 
MLuint32 taskId () const
 get the unique id of this task, the id of a task never changes More...
 
void setTaskFinishedCB (BackgroundTaskFinishedCB *callback, void *userdata)
 set this directly after initialization of the task (from the GUI thread) this callback will be called whenever a task is either finished or canceled More...
 
void addObserver (Observer *observer)
 add the given observer (threadsafe) (ownership stays with caller) More...
 
void removeObserver (Observer *observer)
 remove the given observer (threadsafe) (ownership stays with caller) More...
 

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 ()
 send the status change to all observers More...
 
void sendStatusStringChangedToObservers ()
 send the status string change to all observers More...
 
void sendLogMessageToObservers (const std::string &msg)
 send the status string change to all observers More...
 
void addIdleTime (double timeInSecs)
 add given timeInSecs as spent idle time More...
 

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.

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.

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 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. The call is send 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
get the owner of the task (only call from GUI thread!)
virtual void run()=0
run method that needs to be reimplemented (called from worker thread)
void setMat4Value(const Matrix4 &value)
Definition: mlFields.h:2388
void callMethodOnGUI(const DistantObject< Object > &target, Method method)
Tmat4< MLdouble > Matrix4
The standard 4x4 matrix of type double.
Definition: mlMatrix4.h:726

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 boost::get(), ml::NewBackgroundTaskMethodCall(), ml::BackgroundTask::sendMessageToGUI(), and boost::target().

◆ 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: