DynExp
Highly flexible laboratory automation for dynamically changing experiments.
|
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...
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 | |
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 | |
INonCopyable & | operator= (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::OneToOneNotifier & | GetNewEventNotifier () 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 | |
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.
Object
, always lock the mutex of the corresponding parameter class before the mutex of the corresponding data class (or only one of them). struct DynExp::ModuleDataBase::dispatch_tag |
Refer to ParamsBase::dispatch_tag.
Type | (derived from class ModuleDataBase ) to instantiate the dispatch tag template with. |
using DynExp::ModuleDataBase::EventPtrType = std::unique_ptr<EventBase> |
using DynExp::ModuleDataBase::EventQueueType = std::queue<EventPtrType> |
|
inlinevirtual |
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.
Event | Pointer to the event to be enqueued. Must not be nullptr. |
Util::InvalidArgException | is thrown if Event is nullptr. |
Definition at line 153 of file Module.cpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Getter for ModuleException.
|
inlineprivatenoexcept |
Getter for NewEventNotifier.
|
inlinenoexcept |
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.
Definition at line 162 of file Module.cpp.
|
private |
Resets the ModuleDataBase's
instance and calls ResetImpl(dispatch_tag<ModuleDataBase>) subsequently.
Definition at line 173 of file Module.cpp.
|
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.
|
private |
FIFO event queue of the module which owns the respective ModuleDataBase's
instance.
ModuleBaseOnlyType DynExp::ModuleDataBase::ModuleBaseOnly |
Allow exclusive access to some of ModuleDataBase's
private methods to ModuleBase
.
|
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.
ModuleThreadOnlyType DynExp::ModuleDataBase::ModuleThreadOnly |
Allow exclusive access to some of ModuleDataBase's
private methods to the module thread ModuleThreadMain()
.
|
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.