iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
entry_handle.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_ENTRY_HANDLE_HPP
14#define IOX2_ENTRY_HANDLE_HPP
15
16#include "iox2/event_id.hpp"
17#include "iox2/service_type.hpp"
18#include <cstdint>
19
20namespace iox2 {
22template <typename ValueType>
24 public:
25 auto operator*() -> ValueType&;
26
27 private:
28 template <ServiceType, typename, typename>
29 friend class EntryHandle;
30
31 BlackboardValue(ValueType& value, uint64_t generation_counter);
32
33 ValueType m_value;
34 uint64_t m_generation_counter;
35};
36
37template <typename ValueType>
38inline BlackboardValue<ValueType>::BlackboardValue(ValueType& value, uint64_t generation_counter)
39 : m_value { value }
40 , m_generation_counter { generation_counter } {
41}
42
43template <typename ValueType>
44inline auto BlackboardValue<ValueType>::operator*() -> ValueType& {
45 return m_value;
46}
47
49template <ServiceType S, typename KeyType, typename ValueType>
51 public:
52 EntryHandle(EntryHandle&& rhs) noexcept;
53 auto operator=(EntryHandle&& rhs) noexcept -> EntryHandle&;
55
56 EntryHandle(const EntryHandle&) = delete;
57 auto operator=(const EntryHandle&) -> EntryHandle& = delete;
58
60 auto get() const -> BlackboardValue<ValueType>;
61
63 auto is_up_to_date(BlackboardValue<ValueType>& value) const -> bool;
64
67 auto entry_id() const -> EventId;
68
69 private:
70 template <ServiceType, typename>
71 friend class Reader;
72
73 explicit EntryHandle(iox2_entry_handle_h handle);
74 void drop();
75
76 iox2_entry_handle_h m_handle = nullptr;
77};
78
79template <ServiceType S, typename KeyType, typename ValueType>
80inline EntryHandle<S, KeyType, ValueType>::EntryHandle(iox2_entry_handle_h handle)
81 : m_handle { handle } {
82}
83
84template <ServiceType S, typename KeyType, typename ValueType>
85inline void EntryHandle<S, KeyType, ValueType>::drop() {
86 if (m_handle != nullptr) {
87 iox2_entry_handle_drop(m_handle);
88 m_handle = nullptr;
89 }
90}
91
92template <ServiceType S, typename KeyType, typename ValueType>
94 *this = std::move(rhs);
95}
96
97template <ServiceType S, typename KeyType, typename ValueType>
99 if (this != &rhs) {
100 drop();
101 m_handle = rhs.m_handle;
102 rhs.m_handle = nullptr;
103 }
104
105 return *this;
106}
107
108template <ServiceType S, typename KeyType, typename ValueType>
112
113template <ServiceType S, typename KeyType, typename ValueType>
115 iox2_event_id_t entry_id {};
116
117 iox2_entry_handle_entry_id(&m_handle, &entry_id);
118
119 return EventId { entry_id };
120}
121
122template <ServiceType S, typename KeyType, typename ValueType>
124 ValueType value;
125 uint64_t counter { 0 };
126
127 iox2_entry_handle_get(&m_handle, &value, sizeof(ValueType), alignof(ValueType), &counter);
128
129 return BlackboardValue<ValueType>(value, counter);
130}
131
132template <ServiceType S, typename KeyType, typename ValueType>
134 return iox2_entry_handle_is_up_to_date(&m_handle, value.m_generation_counter);
135}
136} // namespace iox2
137
138#endif
A wrapper for the value returned by [EntryHandle::get()].
auto operator*() -> ValueType &
A handle for direct read access to a specific blackboard value.
auto operator=(const EntryHandle &) -> EntryHandle &=delete
auto entry_id() const -> EventId
EntryHandle(EntryHandle &&rhs) noexcept
EntryHandle(const EntryHandle &)=delete
auto get() const -> BlackboardValue< ValueType >
Returns a copy of the value wrapped in a [BlackboardValue].
auto is_up_to_date(BlackboardValue< ValueType > &value) const -> bool
Checks if the passed value is up-to-date.
auto operator=(EntryHandle &&rhs) noexcept -> EntryHandle &
Type that allows to identify an event uniquely.
Definition event_id.hpp:22
Reading endpoint of a blackboard based communication.
Definition reader.hpp:27