17#ifndef IOX_POSH_POPO_LISTENER_HPP
18#define IOX_POSH_POPO_LISTENER_HPP
20#include "iceoryx_hoofs/cxx/expected.hpp"
21#include "iceoryx_hoofs/cxx/method_callback.hpp"
22#include "iceoryx_hoofs/cxx/type_traits.hpp"
23#include "iceoryx_hoofs/internal/concurrent/loffli.hpp"
24#include "iceoryx_hoofs/internal/concurrent/smart_lock.hpp"
25#include "iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp"
26#include "iceoryx_posh/popo/enum_trigger_type.hpp"
27#include "iceoryx_posh/popo/notification_attorney.hpp"
28#include "iceoryx_posh/popo/notification_callback.hpp"
29#include "iceoryx_posh/popo/trigger_handle.hpp"
30#include "iceoryx_posh/runtime/posh_runtime.hpp"
45 bool isEqualTo(const
void* const origin, const uint64_t eventType, const uint64_t eventTypeHash) const noexcept;
46 bool reset() noexcept;
47 bool init(const uint64_t eventId,
50 const uint64_t eventType,
51 const uint64_t eventTypeHash,
52 internal::GenericCallbackRef_t callback,
53 internal::TranslationCallbackRef_t translationCallback,
54 const cxx::MethodCallback<
void, uint64_t> invalidationCallback) noexcept;
55 void executeCallback() noexcept;
56 bool isInitialized() const noexcept;
59 static constexpr uint64_t INVALID_ID = std::numeric_limits<uint64_t>::max();
61 void* m_origin =
nullptr;
62 uint64_t m_eventType = INVALID_ID;
63 uint64_t m_eventTypeHash = INVALID_ID;
65 internal::GenericCallbackPtr_t m_callback =
nullptr;
66 internal::TranslationCallbackPtr_t m_translationCallback =
nullptr;
67 void* m_userType =
nullptr;
69 uint64_t m_eventId = INVALID_ID;
70 cxx::MethodCallback<
void, uint64_t> m_invalidationCallback;
74enum class ListenerError
77 EVENT_ALREADY_ATTACHED,
79 EMPTY_INVALIDATION_CALLBACK
103template <u
int64_t Capacity>
127 template <
typename T,
129 typename ContextDataType,
130 typename = std::enable_if_t<std::is_enum<EventType>::value>>
132 const EventType eventType,
145 template <
typename T,
typename ContextDataType>
155 template <typename T, typename EventType, typename = std::enable_if_t<std::is_enum<EventType>::value>>
156 void detachEvent(T& eventOrigin,
const EventType eventType)
noexcept;
161 template <
typename T>
170 uint64_t size() const noexcept;
173 ListenerImpl(ConditionVariableData& conditionVariableData) noexcept;
178 void threadLoop() noexcept;
179 cxx::expected<uint32_t, ListenerError>
180 addEvent(
void* const origin,
181 void* const userType,
182 const uint64_t eventType,
183 const uint64_t eventTypeHash,
184 internal::GenericCallbackRef_t callback,
185 internal::TranslationCallbackRef_t translationCallback,
186 const cxx::MethodCallback<
void, uint64_t> invalidationCallback) noexcept;
188 void removeTrigger(const uint64_t index) noexcept;
191 enum class NoEnumUsed : EventEnumIdentifier
200 IndexManager_t() noexcept;
201 bool pop(uint32_t& index) noexcept;
202 void push(const uint32_t index) noexcept;
203 uint64_t indicesInUse() const noexcept;
205 using LoFFLi = concurrent::LoFFLi;
206 LoFFLi::Index_t m_loffliStorage[LoFFLi::requiredIndexMemorySize(Capacity) / sizeof(uint32_t)];
208 std::atomic<uint64_t> m_indicesInUse{0U};
212 std::thread m_thread;
213 concurrent::smart_lock<internal::Event_t, std::recursive_mutex> m_events[Capacity];
214 std::mutex m_addEventMutex;
216 std::atomic_bool m_wasDtorCalled{
false};
217 ConditionVariableData* m_conditionVariableData =
nullptr;
218 ConditionListener m_conditionListener;
228 Listener(ConditionVariableData& conditionVariableData)
noexcept;
234#include "iceoryx_posh/internal/popo/listener.inl"
The Listener is a class which reacts to registered events by executing a corresponding callback concu...
Definition: listener.hpp:105
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 ...
void detachEvent(T &eventOrigin) noexcept
Detaches an event. Hereby, the event is defined as a class T, the eventOrigin.
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 ca...
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 d...
static constexpr uint64_t capacity() noexcept
Returns the capacity of the Listener.
Definition: listener.hpp:222
the struct describes a callback with a user defined type which can be attached to a WaitSet or a List...
Definition: notification_callback.hpp:58