MeVisLab Toolbox Reference
mlBackgroundTaskModuleHandler.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2009, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_BACKGROUND_TASK_MODULE_HANDLER_H
14 #define ML_BACKGROUND_TASK_MODULE_HANDLER_H
15 
16 // Local includes
18 #include "mlModuleBackgroundTask.h"
20 
21 // ML includes
22 #include <mlModuleIncludes.h>
23 
24 ML_START_NAMESPACE
25 
26 class BackgroundTaskBaseModule;
27 
29 {
30 public:
31 
35  Asynchronous
36  };
37 
40 
41  virtual void setupTaskFields(Module* module);
42 
46  void setTaskRunningField(BoolField* taskRunningField) { _taskRunning = taskRunningField; }
47  void setTaskFinishedField(NotifyField* taskFinishedField) { _taskFinished = taskFinishedField; }
48  void setTaskCanceledField(NotifyField* taskCanceledField) { _taskCanceled = taskCanceledField; }
49  void setTaskProgressField(FloatField* progressField) { _progress = progressField; }
50  void setTaskStatusField(StringField* statusField) { _status = statusField; }
52 
53  NotifyField* getStartTaskField() { return _startTask; }
54  NotifyField* getStartTaskSynchronousField() { return _startTaskSynchronous; }
55  NotifyField* getCancelTaskField() { return _cancelTask; }
56  BoolField* getTaskVerboseLoggingField() { return _taskVerboseLogging; }
57 
58  BoolField* getTaskRunningField() { return _taskRunning; }
59  NotifyField* getTaskFinishedField() { return _taskFinished; }
60  NotifyField* getTaskCanceledField() { return _taskCanceled; }
61  FloatField* getTaskProgressField() { return _progress; }
62  StringField* getTaskStatusField() { return _status; }
63 
64 
66  virtual void handleTaskFieldNotification(Field *field);
67 
69  virtual void taskFinished(BackgroundTask* task);
70 
74  virtual void postTaskFinished();
75 
81 
84 
86  void startTask() { startTask(Asynchronous); }
93  void startTask(const ExecutionMode mode);
95  void cancelTask();
99  bool willRestartTask() { return _restartTask; }
101  void setRestartTask(bool flag) { _restartTask = flag; }
102 
103 private:
105  void preTaskFinished();
106 
108  static void taskFinishedCB(void* userData, BackgroundTask* task);
109 
110 protected:
111  // ----------------------------------------------------------
114  // ----------------------------------------------------------
125 
126 private:
129  BackgroundTaskHandle _taskHandle;
130 
132  Module* _module;
133 
135  bool _restartTask;
136 
137  friend class Module;
139 };
140 
141 
142 ML_END_NAMESPACE
143 
144 #endif // __mlBackgroundTaskBaseComponent_H
#define MLBACKGROUNDTASKS_EXPORT
Project global and OS specific declarations.
Base class for ML modules that use background tasks.
A handle to a task that has been created by the background task manager.
void setTaskCanceledField(NotifyField *taskCanceledField)
void startTask()
Start a task with mode Asynchronous.
virtual void handleTaskFieldNotification(Field *field)
Handle field changes of the field field.
void cancelTask()
Cancel a task if it is currently running.
void setTaskProgressField(FloatField *progressField)
bool willRestartTask()
Returns if the task will be restarted after the previous task has been canceled.
virtual void taskFinished(BackgroundTask *task)
Callback for finished/canceled tasks (to be derived, make sure to call parent method).
void setRestartTask(bool flag)
Set if the task should be restarted after the previous task finishes.
virtual void postTaskFinished()
Called after taskFinished() has been called and can be used to handle the restarting of a task.
virtual ModuleBackgroundTask * createTask()=0
Request a new task to be created, reimplement this method and make sure that you keep no reference to...
ExecutionMode
Execution mode of background tasks.
@ Synchronous
Execute the background task synchronously.
void startTask(const ExecutionMode mode)
Start a task with user specifying the mode (Synchronous or Asynchronous).
bool hasRunningTask()
Returns if a task is currently running (and not yet canceled).
virtual void setupTaskFields(Module *module)
virtual void updateFinishedTaskStatus(BackgroundTask *task)
Updates the status and progress field of a finished task, is called by taskFinished and may be reimpl...
void setTaskRunningField(BoolField *taskRunningField)
void setTaskFinishedField(NotifyField *taskFinishedField)
void setTaskStatusField(StringField *statusField)
Base class for a task that is started in an extra thread.
Field to encapsulate a boolean value.
Definition: mlFields.h:62
Base class for all fields used in the ML.
Definition: mlField.h:73
Field to encapsulate a float value.
Definition: mlFields.h:627
ModuleBackgroundTask extends the ImagingBackgroundTask with a number of useful methods that allow asy...
Base class for an image processing module of the ML.
Definition: mlModule.h:156
Field without value for notifications.
Definition: mlFields.h:1049
Field to encapsulate a string value.
Definition: mlFields.h:1000