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

Resource manager for InstrumentBase resources deriving from a specialized ResourceManagerBase class. More...

+ Inheritance diagram for DynExp::InstrumentManager:

Public Types

using ResourceType = Resource< InstrumentPtrType >
 Type of the managed DynExp resources. More...
 
- Public Types inherited from DynExp::ResourceManagerBase< InstrumentPtrType >
using ResourceType = Resource< InstrumentPtrType >
 Type of the managed DynExp resources. More...
 
- Public Types inherited from DynExp::CommonResourceManagerBase
using FunctionToCallWhenObjectStartedType = const std::function< void(Object *const)>
 Type of a callback function to invoke after a resource has been started in a call to ResourceManagerBase::Startup(). The DynExp::Object instance owned by the respective resource is passed to the callback function. Refer e.g. to DynExpManager::RegisterModuleUI(), which is such a callback function. More...
 

Public Member Functions

 InstrumentManager ()=default
 
 ~InstrumentManager ()=default
 
size_t GetNumRunningInstruments () const
 Counts the instruments managed by this resource manager which are running (as determined by RunnableObject::IsRunning()). More...
 
bool AllInitialized () const
 Determines whether all instruments managed by this resource manager are initialized. Only counts instruments with the startup type RunnableObjectParams::StartupType::OnCreation. If any of the managed instruments is in an error state, the related exception is rethrown. More...
 
void TerminateAll () const
 Calls RunnableObject::Terminate() on all instruments managed by this resource manager. Logical const-ness: Refer to CommonResourceManagerBase. More...
 
- Public Member Functions inherited from DynExp::ResourceManagerBase< InstrumentPtrType >
ItemIDType GetNextID () const noexcept
 Getter for the ID to assign to the next resource to be inserted into the resource manager. More...
 
const auto GetNumResources () const noexcept
 Determines the amount of resources stored in this resource manager. More...
 
const bool Empty () const noexcept
 Determines whether this resource manager is empty. More...
 
const PointerType::element_type * GetResource (ItemIDType ID) const
 Retrieves a resource specified by its ID from the resource manager. More...
 
PointerType::element_type * GetResource (ItemIDType ID)
 Retrieves a resource specified by its ID from the resource manager. More...
 
InstrumentPtrType ExtractResource (ItemIDType ID)
 Releases ownership of the owned resource with ID and returns it. More...
 
void RemoveResource (ItemIDType ID, const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout)
 Removes the resource identified by ID from the resource manager and deletes it. More...
 
void DeleteTreeWidgetItem (ItemIDType ID)
 Deletes the Resource::TreeWidgetItem of the requested resource. More...
 
void FocusTreeWidgetItem (ItemIDType ID)
 Selects the Resource::TreeWidgetItem of the requested resource. More...
 
auto ShareResource (ItemIDType ID) const
 Copies and returns the shared pointer pointing to (and owning) the resource identified by ID. The resource itself is neither copied nor changed. The const version of this method returns a shared pointer pointing to a const resource. This method is only available if the resources stored in the resource manager are managed by a shared pointer (i.e. PointerType is std::shared_ptr). More...
 
auto ShareResource (ItemIDType ID)
 Copies and returns the shared pointer pointing to (and owning) the resource identified by ID. The resource itself is neither copied nor changed. The const version of this method returns a shared pointer pointing to a const resource. This method is only available if the resources stored in the resource manager are managed by a shared pointer (i.e. PointerType is std::shared_ptr). More...
 
auto cbegin () const noexcept
 Returns an iterator to the first resource stored in the resource manager. More...
 
auto cend () const noexcept
 Returns an iterator behind the last resource stored in the resource manager. More...
 
ItemIDType InsertResource (ElementType &&Element)
 Inserts a resource into the resource manager. More...
 
ItemIDListType Filter () const
 Builds and returns a list of the IDs of all resources stored in this resource manager which can be cast to DerivedType. More...
 
void Startup (FunctionToCallWhenObjectStartedType FunctionToCallWhenObjectStarted) const
 Starts all resources owned by the resource manager. For HardwareAdapterBase instances, Object::EnsureReadyState() is called. For InstrumentBase and ModuleBase instances, RunnableObject::RunIfRunOnCreation() is called. More...
 
void Shutdown () const
 Calls ShutdownChild() to terminate and clean up all resources stored in this resource manager. More...
 
void ClearResourcesWarnings () const
 Calls Object::ClearWarning() on all resources stored in this resource manager. More...
 
ItemIDListType GetFailedResourceIDs (bool OnlyResourcesBeingInUse=false) const
 Builds and returns a list of the IDs of all resources stored in this resource manager which are in an error state. More...
 
void ResetFailedResources () const
 Calls Object::Reset() on all resources stored in this resource manager which are in an error state (determined by Object::GetException()). More...
 
void PrepareReset ()
 Prepares all resources stored in this resource manager for their deletion by e.g. asking them to terminate. More...
 
void Reset ()
 Resets the resource manager by calling ResetChild(), by removing all resources from Map and by resetting CurrentID. All owned resources are deleted if they are not shared and still in use elsewhere. More...
 
QDomElement EntryConfigsToXML (QDomDocument &Document) const
 Creates and returns the XML tree containing the configuration of each resource owned by this resource manager for saving DynExp projects to XML files. The tree starts with a root node as produced by MakeXMLConfigHeadNode(). More...
 
void DeleteAllTreeWidgetItems ()
 Deletes the Resource::TreeWidgetItem of all resources stored in this resource manager. More...
 
void MakeEntriesFromXML (const QDomElement &XMLNode, const LibraryVectorT &Library, const DynExpCore &Core)
 Creates resources and takes ownership of them according to an XML tree from a DynExp project XML file. More...
 

Private Member Functions

virtual void StartupChild (FunctionToCallWhenObjectStartedType FunctionToCallWhenObjectStarted) const override
 Starts all resources owned by the resource manager. For HardwareAdapterBase instances, Object::EnsureReadyState() is called. For InstrumentBase and ModuleBase instances, RunnableObject::RunIfRunOnCreation() is called. More...
 
virtual void ShutdownChild () const override
 Calls ShutdownChild() to terminate and clean up all resources stored in this resource manager. More...
 
virtual void PrepareResetChild () override
 Prepares all resources stored in this resource manager for their deletion by e.g. asking them to terminate. More...
 
virtual QDomElement MakeXMLConfigHeadNode (QDomDocument &Document) const override
 Creates and returns the XML root node of the (single) resource manager instance of the derived manager type. Below this node in the XML hierarchy, each resource owned by this resource manager stores its configuration for saving DynExp projects to XML files. Also refer to EntryConfigsToXML(). More...
 

Additional Inherited Members

- Public Attributes inherited from DynExp::ResourceManagerBase< InstrumentPtrType >
LinkBaseOnlyType LinkBaseOnly
 
- Protected Member Functions inherited from DynExp::ResourceManagerBase< InstrumentPtrType >
 ResourceManagerBase ()
 
 ~ResourceManagerBase ()=default
 
- Protected Member Functions inherited from DynExp::CommonResourceManagerBase
 CommonResourceManagerBase ()=default
 
 ~CommonResourceManagerBase ()=default
 
- Static Protected Member Functions inherited from DynExp::CommonResourceManagerBase
static std::thread::id GetOwnerThreadID (const DynExpCore &Core) noexcept
 Getter for the thread id of the thread which constructed (and owns) Core. Implementation necessary in Managers.cpp to prevent cyclic includes caused by usage of DynExpCore in ResourceManagerBase::MakeEntriesFromXML(). More...
 

Detailed Description

Resource manager for InstrumentBase resources deriving from a specialized ResourceManagerBase class.

Definition at line 656 of file Managers.h.

Member Typedef Documentation

◆ ResourceType

Type of the managed DynExp resources.

Definition at line 659 of file Managers.h.

Constructor & Destructor Documentation

◆ InstrumentManager()

DynExp::InstrumentManager::InstrumentManager ( )
default

◆ ~InstrumentManager()

DynExp::InstrumentManager::~InstrumentManager ( )
default

Member Function Documentation

◆ AllInitialized()

bool DynExp::InstrumentManager::AllInitialized ( ) const

Determines whether all instruments managed by this resource manager are initialized. Only counts instruments with the startup type RunnableObjectParams::StartupType::OnCreation. If any of the managed instruments is in an error state, the related exception is rethrown.

Returns
Returns true if all owned instruments are initialized (as determined by InstrumentBase::IsInitialized()), false otherwise.

Definition at line 68 of file Managers.cpp.

◆ GetNumRunningInstruments()

size_t DynExp::InstrumentManager::GetNumRunningInstruments ( ) const

Counts the instruments managed by this resource manager which are running (as determined by RunnableObject::IsRunning()).

Returns
Returns the amount of owned running instruments.

Definition at line 63 of file Managers.cpp.

◆ MakeXMLConfigHeadNode()

QDomElement DynExp::InstrumentManager::MakeXMLConfigHeadNode ( QDomDocument &  Document) const
overrideprivatevirtual

Creates and returns the XML root node of the (single) resource manager instance of the derived manager type. Below this node in the XML hierarchy, each resource owned by this resource manager stores its configuration for saving DynExp projects to XML files. Also refer to EntryConfigsToXML().

Parameters
DocumentQt dom document within to create the dom element.
Returns
Qt dom element acting as the root node of this resource manager's resources' configuration.

Implements DynExp::ResourceManagerBase< InstrumentPtrType >.

Definition at line 97 of file Managers.cpp.

◆ PrepareResetChild()

virtual void DynExp::InstrumentManager::PrepareResetChild ( )
inlineoverrideprivatevirtual

Prepares all resources stored in this resource manager for their deletion by e.g. asking them to terminate.

Reimplemented from DynExp::ResourceManagerBase< InstrumentPtrType >.

Definition at line 691 of file Managers.h.

◆ ShutdownChild()

virtual void DynExp::InstrumentManager::ShutdownChild ( ) const
inlineoverrideprivatevirtual

Calls ShutdownChild() to terminate and clean up all resources stored in this resource manager.

Reimplemented from DynExp::ResourceManagerBase< InstrumentPtrType >.

Definition at line 690 of file Managers.h.

◆ StartupChild()

void DynExp::InstrumentManager::StartupChild ( FunctionToCallWhenObjectStartedType  FunctionToCallWhenObjectStarted) const
overrideprivatevirtual

Starts all resources owned by the resource manager. For HardwareAdapterBase instances, Object::EnsureReadyState() is called. For InstrumentBase and ModuleBase instances, RunnableObject::RunIfRunOnCreation() is called.

Parameters
FunctionToCallWhenObjectStartedCallback function. Refer to FunctionToCallWhenObjectStartedType.

Implements DynExp::ResourceManagerBase< InstrumentPtrType >.

Definition at line 87 of file Managers.cpp.

◆ TerminateAll()

void DynExp::InstrumentManager::TerminateAll ( ) const

Calls RunnableObject::Terminate() on all instruments managed by this resource manager. Logical const-ness: Refer to CommonResourceManagerBase.

Definition at line 82 of file Managers.cpp.


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