iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
port_factory_reader.hpp
Go to the documentation of this file.
1// Copyright (c) 2025 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_READER_HPP
14#define IOX2_PORTFACTORY_READER_HPP
15
16#include "iox2/bb/expected.hpp"
17#include "iox2/reader.hpp"
18#include "iox2/reader_error.hpp"
19#include "iox2/service_type.hpp"
20
21namespace iox2 {
24template <ServiceType S, typename KeyType>
26 public:
27 PortFactoryReader(PortFactoryReader&&) noexcept = default;
28 auto operator=(PortFactoryReader&&) noexcept -> PortFactoryReader& = default;
29 ~PortFactoryReader() = default;
30
32 auto operator=(const PortFactoryReader&) -> PortFactoryReader& = delete;
33
35 auto create() && -> bb::Expected<Reader<S, KeyType>, ReaderCreateError>;
36
37 private:
38 template <ServiceType, typename>
40
41 explicit PortFactoryReader(iox2_port_factory_reader_builder_h handle);
42
43 iox2_port_factory_reader_builder_h m_handle = nullptr;
44};
45
46template <ServiceType S, typename KeyType>
47inline PortFactoryReader<S, KeyType>::PortFactoryReader(iox2_port_factory_reader_builder_h handle)
48 : m_handle { handle } {
49}
50
51template <ServiceType S, typename KeyType>
53 iox2_reader_h reader_handle {};
54 auto result = iox2_port_factory_reader_builder_create(m_handle, nullptr, &reader_handle);
55
56 if (result == IOX2_OK) {
57 return Reader<S, KeyType>(reader_handle);
58 }
59
60 return bb::err(bb::into<ReaderCreateError>(result));
61}
62} // namespace iox2
63
64#endif
Represents the port factory of a [Service] with [MessagingPattern::Blackboard].
PortFactoryReader(PortFactoryReader &&) noexcept=default
auto create() &&-> bb::Expected< Reader< S, KeyType >, ReaderCreateError >
Creates a new [Reader] port or returns a [ReaderCreateError] on failure.
Reading endpoint of a blackboard based communication.
Definition reader.hpp:27
constexpr auto err(const E &error) -> Unexpected< E >
Definition expected.hpp:33
iox2::bb::variation::Expected< T, E > Expected
Definition expected.hpp:22
ReaderCreateError