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 instrument thread, the threads of different modules, as well as the main thread might access the instrument at the same time. Every class (indirectly) derived from class InstrumentBase
must be accompanied by a instrument data class derived from InstrumentDataBase
. InstrumentDataBase
and derived classes contain data shared by the respective instrument, module and main threads. Data only used by the instrument itself should be private members of the instrument class.
More...
Classes | |
struct | dispatch_tag |
Refer to ParamsBase::dispatch_tag. More... | |
class | InstrumentBaseOnlyType |
Allow exclusive access to some of InstrumentDataBase's private methods to InstrumentBase . More... | |
class | InstrumenThreadOnlyType |
Allow exclusive access to some of InstrumentDataBase's private methods to the instrument thread InstrumentThreadMain() . More... | |
Public Types | |
using | TaskQueueType = std::list< std::unique_ptr< TaskBase > > |
Type of an instrument task queue owning the tasks within. More... | |
using | TaskQueueIteratorType = TaskQueueType::const_iterator |
Const iterator type to elements of TaskQueueType . More... | |
Public Member Functions | |
InstrumentDataBase () | |
virtual | ~InstrumentDataBase () |
auto | GetLastUpdateTime () const |
Getter for LastUpdate. More... | |
auto | GetException () const noexcept |
Getter for InstrumentDataBase::InstrumentException. More... | |
Instrument task queue | |
Methods to access and manipulate the task queue belonging to the instrument which owns the respective | |
void | EnqueueTask (std::unique_ptr< TaskBase > &&Task) |
Enqueues a task at the back of an instrument's task queue and notifies the instrument about the new task. More... | |
void | EnqueuePriorityTask (std::unique_ptr< TaskBase > &&Task) |
Enqueues a task at the front of an instrument's task queue and notifies the instrument about the new task. More... | |
std::unique_ptr< TaskBase > | PopTaskFront () |
Removes a task from the front of an instrument's task queue. More... | |
std::unique_ptr< TaskBase > | PopTaskBack () |
Removes a task from the back of an instrument's task queue. More... | |
auto | GetTaskFront () noexcept |
Getter for first enqueued task. More... | |
auto | GetTaskBack () noexcept |
Getter for last enqueued task. More... | |
size_t | GetNumEnqueuedTasks () const noexcept |
Getter for the instrument task queue's length. More... | |
std::unique_ptr< TaskBase > | PopFinishedTask () |
Removes a task from the front of an instrument's list of finished tasks. More... | |
size_t | GetNumFinishedTasks () const noexcept |
Getter for the length of the instrument's list of finished tasks. More... | |
bool | IsQueueClosed () const noexcept |
Determines whether the instrument task queue is closed. More... | |
Public Member Functions inherited from Util::INonCopyable | |
INonCopyable (const INonCopyable &)=delete | |
INonCopyable & | operator= (const INonCopyable &)=delete |
Public Attributes | |
InstrumentBaseOnlyType | InstrumentBaseOnly |
Allow exclusive access to some of InstrumentDataBase's private methods to InstrumentBase . More... | |
InstrumenThreadOnlyType | InstrumentThreadOnly |
Allow exclusive access to some of InstrumentDataBase's private methods to the instrument thread InstrumentThreadMain() . More... | |
Private Member Functions | |
void | EnqueueTask (std::unique_ptr< TaskBase > &&Task, bool CallFromInstrThread, bool NotifyReceiver) |
Enqueues a task at the back of an instrument's task queue and notifies the instrument about the new task. More... | |
void | EnqueuePriorityTask (std::unique_ptr< TaskBase > &&Task, bool CallFromInstrThread, bool NotifyReceiver) |
Enqueues a task at the front of an instrument's task queue and notifies the instrument about the new task. More... | |
void | RemoveTaskFromQueue (TaskQueueIteratorType &Task) |
Removes a task from the instrument's task queue and inserts it into the instrument's list of finished tasks if TaskBase::KeepFinishedTask() returns true. More... | |
void | RemoveAllTasks () |
Clears the instrument's task queue. More... | |
void | RemoveAllTasksExceptFront () |
Clears the instrument's task queue but keeps the front task (the task with highest priority which is handled next). More... | |
void | CloseQueue () |
Clsoes the instrument's task queue setting QueueClosed to true. More... | |
Util::OneToOneNotifier & | GetNewTaskNotifier () noexcept |
Getter for NewTaskNotifier. More... | |
void | CheckError () const |
Throws InstrumentException if it is not nullptr using Util::ForwardException(). More... | |
void | CheckQueueState (bool CallFromInstrThread) const |
Checks whether it is currently allowed to enqueue tasks into the instrument task queue. More... | |
Stopped instrument only | |
Must only be called when the instrument thread is not running. | |
void | Reset () |
Resets the InstrumentDataBase's instance and calls ResetImpl(dispatch_tag<InstrumentDataBase>) subsequently. More... | |
virtual void | ResetImpl (dispatch_tag< InstrumentDataBase >) |
Refer to DynExp::InstrumentDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from InstrumentDataBase , descending the inheritance hierarchy. Override in order to reset derived classes. More... | |
Private Attributes | |
TaskQueueType | TaskQueue |
FIFO task queue of the instrument owning this InstrumentDataBase instance. More... | |
TaskQueueType | FinishedTasks |
List of the instrument's finished tasks. Tasks are moved here from TaskQueue after completion. More... | |
bool | QueueClosed |
If set to true, no new tasks can be enqueued (useful if an instrument is e.g. stopped). More... | |
Util::OneToOneNotifier | NewTaskNotifier |
Used to notify the instrument thread about new tasks when enqueuing tasks into the task queue. This allows the instrument thread to sleep until new tasks have to be handled. More... | |
std::chrono::system_clock::time_point | LastUpdate |
Time point when the instrument thread called InstrumentBase::UpdateDataInternal() the last time. More... | |
std::exception_ptr | InstrumentException |
Used to transfer exceptions from the instrument thread to the main thread. Stores the exception responsible for the error state if the instrument which owns the respective InstrumentDataBase'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 instrument thread, the threads of different modules, as well as the main thread might access the instrument at the same time. Every class (indirectly) derived from class InstrumentBase
must be accompanied by a instrument data class derived from InstrumentDataBase
. InstrumentDataBase
and derived classes contain data shared by the respective instrument, module and main threads. Data only used by the instrument itself should be private members of the instrument class.
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 134 of file Instrument.h.
struct DynExp::InstrumentDataBase::dispatch_tag |
Refer to ParamsBase::dispatch_tag.
Type | (derived from class InstrumentDataBase ) to instantiate the dispatch tag template with. |
Definition at line 146 of file Instrument.h.
using DynExp::InstrumentDataBase::TaskQueueIteratorType = TaskQueueType::const_iterator |
Const iterator type to elements of TaskQueueType
.
Definition at line 138 of file Instrument.h.
using DynExp::InstrumentDataBase::TaskQueueType = std::list<std::unique_ptr<TaskBase> > |
Type of an instrument task queue owning the tasks within.
Definition at line 137 of file Instrument.h.
|
inline |
Definition at line 199 of file Instrument.h.
|
inlinevirtual |
Definition at line 200 of file Instrument.h.
|
private |
Throws InstrumentException if it is not nullptr using Util::ForwardException().
Definition at line 189 of file Instrument.cpp.
|
private |
Checks whether it is currently allowed to enqueue tasks into the instrument task queue.
CallFromInstrThread | Pass true if the instrument itself enqueues a task. |
Util::InvalidStateException | is thrown if the instrument task queue is closed and CallFromInstrThread is false. |
Definition at line 194 of file Instrument.cpp.
|
inlineprivate |
Clsoes the instrument's task queue setting QueueClosed to true.
Definition at line 336 of file Instrument.h.
|
inline |
Enqueues a task at the front of an instrument's task queue and notifies the instrument about the new task.
Task | Task to enqueue, the queue takes ownership of the task. |
Definition at line 220 of file Instrument.h.
|
private |
Enqueues a task at the front of an instrument's task queue and notifies the instrument about the new task.
Task | Task to enqueue, the queue takes ownership of the task. |
CallFromInstrThread | Pass true if the instrument itself enqueues a task. This argument is forwarded to CheckQueueState() . |
NotifyReceiver | Determines whether the instrument thread is notified that a new task has been enqueued. This is e.g. not desired when enqueuing update tasks in InstrumentBase::UpdateData(). |
Definition at line 147 of file Instrument.cpp.
|
inline |
Enqueues a task at the back of an instrument's task queue and notifies the instrument about the new task.
Task | Task to enqueue, the queue takes ownership of the task. |
Definition at line 213 of file Instrument.h.
|
private |
Enqueues a task at the back of an instrument's task queue and notifies the instrument about the new task.
Task | Task to enqueue, the queue takes ownership of the task. |
CallFromInstrThread | Pass true if the instrument itself enqueues a task. This argument is forwarded to CheckQueueState() . |
NotifyReceiver | Determines whether the instrument thread is notified that a new task has been enqueued. This is e.g. not desired when enqueuing update tasks in InstrumentBase::UpdateData(). |
Definition at line 137 of file Instrument.cpp.
|
inlinenoexcept |
Getter for InstrumentDataBase::InstrumentException.
Definition at line 289 of file Instrument.h.
|
inline |
Getter for LastUpdate.
Definition at line 283 of file Instrument.h.
|
inlineprivatenoexcept |
Getter for NewTaskNotifier.
Definition at line 342 of file Instrument.h.
|
inlinenoexcept |
Getter for the instrument task queue's length.
Definition at line 256 of file Instrument.h.
|
inlinenoexcept |
Getter for the length of the instrument's list of finished tasks.
Definition at line 270 of file Instrument.h.
|
inlinenoexcept |
Getter for last enqueued task.
Definition at line 250 of file Instrument.h.
|
inlinenoexcept |
Getter for first enqueued task.
Definition at line 244 of file Instrument.h.
|
inlinenoexcept |
Determines whether the instrument task queue is closed.
Definition at line 276 of file Instrument.h.
std::unique_ptr< TaskBase > DynExp::InstrumentDataBase::PopFinishedTask | ( | ) |
Removes a task from the front of an instrument's list of finished tasks.
Definition at line 126 of file Instrument.cpp.
std::unique_ptr< TaskBase > DynExp::InstrumentDataBase::PopTaskBack | ( | ) |
Removes a task from the back of an instrument's task queue.
Util::InvalidStateException | is thrown if the task to be removed is locked. Refer to TaskBase::TaskState. |
Definition at line 112 of file Instrument.cpp.
std::unique_ptr< TaskBase > DynExp::InstrumentDataBase::PopTaskFront | ( | ) |
Removes a task from the front of an instrument's task queue.
Util::InvalidStateException | is thrown if the task to be removed is locked. Refer to TaskBase::TaskState. |
Definition at line 98 of file Instrument.cpp.
|
private |
Clears the instrument's task queue.
Definition at line 165 of file Instrument.cpp.
|
private |
Clears the instrument's task queue but keeps the front task (the task with highest priority which is handled next).
Definition at line 170 of file Instrument.cpp.
|
private |
Removes a task from the instrument's task queue and inserts it into the instrument's list of finished tasks if TaskBase::KeepFinishedTask() returns true.
Task | Iterator to an enqueued task. |
Definition at line 157 of file Instrument.cpp.
|
private |
Resets the InstrumentDataBase's
instance and calls ResetImpl(dispatch_tag<InstrumentDataBase>) subsequently.
Definition at line 178 of file Instrument.cpp.
|
inlineprivatevirtual |
Refer to DynExp::InstrumentDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl()
of every derived class gets called - starting from InstrumentDataBase
, descending the inheritance hierarchy. Override in order to reset derived classes.
Reimplemented in DynExpInstr::InterModuleCommunicatorData.
Definition at line 359 of file Instrument.h.
|
private |
List of the instrument's finished tasks. Tasks are moved here from TaskQueue after completion.
Definition at line 377 of file Instrument.h.
InstrumentBaseOnlyType DynExp::InstrumentDataBase::InstrumentBaseOnly |
Allow exclusive access to some of InstrumentDataBase's
private methods to InstrumentBase
.
Definition at line 291 of file Instrument.h.
|
private |
Used to transfer exceptions from the instrument thread to the main thread. Stores the exception responsible for the error state if the instrument which owns the respective InstrumentDataBase's
instance is in such an error state.
Definition at line 394 of file Instrument.h.
InstrumenThreadOnlyType DynExp::InstrumentDataBase::InstrumentThreadOnly |
Allow exclusive access to some of InstrumentDataBase's
private methods to the instrument thread InstrumentThreadMain()
.
Definition at line 292 of file Instrument.h.
|
private |
Time point when the instrument thread called InstrumentBase::UpdateDataInternal() the last time.
Definition at line 387 of file Instrument.h.
|
private |
Used to notify the instrument thread about new tasks when enqueuing tasks into the task queue. This allows the instrument thread to sleep until new tasks have to be handled.
Definition at line 385 of file Instrument.h.
|
private |
If set to true, no new tasks can be enqueued (useful if an instrument is e.g. stopped).
Definition at line 378 of file Instrument.h.
|
private |
FIFO task queue of the instrument owning this InstrumentDataBase
instance.
Definition at line 376 of file Instrument.h.