iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
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_READER_HPP
14
#define IOX2_READER_HPP
15
16
#include "
iox2/bb/detail/assertions.hpp
"
17
#include "
iox2/bb/expected.hpp
"
18
#include "
iox2/entry_handle.hpp
"
19
#include "
iox2/entry_handle_error.hpp
"
20
#include "
iox2/internal/service_builder_internal.hpp
"
21
#include "
iox2/service_type.hpp
"
22
#include "
iox2/unique_port_id.hpp
"
23
24
namespace
iox2
{
26
template
<ServiceType S,
typename
KeyType>
27
class
Reader
{
28
public
:
29
Reader
(
Reader
&& rhs)
noexcept
;
30
auto
operator=
(
Reader
&& rhs)
noexcept
->
Reader
&;
31
~Reader
();
32
33
Reader
(
const
Reader
&) =
delete
;
34
auto
operator=
(
const
Reader
&) ->
Reader
& =
delete
;
35
37
auto
id
() const ->
UniqueReaderId
;
38
40
template <typename ValueType>
41
auto
entry
(const KeyType& key) -> bb::Expected<
EntryHandle
<S, KeyType, ValueType>,
EntryHandleError
>;
42
43
private:
44
template <
ServiceType
, typename>
45
friend class
PortFactoryReader
;
46
47
explicit
Reader
(iox2_reader_h handle);
48
void
drop();
49
50
iox2_reader_h m_handle =
nullptr
;
51
};
52
53
template <
ServiceType
S, typename KeyType>
54
inline
Reader
<S, KeyType>::
Reader
(iox2_reader_h handle)
55
: m_handle { handle } {
56
}
57
58
template
<ServiceType S,
typename
KeyType>
59
inline
void
Reader<S, KeyType>::drop() {
60
if
(m_handle !=
nullptr
) {
61
// NOTE: false positive; m_handle is initialized in the class itself
62
#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__))
63
#pragma GCC diagnostic push
64
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
65
#endif
66
iox2_reader_drop(m_handle);
67
#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__))
68
#pragma GCC diagnostic pop
69
#endif
70
m_handle =
nullptr
;
71
}
72
}
73
74
template
<ServiceType S,
typename
KeyType>
75
inline
Reader<S, KeyType>::Reader
(
Reader
&& rhs)
noexcept
{
76
*
this
= std::move(rhs);
77
}
78
79
template
<ServiceType S,
typename
KeyType>
80
inline
auto
Reader<S, KeyType>::operator=
(
Reader
&& rhs)
noexcept
->
Reader
& {
81
if
(
this
!= &rhs) {
82
drop();
83
m_handle = rhs.m_handle;
84
rhs.m_handle =
nullptr
;
85
}
86
87
return
*
this
;
88
}
89
90
template
<ServiceType S,
typename
KeyType>
91
inline
Reader<S, KeyType>::~Reader
() {
92
drop();
93
}
94
95
template
<ServiceType S,
typename
KeyType>
96
inline
auto
Reader<S, KeyType>::id
() const ->
UniqueReaderId
{
97
iox2_unique_reader_id_h id_handle =
nullptr
;
98
99
iox2_reader_id(&m_handle,
nullptr
, &id_handle);
100
return
UniqueReaderId
{ id_handle };
101
}
102
103
template
<ServiceType S,
typename
KeyType>
104
template
<
typename
ValueType>
105
inline
auto
Reader<S, KeyType>::entry
(
const
KeyType& key)
106
->
bb::Expected<EntryHandle<S, KeyType, ValueType>
,
EntryHandleError
> {
107
iox2_entry_handle_h entry_handle {};
108
const
auto
type_name = internal::get_type_name<ValueType>();
109
110
auto
result = iox2_reader_entry(&m_handle,
111
nullptr
,
112
&entry_handle,
113
&key,
114
type_name.unchecked_access().c_str(),
115
type_name.size(),
116
sizeof
(ValueType),
117
alignof
(ValueType));
118
119
if
(result == IOX2_OK) {
120
return
EntryHandle<S, KeyType, ValueType>
(entry_handle);
121
}
122
123
return
bb::err
(bb::into<EntryHandleError>(result));
124
}
125
}
// namespace iox2
126
127
#endif
assertions.hpp
expected.hpp
iox2::EntryHandle
A handle for direct read access to a specific blackboard value.
Definition
entry_handle.hpp:50
iox2::PortFactoryReader
Definition
port_factory_reader.hpp:25
iox2::Reader
Reading endpoint of a blackboard based communication.
Definition
reader.hpp:27
iox2::Reader::~Reader
~Reader()
Definition
reader.hpp:91
iox2::Reader::id
auto id() const -> UniqueReaderId
Returns the [UniqueReaderId] of the [Reader].
Definition
reader.hpp:96
iox2::Reader::operator=
auto operator=(const Reader &) -> Reader &=delete
iox2::Reader::operator=
auto operator=(Reader &&rhs) noexcept -> Reader &
Definition
reader.hpp:80
iox2::Reader::Reader
Reader(const Reader &)=delete
iox2::Reader::Reader
Reader(Reader &&rhs) noexcept
Definition
reader.hpp:75
iox2::Reader::entry
auto entry(const KeyType &key) -> bb::Expected< EntryHandle< S, KeyType, ValueType >, EntryHandleError >
Creates an [EntryHandle] for direct read access to the value.
Definition
reader.hpp:105
iox2::UniqueReaderId
The system-wide unique id of a [Reader].
Definition
unique_port_id.hpp:179
entry_handle.hpp
entry_handle_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::EntryHandleError
EntryHandleError
Defines a failure that can occur when a [EntryHandle] is created with [Reader::entry()].
Definition
entry_handle_error.hpp:20
iox2::ServiceType
ServiceType
Definition
service_type.hpp:21
service_builder_internal.hpp
service_type.hpp
unique_port_id.hpp
iox2
reader.hpp
Generated by
1.9.8