DynExp
Highly flexible laboratory automation for dynamically changing experiments.
DynExp::ModuleBase Class Referenceabstract

Base class for modules. Modules implement programs on their own (e.g. measurement protocols or servers for ethernet communication). They might have a user interface. Modules make use of meta instruments (InstrumentBase) to implement e.g. measurement routines on a higher level, which renders the modules independent from physical devices from specific manufacturers. Derive from this class to implement modules without a user interface. More...

+ Inheritance diagram for DynExp::ModuleBase:

Classes

class  EventListenersOnlyType
 Allow exclusive access to some of ModuleBase's private methods to any TypedEventListeners class. More...
 
class  ModuleThreadOnlyType
 Allow exclusive access to some of ModuleBase's private methods to the module thread ModuleThreadMain(). More...
 

Public Types

using ParamsType = ModuleParamsBase
 Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object. More...
 
using ConfigType = ModuleConfiguratorBase
 Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object. More...
 
using ModuleDataType = ModuleDataBase
 Type of the data class belonging to this ModuleBase type. Declare this alias in every derived class with the respective data class accompanying the derived ModuleBase. More...
 
using ModuleDataTypeSyncPtrType = Util::SynchronizedPointer< ModuleDataType >
 Alias for the return type of ModuleBase::GetModuleData(). Data class instances wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way. More...
 
using ModuleDataTypeSyncPtrConstType = Util::SynchronizedPointer< const ModuleDataType >
 Alias for the return type of ModuleBase::GetModuleData() const. Data class instances wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way. More...
 
using ModuleDataGetterType = Util::CallableMemberWrapper< ModuleBase, ModuleDataTypeSyncPtrType(ModuleBase::*)(const std::chrono::milliseconds)>
 Invoking an instance of this alias is supposed to call ModuleBase::GetModuleData() of the instance the Util::CallableMemberWrapper has been constructed with. More...
 
- Public Types inherited from DynExp::RunnableObject
using ParamsType = RunnableObjectParams
 Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object. More...
 
using ConfigType = RunnableObjectConfigurator
 Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object. More...
 
- Public Types inherited from DynExp::Object
using ParamsType = ParamsBase
 Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object. More...
 
using ParamsTypeSyncPtrType = Util::SynchronizedPointer< ParamsType >
 Alias for the return type of Object::GetParams(). Parameters wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way. More...
 
using ParamsConstTypeSyncPtrType = Util::SynchronizedPointer< const ParamsType >
 Alias for the return type of Object::GetParams() const. Parameters wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way. More...
 
using ConfigType = ConfiguratorBase
 Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object. More...
 
using ParamsGetterType = Util::CallableMemberWrapper< Object, decltype(&Object::GetParams)>
 Invoking an instance of this alias is supposed to call Object::GetParams() of the instance the Util::CallableMemberWrapper has been constructed with. More...
 

Public Member Functions

 ModuleBase (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
 Constructs a ModuleBase instance. More...
 
virtual ~ModuleBase ()=0
 
virtual std::string GetCategory () const override
 Returns the category of this Object type. More...
 
Thread-safe public functions

Methods can be called from any thread.

void RestoreWindowStatesFromParams ()
 RestoreWindowStatesFromParams() only calls RestoreWindowStatesFromParamsChild(). Override RestoreWindowStatesFromParamsChild() to restore the styles of possibly owned windows according to the style saved in the module's parameters. More...
 
void UpdateParamsFromWindowStates ()
 UpdateParamsFromWindowStates() only calls UpdateParamsFromWindowStatesChild(). Override UpdateParamsFromWindowStatesChild() to store the styles of possibly owned windows in the module's parameters. More...
 
ModuleDataTypeSyncPtrType GetModuleData (const std::chrono::milliseconds Timeout=GetModuleDataTimeoutDefault)
 Locks the mutex of the module data class instance ModuleData assigned to this ModuleBase instance and returns a pointer to the locked ModuleData. Module data should not be locked by having called this function while subsequently calling a derived module's method which also makes use of the module's data by locking it. If this happens, the module data's mutex is locked recursively. In principle, this does no harm since Util::ISynchronizedPointerLockable supports that. But, it is not considered good practice. More...
 
ModuleDataTypeSyncPtrConstType GetModuleData (const std::chrono::milliseconds Timeout=GetModuleDataTimeoutDefault) const
 Locks the mutex of the module data class instance ModuleData assigned to this ModuleBase instance and returns a pointer to the locked ModuleData. Module data should not be locked by having called this function while subsequently calling a derived module's method which also makes use of the module's data by locking it. If this happens, the module data's mutex is locked recursively. In principle, this does no harm since Util::ISynchronizedPointerLockable supports that. But, it is not considered good practice. More...
 
void EnqueueEvent (ModuleDataBase::EventPtrType &&Event) const
 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...
 
template<typename ReceiverType , typename EventType , typename... ArgsTs>
void MakeAndEnqueueEvent (ReceiverType *Receiver, EventType EventFuncPtr, ArgsTs &&...Args) const
 Calls MakeEvent() to construct a new event and subsequently enqueues the event into the module's event queue. Logical const-ness: this is a const member function to allow pointers to const ModuleBase inserting events into the module's event queue. These kind of pointers are e.g. returned by RunnableInstance::GetOwner() which can be called by events' EventBase::InvokeChild() functions. For const ModuleBase*, it is possible to insert events into the event queue, but not to change the ModuleBase object itself (e.g. calling Object::Reset()). More...
 
- Public Member Functions inherited from DynExp::RunnableObject
 RunnableObject (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
 Constructs an Object instance. More...
 
virtual ~RunnableObject ()=0
 
void SetPaused (bool Pause, std::string Description="")
 Pauses or resumes a RunnableObject instance. Its thread stays running, but the instance does not perform any action while it is paused. More...
 
bool IsRunning () const noexcept
 Returns Running. More...
 
bool IsPaused () const noexcept
 Returns Paused. More...
 
bool IsExiting () const noexcept
 Returns ShouldExit. More...
 
auto GetStartupType () const noexcept
 Returns Startup. More...
 
auto GetReasonWhyPaused () const
 Returns ReasonWhyPaused. More...
 
bool Run (QWidget *ParentWidget=nullptr)
 Starts the RunnableObject instance's thread and ensures that all Object instances linked to this instance via ObjectLink parameters are in a ready state. Calls RunChild() which is to be overridden by derived classes to start a thread and to pass this thread back by calling StoreThread(). More...
 
bool RunIfRunAutomatic ()
 Calls Run() if RunnableObjectParams::Startup is set to RunnableObjectParams::Automatic. More...
 
bool RunIfRunOnCreation ()
 Calls Run() if RunnableObjectParams::Startup is set to RunnableObjectParams::OnCreation. More...
 
void Terminate (bool Force=false, const std::chrono::milliseconds Timeout=TerminateTimeoutDefault)
 Notifies the RunnableObject instance's thread to terminate and waits until it has ended. Calls TerminateImpl(). More...
 
- Public Member Functions inherited from Util::INonCopyable
 INonCopyable (const INonCopyable &)=delete
 
INonCopyableoperator= (const INonCopyable &)=delete
 
- Public Member Functions inherited from DynExp::Object
ItemIDType GetID () const noexcept
 Returns the ID of this Object instance. Thread-safe since ID is const. More...
 
std::string GetCategoryAndName () const
 Builds a string from an Object's category and name to allow the user to identify an Object's type. More...
 
void EnsureReadyState (bool IsAutomaticStartup)
 Ensures that this Object instance is ready by possibly starting its worker thread or by opening connections to hardware devices. More...
 
void CheckLinkedObjectStates () const
 Checks whether Object instances this instance uses are in a ready state. Override CheckLinkedObjectStatesChild() to implement this behavior. More...
 
void Reset ()
 Resets this Object instance (including all its derived classes) by calling ResetImpl(). A reset implies that the derived classes reload all their parameters from Params and that all LinkedObjectWrapper instances owned by this Object instance become invalidated. More...
 
void BlockIfUnused (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout)
 Blocks this Object instance setting Object::IsBlocked to true. Refer to Object::IsBlocked for the consequences. More...
 
ParamsConstTypeSyncPtrType GetParams (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Locks the mutex of the parameter class instance Params assigned to this Object instance and returns a pointer to the locked Params. More...
 
ParamsTypeSyncPtrType GetParams (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault)
 Locks the mutex of the parameter class instance Params assigned to this Object instance and returns a pointer to the locked Params. More...
 
auto GetObjectName (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Returns the name of this Object instance. More...
 
bool IsSharedUsageEnabled (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Returns whether shared usage has been enabled for this Object instance. Refer to ParamsBase::UsageType. More...
 
void SetWarning (std::string Description, int ErrorCode) const
 Setter for Object::Warning. Sets the warning by a description and an error code. More...
 
void SetWarning (const Util::Exception &e) const
 Setter for Object::Warning. Sets the warning by retrieving the warning data from an exception e. More...
 
void ClearWarning () const
 Resets Object::Warning. More...
 
auto GetWarning () const
 Returns Object::Warning in a thread-safe way by copying its internal data. More...
 
std::exception_ptr GetException (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Returns a pointer to the exception which has caused this Object instance to fail. More...
 
bool IsReady () const
 Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) and not blocked (refer to Object::IsBlocked). More...
 
auto GetUseCount (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Counts the registered useres in a thread-safe way. More...
 
bool IsUnused (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Returns whether this Object instance is used by other instances. More...
 
auto GetUserIDs (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Returns a list of the IDs of the registered users in a thread-safe way. More...
 
auto GetUserNamesString (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Builds a string describing which users are registered containing their object names, categories and type names in a thread-safe way. More...
 
virtual std::string GetName () const =0
 Returns the name of this Object type. More...
 

Static Public Member Functions

constexpr static auto Category () noexcept
 Every derived class has to redefine this function. More...
 
- Static Public Member Functions inherited from DynExp::Object
static std::string CategoryAndNameToStr (const std::string &Category, const std::string &Name)
 Builds a string from an Object's category and name to allow the user to identify an Object's type. More...
 

Public Attributes

ModuleThreadOnlyType ModuleThreadOnly
 Allow exclusive access to some of ModuleBase's private methods to the module thread ModuleThreadMain(). More...
 
EventListenersOnlyType EventListenersOnly
 Allow exclusive access to some of ModuleBase's private methods to any TypedEventListeners class. More...
 
- Public Attributes inherited from DynExp::RunnableObject
RunnableInstanceOnlyType RunnableInstanceOnly
 Allow exclusive access to some of RunnableObject's private methods to class RunnableInstance. More...
 
- Public Attributes inherited from DynExp::Object
LinkedObjectWrapperOnlyType LinkedObjectWrapperOnly
 Allow exclusive access to some of Object's private methods to any LinkedObjectWrapper<T>. More...
 

Static Public Attributes

static constexpr auto GetModuleDataTimeoutDefault = std::chrono::milliseconds(1000)
 Determines the default timeout for GetModuleData() to lock the mutex synchronizing the module's data ModuleData. More...
 
- Static Public Attributes inherited from DynExp::RunnableObject
static constexpr auto ShortTimeoutDefault = std::chrono::milliseconds(50)
 Default timeout e.g. used as a default for calls to InstrumentBase::GetInstrumentData or ModuleBase::GetModuleData. More...
 
static constexpr auto TerminateTimeoutDefault = std::chrono::milliseconds(3000)
 Default timeout used as a default for calls to RunnableObject::Terminate. More...
 
- Static Public Attributes inherited from DynExp::Object
static constexpr std::chrono::milliseconds GetParamsTimeoutDefault = std::chrono::milliseconds(100)
 Default timeout used by Object::GetParams() to lock the mutex of the parameter instance assigned to this Object instance. More...
 

Static Protected Member Functions

static auto GetExceptionUnsafe (const ModuleDataTypeSyncPtrConstType &ModuleDataPtr)
 Getter for ModuleDataBase::ModuleException assuming that the module data has already been locked. More...
 

Private Member Functions

void ResetImpl (dispatch_tag< RunnableObject >) override final
 Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy. More...
 
virtual void ResetImpl (dispatch_tag< ModuleBase >)=0
 Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy. More...
 
void ModuleSetReasonWhyPaused (std::string Description)
 Sets the reason why this ModuleBase instance has been paused. More...
 
std::exception_ptr GetExceptionChild ([[maybe_unused]] const std::chrono::milliseconds Timeout) const override final
 
bool IsReadyChild () const override final
 Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) and not blocked (refer to Object::IsBlocked). More...
 
Private functions for logical const-ness

Logical const-ness: refer to ModuleBase::MakeAndEnqueueEvent().

ModuleDataTypeSyncPtrType GetNonConstModuleData (const std::chrono::milliseconds Timeout=GetModuleDataTimeoutDefault) const
 Always allows ModuleBase to obtain a non-const pointer to the module's data - even in const event functions. More...
 
Module thread only

These functions must be called by module thread only.

void HandleEvent (ModuleInstance &Instance)
 Executes and removes the next pending event from the module's event queue. More...
 
void AddRegisteredEvent (EventListenersBase &EventListeners)
 Adds a manager of event listeners to RegisteredEvents if it was not already added before. Called indirectly by TypedEventListeners::Register(). More...
 
void RemoveRegisteredEvent (EventListenersBase &EventListeners)
 Removes a manager of event listeners from RegisteredEvents if it was added before. Called indirectly by TypedEventListeners::Deregister(). More...
 
Util::DynExpErrorCodes::DynExpErrorCodes ExecModuleMainLoop (ModuleInstance &Instance)
 Runs ModuleMainLoop(). More...
 
void OnPause (ModuleInstance &Instance)
 This handler gets called just after the module pauses due to e.g. an error in an instrument the module depends on. Override OnPauseChild() to e.g. abort a measurement or to store internal states for resuming later. More...
 
void OnResume (ModuleInstance &Instance)
 This handler gets called just after the module resumed from a paused state. Override OnResumeChild() to reinitialize instruments or a measurement routine. More...
 
void OnError (ModuleInstance &Instance)
 This handler gets called just before the module thread terminates due to an exception. Override OnErrorChild() to perform shutdown and cleanup actions. More...
 
Main thread only

These functions must not be called by module thread.

void RunChild () override final
 Refer to Run(). More...
 
void NotifyChild () override final
 Notify derived classes that some state has changed (e.g. the termination of Thread is requested) and that the child's event/task queue should run now. More...
 
void TerminateChild (const std::chrono::milliseconds Timeout) override final
 Signals derived classes that terminating the RunnableObject instance's thread is about to be requested. Derived classes might now enqueue respective exit tasks/events into their task/event queues. Refer to TerminateUnsafe(). More...
 
std::unique_ptr< BusyDialogMakeStartupBusyDialogChild (QWidget *ParentWidget) const override final
 Override to make this function return a pointer to a BusyDialog instance. Refer to Run(). More...
 
Events

Event functions running in the module thread.

virtual void OnInit (ModuleInstance *Instance) const
 This event is triggered right before the module thread starts. Override it to lock instruments this module depends on (via RunnableInstance::LockObject()) and to register/subscribe for events (via InterModuleEvent::Register()). More...
 
virtual void OnExit (ModuleInstance *Instance) const
 This event is triggered right before the module thread terminates (not due to an exception, in this case refer to ModuleBase::OnError). Override it to unlock instruments this module depends on (via RunnableInstance::UnlockObject()) and to deregister/unsubscribe from events (via InterModuleEvent::Deregister()). More...
 
void OnDeregisterEvents (ModuleInstance *Instance) const
 This event is triggered after the OnExit event. It calls EventListenersBase::Deregister() for all managers of event listeners stored in RegisteredEvents since we do not trust in derived modules deregistering/unsubscribing from all registered events via InterModuleEvent::Deregister(). More...
 

Private Attributes

const std::unique_ptr< ModuleDataTypeModuleData
 Module data belonging to this ModuleBase instance. More...
 
std::vector< EventListenersBase * > RegisteredEvents
 Holds a list of pointers to managers of event listeners of the events this module has registered/subscribed to. The stored pointers always outlive all module instances since they are static members of types derived from InterModuleEvent. More...
 

Override

Override by derived classes.

virtual bool HasUI () const noexcept
 Determines whether this module possesses a user interface (UI) which is shown in a window dedicated to the module. More...
 
virtual bool TreatModuleExceptionsAsWarnings () const
 Determines whether this module should be terminated if an exception leaves the module's main loop or respective event handlers. More...
 
virtual std::chrono::milliseconds GetMainLoopDelay () const
 Specifies in which time intervals the module's event queue runs to handle pending events. More...
 
virtual void OnPauseChild (ModuleInstance &Instance) const
 This handler gets called just after the module pauses due to e.g. an error in an instrument the module depends on. Override OnPauseChild() to e.g. abort a measurement or to store internal states for resuming later. More...
 
virtual void OnResumeChild (ModuleInstance &Instance) const
 This handler gets called just after the module resumed from a paused state. Override OnResumeChild() to reinitialize instruments or a measurement routine. More...
 
virtual void OnErrorChild (ModuleInstance &Instance) const
 This handler gets called just before the module thread terminates due to an exception. Override OnErrorChild() to perform shutdown and cleanup actions. More...
 
virtual void RestoreWindowStatesFromParamsChild ()
 RestoreWindowStatesFromParams() only calls RestoreWindowStatesFromParamsChild(). Override RestoreWindowStatesFromParamsChild() to restore the styles of possibly owned windows according to the style saved in the module's parameters. More...
 
virtual void UpdateParamsFromWindowStatesChild ()
 UpdateParamsFromWindowStates() only calls UpdateParamsFromWindowStatesChild(). Override UpdateParamsFromWindowStatesChild() to store the styles of possibly owned windows in the module's parameters. More...
 
virtual Util::DynExpErrorCodes::DynExpErrorCodes ModuleMainLoop (ModuleInstance &Instance)=0
 Module main loop. The function is executed periodically by the module thread. Also refer to GetMainLoopDelay(). More...
 

Additional Inherited Members

- Protected Member Functions inherited from DynExp::RunnableObject
void Init ()
 Initializes member variables in case of a reset. More...
 
std::promise< void > MakeThreadExitedPromise ()
 Helper function to be used by overridden RunChild() functions in derived classes to (re)initialize the ThreadExitedSignal future and to provide the derived class a promise to signal the RunnableObject instance that its thread has terminated. More...
 
void StoreThread (std::thread &&Thread) noexcept
 Stores a thread constructed by a derived class overriding RunChild() in Thread taking ownership of the thread. Only call this function within RunChild()! More...
 
bool IsCallFromRunnableThread () const
 Checks whether Thread's id matches the id of the calling thread. This is thread-safe if the function is called by the RunnableObject instance's thread since Terminate() joins the threads before changing the Thread member. It is also thread-safe if the function is called by the thread owning the the RunnableObject instance since Run() and Terminate() can only be called by this thread. Only Run() and Terminate() (indirectly) modify Thread. More...
 
void EnsureCallFromRunnableThread () const
 Asserts that the call to this function is performed from the RunnableObject instance's thread by calling IsCallFromRunnableThread(). More...
 
void SetReasonWhyPaused (std::string Description)
 Sets the reason why this RunnableObject instance has been paused. More...
 
void SetReasonWhyPaused (const Util::Exception &e)
 Sets the reason why this RunnableObject instance has been paused. More...
 
void ClearReasonWhyPaused ()
 Removes the reason why this RunnableObject instance has been paused (since it is resumed). More...
 
- Protected Member Functions inherited from Util::INonCopyable
constexpr INonCopyable ()=default
 
 ~INonCopyable ()=default
 
- Protected Member Functions inherited from DynExp::Object
 Object (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
 Constructs an Object instance. More...
 
virtual ~Object ()=0
 
void EnsureCallFromOwningThread () const
 Asserts that the call to this function is performed from the thread which constructed this Object instance (the thread with the id stored in Object::OwnerThreadID). More...
 
ParamsTypeSyncPtrType GetNonConstParams (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Allows derived Objects to edit their own parameters - even in const task functions (for instruments) or event functions (for modules). More...
 
auto LockUserList (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout)
 Locks the user list for thread-safe manipulation. More...
 
void DeregisterAllUnsafe ()
 Deregisters all users and notifies them that they need to check the states of their used linked objects. More...
 
auto GetUseCountUnsafe ()
 
auto GetUserNamesStringUnsafe () const
 
bool IsUnusedUnsafe ()
 Returns whether this Object instance is used by other instances (not thread-safe). More...
 

Detailed Description

Base class for modules. Modules implement programs on their own (e.g. measurement protocols or servers for ethernet communication). They might have a user interface. Modules make use of meta instruments (InstrumentBase) to implement e.g. measurement routines on a higher level, which renders the modules independent from physical devices from specific manufacturers. Derive from this class to implement modules without a user interface.

Definition at line 391 of file Module.h.

Member Typedef Documentation

◆ ConfigType

Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object.

Definition at line 444 of file Module.h.

◆ ModuleDataGetterType

Invoking an instance of this alias is supposed to call ModuleBase::GetModuleData() of the instance the Util::CallableMemberWrapper has been constructed with.

Definition at line 586 of file Module.h.

◆ ModuleDataType

Type of the data class belonging to this ModuleBase type. Declare this alias in every derived class with the respective data class accompanying the derived ModuleBase.

Definition at line 450 of file Module.h.

◆ ModuleDataTypeSyncPtrConstType

Alias for the return type of ModuleBase::GetModuleData() const. Data class instances wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way.

Definition at line 462 of file Module.h.

◆ ModuleDataTypeSyncPtrType

Alias for the return type of ModuleBase::GetModuleData(). Data class instances wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way.

Definition at line 456 of file Module.h.

◆ ParamsType

Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object.

Definition at line 443 of file Module.h.

Constructor & Destructor Documentation

◆ ModuleBase()

DynExp::ModuleBase::ModuleBase ( const std::thread::id  OwnerThreadID,
ParamsBasePtrType &&  Params 
)

Constructs a ModuleBase instance.

Parameters
OwnerThreadIDThread id of the thread owning the Object instance to be constructed.
ParamsParameter class instance to be assigned to the Object instance to be constructed.
Exceptions
Util::InvalidArgExceptionis thrown if OwnerThreadID is an invalid thread id or if Params is nullptr.
Util::InvalidArgExceptionis thrown if ModuleParamsBase::ModuleData of Params is nullptr.

Definition at line 189 of file Module.cpp.

◆ ~ModuleBase()

DynExp::ModuleBase::~ModuleBase ( )
pure virtual

Definition at line 198 of file Module.cpp.

Member Function Documentation

◆ AddRegisteredEvent()

void DynExp::ModuleBase::AddRegisteredEvent ( EventListenersBase EventListeners)
private

Adds a manager of event listeners to RegisteredEvents if it was not already added before. Called indirectly by TypedEventListeners::Register().

Parameters
EventListenersManager of event listeners to add

Definition at line 242 of file Module.cpp.

◆ Category()

constexpr static auto DynExp::ModuleBase::Category ( )
inlinestaticconstexprnoexcept

Every derived class has to redefine this function.

Returns
Returns the category of this module type.

Definition at line 468 of file Module.h.

◆ EnqueueEvent()

void DynExp::ModuleBase::EnqueueEvent ( ModuleDataBase::EventPtrType &&  Event) const

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.

Parameters
EventPointer to the event to be enqueued. Must not be nullptr.
Exceptions
Util::InvalidArgExceptionis thrown if Event is nullptr.

Definition at line 212 of file Module.cpp.

◆ ExecModuleMainLoop()

Util::DynExpErrorCodes::DynExpErrorCodes DynExp::ModuleBase::ExecModuleMainLoop ( ModuleInstance Instance)
private

Runs ModuleMainLoop().

Parameters
InstanceHandle to the module thread's data
Returns
Return Util::DynExpErrorCodes::NoError if module loop should continue, annother error code otherwise.

Definition at line 264 of file Module.cpp.

◆ GetCategory()

◆ GetExceptionChild()

std::exception_ptr DynExp::ModuleBase::GetExceptionChild ( [[maybe_unused] ] const std::chrono::milliseconds  Timeout) const
finaloverrideprivate

Definition at line 358 of file Module.cpp.

◆ GetExceptionUnsafe()

static auto DynExp::ModuleBase::GetExceptionUnsafe ( const ModuleDataTypeSyncPtrConstType ModuleDataPtr)
inlinestaticprotected

Getter for ModuleDataBase::ModuleException assuming that the module data has already been locked.

Parameters
ModuleDataPtrSynchronized pointer to the locked ModuleDataBase instance.
Returns
Returns the exception being responsible for the module's current state.

Definition at line 610 of file Module.h.

◆ GetMainLoopDelay()

virtual std::chrono::milliseconds DynExp::ModuleBase::GetMainLoopDelay ( ) const
inlinevirtual

Specifies in which time intervals the module's event queue runs to handle pending events.

Returns
Delay time in between event queue executions. Return std::chrono::milliseconds::max() to make the module thread only wake up to execute the module main loop (after handling enqueued events) when an event is enqueued. Return 0 to make the module main loop execute as fast as possible.

Reimplemented in DynExpModule::Widefield::WidefieldMicroscope, DynExpModule::Trajectory1D, DynExpModule::StreamManipulator, DynExpModule::Stage1D, DynExpModule::SpectrumViewer::SpectrumViewer, DynExpModule::SignalPlotter, DynExpModule::OutputPortWriter, DynExpModule::ODMR::ODMR, DynExpModule::LockinAmplifierControl, DynExpModule::InputPortReader, DynExpModule::ImageViewer::ImageViewer, DynExpModule::gRPCModule< gRPCServices >, DynExpModule::gRPCModule< gRPCServices... >, and DynExpModule::ArbitraryFunctionFromCSV.

Definition at line 506 of file Module.h.

◆ GetModuleData() [1/2]

ModuleBase::ModuleDataTypeSyncPtrType DynExp::ModuleBase::GetModuleData ( const std::chrono::milliseconds  Timeout = GetModuleDataTimeoutDefault)

Locks the mutex of the module data class instance ModuleData assigned to this ModuleBase instance and returns a pointer to the locked ModuleData. Module data should not be locked by having called this function while subsequently calling a derived module's method which also makes use of the module's data by locking it. If this happens, the module data's mutex is locked recursively. In principle, this does no harm since Util::ISynchronizedPointerLockable supports that. But, it is not considered good practice.

Parameters
TimeoutTime to wait for locking the mutex of ModuleData.
Returns
Returns a pointer to ModuleDataType (non-const) to allow access all of its members.

Definition at line 202 of file Module.cpp.

◆ GetModuleData() [2/2]

ModuleBase::ModuleDataTypeSyncPtrConstType DynExp::ModuleBase::GetModuleData ( const std::chrono::milliseconds  Timeout = GetModuleDataTimeoutDefault) const

Locks the mutex of the module data class instance ModuleData assigned to this ModuleBase instance and returns a pointer to the locked ModuleData. Module data should not be locked by having called this function while subsequently calling a derived module's method which also makes use of the module's data by locking it. If this happens, the module data's mutex is locked recursively. In principle, this does no harm since Util::ISynchronizedPointerLockable supports that. But, it is not considered good practice.

Parameters
TimeoutTime to wait for locking the mutex of ModuleData.
Returns
Returns a pointer to const ModuleDataType, since access to non-const members of ModuleDataType is only allowed to the main thread!

Definition at line 207 of file Module.cpp.

◆ GetNonConstModuleData()

ModuleBase::ModuleDataTypeSyncPtrType DynExp::ModuleBase::GetNonConstModuleData ( const std::chrono::milliseconds  Timeout = GetModuleDataTimeoutDefault) const
private

Always allows ModuleBase to obtain a non-const pointer to the module's data - even in const event functions.

Parameters
TimeoutTime to wait for locking the mutex of ModuleData.
Returns
Returns a pointer to ModuleDataType (non-const) to allow access all of its members.

Definition at line 217 of file Module.cpp.

◆ HandleEvent()

void DynExp::ModuleBase::HandleEvent ( ModuleInstance Instance)
private

Executes and removes the next pending event from the module's event queue.

Parameters
InstanceHandle to the module thread's data

Definition at line 222 of file Module.cpp.

◆ HasUI()

virtual bool DynExp::ModuleBase::HasUI ( ) const
inlinevirtualnoexcept

Determines whether this module possesses a user interface (UI) which is shown in a window dedicated to the module.

Returns
Return true if the module possesses an UI, false otherwise.

Reimplemented in DynExp::QModuleBase.

Definition at line 490 of file Module.h.

◆ IsReadyChild()

bool DynExp::ModuleBase::IsReadyChild ( ) const
finaloverrideprivatevirtual

Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) and not blocked (refer to Object::IsBlocked).

Returns
Returns true if this Object instance is ready, false otherwise.

Implements DynExp::Object.

Definition at line 368 of file Module.cpp.

◆ MakeAndEnqueueEvent()

template<typename ReceiverType , typename EventType , typename... ArgsTs>
void DynExp::ModuleBase::MakeAndEnqueueEvent ( ReceiverType *  Receiver,
EventType  EventFuncPtr,
ArgsTs &&...  Args 
) const

Calls MakeEvent() to construct a new event and subsequently enqueues the event into the module's event queue. Logical const-ness: this is a const member function to allow pointers to const ModuleBase inserting events into the module's event queue. These kind of pointers are e.g. returned by RunnableInstance::GetOwner() which can be called by events' EventBase::InvokeChild() functions. For const ModuleBase*, it is possible to insert events into the event queue, but not to change the ModuleBase object itself (e.g. calling Object::Reset()).

Template Parameters
ReceiverTypeModule type to receive this event.
EventTypeType (signature) of the event function.
...ArgsTsTypes of arguments passed to the event function.
Parameters
ReceiverPointer to the module receiving this event. Pointer this is not directly used since it is not a pointer to the derived type. Passing a pointer to the derived type saves a dynamic_cast operation.
EventFuncPtrEvent function to be invoked (member function of ReceiverType expected).
...ArgsArguments to pass to the event function.
Exceptions
Util::InvalidArgExceptionis thrown if Receiver is not a pointer to the ModuleBase instance ModuleBase::MakeAndEnqueueEvent() is called on.

Definition at line 780 of file Module.h.

◆ MakeStartupBusyDialogChild()

std::unique_ptr< BusyDialog > DynExp::ModuleBase::MakeStartupBusyDialogChild ( QWidget *  ParentWidget) const
finaloverrideprivatevirtual

Override to make this function return a pointer to a BusyDialog instance. Refer to Run().

Parameters
ParentWidgetQt QWidget acting as a parent of the modal busy dialog
Returns
Pointer to a BusyDialog instance

Reimplemented from DynExp::RunnableObject.

Definition at line 350 of file Module.cpp.

◆ ModuleMainLoop()

◆ ModuleSetReasonWhyPaused()

void DynExp::ModuleBase::ModuleSetReasonWhyPaused ( std::string  Description)
inlineprivate

Sets the reason why this ModuleBase instance has been paused.

Parameters
DescriptionHuman-readable string describing the reason

Definition at line 694 of file Module.h.

◆ NotifyChild()

void DynExp::ModuleBase::NotifyChild ( )
finaloverrideprivatevirtual

Notify derived classes that some state has changed (e.g. the termination of Thread is requested) and that the child's event/task queue should run now.

Reimplemented from DynExp::RunnableObject.

Definition at line 328 of file Module.cpp.

◆ OnDeregisterEvents()

void DynExp::ModuleBase::OnDeregisterEvents ( ModuleInstance Instance) const
private

This event is triggered after the OnExit event. It calls EventListenersBase::Deregister() for all managers of event listeners stored in RegisteredEvents since we do not trust in derived modules deregistering/unsubscribing from all registered events via InterModuleEvent::Deregister().

Parameters
InstanceHandle to the module thread's data

Definition at line 379 of file Module.cpp.

◆ OnError()

void DynExp::ModuleBase::OnError ( ModuleInstance Instance)
private

This handler gets called just before the module thread terminates due to an exception. Override OnErrorChild() to perform shutdown and cleanup actions.

Parameters
InstanceHandle to the module thread's data

Definition at line 285 of file Module.cpp.

◆ OnErrorChild()

virtual void DynExp::ModuleBase::OnErrorChild ( ModuleInstance Instance) const
inlineprivatevirtual

This handler gets called just before the module thread terminates due to an exception. Override OnErrorChild() to perform shutdown and cleanup actions.

Parameters
InstanceHandle to the module thread's data

Reimplemented in DynExpModule::gRPCModule< gRPCServices >, and DynExpModule::gRPCModule< gRPCServices... >.

Definition at line 673 of file Module.h.

◆ OnExit()

virtual void DynExp::ModuleBase::OnExit ( ModuleInstance Instance) const
inlineprivatevirtual

◆ OnInit()

virtual void DynExp::ModuleBase::OnInit ( ModuleInstance Instance) const
inlineprivatevirtual

◆ OnPause()

void DynExp::ModuleBase::OnPause ( ModuleInstance Instance)
private

This handler gets called just after the module pauses due to e.g. an error in an instrument the module depends on. Override OnPauseChild() to e.g. abort a measurement or to store internal states for resuming later.

Parameters
InstanceHandle to the module thread's data

Definition at line 271 of file Module.cpp.

◆ OnPauseChild()

virtual void DynExp::ModuleBase::OnPauseChild ( ModuleInstance Instance) const
inlineprivatevirtual

This handler gets called just after the module pauses due to e.g. an error in an instrument the module depends on. Override OnPauseChild() to e.g. abort a measurement or to store internal states for resuming later.

Parameters
InstanceHandle to the module thread's data

Definition at line 671 of file Module.h.

◆ OnResume()

void DynExp::ModuleBase::OnResume ( ModuleInstance Instance)
private

This handler gets called just after the module resumed from a paused state. Override OnResumeChild() to reinitialize instruments or a measurement routine.

Parameters
InstanceHandle to the module thread's data

Definition at line 278 of file Module.cpp.

◆ OnResumeChild()

virtual void DynExp::ModuleBase::OnResumeChild ( ModuleInstance Instance) const
inlineprivatevirtual

This handler gets called just after the module resumed from a paused state. Override OnResumeChild() to reinitialize instruments or a measurement routine.

Parameters
InstanceHandle to the module thread's data

Definition at line 672 of file Module.h.

◆ RemoveRegisteredEvent()

void DynExp::ModuleBase::RemoveRegisteredEvent ( EventListenersBase EventListeners)
private

Removes a manager of event listeners from RegisteredEvents if it was added before. Called indirectly by TypedEventListeners::Deregister().

Parameters
EventListenersManager of event listeners to remove

Definition at line 253 of file Module.cpp.

◆ ResetImpl() [1/2]

virtual void DynExp::ModuleBase::ResetImpl ( dispatch_tag< ModuleBase )
privatepure virtual

Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy.

Implemented in DynExp::QModuleBase.

◆ ResetImpl() [2/2]

void DynExp::ModuleBase::ResetImpl ( dispatch_tag< RunnableObject )
finaloverrideprivatevirtual

Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy.

Implements DynExp::RunnableObject.

Definition at line 309 of file Module.cpp.

◆ RestoreWindowStatesFromParams()

void DynExp::ModuleBase::RestoreWindowStatesFromParams ( )
inline

RestoreWindowStatesFromParams() only calls RestoreWindowStatesFromParamsChild(). Override RestoreWindowStatesFromParamsChild() to restore the styles of possibly owned windows according to the style saved in the module's parameters.

Definition at line 527 of file Module.h.

◆ RestoreWindowStatesFromParamsChild()

virtual void DynExp::ModuleBase::RestoreWindowStatesFromParamsChild ( )
inlineprivatevirtual

RestoreWindowStatesFromParams() only calls RestoreWindowStatesFromParamsChild(). Override RestoreWindowStatesFromParamsChild() to restore the styles of possibly owned windows according to the style saved in the module's parameters.

Reimplemented in DynExp::QModuleBase.

Definition at line 675 of file Module.h.

◆ RunChild()

void DynExp::ModuleBase::RunChild ( )
finaloverrideprivatevirtual

Refer to Run().

Implements DynExp::RunnableObject.

Definition at line 317 of file Module.cpp.

◆ TerminateChild()

void DynExp::ModuleBase::TerminateChild ( const std::chrono::milliseconds  Timeout)
finaloverrideprivatevirtual

Signals derived classes that terminating the RunnableObject instance's thread is about to be requested. Derived classes might now enqueue respective exit tasks/events into their task/event queues. Refer to TerminateUnsafe().

Parameters
TimeoutTime to wait until the RunnableObject's thread has ended.

Reimplemented from DynExp::RunnableObject.

Definition at line 333 of file Module.cpp.

◆ TreatModuleExceptionsAsWarnings()

virtual bool DynExp::ModuleBase::TreatModuleExceptionsAsWarnings ( ) const
inlinevirtual

Determines whether this module should be terminated if an exception leaves the module's main loop or respective event handlers.

Returns
Return false if the module should be terminated in case of an uncaught exception, true to only record the exception as the module's warning.

Reimplemented in DynExpModule::ODMR::ODMR, DynExpModule::StreamManipulator, DynExpModule::gRPCModule< gRPCServices >, DynExpModule::gRPCModule< gRPCServices... >, and DynExpModule::ArbitraryFunctionFromCSV.

Definition at line 498 of file Module.h.

◆ UpdateParamsFromWindowStates()

void DynExp::ModuleBase::UpdateParamsFromWindowStates ( )
inline

UpdateParamsFromWindowStates() only calls UpdateParamsFromWindowStatesChild(). Override UpdateParamsFromWindowStatesChild() to store the styles of possibly owned windows in the module's parameters.

Definition at line 534 of file Module.h.

◆ UpdateParamsFromWindowStatesChild()

virtual void DynExp::ModuleBase::UpdateParamsFromWindowStatesChild ( )
inlineprivatevirtual

UpdateParamsFromWindowStates() only calls UpdateParamsFromWindowStatesChild(). Override UpdateParamsFromWindowStatesChild() to store the styles of possibly owned windows in the module's parameters.

Reimplemented in DynExp::QModuleBase.

Definition at line 676 of file Module.h.

Member Data Documentation

◆ EventListenersOnly

EventListenersOnlyType DynExp::ModuleBase::EventListenersOnly

Allow exclusive access to some of ModuleBase's private methods to any TypedEventListeners class.

Definition at line 516 of file Module.h.

◆ GetModuleDataTimeoutDefault

constexpr auto DynExp::ModuleBase::GetModuleDataTimeoutDefault = std::chrono::milliseconds(1000)
staticconstexpr

Determines the default timeout for GetModuleData() to lock the mutex synchronizing the module's data ModuleData.

Definition at line 513 of file Module.h.

◆ ModuleData

const std::unique_ptr<ModuleDataType> DynExp::ModuleBase::ModuleData
private

Module data belonging to this ModuleBase instance.

Definition at line 743 of file Module.h.

◆ ModuleThreadOnly

ModuleThreadOnlyType DynExp::ModuleBase::ModuleThreadOnly

Allow exclusive access to some of ModuleBase's private methods to the module thread ModuleThreadMain().

Definition at line 515 of file Module.h.

◆ RegisteredEvents

std::vector<EventListenersBase*> DynExp::ModuleBase::RegisteredEvents
private

Holds a list of pointers to managers of event listeners of the events this module has registered/subscribed to. The stored pointers always outlive all module instances since they are static members of types derived from InterModuleEvent.

Definition at line 750 of file Module.h.


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