fw4spl
fwJobs::Job Class Reference

This class encapsulate a task that will report it's progression The embeded task will be run at most once. Once the job is finished or has been canceled, the job (thus the task) will not be run anymore) More...

#include <Job.hpp>

+ Inheritance diagram for fwJobs::Job:
+ Collaboration diagram for fwJobs::Job:

Public Types

Typedefs
typedef std::shared_ptr< ::fwJobs::Jobsptr
 Task type.
 
typedef std::weak_ptr< ::fwJobs::Jobwptr
 Task type.
 
typedef std::function< void(Job &) > Task
 Task type.
 
typedef std::function< void(std::uint64_t) > ProgressCallback
 Progress callback type.
 
- Public Types inherited from fwJobs::IJob
enum  State {
  WAITING = 0, RUNNING, CANCELING, CANCELED,
  FINISHED
}
 Job's states. More...
 
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 Job (const std::string &name, Task task, const std::shared_ptr< ::fwThread::Worker > &worker=nullptr)
 Construct a new job. More...
 
FWJOBS_API ProgressCallback progressCallback ()
 Return a job callback with the done work number as parameter This callback can only be used if the job is still instantiated.
 
FWJOBS_API std::shared_ptr< ::fwThread::WorkergetWorker ()
 Getter on the current job worker or nullptr if no worker has been set.
 
virtual FWJOBS_API SharedFuture cancel ()
 Reimplements IJob's cancel.
 
- Public Member Functions inherited from fwJobs::IJob
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...
 
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...
 

Static Public Member Functions

static FWJOBS_API sptr New (const std::string &name, Task task, const std::shared_ptr< ::fwThread::Worker > &worker=nullptr)
 Construct a new job and return a smart pointer of it. More...
 

Protected Member Functions

FWJOBS_API SharedFuture runImpl ()
 Run the task of the job and mark the job as finished. More...
 
- Protected Member Functions inherited from fwJobs::IJob
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...
 
 IJob (IJob &)
 
IJoboperator= (IJob &)
 
 IJob (IJob &&)
 
IJoboperator= (IJob &&)
 

Additional Inherited Members

- Protected Attributes inherited from fwJobs::IJob
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 encapsulate a task that will report it's progression The embeded task will be run at most once. Once the job is finished or has been canceled, the job (thus the task) will not be run anymore)

Definition at line 30 of file Job.hpp.

Constructor & Destructor Documentation

fwJobs::Job::Job ( const std::string &  name,
Task  task,
const std::shared_ptr< ::fwThread::Worker > &  worker = nullptr 
)

Construct a new job.

Parameters
namename of the new job
taskThe task managed by the job
fwThread::WorkerAn optional worker to run the task on

Definition at line 32 of file Job.cpp.

References fwJobs::IJob::m_totalWorkUnits.

Member Function Documentation

Job::sptr fwJobs::Job::New ( const std::string &  name,
Task  task,
const std::shared_ptr< ::fwThread::Worker > &  worker = nullptr 
)
static

Construct a new job and return a smart pointer of it.

Parameters
namename of the new job
taskThe task managed by the job
fwThread::WorkerAn optional worker to run the task on
Returns

Definition at line 25 of file Job.cpp.

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

+ Here is the caller graph for this function:

IJob::SharedFuture fwJobs::Job::runImpl ( )
protectedvirtual

Run the task of the job and mark the job as finished.

Returns
future of the task

Implements fwJobs::IJob.

Definition at line 42 of file Job.cpp.

References fwJobs::IJob::finish(), fwJobs::IJob::finishCallback(), and fwJobs::IJob::m_mutex.

+ Here is the call graph for this function:


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