fw4spl
SlotCall.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWCOM_SLOTCALL_HPP__
8 #define __FWCOM_SLOTCALL_HPP__
9 
10 #include "fwCom/SlotRun.hpp"
11 
12 namespace fwThread
13 {
14 class Worker;
15 }
16 
17 namespace fwCom
18 {
19 
20 template< typename F >
21 struct SlotCall;
22 
29 template< typename R, typename ... A >
30 struct SlotCall< R(A ...) > : SlotRun< void ( A ... ) >
31 {
35  typedef R SignatureType (A ...);
37  typedef SPTR ( SelfType ) sptr;
38  typedef WPTR ( SelfType ) wptr;
39  typedef std::shared_future< R > SharedFutureType;
42  SlotCall() :
43  SlotRun< void ( A ... ) >()
44  {
45  }
46 
47  virtual ~SlotCall()
48  {
49  }
50 
54  virtual R call(A ...) const = 0;
55 
66  virtual SharedFutureType asyncCall( const SPTR(::fwThread::Worker)& worker, A ... args ) const;
67 
76  virtual SharedFutureType asyncCall( A ... args ) const;
77 
78  protected:
79 
80  template< typename WEAKCALL >
81  static std::shared_future< R > postWeakCall( const SPTR(::fwThread::Worker)& worker, WEAKCALL f );
82 
88  virtual std::function< R() > bindCall( A ... args ) const;
89 };
90 
91 } // namespace fwCom
92 
93 #endif /* __FWCOM_SLOTCALL_HPP__ */
94 
#define SPTR(_cls_)
Namespace containing fw4spl communication tools.
Definition: DumpEditor.hpp:30
#define WPTR(_cls_)
This class creates and manages a task loop. The default implementation create a loop in a new thread...
Definition: Worker.hpp:32
This namespace fwThread provides few tools to execute asynchronous tasks on different threads...