iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
waitset.hpp
Go to the documentation of this file.
1// Copyright (c) 2024 Contributors to the Eclipse Foundation
2//
3// See the NOTICE file(s) distributed with this work for additional
4// information regarding copyright ownership.
5//
6// This program and the accompanying materials are made available under the
7// terms of the Apache Software License 2.0 which is available at
8// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
9// which is available at https://opensource.org/licenses/MIT.
10//
11// SPDX-License-Identifier: Apache-2.0 OR MIT
12
13#ifndef IOX2_WAITSET_HPP
14#define IOX2_WAITSET_HPP
15
17#include "iox2/bb/duration.hpp"
18#include "iox2/bb/expected.hpp"
22#include "iox2/listener.hpp"
23#include "iox2/service_type.hpp"
26
27namespace iox2 {
33template <ServiceType S>
35 public:
37 auto operator=(WaitSetGuard&& rhs) noexcept -> WaitSetGuard&;
39
40 WaitSetGuard(const WaitSetGuard&) = delete;
41 auto operator=(const WaitSetGuard&) = delete;
42
43 private:
44 template <ServiceType>
45 friend class WaitSet;
46
47 template <ServiceType>
48 friend class WaitSetAttachmentId;
49 explicit WaitSetGuard(iox2_waitset_guard_h handle);
50 void drop();
51
52 iox2_waitset_guard_h m_handle = nullptr;
53};
54
56template <ServiceType S>
58 public:
60 auto operator=(const WaitSetAttachmentId& rhs) -> WaitSetAttachmentId& = delete;
61
65
69 static auto from_guard(const WaitSetGuard<S>& guard) -> WaitSetAttachmentId;
70
73 auto has_event_from(const WaitSetGuard<S>& guard) const -> bool;
74
76 auto has_missed_deadline(const WaitSetGuard<S>& guard) const -> bool;
77
79 auto hash() const -> std::size_t;
80
81 private:
82 explicit WaitSetAttachmentId(iox2_waitset_attachment_id_h handle);
83 template <ServiceType>
84 friend auto run_callback(iox2_waitset_attachment_id_h, void*) -> iox2_callback_progression_e;
85 template <ServiceType ST>
86 friend auto operator==(const WaitSetAttachmentId<ST>&, const WaitSetAttachmentId<ST>&) -> bool;
87 template <ServiceType ST>
88 friend auto operator<(const WaitSetAttachmentId<ST>&, const WaitSetAttachmentId<ST>&) -> bool;
89 template <ServiceType ST>
90 friend auto operator<<(std::ostream& stream, const WaitSetAttachmentId<ST>& self) -> std::ostream&;
91
92 void drop();
93
94 iox2_waitset_attachment_id_h m_handle = nullptr;
95};
96
97template <ServiceType S>
98auto operator==(const WaitSetAttachmentId<S>& lhs, const WaitSetAttachmentId<S>& rhs) -> bool;
99
100template <ServiceType S>
101auto operator<(const WaitSetAttachmentId<S>& lhs, const WaitSetAttachmentId<S>& rhs) -> bool;
102
103template <ServiceType S>
104auto operator<<(std::ostream& stream, const WaitSetAttachmentId<S>& self) -> std::ostream&;
105
116template <ServiceType S>
117class WaitSet {
118 public:
119 WaitSet(const WaitSet&) = delete;
120 auto operator=(const WaitSet&) -> WaitSet& = delete;
121 WaitSet(WaitSet&&) noexcept;
122 auto operator=(WaitSet&&) noexcept -> WaitSet&;
124
149 auto wait_and_process(const iox2::bb::StaticFunction<CallbackProgression(WaitSetAttachmentId<S>)>& fn_call)
150 -> bb::Expected<WaitSetRunResult, WaitSetRunError>;
151
179 auto wait_and_process_once(const iox2::bb::StaticFunction<CallbackProgression(WaitSetAttachmentId<S>)>& fn_call)
180 -> bb::Expected<WaitSetRunResult, WaitSetRunError>;
181
209 auto wait_and_process_once_with_timeout(
210 const iox2::bb::StaticFunction<CallbackProgression(WaitSetAttachmentId<S>)>& fn_call,
211 iox2::bb::Duration timeout) -> bb::Expected<WaitSetRunResult, WaitSetRunError>;
212
214 auto capacity() const -> uint64_t;
215
217 auto len() const -> uint64_t;
218
220 auto is_empty() const -> bool;
221
231 auto attach_notification(const Listener<S>& listener) -> bb::Expected<WaitSetGuard<S>, WaitSetAttachmentError>;
232
242 auto attach_notification(const FileDescriptorBased& attachment)
243 -> bb::Expected<WaitSetGuard<S>, WaitSetAttachmentError>;
244
255 auto attach_deadline(const Listener<S>& listener, iox2::bb::Duration deadline)
256 -> bb::Expected<WaitSetGuard<S>, WaitSetAttachmentError>;
257
268 auto attach_deadline(const FileDescriptorBased& attachment, iox2::bb::Duration deadline)
269 -> bb::Expected<WaitSetGuard<S>, WaitSetAttachmentError>;
270
277 auto attach_interval(iox2::bb::Duration deadline) -> bb::Expected<WaitSetGuard<S>, WaitSetAttachmentError>;
278
280 auto signal_handling_mode() const -> SignalHandlingMode;
281
282 private:
283 friend class WaitSetBuilder;
284 explicit WaitSet(iox2_waitset_h handle);
285 void drop();
286
287 iox2_waitset_h m_handle = nullptr;
288};
289
292 public:
296#ifdef DOXYGEN_MACRO_FIX
297 auto signal_handling_mode(const SignalHandlingMode value) -> decltype(auto);
298#else
299 IOX2_BUILDER_OPTIONAL(SignalHandlingMode, signal_handling_mode);
300#endif
301
302 public:
304 ~WaitSetBuilder() = default;
305
308 auto operator=(const WaitSetBuilder&) -> WaitSetBuilder& = delete;
310
312 template <ServiceType S>
313 auto create() const&& -> bb::Expected<WaitSet<S>, WaitSetCreateError>;
314
315 private:
316 iox2_waitset_builder_h m_handle = nullptr;
317};
318} // namespace iox2
319#endif
#define IOX2_BUILDER_OPTIONAL(type, name)
Definition builder.hpp:47
Abstract class that can be implemented by a class that is based on a [FileDescriptor].
Represents the receiving endpoint of an event based communication.
Definition listener.hpp:33
Represents an attachment to the [WaitSet].
Definition waitset.hpp:57
auto has_missed_deadline(const WaitSetGuard< S > &guard) const -> bool
Returns true if the deadline for the attachment corresponding to [WaitSetGuard] was missed.
auto operator=(const WaitSetAttachmentId &rhs) -> WaitSetAttachmentId &=delete
auto operator=(WaitSetAttachmentId &&rhs) noexcept -> WaitSetAttachmentId &
WaitSetAttachmentId(WaitSetAttachmentId &&rhs) noexcept
auto hash() const -> std::size_t
Returns the a non-secure hash for the [WaitSetAttachmentId].
auto has_event_from(const WaitSetGuard< S > &guard) const -> bool
WaitSetAttachmentId(const WaitSetAttachmentId &rhs)=delete
static auto from_guard(const WaitSetGuard< S > &guard) -> WaitSetAttachmentId
The builder for the [WaitSet].
Definition waitset.hpp:291
auto operator=(const WaitSetBuilder &) -> WaitSetBuilder &=delete
~WaitSetBuilder()=default
auto create() const &&-> bb::Expected< WaitSet< S >, WaitSetCreateError >
Creates the [WaitSet].
auto operator=(WaitSetBuilder &&) -> WaitSetBuilder &=delete
WaitSetBuilder(WaitSetBuilder &&)=delete
auto signal_handling_mode(const SignalHandlingMode value) -> decltype(auto)
WaitSetBuilder(const WaitSetBuilder &)=delete
friend class WaitSetAttachmentId
Definition waitset.hpp:48
WaitSetGuard(WaitSetGuard &&) noexcept
WaitSet(const WaitSet &)=delete
auto operator=(const WaitSet &) -> WaitSet &=delete
WaitSet(WaitSet &&) noexcept
WaitSetRunResult
States why the [WaitSet::run()] method returned.
WaitSetRunError
Defines the failures that can occur when calling [WaitSet::run()].
WaitSetCreateError
Defines the failures that can occur when calling [WaitSetBuilder::create()].
WaitSetAttachmentError