DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Util::QWorker Class Reference

Implements a QObject belonging to a hardware adapter (derived from DynExp::HardwareAdapterBase) that operates in DynExpCore's worker thread, not in the main user interface thread. This is useful to move e.g. ethernet/serial communication operations from the user interface thread to a worker thread. After construction, QWorker instances have to be moved to the worker thread calling QWorker::MoveToWorkerThread(). More...

+ Inheritance diagram for Util::QWorker:

Public Member Functions

void MoveToWorkerThread (DynExp::ItemIDType ID)
 Moves the instance to DynExpCore's worker thread. Do not call from constructor since derived classes have not been instantiated yet in that case. This would prevent QObjects contained in derived classes to be also moved to the worker thread. More...
 
auto GetOwner () const noexcept
 Returns this worker instance's owner. More...
 

Protected Member Functions

 QWorker ()=default
 
 ~QWorker ()=default
 

Private Types

using OwnerPtrType = std::weak_ptr< const DynExp::HardwareAdapterBase >
 

Private Member Functions

void SetOwner (OwnerPtrType Owner) noexcept
 Sets the hardware adapter owning this worker instance. More...
 

Static Private Member Functions

static const DynExp::DynExpCoreGetDynExpCore (const DynExp::DynExpCore *DynExpCore=nullptr)
 Returns the application's DynExp::DynExpCore instance which is globally set in constructor DynExp::DynExpCore::DynExpCore() More...
 

Private Attributes

bool HasBeenMovedToWorkerThread = false
 Indicates whether the worker has already been moved to the worker thread. More...
 
OwnerPtrType Owner
 Pointer to the hardware adapter owning this instance. More...
 

Friends

class DynExp::DynExpCore
 

Detailed Description

Implements a QObject belonging to a hardware adapter (derived from DynExp::HardwareAdapterBase) that operates in DynExpCore's worker thread, not in the main user interface thread. This is useful to move e.g. ethernet/serial communication operations from the user interface thread to a worker thread. After construction, QWorker instances have to be moved to the worker thread calling QWorker::MoveToWorkerThread().

Definition at line 326 of file QtUtil.h.

Member Typedef Documentation

◆ OwnerPtrType

using Util::QWorker::OwnerPtrType = std::weak_ptr<const DynExp::HardwareAdapterBase>
private

Definition at line 352 of file QtUtil.h.

Constructor & Destructor Documentation

◆ QWorker()

Util::QWorker::QWorker ( )
protecteddefault

◆ ~QWorker()

Util::QWorker::~QWorker ( )
protecteddefault

Member Function Documentation

◆ GetDynExpCore()

const DynExp::DynExpCore & Util::QWorker::GetDynExpCore ( const DynExp::DynExpCore DynExpCore = nullptr)
staticprivate

Returns the application's DynExp::DynExpCore instance which is globally set in constructor DynExp::DynExpCore::DynExpCore()

Parameters
DynExpCoreUsed by DynExp::DynExpCore::DynExpCore(). Do not pass anything.
Returns
Reference to the application's DynExp::DynExpCore instance
Exceptions
Util::InvalidArgExceptionis thrown if this function is called without letting DynExp::DynExpCore::DynExpCore() perform the initialization.

Definition at line 281 of file QtUtil.cpp.

◆ GetOwner()

auto Util::QWorker::GetOwner ( ) const
inlinenoexcept

Returns this worker instance's owner.

Returns
Pointer to owning hardware adapter

Definition at line 349 of file QtUtil.h.

◆ MoveToWorkerThread()

void Util::QWorker::MoveToWorkerThread ( DynExp::ItemIDType  ID)

Moves the instance to DynExpCore's worker thread. Do not call from constructor since derived classes have not been instantiated yet in that case. This would prevent QObjects contained in derived classes to be also moved to the worker thread.

Parameters
IDID of the hardware adapter owning this worker instance

Definition at line 272 of file QtUtil.cpp.

◆ SetOwner()

void Util::QWorker::SetOwner ( OwnerPtrType  Owner)
inlineprivatenoexcept

Sets the hardware adapter owning this worker instance.

Parameters
OwnerPointer to the hardware adapter owning this instance

Definition at line 368 of file QtUtil.h.

Friends And Related Function Documentation

◆ DynExp::DynExpCore

friend class DynExp::DynExpCore
friend

Definition at line 330 of file QtUtil.h.

Member Data Documentation

◆ HasBeenMovedToWorkerThread

bool Util::QWorker::HasBeenMovedToWorkerThread = false
private

Indicates whether the worker has already been moved to the worker thread.

Definition at line 370 of file QtUtil.h.

◆ Owner

OwnerPtrType Util::QWorker::Owner
private

Pointer to the hardware adapter owning this instance.

Definition at line 371 of file QtUtil.h.


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