Skip to content

BaseWorker

template <typename T> class BaseWorker

WorkerBase class contains one queue: request and can start auxiliary thread that will run on opposite end of the queue: Main thread Queue Auxiliary thread Methods push(...) --> request --> receive(...)

Functions

Name Description
BaseWorker Construct worker with callback and time and repetition parameters callback : this function will be called periodically timeout : time in milliseconds auxiliary thread is waiting on the request queue; 0 means nowait mode; ,-1 means waiting forever repetition : -1 means cycling forever; >0 means number of cycles.
set Set parameters defining the behavior of the worker callback : function to be called will boolean parameter signaling repetition counter expiration timeout : timeout for receiving from queue repetition : repetition counter
setTimeout Set parameters defining the behavior of the worker timeout : timeout for receiving from queue
setRepetition Set parameters defining the behavior of the worker repetition : repetition counter
start Starts auxiliary thread that works on far ends of the queues Default settings are "waiting forever" and "repeat forever"
stop Stop thread activity.
abort This function stops thread immediately despite the fact like nonempty queue.
join It will block until the auxiliary thread is joined.
push Call this function from the main thread to put new data block to the request queue t : data of type T to put into the request queue
run Receive data block of type T from request queue.

Function Details

BaseWorker

BaseWorker(const std::function<void()>& callback, int timeout = -1, int repetition = -1)

Construct worker with callback and time and repetition parameters

callback : this function will be called periodically

timeout : time in milliseconds auxiliary thread is waiting on the request queue; 0 means nowait mode; ,-1 means waiting forever

repetition : -1 means cycling forever; >0 means number of cycles.

abort

BaseWorker& abort()

This function stops thread immediately despite the fact like nonempty queue.

join

void join()

It will block until the auxiliary thread is joined.

push

void push(const T& t)

Call this function from the main thread to put new data block to the request queue

t : data of type T to put into the request queue

run

void run()

Receive data block of type T from request queue. The behavior is defined by two parameters: m_timeout and m_repetition. In case of successful receiving the m_callback function will be called.

set

BaseWorker& set(const std::function<void()>& callback, int timeout = -1, int repetition = -1)

Set parameters defining the behavior of the worker

callback : function to be called will boolean parameter signaling repetition counter expiration

timeout : timeout for receiving from queue

repetition : repetition counter

setRepetition

BaseWorker& setRepetition(int repetition = -1)

Set parameters defining the behavior of the worker

repetition : repetition counter

setTimeout

BaseWorker& setTimeout(int timeout = -1)

Set parameters defining the behavior of the worker

timeout : timeout for receiving from queue

start

BaseWorker& start()

Starts auxiliary thread that works on far ends of the queues Default settings are "waiting forever" and "repeat forever"

stop

BaseWorker& stop()

Stop thread activity. If "request" queue still has some entries they will be received before thread exits. After requesting a stop the new entries can not be put (just ignored) into request queue.