Workspace 6.21.5
Public Types | Signals | Public Member Functions | Protected Slots | Protected Member Functions | List of all members
SignalDrivenBlockingTask Class Reference

Start a task in a specific thread and wait for a task finished signal. More...

#include <Workspace/Application/System/signaldrivenblockingtask.h>

Inheritance diagram for SignalDrivenBlockingTask:
[legend]

Public Types

enum  State { Running , Aborted , Finished }
 

Signals

void taskAborted ()
 
void taskFinished ()
 
- Signals inherited from BlockingTask
void performTask (bool *result)
 

Public Member Functions

bool doTaskAndAwaitSignal ()
 
State state () const
 
- Public Member Functions inherited from BlockingTask
 ~BlockingTask () override
 
bool doTask ()
 

Protected Slots

void onTaskAborted ()
 
void onTaskFinished ()
 
- Protected Slots inherited from BlockingTask
virtual void taskWrapper (bool *result)
 

Protected Member Functions

 SignalDrivenBlockingTask (QThread *homeThread=QThread::currentThread())
 
 ~SignalDrivenBlockingTask () override
 
- Protected Member Functions inherited from BlockingTask
 BlockingTask (QThread *homeThread=QThread::currentThread())
 
QSemaphore & semaphore ()
 
virtual bool task ()=0
 

Additional Inherited Members

- Static Public Member Functions inherited from BlockingTask
static bool doTask (std::function< bool()> &&work, QThread *homeThread=QCoreApplication::instance() ->thread())
 

Detailed Description

This class is similar to a BlockingTask, but rather than returning as soon as the task is finished, it waits for the taskFinished signal to be emitted before returning. This makes it suitable for tasks such as running a modeless dialog box where the execution thread needs to be blocked while awaiting a response, yet the gui thread should remain responsive.

This is not suitable for blocking the calling thread, as the calling thread would not be able to unblock it. In this case, the task would return straight away - you can test for this as the state would be Running rather than Finished or Aborted

The user is responsible for ensuring that the taskFinished (or taskAborted) signal is emitted: if not, the home thread is paused indefinitely. For example, in the case of a dialogue box where the execution thread is waiting for a response, you could create a modeless dialog box in task() and connect the QDialog accepted or finished signal to the SignalDrivenBlockingTask taskFinished signal

Member Enumeration Documentation

◆ State

enum State
Enumerator
Running 

Task has started but neither taskFinished nor taskAborted signal has been received.

Aborted 

The taskAborted signal has been received.

Finished 

The taskFinished signal has been received.

Constructor & Destructor Documentation

◆ SignalDrivenBlockingTask()

SignalDrivenBlockingTask ( QThread *  homeThread = QThread::currentThread())
protected

◆ ~SignalDrivenBlockingTask()

~SignalDrivenBlockingTask ( )
overrideprotected

The destructor should never be invoked while there is a running task.

Member Function Documentation

◆ doTaskAndAwaitSignal()

bool doTaskAndAwaitSignal ( )

◆ onTaskAborted

void onTaskAborted ( )
protectedslot

This should be emitted to indicate that the home thread should be unblocked even though the task did not finish properly.

◆ onTaskFinished

void onTaskFinished ( )
protectedslot

This (or taskAborted) must be emitted to indicate that the task has finished and that the home thread should be unblocked.

◆ state()

◆ taskAborted

void taskAborted ( )
signal

Emit this rather than task finished to indicate that the home thread should be unblocked even though the task did not finish normally.

◆ taskFinished

void taskFinished ( )
signal

This (or taskAborted) must be emitted to indicate that the task has finished and that the home thread should be unblocked.