Skip to content

iox::popo::Listener🔗

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

#include <listener.hpp>

Public Functions🔗

Name
Listener()
Listener(const Listener & )
Listener(Listener && )
~Listener()
Listener & operator=(const Listener & )
Listener & operator=(Listener && )
template \<typename T ,typename EventType ,typename ContextDataType ,typename =std::enable_if_t::value>>
cxx::expected< ListenerError >
attachEvent(T & eventOrigin, const EventType eventType, const NotificationCallback< T, ContextDataType > & eventCallback)
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)
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::value>>
void
detachEvent(T & eventOrigin, const EventType eventType)
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)
Detaches an event. Hereby, the event is defined as a class T, the eventOrigin.
uint64_t size() const
Returns the size of the Listener.
template \<typename T ,typename UserType >
cxx::expected< ListenerError >
attachEvent(T & eventOrigin, const NotificationCallback< T, UserType > & eventCallback)
template \<typename T ,typename EventType ,typename UserType ,typename >
cxx::expected< ListenerError >
attachEvent(T & eventOrigin, const EventType eventType, const NotificationCallback< T, UserType > & eventCallback)
constexpr uint64_t capacity()
Returns the capacity of the Listener.

Protected Functions🔗

Name
Listener(ConditionVariableData & conditionVariableData)

Detailed Description🔗

class iox::popo::Listener;

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:

  1. One calls detachEvent [1] from thread A, B and C
  2. thread B wins and detaches event [1]
  3. A new thread D spawns and would like to attach event [1] again while thread A and C are still waiting to detach [1].
  4. Thread A wins but cannot detach event [1] since it is not attached.
  5. Thread D wins and attaches event [1].
  6. 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.

Public Functions Documentation🔗

function Listener🔗

Listener()

function Listener🔗

Listener(
    const Listener & 
)

function Listener🔗

Listener(
    Listener && 
)

function ~Listener🔗

~Listener()

function operator=🔗

Listener & operator=(
    const Listener & 
)

function operator=🔗

Listener & operator=(
    Listener && 
)

function attachEvent🔗

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
)

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 Parameters:


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.

function attachEvent🔗

template <typename T ,
typename ContextDataType >
cxx::expected< ListenerError > attachEvent(
    T & eventOrigin,
    const NotificationCallback< T, ContextDataType > & eventCallback
)

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 Parameters:


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.

function detachEvent🔗

template <typename T ,
typename EventType ,
typename  =std::enable_if_t<std::is_enum<EventType>::value>>
inline void detachEvent(
    T & eventOrigin,
    const EventType eventType
)

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 Parameters:


Note: This method can be called from any thread concurrently without any restrictions!

function detachEvent🔗

template <typename T >
inline void detachEvent(
    T & eventOrigin
)

Detaches an event. Hereby, the event is defined as a class T, the eventOrigin.

Template Parameters:


Note: This method can be called from any thread concurrently without any restrictions!

function size🔗

uint64_t size() const

Returns the size of the Listener.

Return: size of the Listener

function attachEvent🔗

template <typename T ,
typename UserType >
inline cxx::expected< ListenerError > attachEvent(
    T & eventOrigin,
    const NotificationCallback< T, UserType > & eventCallback
)

function attachEvent🔗

template <typename T ,
typename EventType ,
typename UserType ,
typename >
inline cxx::expected< ListenerError > attachEvent(
    T & eventOrigin,
    const EventType eventType,
    const NotificationCallback< T, UserType > & eventCallback
)

function capacity🔗

static inline constexpr uint64_t capacity()

Returns the capacity of the Listener.

Return: capacity of the Listener

Protected Functions Documentation🔗

function Listener🔗

Listener(
    ConditionVariableData & conditionVariableData
)

Updated on 17 June 2021 at 11:15:27 CEST