libgpiod
Loading...
Searching...
No Matches
timestamp.hpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/* SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl> */
3
8#ifndef __LIBGPIOD_CXX_TIMESTAMP_HPP__
9#define __LIBGPIOD_CXX_TIMESTAMP_HPP__
10
11#if !defined(__LIBGPIOD_GPIOD_CXX_INSIDE__)
12#error "Only gpiod.hpp can be included directly."
13#endif
14
15#include <chrono>
16#include <cstdint>
17
18namespace gpiod {
19
24class timestamp final
25{
26public:
27
31 using time_point_monotonic = ::std::chrono::time_point<::std::chrono::steady_clock>;
32
36 using time_point_realtime = ::std::chrono::time_point<::std::chrono::system_clock,
37 ::std::chrono::nanoseconds>;
38
43 timestamp(::std::uint64_t ns) : _m_ns(ns) { }
44
49 timestamp(const timestamp& other) noexcept = default;
50
55 timestamp(timestamp&& other) noexcept = default;
56
62 timestamp& operator=(const timestamp& other) noexcept = default;
63
69 timestamp& operator=(timestamp&& other) noexcept = default;
70
71 ~timestamp() = default;
72
76 operator ::std::uint64_t() noexcept
77 {
78 return this->ns();
79 }
80
85 ::std::uint64_t ns() const noexcept
86 {
87 return this->_m_ns;
88 }
89
95 {
96 return time_point_monotonic(::std::chrono::nanoseconds(this->ns()));
97 }
98
104 {
105 return time_point_realtime(::std::chrono::nanoseconds(this->ns()));
106 }
107
108private:
109 ::std::uint64_t _m_ns;
110};
111
112} /* namespace gpiod */
113
114#endif /* __LIBGPIOD_CXX_TIMESTAMP_HPP__ */
Stores the edge and info event timestamps as returned by the kernel and allows to convert them to std...
Definition timestamp.hpp:25
timestamp & operator=(timestamp &&other) noexcept=default
Move assignment operator.
::std::uint64_t ns() const noexcept
Get the timestamp in nanoseconds.
Definition timestamp.hpp:85
timestamp(timestamp &&other) noexcept=default
Move constructor.
::std::chrono::time_point<::std::chrono::steady_clock > time_point_monotonic
Monotonic time_point.
Definition timestamp.hpp:31
::std::chrono::time_point<::std::chrono::system_clock, ::std::chrono::nanoseconds > time_point_realtime
Real-time time_point.
Definition timestamp.hpp:36
timestamp(const timestamp &other) noexcept=default
Copy constructor.
timestamp & operator=(const timestamp &other) noexcept=default
Assignment operator.
time_point_realtime to_time_point_realtime() const
Convert the timestamp to a real-time time_point.
Definition timestamp.hpp:103
timestamp(::std::uint64_t ns)
Constructor with implicit conversion from uint64_t.
Definition timestamp.hpp:43
~timestamp()=default
time_point_monotonic to_time_point_monotonic() const
Convert the timestamp to a monotonic time_point.
Definition timestamp.hpp:94
Definition chip-info.hpp:18