iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
entry_handle_mut.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_MUT_HPP
14#define IOX2_ENTRY_HANDLE_MUT_HPP
15
17#include "iox2/event_id.hpp"
18#include "iox2/service_type.hpp"
19
20namespace iox2 {
22template <ServiceType S, typename KeyType, typename ValueType>
24 public:
25 EntryHandleMut(EntryHandleMut&& rhs) noexcept;
26 auto operator=(EntryHandleMut&& rhs) noexcept -> EntryHandleMut&;
27 ~EntryHandleMut() noexcept;
28
30 auto operator=(const EntryHandleMut&) -> EntryHandleMut& = delete;
31
33 void update_with_copy(ValueType value);
34
36 template <ServiceType ST, typename KeyT, typename ValueT>
38
41 auto entry_id() const -> EventId;
42
43 private:
44 template <ServiceType, typename>
45 friend class Writer;
46 template <ServiceType ST, typename KeyT, typename ValueT>
47 friend auto update_with_copy(EntryValueUninit<ST, KeyT, ValueT>&&, ValueT) -> EntryHandleMut<ST, KeyT, ValueT>;
48 template <ServiceType ST, typename KeyT, typename ValueT>
49 friend auto discard(EntryValueUninit<ST, KeyT, ValueT>&& self) -> EntryHandleMut<ST, KeyT, ValueT>;
50 template <ServiceType ST, typename KeyT, typename ValueT>
51 friend auto assume_init_and_update(EntryValueUninit<ST, KeyT, ValueT>&& self) -> EntryHandleMut<ST, KeyT, ValueT>;
52
53 explicit EntryHandleMut(iox2_entry_handle_mut_h handle);
54
55 void drop();
56
57 auto take_handle_ownership() -> iox2_entry_handle_mut_h;
58
59 iox2_entry_handle_mut_h m_handle = nullptr;
60};
61
62template <ServiceType S, typename KeyType, typename ValueType>
63inline EntryHandleMut<S, KeyType, ValueType>::EntryHandleMut(iox2_entry_handle_mut_h handle)
64 : m_handle { handle } {
65}
66
67template <ServiceType S, typename KeyType, typename ValueType>
69 *this = std::move(rhs);
70}
71
72template <ServiceType S, typename KeyType, typename ValueType>
74 if (this != &rhs) {
75 drop();
76 m_handle = rhs.m_handle;
77 rhs.m_handle = nullptr;
78 }
79
80 return *this;
81}
82
83template <ServiceType S, typename KeyType, typename ValueType>
87
88template <ServiceType S, typename KeyType, typename ValueType>
90 // NOLINTNEXTLINE(cppcoreguidelines-owning-memory): required by C API
91 auto value_ptr = new ValueType(value);
92 iox2_entry_handle_mut_update_with_copy(&m_handle, value_ptr, sizeof(ValueType), alignof(ValueType));
93 // NOLINTNEXTLINE(cppcoreguidelines-owning-memory): required by C API
94 delete value_ptr;
95}
96
97template <ServiceType S, typename KeyType, typename ValueType>
101
102template <ServiceType S, typename KeyType, typename ValueType>
104 iox2_event_id_t entry_id {};
105
106 iox2_entry_handle_mut_entry_id(&m_handle, &entry_id);
107
108 return EventId { entry_id };
109}
110
111template <ServiceType S, typename KeyType, typename ValueType>
113 if (m_handle != nullptr) {
114 iox2_entry_handle_mut_drop(m_handle);
115 m_handle = nullptr;
116 }
117}
118
119template <ServiceType S, typename KeyType, typename ValueType>
120inline auto EntryHandleMut<S, KeyType, ValueType>::take_handle_ownership() -> iox2_entry_handle_mut_h {
121 auto* result = m_handle;
122 m_handle = nullptr;
123 return result;
124}
125} // namespace iox2
126
127#endif
A handle for direct write access to a specific blackboard value.
auto operator=(const EntryHandleMut &) -> EntryHandleMut &=delete
auto entry_id() const -> EventId
EntryHandleMut(EntryHandleMut &&rhs) noexcept
friend auto update_with_copy(EntryValueUninit< ST, KeyT, ValueT > &&, ValueT) -> EntryHandleMut< ST, KeyT, ValueT >
EntryHandleMut(const EntryHandleMut &)=delete
friend auto loan_uninit(EntryHandleMut< ST, KeyT, ValueT > &&self) -> EntryValueUninit< ST, KeyT, ValueT >
Consumes the [EntryHandleMut] and loans an uninitialized entry value that can be used to update witho...
auto operator=(EntryHandleMut &&rhs) noexcept -> EntryHandleMut &
friend auto discard(EntryValueUninit< ST, KeyT, ValueT > &&self) -> EntryHandleMut< ST, KeyT, ValueT >
friend auto assume_init_and_update(EntryValueUninit< ST, KeyT, ValueT > &&self) -> EntryHandleMut< ST, KeyT, ValueT >
Wrapper around an uninitialized entry value that can be used for a zero-copy update.
Type that allows to identify an event uniquely.
Definition event_id.hpp:22
Producing endpoint of a blackboard based communication.
Definition writer.hpp:26