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