fw4spl
fwJobs::IJob Class Referenceabstract

This class is an interface for class managing job. More...

#include <IJob.hpp>

+ Inheritance diagram for fwJobs::IJob:
+ Collaboration diagram for fwJobs::IJob:

Public Types

enum  State {
  WAITING = 0, RUNNING, CANCELING, CANCELED,
  FINISHED
}
 Job's states. More...
 
Typedef used in IJob
typedef std::shared_ptr< ::fwJobs::IJobsptr
 Cancel request callback type.
 
typedef std::weak_ptr< ::fwJobs::IJobwptr
 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< JobCancelHookCancelHookSeq
 Job cancel callback sequence type for cancel hook.
 
typedef std::vector< DoneWorkHookDoneWorkHookSeq
 Done work callback sequence type for done work hook.
 
typedef std::vector< TotalWorkUnitsHookTotalWorkUnitsHookSeq
 Work units callback sequence type for total work unit hook.
 
typedef std::vector< LogHookLogHookSeq
 Log callback sequence type for log hook.
 
typedef std::vector< StateHookStateHookSeq
 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 &)
 
IJoboperator= (IJob &)
 
 IJob (IJob &&)
 
IJoboperator= (IJob &&)
 

Protected Attributes

std::shared_ptr< CancelRequestedSignalm_sigCancelRequested
 Signal emitted when cancel has been requested.
 
std::shared_ptr< StateSignalm_sigCanceled
 Signal emitted when te job has been canceled.
 
std::shared_ptr< StateSignalm_sigStarted
 Signal emitted when the job has been started.
 
std::shared_ptr< StateSignalm_sigFinished
 Signal emitted when the job has been finished.
 
std::shared_ptr< DoneWorkSignalm_sigDoneWork
 Signal emitted when done work units have been changed. Takes a std::uint64_t as parameter.
 
std::shared_ptr< LogSignalm_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.
 

Detailed Description

This class is an interface for class managing job.

Definition at line 28 of file IJob.hpp.

Member Enumeration Documentation

Job's states.

State :

  • WAITING : The job is ready to be used
  • RUNNING : The job is currently running
  • CANCELING : The job received a cancel request
  • CANCELED : The job is canceled
  • FINISHED : The job have finished to run his task

Definition at line 42 of file IJob.hpp.

Constructor & Destructor Documentation

fwJobs::IJob::IJob ( const std::string &  name = "")

Default constructor.

Parameters
nameThe name of the job.

Definition at line 23 of file IJob.cpp.

Member Function Documentation

void fwJobs::IJob::addCancelHook ( JobCancelHook  callback)

Add cancel callback to sequence for cancel hook.

Parameters
callbackjob 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fwJobs::IJob::addCancelHookNoLock ( JobCancelHook  callback)
protected

Add job cancel callback to sequence without mutex lock for cancel hook.

Parameters
callbackjob 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().

+ Here is the caller graph for this function:

void fwJobs::IJob::addDoneWorkHook ( DoneWorkHook  callback)

Add job done work unit callback to sequence for done work hook.

Parameters
callbackjob done work unit callback, taking a IJob as parameter

Definition at line 152 of file IJob.cpp.

References addDoneWorkHookNoLock(), and m_mutex.

+ Here is the call graph for this function:

void fwJobs::IJob::addDoneWorkHookNoLock ( DoneWorkHook  callback)
protected

Add job done work unit callback to sequence without mutex lock for done work hook.

Parameters
callbackjob 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().

+ Here is the caller graph for this function:

void fwJobs::IJob::addLogHook ( LogHook  callback)

Add job log callback to sequence for log hook.

Parameters
callbackjob log callback, taking a std::string message as parameter

Definition at line 168 of file IJob.cpp.

References addLogHookNoLock(), and m_mutex.

+ Here is the call graph for this function:

void fwJobs::IJob::addLogHookNoLock ( LogHook  callback)
protected

Add job log callback to sequence without mutex lock for log hook.

Parameters
callbackjob log callback, taking a std::string message as parameter

Definition at line 365 of file IJob.cpp.

References m_logHooks.

Referenced by addLogHook().

+ Here is the caller graph for this function:

void fwJobs::IJob::addSimpleCancelHook ( CancelHook  callback)

Add cancel callback to sequence for cancel hook.

Parameters
callbackcancel callback

Definition at line 142 of file IJob.cpp.

References addCancelHook().

Referenced by fwJobs::Observer::Observer().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fwJobs::IJob::addStateHook ( StateHook  callback)

Add job state callback to sequence for state hook.

Parameters
callbackjob state callback, taking a State as parameter

Definition at line 176 of file IJob.cpp.

References addStateHookNoLock(), and m_mutex.

+ Here is the call graph for this function:

void fwJobs::IJob::addStateHookNoLock ( StateHook  callback)
protected

Add cancel callback to sequence without mutex lock for state hook.

Parameters
callbackcancel callback, taking a State as parameter

Definition at line 372 of file IJob.cpp.

References m_stateHooks.

Referenced by addStateHook().

+ Here is the caller graph for this function:

void fwJobs::IJob::addTotalWorkUnitsHook ( TotalWorkUnitsHook  callback)

Add job work unit callback to sequence for total work unit hook.

Parameters
callbackjob work unit callback, taking a IJob as parameter

Definition at line 160 of file IJob.cpp.

References addTotalWorkUnitsHookNoLock(), and m_mutex.

+ Here is the call graph for this function:

void fwJobs::IJob::addTotalWorkUnitsHookNoLock ( TotalWorkUnitsHook  callback)
protected

Add job work unit callback to sequence without mutex lock for total work unit hook.

Parameters
callbackjob 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().

+ Here is the caller graph for this function:

IJob::SharedFuture fwJobs::IJob::cancel ( )
virtual

Cancel the current job and call all available cancel callbacks.

Returns
A future on the current running job or an empty future if the job is canceled

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const bool & fwJobs::IJob::cancelRequested ( ) const

Returns the job canceling status.

Returns
A boolean: true if cancel have been requested.

Definition at line 52 of file IJob.cpp.

References m_cancelRequested.

Referenced by ioAtoms::SWriter::updating(), ioAtoms::SReader::updating(), and fwGdcmIO::helper::DicomSeriesDBWriter::write().

+ Here is the caller graph for this function:

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.

Returns
A callback to check if the job have been requested.

Definition at line 60 of file IJob.cpp.

References m_cancelRequested, and m_mutex.

void fwJobs::IJob::doneWork ( std::uint64_t  units,
::fwCore::mt::ReadToWriteLock lock 
)
protected

Setter on done work units.

Warning
This method leaves lock in an unlocked state
Parameters
unitsnew done work units
lockmutex to upgrade to write lock

Definition at line 387 of file IJob.cpp.

References m_doneWorkHooks, m_doneWorkUnits, m_sigDoneWork, and m_totalWorkUnits.

std::function< void() > fwJobs::IJob::finishCallback ( )
protected

Return callback to finish the job.

Returns
A callback

Definition at line 278 of file IJob.cpp.

References finish().

Referenced by fwJobs::Job::runImpl().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

IJob::State fwJobs::IJob::getState ( ) const

Getter on the current State.

See also
State

Definition at line 184 of file IJob.cpp.

References m_mutex, and m_state.

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

Parameters
logthe 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fwJobs::IJob::logNoLock ( const std::string &  message)
protected

Add a message to thelog sequence.

Parameters
messagethe 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().

+ Here is the caller graph for this function:

IJob::SharedFuture fwJobs::IJob::run ( )

Run the current job.

Returns
future on the current running job

Definition at line 199 of file IJob.cpp.

References m_mutex, m_runFuture, m_state, runImpl(), and setStateNoLock().

Referenced by fwJobs::Observer::Observer().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fwJobs::IJob::setTotalWorkUnits ( std::uint64_t  units)
protected

Setter on total work units.

Parameters
unitsNew total for work units.

Definition at line 417 of file IJob.cpp.

References m_mutex, and setTotalWorkUnitsUpgradeLock().

+ Here is the call graph for this function:

void fwJobs::IJob::setTotalWorkUnitsUpgradeLock ( std::uint64_t  units,
::fwCore::mt::ReadToWriteLock lock 
)
protected

Setter on total work units.

Warning
This method leaves lock in an unlocked state
Parameters
unitsnew total work units
lockmutex 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.


The documentation for this class was generated from the following files: