DynExp
Highly flexible laboratory automation for dynamically changing experiments.
|
Typed resource manager base class deriving from class CommonResourceManagerBase
.
More...
Classes | |
class | LinkBaseOnlyType |
Allow exclusive access to some of ResourceManagerBase's private methods to LinkBase . More... | |
Public Types | |
using | ResourceType = Resource< PointerType > |
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 | |
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... | |
PointerType | 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... | |
template<typename T = PointerType, ShareResourceEnablerType< T > = 0> | |
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... | |
template<typename T = PointerType, ShareResourceEnablerType< T > = 0> | |
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... | |
template<typename ElementType > | |
ItemIDType | InsertResource (ElementType &&Element) |
Inserts a resource into the resource manager. More... | |
template<typename DerivedType > | |
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... | |
template<typename LibraryVectorT > | |
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... | |
Public Attributes | |
LinkBaseOnlyType | LinkBaseOnly |
Protected Member Functions | |
ResourceManagerBase () | |
~ResourceManagerBase ()=default | |
Protected Member Functions inherited from DynExp::CommonResourceManagerBase | |
CommonResourceManagerBase ()=default | |
~CommonResourceManagerBase ()=default | |
Private Types | |
template<typename T > | |
using | ShareResourceEnablerType = std::enable_if_t< std::is_same_v< std::shared_ptr< typename T::element_type >, PointerType >, int > |
SFINAE alias to define methods assuming shared resource ownership only if PointerType is a std::shared_ptr pointing to a type T::element_type . More... | |
using | MapType = std::unordered_map< ItemIDType, ResourceType > |
Type of a map mapping DynExp object IDs (ItemIDType ) to DynExp resources (ResourceType ) More... | |
Private Member Functions | |
auto | LookUpResource (ItemIDType ID) const |
Retrieves a resource specified by its ID from the resource manager. More... | |
template<typename ElementType > | |
ItemIDType | InsertResource (ElementType &&Element, const ItemIDType ID) |
Inserts a resource into the resource manager. More... | |
void | RaiseID (const ItemIDType ConsumedID) |
If CurrentID is less or equal to ConsumedID , sets CurrentID to ConsumedID + 1. If CurrentID is greater than ConsumedID , does nothing. More... | |
void | IncrementID () |
Increments CurrentID. More... | |
Override | |
Override by derived classes. | |
virtual void | StartupChild (FunctionToCallWhenObjectStartedType FunctionToCallWhenObjectStarted) const =0 |
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 |
Calls ShutdownChild() to terminate and clean up all resources stored in this resource manager. More... | |
virtual void | PrepareResetChild () |
Prepares all resources stored in this resource manager for their deletion by e.g. asking them to terminate. More... | |
virtual void | ResetChild () |
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... | |
virtual QDomElement | MakeXMLConfigHeadNode (QDomDocument &Document) const =0 |
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... | |
Private Attributes | |
MapType | Map |
Map storing all resources owned by this resource manager. More... | |
ItemIDType | CurrentID |
ID, the next resource added to the manager will receive. After initialization and reset (Reset() ), the CurrentID will start with 1, so that 0 can have a special meaning (e.g. "resource not set"). More... | |
Additional Inherited Members | |
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... | |
Typed resource manager base class deriving from class CommonResourceManagerBase
.
PointerType | Type of the pointers pointing to the managed DynExp::Object instances |
Definition at line 86 of file Managers.h.
|
private |
Type of a map mapping DynExp object IDs (ItemIDType
) to DynExp resources (ResourceType
)
Definition at line 122 of file Managers.h.
using DynExp::ResourceManagerBase< PointerType >::ResourceType = Resource<PointerType> |
Type of the managed DynExp resources.
Definition at line 111 of file Managers.h.
|
private |
SFINAE alias to define methods assuming shared resource ownership only if PointerType
is a std::shared_ptr
pointing to a type T::element_type
.
T | Pointer type with an alias element_type to perform the test with |
Definition at line 120 of file Managers.h.
|
inlineprotected |
Definition at line 125 of file Managers.h.
|
protecteddefault |
|
inlinenoexcept |
Returns an iterator to the first resource stored in the resource manager.
const
iterator pointing to the beginning of Map. Definition at line 220 of file Managers.h.
|
inlinenoexcept |
Returns an iterator behind the last resource stored in the resource manager.
const
iterator pointing to the end of Map. Definition at line 226 of file Managers.h.
void DynExp::ResourceManagerBase< PointerType >::ClearResourcesWarnings |
Calls Object::ClearWarning() on all resources stored in this resource manager.
Definition at line 487 of file Managers.h.
void DynExp::ResourceManagerBase< PointerType >::DeleteAllTreeWidgetItems |
Deletes the Resource::TreeWidgetItem of all resources stored in this resource manager.
Definition at line 548 of file Managers.h.
void DynExp::ResourceManagerBase< PointerType >::DeleteTreeWidgetItem | ( | ItemIDType | ID | ) |
Deletes the Resource::TreeWidgetItem of the requested resource.
ID | ID of the resource whose Resource::TreeWidgetItem to delete. |
Util::NotFoundException | is thrown if the resource manager does not own a resource with ID (resource not found in Map). |
Definition at line 431 of file Managers.h.
|
inlinenoexcept |
Determines whether this resource manager is empty.
Definition at line 145 of file Managers.h.
QDomElement DynExp::ResourceManagerBase< PointerType >::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()
.
Document | Qt dom document within to create the dom element. |
Definition at line 526 of file Managers.h.
PointerType DynExp::ResourceManagerBase< PointerType >::ExtractResource | ( | ItemIDType | ID | ) |
Releases ownership of the owned resource with ID
and returns it.
ID | ID of the resource to extract |
PointerType
pointing to the extracted resource. Util::NotFoundException | is thrown if the resource manager does not own a resource with ID (resource not found in Map). |
Definition at line 406 of file Managers.h.
ItemIDListType DynExp::ResourceManagerBase< PointerType >::Filter |
Builds and returns a list of the IDs of all resources stored in this resource manager which can be cast to DerivedType
.
DerivedType | Type derived from DynExp::Object to filter the resources with |
ItemIDListType
) of the resource IDs belonging to owned resources which are of type DerivedType
. Definition at line 475 of file Managers.h.
void DynExp::ResourceManagerBase< PointerType >::FocusTreeWidgetItem | ( | ItemIDType | ID | ) |
Selects the Resource::TreeWidgetItem of the requested resource.
ID | ID of the resource whose Resource::TreeWidgetItem to select. |
Util::NotFoundException | is thrown if the resource manager does not own a resource with ID (resource not found in Map). |
Definition at line 437 of file Managers.h.
ItemIDListType DynExp::ResourceManagerBase< PointerType >::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.
OnlyResourcesBeingInUse | If this argument is true, only resources are considered for which Object::IsUnused() returns false (i.e. resources which are used by other DynExp::Object instances). Otherwise, all owned resources are considered. |
ItemIDListType
) of the resource IDs belonging to owned resources which are in an error state (determined by Object::GetException()). Definition at line 495 of file Managers.h.
|
inlinenoexcept |
Getter for the ID to assign to the next resource to be inserted into the resource manager.
Definition at line 133 of file Managers.h.
|
inlinenoexcept |
Determines the amount of resources stored in this resource manager.
Definition at line 139 of file Managers.h.
PointerType::element_type * DynExp::ResourceManagerBase< PointerType >::GetResource | ( | ItemIDType | ID | ) |
Retrieves a resource specified by its ID from the resource manager.
ID | ID of the resource to return |
Util::NotFoundException | is thrown if the resource manager does not own a resource with ID (resource not found in Map). |
Definition at line 400 of file Managers.h.
const PointerType::element_type * DynExp::ResourceManagerBase< PointerType >::GetResource | ( | ItemIDType | ID | ) | const |
Retrieves a resource specified by its ID from the resource manager.
ID | ID of the resource to return |
Util::NotFoundException | is thrown if the resource manager does not own a resource with ID (resource not found in Map). |
Definition at line 394 of file Managers.h.
|
private |
Increments CurrentID.
Util::OverflowException | is thrown if CurrentID cannot be incremented without causing a numeric overflow. |
Definition at line 618 of file Managers.h.
ItemIDType DynExp::ResourceManagerBase< PointerType >::InsertResource | ( | ElementType && | Element | ) |
Inserts a resource into the resource manager.
ElementType | Type of Element , which is perfectly forwarded to the constructor of ResourceType to create a DynExp resource to insert into the resource manager. |
Element | Pointer to a DynExp object (e.g. DynExp::ModulePtrType). |
ID | ID of the resource to insert |
ID
. Util::InvalidArgException | is thrown if ID is DynExp::ItemIDNotSet. |
Util::InvalidStateException | is thrown if the resource manager owns already a resource with ID (resource already stored in Map). |
Definition at line 468 of file Managers.h.
|
private |
Inserts a resource into the resource manager.
ElementType | Type of Element , which is perfectly forwarded to the constructor of ResourceType to create a DynExp resource to insert into the resource manager. |
Element | Pointer to a DynExp object (e.g. DynExp::ModulePtrType). |
ID | ID of the resource to insert |
ID
. Util::InvalidArgException | is thrown if ID is DynExp::ItemIDNotSet. |
Util::InvalidStateException | is thrown if the resource manager owns already a resource with ID (resource already stored in Map). |
Definition at line 591 of file Managers.h.
|
private |
Retrieves a resource specified by its ID from the resource manager.
ID | ID of the resource to return |
ID
. Util::NotFoundException | is thrown if the resource manager does not own a resource with ID (resource not found in Map). |
Definition at line 579 of file Managers.h.
void DynExp::ResourceManagerBase< PointerType >::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.
LibraryVectorT | Type of the library containing the DynExp::Object types available to this resource manager (any of HardwareAdapterLibraryVectorType , InstrumentLibraryVectorType , or ModuleLibraryVectorType ) |
XMLNode | XML root node of the (single) resource manager instance of the derived manager type. |
Library | Library to to create resources from |
Core | Reference to DynExp's core |
Util::InvalidDataException | is thrown if the XML tree does not contain data in the expected format. |
Definition at line 555 of file Managers.h.
|
privatepure virtual |
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()
.
Document | Qt dom document within to create the dom element. |
Implemented in DynExp::ModuleManager, DynExp::InstrumentManager, and DynExp::HardwareAdapterManager.
|
inline |
Prepares all resources stored in this resource manager for their deletion by e.g. asking them to terminate.
Definition at line 283 of file Managers.h.
|
inlineprivatevirtual |
Prepares all resources stored in this resource manager for their deletion by e.g. asking them to terminate.
Reimplemented in DynExp::ModuleManager, and DynExp::InstrumentManager.
Definition at line 369 of file Managers.h.
|
private |
void DynExp::ResourceManagerBase< PointerType >::RemoveResource | ( | ItemIDType | ID, |
const std::chrono::milliseconds | Timeout = Util::ILockable::DefaultTimeout |
||
) |
Removes the resource identified by ID
from the resource manager and deletes it.
ID | ID of the resource to remove |
Timeout |
Util::NotFoundException | is thrown if the resource manager does not own a resource with ID (resource not found in Map). |
Definition at line 418 of file Managers.h.
void DynExp::ResourceManagerBase< PointerType >::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.
Definition at line 517 of file Managers.h.
|
inlineprivatevirtual |
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.
Definition at line 370 of file Managers.h.
void DynExp::ResourceManagerBase< PointerType >::ResetFailedResources |
Calls Object::Reset() on all resources stored in this resource manager which are in an error state (determined by Object::GetException()).
Definition at line 508 of file Managers.h.
auto DynExp::ResourceManagerBase< PointerType >::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
).
T | Set to PointerType . Do not pass anything. |
ID | ID of the resource to share |
Util::NotFoundException | is thrown if the resource manager does not own a resource with ID (resource not found in Map). |
Definition at line 461 of file Managers.h.
auto DynExp::ResourceManagerBase< PointerType >::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
).
T | Set to PointerType . Do not pass anything. |
ID | ID of the resource to share |
Util::NotFoundException | is thrown if the resource manager does not own a resource with ID (resource not found in Map). |
Definition at line 454 of file Managers.h.
|
inline |
Calls ShutdownChild()
to terminate and clean up all resources stored in this resource manager.
Definition at line 255 of file Managers.h.
|
inlineprivatevirtual |
Calls ShutdownChild()
to terminate and clean up all resources stored in this resource manager.
Reimplemented in DynExp::ModuleManager, and DynExp::InstrumentManager.
Definition at line 368 of file Managers.h.
|
inline |
Starts all resources owned by the resource manager. For HardwareAdapterBase
instances, Object::EnsureReadyState() is called. For InstrumentBase
and ModuleBase
instances, RunnableObject::RunIfRunOnCreation() is called.
FunctionToCallWhenObjectStarted | Callback function. Refer to FunctionToCallWhenObjectStartedType . |
Definition at line 250 of file Managers.h.
|
privatepure virtual |
Starts all resources owned by the resource manager. For HardwareAdapterBase
instances, Object::EnsureReadyState() is called. For InstrumentBase
and ModuleBase
instances, RunnableObject::RunIfRunOnCreation() is called.
FunctionToCallWhenObjectStarted | Callback function. Refer to FunctionToCallWhenObjectStartedType . |
Implemented in DynExp::ModuleManager, DynExp::InstrumentManager, and DynExp::HardwareAdapterManager.
|
private |
ID, the next resource added to the manager will receive. After initialization and reset (Reset()
), the CurrentID will start with 1, so that 0 can have a special meaning (e.g. "resource not set").
Definition at line 390 of file Managers.h.
LinkBaseOnlyType DynExp::ResourceManagerBase< PointerType >::LinkBaseOnly |
Definition at line 322 of file Managers.h.
|
private |
Map storing all resources owned by this resource manager.
Definition at line 383 of file Managers.h.