|
| 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. More...
|
|
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. More...
|
|
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. More...
|
|
template<typename T > |
void | detachEvent (T &eventOrigin) noexcept |
| Detaches an event. Hereby, the event is defined as a class T, the eventOrigin. More...
|
|
uint64_t | size () const noexcept |
| Returns the size of the Listener. More...
|
|
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.
template<uint64_t Capacity>
template<typename T , typename EventType , typename ContextDataType , typename = std::enable_if_t<std::is_enum<EventType>::value>>
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.
- Note
- This method can be called from any thread concurrently without any restrictions! Furthermore, attachEvent does not take ownership of callback in the underlying eventCallback or the optional contextData. The user has to ensure that both will live as long as the event is attached.
- Template Parameters
-
in] T type of the class which will signal the event
- Parameters
-
[in] | eventOrigin | the object which will signal the event (the origin) |
[in] | eventType | enum required to specify the type of event inside of eventOrigin |
[in] | eventCallback | callback which will be executed concurrently when the event occurs. has to be created with iox::popo::createNotificationCallback |
- Returns
- If an error occurs the enum packed inside an expected which describes the error.
template<uint64_t Capacity>
template<typename T , typename ContextDataType >
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.
- Note
- This method can be called from any thread concurrently without any restrictions! Furthermore, attachEvent does not take ownership of callback in the underlying eventCallback or the optional contextData. The user has to ensure that both will live as long as the event is attached.
- Template Parameters
-
in] T type of the class which will signal the event
- Parameters
-
[in] | eventOrigin | the object which will signal the event (the origin) |
[in] | eventCallback | callback which will be executed concurrently when the event occurs. Has to be created with iox::popo::createNotificationCallback |
- Returns
- If an error occurs the enum packed inside an expected which describes the error.
template<uint64_t Capacity>
template<typename T , typename EventType , typename = std::enable_if_t<std::is_enum<EventType>::value>>
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.
- Note
- This method can be called from any thread concurrently without any restrictions!
- Template Parameters
-
in] T type of the class which will signal the event
- Parameters
-
[in] | eventOrigin | the object which will signal the event (the origin) |
[in] | eventType | enum required to specify the type of event inside of eventOrigin |