Skip to content

Commit 9db6181

Browse files
committed
[#390] Renamed {try_}wait into {try_}wait_and_process_events
1 parent 4fb5957 commit 9db6181

File tree

8 files changed

+123
-97
lines changed

8 files changed

+123
-97
lines changed

examples/rust/event_multiplexing/wait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6868
// loops until the user has pressed CTRL+c, the application has received a SIGTERM or SIGINT
6969
// signal or the user has called explicitly `waitset.stop()` in the `on_event` callback. We
7070
// didn't add this to the example so feel free to play around with it.
71-
waitset.wait(on_event)?;
71+
waitset.wait_and_process_events(on_event)?;
7272

7373
println!("Exit");
7474

iceoryx2-ffi/cxx/include/iox2/waitset.hpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
namespace iox2 {
2525
/// The [`WaitSetGuard`] is returned by [`WaitSet::attach_deadline()`], [`WaitSet::attach_notification()`]
2626
/// or [`WaitSet::attach_interval()`]. As soon as it goes out-of-scope it detaches the attachment.
27-
/// It can also be used to determine the origin of an event in [`WaitSet::wait()`] or
28-
/// [`WaitSet::try_wait()`] via [`WaitSetAttachmentId::has_event_from()`] or
27+
/// It can also be used to determine the origin of an event in [`WaitSet::wait_and_process_events()`] or
28+
/// [`WaitSet::try_wait_and_process_events()`] via [`WaitSetAttachmentId::has_event_from()`] or
2929
/// [`WaitSetAttachmentId::has_missed_deadline()`].
3030
template <ServiceType S>
3131
class WaitSetGuard {
@@ -93,8 +93,8 @@ template <ServiceType S>
9393
auto operator<(const WaitSetAttachmentId<S>& lhs, const WaitSetAttachmentId<S>& rhs) -> bool;
9494

9595
/// The [`WaitSet`] implements a reactor pattern and allows to wait on multiple events in one
96-
/// single call [`WaitSet::try_wait()`] until it wakes up or to run repeatedly with
97-
/// [`WaitSet::wait()`] until the a interrupt or termination signal was received or the user
96+
/// single call [`WaitSet::try_wait_and_process_events()`] until it wakes up or to run repeatedly with
97+
/// [`WaitSet::wait_and_process_events()`] until the a interrupt or termination signal was received or the user
9898
/// has explicitly requested to stop with [`WaitSet::stop()`].
9999
///
100100
/// The [`Listener`] can be attached as well as sockets or anything else that
@@ -110,7 +110,7 @@ class WaitSet {
110110
auto operator=(WaitSet&&) noexcept -> WaitSet&;
111111
~WaitSet();
112112

113-
/// Can be called from within a callback during [`WaitSet::wait()`] to signal the [`WaitSet`]
113+
/// Can be called from within a callback during [`WaitSet::wait_and_process_events()`] to signal the [`WaitSet`]
114114
/// to stop running after this iteration.
115115
void stop();
116116

@@ -119,14 +119,15 @@ class WaitSet {
119119
/// acquire the source.
120120
/// If an interrupt- (`SIGINT`) or a termination-signal (`SIGTERM`) was received, it will exit
121121
/// the loop and inform the user via [`WaitSetRunResult`].
122-
auto wait(const iox::function<void(WaitSetAttachmentId<S>)>& fn_call)
122+
auto wait_and_process_events(const iox::function<void(WaitSetAttachmentId<S>)>& fn_call)
123123
-> iox::expected<WaitSetRunResult, WaitSetRunError>;
124124

125125
/// Tries to wait on the [`WaitSet`]. The provided callback is called for every attachment that
126126
/// was triggered and the [`WaitSetAttachmentId`] is provided as an input argument to acquire the
127127
/// source.
128128
/// If nothing was triggered the [`WaitSet`] returns immediately.
129-
auto try_wait(const iox::function<void(WaitSetAttachmentId<S>)>& fn_call) -> iox::expected<void, WaitSetRunError>;
129+
auto try_wait_and_process_events(const iox::function<void(WaitSetAttachmentId<S>)>& fn_call)
130+
-> iox::expected<void, WaitSetRunError>;
130131

131132
/// Returns the capacity of the [`WaitSet`]
132133
auto capacity() const -> uint64_t;
@@ -138,7 +139,7 @@ class WaitSet {
138139
auto is_empty() const -> bool;
139140

140141
/// Attaches a [`Listener`] as notification to the [`WaitSet`]. Whenever an event is received on the
141-
/// object the [`WaitSet`] informs the user in [`WaitSet::wait()`] to handle the event.
142+
/// object the [`WaitSet`] informs the user in [`WaitSet::wait_and_process_events()`] to handle the event.
142143
/// The object cannot be attached twice and the
143144
/// [`WaitSet::capacity()`] is limited by the underlying implementation.
144145
///
@@ -149,7 +150,7 @@ class WaitSet {
149150
auto attach_notification(const Listener<S>& listener) -> iox::expected<WaitSetGuard<S>, WaitSetAttachmentError>;
150151

151152
/// Attaches a [`FileDescriptorView`] as notification to the [`WaitSet`]. Whenever an event is received on the
152-
/// object the [`WaitSet`] informs the user in [`WaitSet::wait()`] to handle the event.
153+
/// object the [`WaitSet`] informs the user in [`WaitSet::wait_and_process_events()`] to handle the event.
153154
/// The object cannot be attached twice and the
154155
/// [`WaitSet::capacity()`] is limited by the underlying implementation.
155156
///
@@ -161,7 +162,7 @@ class WaitSet {
161162
attach_notification(FileDescriptorView file_descriptor) -> iox::expected<WaitSetGuard<S>, WaitSetAttachmentError>;
162163

163164
/// Attaches a [`Listener`] as deadline to the [`WaitSet`]. Whenever the event is received or the
164-
/// deadline is hit, the user is informed in [`WaitSet::wait()`].
165+
/// deadline is hit, the user is informed in [`WaitSet::wait_and_process_events()`].
165166
/// The object cannot be attached twice and the
166167
/// [`WaitSet::capacity()`] is limited by the underlying implementation.
167168
/// Whenever the object emits an event the deadline is reset by the [`WaitSet`].
@@ -174,7 +175,7 @@ class WaitSet {
174175
iox::units::Duration deadline) -> iox::expected<WaitSetGuard<S>, WaitSetAttachmentError>;
175176

176177
/// Attaches a [`FileDescriptorView`] as deadline to the [`WaitSet`]. Whenever the event is received or the
177-
/// deadline is hit, the user is informed in [`WaitSet::wait()`].
178+
/// deadline is hit, the user is informed in [`WaitSet::wait_and_process_events()`].
178179
/// The object cannot be attached twice and the
179180
/// [`WaitSet::capacity()`] is limited by the underlying implementation.
180181
/// Whenever the object emits an event the deadline is reset by the [`WaitSet`].
@@ -187,7 +188,7 @@ class WaitSet {
187188
iox::units::Duration deadline) -> iox::expected<WaitSetGuard<S>, WaitSetAttachmentError>;
188189

189190
/// Attaches a tick event to the [`WaitSet`]. Whenever the timeout is reached the [`WaitSet`]
190-
/// informs the user in [`WaitSet::wait()`].
191+
/// informs the user in [`WaitSet::wait_and_process_events()`].
191192
///
192193
/// # Safety
193194
///

iceoryx2-ffi/cxx/src/waitset.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,12 @@ auto run_callback(iox2_waitset_attachment_id_h attachment_id, void* context) {
280280
}
281281

282282
template <ServiceType S>
283-
auto WaitSet<S>::wait(const iox::function<void(WaitSetAttachmentId<S>)>& fn_call)
283+
auto WaitSet<S>::wait_and_process_events(const iox::function<void(WaitSetAttachmentId<S>)>& fn_call)
284284
-> iox::expected<WaitSetRunResult, WaitSetRunError> {
285285
iox2_waitset_run_result_e run_result = iox2_waitset_run_result_e_STOP_REQUEST;
286286
auto ctx = internal::ctx(fn_call);
287-
auto result = iox2_waitset_wait(&m_handle, run_callback<S>, static_cast<void*>(&ctx), &run_result);
287+
auto result =
288+
iox2_waitset_wait_and_process_events(&m_handle, run_callback<S>, static_cast<void*>(&ctx), &run_result);
288289

289290
if (result == IOX2_OK) {
290291
return iox::ok(iox::into<WaitSetRunResult>(static_cast<int>(run_result)));
@@ -294,10 +295,10 @@ auto WaitSet<S>::wait(const iox::function<void(WaitSetAttachmentId<S>)>& fn_call
294295
}
295296

296297
template <ServiceType S>
297-
auto WaitSet<S>::try_wait(const iox::function<void(WaitSetAttachmentId<S>)>& fn_call)
298+
auto WaitSet<S>::try_wait_and_process_events(const iox::function<void(WaitSetAttachmentId<S>)>& fn_call)
298299
-> iox::expected<void, WaitSetRunError> {
299300
auto ctx = internal::ctx(fn_call);
300-
auto result = iox2_waitset_try_wait(&m_handle, run_callback<S>, static_cast<void*>(&ctx));
301+
auto result = iox2_waitset_try_wait_and_process_events(&m_handle, run_callback<S>, static_cast<void*>(&ctx));
301302

302303
if (result == IOX2_OK) {
303304
return iox::ok();

iceoryx2-ffi/cxx/tests/src/waitset_tests.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ TYPED_TEST(WaitSetTest, attaching_same_notification_twice_fails) {
132132

133133
TYPED_TEST(WaitSetTest, empty_waitset_returns_error_on_run) {
134134
auto sut = this->create_sut();
135-
auto result = sut.wait([](auto) {});
135+
auto result = sut.wait_and_process_events([](auto) {});
136136

137137
ASSERT_THAT(result.has_error(), Eq(true));
138138
ASSERT_THAT(result.get_error(), Eq(WaitSetRunError::NoAttachments));
139139
}
140140

141141
TYPED_TEST(WaitSetTest, empty_waitset_returns_error_on_run_once) {
142142
auto sut = this->create_sut();
143-
auto result = sut.try_wait([](auto) {});
143+
auto result = sut.try_wait_and_process_events([](auto) {});
144144

145145
ASSERT_THAT(result.has_error(), Eq(true));
146146
ASSERT_THAT(result.get_error(), Eq(WaitSetRunError::NoAttachments));
@@ -153,7 +153,7 @@ TYPED_TEST(WaitSetTest, interval_attachment_blocks_for_at_least_timeout) {
153153
auto guard = sut.attach_interval(TIMEOUT).expect("");
154154

155155
auto callback_called = false;
156-
auto result = sut.wait([&](auto attachment_id) {
156+
auto result = sut.wait_and_process_events([&](auto attachment_id) {
157157
callback_called = true;
158158
sut.stop();
159159
ASSERT_THAT(attachment_id.has_event_from(guard), Eq(true));
@@ -175,7 +175,7 @@ TYPED_TEST(WaitSetTest, deadline_attachment_blocks_for_at_least_timeout) {
175175
auto guard = sut.attach_deadline(listener, TIMEOUT).expect("");
176176

177177
auto callback_called = false;
178-
auto result = sut.wait([&](auto attachment_id) {
178+
auto result = sut.wait_and_process_events([&](auto attachment_id) {
179179
callback_called = true;
180180
sut.stop();
181181
ASSERT_THAT(attachment_id.has_event_from(guard), Eq(false));
@@ -201,7 +201,7 @@ TYPED_TEST(WaitSetTest, deadline_attachment_wakes_up_when_notified) {
201201
auto notifier = this->create_notifier();
202202
notifier.notify().expect("");
203203
});
204-
auto result = sut.wait([&](auto attachment_id) {
204+
auto result = sut.wait_and_process_events([&](auto attachment_id) {
205205
callback_called = true;
206206
sut.stop();
207207
ASSERT_THAT(attachment_id.has_event_from(guard), Eq(true));
@@ -224,7 +224,7 @@ TYPED_TEST(WaitSetTest, notification_attachment_wakes_up_when_notified) {
224224
auto notifier = this->create_notifier();
225225
notifier.notify().expect("");
226226
});
227-
auto result = sut.wait([&](auto attachment_id) {
227+
auto result = sut.wait_and_process_events([&](auto attachment_id) {
228228
callback_called = true;
229229
sut.stop();
230230
ASSERT_THAT(attachment_id.has_event_from(guard), Eq(true));
@@ -266,7 +266,7 @@ TYPED_TEST(WaitSetTest, triggering_everything_works) {
266266
std::this_thread::sleep_for(std::chrono::milliseconds(TIMEOUT.toMilliseconds()));
267267
std::vector<bool> was_triggered(guards.size(), false);
268268

269-
sut.try_wait([&](auto attachment_id) {
269+
sut.try_wait_and_process_events([&](auto attachment_id) {
270270
for (uint64_t idx = 0; idx < guards.size(); ++idx) {
271271
if (attachment_id.has_event_from(guards[idx])) {
272272
was_triggered[idx] = true;

iceoryx2-ffi/ffi/src/api/waitset.rs

+70-46
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ pub unsafe extern "C" fn iox2_waitset_capacity(handle: iox2_waitset_h_ref) -> c_
283283
}
284284
}
285285

286-
/// Stops the current [`iox2_waitset_wait()`] operation. Any [`iox2_waitset_wait()`]
286+
/// Stops the current [`iox2_waitset_wait_and_process_events()`] operation. Any [`iox2_waitset_wait_and_process_events()`]
287287
/// call after this call is not affected and the user needs to call
288288
/// [`iox2_waitset_stop()`] again.
289289
///
@@ -305,7 +305,7 @@ pub unsafe extern "C" fn iox2_waitset_stop(handle: iox2_waitset_h_ref) {
305305

306306
/// Attaches a provided [`iox2_file_descriptor_ptr`] as notification to the
307307
/// [`iox2_waitset_h`]. As soon as the attachment receives data, the WaitSet
308-
/// wakes up in [`iox2_waitset_wait()`] and informs the user.
308+
/// wakes up in [`iox2_waitset_wait_and_process_events()`] and informs the user.
309309
///
310310
/// With [`iox2_waitset_attachment_id_has_event_from()`](crate::iox2_waitset_attachment_id_has_event_from())
311311
/// the origin of the event can be determined from its corresponding
@@ -381,7 +381,7 @@ pub unsafe extern "C" fn iox2_waitset_attach_notification(
381381

382382
/// Attaches a provided [`iox2_file_descriptor_ptr`] as deadline to the
383383
/// [`iox2_waitset_h`]. As soon as the attachment receives data or the deadline
384-
/// was missed, the WaitSet wakes up in [`iox2_waitset_wait()`] and informs the user.
384+
/// was missed, the WaitSet wakes up in [`iox2_waitset_wait_and_process_events()`] and informs the user.
385385
///
386386
/// With [`iox2_waitset_attachment_id_has_event_from()`](crate::iox2_waitset_attachment_id_has_event_from())
387387
/// the origin of the event can be determined from its corresponding
@@ -469,7 +469,7 @@ pub unsafe extern "C" fn iox2_waitset_attach_deadline(
469469
}
470470

471471
/// Attaches an interval to the [`iox2_waitset_h`]. As soon as the interval has passed
472-
/// the WaitSet wakes up in [`iox2_waitset_wait()`] and informs the user.
472+
/// the WaitSet wakes up in [`iox2_waitset_wait_and_process_events()`] and informs the user.
473473
///
474474
/// With [`iox2_waitset_attachment_id_has_event_from()`](crate::iox2_waitset_attachment_id_has_event_from())
475475
/// the origin of the event can be determined from its corresponding
@@ -568,7 +568,7 @@ pub unsafe extern "C" fn iox2_waitset_attach_interval(
568568
/// * the provided [`iox2_waitset_attachment_id_h`] in the callback must be released via
569569
/// [`iox2_waitset_attachment_id_drop()`](crate::iox2_waitset_attachment_id_drop())
570570
#[no_mangle]
571-
pub unsafe extern "C" fn iox2_waitset_try_wait(
571+
pub unsafe extern "C" fn iox2_waitset_try_wait_and_process_events(
572572
handle: iox2_waitset_h_ref,
573573
callback: iox2_waitset_run_callback,
574574
callback_ctx: iox2_callback_context,
@@ -578,26 +578,38 @@ pub unsafe extern "C" fn iox2_waitset_try_wait(
578578
let waitset = &mut *handle.as_type();
579579

580580
let run_once_result = match waitset.service_type {
581-
iox2_service_type_e::IPC => waitset.value.as_ref().ipc.try_wait(|attachment_id| {
582-
let attachment_id_ptr = iox2_waitset_attachment_id_t::alloc();
583-
(*attachment_id_ptr).init(
584-
waitset.service_type,
585-
AttachmentIdUnion::new_ipc(attachment_id),
586-
iox2_waitset_attachment_id_t::dealloc,
587-
);
588-
let attachment_id_handle_ptr = (*attachment_id_ptr).as_handle();
589-
callback(attachment_id_handle_ptr, callback_ctx);
590-
}),
591-
iox2_service_type_e::LOCAL => waitset.value.as_ref().local.try_wait(|attachment_id| {
592-
let attachment_id_ptr = iox2_waitset_attachment_id_t::alloc();
593-
(*attachment_id_ptr).init(
594-
waitset.service_type,
595-
AttachmentIdUnion::new_local(attachment_id),
596-
iox2_waitset_attachment_id_t::dealloc,
597-
);
598-
let attachment_id_handle_ptr = (*attachment_id_ptr).as_handle();
599-
callback(attachment_id_handle_ptr, callback_ctx);
600-
}),
581+
iox2_service_type_e::IPC => {
582+
waitset
583+
.value
584+
.as_ref()
585+
.ipc
586+
.try_wait_and_process_events(|attachment_id| {
587+
let attachment_id_ptr = iox2_waitset_attachment_id_t::alloc();
588+
(*attachment_id_ptr).init(
589+
waitset.service_type,
590+
AttachmentIdUnion::new_ipc(attachment_id),
591+
iox2_waitset_attachment_id_t::dealloc,
592+
);
593+
let attachment_id_handle_ptr = (*attachment_id_ptr).as_handle();
594+
callback(attachment_id_handle_ptr, callback_ctx);
595+
})
596+
}
597+
iox2_service_type_e::LOCAL => {
598+
waitset
599+
.value
600+
.as_ref()
601+
.local
602+
.try_wait_and_process_events(|attachment_id| {
603+
let attachment_id_ptr = iox2_waitset_attachment_id_t::alloc();
604+
(*attachment_id_ptr).init(
605+
waitset.service_type,
606+
AttachmentIdUnion::new_local(attachment_id),
607+
iox2_waitset_attachment_id_t::dealloc,
608+
);
609+
let attachment_id_handle_ptr = (*attachment_id_ptr).as_handle();
610+
callback(attachment_id_handle_ptr, callback_ctx);
611+
})
612+
}
601613
};
602614

603615
match run_once_result {
@@ -631,7 +643,7 @@ pub unsafe extern "C" fn iox2_waitset_try_wait(
631643
/// * the provided [`iox2_waitset_attachment_id_h`] in the callback must be released via
632644
/// [`iox2_waitset_attachment_id_drop()`](crate::iox2_waitset_attachment_id_drop())
633645
#[no_mangle]
634-
pub unsafe extern "C" fn iox2_waitset_wait(
646+
pub unsafe extern "C" fn iox2_waitset_wait_and_process_events(
635647
handle: iox2_waitset_h_ref,
636648
callback: iox2_waitset_run_callback,
637649
callback_ctx: iox2_callback_context,
@@ -643,26 +655,38 @@ pub unsafe extern "C" fn iox2_waitset_wait(
643655
let waitset = &mut *handle.as_type();
644656

645657
let run_result = match waitset.service_type {
646-
iox2_service_type_e::IPC => waitset.value.as_ref().ipc.wait(|attachment_id| {
647-
let attachment_id_ptr = iox2_waitset_attachment_id_t::alloc();
648-
(*attachment_id_ptr).init(
649-
waitset.service_type,
650-
AttachmentIdUnion::new_ipc(attachment_id),
651-
iox2_waitset_attachment_id_t::dealloc,
652-
);
653-
let attachment_id_handle_ptr = (*attachment_id_ptr).as_handle();
654-
callback(attachment_id_handle_ptr, callback_ctx);
655-
}),
656-
iox2_service_type_e::LOCAL => waitset.value.as_ref().local.wait(|attachment_id| {
657-
let attachment_id_ptr = iox2_waitset_attachment_id_t::alloc();
658-
(*attachment_id_ptr).init(
659-
waitset.service_type,
660-
AttachmentIdUnion::new_local(attachment_id),
661-
iox2_waitset_attachment_id_t::dealloc,
662-
);
663-
let attachment_id_handle_ptr = (*attachment_id_ptr).as_handle();
664-
callback(attachment_id_handle_ptr, callback_ctx);
665-
}),
658+
iox2_service_type_e::IPC => {
659+
waitset
660+
.value
661+
.as_ref()
662+
.ipc
663+
.wait_and_process_events(|attachment_id| {
664+
let attachment_id_ptr = iox2_waitset_attachment_id_t::alloc();
665+
(*attachment_id_ptr).init(
666+
waitset.service_type,
667+
AttachmentIdUnion::new_ipc(attachment_id),
668+
iox2_waitset_attachment_id_t::dealloc,
669+
);
670+
let attachment_id_handle_ptr = (*attachment_id_ptr).as_handle();
671+
callback(attachment_id_handle_ptr, callback_ctx);
672+
})
673+
}
674+
iox2_service_type_e::LOCAL => {
675+
waitset
676+
.value
677+
.as_ref()
678+
.local
679+
.wait_and_process_events(|attachment_id| {
680+
let attachment_id_ptr = iox2_waitset_attachment_id_t::alloc();
681+
(*attachment_id_ptr).init(
682+
waitset.service_type,
683+
AttachmentIdUnion::new_local(attachment_id),
684+
iox2_waitset_attachment_id_t::dealloc,
685+
);
686+
let attachment_id_handle_ptr = (*attachment_id_ptr).as_handle();
687+
callback(attachment_id_handle_ptr, callback_ctx);
688+
})
689+
}
666690
};
667691

668692
match run_result {

iceoryx2-ffi/ffi/src/api/waitset_attachment_id.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ impl HandleToType for iox2_waitset_attachment_id_h_ref {
112112

113113
// BEGIN C API
114114
/// Release an [`iox2_waitset_attachment_id_h`] that was acquired by calling either
115-
/// * [`iox2_waitset_wait()`](crate::iox2_waitset_wait())
116-
/// * [`iox2_waitset_try_wait()`](crate::iox2_waitset_try_wait())
115+
/// * [`iox2_waitset_wait_and_process_events()`](crate::iox2_waitset_wait_and_process_events())
116+
/// * [`iox2_waitset_try_wait_and_process_events()`](crate::iox2_waitset_try_wait_and_process_events())
117117
///
118118
/// # Safety
119119
/// * `handle` must be valid and provided by the previously mentioned functions.

0 commit comments

Comments
 (0)