Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryAsyncRunnable.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 
18 #ifndef BERRYASYNCRUNNABLE_H_
19 #define BERRYASYNCRUNNABLE_H_
20 
21 #include <Poco/ActiveRunnable.h>
22 
23 namespace berry {
24 
30 template <class ArgType, class OwnerType>
31 class AsyncRunnable : public Poco::ActiveRunnableBase
32 {
33 public:
34  typedef void (OwnerType::*Callback)(const ArgType&);
35 
36  AsyncRunnable(OwnerType* pOwner, Callback method, const ArgType& arg):
37  _pOwner(pOwner),
38  _method(method),
39  _arg(arg)
40  {
41  poco_check_ptr (pOwner);
42  }
43 
44  void run() override
45  {
46  ActiveRunnableBase::Ptr guard(this, false); // ensure automatic release when done
47  (_pOwner->*_method)(_arg);
48  }
49 
50 private:
51  OwnerType* _pOwner;
52  Callback _method;
53  ArgType _arg;
54 };
55 
56 }
57 
58 #endif /* BERRYASYNCRUNNABLE_H_ */
void(OwnerType::* Callback)(const ArgType &)
AsyncRunnable(OwnerType *pOwner, Callback method, const ArgType &arg)