17 #ifndef IOX_POSH_POPO_LISTENER_HPP
18 #define IOX_POSH_POPO_LISTENER_HPP
20 #include "iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp"
21 #include "iceoryx_posh/popo/enum_trigger_type.hpp"
22 #include "iceoryx_posh/popo/notification_attorney.hpp"
23 #include "iceoryx_posh/popo/notification_callback.hpp"
24 #include "iceoryx_posh/popo/trigger_handle.hpp"
25 #include "iceoryx_utils/cxx/expected.hpp"
26 #include "iceoryx_utils/cxx/method_callback.hpp"
27 #include "iceoryx_utils/cxx/type_traits.hpp"
28 #include "iceoryx_utils/internal/concurrent/loffli.hpp"
29 #include "iceoryx_utils/internal/concurrent/smart_lock.hpp"
37 enum class ListenerError
41 EVENT_ALREADY_ATTACHED,
42 EMPTY_INVALIDATION_CALLBACK
91 typename ContextDataType,
92 typename = std::enable_if_t<std::is_enum<EventType>::value>>
94 const EventType eventType,
107 template <
typename T,
typename ContextDataType>
117 template <typename T, typename EventType, typename = std::enable_if_t<std::is_enum<EventType>::value>>
118 void detachEvent(T& eventOrigin,
const EventType eventType) noexcept;
123 template <
typename T>
128 static constexpr uint64_t
capacity() noexcept;
132 uint64_t
size() const noexcept;
140 void threadLoop() noexcept;
141 cxx::expected<uint32_t, ListenerError>
142 addEvent(
void* const origin,
143 void* const userType,
144 const uint64_t eventType,
145 const uint64_t eventTypeHash,
146 internal::GenericCallbackRef_t callback,
147 internal::TranslationCallbackRef_t translationCallback,
148 const cxx::MethodCallback<
void, uint64_t> invalidationCallback) noexcept;
150 void removeTrigger(const uint64_t index) noexcept;
153 enum class NoEnumUsed : EventEnumIdentifier
163 bool isEqualTo(
const void*
const origin,
const uint64_t eventType,
const uint64_t eventTypeHash)
const noexcept;
164 bool reset() noexcept;
165 bool init(const uint64_t eventId,
167 void* const userType,
168 const uint64_t eventType,
169 const uint64_t eventTypeHash,
170 internal::GenericCallbackRef_t callback,
171 internal::TranslationCallbackRef_t translationCallback,
172 const cxx::MethodCallback<
void, uint64_t> invalidationCallback) noexcept;
173 void executeCallback() noexcept;
174 bool isInitialized() const noexcept;
177 static constexpr uint64_t INVALID_ID = std::numeric_limits<uint64_t>::max();
179 void* m_origin =
nullptr;
180 uint64_t m_eventType = INVALID_ID;
181 uint64_t m_eventTypeHash = INVALID_ID;
183 internal::GenericCallbackPtr_t m_callback =
nullptr;
184 internal::TranslationCallbackPtr_t m_translationCallback =
nullptr;
185 void* m_userType =
nullptr;
187 uint64_t m_eventId = INVALID_ID;
188 cxx::MethodCallback<
void, uint64_t> m_invalidationCallback;
194 IndexManager_t() noexcept;
195 bool pop(uint32_t& index) noexcept;
196 void push(const uint32_t index) noexcept;
197 uint64_t indicesInUse() const noexcept;
199 using LoFFLi = concurrent::LoFFLi;
201 m_loffliStorage[LoFFLi::requiredIndexMemorySize(MAX_NUMBER_OF_EVENTS_PER_LISTENER) / sizeof(uint32_t)];
203 std::atomic<uint64_t> m_indicesInUse{0U};
207 std::thread m_thread;
208 concurrent::smart_lock<Event_t, std::recursive_mutex> m_events[MAX_NUMBER_OF_EVENTS_PER_LISTENER];
209 std::mutex m_addEventMutex;
211 std::atomic_bool m_wasDtorCalled{
false};
212 ConditionVariableData* m_conditionVariableData =
nullptr;
213 ConditionListener m_conditionListener;
218 #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:67
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...
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...
static constexpr uint64_t capacity() noexcept
Returns the capacity of the Listener.
Definition: listener.inl:73
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 ...
Definition: listener.inl:60
uint64_t size() const noexcept
Returns the size of the Listener.
Definition: service_description.hpp:29
Definition: condition_variable_data.hpp:31
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