RunningTaskBase Class Reference

#include <ArmarXCore/core/services/tasks/RunningTask.h>

+ Inheritance diagram for RunningTaskBase:

Classes

struct  Impl
 

Public Types

using CallbackT = std::function< void()>
 

Public Member Functions

std::string getName () const
 
bool isFinished () const
 Retrieve finished state of the thread. More...
 
bool isRunning () const
 Retrieve running state of the thread. More...
 
bool isStopped ()
 Retrieve whether stop() has been called. More...
 
void join ()
 Wait for the RunningTask to finish without telling it to finish. More...
 
 RunningTaskBase (std::string const &name)
 
template<typename T >
 RunningTaskBase (T *parent, void(T::*runningFn)(), const std::string &name="")
 Constructs a running task within the class parent which calls the runningFn in a new thread. More...
 
void setName (const std::string &name)
 
void setThreadList (ThreadListPtr threadList)
 
void start ()
 Starts the thread. More...
 
void stop (bool waitForJoin=true)
 Stops the thread. More...
 
bool waitForFinished (int timeoutMS=-1)
 wait blocking for thread to be finished. More...
 
void waitForStop ()
 Wait blocking for thread until stop() has been called. More...
 
 ~RunningTaskBase () override
 Destructor stops the thread and waits for completion. More...
 

Public Attributes

CallbackT callback
 

Detailed Description

Definition at line 41 of file RunningTask.h.

Member Typedef Documentation

◆ CallbackT

using CallbackT = std::function<void()>

Definition at line 46 of file RunningTask.h.

Constructor & Destructor Documentation

◆ RunningTaskBase() [1/2]

RunningTaskBase ( std::string const &  name)

Definition at line 29 of file RunningTask.cpp.

+ Here is the call graph for this function:

◆ RunningTaskBase() [2/2]

RunningTaskBase ( T parent,
void(T::*)()  runningFn,
const std::string &  name = "" 
)
inline

Constructs a running task within the class parent which calls the runningFn in a new thread.

Parameters
nameof this thread, that describes what it is doing. If string is empty, it will use the name of the class with RTTI

Definition at line 60 of file RunningTask.h.

◆ ~RunningTaskBase()

~RunningTaskBase ( )
override

Destructor stops the thread and waits for completion.

Definition at line 40 of file RunningTask.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ getName()

std::string getName ( ) const

Definition at line 195 of file RunningTask.cpp.

◆ isFinished()

bool isFinished ( ) const

Retrieve finished state of the thread.

The task is finished once the thread has joined.

Returns
finished state

Definition at line 151 of file RunningTask.cpp.

+ Here is the caller graph for this function:

◆ isRunning()

bool isRunning ( ) const

Retrieve running state of the thread.

The task is running when it is started until the thread method joints.

Returns
running state

Definition at line 146 of file RunningTask.cpp.

+ Here is the caller graph for this function:

◆ isStopped()

bool isStopped ( )

Retrieve whether stop() has been called.

Has to be handled in thread function implementation for proper exit.

Returns
stopped state

Definition at line 178 of file RunningTask.cpp.

+ Here is the caller graph for this function:

◆ join()

void join ( )

Wait for the RunningTask to finish without telling it to finish.

Definition at line 136 of file RunningTask.cpp.

◆ setName()

void setName ( const std::string &  name)

Definition at line 45 of file RunningTask.cpp.

+ Here is the caller graph for this function:

◆ setThreadList()

void setThreadList ( ThreadListPtr  threadList)

Definition at line 50 of file RunningTask.cpp.

+ Here is the call graph for this function:

◆ start()

void start ( )

Starts the thread.

Only has effect if the task has not been started. After completion of the task, it cannot be started again.

Definition at line 60 of file RunningTask.cpp.

+ Here is the call graph for this function:

◆ stop()

void stop ( bool  waitForJoin = true)

Stops the thread.

Only has effect if the task has been started.

Parameters
waitForJoinwait for the thread to terminate and join with the process.

Definition at line 83 of file RunningTask.cpp.

+ Here is the caller graph for this function:

◆ waitForFinished()

bool waitForFinished ( int  timeoutMS = -1)

wait blocking for thread to be finished.

The task is finished once the thread has joined.

Parameters
timeoutMStimeout in milliseconds. If -1 there is no timeout.
Returns
returns true if the task finished in the given time interval

Definition at line 156 of file RunningTask.cpp.

+ Here is the call graph for this function:

◆ waitForStop()

void waitForStop ( )

Wait blocking for thread until stop() has been called.

Can be used for blocking wait for stop in thread function implementation

Definition at line 184 of file RunningTask.cpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ callback

CallbackT callback

Definition at line 48 of file RunningTask.h.


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