DynExp
Highly flexible laboratory automation for dynamically changing experiments.
|
Base class for all DynExp Objects like hardware adapters (DynExp::HardwareAdapterBase), instruments (DynExp::InstrumentBase) and modules (DynExp::ModuleBase). Subclasses should also derive either form Util::INonCopyable or Util::ILockable since Object is not intended to be copied. Especially, it must not be moved to another thread (than the one creating it). Logical const-ness: const member functions can be called by other threads, non-const functions are visible only to main thread. More...
Classes | |
struct | dispatch_tag |
Refer to ParamsBase::dispatch_tag. More... | |
class | LinkedObjectWrapperOnlyType |
Allow exclusive access to some of Object's private methods to any LinkedObjectWrapper<T>. More... | |
Public Types | |
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... | |
Public Member Functions | |
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... | |
Not thread-safe | |
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... | |
Static Public Member Functions | |
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 | |
LinkedObjectWrapperOnlyType | LinkedObjectWrapperOnly |
Allow exclusive access to some of Object's private methods to any LinkedObjectWrapper<T>. More... | |
Static Public Attributes | |
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... | |
Protected Member Functions | |
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... | |
Non-const methods | |
Not const, to avoid usage by e.g. tasks of derived instruments. | |
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... | |
Private Member Functions | |
void | LogWarning () const |
Writes Object::Warning to the event log returned by Util::EventLog(). More... | |
Private Attributes | |
const std::thread::id | OwnerThreadID |
Thread id of the thread which has constructed (and owns) this Object instance. More... | |
const ParamsBasePtrType | Params |
Pointer to the parameter class instance belonging to this Object instance. More... | |
Util::Warning | Warning |
Last warning which occurred within this Object instance. (Logical const-ness: see above.) More... | |
ObjectUserList | UserList |
List of Object instances making use of this Object instance. Other Object instances making use of this Object instance have to register and deregister themselves (via class LinkedObjectWrapper ). More... | |
bool | IsBlocked = false |
This flag indicates whether this Object instance is blocked in order to be destroyed subsequently. Blocked objects are never ready (Object::IsReady() returns always false for them). Thus, RunnableInstance cannot lock this object instance anymore. Unblocking is not possible since blocking indicates approaching destruction. More... | |
Thread-safe public functions | |
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... | |
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... | |
Override | |
Override by derived class to make public versions of these functions behave as described above. | |
virtual std::string | GetName () const =0 |
Returns the name of this Object type. More... | |
virtual std::string | GetCategory () const =0 |
Returns the category of this Object type. More... | |
virtual void | ResetImpl (dispatch_tag< Object >)=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... | |
virtual std::exception_ptr | GetExceptionChild (const std::chrono::milliseconds Timeout) const =0 |
Returns a pointer to the exception which has caused this Object instance to fail. More... | |
virtual void | EnsureReadyStateChild (bool IsAutomaticStartup)=0 |
Ensures that this Object instance is ready by possibly starting its worker thread or by opening connections to hardware devices. More... | |
virtual bool | IsReadyChild () const =0 |
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... | |
virtual void | CheckLinkedObjectStatesChild () const |
Override to implement a check whether linked objects are in a ready state. More... | |
Base class for all DynExp Objects like hardware adapters (DynExp::HardwareAdapterBase), instruments (DynExp::InstrumentBase) and modules (DynExp::ModuleBase). Subclasses should also derive either form Util::INonCopyable or Util::ILockable since Object is not intended to be copied. Especially, it must not be moved to another thread (than the one creating it). Logical const-ness: const member functions can be called by other threads, non-const functions are visible only to main thread.
struct DynExp::Object::dispatch_tag |
Refer to ParamsBase::dispatch_tag.
Type | (derived from class Object ) to instantiate the dispatch tag template with. |
Alias for the return type of Object::GetParams() const. Parameters wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way.
using DynExp::Object::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.
using DynExp::Object::ParamsType = ParamsBase |
Alias for the return type of Object::GetParams(). Parameters wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way.
|
protected |
Constructs an Object
instance.
OwnerThreadID | Thread id of the thread owning the Object instance to be constructed. |
Params | Parameter class instance to be assigned to the Object instance to be constructed. |
Util::InvalidArgException | is thrown if OwnerThreadID is an invalid thread id or if Params is nullptr. |
Definition at line 358 of file Object.cpp.
|
protectedpure virtual |
Definition at line 368 of file Object.cpp.
void DynExp::Object::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.
Timeout | Time to wait for locking the mutex of Object::UserList. |
Util::NotAvailableException | is thrown if this Object instance is currently being used by another Object instance. |
Definition at line 421 of file Object.cpp.
|
static |
Builds a string from an Object's
category and name to allow the user to identify an Object's
type.
Category | Refer to Object::GetCategory(). |
Name | Refer to Object::GetName(). |
Object's
type. Definition at line 350 of file Object.cpp.
|
inline |
Checks whether Object
instances this instance uses are in a ready state. Override CheckLinkedObjectStatesChild()
to implement this behavior.
|
inlineprivatevirtual |
Override to implement a check whether linked objects are in a ready state.
Reimplemented in DynExp::RunnableObject.
|
inline |
Resets Object::Warning.
|
inlineprotected |
|
protected |
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).
Util::InvalidCallException | is thrown if the assertion fails. |
Definition at line 468 of file Object.cpp.
void DynExp::Object::EnsureReadyState | ( | bool | IsAutomaticStartup | ) |
Ensures that this Object
instance is ready by possibly starting its worker thread or by opening connections to hardware devices.
IsAutomaticStartup | Pass true if ensuring other Object instances to be ready have caused a call to this function. Pass false if an action performed by the user has caused the call to this function. |
Definition at line 446 of file Object.cpp.
|
privatepure virtual |
Ensures that this Object
instance is ready by possibly starting its worker thread or by opening connections to hardware devices.
IsAutomaticStartup | Pass true if ensuring other Object instances to be ready have caused a call to this function. Pass false if an action performed by the user has caused the call to this function. |
Implemented in DynExp::RunnableObject.
|
pure virtual |
Returns the category of this Object
type.
Implemented in DynExpModule::Widefield::WidefieldMicroscope, DynExpModule::Trajectory1D, DynExpModule::StreamManipulator, DynExpModule::Stage1D, DynExpModule::SpectrumViewer::SpectrumViewer, DynExpModule::SignalPlotter, DynExpModule::SignalDesigner, DynExpModule::OutputPortWriter, DynExpModule::ODMR::ODMR, DynExpModule::LockinAmplifierControl, DynExpModule::InputPortReader, DynExpModule::ImageViewer::ImageViewer, DynExpModule::gRPCModule< gRPCServices >, DynExpModule::gRPCModule< gRPCServices... >, DynExpModule::ArbitraryFunctionFromCSV, DynExp::ModuleBase, DynExpInstr::TimeTagger, DynExpInstr::PositionerStage, DynExpInstr::Spectrometer, DynExpInstr::OutputPort, DynExpInstr::LockinAmplifier, DynExpInstr::InputPort, DynExpInstr::gRPCInstrument< Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer >, DynExpInstr::gRPCInstrument< DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization >, DynExpInstr::FunctionGenerator, DynExpInstr::DigitalOut, DynExpInstr::DigitalIn, DynExpInstr::DataStreamInstrument, DynExpInstr::Camera, DynExpInstr::AnalogOut, DynExpInstr::AnalogIn, DynExp::InstrumentBase, DynExpHardware::ZILabOneHardwareAdapter, DynExpHardware::SIPulseStreamerHardwareAdapter, DynExpHardware::SmarActHardwareAdapter, DynExpHardware::QutoolsTDCHardwareAdapter, DynExpHardware::PVCamHardwareAdapter, DynExpHardware::NIDAQHardwareAdapter, DynExpHardware::gRPCHardwareAdapter< gRPCStub >, DynExpHardware::gRPCHardwareAdapter< pulse_streamer::PulseStreamer >, DynExp::SerialCommunicationHardwareAdapter, and DynExp::HardwareAdapterBase.
|
inline |
|
inline |
Returns a pointer to the exception which has caused this Object
instance to fail.
Timeout | Time to wait for locking the mutex used to protect the stored exception data. |
|
privatepure virtual |
Returns a pointer to the exception which has caused this Object
instance to fail.
Timeout | Time to wait for locking the mutex used to protect the stored exception data. |
Implemented in DynExp::HardwareAdapterBase.
|
inlinenoexcept |
|
pure virtual |
Returns the name of this Object
type.
Implemented in DynExpModule::Widefield::WidefieldMicroscope, DynExpModule::Trajectory1D, DynExpModule::StreamManipulator, DynExpModule::Stage1D, DynExpModule::SpectrumViewer::SpectrumViewer, DynExpModule::SignalPlotter, DynExpModule::SignalDesigner, DynExpModule::OutputPortWriter, DynExpModule::ODMR::ODMR, DynExpModule::NetworkTimeTaggerT< gRPCServices >, DynExpModule::NetworkDigitalOutT< gRPCServices >, DynExpModule::NetworkDigitalInT< gRPCServices >, DynExpModule::NetworkDataStreamInstrumentT< gRPCServices >, DynExpModule::NetworkDataStreamInstrumentT< gRPCServices... >, DynExpModule::NetworkAnalogOutT< gRPCServices >, DynExpModule::NetworkAnalogInT< gRPCServices >, DynExpModule::LockinAmplifierControl, DynExpModule::InputPortReader, DynExpModule::ImageViewer::ImageViewer, DynExpModule::gRPCModule< gRPCServices >, DynExpModule::gRPCModule< gRPCServices... >, DynExpModule::ArbitraryFunctionFromCSV, DynExpInstr::TimeTagger, DynExpInstr::PositionerStage, DynExpInstr::Spectrometer, DynExpInstr::OutputPort, DynExpInstr::LockinAmplifier, DynExpInstr::InputPort, DynExpInstr::gRPCInstrument< Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer >, DynExpInstr::gRPCInstrument< DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization >, DynExpInstr::FunctionGenerator, DynExpInstr::DigitalOut, DynExpInstr::DigitalIn, DynExpInstr::DataStreamInstrument, DynExpInstr::Camera, DynExpInstr::AnalogOut, DynExpInstr::AnalogIn, DynExpInstr::ZI_MFLI, DynExpInstr::WidefieldLocalization, DynExpInstr::SwabianInstrumentsPulseStreamer, DynExpInstr::SmarAct, DynExpInstr::RS_SMC100A, DynExpInstr::RS_SMB100B, DynExpInstr::QutoolsQuTAG, DynExpInstr::PVCam, DynExpInstr::PI_C_862, DynExpInstr::NIDAQDigitalOut, DynExpInstr::NIDAQDigitalIn, DynExpInstr::NIDAQAnalogOut, DynExpInstr::NIDAQAnalogIn, DynExpInstr::NetworkSpectrometer, DynExpInstr::NenionLeakvalveF3, DynExpInstr::InterModuleCommunicator, DynExpInstr::DummyDataStreamInstrument, DynExpInstr::DummyCamera, DynExpHardware::ZILabOneHardwareAdapter, DynExpHardware::SIPulseStreamerHardwareAdapter, DynExpHardware::SmarActHardwareAdapter, DynExp::HardwareAdapterSerialPort, DynExpHardware::QutoolsTDCHardwareAdapter, DynExpHardware::PVCamHardwareAdapter, DynExpHardware::NIDAQHardwareAdapter, DynExpHardware::gRPCHardwareAdapter< gRPCStub >, DynExpHardware::gRPCHardwareAdapter< pulse_streamer::PulseStreamer >, DynExp::HardwareAdapterTcpSocket, and DynExp::SerialCommunicationHardwareAdapter.
|
protected |
Allows derived Objects
to edit their own parameters - even in const task functions (for instruments) or event functions (for modules).
Timeout | Time to wait for locking the mutex of Params. |
ParamsType
(non-const) to allow access all of its members. Definition at line 475 of file Object.cpp.
|
inline |
Object::ParamsTypeSyncPtrType DynExp::Object::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.
Timeout | Time to wait for locking the mutex of Params. |
ParamsType
(non-const) to allow access to all of its members. Definition at line 441 of file Object.cpp.
Object::ParamsConstTypeSyncPtrType DynExp::Object::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.
Timeout | Time to wait for locking the mutex of Params. |
ParamsType
, since users of this Object
instance are not allowed to access non-const members of ParamsType
. These are only to be accessed by the main thread! Definition at line 436 of file Object.cpp.
|
inline |
|
inlineprotected |
|
inline |
|
inline |
|
inlineprotected |
|
inline |
Returns Object::Warning in a thread-safe way by copying its internal data.
|
inline |
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).
Object
instance is ready, false otherwise.
|
privatepure virtual |
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).
Object
instance is ready, false otherwise. Implemented in DynExp::ModuleBase, DynExp::InstrumentBase, DynExpHardware::ZILabOneHardwareAdapter, DynExpHardware::SmarActHardwareAdapter, DynExpHardware::QutoolsTDCHardwareAdapter, DynExpHardware::PVCamHardwareAdapter, DynExpHardware::NIDAQHardwareAdapter, DynExpHardware::gRPCHardwareAdapter< gRPCStub >, DynExpHardware::gRPCHardwareAdapter< pulse_streamer::PulseStreamer >, and DynExp::QSerialCommunicationHardwareAdapter.
|
inline |
Returns whether shared usage has been enabled for this Object
instance. Refer to ParamsBase::UsageType.
Timeout | Time to wait for locking the mutex of Params. |
|
inline |
Returns whether this Object
instance is used by other instances.
Timeout | Time to wait for locking the mutex of Object::UserList. |
|
inlineprotected |
Returns whether this Object
instance is used by other instances (not thread-safe).
|
inlineprotected |
|
private |
Writes Object::Warning to the event log returned by Util::EventLog().
Definition at line 480 of file Object.cpp.
void DynExp::Object::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.
Util::NotAvailableException | is thrown if this Object instance is currently being used by another Object instance. |
Definition at line 403 of file Object.cpp.
|
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::RunnableObject, and DynExp::HardwareAdapterBase.
void DynExp::Object::SetWarning | ( | const Util::Exception & | e | ) | const |
Setter for Object::Warning. Sets the warning by retrieving the warning data from an exception e
.
e | Exception derived from class Util::Exception |
Definition at line 461 of file Object.cpp.
void DynExp::Object::SetWarning | ( | std::string | Description, |
int | ErrorCode | ||
) | const |
Setter for Object::Warning. Sets the warning by a description and an error code.
Description | String describing the reason and consequences of the warning |
ErrorCode | DynExp error code from DynExpErrorCodes::DynExpErrorCodes |
Definition at line 454 of file Object.cpp.
|
staticconstexpr |
Default timeout used by Object::GetParams() to lock the mutex of the parameter instance assigned to this Object
instance.
|
private |
This flag indicates whether this Object
instance is blocked in order to be destroyed subsequently. Blocked objects are never ready (Object::IsReady() returns always false for them). Thus, RunnableInstance
cannot lock this object instance anymore. Unblocking is not possible since blocking indicates approaching destruction.
LinkedObjectWrapperOnlyType DynExp::Object::LinkedObjectWrapperOnly |
|
private |
|
private |
|
private |
|
mutableprivate |