fw4spl
Observer.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 __FWJOBS_OBSERVER_HPP__
8 #define __FWJOBS_OBSERVER_HPP__
9 
10 #include "fwJobs/config.hpp"
11 #include "fwJobs/IJob.hpp"
12 
13 #include <cstdint>
14 #include <string>
15 
16 namespace fwJobs
17 {
18 
22 class FWJOBS_CLASS_API Observer : public IJob
23 {
24 public:
28  typedef SPTR (::fwJobs::Observer) sptr;
29  typedef WPTR (::fwJobs::Observer) wptr;
30 
32  typedef std::function< void (std::uint64_t) > ProgressCallback;
42  FWJOBS_API static sptr New(const std::string& name, std::uint64_t workUnits = 100);
43 
49  FWJOBS_API Observer(const std::string& name, std::uint64_t workUnits = 100);
50 
55  using IJob::doneWork;
56  using IJob::setTotalWorkUnits;
57  using IJob::done;
63  FWJOBS_API void finish();
64 
70  FWJOBS_API ProgressCallback progressCallback();
71 
72 protected:
73 
75  using IJob::run;
76 
82  FWJOBS_API virtual SharedFuture runImpl();
83 
85  typedef std::packaged_task< void () > PackagedTask;
86 
88  PackagedTask m_finishTask;
89 
90 };
91 
92 } //namespace fwJobs
93 
94 #endif //__FWJOBS_OBSERVER_HPP__
std::function< void(std::uint64_t) > ProgressCallback
Progress callback type.
Definition: Observer.hpp:32
#define SPTR(_cls_)
This class is an interface for class managing job.
Definition: IJob.hpp:28
#define WPTR(_cls_)
std::weak_ptr< ::fwJobs::IJob > wptr
Cancel request callback type.
Definition: IJob.hpp:55
std::shared_future< void > SharedFuture
Future type.
Definition: IJob.hpp:109
STL namespace.
std::shared_ptr< ::fwJobs::IJob > sptr
Cancel request callback type.
Definition: IJob.hpp:54
std::packaged_task< void() > PackagedTask
Task type.
Definition: Observer.hpp:85
This namespace fwJobs provides jobs management.
This class manages a job.
Definition: Observer.hpp:22