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

Defines data for a thread belonging to a RunnableObject instance. This data is only accessed by the RunnableObject instance's thread. So, no synchronization mechanism is needed. Furthermore, this class is designed to exist only on the stack. RunnableInstance instances are to be passed as a parameter to the respective thread functions. This ensures that a RunnableInstance instances is deleted when its thread function returns. This class is responsible for locking an object link (list) parameter (ParamsBase::Param< ObjectLink< ObjectT > > or ParamsBase::ListParam< ObjectLink< ObjectT > >) hold by a class derived (indirectly) from class ParamsBase and for storing the locked resource in a LinkedObjectWrapper instance. In turn, the created LinkedObjectWrapper instance is stored in a LinkedObjectWrapperContainer instance hold by a class derived (indirectly) from InstrumentDataBase or from ModuleDataBase. Furthermore, this class is responsible for unlocking LinkedObjectWrapper instances it created. Unlocking is triggered either on request or on destruction of the RunnableInstance instance owning the LinkedObjectWrapper instance. More...

+ Inheritance diagram for DynExp::RunnableInstance:

Public Member Functions

const auto & GetOwner () const noexcept
 Returns Owner. More...
 
template<typename ObjectT >
void TryLockObject (const ParamsBase::Param< ObjectLink< ObjectT >> &LinkParam, LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer, std::chrono::milliseconds Timeout=ObjectLinkBase::LockObjectTimeoutDefault)
 Locks an Object instance referenced by a parameter LinkParam of type ParamsBase::Param< ObjectLink< ObjectT > > and makes the LinkedObjectWrapperContainer ObjectWrapperContainer point to the locked resource. More...
 
template<typename ObjectT >
void LockObject (const ParamsBase::Param< ObjectLink< ObjectT >> &LinkParam, LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer, std::chrono::milliseconds Timeout=ObjectLinkBase::LockObjectTimeoutDefault)
 Locks an Object instance referenced by a parameter LinkParam of type ParamsBase::Param< ObjectLink< ObjectT > > and makes the LinkedObjectWrapperContainer ObjectWrapperContainer point to the locked resource. More...
 
template<typename ObjectT >
void UnlockObject (LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer)
 Unlocks an Object instance stored in the LinkedObjectWrapperContainer ObjectWrapperContainer. The LinkedObjectWrapperPointer contained in ObjectWrapperContainer is invalidated (set to nullptr)! More...
 
template<typename ObjectT >
void LockObject (const ParamsBase::ListParam< ObjectLink< ObjectT >> &LinkListParam, LinkedObjectWrapperContainerList< ObjectT > &ObjectWrapperContainerList, std::chrono::milliseconds Timeout=ObjectLinkBase::LockObjectTimeoutDefault)
 Locks Object instances referenced by a list parameter LinkListParam of type ParamsBase::ListParam< ObjectLink< ObjectT > > and creates containers in LinkedObjectWrapperContainerList ObjectWrapperContainerList which point to the locked resources. More...
 
template<typename ObjectT >
void UnlockObject (LinkedObjectWrapperContainerList< ObjectT > &ObjectWrapperContainerList)
 Unlocks Object instances stored in the LinkedObjectWrapperContainerList ObjectWrapperContainerList. More...
 
bool CareAboutWrappers ()
 Unregisters owned LinkedObjectWrapper instances from their destiny resources in case of the respective destiny resource not being in a ready state (e.g. a stopped/error state). Registers again after the respective destiny resource has returned to a ready state. More...
 
std::string GetNotReadyObjectNamesString () const
 Finds all linked Object instances Owner makes use of which are not in a ready state and builds a string identifying all these Object instances. More...
 
- Public Member Functions inherited from Util::INonCopyable
 INonCopyable (const INonCopyable &)=delete
 
INonCopyableoperator= (const INonCopyable &)=delete
 

Public Attributes

const Object::ParamsGetterType ParamsGetter
 Invoke to obtain the parameters (derived from ParamsBase) of Owner. More...
 

Protected Member Functions

 RunnableInstance (RunnableObject &Owner, std::promise< void > &&ThreadExitedPromise)
 Constructs a non-empty RunnableInstance instance. More...
 
 RunnableInstance (RunnableInstance &&Other)
 Move-constructs a RunnableInstance instance. Other becomes empty. Not noexcept since LinkedObjectWrapperBase::ListType (std::list) move constructor might throw. More...
 
 ~RunnableInstance ()
 
- Protected Member Functions inherited from Util::INonCopyable
constexpr INonCopyable ()=default
 
 ~INonCopyable ()=default
 

Private Member Functions

void SetThreadExited ()
 Signals that Owner's thread has exited. Refer to RunnableObject::OnThreadHasExited(). More...
 
template<typename ObjectT >
decltype(auto) StoreLockedObject (std::unique_ptr< LinkedObjectWrapper< ObjectT >> &&ObjectWrapperPtr, LinkedObjectWrapperContainerBase &ObjectWrapperContainer)
 Stores a newly created LinkedObjectWrapper instance in OwnedLinkedObjectWrappers. More...
 

Private Attributes

const RunnableObjectOwner
 RunnableObject instance which operates on this RunnableInstance (by its thread). The RunnableObject instance's tasks/events might access the object itself via GetOwner(). More...
 
std::promise< void > ThreadExitedPromise
 Signals the RunnableObject instance owning the thread that its thread has terminated. This is signaled on destruction of this RunnableInstance instance. Refer to RunnableObject::ThreadExitedSignal and to RunnableObject::OnThreadHasExited(). More...
 
bool Empty = false
 Set to true if it was moved from this instance to indicate that ThreadExitedPromise has no shared state anymore. More...
 
LinkedObjectWrapperBase::ListType OwnedLinkedObjectWrappers
 List of all LinkedObjectWrapper instances owned by this RunnableInstance instance (thus belonging to a RunnableObject instance). If the RunnableInstance's parent RunnableObject is terminated, by deleting the corresponding RunnableInstance, all these LinkedObjectWrapper instances are also deleted to unlock their linked resources. More...
 

Detailed Description

Defines data for a thread belonging to a RunnableObject instance. This data is only accessed by the RunnableObject instance's thread. So, no synchronization mechanism is needed. Furthermore, this class is designed to exist only on the stack. RunnableInstance instances are to be passed as a parameter to the respective thread functions. This ensures that a RunnableInstance instances is deleted when its thread function returns. This class is responsible for locking an object link (list) parameter (ParamsBase::Param< ObjectLink< ObjectT > > or ParamsBase::ListParam< ObjectLink< ObjectT > >) hold by a class derived (indirectly) from class ParamsBase and for storing the locked resource in a LinkedObjectWrapper instance. In turn, the created LinkedObjectWrapper instance is stored in a LinkedObjectWrapperContainer instance hold by a class derived (indirectly) from InstrumentDataBase or from ModuleDataBase. Furthermore, this class is responsible for unlocking LinkedObjectWrapper instances it created. Unlocking is triggered either on request or on destruction of the RunnableInstance instance owning the LinkedObjectWrapper instance.

Definition at line 3504 of file Object.h.

Constructor & Destructor Documentation

◆ RunnableInstance() [1/2]

DynExp::RunnableInstance::RunnableInstance ( RunnableObject Owner,
std::promise< void > &&  ThreadExitedPromise 
)
protected

Constructs a non-empty RunnableInstance instance.

Parameters
OwnerRefer to Owner.
ThreadExitedPromiseRefer to ThreadExitedPromise.

Definition at line 753 of file Object.cpp.

◆ RunnableInstance() [2/2]

DynExp::RunnableInstance::RunnableInstance ( RunnableInstance &&  Other)
protected

Move-constructs a RunnableInstance instance. Other becomes empty. Not noexcept since LinkedObjectWrapperBase::ListType (std::list) move constructor might throw.

Parameters
OtherRunnableInstance instance to move from

Definition at line 760 of file Object.cpp.

◆ ~RunnableInstance()

DynExp::RunnableInstance::~RunnableInstance ( )
protected

Definition at line 767 of file Object.cpp.

Member Function Documentation

◆ CareAboutWrappers()

bool DynExp::RunnableInstance::CareAboutWrappers ( )

Unregisters owned LinkedObjectWrapper instances from their destiny resources in case of the respective destiny resource not being in a ready state (e.g. a stopped/error state). Registers again after the respective destiny resource has returned to a ready state.

Returns
Returns true if the destiny resources of every owned LinkedObjectWrapper instance is in a ready state. Returns false if any destiny resource is in an error state.

Definition at line 776 of file Object.cpp.

◆ GetNotReadyObjectNamesString()

std::string DynExp::RunnableInstance::GetNotReadyObjectNamesString ( ) const

Finds all linked Object instances Owner makes use of which are not in a ready state and builds a string identifying all these Object instances.

Returns
Human-readable string identifying all linked resources not being in a ready state

Definition at line 815 of file Object.cpp.

◆ GetOwner()

const auto& DynExp::RunnableInstance::GetOwner ( ) const
inlinenoexcept

Returns Owner.

Definition at line 3524 of file Object.h.

◆ LockObject() [1/2]

template<typename ObjectT >
void DynExp::RunnableInstance::LockObject ( const ParamsBase::ListParam< ObjectLink< ObjectT >> &  LinkListParam,
LinkedObjectWrapperContainerList< ObjectT > &  ObjectWrapperContainerList,
std::chrono::milliseconds  Timeout = ObjectLinkBase::LockObjectTimeoutDefault 
)
inline

Locks Object instances referenced by a list parameter LinkListParam of type ParamsBase::ListParam< ObjectLink< ObjectT > > and creates containers in LinkedObjectWrapperContainerList ObjectWrapperContainerList which point to the locked resources.

Template Parameters
ObjectTType of the (multiple) managed Object
Parameters
LinkListParamObject link list parameter describing the destiny resources to lock
ObjectWrapperContainerListLinkedObjectWrapperContainerList to store references to the locked resources
TimeoutTimeout to be passed to ObjectLink::LockObject
Exceptions
Util::EmptyExceptionis thrown if LinkListParam is empty and non-optional.

Definition at line 3598 of file Object.h.

◆ LockObject() [2/2]

template<typename ObjectT >
void DynExp::RunnableInstance::LockObject ( const ParamsBase::Param< ObjectLink< ObjectT >> &  LinkParam,
LinkedObjectWrapperContainer< ObjectT > &  ObjectWrapperContainer,
std::chrono::milliseconds  Timeout = ObjectLinkBase::LockObjectTimeoutDefault 
)
inline

Locks an Object instance referenced by a parameter LinkParam of type ParamsBase::Param< ObjectLink< ObjectT > > and makes the LinkedObjectWrapperContainer ObjectWrapperContainer point to the locked resource.

Throwing version of TryLockObject(). Refer to ObjectLink::LockObject.

Template Parameters
ObjectTType of the managed Object
Parameters
LinkParamObject link parameter describing the destiny resource to lock
ObjectWrapperContainerLinkedObjectWrapperContainer to store a reference to the locked resource
TimeoutTimeout to be passed to ObjectLink::LockObject

Definition at line 3554 of file Object.h.

◆ SetThreadExited()

void DynExp::RunnableInstance::SetThreadExited ( )
private

Signals that Owner's thread has exited. Refer to RunnableObject::OnThreadHasExited().

Definition at line 825 of file Object.cpp.

◆ StoreLockedObject()

template<typename ObjectT >
decltype(auto) DynExp::RunnableInstance::StoreLockedObject ( std::unique_ptr< LinkedObjectWrapper< ObjectT >> &&  ObjectWrapperPtr,
LinkedObjectWrapperContainerBase ObjectWrapperContainer 
)
inlineprivate

Stores a newly created LinkedObjectWrapper instance in OwnedLinkedObjectWrappers.

Template Parameters
ObjectTType of the managed Object
Parameters
ObjectWrapperPtrPointer to the newly created LinkedObjectWrapper instance to take ownership of
ObjectWrapperContainerReference to the ObjectWrapperContainer referencing the newly created LinkedObjectWrapper instance
Returns
Pointer to the stored LinkedObjectWrapper instance

Definition at line 3689 of file Object.h.

◆ TryLockObject()

template<typename ObjectT >
void DynExp::RunnableInstance::TryLockObject ( const ParamsBase::Param< ObjectLink< ObjectT >> &  LinkParam,
LinkedObjectWrapperContainer< ObjectT > &  ObjectWrapperContainer,
std::chrono::milliseconds  Timeout = ObjectLinkBase::LockObjectTimeoutDefault 
)
inline

Locks an Object instance referenced by a parameter LinkParam of type ParamsBase::Param< ObjectLink< ObjectT > > and makes the LinkedObjectWrapperContainer ObjectWrapperContainer point to the locked resource.

Template Parameters
ObjectTType of the managed Object
Parameters
LinkParamObject link parameter describing the destiny resource to lock
ObjectWrapperContainerLinkedObjectWrapperContainer to store a reference to the locked resource
TimeoutTimeout to be passed to ObjectLink::TryLockObject

Definition at line 3537 of file Object.h.

◆ UnlockObject() [1/2]

template<typename ObjectT >
void DynExp::RunnableInstance::UnlockObject ( LinkedObjectWrapperContainer< ObjectT > &  ObjectWrapperContainer)
inline

Unlocks an Object instance stored in the LinkedObjectWrapperContainer ObjectWrapperContainer. The LinkedObjectWrapperPointer contained in ObjectWrapperContainer is invalidated (set to nullptr)!

Template Parameters
ObjectTType of the managed Object
Parameters
ObjectWrapperContainerLinkedObjectWrapperContainer holding a reference to the locked resource

Definition at line 3570 of file Object.h.

◆ UnlockObject() [2/2]

template<typename ObjectT >
void DynExp::RunnableInstance::UnlockObject ( LinkedObjectWrapperContainerList< ObjectT > &  ObjectWrapperContainerList)
inline

Unlocks Object instances stored in the LinkedObjectWrapperContainerList ObjectWrapperContainerList.

Template Parameters
ObjectTType of the (multiple) managed Object
Parameters
ObjectWrapperContainerListLinkedObjectWrapperContainerList holding references to the locked resources

Definition at line 3642 of file Object.h.

Member Data Documentation

◆ Empty

bool DynExp::RunnableInstance::Empty = false
private

Set to true if it was moved from this instance to indicate that ThreadExitedPromise has no shared state anymore.

Definition at line 3718 of file Object.h.

◆ OwnedLinkedObjectWrappers

LinkedObjectWrapperBase::ListType DynExp::RunnableInstance::OwnedLinkedObjectWrappers
private

List of all LinkedObjectWrapper instances owned by this RunnableInstance instance (thus belonging to a RunnableObject instance). If the RunnableInstance's parent RunnableObject is terminated, by deleting the corresponding RunnableInstance, all these LinkedObjectWrapper instances are also deleted to unlock their linked resources.

Definition at line 3726 of file Object.h.

◆ Owner

const RunnableObject& DynExp::RunnableInstance::Owner
private

RunnableObject instance which operates on this RunnableInstance (by its thread). The RunnableObject instance's tasks/events might access the object itself via GetOwner().

Definition at line 3705 of file Object.h.

◆ ParamsGetter

const Object::ParamsGetterType DynExp::RunnableInstance::ParamsGetter

Invoke to obtain the parameters (derived from ParamsBase) of Owner.

Definition at line 3671 of file Object.h.

◆ ThreadExitedPromise

std::promise<void> DynExp::RunnableInstance::ThreadExitedPromise
private

Signals the RunnableObject instance owning the thread that its thread has terminated. This is signaled on destruction of this RunnableInstance instance. Refer to RunnableObject::ThreadExitedSignal and to RunnableObject::OnThreadHasExited().

Definition at line 3712 of file Object.h.


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