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
17#include "iox2/bb/expected.hpp"
18#include "iox2/port_name.hpp"
19#include "iox2/service_type.hpp"
20#include "iox2/writer.hpp"
21#include "iox2/writer_error.hpp"
22
23namespace iox2 {
26template <ServiceType S, typename KeyType>
28 public:
32#ifdef DOXYGEN_MACRO_FIX
33 auto name(const PortName value) -> decltype(auto);
34#else
36#endif
37
38 public:
39 PortFactoryWriter(PortFactoryWriter&&) noexcept = default;
40 auto operator=(PortFactoryWriter&&) noexcept -> PortFactoryWriter& = default;
41 ~PortFactoryWriter() = default;
42
44 auto operator=(const PortFactoryWriter&) -> PortFactoryWriter& = delete;
45
47 auto create() && -> bb::Expected<Writer<S, KeyType>, WriterCreateError>;
48
49 private:
50 template <ServiceType, typename>
52
53 explicit PortFactoryWriter(iox2_port_factory_writer_builder_h handle);
54
55 iox2_port_factory_writer_builder_h m_handle = nullptr;
56};
57
58template <ServiceType S, typename KeyType>
59inline PortFactoryWriter<S, KeyType>::PortFactoryWriter(iox2_port_factory_writer_builder_h handle)
60 : m_handle { handle } {
61}
62
63template <ServiceType S, typename KeyType>
65 if (m_name.has_value()) {
66 const auto* name_ptr = m_name.value().as_view().native_ptr();
67 iox2_port_factory_writer_builder_set_name(&m_handle, name_ptr);
68 }
69
70 iox2_writer_h writer_handle {};
71 auto result = iox2_port_factory_writer_builder_create(m_handle, nullptr, &writer_handle);
72
73 if (result == IOX2_OK) {
74 return Writer<S, KeyType>(writer_handle);
75 }
76
77 return bb::err(bb::into<WriterCreateError>(result));
78}
79} // namespace iox2
80
81#endif
#define IOX2_BUILDER_OPTIONAL(type, name)
Definition builder.hpp:47
Represents the port factory of a [Service] with [MessagingPattern::Blackboard].
auto name(const PortName value) -> decltype(auto)
PortFactoryWriter(PortFactoryWriter &&) noexcept=default
auto create() &&-> bb::Expected< Writer< S, KeyType >, WriterCreateError >
Creates a new [Writer] port or returns a [WriterCreateError] on failure.
Represent the name for a [Port].
Definition port_name.hpp:52
Producing endpoint of a blackboard based communication.
Definition writer.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
WriterCreateError