7 #ifndef __FWJOBS_IJOB_HPP__ 8 #define __FWJOBS_IJOB_HPP__ 10 #include "fwJobs/config.hpp" 12 #include <fwCom/Signal.hpp> 14 #include <fwCore/mt/types.hpp> 28 class FWJOBS_CLASS_API
IJob 117 FWJOBS_API IJob(const
std::
string& name = "");
120 FWJOBS_API virtual ~IJob();
123 FWJOBS_API
std::uint64_t getDoneWorkUnits() const;
126 FWJOBS_API
std::uint64_t getTotalWorkUnits() const;
129 FWJOBS_API
State getState() const;
132 FWJOBS_API const
std::
string& getName() const;
135 FWJOBS_API Logs getLogs() const;
138 FWJOBS_API
bool isCancelable() const;
141 FWJOBS_API
void setCancelable(
bool cancel);
148 FWJOBS_API SharedFuture run();
157 FWJOBS_API
void wait();
164 FWJOBS_API const
bool& cancelRequested() const;
171 FWJOBS_API CancelRequestCallback cancelRequestedCallback() const;
179 FWJOBS_API virtual SharedFuture cancel();
186 FWJOBS_API
void addSimpleCancelHook(CancelHook callback);
193 FWJOBS_API
void addCancelHook(JobCancelHook callback);
200 FWJOBS_API
void addDoneWorkHook(DoneWorkHook callback);
207 FWJOBS_API
void addTotalWorkUnitsHook(TotalWorkUnitsHook callback);
214 FWJOBS_API
void addLogHook(LogHook callback);
221 FWJOBS_API
void addStateHook(StateHook callback);
231 FWJOBS_API
void log(const
std::
string& message);
239 IJob& operator=(IJob&);
241 IJob& operator=(IJob&&);
244 FWJOBS_API virtual SharedFuture runImpl() = 0;
248 FWJOBS_API virtual
void finish();
251 FWJOBS_API
void finishNoLock();
261 FWJOBS_API
std::function<
void() > finishCallback();
264 FWJOBS_API
State getStateNoLock() const;
267 FWJOBS_API
void setState(
State state );
270 FWJOBS_API
void setStateNoLock(
State state );
273 FWJOBS_API
void doneWork(
std::uint64_t units );
282 FWJOBS_API
void doneWork(
std::uint64_t units, ::
fwCore::mt::ReadToWriteLock& lock );
285 FWJOBS_API
void done();
292 FWJOBS_API
void setTotalWorkUnits(
std::uint64_t units);
301 FWJOBS_API
void setTotalWorkUnitsUpgradeLock(
std::uint64_t units, ::
fwCore::mt::ReadToWriteLock& lock );
308 FWJOBS_API
void addCancelHookNoLock(JobCancelHook callback);
315 FWJOBS_API
void addDoneWorkHookNoLock(DoneWorkHook callback);
322 FWJOBS_API
void addTotalWorkUnitsHookNoLock(TotalWorkUnitsHook callback);
329 FWJOBS_API
void addLogHookNoLock(LogHook callback);
336 FWJOBS_API
void addStateHookNoLock(StateHook callback);
343 FWJOBS_API
void logNoLock(const
std::
string& message);
346 SPTR(CancelRequestedSignal) m_sigCancelRequested;
349 SPTR(StateSignal) m_sigCanceled;
352 SPTR(StateSignal) m_sigStarted;
355 SPTR(StateSignal) m_sigFinished;
358 SPTR(DoneWorkSignal) m_sigDoneWork;
364 mutable ::
fwCore::mt::ReadWriteMutex m_mutex;
373 std::uint64_t m_doneWorkUnits;
376 std::uint64_t m_totalWorkUnits;
379 bool m_cancelRequested;
385 CancelHookSeq m_cancelHooks;
388 DoneWorkHookSeq m_doneWorkHooks;
391 TotalWorkUnitsHookSeq m_totalWorkUnitsHooks;
394 LogHookSeq m_logHooks;
397 StateHookSeq m_stateHooks;
400 SharedFuture m_runFuture;
408 #endif //__FWJOBS_IJOB_HPP__
std::vector< StateHook > StateHookSeq
Log callback sequence type for state hook.
std::vector< LogHook > LogHookSeq
Log callback sequence type for log hook.
This class is an interface for class managing job.
Namespace containing fw4spl communication tools.
std::weak_ptr< ::fwJobs::IJob > wptr
Cancel request callback type.
std::vector< TotalWorkUnitsHook > TotalWorkUnitsHookSeq
Work units callback sequence type for total work unit hook.
std::shared_future< void > SharedFuture
Future type.
std::vector< JobCancelHook > CancelHookSeq
Job cancel callback sequence type for cancel hook.
This namespace fwCore provides common foundations for FW4SPL.
std::shared_ptr< ::fwJobs::IJob > sptr
Cancel request callback type.
std::function< void(IJob &, const std::string &) > LogHook
Log callback type for log hook.
std::function< void(State) > StateHook
State callback type for state hook.
std::function< void(IJob &, std::uint64_t) > TotalWorkUnitsHook
Work units callback type for total work unit hook.
std::function< void(IJob &) > JobCancelHook
Job cancel callback type for cancel hook.
std::function< void(IJob &, std::uint64_t) > DoneWorkHook
Done work callback type for done work hook.
std::function< bool() > CancelRequestCallback
Cancel request callback type.
std::vector< DoneWorkHook > DoneWorkHookSeq
Done work callback sequence type for done work hook.
std::function< void() > CancelHook
Cancel callback type for cancel hook.
std::vector< std::string > Logs
Log container type.
This namespace fwJobs provides jobs management.