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
138 auto wait_and_process(const iox2::bb::StaticFunction<CallbackProgression(WaitSetAttachmentId<S>)>& fn_call)
139 -> bb::Expected<WaitSetRunResult, WaitSetRunError>;
140
157 auto wait_and_process_once(const iox2::bb::StaticFunction<CallbackProgression(WaitSetAttachmentId<S>)>& fn_call)
158 -> bb::Expected<WaitSetRunResult, WaitSetRunError>;
159
176 auto wait_and_process_once_with_timeout(
177 const iox2::bb::StaticFunction<CallbackProgression(WaitSetAttachmentId<S>)>& fn_call,
178 iox2::bb::Duration timeout) -> bb::Expected<WaitSetRunResult, WaitSetRunError>;
179
181 auto capacity() const -> uint64_t;
182
184 auto len() const -> uint64_t;
185
187 auto is_empty() const -> bool;
188
198 auto attach_notification(const Listener<S>& listener) -> bb::Expected<WaitSetGuard<S>, WaitSetAttachmentError>;
199
209 auto attach_notification(const FileDescriptorBased& attachment)
210 -> bb::Expected<WaitSetGuard<S>, WaitSetAttachmentError>;
211
222 auto attach_deadline(const Listener<S>& listener, iox2::bb::Duration deadline)
223 -> bb::Expected<WaitSetGuard<S>, WaitSetAttachmentError>;
224
235 auto attach_deadline(const FileDescriptorBased& attachment, iox2::bb::Duration deadline)
236 -> bb::Expected<WaitSetGuard<S>, WaitSetAttachmentError>;
237
244 auto attach_interval(iox2::bb::Duration deadline) -> bb::Expected<WaitSetGuard<S>, WaitSetAttachmentError>;
245
247 auto signal_handling_mode() const -> SignalHandlingMode;
248
249 private:
250 friend class WaitSetBuilder;
251 explicit WaitSet(iox2_waitset_h handle);
252 void drop();
253
254 iox2_waitset_h m_handle = nullptr;
255};
256
259 public:
263#ifdef DOXYGEN_MACRO_FIX
264 auto signal_handling_mode(const SignalHandlingMode value) -> decltype(auto);
265#else
266 IOX2_BUILDER_OPTIONAL(SignalHandlingMode, signal_handling_mode);
267#endif
268
269 public:
271 ~WaitSetBuilder() = default;
272
275 auto operator=(const WaitSetBuilder&) -> WaitSetBuilder& = delete;
277
279 template <ServiceType S>
280 auto create() const&& -> bb::Expected<WaitSet<S>, WaitSetCreateError>;
281
282 private:
283 iox2_waitset_builder_h m_handle = nullptr;
284};
285} // namespace iox2
286#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:32
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:258
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