fw4spl
|
This class is an interface for class managing job. More...
#include <IJob.hpp>
Public Types | |
enum | State { WAITING = 0, RUNNING, CANCELING, CANCELED, FINISHED } |
Job's states. More... | |
Typedef used in IJob | |
typedef std::shared_ptr< ::fwJobs::IJob > | sptr |
Cancel request callback type. | |
typedef std::weak_ptr< ::fwJobs::IJob > | wptr |
Cancel request callback type. | |
typedef std::function< bool() > | CancelRequestCallback |
Cancel request callback type. | |
typedef std::function< void(IJob &) > | JobCancelHook |
Job cancel callback type for cancel hook. | |
typedef std::function< void(IJob &, const std::string &) > | LogHook |
Log callback type for log hook. | |
typedef std::function< void(IJob &, std::uint64_t) > | DoneWorkHook |
Done work callback type for done work hook. | |
typedef std::function< void(IJob &, std::uint64_t) > | TotalWorkUnitsHook |
Work units callback type for total work unit hook. | |
typedef std::function< void() > | CancelHook |
Cancel callback type for cancel hook. | |
typedef std::function< void(State) > | StateHook |
State callback type for state hook. | |
typedef std::vector< JobCancelHook > | CancelHookSeq |
Job cancel callback sequence type for cancel hook. | |
typedef std::vector< DoneWorkHook > | DoneWorkHookSeq |
Done work callback sequence type for done work hook. | |
typedef std::vector< TotalWorkUnitsHook > | TotalWorkUnitsHookSeq |
Work units callback sequence type for total work unit hook. | |
typedef std::vector< LogHook > | LogHookSeq |
Log callback sequence type for log hook. | |
typedef std::vector< StateHook > | StateHookSeq |
Log callback sequence type for state hook. | |
typedef std::vector< std::string > | Logs |
Log container type. | |
typedef ::fwCom::Signal< void() > | StateSignal |
State signal type. | |
typedef ::fwCom::Signal< void() > | CancelRequestedSignal |
Cancel request signal type. | |
typedef ::fwCom::Signal< void(std::uint64_t, std::uint64_t) > | DoneWorkSignal |
Done work signal type. | |
typedef ::fwCom::Signal< void(std::string) > | LogSignal |
Log signal type. | |
typedef std::shared_future< void > | SharedFuture |
Future type. | |
Public Member Functions | |
FWJOBS_API | IJob (const std::string &name="") |
Default constructor. More... | |
virtual FWJOBS_API | ~IJob () |
Default destructor. | |
FWJOBS_API std::uint64_t | getDoneWorkUnits () const |
Getter on the number of done work units. | |
FWJOBS_API std::uint64_t | getTotalWorkUnits () const |
Getter on the total number of work units. | |
FWJOBS_API State | getState () const |
Getter on the current State. More... | |
FWJOBS_API const std::string & | getName () const |
Getter on the name of the job. | |
FWJOBS_API Logs | getLogs () const |
Getter on the log container. | |
FWJOBS_API bool | isCancelable () const |
Getter on cancelable, returns whether the job is cancelable. | |
FWJOBS_API void | setCancelable (bool cancel) |
Setter on cancelable. | |
FWJOBS_API SharedFuture | run () |
Run the current job. More... | |
FWJOBS_API void | wait () |
Wait job execution ending. More... | |
FWJOBS_API const bool & | cancelRequested () const |
Returns the job canceling status. More... | |
FWJOBS_API CancelRequestCallback | cancelRequestedCallback () const |
Returns a callback on job canceling status. This callback can only be used if the job is still instanciated. More... | |
virtual FWJOBS_API SharedFuture | cancel () |
Cancel the current job and call all available cancel callbacks. More... | |
FWJOBS_API void | addSimpleCancelHook (CancelHook callback) |
Add cancel callback to sequence for cancel hook. More... | |
FWJOBS_API void | addCancelHook (JobCancelHook callback) |
Add cancel callback to sequence for cancel hook. More... | |
FWJOBS_API void | addDoneWorkHook (DoneWorkHook callback) |
Add job done work unit callback to sequence for done work hook. More... | |
FWJOBS_API void | addTotalWorkUnitsHook (TotalWorkUnitsHook callback) |
Add job work unit callback to sequence for total work unit hook. More... | |
FWJOBS_API void | addLogHook (LogHook callback) |
Add job log callback to sequence for log hook. More... | |
FWJOBS_API void | addStateHook (StateHook callback) |
Add job state callback to sequence for state hook. More... | |
FWJOBS_API void | log (const std::string &message) |
Log a message. More... | |
Protected Member Functions | |
virtual FWJOBS_API SharedFuture | runImpl ()=0 |
Run an instanciated job. | |
virtual FWJOBS_API void | finish () |
Finish the job: set state to finished or canceled. | |
FWJOBS_API void | finishNoLock () |
Finish the job without mutex lock: set the state to finished or canceled. | |
FWJOBS_API std::function< void() > | finishCallback () |
Return callback to finish the job. More... | |
FWJOBS_API State | getStateNoLock () const |
Getter on the state without mutex lock. | |
FWJOBS_API void | setState (State state) |
Setter on the state. | |
FWJOBS_API void | setStateNoLock (State state) |
Setter on the state without mutex lock. | |
FWJOBS_API void | doneWork (std::uint64_t units) |
Setter on done work units. | |
FWJOBS_API void | doneWork (std::uint64_t units,::fwCore::mt::ReadToWriteLock &lock) |
Setter on done work units. More... | |
FWJOBS_API void | done () |
Set done work units to total work units. | |
FWJOBS_API void | setTotalWorkUnits (std::uint64_t units) |
Setter on total work units. More... | |
FWJOBS_API void | setTotalWorkUnitsUpgradeLock (std::uint64_t units,::fwCore::mt::ReadToWriteLock &lock) |
Setter on total work units. More... | |
FWJOBS_API void | addCancelHookNoLock (JobCancelHook callback) |
Add job cancel callback to sequence without mutex lock for cancel hook. More... | |
FWJOBS_API void | addDoneWorkHookNoLock (DoneWorkHook callback) |
Add job done work unit callback to sequence without mutex lock for done work hook. More... | |
FWJOBS_API void | addTotalWorkUnitsHookNoLock (TotalWorkUnitsHook callback) |
Add job work unit callback to sequence without mutex lock for total work unit hook. More... | |
FWJOBS_API void | addLogHookNoLock (LogHook callback) |
Add job log callback to sequence without mutex lock for log hook. More... | |
FWJOBS_API void | addStateHookNoLock (StateHook callback) |
Add cancel callback to sequence without mutex lock for state hook. More... | |
FWJOBS_API void | logNoLock (const std::string &message) |
Add a message to thelog sequence. More... | |
Not implemented | |
IJob (IJob &) | |
IJob & | operator= (IJob &) |
IJob (IJob &&) | |
IJob & | operator= (IJob &&) |
Protected Attributes | |
std::shared_ptr< CancelRequestedSignal > | m_sigCancelRequested |
Signal emitted when cancel has been requested. | |
std::shared_ptr< StateSignal > | m_sigCanceled |
Signal emitted when te job has been canceled. | |
std::shared_ptr< StateSignal > | m_sigStarted |
Signal emitted when the job has been started. | |
std::shared_ptr< StateSignal > | m_sigFinished |
Signal emitted when the job has been finished. | |
std::shared_ptr< DoneWorkSignal > | m_sigDoneWork |
Signal emitted when done work units have been changed. Takes a std::uint64_t as parameter. | |
std::shared_ptr< LogSignal > | m_sigLogged |
Signal emitted when a message has been added to logs. Takes a std::string as parameter. | |
mutable::fwCore::mt::ReadWriteMutex | m_mutex |
Mutex to protect object access. | |
std::string | m_name |
Job's name. | |
Logs | m_logs |
Logs container. | |
std::uint64_t | m_doneWorkUnits |
Number of work units already reached. | |
std::uint64_t | m_totalWorkUnits |
Number of work units to reach to complete the job. | |
bool | m_cancelRequested |
Determines if cancellation has been requested. The job is/will be canceling if true. | |
bool | m_cancelable |
Determines if the job can be cancelled. The job is cancelable if true. | |
CancelHookSeq | m_cancelHooks |
Container of cancel callbacks. Cancel callbacks will be run when job is canceling. | |
DoneWorkHookSeq | m_doneWorkHooks |
Container of done work callbacks. These callbacks take nothing or a IJob as parameter. | |
TotalWorkUnitsHookSeq | m_totalWorkUnitsHooks |
Container of total work unit callbacks. These callbacks take a IJob as parameter. | |
LogHookSeq | m_logHooks |
Container of log callbacks. These callbacks take a std::string as parameter. | |
StateHookSeq | m_stateHooks |
Container of state callbacks. These callbacks take a State as parameter. | |
SharedFuture | m_runFuture |
Job's future returned by 'run'. | |
State | m_state |
Job's state. | |
enum fwJobs::IJob::State |
fwJobs::IJob::IJob | ( | const std::string & | name = "" | ) |
void fwJobs::IJob::addCancelHook | ( | JobCancelHook | callback | ) |
Add cancel callback to sequence for cancel hook.
callback | job cancel callback, taking a IJob as parameter |
Definition at line 134 of file IJob.cpp.
References addCancelHookNoLock(), and m_mutex.
Referenced by addSimpleCancelHook(), and fwGdcmIO::helper::DicomSeriesDBWriter::write().
|
protected |
Add job cancel callback to sequence without mutex lock for cancel hook.
callback | job cancel callback, taking a IJob as parameter or not |
Definition at line 335 of file IJob.cpp.
References m_cancelHooks, and m_state.
Referenced by fwJobs::Aggregator::add(), and addCancelHook().
void fwJobs::IJob::addDoneWorkHook | ( | DoneWorkHook | callback | ) |
Add job done work unit callback to sequence for done work hook.
callback | job done work unit callback, taking a IJob as parameter |
Definition at line 152 of file IJob.cpp.
References addDoneWorkHookNoLock(), and m_mutex.
|
protected |
Add job done work unit callback to sequence without mutex lock for done work hook.
callback | job done work unit callback, taking a IJob as parameter |
Definition at line 345 of file IJob.cpp.
References m_doneWorkHooks, and m_state.
Referenced by addDoneWorkHook().
void fwJobs::IJob::addLogHook | ( | LogHook | callback | ) |
Add job log callback to sequence for log hook.
callback | job log callback, taking a std::string message as parameter |
Definition at line 168 of file IJob.cpp.
References addLogHookNoLock(), and m_mutex.
|
protected |
Add job log callback to sequence without mutex lock for log hook.
callback | job log callback, taking a std::string message as parameter |
Definition at line 365 of file IJob.cpp.
References m_logHooks.
Referenced by addLogHook().
void fwJobs::IJob::addSimpleCancelHook | ( | CancelHook | callback | ) |
Add cancel callback to sequence for cancel hook.
callback | cancel callback |
Definition at line 142 of file IJob.cpp.
References addCancelHook().
Referenced by fwJobs::Observer::Observer().
void fwJobs::IJob::addStateHook | ( | StateHook | callback | ) |
Add job state callback to sequence for state hook.
callback | job state callback, taking a State as parameter |
Definition at line 176 of file IJob.cpp.
References addStateHookNoLock(), and m_mutex.
|
protected |
Add cancel callback to sequence without mutex lock for state hook.
callback | cancel callback, taking a State as parameter |
Definition at line 372 of file IJob.cpp.
References m_stateHooks.
Referenced by addStateHook().
void fwJobs::IJob::addTotalWorkUnitsHook | ( | TotalWorkUnitsHook | callback | ) |
Add job work unit callback to sequence for total work unit hook.
callback | job work unit callback, taking a IJob as parameter |
Definition at line 160 of file IJob.cpp.
References addTotalWorkUnitsHookNoLock(), and m_mutex.
|
protected |
Add job work unit callback to sequence without mutex lock for total work unit hook.
callback | job work unit callback, taking a IJob as parameter |
Definition at line 355 of file IJob.cpp.
References m_state, and m_totalWorkUnitsHooks.
Referenced by addTotalWorkUnitsHook().
|
virtual |
Cancel the current job and call all available cancel callbacks.
Reimplemented in fwJobs::Job.
Definition at line 87 of file IJob.cpp.
References m_cancelable, m_cancelHooks, m_cancelRequested, m_mutex, m_runFuture, m_state, setStateNoLock(), and SLM_ASSERT.
Referenced by fwJobs::Job::cancel(), setCancelable(), and gui::editor::SJobBar::showJob().
const bool & fwJobs::IJob::cancelRequested | ( | ) | const |
Returns the job canceling status.
Definition at line 52 of file IJob.cpp.
References m_cancelRequested.
Referenced by ioAtoms::SWriter::updating(), ioAtoms::SReader::updating(), and fwGdcmIO::helper::DicomSeriesDBWriter::write().
IJob::CancelRequestCallback fwJobs::IJob::cancelRequestedCallback | ( | ) | const |
Returns a callback on job canceling status. This callback can only be used if the job is still instanciated.
Definition at line 60 of file IJob.cpp.
References m_cancelRequested, and m_mutex.
|
protected |
Setter on done work units.
lock
in an unlocked stateunits | new done work units |
lock | mutex to upgrade to write lock |
Definition at line 387 of file IJob.cpp.
References m_doneWorkHooks, m_doneWorkUnits, m_sigDoneWork, and m_totalWorkUnits.
|
protected |
Return callback to finish the job.
Definition at line 278 of file IJob.cpp.
References finish().
Referenced by fwJobs::Job::runImpl().
IJob::State fwJobs::IJob::getState | ( | ) | const |
void fwJobs::IJob::log | ( | const std::string & | message | ) |
Log a message.
Push the message in the log container and emit a logged signal with log as parameter. finally call all log callbacks
log | the message to log |
Definition at line 305 of file IJob.cpp.
References logNoLock(), and m_mutex.
Referenced by fwJobs::Aggregator::add(), and fwGdcmIO::helper::DicomSeriesDBWriter::write().
|
protected |
Add a message to thelog sequence.
message | the message to add to the sequence |
Definition at line 313 of file IJob.cpp.
References m_logHooks, m_logs, and m_sigLogged.
Referenced by fwJobs::Aggregator::add(), and log().
IJob::SharedFuture fwJobs::IJob::run | ( | ) |
Run the current job.
Definition at line 199 of file IJob.cpp.
References m_mutex, m_runFuture, m_state, runImpl(), and setStateNoLock().
Referenced by fwJobs::Observer::Observer().
|
protected |
Setter on total work units.
units | New total for work units. |
Definition at line 417 of file IJob.cpp.
References m_mutex, and setTotalWorkUnitsUpgradeLock().
|
protected |
Setter on total work units.
lock
in an unlocked stateunits | new total work units |
lock | mutex to upgrade to write lock |
Definition at line 425 of file IJob.cpp.
References doneWork(), m_doneWorkUnits, m_totalWorkUnits, and m_totalWorkUnitsHooks.
Referenced by fwJobs::Aggregator::add(), and setTotalWorkUnits().
void fwJobs::IJob::wait | ( | ) |
Wait job execution ending.
This method raise a fwJobs::exception::Waiting Exception if the job is not running.
Definition at line 285 of file IJob.cpp.
References m_mutex, and m_runFuture.