iceoryx2
C++ Bindings
Loading...
Searching...
No Matches
unique_node_id.hpp
Go to the documentation of this file.
1// Copyright (c) 2024 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_UNIQUE_NODE_ID_HPP
14#define IOX2_UNIQUE_NODE_ID_HPP
15
16#include "iox2/bb/expected.hpp"
17#include "iox2/bb/into.hpp"
19#include "iox2/iceoryx2.h"
20#include "iox2/service_type.hpp"
22
23#include <cstdint>
24#include <ctime>
25#include <iostream>
26
27namespace iox2 {
28namespace internal {
29template <ServiceType>
30auto list_callback(
31 iox2_node_state_e, iox2_unique_node_id_ptr, const char*, iox2_node_name_ptr, iox2_config_ptr, iox2_callback_context)
32 -> iox2_callback_progression_e;
33}
34
37 public:
39 UniqueNodeId(UniqueNodeId&& rhs) noexcept;
40 auto operator=(const UniqueNodeId& rhs) -> UniqueNodeId&;
41 auto operator=(UniqueNodeId&& rhs) noexcept -> UniqueNodeId&;
43
45 auto value_high() const -> uint64_t;
46
48 auto value_low() const -> uint64_t;
49
51 template <ServiceType T>
52 auto pid() const -> bb::Expected<int32_t, UniqueIdGeneratorDetailsError>;
53
55 template <ServiceType T>
56 auto creation_time() const -> bb::Expected<timespec, UniqueIdGeneratorDetailsError>;
57
58 private:
59 template <ServiceType>
60 friend class Node;
61 template <ServiceType>
62 friend class DeadNodeView;
63 template <ServiceType>
64 friend auto internal::list_callback(iox2_node_state_e,
65 iox2_unique_node_id_ptr,
66 const char*,
67 iox2_node_name_ptr,
68 iox2_config_ptr,
69 iox2_callback_context) -> iox2_callback_progression_e;
70 friend class ClientDetailsView;
71 friend class ServerDetailsView;
72 friend class NotifierDetailsView;
73 friend class ListenerDetailsView;
75 friend class ReaderDetailsView;
77 friend class WriterDetailsView;
78
79 explicit UniqueNodeId(iox2_unique_node_id_h handle);
80 void drop();
81
82 iox2_unique_node_id_h m_handle = nullptr;
83};
84
85template <ServiceType T>
86inline auto UniqueNodeId::pid() const -> bb::Expected<int32_t, UniqueIdGeneratorDetailsError> {
87 int32_t pid = 0;
88 auto result = iox2_unique_node_id_pid(&m_handle, iox2::bb::into<iox2_service_type_e>(T), &pid);
89 if (result == IOX2_OK) {
90 return pid;
91 }
92 return bb::err(bb::into<UniqueIdGeneratorDetailsError>(result));
93}
94
95template <ServiceType T>
96inline auto UniqueNodeId::creation_time() const -> bb::Expected<timespec, UniqueIdGeneratorDetailsError> {
97 uint64_t seconds = 0;
98 uint32_t nanoseconds = 0;
99 auto result =
100 iox2_unique_node_id_creation_time(&m_handle, iox2::bb::into<iox2_service_type_e>(T), &seconds, &nanoseconds);
101 if (result == IOX2_OK) {
102 return timespec { static_cast<decltype(timespec::tv_sec)>(seconds),
103 static_cast<decltype(timespec::tv_nsec)>(nanoseconds) };
104 }
105 return bb::err(bb::into<UniqueIdGeneratorDetailsError>(result));
106}
107
108auto operator<<(std::ostream& stream, const UniqueNodeId& node) -> std::ostream&;
109auto operator==(const UniqueNodeId& lhs, const UniqueNodeId& rhs) -> bool;
110auto operator!=(const UniqueNodeId& lhs, const UniqueNodeId& rhs) -> bool;
111} // namespace iox2
112
113#endif
Contains the communication settings of the connected [Client].
Contains all details of a [Node] that is dead.
Contains the communication settings of the connected [Listener].
Contains the communication settings of the connected [Notifier].
Contains the communication settings of the connected [Publisher].
Contains the communication settings of the connected [Reader].
Contains the communication settings of the connected [Server].
Contains the communication settings of the connected [Subscriber].
The system-wide unique id of a [Node].
auto operator=(UniqueNodeId &&rhs) noexcept -> UniqueNodeId &
auto operator=(const UniqueNodeId &rhs) -> UniqueNodeId &
UniqueNodeId(const UniqueNodeId &rhs)
auto creation_time() const -> bb::Expected< timespec, UniqueIdGeneratorDetailsError >
Returns the time the [Node] was created.
auto value_high() const -> uint64_t
Returns the high bits of the underlying value of the [NodeId].
UniqueNodeId(UniqueNodeId &&rhs) noexcept
auto value_low() const -> uint64_t
Returns the low bits of the underlying value of the [NodeId].
auto pid() const -> bb::Expected< int32_t, UniqueIdGeneratorDetailsError >
Returns the [ProcessId] of the process that owns the [Node].
friend auto internal::list_callback(iox2_node_state_e, iox2_unique_node_id_ptr, const char *, iox2_node_name_ptr, iox2_config_ptr, iox2_callback_context) -> iox2_callback_progression_e
Contains the communication settings of the connected [Writer].
constexpr auto err(const E &error) -> Unexpected< E >
Definition expected.hpp:33
auto list_callback(iox2_node_state_e node_state, iox2_unique_node_id_ptr node_id_ptr, const char *executable, iox2_node_name_ptr node_name, iox2_config_ptr config, iox2_callback_context context) -> iox2_callback_progression_e
auto operator==(const EventId &lhs, const EventId &rhs) -> bool
auto operator!=(const EventId &lhs, const EventId &rhs) -> bool
auto operator<<(std::ostream &stream, const EventId &value) -> std::ostream &