fw4spl
fwJobs::Aggregator Class Reference

This class manages an aggregation of IJob. More...

#include <Aggregator.hpp>

+ Inheritance diagram for fwJobs::Aggregator:
+ Collaboration diagram for fwJobs::Aggregator:

Public Types

Typedefs
typedef std::shared_ptr< ::fwJobs::Aggregatorsptr
 Aggregator container type.
 
typedef std::weak_ptr< ::fwJobs::Aggregatorwptr
 Aggregator container type.
 
typedef ::boost::multi_index_container< ::fwJobs::IJob::sptr,::boost::multi_index::indexed_by< ::boost::multi_index::random_access<>,::boost::multi_index::hashed_unique< ::boost::multi_index::identity< ::fwJobs::IJob::sptr > > > > IJobSeq
 Aggregator container 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 Aggregator ()
 Default constructor. The name is initialized with an empty string.
 
FWJOBS_API Aggregator (const std::string &name)
 Constructor. More...
 
FWJOBS_API void add (const ::fwJobs::IJob::sptr &iJob, double weight=1.)
 Add an IJob to the Aggregator. More...
 
FWJOBS_API IJobSeq getSubJobs ()
 Retrieve sub job sequence of the Aggregator. 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="")
 Create a new Aggregator smart pointer. More...
 

Protected Member Functions

FWJOBS_API SharedFuture runImpl ()
 Run all the jobs of the Aggregator. 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 manages an aggregation of IJob.

Definition at line 32 of file Aggregator.hpp.

Constructor & Destructor Documentation

fwJobs::Aggregator::Aggregator ( const std::string &  name)

Constructor.

Parameters
nameThe job's name

Definition at line 37 of file Aggregator.cpp.

Member Function Documentation

void fwJobs::Aggregator::add ( const ::fwJobs::IJob::sptr iJob,
double  weight = 1. 
)

Add an IJob to the Aggregator.

Warning
Be careful not to add an aggregator to itself, directly or indirectly (through other aggregators for instance).
Parameters
iJobthe IJob to add to the Aggregator
weightadded IJob's weight. Avoid values lower than 0.01

Definition at line 79 of file Aggregator.cpp.

References fwJobs::IJob::addCancelHookNoLock(), fwJobs::IJob::doneWork(), fwJobs::IJob::getTotalWorkUnits(), fwJobs::IJob::log(), fwJobs::IJob::logNoLock(), fwJobs::IJob::m_doneWorkUnits, fwJobs::IJob::m_mutex, fwJobs::IJob::m_state, fwJobs::IJob::m_totalWorkUnits, fwJobs::IJob::setTotalWorkUnitsUpgradeLock(), and SLM_ASSERT.

+ Here is the call graph for this function:

Aggregator::IJobSeq fwJobs::Aggregator::getSubJobs ( )

Retrieve sub job sequence of the Aggregator.

Returns
The job aggregator container

Definition at line 182 of file Aggregator.cpp.

References fwJobs::IJob::m_mutex.

Aggregator::sptr fwJobs::Aggregator::New ( const std::string &  name = "")
static

Create a new Aggregator smart pointer.

Parameters
nameThe job's name
Returns
A pointer to a new Aggregator

Definition at line 24 of file Aggregator.cpp.

Referenced by ioAtoms::SWriter::updating(), and ioAtoms::SReader::updating().

+ Here is the caller graph for this function:

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

Run all the jobs of the Aggregator.

Returns
future of all the IJobs of the Aggregator

Implements fwJobs::IJob.

Definition at line 44 of file Aggregator.cpp.

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

+ Here is the call graph for this function:


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