| 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | /* SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> */ |
| 3 | |
| 4 | /** |
| 5 | * @file edge-event.hpp |
| 6 | */ |
| 7 | |
| 8 | #ifndef __LIBGPIOD_CXX_EDGE_EVENT_HPP__ |
| 9 | #define __LIBGPIOD_CXX_EDGE_EVENT_HPP__ |
| 10 | |
| 11 | #if !defined(__LIBGPIOD_GPIOD_CXX_INSIDE__) |
| 12 | #error "Only gpiod.hpp can be included directly." |
| 13 | #endif |
| 14 | |
| 15 | #include <cstdint> |
| 16 | #include <iostream> |
| 17 | #include <memory> |
| 18 | |
| 19 | #include "timestamp.hpp" |
| 20 | |
| 21 | namespace gpiod { |
| 22 | |
| 23 | class edge_event_buffer; |
| 24 | |
| 25 | /** |
| 26 | * @brief Immutable object containing data about a single edge event. |
| 27 | */ |
| 28 | class edge_event final |
| 29 | { |
| 30 | public: |
| 31 | |
| 32 | /** |
| 33 | * @brief Edge event types. |
| 34 | */ |
| 35 | enum class event_type |
| 36 | { |
| 37 | RISING_EDGE = 1, |
| 38 | /**< This is a rising edge event. */ |
| 39 | FALLING_EDGE, |
| 40 | /**< This is falling edge event. */ |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * @brief Copy constructor. |
| 45 | * @param other Object to copy. |
| 46 | */ |
| 47 | edge_event(const edge_event& other); |
| 48 | |
| 49 | /** |
| 50 | * @brief Move constructor. |
| 51 | * @param other Object to move. |
| 52 | */ |
| 53 | edge_event(edge_event&& other) noexcept; |
| 54 | |
| 55 | ~edge_event(); |
| 56 | |
| 57 | /** |
| 58 | * @brief Copy assignment operator. |
| 59 | * @param other Object to copy. |
| 60 | * @return Reference to self. |
| 61 | */ |
| 62 | edge_event& operator=(const edge_event& other); |
| 63 | |
| 64 | /** |
| 65 | * @brief Move assignment operator. |
| 66 | * @param other Object to move. |
| 67 | * @return Reference to self. |
| 68 | */ |
| 69 | edge_event& operator=(edge_event&& other) noexcept; |
| 70 | |
| 71 | /** |
| 72 | * @brief Retrieve the event type. |
| 73 | * @return Event type (rising or falling edge). |
| 74 | */ |
| 75 | event_type type() const; |
| 76 | |
| 77 | /** |
| 78 | * @brief Retrieve the event time-stamp. |
| 79 | * @return Time-stamp in nanoseconds as registered by the kernel using |
| 80 | * the configured edge event clock. |
| 81 | */ |
| 82 | timestamp timestamp_ns() const noexcept; |
| 83 | |
| 84 | /** |
| 85 | * @brief Read the offset of the line on which this event was |
| 86 | * registered. |
| 87 | * @return Line offset. |
| 88 | */ |
| 89 | line::offset line_offset() const noexcept; |
| 90 | |
| 91 | /** |
| 92 | * @brief Get the global sequence number of this event. |
| 93 | * @return Sequence number of the event relative to all lines in the |
| 94 | * associated line request. |
| 95 | */ |
| 96 | unsigned long global_seqno() const noexcept; |
| 97 | |
| 98 | /** |
| 99 | * @brief Get the event sequence number specific to the concerned line. |
| 100 | * @return Sequence number of the event relative to this line within |
| 101 | * the lifetime of the associated line request. |
| 102 | */ |
| 103 | unsigned long line_seqno() const noexcept; |
| 104 | |
| 105 | private: |
| 106 | |
| 107 | edge_event(); |
| 108 | |
| 109 | struct impl; |
| 110 | struct impl_managed; |
| 111 | struct impl_external; |
| 112 | |
| 113 | ::std::shared_ptr<impl> _m_priv; |
| 114 | |
| 115 | friend edge_event_buffer; |
| 116 | }; |
| 117 | |
| 118 | /** |
| 119 | * @brief Stream insertion operator for edge events. |
| 120 | * @param out Output stream to write to. |
| 121 | * @param event Edge event to insert into the output stream. |
| 122 | * @return Reference to out. |
| 123 | */ |
| 124 | ::std::ostream& operator<<(::std::ostream& out, const edge_event& event); |
| 125 | |
| 126 | } /* namespace gpiod */ |
| 127 | |
| 128 | #endif /* __LIBGPIOD_CXX_EDGE_EVENT_HPP__ */ |