17 class EventListenersBase;
18 class InterModuleEventLibrary;
32 template <
typename ModuleT>
35 return std::make_shared<typename ModuleT::ConfigType>();
45 template <
typename ModuleT>
48 dynamic_Params_cast<ModuleT>(Params.get())->ModuleData = std::make_unique<typename ModuleT::ModuleDataType>();
50 return std::make_unique<ModuleT>(OwnerThreadID, std::move(Params));
96 template <
typename ReceiverType,
typename ArgTupleType>
104 template <
size_t... Indices>
127 template <
size_t... Indices>
142 using EventFuncType =
typename InstantiatedEventFuncTraitsType::EventFuncType;
341 void SetException(std::exception_ptr Exception)
noexcept;
389 virtual const char*
GetParamClassTag() const noexcept
override {
return "ModuleParamsBase"; }
465 template <
typename...>
506 constexpr static auto Category() noexcept {
return ""; }
528 virtual bool HasUI() const noexcept {
return false; }
544 virtual std::chrono::milliseconds
GetMainLoopDelay()
const {
return std::chrono::milliseconds(10); }
616 template <
typename ReceiverType,
typename EventType,
typename... ArgsTs>
617 void MakeAndEnqueueEvent(ReceiverType* Receiver, EventType EventFuncPtr, ArgsTs&& ...Args)
const;
687 void SetException(std::exception_ptr Exception)
noexcept;
748 void TerminateChild(const std::chrono::milliseconds Timeout) override final;
752 std::exception_ptr
GetExceptionChild([[maybe_unused]] const std::chrono::milliseconds Timeout) const override final;
810 template <
typename ReceiverType,
typename... ArgsTs>
812 typename DefaultEvent<ReceiverType, std::tuple<std::remove_reference_t<ArgsTs>...>>::EventFuncPtrType EventFuncPtr,
824 return std::make_unique<DefaultEvent<ReceiverType, EventArgTs>>(EventFunc);
827 template <
typename ReceiverType,
typename EventType,
typename... ArgsTs>
830 if (Receiver !=
this)
831 throw Util::InvalidArgException(
"Receiver cannot point to a module different from the instance MakeAndEnqueueEvent() is called on.");
896 template <
typename To,
typename From, std::enable_if_t<
897 std::is_same_v<ModuleDataBase, std::remove_cv_t<From>>,
int> = 0
905 std::conditional_t<std::is_const_v<From>, std::add_const_t<typename To::ModuleDataType>,
typename To::ModuleDataType>
906 >(std::move(ModuleDataPtr));
928 const std::chrono::milliseconds Timeout = std::chrono::milliseconds(0)) = 0;
939 const std::chrono::milliseconds Timeout = std::chrono::milliseconds(0)) = 0;
950 template <
typename... EventFuncArgs>
995 size_t seed = std::hash<decltype(ListenersTypeKey::Module)>()(v.
Module);
1030 template <
typename CallableT>
1032 const std::chrono::milliseconds Timeout = std::chrono::milliseconds(0))
1039 const std::chrono::milliseconds Timeout = std::chrono::milliseconds(0))
override
1046 const std::chrono::milliseconds Timeout = std::chrono::milliseconds(0))
override
1079 template <
typename CallableT>
1082 const auto NumListeners =
Listeners.size();
1084 (
dynamic_cast<std::add_const_t<typename Util::member_fn_ptr_traits<CallableT>::instance_type
>&>(Listener).*EventFunc)(Instance, Args...);
1117 const auto NumErased = std::erase_if(
Listeners, [&Listener](
const auto& v) {
return v.first.Module == &Listener; });
1119 for (std::remove_const_t<
decltype(NumErased)> i = 0; i < NumErased; ++i)
1136 return ListenerIt->second;
1140 return ListenerIt !=
Listeners.cend() ? ListenerIt->second :
nullptr;
1147 std::unordered_map<const ListenersTypeKey, EventFunctionType, ListenersTypeKeyHasher>
Listeners;
1183 virtual size_t GetID() const noexcept = 0;
1210 template <
typename DerivedEvent,
typename... EventFuncArgs>
1255 virtual size_t GetID() const noexcept override final {
return ID(); }
1256 virtual std::string
GetName()
const override {
return typeid(DerivedEvent).name(); }
1262 template <
typename CallableT>
1362 std::map<size_t, EventFactoryFuncPtrType>
Events;
1365 template <
typename DerivedEvent,
typename ...EventFuncArgs>
1368 auto ID = Util::UniqueID::Get<DerivedEvent>();
1380 template <
typename DerivedEvent,
typename... EventFuncArgs>
1387 template <
typename DerivedEvent,
typename... EventFuncArgs>
1484 virtual
void closeEvent(QCloseEvent* Event) override;
1526 virtual void closeEvent(QCloseEvent* Event)
override;
1535 virtual void keyPressEvent(QKeyEvent* Event)
override;
1597 : WindowPosX{ Owner, Prefix +
"WindowPosX" },
1598 WindowPosY{ Owner, Prefix +
"WindowPosY" },
1599 WindowWidth{ Owner, Prefix +
"WindowWidth" },
1600 WindowHeight{ Owner, Prefix +
"WindowHeight" },
1601 WindowState{ Owner, Prefix +
"WindowState",
WindowStateType::Normal },
1610 void ApplyTo(QWidget& Widget,
bool Show =
true)
const;
1616 void FromWidget(
const QWidget& Widget);
1682 bool HasUI() const noexcept override final {
return true; }
1701 virtual void DisableUI();
1702 virtual void UpdateUI();
1711 void UpdateModuleWindowFocusAction();
1713 void DockWindow() noexcept;
1714 void UndockWindow() noexcept;
1715 void DockUndockWindow() noexcept;
1716 void SetFocus() noexcept;
1717 void FocusMainWindow() noexcept;
1724 void SendKeyPressEventToMainWindow(QKeyEvent* Event) noexcept;
1732 bool IsWindowDocked() noexcept;
1741 bool IsActiveWindow();
1767 template <typename SenderType, typename SignalType, typename ReceiverType, typename EventType>
1768 void Connect(SenderType* Sender, SignalType Signal, ReceiverType* Receiver, EventType Event);
1778 WidgetType* GetWidget() const;
1781 virtual
void RestoreWindowStatesFromParamsChild() override;
1782 virtual
void UpdateParamsFromWindowStatesChild() override;
1790 void SetWidgetProperties(QWidget* const WindowWidget) const;
1792 void ResetImpl(dispatch_tag<
ModuleBase>) override final;
1824 template <
typename SenderType,
typename SignalType,
typename ReceiverType,
typename EventType>
1827 EnsureCallFromOwningThread();
1829 if (!Sender || !Receiver)
1834 auto Connection = QObject::connect(Sender, Signal, [
this, Receiver, Event](
auto... Args) {
1837 MakeAndEnqueueEvent(Receiver, Event, std::move(Args)...);
1844 catch (
const std::exception& e)
1856 throw Util::InvalidArgException(
"QObject::connect() cannot establish a connection for the given sender and signal types.");
1859 template <
typename W
idgetType>
1869 return &
dynamic_cast<WidgetType&
>(*Widget);
1889 QObject* GetRootObject() const noexcept;
1895 QObject* GetBackend() const noexcept;
1897 bool AllowResize() const noexcept
override {
return true; }
1902 mutable QObject* Backend =
nullptr;
1934 virtual const char*
GetParamClassTag() const noexcept
override {
return "QMLModuleParamsBase"; }
1975 void DisableUI()
override;
1976 void UpdateUI()
override;
1988 template <
typename BackendType>
1989 BackendType* GetBackend()
const;
1995 std::unique_ptr<QModuleWidget> MakeUIWidget() override final;
2005 virtual
void MakeConnections(QObject* Backend) {}
2019 virtual QAnyStringView GetModuleSourceTypeName() const noexcept = 0;
2023 template <typename BackendType>
2026 EnsureCallFromOwningThread();
2028 auto Backend = GetWidget<QMLModuleWidget>()->GetBackend();
2032 return &
dynamic_cast<BackendType&
>(*Backend);
Implementation of DynExp objects as the base for derived resources and implementation of the object p...
Implements DynExp's main window as a Qt-based user interface (UI).
Describes an event which consists of a receiver's member function and a set of arguments to call this...
decltype(DefaultEvent< ReceiverType, ArgTupleType >::MakeEventFuncTraits(std::declval< ArgTupleIndexSequenceType >())) InstantiatedEventFuncTraitsType
Type of the instantiated EventFuncTraits - not actually instantiating it.
DefaultEvent(EventFuncType EventFunc) noexcept
Constructs a DefaultEvent instance.
decltype(std::make_index_sequence< std::tuple_size_v< ArgTupleType > >()) ArgTupleIndexSequenceType
Index sequence for the (pseudo-)instantiation of EventFuncTraits.
virtual void InvokeChild(ModuleInstance &Instance) const override
Invokes the event passing the receiving module's instance reference to it. Only to be called from Mod...
const EventFuncType EventFunc
Util::CallableMemberWrapper to store the event receiver, the event function, and its arguments.
static constexpr auto MakeEventFuncTraits(std::index_sequence< Indices... >)
Instantiates EventFuncTraits. This function is not meant to be called. It is used for type deduction ...
typename InstantiatedEventFuncTraitsType::EventFuncPtrType EventFuncPtrType
Signature of an event function. Pointer to ModuleInstance to be passed as parameter instead of refere...
typename InstantiatedEventFuncTraitsType::EventFuncType EventFuncType
Type of a Util::CallableMemberWrapper to store the event.
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Common base class for all events to store them in a FIFO queue to be invoked later.
void Invoke(ModuleInstance &Instance) const
Invokes the event passing the receiving module's instance reference to it. Only to be called from Mod...
virtual void InvokeChild(ModuleInstance &Instance) const =0
Invokes the event passing the receiving module's instance reference to it. Only to be called from Mod...
Common base class for all managers of event listeners of type TypedEventListeners....
virtual void Deregister(const ModuleBase &Listener, ItemIDType CommunicatorID, const std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))=0
Deregisters/unsubscribes module Listener from the event, removing a single registration for a particu...
EventListenersBase()=default
virtual ~EventListenersBase()
virtual void Deregister(const ModuleBase &Listener, const std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))=0
Deregisters/unsubscribes module Listener from the event, regardless of the inter-module communicator ...
Common base class for all inter-module events.
virtual std::string GetName() const =0
Returns the name of this event type.
virtual InterModuleEventPtrType Clone(ItemIDType CommunicatorID) const =0
Creates a deep copy of this inter-module instance.
const ItemIDType CommunicatorID
ID of the DynExpInstr::InterModuleCommunicator instance that sends the event.
InterModuleEventBase(const InterModuleEventBase &Other, ItemIDType CommunicatorID)
Copy-constrcuts an inter-module event setting the CommunicatorID.
virtual size_t GetID() const noexcept=0
Returns the unique ID of this event type.
std::unique_ptr< InterModuleEventBase > InterModuleEventPtrType
Pointer type to store an inter-module event (InterModuleEventBase).
auto GetCommunicatorID() const noexcept
Getter for CommunicatorID.
InterModuleEventBase()
Constructs an inter-module event.
virtual ~InterModuleEventBase()=0
Library type that holds factory functions to all available inter-module events.
std::map< size_t, EventFactoryFuncPtrType > Events
Maps the unique ID of inter-module events derived from InterModuleEventBase to their respective facto...
InterModuleEventLibrary()=default
Constructs an instance of InterModuleEventLibrary. Private to make singleton class.
static InterModuleEventLibrary & Get()
Getter for the singleton instance of InterModuleEventLibrary.
std::function< InterModuleEventBase::InterModuleEventPtrType(void)> EventFactoryFuncPtrType
Type of a function pointer pointing to a factory function to create an instance of an inter-module ev...
void Register(size_t ID, EventFactoryFuncPtrType EventFactoryFuncPtr)
Adds an inter-module event derived from InterModuleEventBase to this library.
auto & GetEvents() const noexcept
Getter for Events.
Typed base class for inter-module events to realize CRTP.
static void Register(const ModuleBase &Listener, CallableT EventFunc, ItemIDType CommunicatorID=ItemIDNotSet)
Registers/Subscribes module Listener to the event with the event function EventFunc....
static const size_t EventID
Unique ID assigned to this inter-module event.
static size_t Publish(InterModuleEventLibrary &Library)
Publishes this event type to the InterModuleEventLibrary. This function should not be called manually...
InterModuleEvent()=default
Constructs an inter-module event.
virtual void InvokeWithParamsChild(ModuleInstance &Instance, EventListenersType::EventFunctionType EventFunc) const =0
Called by InvokeChild(). Override to call EventFunc with Instance as the first argument and with furt...
virtual size_t GetID() const noexcept override final
Returns the unique ID of this event type.
virtual ~InterModuleEvent()
virtual void InvokeChild(ModuleInstance &Instance) const override final
Invokes the event passing the receiving module's instance reference to it. Only to be called from Mod...
static InterModuleEventPtrType Make()
Factory function for events of type DerivedEvent.
virtual InterModuleEventPtrType Clone(ItemIDType CommunicatorID) const override final
Creates a deep copy of this inter-module instance.
static void Deregister(const ModuleBase &Listener, ItemIDType CommunicatorID)
Deregisters/unsubscribes module Listener from the event, removing a single registration for a particu...
InterModuleEvent(const InterModuleEventBase &Other, ItemIDType CommunicatorID)
Copy-constrcuts an inter-module event setting the CommunicatorID.
static auto ID()
Getter for EventID.
static void Deregister(const ModuleBase &Listener)
Deregisters/unsubscribes module Listener from the event, regardless of the inter-module communicator ...
static EventListenersType Listeners
Holds one EventListenersType instance per derived event, which manages all the subscribers of Derived...
virtual std::string GetName() const override
Returns the name of this event type.
Allow exclusive access to some of ModuleBase's private methods to any TypedEventListeners class.
ModuleBase & Parent
Owning ModuleBase instance.
constexpr EventListenersOnlyType(ModuleBase &Parent) noexcept
Construcs an instance - one for each ModuleBase instance.
void AddRegisteredEvent(EventListenersBase &EventListeners) const
Adds a manager of event listeners to RegisteredEvents. Called indirectly by TypedEventListeners::Regi...
void RemoveRegisteredEvent(EventListenersBase &EventListeners) const
Removes a manager of event listeners from RegisteredEvents if it was added before....
friend class TypedEventListeners
Allow exclusive access to some of ModuleBase's private methods to the module thread ModuleThreadMain(...
void OnPause(ModuleInstance &Instance)
ModuleBase & Parent
Owning ModuleBase instance.
void SetException(std::exception_ptr Exception) noexcept
Sets this module instance to an error state and tries to store the exception responsible for the erro...
Util::DynExpErrorCodes::DynExpErrorCodes ModuleMainLoop(ModuleInstance &Instance)
void OnError(ModuleInstance &Instance)
constexpr ModuleThreadOnlyType(ModuleBase &Parent) noexcept
Construcs an instance - one for each ModuleBase instance.
void SetReasonWhyPaused(std::string Description)
friend int ModuleThreadMain(std::unique_ptr< RunnableInstance > &&, RunnableObject *)
Modules run in their own thread. This is the module thread's main function.
void HandleEvent(ModuleInstance &Instance)
void OnResume(ModuleInstance &Instance)
Base class for modules. Modules implement programs on their own (e.g. measurement protocols or server...
void TerminateChild(const std::chrono::milliseconds Timeout) override final
Signals derived classes that terminating the RunnableObject instance's thread is about to be requeste...
ModuleDataTypeSyncPtrType GetModuleData(const std::chrono::milliseconds Timeout=GetModuleDataTimeoutDefault)
Locks the mutex of the module data class instance ModuleData assigned to this ModuleBase instance and...
virtual void OnErrorChild(ModuleInstance &Instance) const
This handler gets called just before the module thread terminates due to an exception....
void OnPause(ModuleInstance &Instance)
This handler gets called just after the module pauses due to e.g. an error in an instrument the modul...
void NotifyChild() override final
Notify derived classes that some state has changed (e.g. the termination of Thread is requested) and ...
void RunChild() override final
Refer to Run().
void ModuleSetReasonWhyPaused(std::string Description)
Sets the reason why this ModuleBase instance has been paused.
void OnDeregisterEvents(ModuleInstance *Instance) const
This event is triggered after the OnExit event. It calls EventListenersBase::Deregister() for all man...
static auto GetExceptionUnsafe(const ModuleDataTypeSyncPtrConstType &ModuleDataPtr)
Getter for ModuleDataBase::ModuleException assuming that the module data has already been locked.
virtual void ResetImpl(dispatch_tag< ModuleBase >)=0
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual void OnInit(ModuleInstance *Instance) const
This event is triggered right before the module thread starts. Override it to lock instruments this m...
const std::unique_ptr< ModuleDataType > ModuleData
Module data belonging to this ModuleBase instance.
void ResetImpl(dispatch_tag< RunnableObject >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual void OnResumeChild(ModuleInstance &Instance) const
This handler gets called just after the module resumed from a paused state. Override OnResumeChild() ...
void SetException(std::exception_ptr Exception) noexcept
Sets this module instance to an error state and tries to store the exception responsible for the erro...
void UpdateParamsFromWindowStates()
UpdateParamsFromWindowStates() only calls UpdateParamsFromWindowStatesChild(). Override UpdateParamsF...
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 even...
virtual std::string GetCategory() const override
Returns the category of this Object type.
virtual void OnExit(ModuleInstance *Instance) const
This event is triggered right before the module thread terminates (not due to an exception,...
void EnqueueEvent(ModuleDataBase::EventPtrType &&Event) const
Enqueues Event at the module event queue's back. Takes ownership of the event. Notifies the module ow...
void RemoveRegisteredEvent(EventListenersBase &EventListeners)
Removes a manager of event listeners from RegisteredEvents if it was added before....
void HandleEvent(ModuleInstance &Instance)
Executes and removes the next pending event from the module's event queue.
virtual void RestoreWindowStatesFromParamsChild()
RestoreWindowStatesFromParams() only calls RestoreWindowStatesFromParamsChild(). Override RestoreWind...
Util::SynchronizedPointer< const ModuleDataType > ModuleDataTypeSyncPtrConstType
Alias for the return type of ModuleBase::GetModuleData() const. Data class instances wrapped into Uti...
void OnResume(ModuleInstance &Instance)
This handler gets called just after the module resumed from a paused state. Override OnResumeChild() ...
ModuleThreadOnlyType ModuleThreadOnly
Allow exclusive access to some of ModuleBase's private methods to the module thread ModuleThreadMain(...
Util::SynchronizedPointer< ModuleDataType > ModuleDataTypeSyncPtrType
Alias for the return type of ModuleBase::GetModuleData(). Data class instances wrapped into Util::Syn...
EventListenersOnlyType EventListenersOnly
Allow exclusive access to some of ModuleBase's private methods to any TypedEventListeners class.
std::unique_ptr< BusyDialog > MakeStartupBusyDialogChild(QWidget *ParentWidget) const override final
Override to make this function return a pointer to a BusyDialog instance. Refer to Run().
std::vector< EventListenersBase * > RegisteredEvents
Holds a list of pointers to managers of event listeners of the events this module has registered/subs...
void OnError(ModuleInstance &Instance)
This handler gets called just before the module thread terminates due to an exception....
static constexpr auto Category() noexcept
Every derived class has to redefine this function.
virtual Util::DynExpErrorCodes::DynExpErrorCodes ModuleMainLoop(ModuleInstance &Instance)=0
Module main loop. The function is executed periodically by the module thread. Also refer to GetMainLo...
void AddRegisteredEvent(EventListenersBase &EventListeners)
Adds a manager of event listeners to RegisteredEvents. Called indirectly by TypedEventListeners::Regi...
virtual void UpdateParamsFromWindowStatesChild()
UpdateParamsFromWindowStates() only calls UpdateParamsFromWindowStatesChild(). Override UpdateParamsF...
static constexpr auto GetModuleDataTimeoutDefault
Determines the default timeout for GetModuleData() to lock the mutex synchronizing the module's data ...
std::exception_ptr GetExceptionChild(const std::chrono::milliseconds Timeout) const override final
Returns a pointer to the exception which has caused this Object instance to fail.
bool IsReadyChild() const override final
Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) a...
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 modul...
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 fun...
virtual bool TreatModuleExceptionsAsWarnings() const
Determines whether this module should be terminated if an exception leaves the module's main loop or ...
void RestoreWindowStatesFromParams()
RestoreWindowStatesFromParams() only calls RestoreWindowStatesFromParamsChild(). Override RestoreWind...
virtual std::chrono::milliseconds GetMainLoopDelay() const
Specifies in which time intervals the module's event queue runs to handle pending events.
Util::DynExpErrorCodes::DynExpErrorCodes ExecModuleMainLoop(ModuleInstance &Instance)
Runs ModuleMainLoop().
virtual bool HasUI() const noexcept
Determines whether this module possesses a user interface (UI) which is shown in a window dedicated t...
Configurator class for ModuleBase.
virtual ~ModuleConfiguratorBase()=0
ModuleConfiguratorBase()=default
Allow exclusive access to some of ModuleDataBase's private methods to ModuleBase.
auto & GetNewEventNotifier() noexcept
Getter for NewEventNotifier.
ModuleDataBase & Parent
Owning ModuleDataBase instance.
void IndicateException() noexcept
Indicates to the main thread that an exception has happened in the module thread. Only performs atomi...
void Reset()
Resets the ModuleDataBase's instance and calls ResetImpl(dispatch_tag<ModuleDataBase>) subsequently.
constexpr ModuleBaseOnlyType(ModuleDataBase &Parent) noexcept
Construcs an instance - one for each ModuleDataBase instance.
void SetException(std::exception_ptr Exception) noexcept
Setter for ModuleException.
Allow exclusive access to some of ModuleDataBase's private methods to the module thread ModuleThreadM...
auto & GetNewEventNotifier() noexcept
Getter for NewEventNotifier.
ModuleDataBase & Parent
Owning ModuleDataBase instance.
constexpr ModuleThreadOnlyType(ModuleDataBase &Parent) noexcept
Construcs an instance - one for each ModuleDataBase instance.
friend int ModuleThreadMain(std::unique_ptr< RunnableInstance > &&, RunnableObject *)
Modules run in their own thread. This is the module thread's main function.
Data structure to contain data which is synchronized in between different threads....
ModuleThreadOnlyType ModuleThreadOnly
Allow exclusive access to some of ModuleDataBase's private methods to the module thread ModuleThreadM...
virtual ~ModuleDataBase()
const auto & GetEventFront() const noexcept
Returns a pointer to the event in the front of the module's event queue without transferring ownershi...
std::exception_ptr ModuleException
Used to transfer exceptions from the module thread to the main (user interface) thread....
Util::OneToOneNotifier NewEventNotifier
Notifies the thread of the module which owns the respective ModuleDataBase's instance when an event h...
std::queue< EventPtrType > EventQueueType
A module's event queue is a FIFO queue owning the enqueued events.
std::unique_ptr< EventBase > EventPtrType
Pointer owning an event.
void IndicateException() noexcept
Indicates to the main thread that an exception has happened in the module thread. Only performs atomi...
void SetException(std::exception_ptr Exception) noexcept
Setter for ModuleException.
void RunQueue()
Wakes up a module waiting for events and forces it to run its main loop once.
std::exception_ptr GetException() const noexcept
Getter for ModuleDataBase::ModuleException. If ModuleDataBase::ModuleException is nullptr and ModuleD...
Util::OneToOneNotifier & GetNewEventNotifier() noexcept
Getter for NewEventNotifier.
bool IsExceptionIndicated() const noexcept
Getter for HasException. Only performs atomic operations. Hence, this module data instance does not n...
void Reset()
Resets the ModuleDataBase's instance and calls ResetImpl(dispatch_tag<ModuleDataBase>) subsequently.
auto & GetEventFront() noexcept
Returns a pointer to the event in the front of the module's event queue without transferring ownershi...
size_t GetNumEnqueuedEvents() const noexcept
Getter for the module event queue's length.
void EnqueueEvent(EventPtrType &&Event)
Enqueues Event at the module event queue's back. Takes ownership of the event. Notifies the module ow...
EventQueueType EventQueue
FIFO event queue of the module which owns the respective ModuleDataBase's instance.
std::atomic< bool > HasException
If set to true, indicates to the main (user interface) thread that an exception has happened in the m...
virtual void ResetImpl(dispatch_tag< ModuleDataBase >)
Refer to DynExp::ModuleDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of ...
EventPtrType PopEvent()
Removes one event from the event queue's front and returns the event. Ownership of the event is trans...
ModuleBaseOnlyType ModuleBaseOnly
Allow exclusive access to some of ModuleDataBase's private methods to ModuleBase.
Refer to ParamsBase::dispatch_tag.
Defines data for a thread belonging to a ModuleBase instance. Refer to RunnableInstance.
void Exit() noexcept
Might be called from anywhere where this ModuleInstance instance is accessible to make the associated...
const ModuleBase::ModuleDataGetterType ModuleDataGetter
Getter for module's data. Refer to ModuleBase::ModuleDataGetterType.
bool IsExiting() const noexcept
Getter for ShouldExit.
~ModuleInstance()=default
bool ShouldExit
Indicates whether the module thread using this ModuleInstance instance should terminate.
Parameter class for ModuleBase.
std::unique_ptr< ModuleDataBase > ModuleData
Just used temporarily during the construction of a module. Refer to MakeModule() and ModuleBase::Modu...
DummyParam Dummy
Dummy parameter which is to be owned once by parameter classes that do not contain any other paramete...
bool ConfigureUsageTypeChild() const noexcept override final
Determines whether the Usage parameter should be configurable in the settings dialog....
void ConfigureParamsImpl(dispatch_tag< RunnableObjectParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
friend ModulePtrType MakeModule(const std::thread::id, ParamsBasePtrType &&)
Factory function to generate a module of a specific type.
virtual void ConfigureParamsImpl(dispatch_tag< ModuleParamsBase >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
virtual ~ModuleParamsBase()=0
ModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a ModuleBase instance.
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Refer to ParamsBase::dispatch_tag.
Dummy parameter which is to be owned once by parameter classes that do not contain any other paramete...
Abstract base class for object parameter classes. Each class derived from class Object must be accomp...
const ItemIDType ID
ID of the Object this parameter class instance belongs to.
const DynExpCore & Core
Reference to DynExp's core.
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Base class for modules with a QML-based user interface. Derive from this class to implement modules w...
virtual QAnyStringView GetModuleSourceUri() const noexcept=0
Used by QModuleBase::MakeUIWidget to construct the module's user interface QML widget.
virtual void ResetImpl(dispatch_tag< QMLModuleBase >)=0
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
Configurator class for QMLModuleBase.
QMLModuleConfiguratorBase()=default
Data class for QMLModuleBase.
QMLModuleDataBase()=default
virtual ~QMLModuleDataBase()=default
virtual void ResetImpl(dispatch_tag< QMLModuleDataBase >)
Parameter class for QMLModuleBase.
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
void ConfigureParamsImpl(dispatch_tag< QModuleParamsBase >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
virtual void ConfigureParamsImpl(dispatch_tag< QMLModuleParamsBase >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
QMLModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a QMLModuleBase instance.
Base class for modules with a Qt-based user interface. Derive from this class to implement modules wi...
WidgetType * GetWidget() const
Getter for Widget.
QModuleWidget * Widget
User interface widget belonging to the module.
void Connect(SenderType *Sender, SignalType Signal, ReceiverType *Receiver, EventType Event)
Uses Qt's connect mechanism to connect a QObject's signal to a DynExp module's event....
bool HasUI() const noexcept override final
Determines whether this module possesses a user interface (UI) which is shown in a window dedicated t...
QMdiArea * MdiArea
Pointer to DynExpManager's QMdiArea.
std::unique_ptr< QModuleDockWidget > DockWidget
Frame for Widget when the module window is undocked from MdiArea.
std::unique_ptr< QMdiSubWindow > MdiSubWindow
Frame for Widget when the module window is docked to MdiArea.
std::unique_ptr< QAction > ModuleWindowFocusAction
Qt action to push module window into focus. When triggered, QModuleWidget::OnFocusWindow() in invoked...
Configurator class for QModuleBase.
QModuleConfiguratorBase()=default
Data class for QModuleBase.
virtual ~QModuleDataBase()=default
virtual void ResetImpl(dispatch_tag< QModuleDataBase >)
QModuleDataBase()=default
Parameter class for QModuleBase.
virtual void ConfigureParamsImpl(dispatch_tag< QModuleParamsBase >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
WindowStyleParamsExtension WindowStyleParams
Bundles several parameters to describe a UI window's style. Use in parameter classes.
void ConfigureParamsImpl(dispatch_tag< ModuleParamsBase >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
QModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a QModuleBase instance.
Defines data for a thread belonging to a RunnableObject instance. This data is only accessed by the R...
const RunnableObject & Owner
RunnableObject instance which operates on this RunnableInstance (by its thread). The RunnableObject i...
std::promise< void > ThreadExitedPromise
Signals the RunnableObject instance owning the thread that its thread has terminated....
Configurator class for RunnableObject.
Parameter class for RunnableObject.
Defines an Object which possesses a thread it runs in. The RunnableObject can be started and stopped ...
void SetReasonWhyPaused(std::string Description)
Sets the reason why this RunnableObject instance has been paused.
Typed managers of event listeners class whose instances are owned by classes derived from InterModule...
virtual ~TypedEventListeners()=default
void DeregisterAllUnsafe(const ModuleBase &Listener)
This function is not thread-safe (assuming EventListenersBase's mutex has already been locked before ...
std::unordered_map< const ListenersTypeKey, EventFunctionType, ListenersTypeKeyHasher > Listeners
Each module can register to each inter-module event with one event function of type EventFunctionType...
EventFunctionType GetFunc(const ModuleBase &Listener, ItemIDType CommunicatorID=ItemIDNotSet, const std::chrono::milliseconds Timeout=DefaultTimeout) const
Looks up the event function the module Listener has registered/subscribed with.
virtual void Deregister(const ModuleBase &Listener, const std::chrono::milliseconds Timeout=std::chrono::milliseconds(0)) override
Deregisters/unsubscribes module Listener from the event, regardless of the inter-module communicator ...
EventFunctionType GetFuncUnsafe(const ModuleBase &Listener, ItemIDType CommunicatorID) const
This function is the version of GetFunc() which is not thread-safe (assuming EventListenersBase's mut...
TypedEventListeners()=default
virtual void Deregister(const ModuleBase &Listener, ItemIDType CommunicatorID, const std::chrono::milliseconds Timeout=std::chrono::milliseconds(0)) override
Deregisters/unsubscribes module Listener from the event, removing a single registration for a particu...
void DeregisterUnsafe(const ModuleBase &Listener, ItemIDType CommunicatorID)
This function is not thread-safe (assuming EventListenersBase's mutex has already been locked before ...
void Register(const ModuleBase &Listener, CallableT EventFunc, ItemIDType CommunicatorID=ItemIDNotSet, const std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))
Registers/Subscribes module Listener to the event with the event function EventFunc....
std::function< void(ModuleInstance *, EventFuncArgs...)> EventFunctionType
Type of event functions to be invoked when the event is triggered. The first ModuleInstance argument ...
void RegisterUnsafe(const ModuleBase &Listener, CallableT EventFunc, ItemIDType CommunicatorID)
This function is not thread-safe (assuming EventListenersBase's mutex has already been locked before ...
Bundles several parameters to describe a UI window's style. Use in parameter classes.
WindowStyleParamsExtension(ParamsBase &Owner, const std::string &Prefix="")
Constructs a WindowStyleParamsExtension instance.
WindowDockingStateType
Indicates the window docking state.
ParamsBase::Param< unsigned int > WindowWidth
Window width.
ParamsBase::Param< int > WindowPosY
Window y coordinate.
WindowStateType
Indicates the window state for showing it.
ParamsBase::Param< WindowDockingStateType > WindowDockingState
Window docking state.
ParamsBase::Param< int > WindowPosX
Window x coordinate.
ParamsBase::Param< WindowStateType > WindowState
Window show state.
ParamsBase::Param< unsigned int > WindowHeight
Window height.
Wraps a member function of some object and stores its default arguments. Moving from CallableMemberWr...
void Log(const std::string &Message, const ErrorType Type=ErrorType::Info, const size_t Line=0, const std::string &Function="", const std::string &File="", const int ErrorCode=0, const std::stacktrace &Trace={}) noexcept
Logs an event from information specified manually.
DynExp exceptions are derived from this class. It contains basic information about the cause of the e...
Interface to allow synchronizing the access to derived classes between different threads by providing...
LockType AcquireLock(const std::chrono::milliseconds Timeout=DefaultTimeout) const
Locks the internal mutex. Blocks until the mutex is locked or until the timeout duration is exceeded.
static constexpr std::chrono::milliseconds DefaultTimeout
Duration which is used as a default timeout within all methods of this class if no different duration...
Interface to allow synchronizing the access to derived classes between different threads by making th...
An invalid argument like a null pointer has been passed to a function.
An operation cannot be performed currently since the related object is in an invalid state like an er...
Helper class to communicate flags between different threads based on a condition variable and a mutex...
void Notify()
Set notification to stop waiting (sets EventOccurred to true).
Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads....
DynExp's module namespace contains the implementation of DynExp modules which extend DynExp's core fu...
DynExp's main namespace contains the implementation of DynExp including classes to manage resources (...
int ModuleThreadMain(std::unique_ptr< RunnableInstance > &&InstancePtr, RunnableObject *BaseObject)
Modules run in their own thread. This is the module thread's main function.
ConfiguratorBasePtrType MakeModuleConfig()
Factory function to generate a configurator for a specific module type.
ModulePtrType MakeModule(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Factory function to generate a module of a specific type.
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
size_t ItemIDType
ID type of objects/items managed by DynExp.
auto MakeEvent(ReceiverType *Receiver, typename DefaultEvent< ReceiverType, std::tuple< std::remove_reference_t< ArgsTs >... > >::EventFuncPtrType EventFuncPtr, ArgsTs &&...Args)
Creates an event of type DefaultEvent.
auto dynamic_ModuleData_cast(Util::SynchronizedPointer< From > &&ModuleDataPtr)
Casts the data base class From into a derived ModuleBase's (To) data class keeping the data locked by...
std::unique_ptr< ModuleBase > ModulePtrType
Pointer type to store a module (DynExp::ModuleBase) with.
std::shared_ptr< ConfiguratorBase > ConfiguratorBasePtrType
Alias for a pointer to the configurator base class ConfiguratorBase.
DynExpErrorCodes
DynExp's error codes
DynExp's Util namespace contains commonly used functions and templates as well as extensions to Qt an...
typename remove_first_from_tuple< TupleT >::type remove_first_from_tuple_t
Alias for a tuple of types where the first type of the input tuple TupleT is removed.
EventLogger & EventLog()
This function holds a static EventLogger instance and returns a reference to it. DynExp uses only one...
void HashCombine(std::size_t &seed, const T &value)
Combines the std::hash seed with the hash of value. Resembles hash_combine() from the Boost library p...
typename member_fn_ptr_traits< CallableT >::argument_types argument_of_t
Alias for a tuple of argument types the member function callable of type CallableT expects.
Accumulates include statements to provide a precompiled header.
Helper struct to allow accessing elements within ArgTupleType.
constexpr EventFuncTraits()=default
void(ReceiverType::*)(ModuleInstance *, std::tuple_element_t< Indices, ArgTupleType >...) const EventFuncPtrType
Signature of an event function. Pointer to ModuleInstance to be passed as parameter instead of refere...
Hasher required to use ListenersTypeKey as the key type for the std::unordered_map Listeners.
size_t operator()(const ListenersTypeKey &v) const
Computes the hash of v.
Key type of the unordered_map storing module/inter-module communicator combinations that registered t...
const ModuleBase * Module
Module that registered to the event.
bool operator==(const ListenersTypeKey &Other) const
Checks for equality of Module and CommunicatorID.
const ItemIDType CommunicatorID
ID of the inter-module communicator instrument (instance of DynExpInstr::InterModuleCommunicator) bel...