fw4spl
fwJobs::Observer Class Reference

This class manages a job. More...

#include <Observer.hpp>

+ Inheritance diagram for fwJobs::Observer:
+ Collaboration diagram for fwJobs::Observer:

Public Types

Typedefs
typedef std::shared_ptr< ::fwJobs::Observersptr
 Progress callback type.
 
typedef std::weak_ptr< ::fwJobs::Observerwptr
 Progress callback 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 Observer (const std::string &name, std::uint64_t workUnits=100)
 Constructor. More...
 
FWJOBS_API void finish ()
 Call for finishing observer progress.
 
FWJOBS_API ProgressCallback progressCallback ()
 return a progress Callback function. This function takes work units in parameter. More...
 
- 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...
 
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...
 

Static Public Member Functions

static FWJOBS_API sptr New (const std::string &name, std::uint64_t workUnits=100)
 Create a new Observer sptr with a name. More...
 

Protected Types

typedef std::packaged_task< void() > PackagedTask
 Task type.
 

Protected Member Functions

virtual FWJOBS_API SharedFuture runImpl ()
 Runs the task. More...
 
- Protected Member Functions inherited from fwJobs::IJob
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 &&)
 

Protected Attributes

PackagedTask m_finishTask
 Task observed.
 
- 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 manages a job.

Definition at line 22 of file Observer.hpp.

Constructor & Destructor Documentation

fwJobs::Observer::Observer ( const std::string &  name,
std::uint64_t  workUnits = 100 
)

Constructor.

Parameters
nameThe job name

Definition at line 21 of file Observer.cpp.

References fwJobs::IJob::addSimpleCancelHook(), finish(), fwJobs::IJob::finishNoLock(), m_finishTask, fwJobs::IJob::m_mutex, fwJobs::IJob::m_totalWorkUnits, and fwJobs::IJob::run().

+ Here is the call graph for this function:

Member Function Documentation

Observer::sptr fwJobs::Observer::New ( const std::string &  name,
std::uint64_t  workUnits = 100 
)
static

Create a new Observer sptr with a name.

Parameters
nameThe name of the job
Returns
A pointer to a new Observer

Definition at line 14 of file Observer.cpp.

Observer::ProgressCallback fwJobs::Observer::progressCallback ( )

return a progress Callback function. This function takes work units in parameter.

Warning
This callback can only be used if the job is still instantiated.

Definition at line 40 of file Observer.cpp.

References fwJobs::IJob::doneWork().

+ Here is the call graph for this function:

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

Runs the task.

Returns
future of the task

Implements fwJobs::IJob.

Definition at line 62 of file Observer.cpp.

References m_finishTask, and fwJobs::IJob::m_mutex.


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