| 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | /* SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> */ |
| 3 | |
| 4 | /** |
| 5 | * @file line-config.hpp |
| 6 | */ |
| 7 | |
| 8 | #ifndef __LIBGPIOD_CXX_LINE_CONFIG_HPP__ |
| 9 | #define __LIBGPIOD_CXX_LINE_CONFIG_HPP__ |
| 10 | |
| 11 | #if !defined(__LIBGPIOD_GPIOD_CXX_INSIDE__) |
| 12 | #error "Only gpiod.hpp can be included directly." |
| 13 | #endif |
| 14 | |
| 15 | #include <map> |
| 16 | #include <memory> |
| 17 | |
| 18 | namespace gpiod { |
| 19 | |
| 20 | class chip; |
| 21 | class line_request; |
| 22 | class line_settings; |
| 23 | |
| 24 | /** |
| 25 | * @brief Contains a set of line config options used in line requests and |
| 26 | * reconfiguration. |
| 27 | */ |
| 28 | class line_config final |
| 29 | { |
| 30 | public: |
| 31 | |
| 32 | |
| 33 | line_config(); |
| 34 | |
| 35 | line_config(const line_config& other) = delete; |
| 36 | |
| 37 | /** |
| 38 | * @brief Move constructor. |
| 39 | * @param other Object to move. |
| 40 | */ |
| 41 | line_config(line_config&& other) noexcept; |
| 42 | |
| 43 | ~line_config(); |
| 44 | |
| 45 | /** |
| 46 | * @brief Move assignment operator. |
| 47 | * @param other Object to move. |
| 48 | * @return Reference to self. |
| 49 | */ |
| 50 | line_config& operator=(line_config&& other) noexcept; |
| 51 | |
| 52 | /** |
| 53 | * @brief Reset the line config object. |
| 54 | * @return Reference to self. |
| 55 | */ |
| 56 | line_config& reset() noexcept; |
| 57 | |
| 58 | /** |
| 59 | * @brief Add line settings for a single offset. |
| 60 | * @param offset Offset for which to add settings. |
| 61 | * @param settings Line settings to add. |
| 62 | * @return Reference to self. |
| 63 | */ |
| 64 | line_config& add_line_settings(line::offset offset, const line_settings& settings); |
| 65 | |
| 66 | /** |
| 67 | * @brief Add line settings for a set of offsets. |
| 68 | * @param offsets Offsets for which to add settings. |
| 69 | * @param settings Line settings to add. |
| 70 | * @return Reference to self. |
| 71 | */ |
| 72 | line_config& add_line_settings(const line::offsets& offsets, const line_settings& settings); |
| 73 | |
| 74 | /** |
| 75 | * @brief Set output values for a number of lines. |
| 76 | * @param values Buffer containing the output values. |
| 77 | * @return Reference to self. |
| 78 | */ |
| 79 | line_config& set_output_values(const line::values& values); |
| 80 | |
| 81 | /** |
| 82 | * @brief Get a mapping of offsets to line settings stored by this |
| 83 | * object. |
| 84 | * @return Map in which keys represent line offsets and values are |
| 85 | * the settings corresponding with them. |
| 86 | */ |
| 87 | ::std::map<line::offset, line_settings> get_line_settings() const; |
| 88 | |
| 89 | private: |
| 90 | |
| 91 | struct impl; |
| 92 | |
| 93 | ::std::shared_ptr<impl> _m_priv; |
| 94 | |
| 95 | line_config& operator=(const line_config& other); |
| 96 | |
| 97 | friend line_request; |
| 98 | friend request_builder; |
| 99 | }; |
| 100 | |
| 101 | /** |
| 102 | * @brief Stream insertion operator for GPIO line config objects. |
| 103 | * @param out Output stream to write to. |
| 104 | * @param config Line config object to insert into the output stream. |
| 105 | * @return Reference to out. |
| 106 | */ |
| 107 | ::std::ostream& operator<<(::std::ostream& out, const line_config& config); |
| 108 | |
| 109 | } /* namespace gpiod */ |
| 110 | |
| 111 | #endif /* __LIBGPIOD_CXX_LINE_CONFIG_HPP__ */ |