17 #ifndef IOX_POSH_POPO_WAIT_SET_HPP
18 #define IOX_POSH_POPO_WAIT_SET_HPP
20 #include "iceoryx_posh/iceoryx_posh_types.hpp"
21 #include "iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp"
22 #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp"
23 #include "iceoryx_posh/popo/enum_trigger_type.hpp"
24 #include "iceoryx_posh/popo/notification_attorney.hpp"
25 #include "iceoryx_posh/popo/notification_callback.hpp"
26 #include "iceoryx_posh/popo/notification_info.hpp"
27 #include "iceoryx_posh/popo/trigger.hpp"
28 #include "iceoryx_posh/popo/trigger_handle.hpp"
29 #include "iceoryx_posh/runtime/posh_runtime.hpp"
30 #include "iceoryx_utils/cxx/algorithm.hpp"
31 #include "iceoryx_utils/cxx/function_ref.hpp"
32 #include "iceoryx_utils/cxx/helplets.hpp"
33 #include "iceoryx_utils/cxx/list.hpp"
34 #include "iceoryx_utils/cxx/method_callback.hpp"
35 #include "iceoryx_utils/cxx/stack.hpp"
36 #include "iceoryx_utils/cxx/vector.hpp"
46 enum class WaitSetError : uint8_t
60 template <u
int64_t Capacity = MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET>
64 static constexpr uint64_t CAPACITY = Capacity;
65 using TriggerArray = cxx::optional<Trigger>[Capacity];
66 using NotificationInfoVector = cxx::vector<const NotificationInfo*, CAPACITY>;
93 typename ContextDataType = internal::NoType_t,
94 typename = std::enable_if_t<std::is_enum<EventType>::value>>
95 cxx::expected<WaitSetError>
97 const EventType eventType,
98 const uint64_t notificationId = 0U,
107 template <
typename T,
110 typename = std::enable_if_t<std::is_enum<EventType>::value,
void>>
111 cxx::expected<WaitSetError>
attachEvent(T& eventOrigin,
112 const EventType eventType,
121 template <
typename T,
typename ContextDataType =
internal::NoType_t>
122 cxx::expected<WaitSetError>
124 const uint64_t notificationId = 0U,
132 template <
typename T,
typename ContextDataType =
internal::NoType_t>
133 cxx::expected<WaitSetError>
attachEvent(T& eventOrigin,
134 const NotificationCallback<T, ContextDataType>& eventCallback) noexcept;
143 template <
typename T,
145 typename ContextDataType = internal::NoType_t,
146 typename = std::enable_if_t<std::is_enum<StateType>::value>>
147 cxx::expected<WaitSetError>
149 const StateType stateType,
150 const uint64_t
id = 0U,
151 const NotificationCallback<T, ContextDataType>& stateCallback = {}) noexcept;
159 template <
typename T,
161 typename ContextDataType = internal::NoType_t,
162 typename = std::enable_if_t<std::is_enum<StateType>::value,
void>>
163 cxx::expected<WaitSetError>
attachState(T& stateOrigin,
164 const StateType stateType,
165 const NotificationCallback<T, ContextDataType>& stateCallback) noexcept;
173 template <
typename T,
typename ContextDataType =
internal::NoType_t>
174 cxx::expected<WaitSetError>
176 const uint64_t
id = 0U,
177 const NotificationCallback<T, ContextDataType>& stateCallback = {}) noexcept;
184 template <
typename T,
typename ContextDataType =
internal::NoType_t>
185 cxx::expected<WaitSetError>
attachState(T& stateOrigin,
186 const NotificationCallback<T, ContextDataType>& stateCallback) noexcept;
191 template <
typename T,
typename... Targs>
192 void detachEvent(T& eventOrigin,
const Targs&... args) noexcept;
197 template <
typename T,
typename... Targs>
198 void detachState(T& stateOrigin,
const Targs&... args) noexcept;
203 NotificationInfoVector
timedWait(
const units::Duration timeout) noexcept;
207 NotificationInfoVector
wait() noexcept;
210 uint64_t
size() const noexcept;
213 static constexpr uint64_t
capacity() noexcept;
216 explicit WaitSet(ConditionVariableData& condVarData) noexcept;
219 enum class NoStateEnumUsed : StateEnumIdentifier
224 enum class NoEventEnumUsed : EventEnumIdentifier
229 using WaitFunction = cxx::function_ref<ConditionListener::NotificationVector_t()>;
230 template <
typename T,
typename ContextDataType>
231 cxx::expected<uint64_t, WaitSetError> attachImpl(T& eventOrigin,
232 const WaitSetIsConditionSatisfiedCallback& hasTriggeredCallback,
233 const uint64_t notificationId,
234 const NotificationCallback<T, ContextDataType>& eventCallback,
235 const uint64_t originType,
236 const uint64_t originTypeHash) noexcept;
238 NotificationInfoVector waitAndReturnTriggeredTriggers(
const WaitFunction&
wait) noexcept;
239 NotificationInfoVector createVectorWithTriggeredTriggers() noexcept;
241 void removeTrigger(const uint64_t uniqueTriggerId) noexcept;
242 void removeAllTriggers() noexcept;
243 void acquireNotifications(const WaitFunction&
wait) noexcept;
247 TriggerArray m_triggerArray;
248 ConditionVariableData* m_conditionVariableDataPtr{
nullptr};
249 ConditionListener m_conditionListener;
251 cxx::stack<uint64_t, Capacity> m_indexRepository;
252 ConditionListener::NotificationVector_t m_activeNotifications;
258 #include "iceoryx_posh/internal/popo/wait_set.inl"
Logical disjunction of a certain number of Triggers.
Definition: wait_set.hpp:62
NotificationInfoVector wait() noexcept
Blocking wait till one or more of the triggers are triggered.
Definition: wait_set.inl:270
void markForDestruction() noexcept
Non-reversible call. After this call wait() and timedWait() do not block any longer and never return ...
Definition: wait_set.inl:49
cxx::expected< WaitSetError > attachEvent(T &eventOrigin, const EventType eventType, const uint64_t notificationId=0U, const NotificationCallback< T, ContextDataType > &eventCallback={}) noexcept
attaches an event of a given class to the WaitSet.
Definition: wait_set.inl:111
cxx::expected< WaitSetError > attachState(T &stateOrigin, const StateType stateType, const uint64_t id=0U, const NotificationCallback< T, ContextDataType > &stateCallback={}) noexcept
attaches a state of a given class to the WaitSet.
Definition: wait_set.inl:168
NotificationInfoVector timedWait(const units::Duration timeout) noexcept
Blocking wait with time limit till one or more of the triggers are triggered.
Definition: wait_set.inl:264
void detachState(T &stateOrigin, const Targs &... args) noexcept
detaches a state based trigger from the WaitSet
Definition: wait_set.inl:233
WaitSet(const WaitSet &rhs)=delete
all the Trigger have a pointer pointing to this waitset for cleanup calls, therefore the WaitSet cann...
void detachEvent(T &eventOrigin, const Targs &... args) noexcept
detaches an event from the WaitSet
Definition: wait_set.inl:226
uint64_t size() const noexcept
Returns the amount of stored Trigger inside of the WaitSet.
Definition: wait_set.inl:344
static constexpr uint64_t capacity() noexcept
returns the maximum amount of triggers which can be acquired from a waitset
Definition: wait_set.inl:350
Definition: service_description.hpp:29
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
Definition: notification_callback.hpp:32