iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
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_WRITER_HPP
14
#define IOX2_WRITER_HPP
15
16
#include "
iox2/bb/expected.hpp
"
17
#include "
iox2/entry_handle_mut.hpp
"
18
#include "
iox2/entry_handle_mut_error.hpp
"
19
#include "
iox2/internal/service_builder_internal.hpp
"
20
#include "
iox2/service_type.hpp
"
21
#include "
iox2/unique_port_id.hpp
"
22
23
namespace
iox2
{
25
template
<ServiceType S,
typename
KeyType>
26
class
Writer
{
27
public
:
28
Writer
(
Writer
&& rhs)
noexcept
;
29
auto
operator=
(
Writer
&& rhs)
noexcept
->
Writer
&;
30
~Writer
();
31
32
Writer
(
const
Writer
&) =
delete
;
33
auto
operator=
(
const
Writer
&) ->
Writer
& =
delete
;
34
36
auto
id
() const ->
UniqueWriterId
;
37
40
template <typename ValueType>
41
auto
entry
(const KeyType& key) -> bb::Expected<
EntryHandleMut
<S, KeyType, ValueType>,
EntryHandleMutError
>;
42
43
private:
44
template <
ServiceType
, typename>
45
friend class
PortFactoryWriter
;
46
47
explicit
Writer
(iox2_writer_h handle);
48
void
drop();
49
50
iox2_writer_h m_handle =
nullptr
;
51
};
52
53
template <
ServiceType
S, typename KeyType>
54
inline
Writer
<S, KeyType>::
Writer
(iox2_writer_h handle)
55
: m_handle { handle } {
56
}
57
58
template
<ServiceType S,
typename
KeyType>
59
inline
void
Writer<S, KeyType>::drop() {
60
if
(m_handle !=
nullptr
) {
61
iox2_writer_drop(m_handle);
62
m_handle =
nullptr
;
63
}
64
}
65
66
template
<ServiceType S,
typename
KeyType>
67
inline
Writer<S, KeyType>::Writer
(
Writer
&& rhs)
noexcept
{
68
*
this
= std::move(rhs);
69
}
70
71
template
<ServiceType S,
typename
KeyType>
72
inline
auto
Writer<S, KeyType>::operator=
(
Writer
&& rhs)
noexcept
->
Writer
& {
73
if
(
this
!= &rhs) {
74
drop();
75
m_handle = rhs.m_handle;
76
rhs.m_handle =
nullptr
;
77
}
78
79
return
*
this
;
80
}
81
82
template
<ServiceType S,
typename
KeyType>
83
inline
Writer<S, KeyType>::~Writer
() {
84
drop();
85
}
86
87
template
<ServiceType S,
typename
KeyType>
88
inline
auto
Writer<S, KeyType>::id
() const ->
UniqueWriterId
{
89
iox2_unique_writer_id_h id_handle =
nullptr
;
90
91
iox2_writer_id(&m_handle,
nullptr
, &id_handle);
92
return
UniqueWriterId
{ id_handle };
93
}
94
95
template
<ServiceType S,
typename
KeyType>
96
template
<
typename
ValueType>
97
inline
auto
Writer<S, KeyType>::entry
(
const
KeyType& key)
98
->
bb::Expected<EntryHandleMut<S, KeyType, ValueType>
,
EntryHandleMutError
> {
99
iox2_entry_handle_mut_h entry_handle {};
100
const
auto
type_name = internal::get_type_name<ValueType>();
101
102
auto
result = iox2_writer_entry(&m_handle,
103
nullptr
,
104
&entry_handle,
105
&key,
106
type_name.unchecked_access().c_str(),
107
type_name.size(),
108
sizeof
(ValueType),
109
alignof
(ValueType));
110
111
if
(result == IOX2_OK) {
112
return
EntryHandleMut<S, KeyType, ValueType>
(entry_handle);
113
}
114
115
return
bb::err
(bb::into<EntryHandleMutError>(result));
116
}
117
}
// namespace iox2
118
119
#endif
expected.hpp
iox2::EntryHandleMut
A handle for direct write access to a specific blackboard value.
Definition
entry_handle_mut.hpp:23
iox2::PortFactoryWriter
Definition
port_factory_writer.hpp:25
iox2::UniqueWriterId
The system-wide unique id of a [Writer].
Definition
unique_port_id.hpp:204
iox2::Writer
Producing endpoint of a blackboard based communication.
Definition
writer.hpp:26
iox2::Writer::Writer
Writer(Writer &&rhs) noexcept
Definition
writer.hpp:67
iox2::Writer::id
auto id() const -> UniqueWriterId
Returns the [UniqueWriterId] of the [Writer].
Definition
writer.hpp:88
iox2::Writer::entry
auto entry(const KeyType &key) -> bb::Expected< EntryHandleMut< S, KeyType, ValueType >, EntryHandleMutError >
Definition
writer.hpp:97
iox2::Writer::operator=
auto operator=(const Writer &) -> Writer &=delete
iox2::Writer::operator=
auto operator=(Writer &&rhs) noexcept -> Writer &
Definition
writer.hpp:72
iox2::Writer::~Writer
~Writer()
Definition
writer.hpp:83
iox2::Writer::Writer
Writer(const Writer &)=delete
entry_handle_mut.hpp
entry_handle_mut_error.hpp
iox2::bb::err
constexpr auto err(const E &error) -> Unexpected< E >
Definition
expected.hpp:33
iox2::bb::Expected
iox2::bb::variation::Expected< T, E > Expected
Definition
expected.hpp:22
iox2
Definition
active_request.hpp:26
iox2::ServiceType
ServiceType
Definition
service_type.hpp:21
iox2::EntryHandleMutError
EntryHandleMutError
Defines a failure that can occur when a [EntryHandleMut] is created with [Writer::entry()].
Definition
entry_handle_mut_error.hpp:20
service_builder_internal.hpp
service_type.hpp
unique_port_id.hpp
iox2
writer.hpp
Generated by
1.9.8