fw4spl
Job.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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_JOB_HPP__
8 #define __FWJOBS_JOB_HPP__
9 
10 #include "fwJobs/config.hpp"
11 #include "fwJobs/IJob.hpp"
12 
13 #include <cstdint>
14 #include <functional>
15 #include <string>
16 
17 namespace fwThread
18 {
19 class Worker;
20 } //namespace fwThread
21 
22 namespace fwJobs
23 {
24 
30 class FWJOBS_CLASS_API Job : public IJob
31 {
32 public:
36  typedef SPTR (::fwJobs::Job) sptr;
37  typedef WPTR (::fwJobs::Job) wptr;
38 
40  typedef std::function< void (Job&) > Task;
41 
43  typedef std::function< void (std::uint64_t) > ProgressCallback;
55  FWJOBS_API static sptr New(const std::string &name, Task task, const SPTR(::fwThread::Worker) &worker = nullptr );
56 
64  FWJOBS_API Job(const std::string &name, Task task, const SPTR(::fwThread::Worker) &worker = nullptr );
65 
70  FWJOBS_API ProgressCallback progressCallback();
71 
76  using IJob::doneWork;
77  using IJob::setTotalWorkUnits;
78  using IJob::done;
81  FWJOBS_API SPTR(::fwThread::Worker) getWorker();
83 
85  FWJOBS_API virtual SharedFuture cancel();
86 
87 protected:
88 
94  FWJOBS_API SharedFuture runImpl();
95 
96 private:
97 
99  Task m_task;
100 
102  SPTR(::fwThread::Worker) m_worker;
103 
104 };
105 
106 } //namespace fwJobs
107 
108 #endif //__FWJOBS_JOB_HPP__
#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
This class encapsulate a task that will report it&#39;s progression The embeded task will be run at most ...
Definition: Job.hpp:30
std::function< void(Job &) > Task
Task type.
Definition: Job.hpp:40
This namespace fwThread provides few tools to execute asynchronous tasks on different threads...
This namespace fwJobs provides jobs management.
std::function< void(std::uint64_t) > ProgressCallback
Progress callback type.
Definition: Job.hpp:43