iceoryx2
C++ 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:
40 auto operator=(PortFactoryWriter&& rhs) noexcept -> PortFactoryWriter&;
42
45
48
49 private:
50 template <ServiceType, typename>
52
53 explicit PortFactoryWriter(iox2_port_factory_writer_builder_h handle);
54 void drop();
55
56 iox2_port_factory_writer_builder_h m_handle = nullptr;
57};
58
59template <ServiceType S, typename KeyType>
60inline PortFactoryWriter<S, KeyType>::PortFactoryWriter(iox2_port_factory_writer_builder_h handle)
61 : m_handle { handle } {
62}
63
64template <ServiceType S, typename KeyType>
65inline void PortFactoryWriter<S, KeyType>::drop() {
66 if (m_handle != nullptr) {
67 iox2_port_factory_writer_builder_drop(m_handle);
68 m_handle = nullptr;
69 }
70}
71
72template <ServiceType S, typename KeyType>
74 *this = std::move(rhs);
75}
76
77template <ServiceType S, typename KeyType>
79 if (this != &rhs) {
80 drop();
81 m_handle = rhs.m_handle;
82 rhs.m_handle = nullptr;
83 m_name = std::move(rhs.m_name);
84 }
85
86 return *this;
87}
88
89template <ServiceType S, typename KeyType>
93
94template <ServiceType S, typename KeyType>
96 if (m_name.has_value()) {
97 const auto* name_ptr = m_name.value().as_view().native_ptr();
98 iox2_port_factory_writer_builder_set_name(&m_handle, name_ptr);
99 }
100
101 iox2_writer_h writer_handle {};
102 auto result = iox2_port_factory_writer_builder_create(m_handle, nullptr, &writer_handle);
103 m_handle = nullptr;
104
105 if (result == IOX2_OK) {
106 return Writer<S, KeyType>(writer_handle);
107 }
108
109 return bb::err(bb::into<WriterCreateError>(result));
110}
111} // namespace iox2
112
113#endif
#define IOX2_BUILDER_OPTIONAL(type, name)
Definition builder.hpp:47
auto operator=(PortFactoryWriter &&rhs) noexcept -> PortFactoryWriter &
PortFactoryWriter(PortFactoryWriter &&rhs) noexcept
auto name(const PortName value) -> decltype(auto)
auto operator=(const PortFactoryWriter &) -> PortFactoryWriter &=delete
auto create() &&-> bb::Expected< Writer< S, KeyType >, WriterCreateError >
Creates a new [Writer] port or returns a [WriterCreateError] on failure.
PortFactoryWriter(const PortFactoryWriter &)=delete
Represent the name for a [Port].
Definition port_name.hpp:52
Producing endpoint of a blackboard based communication.
Definition writer.hpp:27
constexpr auto into(const SourceType value) noexcept -> typename detail::ExtractIntoType< DestinationType >::TargetType
Converts a value of type SourceType to a corresponding value of type DestinationType....
Definition into.hpp:120
constexpr auto err(const E &error) -> Unexpected< E >
Definition expected.hpp:33
iox2::bb::variation::Expected< T, E > Expected
Definition expected.hpp:22
WriterCreateError