DynExp
Highly flexible laboratory automation for dynamically changing experiments.
|
Typed managers of event listeners class whose instances are owned by classes derived from InterModuleEvent
. The class maps modules registering/subscribing to inter-module events to the respective event functions which are invoked when the related event occurs.
More...
Public Types | |
using | EventFunctionType = std::function< void(ModuleInstance *, EventFuncArgs...)> |
Type of event functions to be invoked when the event is triggered. The first ModuleInstance argument is a pointer to the module data of the respective module the event function is invoked on. The further parameters are determined by the class InterModuleEvent owning this TypedEventListeners . More... | |
Public Member Functions | |
TypedEventListeners ()=default | |
virtual | ~TypedEventListeners ()=default |
template<typename CallableT > | |
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 . Indirectly calls ModuleBase::AddRegisteredEvent(). More... | |
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::RemoveRegisteredEvent(). More... | |
EventFunctionType | GetFunc (const ModuleBase &Listener, const std::chrono::milliseconds Timeout=DefaultTimeout) const |
Looks up the event function the module Listener has registered/subscribed with. More... | |
Public Member Functions inherited from Util::INonCopyable | |
INonCopyable (const INonCopyable &)=delete | |
INonCopyable & | operator= (const INonCopyable &)=delete |
Private Member Functions | |
template<typename CallableT > | |
void | RegisterUnsafe (const ModuleBase &Listener, CallableT EventFunc) |
This function is the version of Register() which is not thread-safe (assuming EventListenersBase's mutex has already been locked before. More... | |
void | DeregisterUnsafe (const ModuleBase &Listener) |
This function is the version of Deregister() which is not thread-safe (assuming EventListenersBase's mutex has already been locked before. More... | |
EventFunctionType | GetFuncUnsafe (const ModuleBase &Listener) const |
This function is the version of GetFunc() which is not thread-safe (assuming EventListenersBase's mutex has already been locked before. More... | |
Private Attributes | |
std::unordered_map< const ModuleBase *, EventFunctionType > | Listeners |
Each module can register to each inter-module event with one event function of type EventFunctionType . This mapping is stored here. More... | |
Additional Inherited Members | |
Static Public Attributes inherited from Util::ILockable | |
static constexpr std::chrono::milliseconds | DefaultTimeout = std::chrono::milliseconds(10) |
Duration which is used as a default timeout within all methods of this class if no different duration is passed to them. More... | |
Protected Types inherited from Util::ILockable | |
using | MutexType = std::timed_mutex |
using | LockType = std::unique_lock< MutexType > |
Protected Member Functions inherited from DynExp::EventListenersBase | |
EventListenersBase ()=default | |
virtual | ~EventListenersBase () |
Protected Member Functions inherited from Util::ILockable | |
ILockable ()=default | |
~ILockable ()=default | |
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. More... | |
Protected Member Functions inherited from Util::INonCopyable | |
constexpr | INonCopyable ()=default |
~INonCopyable ()=default | |
Typed managers of event listeners class whose instances are owned by classes derived from InterModuleEvent
. The class maps modules registering/subscribing to inter-module events to the respective event functions which are invoked when the related event occurs.
...EventFuncArgs | Types of the arguments to be passed to event functions registered/subscribed to DerivedEvent . |
using DynExp::TypedEventListeners< EventFuncArgs >::EventFunctionType = std::function<void(ModuleInstance*, EventFuncArgs...)> |
Type of event functions to be invoked when the event is triggered. The first ModuleInstance
argument is a pointer to the module data of the respective module the event function is invoked on. The further parameters are determined by the class InterModuleEvent
owning this TypedEventListeners
.
|
default |
|
virtualdefault |
|
inlineoverridevirtual |
Deregisters/unsubscribes module Listener
from the event. Indirectly calls ModuleBase::RemoveRegisteredEvent().
Listener | Module to deregister/unsubscribe. |
Timeout | Time to wait for locking the mutex of this EventListenersBase instance. |
Implements DynExp::EventListenersBase.
|
inlineprivate |
This function is the version of Deregister()
which is not thread-safe (assuming EventListenersBase's
mutex has already been locked before.
Listener | Module to deregister/unsubscribe. |
|
inline |
Looks up the event function the module Listener
has registered/subscribed with.
Listener | Module to look up the registered event function for |
Timeout | Time to wait for locking the mutex of this EventListenersBase instance. |
nullptr
if Listener
has not registered/subscribed for this event.
|
inlineprivate |
This function is the version of GetFunc()
which is not thread-safe (assuming EventListenersBase's
mutex has already been locked before.
Listener | Module to look up the registered event function for |
nullptr
if Listener
has not registered/subscribed for this event.
|
inline |
Registers/Subscribes module Listener
to the event with the event function EventFunc
. Indirectly calls ModuleBase::AddRegisteredEvent().
CallableT | Type of the event function (member function of Listener's derived type) to invoke for Listener when the event is triggered. |
Listener | Module to register/subscribe. |
EventFunc | Event function to invoke on module Listener when the event is triggered. |
Timeout | Time to wait for locking the mutex of this EventListenersBase instance. |
|
inlineprivate |
This function is the version of Register()
which is not thread-safe (assuming EventListenersBase's
mutex has already been locked before.
CallableT | Type of the event function (member function of Listener's derived type) to invoke for Listener when the event is triggered. |
Listener | Module to register/subscribe. |
EventFunc | Event function to invoke on module Listener when the event is triggered. |
|
private |