|
| ListenerImpl (const ListenerImpl &)=delete |
|
| ListenerImpl (ListenerImpl &&)=delete |
|
ListenerImpl & | operator= (const ListenerImpl &)=delete |
|
ListenerImpl & | operator= (ListenerImpl &&)=delete |
|
template<typename T , typename EventType , typename ContextDataType , typename = std::enable_if_t<std::is_enum<EventType>::value>> |
cxx::expected< ListenerError > | attachEvent (T &eventOrigin, const EventType eventType, const NotificationCallback< T, ContextDataType > &eventCallback) noexcept |
| Attaches an event. Hereby the event is defined as a class T, the eventOrigin, an enum which further defines the event inside the class and the corresponding callback which will be called when the event occurs.
|
|
template<typename T , typename ContextDataType > |
cxx::expected< ListenerError > | attachEvent (T &eventOrigin, const NotificationCallback< T, ContextDataType > &eventCallback) noexcept |
| Attaches an event. Hereby the event is defined as a class T, the eventOrigin and the corresponding callback which will be called when the event occurs.
|
|
template<typename T , typename EventType , typename = std::enable_if_t<std::is_enum<EventType>::value>> |
void | detachEvent (T &eventOrigin, const EventType eventType) noexcept |
| Detaches an event. Hereby, the event is defined as a class T, the eventOrigin and the eventType with further specifies the event inside of eventOrigin.
|
|
template<typename T > |
void | detachEvent (T &eventOrigin) noexcept |
| Detaches an event. Hereby, the event is defined as a class T, the eventOrigin.
|
|
uint64_t | size () const noexcept |
| Returns the size of the Listener.
|
|
template<
uint64_t Capacity>
class iox::popo::ListenerImpl< Capacity >
The Listener is a class which reacts to registered events by executing a corresponding callback concurrently. This is achieved via an encapsulated thread inside this class.
- Note
- The Listener is threadsafe and can be used without any restrictions concurrently.
- Attention
- Calling detachEvent for the same event from multiple threads is supported but can cause a race condition if you attach the same event again concurrently from another thread. Example:
- One calls detachEvent [1] from thread A, B and C
- thread B wins and detaches event [1]
- A new thread D spawns and would like to attach event [1] again while thread A and C are still waiting to detach [1].
- Thread A wins but cannot detach event [1] since it is not attached.
- Thread D wins and attaches event [1].
- Finally thread C can continue and detaches event [1] again.
If thread D is executed last then the event is attached. So depending on the operating system defined execution order the event is either attached or detached.
Best practice: Detach a specific event only from one specific thread and not from multiple contexts.