fw4spl
fwThread::Worker Class Referenceabstract

This class creates and manages a task loop. The default implementation create a loop in a new thread. More...

#include <Worker.hpp>

+ Inheritance diagram for fwThread::Worker:
+ Collaboration diagram for fwThread::Worker:

Public Types

typedef ::fwCore::HiResClock::HiResClockType PeriodType
 
typedef std::function< void() > TaskType
 
typedef ::boost::any ExitReturnType
 
typedef std::shared_future< ExitReturnType > FutureType
 

Public Member Functions

virtual bool isA (const std::string &type) const override
 
virtual FWTHREAD_API void stop ()=0
 Waits for the last task to be processed and stops the loop.
 
virtual void post (TaskType handler)=0
 Requests invocation of the given task handler and returns immediately.
 
template<typename R , typename CALLABLE >
std::shared_future< R > postTask (CALLABLE f)
 Requests invocation of the given callable and returns a shared future. More...
 
virtual FWTHREAD_API ThreadIdType getThreadId () const =0
 Returns the worker's thread id.
 
virtual FWTHREAD_API std::shared_ptr< ::fwThread::TimercreateTimer ()=0
 Creates and returns a fwThread::Timer running in this Worker.
 
virtual FutureType getFuture ()
 Returns a std::shared_future associated with the execution of Worker's loop. More...
 
virtual FWTHREAD_API void processTasks (PeriodType maxtime)=0
 Processes worker pending tasks for the calling thread for maxtime milliseconds or until there are no more tasks to process. You can call this function occasionally when your program is busy performing a long operation. More...
 
virtual FWTHREAD_API void processTasks ()=0
 Processes all worker pending tasks for the calling thread until there are no more tasks to process. You can call this function occasionally when your program is busy performing a long operation. More...
 
template<typename R , typename TASK >
std::shared_future< R > postTask (TASK f)
 
- Public Member Functions inherited from fwCore::BaseObject

Static Public Member Functions

static bool isTypeOf (const std::string &type)
 
- Static Public Member Functions inherited from fwCore::BaseObject
static bool isTypeOf (const std::string &type)
 
static const std::string & leafClassname ()
 return object's classname without its namespace, i.e. BaseObject
 
static const std::string & classname ()
 return object's classname without its namespace, i.e. BaseObject
 

Protected Member Functions

 Worker (const Worker &)
 Copy constructor forbidden.
 
Workeroperator= (const Worker &)
 Copy operator forbidden.
 

Static Protected Member Functions

static FWTHREAD_API std::shared_ptr< WorkerdefaultFactory ()
 

Protected Attributes

FutureType m_future
 Worker's loop future.
 

Friends

template<class , class , class >
class ::fwTools::ClassFactory
 
class ::fwTools::Factory
 

Demangling methods

virtual const std::string & getLeafClassname () const override
 return object's classname without its namespace, i.e. BaseObject
 
virtual const std::string & getClassname () const override
 return full object's classname with its namespace, i.e. fwCore::BaseObject
 
static const std::string & leafClassname ()
 return object's classname without its namespace, i.e. BaseObject
 
static const std::string & classname ()
 return object's classname without its namespace, i.e. BaseObject
 

Detailed Description

This class creates and manages a task loop. The default implementation create a loop in a new thread.

Definition at line 32 of file Worker.hpp.

Member Function Documentation

std::shared_ptr< Worker > fwThread::Worker::defaultFactory ( )
staticprotected

Creates and returns a new instance of Worker default implementation (boost::Asio).

Definition at line 216 of file WorkerAsio.cpp.

virtual FutureType fwThread::Worker::getFuture ( )
inlinevirtual

Returns a std::shared_future associated with the execution of Worker's loop.

Warning
Calling getFuture() may be blocking if it is required by a specific implementation (for example, the Qt implementation).

Reimplemented in fwGuiQt::WorkerQt.

Definition at line 78 of file Worker.hpp.

References SPTR.

template<typename R , typename CALLABLE >
std::shared_future< R > fwThread::Worker::postTask ( CALLABLE  f)

Requests invocation of the given callable and returns a shared future.

Returns immediately if called from another thread. Otherwise, the given callable is called immediately.

Template Parameters
Rfuture's value type
CALLABLEAny type wrappable with a boost::function< void() >
Returns
a std::shared_future associated with the result of the given callable
virtual FWTHREAD_API void fwThread::Worker::processTasks ( PeriodType  maxtime)
pure virtual

Processes worker pending tasks for the calling thread for maxtime milliseconds or until there are no more tasks to process. You can call this function occasionally when your program is busy performing a long operation.

Parameters
maxtimemilliseconds to process worker pending tasks.
Warning
Qt implementation processes all Qt and Worker pending events, be careful.
WxWidgets version is not yet implemented.

Implemented in fwGuiQt::WorkerQt, and fwThread::WorkerAsio.

virtual FWTHREAD_API void fwThread::Worker::processTasks ( )
pure virtual

Processes all worker pending tasks for the calling thread until there are no more tasks to process. You can call this function occasionally when your program is busy performing a long operation.

Warning
WxWidgets version is not yet implemented.

Implemented in fwGuiQt::WorkerQt, and fwThread::WorkerAsio.


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