DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Module.h
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
8 #pragma once
9 
10 #include "stdafx.h"
11 #include "Object.h"
12 
13 namespace DynExp
14 {
15  class ModuleBase;
16  class ModuleInstance;
17  class EventListenersBase;
18  class QModuleBase;
19 
23  using ModulePtrType = std::unique_ptr<ModuleBase>;
24 
30  template <typename ModuleT>
32  {
33  return std::make_shared<typename ModuleT::ConfigType>();
34  }
35 
43  template <typename ModuleT>
44  ModulePtrType MakeModule(const std::thread::id OwnerThreadID, ParamsBasePtrType&& Params)
45  {
46  dynamic_Params_cast<ModuleT>(Params.get())->ModuleData = std::make_unique<typename ModuleT::ModuleDataType>();
47 
48  return std::make_unique<ModuleT>(OwnerThreadID, std::move(Params));
49  }
50 
61  int ModuleThreadMain(ModuleInstance Instance, ModuleBase* const Module);
62 
66  class EventBase
67  {
68  public:
69  EventBase() = default;
70  virtual ~EventBase() = 0;
71 
76  void Invoke(ModuleInstance& Instance) const { InvokeChild(Instance); }
77 
78  private:
83  virtual void InvokeChild(ModuleInstance& Instance) const = 0;
85  };
86 
93  template <typename ReceiverType, typename ArgTupleType>
94  class DefaultEvent : public EventBase
95  {
96  private:
101  template <size_t... Indices>
103  {
104  constexpr EventFuncTraits() = default;
105 
111  using EventFuncPtrType = void (ReceiverType::*)(ModuleInstance*, std::tuple_element_t<Indices, ArgTupleType>...) const;
112 
117  };
118 
124  template <size_t... Indices>
125  constexpr static auto MakeEventFuncTraits(std::index_sequence<Indices...>) { return EventFuncTraits<Indices...>(); }
126 
130  using ArgTupleIndexSequenceType = decltype(std::make_index_sequence<std::tuple_size_v<ArgTupleType>>());
131 
135  using InstantiatedEventFuncTraitsType = decltype(DefaultEvent<ReceiverType, ArgTupleType>::MakeEventFuncTraits(std::declval<ArgTupleIndexSequenceType>()));
136 
137  public:
138  using EventFuncPtrType = typename InstantiatedEventFuncTraitsType::EventFuncPtrType;
139  using EventFuncType = typename InstantiatedEventFuncTraitsType::EventFuncType;
140 
146 
147  virtual ~DefaultEvent() {}
148 
149  private:
150  virtual void InvokeChild(ModuleInstance& Instance) const override { EventFunc(&Instance); }
151 
156  };
157 
171  {
172  public:
176  using EventPtrType = std::unique_ptr<EventBase>;
177 
181  using EventQueueType = std::queue<EventPtrType>;
182 
183  protected:
188  template <typename>
189  struct dispatch_tag {};
190 
191  private:
196  {
197  friend class ModuleDataBase;
198  friend class ModuleBase;
199 
205 
206  void Reset() { Parent.Reset(); }
207 
208  auto& GetNewEventNotifier() noexcept { return Parent.GetNewEventNotifier(); }
209 
211  };
212 
218  {
219  friend class ModuleDataBase;
220  friend int ModuleThreadMain(ModuleInstance, ModuleBase* const);
221 
227 
228  auto& GetNewEventNotifier() noexcept { return Parent.GetNewEventNotifier(); }
229  void SetException(std::exception_ptr ModuleException) noexcept { Parent.ModuleException = ModuleException; }
230 
232  };
233 
234  public:
236  virtual ~ModuleDataBase() {}
237 
243 
250  void EnqueueEvent(EventPtrType&& Event);
251 
258 
264  const auto& GetEventFront() const noexcept { return *EventQueue.front().get(); }
265 
270  auto& GetEventFront() noexcept { return *EventQueue.front().get(); }
271 
276  size_t GetNumEnqueuedEvents() const noexcept { return EventQueue.size(); }
278 
283  auto GetException() const noexcept { return ModuleException; }
284 
287 
288  private:
294 
299 
303  void Reset();
304 
312 
317 
324 
330  std::exception_ptr ModuleException;
331  };
332 
337  {
338  friend class ModuleBase;
339 
340  template <typename>
341  friend ModulePtrType MakeModule(const std::thread::id, ParamsBasePtrType&&);
342 
343  public:
349 
350  virtual ~ModuleParamsBase() = 0;
351 
352  virtual const char* GetParamClassTag() const noexcept override { return "ModuleParamsBase"; }
353 
354  private:
357 
358  // Usage parameters may be used in the future also by modules.
359  bool ConfigureUsageTypeChild() const noexcept override final { return false; }
360 
365  std::unique_ptr<ModuleDataBase> ModuleData;
366 
367  DummyParam Dummy = { *this };
368  };
369 
374  {
375  public:
378 
380  virtual ~ModuleConfiguratorBase() = 0;
381  };
382 
391  class ModuleBase : public RunnableObject
392  {
398  {
399  friend class ModuleBase;
400  friend int ModuleThreadMain(ModuleInstance, ModuleBase* const);
401 
407 
408  void HandleEvent(ModuleInstance& Instance) { Parent.HandleEvent(Instance); } //<! @copydoc ModuleBase::HandleEvent
409  Util::DynExpErrorCodes::DynExpErrorCodes ModuleMainLoop(ModuleInstance& Instance) { return Parent.ExecModuleMainLoop(Instance); } //<! @copydoc ModuleBase::ExecModuleMainLoop
410  void OnPause(ModuleInstance& Instance) { Parent.OnPause(Instance); } //<! @copydoc ModuleBase::OnPause
411  void OnResume(ModuleInstance& Instance) { Parent.OnResume(Instance); } //<! @copydoc ModuleBase::OnResume
412  void OnError(ModuleInstance& Instance) { Parent.OnError(Instance); } //<! @copydoc ModuleBase::OnError
413 
414  void SetReasonWhyPaused(std::string Description) { Parent.ModuleSetReasonWhyPaused(std::move(Description)); } //<! @copydoc ModuleBase::ModuleSetReasonWhyPaused
415 
417  };
418 
424  {
425  friend class ModuleBase;
426 
427  template <typename...>
428  friend class TypedEventListeners;
429 
435 
436  void AddRegisteredEvent(EventListenersBase& EventListeners) const { Parent.AddRegisteredEvent(EventListeners); }
437  void RemoveRegisteredEvent(EventListenersBase& EventListeners) const { Parent.RemoveRegisteredEvent(EventListeners); }
438 
440  };
441 
442  public:
445 
451 
457 
463 
468  constexpr static auto Category() noexcept { return ""; }
469 
475  ModuleBase(const std::thread::id OwnerThreadID, ParamsBasePtrType&& Params);
476 
477  virtual ~ModuleBase() = 0;
478 
479  virtual std::string GetCategory() const override { return Category(); }
480 
485 
490  virtual bool HasUI() const noexcept { return false; }
491 
498  virtual bool TreatModuleExceptionsAsWarnings() const { return true; }
499 
506  virtual std::chrono::milliseconds GetMainLoopDelay() const { return std::chrono::milliseconds(10); }
508 
513  static constexpr auto GetModuleDataTimeoutDefault = std::chrono::milliseconds(1000);
514 
517 
522 
528 
535 
546 
553  ModuleDataTypeSyncPtrConstType GetModuleData(const std::chrono::milliseconds Timeout = GetModuleDataTimeoutDefault) const;
554 
558  void EnqueueEvent(ModuleDataBase::EventPtrType&& Event) const;
559 
578  template <typename ReceiverType, typename EventType, typename... ArgsTs>
579  void MakeAndEnqueueEvent(ReceiverType* Receiver, EventType EventFuncPtr, ArgsTs&& ...Args) const;
581 
587  ModuleDataTypeSyncPtrType (ModuleBase::*)(const std::chrono::milliseconds)>;
588 
589  private:
594 
602 
603  protected:
610  static auto GetExceptionUnsafe(const ModuleDataTypeSyncPtrConstType& ModuleDataPtr) { return ModuleDataPtr->GetException(); }
611 
612  private:
617 
621  void HandleEvent(ModuleInstance& Instance);
622 
628  void AddRegisteredEvent(EventListenersBase& EventListeners);
629 
635  void RemoveRegisteredEvent(EventListenersBase& EventListeners);
636 
642 
649  void OnPause(ModuleInstance& Instance);
650 
657  void OnResume(ModuleInstance& Instance);
658 
664  void OnError(ModuleInstance& Instance);
666 
671  virtual void OnPauseChild(ModuleInstance& Instance) const {}
672  virtual void OnResumeChild(ModuleInstance& Instance) const {}
673  virtual void OnErrorChild(ModuleInstance& Instance) const {}
674 
677 
686 
687  void ResetImpl(dispatch_tag<RunnableObject>) override final;
689 
694  void ModuleSetReasonWhyPaused(std::string Description) { SetReasonWhyPaused(std::move(Description)); }
695 
700  void RunChild() override final;
701  void NotifyChild() override final;
702  void TerminateChild(const std::chrono::milliseconds Timeout) override final;
703  std::unique_ptr<BusyDialog> MakeStartupBusyDialogChild(QWidget* ParentWidget) const override final;
705 
706  std::exception_ptr GetExceptionChild([[maybe_unused]] const std::chrono::milliseconds Timeout) const override final;
707  bool IsReadyChild() const override final;
708 
713 
719  virtual void OnInit(ModuleInstance* Instance) const {}
720 
728  virtual void OnExit(ModuleInstance* Instance) const {}
729 
737  void OnDeregisterEvents(ModuleInstance* Instance) const;
739 
743  const std::unique_ptr<ModuleDataType> ModuleData;
744 
750  std::vector<EventListenersBase*> RegisteredEvents;
751  };
752 
762  template <typename ReceiverType, typename... ArgsTs>
763  auto MakeEvent(ReceiverType* Receiver,
764  typename DefaultEvent<ReceiverType, std::tuple<std::remove_reference_t<ArgsTs>...>>::EventFuncPtrType EventFuncPtr,
765  ArgsTs&& ...Args)
766  {
767  if (!EventFuncPtr)
768  throw Util::InvalidArgException("EventFuncPtr cannot be nullptr.");
769 
770  // Use EventArgTs instead of std::tuple<ArgsTs...> since the latter would create a tuple of references!
771  using EventArgTs = Util::remove_first_from_tuple_t<Util::argument_of_t<decltype(EventFuncPtr)>>;
772 
773  auto EventFunc = typename DefaultEvent<ReceiverType, EventArgTs>::EventFuncType(*Receiver, EventFuncPtr,
774  Util::argument_of_t<decltype(EventFuncPtr)>(nullptr, std::forward<ArgsTs>(Args)...));
775 
776  return std::make_unique<DefaultEvent<ReceiverType, EventArgTs>>(EventFunc);
777  }
778 
779  template <typename ReceiverType, typename EventType, typename... ArgsTs>
780  void ModuleBase::MakeAndEnqueueEvent(ReceiverType* Receiver, EventType EventFuncPtr, ArgsTs&& ...Args) const
781  {
782  if (Receiver != this)
783  throw Util::InvalidArgException("Receiver cannot point to a module different from the instance MakeAndEnqueueEvent() is called on.");
784 
785  EnqueueEvent(MakeEvent(Receiver, EventFuncPtr, std::forward<ArgsTs>(Args)...));
786  }
787 
793  {
794  public:
799  ModuleInstance(ModuleBase& Owner, std::promise<void>&& ThreadExitedPromise,
801 
806 
807  ~ModuleInstance() = default;
808 
813  void Exit() noexcept { ShouldExit = true; }
814 
820  bool IsExiting() const noexcept { return ShouldExit; }
821 
826 
827  private:
832  bool ShouldExit = false;
833  };
834 
848  template <typename To, typename From, std::enable_if_t<
849  std::is_same_v<ModuleDataBase, std::remove_cv_t<From>>, int> = 0
850  >
852  {
853  if (!ModuleDataPtr)
854  throw Util::InvalidArgException("ModuleDataPtr must not be nullptr.");
855 
857  std::conditional_t<std::is_const_v<From>, std::add_const_t<typename To::ModuleDataType>, typename To::ModuleDataType>
858  >(std::move(ModuleDataPtr));
859  }
860 
866  {
867  protected:
868  EventListenersBase() = default;
869  virtual ~EventListenersBase() {};
870 
871  public:
878  virtual void Deregister(const ModuleBase& Listener, const std::chrono::milliseconds Timeout = std::chrono::milliseconds(0)) = 0;
879  };
880 
889  template <typename... EventFuncArgs>
891  {
892  public:
899  using EventFunctionType = std::function<void(ModuleInstance*, EventFuncArgs...)>;
900 
901  TypedEventListeners() = default;
902  virtual ~TypedEventListeners() = default;
903 
913  template <typename CallableT>
914  void Register(const ModuleBase& Listener, CallableT EventFunc, const std::chrono::milliseconds Timeout = std::chrono::milliseconds(0))
915  {
916  auto lock = AcquireLock(Timeout);
917  RegisterUnsafe(Listener, EventFunc);
918  }
919 
920  virtual void Deregister(const ModuleBase& Listener, const std::chrono::milliseconds Timeout = std::chrono::milliseconds(0)) override
921  {
922  auto lock = AcquireLock(Timeout);
923  DeregisterUnsafe(Listener);
924  }
925 
933  EventFunctionType GetFunc(const ModuleBase& Listener, const std::chrono::milliseconds Timeout = DefaultTimeout) const
934  {
935  auto lock = AcquireLock(Timeout);
936  return GetFuncUnsafe(Listener);
937  }
938 
939  private:
948  template <typename CallableT>
949  void RegisterUnsafe(const ModuleBase& Listener, CallableT EventFunc)
950  {
951  Listeners[&Listener] = [&Listener, EventFunc](ModuleInstance* Instance, EventFuncArgs... Args) {
952  (dynamic_cast<std::add_const_t<typename Util::member_fn_ptr_traits<CallableT>::instance_type>&>(Listener).*EventFunc)(Instance, Args...);
953  };
954 
955  Listener.EventListenersOnly.AddRegisteredEvent(*this);
956  }
957 
963  void DeregisterUnsafe(const ModuleBase& Listener)
964  {
965  auto ListenerIt = Listeners.find(&Listener);
966  if (ListenerIt == Listeners.cend())
967  return;
968 
969  Listeners.erase(ListenerIt);
971  }
972 
981  {
982  auto ListenerIt = Listeners.find(&Listener);
983  return ListenerIt != Listeners.cend() ? ListenerIt->second : nullptr;
984  }
985 
990  std::unordered_map<const ModuleBase*, EventFunctionType> Listeners;
991  };
992 
997  {
998  public:
999  InterModuleEventBase() = default;
1000  virtual ~InterModuleEventBase() = 0;
1001  };
1002 
1009  template <typename DerivedEvent, typename... EventFuncArgs>
1011  {
1012  public:
1018  using EventListenersType = TypedEventListeners<EventFuncArgs...>;
1019 
1020  InterModuleEvent() = default;
1021  virtual ~InterModuleEvent() {}
1022 
1027  template <typename CallableT>
1028  static void Register(const ModuleBase& Listener, CallableT EventFunc) { Listeners.Register(Listener, EventFunc); }
1029 
1034  static void Deregister(const ModuleBase& Listener) { Listeners.Deregister(Listener); }
1035 
1036  private:
1037  virtual void InvokeChild(ModuleInstance& Instance) const override final
1038  {
1039  auto EventFunc = Listeners.GetFunc(static_cast<const ModuleBase&>(Instance.GetOwner()));
1040 
1041  if (EventFunc)
1042  InvokeWithParamsChild(Instance, EventFunc);
1043  }
1044 
1049 
1058 
1064  };
1065 
1070  template <typename DerivedEvent, typename... EventFuncArgs>
1071  typename InterModuleEvent<DerivedEvent, EventFuncArgs...>::EventListenersType InterModuleEvent<DerivedEvent, EventFuncArgs...>::Listeners;
1072 
1078  class QModuleWidget : public QWidget
1079  {
1080  Q_OBJECT
1081 
1082  friend class QModuleBase;
1083 
1084  public:
1089  constexpr static Qt::WindowFlags GetQtWindowFlagsResizable();
1090 
1095  constexpr static Qt::WindowFlags GetQtWindowFlagsNonResizable();
1096 
1103  QModuleWidget(QModuleBase& Owner, QWidget* Parent = nullptr);
1104 
1105  ~QModuleWidget() = default;
1106 
1111  const auto& GetOwner() const noexcept { return Owner; }
1112 
1117 
1121  virtual bool AllowResize() const noexcept { return false; }
1123 
1129  Qt::WindowFlags GetQtWindowFlags() const noexcept;
1130 
1137  std::string GetDataSaveDirectory() const;
1138 
1145  void SetDataSaveDirectory(std::string_view Directory) const;
1146 
1147  private:
1152  void EnableDockWindowShortcut(bool Enable) noexcept;
1153 
1160  virtual void closeEvent(QCloseEvent* Event) override;
1161 
1164 
1165  QShortcut* DockWindowShortcut;
1167 
1168  private slots:
1169  void OnDockWindow();
1170  void OnFocusWindow();
1171  void OnFocusMainWindow();
1172  };
1173 
1178  class QModuleDockWidget : public QDockWidget
1179  {
1180  Q_OBJECT
1181 
1182  public:
1191  QModuleDockWidget(QModuleBase& Owner, QWidget* Parent, Qt::WindowFlags Flags);
1192 
1193  ~QModuleDockWidget() = default;
1194 
1195  private:
1202  virtual void closeEvent(QCloseEvent* Event) override;
1203 
1211  virtual void keyPressEvent(QKeyEvent* Event) override;
1212 
1214  };
1215 
1220  {
1221  public:
1222  QModuleDataBase() = default;
1223  virtual ~QModuleDataBase() = default;
1224 
1225  private:
1226  void ResetImpl(dispatch_tag<ModuleDataBase>) override final;
1228  };
1229 
1234  {
1235  public:
1239  enum WindowStateType { Normal, Minimized, Maximized };
1256  enum WindowDockingStateType { Docked, Undocked };
1272  WindowStyleParamsExtension(ParamsBase& Owner, const std::string& Prefix = "")
1273  : WindowPosX{ Owner, Prefix + "WindowPosX" },
1274  WindowPosY{ Owner, Prefix + "WindowPosY" },
1275  WindowWidth{ Owner, Prefix + "WindowWidth" },
1276  WindowHeight{ Owner, Prefix + "WindowHeight" },
1277  WindowState{ Owner, Prefix + "WindowState", WindowStateType::Normal },
1278  WindowDockingState{ Owner, Prefix + "WindowDockingState", WindowDockingStateType::Docked }
1279  {}
1280 
1286  void ApplyTo(QWidget& Widget, bool Show = true) const;
1287 
1292  void FromWidget(const QWidget& Widget);
1293 
1300  };
1301 
1306  {
1307  public:
1313  : ModuleParamsBase(ID, Core), WindowStyleParams(*this) {}
1314 
1315  virtual ~QModuleParamsBase() = 0;
1316 
1317  virtual const char* GetParamClassTag() const noexcept override { return "QModuleParamsBase"; }
1318 
1320 
1321  private:
1324  };
1325 
1330  {
1331  public:
1334 
1336  virtual ~QModuleConfiguratorBase() = 0;
1337  };
1338 
1343  class QModuleBase : public ModuleBase
1344  {
1345  public:
1349 
1354  QModuleBase(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType&& Params);
1355 
1356  virtual ~QModuleBase() = 0;
1357 
1358  bool HasUI() const noexcept override final { return true; }
1359 
1365 
1374  QAction& InitUI(DynExpManager& DynExpMgr, QMdiArea* const MdiArea);
1375 
1376  void HideUI();
1377  void DisableUI();
1378  void UpdateUI();
1379 
1387  void UpdateModuleWindowFocusAction();
1388 
1389  void DockWindow() noexcept;
1390  void UndockWindow() noexcept;
1391  void DockUndockWindow() noexcept;
1392  void SetFocus() noexcept;
1393  void FocusMainWindow() noexcept;
1394 
1400  void SendKeyPressEventToMainWindow(QKeyEvent* Event) noexcept;
1401 
1408  bool IsWindowDocked() noexcept;
1409 
1417  bool IsActiveWindow();
1419 
1420  protected:
1443  template <typename SenderType, typename SignalType, typename ReceiverType, typename EventType>
1444  void Connect(SenderType* Sender, SignalType Signal, ReceiverType* Receiver, EventType Event);
1445 
1452  template <typename WidgetType>
1453  WidgetType* GetWidget() const;
1454 
1455  private:
1456  virtual void RestoreWindowStatesFromParamsChild() override;
1457  virtual void UpdateParamsFromWindowStatesChild() override;
1458 
1465  void SetWidgetProperties(QWidget* const WindowWidget) const;
1466 
1467  void ResetImpl(dispatch_tag<ModuleBase>) override final;
1468  virtual void ResetImpl(dispatch_tag<QModuleBase>) = 0;
1469 
1474 
1480  virtual std::unique_ptr<QModuleWidget> MakeUIWidget() = 0;
1481 
1488  virtual void UpdateUIChild(const ModuleBase::ModuleDataGetterType& ModuleDataGetter) {}
1490 
1492  std::unique_ptr<QMdiSubWindow> MdiSubWindow;
1493  std::unique_ptr<QModuleDockWidget> DockWidget;
1494  std::unique_ptr<QAction> ModuleWindowFocusAction;
1495 
1496  QMdiArea* MdiArea;
1497  };
1498 
1499  template <typename SenderType, typename SignalType, typename ReceiverType, typename EventType>
1500  void QModuleBase::Connect(SenderType* Sender, SignalType Signal, ReceiverType* Receiver, EventType Event)
1501  {
1502  EnsureCallFromOwningThread();
1503 
1504  if (!Sender || !Receiver)
1505  throw Util::InvalidArgException("Sender and Receiver cannot be nullptr.");
1506 
1507  // Arguments must not be passed by reference or by pointer to Event since Event is invoked later when
1508  // references/pointers might not be valid anymore.
1509  auto Connection = QObject::connect(Sender, Signal, [this, Receiver, Event](auto... Args) {
1510  try
1511  {
1512  MakeAndEnqueueEvent(Receiver, Event, std::move(Args)...);
1513  }
1514  catch (const Util::Exception& e)
1515  {
1516  Util::EventLog().Log("Posting an event from a module's UI to the module's thread, the error listed below occurred.", Util::ErrorType::Error);
1517  Util::EventLog().Log(e);
1518  }
1519  catch (const std::exception& e)
1520  {
1521  Util::EventLog().Log("Posting an event from a module's UI to the module's thread, the error listed below occurred.", Util::ErrorType::Error);
1522  Util::EventLog().Log(e.what());
1523  }
1524  catch (...)
1525  {
1526  Util::EventLog().Log("Posting an event from a module's UI to the module's thread, an unknown error occurred.", Util::ErrorType::Error);
1527  }
1528  });
1529 
1530  if (!Connection)
1531  throw Util::InvalidArgException("QObject::connect() cannot establish a connection for the given sender and signal types.");
1532  }
1533 
1534  template <typename WidgetType>
1535  WidgetType* QModuleBase::GetWidget() const
1536  {
1537  // EnsureCallFromOwningThread(); considered here, but it also prohibits legitimate calls
1538  // to thread-safe (probably const) member functions of the widget. Note, accessing the UI
1539  // objects from another thread than the application's main thread is strongly forbidden!
1540 
1541  if (!Widget)
1542  throw Util::InvalidStateException("UI widget has not been created yet.");
1543 
1544  // Throws if it fails.
1545  return &dynamic_cast<WidgetType&>(*Widget);
1546  }
1547 }
1548 
1553 namespace DynExpModule {};
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).
Definition: DynExpManager.h:21
Describes an event which consists of a receiver's member function and a set of arguments to call this...
Definition: Module.h:95
decltype(DefaultEvent< ReceiverType, ArgTupleType >::MakeEventFuncTraits(std::declval< ArgTupleIndexSequenceType >())) InstantiatedEventFuncTraitsType
Type of the instantiated EventFuncTraits - not actually instantiating it.
Definition: Module.h:135
DefaultEvent(EventFuncType EventFunc) noexcept
Constructs a DefaultEvent instance.
Definition: Module.h:145
virtual ~DefaultEvent()
Definition: Module.h:147
decltype(std::make_index_sequence< std::tuple_size_v< ArgTupleType > >()) ArgTupleIndexSequenceType
Index sequence for the (pseudo-)instantiation of EventFuncTraits.
Definition: Module.h:130
virtual void InvokeChild(ModuleInstance &Instance) const override
Invokes the event passing the receiving module's instance reference to it.
Definition: Module.h:150
const EventFuncType EventFunc
Util::CallableMemberWrapper to store the event receiver, the event function, and its arguments.
Definition: Module.h:155
constexpr static auto MakeEventFuncTraits(std::index_sequence< Indices... >)
Instantiates EventFuncTraits. This function is not meant to be called. It is used for type deduction ...
Definition: Module.h:125
typename InstantiatedEventFuncTraitsType::EventFuncPtrType EventFuncPtrType
Signature of an event function. Pointer to ModuleInstance to be passed as parameter instead of refere...
Definition: Module.h:138
typename InstantiatedEventFuncTraitsType::EventFuncType EventFuncType
Type of a Util::CallableMemberWrapper to store the event.
Definition: Module.h:139
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition: DynExpCore.h:127
Common base class for all events to store them in a FIFO queue to be invoked later.
Definition: Module.h:67
EventBase()=default
virtual ~EventBase()=0
Definition: Module.cpp:149
void Invoke(ModuleInstance &Instance) const
Invokes the event passing the receiving module's instance reference to it.
Definition: Module.h:76
virtual void InvokeChild(ModuleInstance &Instance) const =0
Invokes the event passing the receiving module's instance reference to it.
Common base class for all managers of event listeners of type TypedEventListeners....
Definition: Module.h:866
virtual ~EventListenersBase()
Definition: Module.h:869
virtual void Deregister(const ModuleBase &Listener, const std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))=0
Deregisters/unsubscribes module Listener from the event. Indirectly calls ModuleBase::RemoveRegistere...
Common base class for all inter-module events.
Definition: Module.h:997
virtual ~InterModuleEventBase()=0
Definition: Module.cpp:401
Typed base class for inter-module events to realize CRTP.
Definition: Module.h:1011
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 ~InterModuleEvent()
Definition: Module.h:1021
virtual void InvokeChild(ModuleInstance &Instance) const override final
Invokes the event passing the receiving module's instance reference to it.
Definition: Module.h:1037
static void Register(const ModuleBase &Listener, CallableT EventFunc)
Registers/Subscribes module Listener to the event with the event function EventFunc....
Definition: Module.h:1028
static void Deregister(const ModuleBase &Listener)
Deregisters/unsubscribes module Listener from the event. Indirectly calls ModuleBase::RemoveRegistere...
Definition: Module.h:1034
static EventListenersType Listeners
Holds one EventListenersType instance per derived event, which manages all the subscribers of Derived...
Definition: Module.h:1063
Allow exclusive access to some of ModuleBase's private methods to any TypedEventListeners class.
Definition: Module.h:424
ModuleBase & Parent
Owning ModuleBase instance.
Definition: Module.h:439
constexpr EventListenersOnlyType(ModuleBase &Parent) noexcept
Construcs an instance - one for each ModuleBase instance.
Definition: Module.h:434
void AddRegisteredEvent(EventListenersBase &EventListeners) const
Adds a manager of event listeners to RegisteredEvents if it was not already added before....
Definition: Module.h:436
void RemoveRegisteredEvent(EventListenersBase &EventListeners) const
Removes a manager of event listeners from RegisteredEvents if it was added before....
Definition: Module.h:437
Allow exclusive access to some of ModuleBase's private methods to the module thread ModuleThreadMain(...
Definition: Module.h:398
void OnPause(ModuleInstance &Instance)
Definition: Module.h:410
ModuleBase & Parent
Owning ModuleBase instance.
Definition: Module.h:416
Util::DynExpErrorCodes::DynExpErrorCodes ModuleMainLoop(ModuleInstance &Instance)
Definition: Module.h:409
void OnError(ModuleInstance &Instance)
Definition: Module.h:412
constexpr ModuleThreadOnlyType(ModuleBase &Parent) noexcept
Construcs an instance - one for each ModuleBase instance.
Definition: Module.h:406
void SetReasonWhyPaused(std::string Description)
Definition: Module.h:414
friend int ModuleThreadMain(ModuleInstance, ModuleBase *const)
Modules run in their own thread. This is the module thread's main function.
Definition: Module.cpp:10
void HandleEvent(ModuleInstance &Instance)
Definition: Module.h:408
void OnResume(ModuleInstance &Instance)
Definition: Module.h:411
Base class for modules. Modules implement programs on their own (e.g. measurement protocols or server...
Definition: Module.h:392
void TerminateChild(const std::chrono::milliseconds Timeout) override final
Signals derived classes that terminating the RunnableObject instance's thread is about to be requeste...
Definition: Module.cpp:333
ModuleDataTypeSyncPtrType GetModuleData(const std::chrono::milliseconds Timeout=GetModuleDataTimeoutDefault)
Locks the mutex of the module data class instance ModuleData assigned to this ModuleBase instance and...
Definition: Module.cpp:202
virtual void OnErrorChild(ModuleInstance &Instance) const
This handler gets called just before the module thread terminates due to an exception....
Definition: Module.h:673
void OnPause(ModuleInstance &Instance)
This handler gets called just after the module pauses due to e.g. an error in an instrument the modul...
Definition: Module.cpp:271
void NotifyChild() override final
Notify derived classes that some state has changed (e.g. the termination of Thread is requested) and ...
Definition: Module.cpp:328
void RunChild() override final
Refer to Run().
Definition: Module.cpp:317
void ModuleSetReasonWhyPaused(std::string Description)
Sets the reason why this ModuleBase instance has been paused.
Definition: Module.h:694
void OnDeregisterEvents(ModuleInstance *Instance) const
This event is triggered after the OnExit event. It calls EventListenersBase::Deregister() for all man...
Definition: Module.cpp:379
static auto GetExceptionUnsafe(const ModuleDataTypeSyncPtrConstType &ModuleDataPtr)
Getter for ModuleDataBase::ModuleException assuming that the module data has already been locked.
Definition: Module.h:610
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...
Definition: Module.h:719
const std::unique_ptr< ModuleDataType > ModuleData
Module data belonging to this ModuleBase instance.
Definition: Module.h:743
virtual ~ModuleBase()=0
Definition: Module.cpp:198
void ResetImpl(dispatch_tag< RunnableObject >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
Definition: Module.cpp:309
virtual void OnResumeChild(ModuleInstance &Instance) const
This handler gets called just after the module resumed from a paused state. Override OnResumeChild() ...
Definition: Module.h:672
void UpdateParamsFromWindowStates()
UpdateParamsFromWindowStates() only calls UpdateParamsFromWindowStatesChild(). Override UpdateParamsF...
Definition: Module.h:534
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...
Definition: Module.h:780
virtual std::string GetCategory() const override
Returns the category of this Object type.
Definition: Module.h:479
virtual void OnExit(ModuleInstance *Instance) const
This event is triggered right before the module thread terminates (not due to an exception,...
Definition: Module.h:728
void EnqueueEvent(ModuleDataBase::EventPtrType &&Event) const
Enqueues Event at the module event queue's back. Takes ownership of the event. Notifies the module ow...
Definition: Module.cpp:212
void RemoveRegisteredEvent(EventListenersBase &EventListeners)
Removes a manager of event listeners from RegisteredEvents if it was added before....
Definition: Module.cpp:253
void HandleEvent(ModuleInstance &Instance)
Executes and removes the next pending event from the module's event queue.
Definition: Module.cpp:222
ModuleBase(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs a ModuleBase instance.
Definition: Module.cpp:189
virtual void RestoreWindowStatesFromParamsChild()
RestoreWindowStatesFromParams() only calls RestoreWindowStatesFromParamsChild(). Override RestoreWind...
Definition: Module.h:675
Util::SynchronizedPointer< const ModuleDataType > ModuleDataTypeSyncPtrConstType
Alias for the return type of ModuleBase::GetModuleData() const. Data class instances wrapped into Uti...
Definition: Module.h:462
void OnResume(ModuleInstance &Instance)
This handler gets called just after the module resumed from a paused state. Override OnResumeChild() ...
Definition: Module.cpp:278
ModuleThreadOnlyType ModuleThreadOnly
Allow exclusive access to some of ModuleBase's private methods to the module thread ModuleThreadMain(...
Definition: Module.h:515
Util::SynchronizedPointer< ModuleDataType > ModuleDataTypeSyncPtrType
Alias for the return type of ModuleBase::GetModuleData(). Data class instances wrapped into Util::Syn...
Definition: Module.h:456
EventListenersOnlyType EventListenersOnly
Allow exclusive access to some of ModuleBase's private methods to any TypedEventListeners class.
Definition: Module.h:516
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().
Definition: Module.cpp:350
std::vector< EventListenersBase * > RegisteredEvents
Holds a list of pointers to managers of event listeners of the events this module has registered/subs...
Definition: Module.h:750
void OnError(ModuleInstance &Instance)
This handler gets called just before the module thread terminates due to an exception....
Definition: Module.cpp:285
constexpr static auto Category() noexcept
Every derived class has to redefine this function.
Definition: Module.h:468
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 if it was not already added before....
Definition: Module.cpp:242
virtual void UpdateParamsFromWindowStatesChild()
UpdateParamsFromWindowStates() only calls UpdateParamsFromWindowStatesChild(). Override UpdateParamsF...
Definition: Module.h:676
std::exception_ptr GetExceptionChild([[maybe_unused]] const std::chrono::milliseconds Timeout) const override final
Definition: Module.cpp:358
static constexpr auto GetModuleDataTimeoutDefault
Determines the default timeout for GetModuleData() to lock the mutex synchronizing the module's data ...
Definition: Module.h:513
bool IsReadyChild() const override final
Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) a...
Definition: Module.cpp:368
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...
Definition: Module.h:671
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...
Definition: Module.cpp:217
virtual bool TreatModuleExceptionsAsWarnings() const
Determines whether this module should be terminated if an exception leaves the module's main loop or ...
Definition: Module.h:498
void RestoreWindowStatesFromParams()
RestoreWindowStatesFromParams() only calls RestoreWindowStatesFromParamsChild(). Override RestoreWind...
Definition: Module.h:527
virtual std::chrono::milliseconds GetMainLoopDelay() const
Specifies in which time intervals the module's event queue runs to handle pending events.
Definition: Module.h:506
Util::DynExpErrorCodes::DynExpErrorCodes ExecModuleMainLoop(ModuleInstance &Instance)
Runs ModuleMainLoop().
Definition: Module.cpp:264
virtual bool HasUI() const noexcept
Determines whether this module possesses a user interface (UI) which is shown in a window dedicated t...
Definition: Module.h:490
Configurator class for ModuleBase.
Definition: Module.h:374
virtual ~ModuleConfiguratorBase()=0
Definition: Module.cpp:185
Allow exclusive access to some of ModuleDataBase's private methods to ModuleBase.
Definition: Module.h:196
ModuleDataBase & Parent
Owning ModuleDataBase instance.
Definition: Module.h:210
auto & GetNewEventNotifier() noexcept
Getter for NewEventNotifier.
Definition: Module.h:208
void Reset()
Resets the ModuleDataBase's instance and calls ResetImpl(dispatch_tag<ModuleDataBase>) subsequently.
Definition: Module.h:206
constexpr ModuleBaseOnlyType(ModuleDataBase &Parent) noexcept
Construcs an instance - one for each ModuleDataBase instance.
Definition: Module.h:204
Allow exclusive access to some of ModuleDataBase's private methods to the module thread ModuleThreadM...
Definition: Module.h:218
auto & GetNewEventNotifier() noexcept
Getter for NewEventNotifier.
Definition: Module.h:228
ModuleDataBase & Parent
Owning ModuleDataBase instance.
Definition: Module.h:231
constexpr ModuleThreadOnlyType(ModuleDataBase &Parent) noexcept
Construcs an instance - one for each ModuleDataBase instance.
Definition: Module.h:226
void SetException(std::exception_ptr ModuleException) noexcept
Setter for ModuleDataBase::ModuleException.
Definition: Module.h:229
friend int ModuleThreadMain(ModuleInstance, ModuleBase *const)
Modules run in their own thread. This is the module thread's main function.
Definition: Module.cpp:10
Data structure to contain data which is synchronized in between different threads....
Definition: Module.h:171
ModuleThreadOnlyType ModuleThreadOnly
Allow exclusive access to some of ModuleDataBase's private methods to the module thread ModuleThreadM...
Definition: Module.h:286
virtual ~ModuleDataBase()
Definition: Module.h:236
std::exception_ptr ModuleException
Used to transfer exceptions from the module thread to the main (user interface) thread....
Definition: Module.h:330
Util::OneToOneNotifier NewEventNotifier
Notifies the thread of the module which owns the respective ModuleDataBase's instance when an event h...
Definition: Module.h:323
std::queue< EventPtrType > EventQueueType
A module's event queue is a FIFO queue owning the enqueued events.
Definition: Module.h:181
const auto & GetEventFront() const noexcept
Returns a pointer to the event in the front of the module's event queue without transferring ownershi...
Definition: Module.h:264
std::unique_ptr< EventBase > EventPtrType
Pointer owning an event.
Definition: Module.h:176
Util::OneToOneNotifier & GetNewEventNotifier() noexcept
Getter for NewEventNotifier.
Definition: Module.h:293
auto & GetEventFront() noexcept
Returns a pointer to the event in the front of the module's event queue without transferring ownershi...
Definition: Module.h:270
void Reset()
Resets the ModuleDataBase's instance and calls ResetImpl(dispatch_tag<ModuleDataBase>) subsequently.
Definition: Module.cpp:173
size_t GetNumEnqueuedEvents() const noexcept
Getter for the module event queue's length.
Definition: Module.h:276
auto GetException() const noexcept
Getter for ModuleException.
Definition: Module.h:283
void EnqueueEvent(EventPtrType &&Event)
Enqueues Event at the module event queue's back. Takes ownership of the event. Notifies the module ow...
Definition: Module.cpp:153
EventQueueType EventQueue
FIFO event queue of the module which owns the respective ModuleDataBase's instance.
Definition: Module.h:316
virtual void ResetImpl(dispatch_tag< ModuleDataBase >)
Refer to DynExp::ModuleDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of ...
Definition: Module.h:310
EventPtrType PopEvent()
Removes one event from the event queue's front and returns the event. Ownership of the event is trans...
Definition: Module.cpp:162
ModuleBaseOnlyType ModuleBaseOnly
Allow exclusive access to some of ModuleDataBase's private methods to ModuleBase.
Definition: Module.h:285
Refer to ParamsBase::dispatch_tag.
Definition: Module.h:189
Defines data for a thread belonging to a ModuleBase instance. Refer to RunnableInstance.
Definition: Module.h:793
void Exit() noexcept
Might be called from anywhere where this ModuleInstance instance is accessible to make the associated...
Definition: Module.h:813
const ModuleBase::ModuleDataGetterType ModuleDataGetter
Getter for module's data. Refer to ModuleBase::ModuleDataGetterType.
Definition: Module.h:825
bool IsExiting() const noexcept
Getter for ShouldExit.
Definition: Module.h:820
ModuleInstance(ModuleBase &Owner, std::promise< void > &&ThreadExitedPromise, const ModuleBase::ModuleDataGetterType ModuleDataGetter)
Constructs a non-empty RunnableInstance instance.
Definition: Module.cpp:389
bool ShouldExit
Indicates whether the module thread using this ModuleInstance instance should terminate.
Definition: Module.h:832
Parameter class for ModuleBase.
Definition: Module.h:337
std::unique_ptr< ModuleDataBase > ModuleData
Just used temporarily during the construction of a module. Refer to MakeModule() and ModuleBase::Modu...
Definition: Module.h:365
DummyParam Dummy
Dummy parameter which is to be owned once by parameter classes that do not contain any other paramete...
Definition: Module.h:367
bool ConfigureUsageTypeChild() const noexcept override final
Determines whether the Usage parameter should be configurable in the settings dialog....
Definition: Module.h:359
void ConfigureParamsImpl(dispatch_tag< RunnableObjectParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: Module.h:355
friend ModulePtrType MakeModule(const std::thread::id, ParamsBasePtrType &&)
Factory function to generate a module of a specific type.
Definition: Module.h:44
virtual void ConfigureParamsImpl(dispatch_tag< ModuleParamsBase >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: Module.h:356
virtual ~ModuleParamsBase()=0
Definition: Module.cpp:181
ModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a ModuleBase instance.
Definition: Module.h:348
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...
Definition: Module.h:352
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
Definition: Object.h:2302
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Definition: Object.h:2303
Refer to ParamsBase::dispatch_tag.
Definition: Object.h:2018
Dummy parameter which is to be owned once by parameter classes that do not contain any other paramete...
Definition: Object.h:522
Abstract base class for object parameter classes. Each class derived from class Object must be accomp...
Definition: Object.h:326
const ItemIDType ID
ID of the Object this parameter class instance belongs to.
Definition: Object.h:1779
const DynExpCore & Core
Reference to DynExp's core.
Definition: Object.h:1780
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Definition: Object.h:349
Base class for modules with a Qt-based user interface. Derive from this class to implement modules wi...
Definition: Module.h:1344
WidgetType * GetWidget() const
Getter for Widget.
Definition: Module.h:1535
QModuleWidget * Widget
User interface widget belonging to the module.
Definition: Module.h:1491
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....
Definition: Module.h:1500
bool HasUI() const noexcept override final
Determines whether this module possesses a user interface (UI) which is shown in a window dedicated t...
Definition: Module.h:1358
QMdiArea * MdiArea
Pointer to DynExpManager's QMdiArea.
Definition: Module.h:1496
std::unique_ptr< QModuleDockWidget > DockWidget
Frame for Widget when the module window is undocked from MdiArea.
Definition: Module.h:1493
std::unique_ptr< QMdiSubWindow > MdiSubWindow
Frame for Widget when the module window is docked to MdiArea.
Definition: Module.h:1492
std::unique_ptr< QAction > ModuleWindowFocusAction
Qt action to push module window into focus. When triggered, QModuleWidget::OnFocusWindow() in invoked...
Definition: Module.h:1494
Configurator class for QModuleBase.
Definition: Module.h:1330
Data class for QModuleBase.
Definition: Module.h:1220
virtual ~QModuleDataBase()=default
virtual void ResetImpl(dispatch_tag< QModuleDataBase >)
Definition: Module.h:1227
Provides a frame for QModuleWidget windows, which are undocked from the DynExpManager's QMdiArea.
Definition: Module.h:1179
QModuleBase & Owner
Module owning this user interface window.
Definition: Module.h:1213
Parameter class for QModuleBase.
Definition: Module.h:1306
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...
Definition: Module.h:1317
virtual void ConfigureParamsImpl(dispatch_tag< QModuleParamsBase >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: Module.h:1323
WindowStyleParamsExtension WindowStyleParams
Bundles several parameters to describe a UI window's style. Use in parameter classes.
Definition: Module.h:1319
void ConfigureParamsImpl(dispatch_tag< ModuleParamsBase >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: Module.h:1322
QModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a QModuleBase instance.
Definition: Module.h:1312
Window class for Qt-based user interfaces belonging to DynExp modules. User interface Qt window class...
Definition: Module.h:1079
void OnDockWindow()
Qt slot called when DockWindowShortcut is activated, calls QModuleBase::DockUndockWindow().
Definition: Module.cpp:462
virtual bool AllowResize() const noexcept
Indicates the resizing behavior of the user interface window. Override to adjust.
Definition: Module.h:1121
friend class QModuleBase
Definition: Module.h:1082
Qt::WindowFlags GetQtWindowFlags() const noexcept
Depending on thr return value of AllowResize(), returns either the return value of GetQtWindowFlagsRe...
Definition: Module.cpp:426
void OnFocusWindow()
Qt slot called when QModuleBase::ModuleWindowFocusAction is triggered, calls QModuleBase::SetFocus().
Definition: Module.cpp:467
virtual void closeEvent(QCloseEvent *Event) override
Qt event indicating that the module window is closed. Asks the user whether to terminate the module....
Definition: Module.cpp:446
QModuleBase & Owner
Module owning this user interface window (reference, because it should never change nor be nullptr).
Definition: Module.h:1162
constexpr static Qt::WindowFlags GetQtWindowFlagsResizable()
Default Qt window flags for resizable module windows.
Definition: Module.cpp:405
QModuleWidget(QModuleBase &Owner, QWidget *Parent=nullptr)
Constructs a QModuleWidget instance.
Definition: Module.cpp:417
void OnFocusMainWindow()
Qt slot called when FocusMainWindowShortcut is activated, calls QModuleBase::FocusMainWindow().
Definition: Module.cpp:472
constexpr static Qt::WindowFlags GetQtWindowFlagsNonResizable()
Default Qt window flags for non-resizable module windows.
Definition: Module.cpp:411
const auto & GetOwner() const noexcept
Getter for the owning module.
Definition: Module.h:1111
QShortcut * FocusMainWindowShortcut
Shortcut (Ctrl + 0) to activate/focus DynExp's main window.
Definition: Module.h:1166
std::string GetDataSaveDirectory() const
Recalls a path where modules might save recorded data to. Used by Util::PromptSaveFilePathModule() to...
Definition: Module.cpp:431
QShortcut * DockWindowShortcut
Shortcut (Ctrl + D) to dock/undock a module window to/from DynExp's main window.
Definition: Module.h:1165
void SetDataSaveDirectory(std::string_view Directory) const
Sets a path where modules might save recorded data to. Used by Util::PromptSaveFilePathModule() to st...
Definition: Module.cpp:436
void EnableDockWindowShortcut(bool Enable) noexcept
Enables/disables DockWindowShortcut.
Definition: Module.cpp:441
DynExpManager * DynExpMgr
DynExp's main window (pointer, because it is set later by QModuleBase::InitUI()).
Definition: Module.h:1163
Defines data for a thread belonging to a RunnableObject instance. This data is only accessed by the R...
Definition: Object.h:3505
const RunnableObject & Owner
RunnableObject instance which operates on this RunnableInstance (by its thread). The RunnableObject i...
Definition: Object.h:3705
std::promise< void > ThreadExitedPromise
Signals the RunnableObject instance owning the thread that its thread has terminated....
Definition: Object.h:3712
Configurator class for RunnableObject.
Definition: Object.h:2412
Parameter class for RunnableObject.
Definition: Object.h:2349
Defines an Object which possesses a thread it runs in. The RunnableObject can be started and stopped ...
Definition: Object.h:2426
void SetReasonWhyPaused(std::string Description)
Sets the reason why this RunnableObject instance has been paused.
Definition: Object.h:2599
Typed managers of event listeners class whose instances are owned by classes derived from InterModule...
Definition: Module.h:891
void DeregisterUnsafe(const ModuleBase &Listener)
This function is the version of Deregister() which is not thread-safe (assuming EventListenersBase's ...
Definition: Module.h:963
virtual ~TypedEventListeners()=default
std::unordered_map< const ModuleBase *, EventFunctionType > Listeners
Each module can register to each inter-module event with one event function of type EventFunctionType...
Definition: Module.h:990
void RegisterUnsafe(const ModuleBase &Listener, CallableT EventFunc)
This function is the version of Register() which is not thread-safe (assuming EventListenersBase's mu...
Definition: Module.h:949
EventFunctionType GetFunc(const ModuleBase &Listener, const std::chrono::milliseconds Timeout=DefaultTimeout) const
Looks up the event function the module Listener has registered/subscribed with.
Definition: Module.h:933
EventFunctionType GetFuncUnsafe(const ModuleBase &Listener) const
This function is the version of GetFunc() which is not thread-safe (assuming EventListenersBase's mut...
Definition: Module.h:980
virtual void Deregister(const ModuleBase &Listener, const std::chrono::milliseconds Timeout=std::chrono::milliseconds(0)) override
Deregisters/unsubscribes module Listener from the event. Indirectly calls ModuleBase::RemoveRegistere...
Definition: Module.h:920
void Register(const ModuleBase &Listener, CallableT EventFunc, const std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))
Registers/Subscribes module Listener to the event with the event function EventFunc....
Definition: Module.h:914
std::function< void(ModuleInstance *, EventFuncArgs...)> EventFunctionType
Type of event functions to be invoked when the event is triggered. The first ModuleInstance argument ...
Definition: Module.h:899
Bundles several parameters to describe a UI window's style. Use in parameter classes.
Definition: Module.h:1234
WindowStyleParamsExtension(ParamsBase &Owner, const std::string &Prefix="")
Constructs a WindowStyleParamsExtension instance.
Definition: Module.h:1272
WindowDockingStateType
Indicates the window docking state.
Definition: Module.h:1256
ParamsBase::Param< unsigned int > WindowWidth
Window width.
Definition: Module.h:1296
ParamsBase::Param< int > WindowPosY
Window y coordinate.
Definition: Module.h:1295
WindowStateType
Indicates the window state for showing it.
Definition: Module.h:1239
ParamsBase::Param< WindowDockingStateType > WindowDockingState
Window docking state.
Definition: Module.h:1299
ParamsBase::Param< int > WindowPosX
Window x coordinate.
Definition: Module.h:1294
ParamsBase::Param< WindowStateType > WindowState
Window show state.
Definition: Module.h:1298
ParamsBase::Param< unsigned int > WindowHeight
Window height.
Definition: Module.h:1297
Wraps a member function of some object and stores its default arguments. Moving from CallableMemberWr...
Definition: Util.h:448
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.
Definition: Util.cpp:309
DynExp exceptions are derived from this class. It contains basic information about the cause of the e...
Definition: Exception.h:51
Interface to allow synchronizing the access to derived classes between different threads by providing...
Definition: Util.h:56
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.
Definition: Util.cpp:8
static constexpr std::chrono::milliseconds DefaultTimeout
Duration which is used as a default timeout within all methods of this class if no different duration...
Definition: Util.h:62
Interface to allow synchronizing the access to derived classes between different threads by making th...
Definition: Util.h:93
An invalid argument like a null pointer has been passed to a function.
Definition: Exception.h:137
An operation cannot be performed currently since the related object is in an invalid state like an er...
Definition: Exception.h:150
Helper class to communicate flags between different threads based on a condition variable and a mutex...
Definition: Util.h:265
Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads....
Definition: Util.h:170
SignalType
Type specifying different signal coordinates a lock-in amplifier can record. Not a strongly-typed enu...
DynExp's module namespace contains the implementation of DynExp modules which extend DynExp's core fu...
constexpr auto Module
DynExp's main namespace contains the implementation of DynExp including classes to manage resources (...
ConfiguratorBasePtrType MakeModuleConfig()
Factory function to generate a configurator for a specific module type.
Definition: Module.h:31
ModulePtrType MakeModule(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Factory function to generate a module of a specific type.
Definition: Module.h:44
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition: Object.h:1807
size_t ItemIDType
ID type of objects/items managed by DynExp.
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...
Definition: Module.h:851
auto MakeEvent(ReceiverType *Receiver, typename DefaultEvent< ReceiverType, std::tuple< std::remove_reference_t< ArgsTs >... >>::EventFuncPtrType EventFuncPtr, ArgsTs &&...Args)
Creates an event of type DefaultEvent.
Definition: Module.h:763
std::unique_ptr< ModuleBase > ModulePtrType
Pointer type to store a module (DynExp::ModuleBase) with.
Definition: Module.h:23
int ModuleThreadMain(ModuleInstance Instance, ModuleBase *const Module)
Modules run in their own thread. This is the module thread's main function.
Definition: Module.cpp:10
std::shared_ptr< ConfiguratorBase > ConfiguratorBasePtrType
Alias for a pointer to the configurator base class ConfiguratorBase.
Definition: Object.h:1959
DynExpErrorCodes
DynExp's error codes
Definition: Exception.h:22
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.
Definition: Util.h:392
EventLogger & EventLog()
This function holds a static EventLogger instance and returns a reference to it. DynExp uses only one...
Definition: Util.cpp:509
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.
Definition: Util.h:374
Accumulates include statements to provide a precompiled header.
Helper struct to allow accessing elements within ArgTupleType.
Definition: Module.h:103
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...
Definition: Module.h:111