MeVisLab Toolbox Reference
mlTypedBackgroundTaskHandle.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_TYPED_BACKGROUND_TASK_HANDLE_H
14 #define ML_TYPED_BACKGROUND_TASK_HANDLE_H
15 
16 // Local includes
18 
19 #include "mlBackgroundTaskHandle.h"
21 
22 ML_START_NAMESPACE
23 
24 //-----------------------------------------------------------------------
25 
26 class BackgroundTask;
27 
40 template <typename Task>
42 {
43 public:
45  typedef Task TaskType;
46 
47  TypedBackgroundTaskHandle() { _task = nullptr; }
48 
50 
52  _task = task;
53  return *this;
54  }
55 
56  //------------------------------------------------------
58 
80  //------------------------------------------------------
81 
82  template <typename Method>
83  void callMethodOnTask(Method method)
84  {
85  BackgroundTaskManager::self().sendMessageToTask(typedTask(), NewBackgroundTaskMethodCall(typedTask(), method));
86  }
87 
88  template <typename Method, typename Arg1>
89  void callMethodOnTask(Method method, const Arg1& arg1)
90  {
91  BackgroundTaskManager::self().sendMessageToTask(typedTask(), NewBackgroundTaskMethodCall(typedTask(), method, arg1));
92  }
93 
94  template <typename Method, typename Arg1, typename Arg2>
95  void callMethodOnTask(Method method, const Arg1& arg1, const Arg2& arg2)
96  {
97  BackgroundTaskManager::self().sendMessageToTask(typedTask(), NewBackgroundTaskMethodCall(typedTask(), method, arg1, arg2));
98  }
99 
100  template <typename Method, typename Arg1, typename Arg2, typename Arg3>
101  void callMethodOnTask(Method method, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
102  {
103  BackgroundTaskManager::self().sendMessageToTask(typedTask(), NewBackgroundTaskMethodCall(typedTask(), method, arg1, arg2, arg3));
104  }
105 
106  template <typename Method, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
107  void callMethodOnTask(Method method, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4)
108  {
109  BackgroundTaskManager::self().sendMessageToTask(typedTask(), NewBackgroundTaskMethodCall(typedTask(), method, arg1, arg2, arg3, arg4));
110  }
111 
112  template <typename Method, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
113  void callMethodOnTask(Method method, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
114  {
115  BackgroundTaskManager::self().sendMessageToTask(typedTask(), NewBackgroundTaskMethodCall(typedTask(), method, arg1, arg2, arg3, arg4, arg5));
116  }
117 
119 
120 protected:
122  inline Task* typedTask() const { return static_cast<Task*>(_task); }
123 };
124 
125 ML_END_NAMESPACE
126 
127 #endif
128 
129 
A handle to a task that has been created by the background task manager.
The TypedBackgroundTaskHandle class provides a secure interface to communicate with a running Backgro...
TypedBackgroundTaskHandle & operator=(Task *task)
void callMethodOnTask(Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
Task TaskType
Typedef to access the type of the stored task.
void callMethodOnTask(Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
void callMethodOnTask(Method method, const Arg1 &arg1, const Arg2 &arg2)
void callMethodOnTask(Method method, const Arg1 &arg1)
Task * typedTask() const
get access to the typed task value
void callMethodOnTask(Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
BackgroundTaskMessage * NewBackgroundTaskMethodCall(Object *object, Method method)
create new method call with 0 arguments