1515
1616#include " iox/duration.hpp"
1717#include " iox/expected.hpp"
18+ #include " iox2/callback_progression.hpp"
1819#include " iox2/file_descriptor.hpp"
1920#include " iox2/internal/iceoryx2.hpp"
2021#include " iox2/listener.hpp"
@@ -78,7 +79,7 @@ class WaitSetAttachmentId {
7879 private:
7980 explicit WaitSetAttachmentId (iox2_waitset_attachment_id_h handle);
8081 template <ServiceType>
81- friend auto run_callback (iox2_waitset_attachment_id_h, void *);
82+ friend auto run_callback (iox2_waitset_attachment_id_h, void *) -> iox2_callback_progression_e ;
8283 template <ServiceType ST >
8384 friend auto operator ==(const WaitSetAttachmentId<ST >&, const WaitSetAttachmentId<ST >&) -> bool ;
8485 template <ServiceType ST >
@@ -103,7 +104,8 @@ auto operator<<(std::ostream& stream, const WaitSetAttachmentId<S>& self) -> std
103104// / The [`WaitSet`] implements a reactor pattern and allows to wait on multiple events in one
104105// / single call [`WaitSet::try_wait_and_process()`] until it wakes up or to run repeatedly with
105106// / [`WaitSet::wait_and_process()`] until the a interrupt or termination signal was received or the user
106- // / has explicitly requested to stop with [`WaitSet::stop()`].
107+ // / has explicitly requested to stop by returning [`CallbackProgression::Stop`] in the provided
108+ // / callback.
107109// /
108110// / The [`Listener`] can be attached as well as sockets or anything else that
109111// / can be packed into a [`FileDescriptorView`].
@@ -118,24 +120,39 @@ class WaitSet {
118120 auto operator =(WaitSet&&) noexcept -> WaitSet&;
119121 ~WaitSet ();
120122
121- // / Can be called from within a callback during [`WaitSet::wait_and_process()`] to signal the [`WaitSet`]
122- // / to stop running after this iteration.
123- void stop ();
124-
125- // / Waits in an infinite loop on the [`WaitSet`]. The provided callback is called for every
126- // / attachment that was triggered and the [`WaitSetAttachmentId`] is provided as an input argument to
127- // / acquire the source.
123+ // / Waits until an event arrives on the [`WaitSet`], then collects all events by calling the
124+ // / provided `fn_call` callback with the corresponding [`WaitSetAttachmentId`]. In contrast
125+ // / to [`WaitSet::wait_and_process_once()`] it will never return until the user explicitly
126+ // / requests it by returning [`CallbackProgression::Stop`] or by receiving a signal.
127+ // /
128+ // / The provided callback must return [`CallbackProgression::Continue`] to continue the event
129+ // / processing and handle the next event or [`CallbackProgression::Stop`] to return from this
130+ // / call immediately. All unhandled events will be lost forever and the call will return
131+ // / [`WaitSetRunResult::StopRequest`].
132+ // /
128133 // / If an interrupt- (`SIGINT`) or a termination-signal (`SIGTERM`) was received, it will exit
129- // / the loop and inform the user via [`WaitSetRunResult`].
130- auto wait_and_process (const iox::function<void (WaitSetAttachmentId<S>)>& fn_call)
134+ // / the loop and inform the user with [`WaitSetRunResult::Interrupt`] or
135+ // / [`WaitSetRunResult::TerminationRequest`].
136+ auto wait_and_process (const iox::function<CallbackProgression(WaitSetAttachmentId<S>)>& fn_call)
131137 -> iox::expected<WaitSetRunResult, WaitSetRunError>;
132138
133- // / Tries to wait on the [`WaitSet`]. The provided callback is called for every attachment that
134- // / was triggered and the [`WaitSetAttachmentId`] is provided as an input argument to acquire the
135- // / source.
136- // / If nothing was triggered the [`WaitSet`] returns immediately.
137- auto try_wait_and_process (const iox::function<void (WaitSetAttachmentId<S>)>& fn_call)
138- -> iox::expected<void, WaitSetRunError>;
139+ // / Waits until an event arrives on the [`WaitSet`], then collects all events by calling the
140+ // / provided `fn_call` callback with the corresponding [`WaitSetAttachmentId`] and then
141+ // / returns. This makes it ideal to be called in some kind of event-loop.
142+ // /
143+ // / The provided callback must return [`CallbackProgression::Continue`] to continue the event
144+ // / processing and handle the next event or [`CallbackProgression::Stop`] to return from this
145+ // / call immediately. All unhandled events will be lost forever and the call will return
146+ // / [`WaitSetRunResult::StopRequest`].
147+ // /
148+ // / If an interrupt- (`SIGINT`) or a termination-signal (`SIGTERM`) was received, it will exit
149+ // / the loop and inform the user with [`WaitSetRunResult::Interrupt`] or
150+ // / [`WaitSetRunResult::TerminationRequest`].
151+ // /
152+ // / When no signal was received and all events were handled, it will return
153+ // / [`WaitSetRunResult::AllEventsHandled`].
154+ auto wait_and_process_once (const iox::function<CallbackProgression(WaitSetAttachmentId<S>)>& fn_call)
155+ -> iox::expected<WaitSetRunResult, WaitSetRunError>;
139156
140157 // / Returns the capacity of the [`WaitSet`]
141158 auto capacity () const -> uint64_t;
0 commit comments