MeVisLab Toolbox Reference
mlBackgroundTaskHandle.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_HANDLE_H
14 #define ML_BACKGROUND_TASK_HANDLE_H
15 
16 // Local includes
18 
19 ML_START_NAMESPACE
20 
21 //-----------------------------------------------------------------------
22 
23 class BackgroundTask;
24 
26 
31 {
32 public:
33  BackgroundTaskHandle() { _task = nullptr; }
34 
36  void clear();
37 
39  bool hasTask() const;
40 
42  bool hasRunningTask() const;
43 
45  bool isCanceled() const;
46 
48  void cancel();
49 
52 
53 protected:
54  friend class BackgroundTaskManager;
56  BackgroundTaskHandle(BackgroundTask* task) { _task = task; }
57 
59 };
60 
65 {
66 public:
67  inline static BackgroundTask* get(const BackgroundTaskHandle& handle) { return handle._task; }
68 };
69 
70 ML_END_NAMESPACE
71 
72 #endif
73 
74 
#define MLBACKGROUNDTASKS_EXPORT
This class offers direct access to the contained background task.
static BackgroundTask * get(const BackgroundTaskHandle &handle)
A handle to a task that has been created by the background task manager.
bool isCanceled() const
Returns whether the task was canceled.
void clear()
Clears the handle. Make sure to call this from the taskFinishedCB of the background task manager.
bool hasTask() const
Returns whether the handle has a task.
BackgroundTaskHandle(BackgroundTask *task)
void setOwnerWasDeleted()
Tells the task that the owner was deleted.
void cancel()
Cancels the running task.
bool hasRunningTask() const
Returns whether the handle has a task that is not canceled.
The BackgroundTaskManager is the central singleton that manages running background tasks.
Base class for a task that is started in an extra thread.