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

Data structure to contain data which is synchronized in between different threads. This is needed since the module thread as well as the main thread might access the module at the same time. Every class (indirectly) derived from class ModuleBase must be accompanied by a module data class derived from ModuleDataBase. ModuleDataBase and derived classes contain data shared by the respective module thread and the user interface (main) thread to e.g. visualize data. Data only used by the module thread should be private members of the module class. Data only used by the user interface should be private members of the module's widget class (derived from QModuleWidget), respectively. More...

+ Inheritance diagram for DynExp::ModuleDataBase:

Classes

struct  dispatch_tag
 Refer to ParamsBase::dispatch_tag. More...
 
class  ModuleBaseOnlyType
 Allow exclusive access to some of ModuleDataBase's private methods to ModuleBase. More...
 
class  ModuleThreadOnlyType
 Allow exclusive access to some of ModuleDataBase's private methods to the module thread ModuleThreadMain(). More...
 

Public Types

using EventPtrType = std::unique_ptr< EventBase >
 Pointer owning an event. More...
 
using EventQueueType = std::queue< EventPtrType >
 A module's event queue is a FIFO queue owning the enqueued events. More...
 

Public Member Functions

 ModuleDataBase ()
 
virtual ~ModuleDataBase ()
 
auto GetException () const noexcept
 Getter for ModuleException. More...
 
Module event queue

Methods to access and manipulate the event queue belonging to the module which owns the respective ModuleDataBase's instance

void EnqueueEvent (EventPtrType &&Event)
 Enqueues Event at the module event queue's back. Takes ownership of the event. Notifies the module owning the respective ModuleDataBase's instance that a new event has been enqueued. More...
 
EventPtrType PopEvent ()
 Removes one event from the event queue's front and returns the event. Ownership of the event is transferred to the caller of this method. More...
 
const auto & GetEventFront () const noexcept
 Returns a pointer to the event in the front of the module's event queue without transferring ownership and without removing the event from the queue. More...
 
auto & GetEventFront () noexcept
 Returns a pointer to the event in the front of the module's event queue without transferring ownership and without removing the event from the queue. More...
 
size_t GetNumEnqueuedEvents () const noexcept
 Getter for the module event queue's length. More...
 
- Public Member Functions inherited from Util::INonCopyable
 INonCopyable (const INonCopyable &)=delete
 
INonCopyableoperator= (const INonCopyable &)=delete
 

Public Attributes

ModuleBaseOnlyType ModuleBaseOnly
 Allow exclusive access to some of ModuleDataBase's private methods to ModuleBase. More...
 
ModuleThreadOnlyType ModuleThreadOnly
 Allow exclusive access to some of ModuleDataBase's private methods to the module thread ModuleThreadMain(). More...
 

Private Member Functions

Util::OneToOneNotifierGetNewEventNotifier () noexcept
 Getter for NewEventNotifier. More...
 
Stopped module only

Must only be called when the module thread is not running.

void Reset ()
 Resets the ModuleDataBase's instance and calls ResetImpl(dispatch_tag<ModuleDataBase>) subsequently. More...
 
virtual void ResetImpl (dispatch_tag< ModuleDataBase >)
 Refer to DynExp::ModuleDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from ModuleDataBase, descending the inheritance hierarchy. Override in order to reset derived classes. More...
 

Private Attributes

EventQueueType EventQueue
 FIFO event queue of the module which owns the respective ModuleDataBase's instance. More...
 
Util::OneToOneNotifier NewEventNotifier
 Notifies the thread of the module which owns the respective ModuleDataBase's instance when an event has been enqueued into the module's event queue. This allows the module thread to sleep until new events have to be handled. More...
 
std::exception_ptr ModuleException
 Used to transfer exceptions from the module thread to the main (user interface) thread. Stores the exception responsible for the error state if the module which owns the respective ModuleDataBase's instance is in such an error state. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Util::ISynchronizedPointerLockable
 ISynchronizedPointerLockable ()
 
 ~ISynchronizedPointerLockable ()
 Object should never be destroyed before completely unlocked. More...
 
- Protected Member Functions inherited from Util::INonCopyable
constexpr INonCopyable ()=default
 
 ~INonCopyable ()=default
 

Detailed Description

Data structure to contain data which is synchronized in between different threads. This is needed since the module thread as well as the main thread might access the module at the same time. Every class (indirectly) derived from class ModuleBase must be accompanied by a module data class derived from ModuleDataBase. ModuleDataBase and derived classes contain data shared by the respective module thread and the user interface (main) thread to e.g. visualize data. Data only used by the module thread should be private members of the module class. Data only used by the user interface should be private members of the module's widget class (derived from QModuleWidget), respectively.

Warning
For the same Object, always lock the mutex of the corresponding parameter class before the mutex of the corresponding data class (or only one of them).

Definition at line 170 of file Module.h.


Class Documentation

◆ DynExp::ModuleDataBase::dispatch_tag

struct DynExp::ModuleDataBase::dispatch_tag

template<typename>
struct DynExp::ModuleDataBase::dispatch_tag< typename >

Refer to ParamsBase::dispatch_tag.

Template Parameters
Type(derived from class ModuleDataBase) to instantiate the dispatch tag template with.

Definition at line 189 of file Module.h.

Member Typedef Documentation

◆ EventPtrType

Pointer owning an event.

Definition at line 176 of file Module.h.

◆ EventQueueType

A module's event queue is a FIFO queue owning the enqueued events.

Definition at line 181 of file Module.h.

Constructor & Destructor Documentation

◆ ModuleDataBase()

DynExp::ModuleDataBase::ModuleDataBase ( )
inline

Definition at line 235 of file Module.h.

◆ ~ModuleDataBase()

virtual DynExp::ModuleDataBase::~ModuleDataBase ( )
inlinevirtual

Definition at line 236 of file Module.h.

Member Function Documentation

◆ EnqueueEvent()

void DynExp::ModuleDataBase::EnqueueEvent ( EventPtrType &&  Event)

Enqueues Event at the module event queue's back. Takes ownership of the event. Notifies the module owning the respective ModuleDataBase's instance that a new event has been enqueued.

Parameters
EventPointer to the event to be enqueued. Must not be nullptr.
Exceptions
Util::InvalidArgExceptionis thrown if Event is nullptr.

Definition at line 153 of file Module.cpp.

◆ GetEventFront() [1/2]

const auto& DynExp::ModuleDataBase::GetEventFront ( ) const
inlinenoexcept

Returns a pointer to the event in the front of the module's event queue without transferring ownership and without removing the event from the queue.

Returns
Constant pointer to the event

Definition at line 264 of file Module.h.

◆ GetEventFront() [2/2]

auto& DynExp::ModuleDataBase::GetEventFront ( )
inlinenoexcept

Returns a pointer to the event in the front of the module's event queue without transferring ownership and without removing the event from the queue.

Returns
Pointer to the event

Definition at line 270 of file Module.h.

◆ GetException()

auto DynExp::ModuleDataBase::GetException ( ) const
inlinenoexcept

Getter for ModuleException.

Returns
Returns the exception being responsible for the module's current state.

Definition at line 283 of file Module.h.

◆ GetNewEventNotifier()

Util::OneToOneNotifier& DynExp::ModuleDataBase::GetNewEventNotifier ( )
inlineprivatenoexcept

Getter for NewEventNotifier.

Returns
Returns NewEventNotifier to notify the module thread about new events.

Definition at line 293 of file Module.h.

◆ GetNumEnqueuedEvents()

size_t DynExp::ModuleDataBase::GetNumEnqueuedEvents ( ) const
inlinenoexcept

Getter for the module event queue's length.

Returns
Returns the number of currently enqueued events.

Definition at line 276 of file Module.h.

◆ PopEvent()

ModuleDataBase::EventPtrType DynExp::ModuleDataBase::PopEvent ( )

Removes one event from the event queue's front and returns the event. Ownership of the event is transferred to the caller of this method.

Returns
Pointer to the popped event or nullptr if the event queue is empty.

Definition at line 162 of file Module.cpp.

◆ Reset()

void DynExp::ModuleDataBase::Reset ( )
private

Resets the ModuleDataBase's instance and calls ResetImpl(dispatch_tag<ModuleDataBase>) subsequently.

Definition at line 173 of file Module.cpp.

◆ ResetImpl()

virtual void DynExp::ModuleDataBase::ResetImpl ( dispatch_tag< ModuleDataBase )
inlineprivatevirtual

Refer to DynExp::ModuleDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from ModuleDataBase, descending the inheritance hierarchy. Override in order to reset derived classes.

Reimplemented in DynExp::QModuleDataBase.

Definition at line 310 of file Module.h.

Member Data Documentation

◆ EventQueue

EventQueueType DynExp::ModuleDataBase::EventQueue
private

FIFO event queue of the module which owns the respective ModuleDataBase's instance.

Definition at line 316 of file Module.h.

◆ ModuleBaseOnly

ModuleBaseOnlyType DynExp::ModuleDataBase::ModuleBaseOnly

Allow exclusive access to some of ModuleDataBase's private methods to ModuleBase.

Definition at line 285 of file Module.h.

◆ ModuleException

std::exception_ptr DynExp::ModuleDataBase::ModuleException
private

Used to transfer exceptions from the module thread to the main (user interface) thread. Stores the exception responsible for the error state if the module which owns the respective ModuleDataBase's instance is in such an error state.

Definition at line 330 of file Module.h.

◆ ModuleThreadOnly

ModuleThreadOnlyType DynExp::ModuleDataBase::ModuleThreadOnly

Allow exclusive access to some of ModuleDataBase's private methods to the module thread ModuleThreadMain().

Definition at line 286 of file Module.h.

◆ NewEventNotifier

Util::OneToOneNotifier DynExp::ModuleDataBase::NewEventNotifier
private

Notifies the thread of the module which owns the respective ModuleDataBase's instance when an event has been enqueued into the module's event queue. This allows the module thread to sleep until new events have to be handled.

Definition at line 323 of file Module.h.


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