iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
port_factory_publish_subscribe.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_PORTFACTORY_PUBLISH_SUBSCRIBE_HPP
14#define IOX2_PORTFACTORY_PUBLISH_SUBSCRIBE_HPP
15
17#include "iox2/bb/expected.hpp"
25#include "iox2/node_state.hpp"
28#include "iox2/service_hash.hpp"
29#include "iox2/service_name.hpp"
30#include "iox2/service_type.hpp"
32
33namespace iox2 {
37template <ServiceType S, typename Payload, typename UserHeader>
39 public:
43
46
48 auto name() const -> ServiceNameView;
49
51 auto service_hash() const -> ServiceHash;
52
54 auto attributes() const -> AttributeSetView;
55
59
63
68 auto nodes(const iox2::bb::StaticFunction<CallbackProgression(NodeState<S>)>& callback) const
69 -> bb::Expected<void, NodeListFailure>;
70
72 auto subscriber_builder() const -> PortFactorySubscriber<S, Payload, UserHeader>;
73
75 auto publisher_builder() const -> PortFactoryPublisher<S, Payload, UserHeader>;
76
82
90 auto blocking_cleanup_dead_nodes(iox2::bb::Duration timeout) const -> CleanupState;
91
92 private:
93 template <typename, typename, ServiceType>
95
96 explicit PortFactoryPublishSubscribe(iox2_port_factory_pub_sub_h handle);
97 void drop();
98
99 iox2_port_factory_pub_sub_h m_handle = nullptr;
100};
101
102template <ServiceType S, typename Payload, typename UserHeader>
103inline PortFactoryPublishSubscribe<S, Payload, UserHeader>::PortFactoryPublishSubscribe(
104 iox2_port_factory_pub_sub_h handle)
105 : m_handle { handle } {
106}
107
108template <ServiceType S, typename Payload, typename UserHeader>
109inline void PortFactoryPublishSubscribe<S, Payload, UserHeader>::drop() {
110 if (m_handle != nullptr) {
111 iox2_port_factory_pub_sub_drop(m_handle);
112 m_handle = nullptr;
113 }
114}
115
116template <ServiceType S, typename Payload, typename UserHeader>
121
122template <ServiceType S, typename Payload, typename UserHeader>
125 if (this != &rhs) {
126 drop();
127 m_handle = rhs.m_handle;
128 rhs.m_handle = nullptr;
129 }
130
131 return *this;
132}
133
134template <ServiceType S, typename Payload, typename UserHeader>
138
139template <ServiceType S, typename Payload, typename UserHeader>
141 const auto* service_name_ptr = iox2_port_factory_pub_sub_service_name(&m_handle);
142 return ServiceNameView(service_name_ptr);
143}
144
145template <ServiceType S, typename Payload, typename UserHeader>
148 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-avoid-unchecked-container-access) index 0 is guaranteed to be valid
149 iox2_port_factory_pub_sub_service_hash(&m_handle, &buffer[0], IOX2_SERVICE_HASH_LENGTH);
150
152 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-avoid-unchecked-container-access) index 0 is guaranteed to be valid
153 &buffer[0],
154 IOX2_SERVICE_HASH_LENGTH));
155}
156
157template <ServiceType S, typename Payload, typename UserHeader>
159 return AttributeSetView(iox2_port_factory_pub_sub_attributes(&m_handle));
160}
161
162template <ServiceType S, typename Payload, typename UserHeader>
164 iox2_static_config_publish_subscribe_t static_config {};
165 iox2_port_factory_pub_sub_static_config(&m_handle, &static_config);
166
168}
169
170template <ServiceType S, typename Payload, typename UserHeader>
175
176template <ServiceType S, typename Payload, typename UserHeader>
178 iox2_cleanup_state_t cleanup_state {};
179
180 iox2_port_factory_pub_sub_try_cleanup_dead_nodes(&m_handle, &cleanup_state);
181
182 CleanupState ret_val {};
183 ret_val.cleanups = cleanup_state.cleanups;
184 ret_val.failed_cleanups = cleanup_state.failed_cleanups;
185 return ret_val;
186}
187
188template <ServiceType T, typename Payload, typename UserHeader>
189inline auto
191 -> CleanupState {
192 iox2_cleanup_state_t cleanup_state {};
193
194 iox2_port_factory_pub_sub_blocking_cleanup_dead_nodes(
195 &m_handle, &cleanup_state, timeout.as_secs(), timeout.subsec_nanos());
196
197 CleanupState ret_val {};
198 ret_val.cleanups = cleanup_state.cleanups;
199 ret_val.failed_cleanups = cleanup_state.failed_cleanups;
200 return ret_val;
201}
202
203template <ServiceType S, typename Payload, typename UserHeader>
207 auto ctx = internal::ctx(callback);
208
209 const auto ret_val =
210 iox2_port_factory_pub_sub_nodes(&m_handle, internal::list_callback<S>, static_cast<void*>(&ctx));
211
212 if (ret_val == IOX2_OK) {
213 return {};
214 }
215
216 return bb::err(bb::into<NodeListFailure>(ret_val));
217}
218
219template <ServiceType S, typename Payload, typename UserHeader>
221 -> PortFactorySubscriber<S, Payload, UserHeader> {
223 iox2_port_factory_pub_sub_subscriber_builder(&m_handle, nullptr));
224}
225
226template <ServiceType S, typename Payload, typename UserHeader>
228 -> PortFactoryPublisher<S, Payload, UserHeader> {
230 iox2_port_factory_pub_sub_publisher_builder(&m_handle, nullptr));
231}
232
233
234} // namespace iox2
235
236#endif
Describes the state of a [Node].
auto operator=(const PortFactoryPublishSubscribe &) -> PortFactoryPublishSubscribe &=delete
auto subscriber_builder() const -> PortFactorySubscriber< S, Payload, UserHeader >
Returns a [PortFactorySubscriber] to create a new [Subscriber] port.
auto blocking_cleanup_dead_nodes(iox2::bb::Duration timeout) const -> CleanupState
auto service_hash() const -> ServiceHash
Returns the [ServiceHash] of the [Service].
auto nodes(const iox2::bb::StaticFunction< CallbackProgression(NodeState< S >)> &callback) const -> bb::Expected< void, NodeListFailure >
auto name() const -> ServiceNameView
Returns the [ServiceName] of the service.
PortFactoryPublishSubscribe(const PortFactoryPublishSubscribe &)=delete
auto operator=(PortFactoryPublishSubscribe &&rhs) noexcept -> PortFactoryPublishSubscribe &
auto publisher_builder() const -> PortFactoryPublisher< S, Payload, UserHeader >
Returns a [PortFactoryPublisher] to create a new [Publisher] port.
PortFactoryPublishSubscribe(PortFactoryPublishSubscribe &&rhs) noexcept
auto dynamic_config() const -> DynamicConfigPublishSubscribe
auto attributes() const -> AttributeSetView
Returns the attributes defined in the [Service].
auto static_config() const -> StaticConfigPublishSubscribe
Builder to create new [MessagingPattern::PublishSubscribe] based [Service]s.
Represents the unique if of a [Service].
Non-owning view of a [ServiceName].
Wrapper class for a C-style array of type ElementType and size Capacity. Per default it is uninitiali...
constexpr auto err(const E &error) -> Unexpected< E >
Definition expected.hpp:33
iox2::bb::variation::Expected< T, E > Expected
Definition expected.hpp:22
auto ctx(const T &ptr) -> CallbackContext< T >
NodeListFailure
All failures that can occur in [Node::list()].
uint64_t cleanups
The number of successful dead node cleanups.