DynExp
Highly flexible laboratory automation for dynamically changing experiments.
DynExp::TypedEventListeners< EventFuncArgs > Class Template Reference

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...

+ Inheritance diagram for DynExp::TypedEventListeners< EventFuncArgs >:

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
 
INonCopyableoperator= (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 *, EventFunctionTypeListeners
 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
 

Detailed Description

template<typename... EventFuncArgs>
class DynExp::TypedEventListeners< EventFuncArgs >

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.

Template Parameters
...EventFuncArgsTypes of the arguments to be passed to event functions registered/subscribed to DerivedEvent.

Definition at line 890 of file Module.h.

Member Typedef Documentation

◆ EventFunctionType

template<typename... EventFuncArgs>
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.

Definition at line 899 of file Module.h.

Constructor & Destructor Documentation

◆ TypedEventListeners()

template<typename... EventFuncArgs>
DynExp::TypedEventListeners< EventFuncArgs >::TypedEventListeners ( )
default

◆ ~TypedEventListeners()

template<typename... EventFuncArgs>
virtual DynExp::TypedEventListeners< EventFuncArgs >::~TypedEventListeners ( )
virtualdefault

Member Function Documentation

◆ Deregister()

template<typename... EventFuncArgs>
virtual void DynExp::TypedEventListeners< EventFuncArgs >::Deregister ( const ModuleBase Listener,
const std::chrono::milliseconds  Timeout = std::chrono::milliseconds(0) 
)
inlineoverridevirtual

Deregisters/unsubscribes module Listener from the event. Indirectly calls ModuleBase::RemoveRegisteredEvent().

Parameters
ListenerModule to deregister/unsubscribe.
TimeoutTime to wait for locking the mutex of this EventListenersBase instance.

Implements DynExp::EventListenersBase.

Definition at line 920 of file Module.h.

◆ DeregisterUnsafe()

template<typename... EventFuncArgs>
void DynExp::TypedEventListeners< EventFuncArgs >::DeregisterUnsafe ( const ModuleBase Listener)
inlineprivate

This function is the version of Deregister() which is not thread-safe (assuming EventListenersBase's mutex has already been locked before.

Parameters
ListenerModule to deregister/unsubscribe.

Definition at line 963 of file Module.h.

◆ GetFunc()

template<typename... EventFuncArgs>
EventFunctionType DynExp::TypedEventListeners< EventFuncArgs >::GetFunc ( const ModuleBase Listener,
const std::chrono::milliseconds  Timeout = DefaultTimeout 
) const
inline

Looks up the event function the module Listener has registered/subscribed with.

Parameters
ListenerModule to look up the registered event function for
TimeoutTime to wait for locking the mutex of this EventListenersBase instance.
Returns
Returns the registered event function or nullptr if Listener has not registered/subscribed for this event.

Definition at line 933 of file Module.h.

◆ GetFuncUnsafe()

template<typename... EventFuncArgs>
EventFunctionType DynExp::TypedEventListeners< EventFuncArgs >::GetFuncUnsafe ( const ModuleBase Listener) const
inlineprivate

This function is the version of GetFunc() which is not thread-safe (assuming EventListenersBase's mutex has already been locked before.

Parameters
ListenerModule to look up the registered event function for
Returns
Returns the registered event function or nullptr if Listener has not registered/subscribed for this event.

Definition at line 980 of file Module.h.

◆ Register()

template<typename... EventFuncArgs>
template<typename CallableT >
void DynExp::TypedEventListeners< EventFuncArgs >::Register ( const ModuleBase Listener,
CallableT  EventFunc,
const std::chrono::milliseconds  Timeout = std::chrono::milliseconds(0) 
)
inline

Registers/Subscribes module Listener to the event with the event function EventFunc. Indirectly calls ModuleBase::AddRegisteredEvent().

Template Parameters
CallableTType of the event function (member function of Listener's derived type) to invoke for Listener when the event is triggered.
Parameters
ListenerModule to register/subscribe.
EventFuncEvent function to invoke on module Listener when the event is triggered.
TimeoutTime to wait for locking the mutex of this EventListenersBase instance.

Definition at line 914 of file Module.h.

◆ RegisterUnsafe()

template<typename... EventFuncArgs>
template<typename CallableT >
void DynExp::TypedEventListeners< EventFuncArgs >::RegisterUnsafe ( const ModuleBase Listener,
CallableT  EventFunc 
)
inlineprivate

This function is the version of Register() which is not thread-safe (assuming EventListenersBase's mutex has already been locked before.

Template Parameters
CallableTType of the event function (member function of Listener's derived type) to invoke for Listener when the event is triggered.
Parameters
ListenerModule to register/subscribe.
EventFuncEvent function to invoke on module Listener when the event is triggered.

Definition at line 949 of file Module.h.

Member Data Documentation

◆ Listeners

template<typename... EventFuncArgs>
std::unordered_map<const ModuleBase*, EventFunctionType> DynExp::TypedEventListeners< EventFuncArgs >::Listeners
private

Each module can register to each inter-module event with one event function of type EventFunctionType. This mapping is stored here.

Definition at line 990 of file Module.h.


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