| 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | /* SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> */ |
| 3 | |
| 4 | /** |
| 5 | * @file request-builder.hpp |
| 6 | */ |
| 7 | |
| 8 | #ifndef __LIBGPIOD_CXX_REQUEST_BUILDER_HPP__ |
| 9 | #define __LIBGPIOD_CXX_REQUEST_BUILDER_HPP__ |
| 10 | |
| 11 | #if !defined(__LIBGPIOD_GPIOD_CXX_INSIDE__) |
| 12 | #error "Only gpiod.hpp can be included directly." |
| 13 | #endif |
| 14 | |
| 15 | #include <memory> |
| 16 | #include <ostream> |
| 17 | |
| 18 | namespace gpiod { |
| 19 | |
| 20 | class chip; |
| 21 | class line_config; |
| 22 | class line_request; |
| 23 | class request_config; |
| 24 | |
| 25 | /** |
| 26 | * @brief Intermediate object storing the configuration for a line request. |
| 27 | */ |
| 28 | class request_builder final |
| 29 | { |
| 30 | public: |
| 31 | |
| 32 | request_builder(const request_builder& other) = delete; |
| 33 | |
| 34 | /** |
| 35 | * @brief Move constructor. |
| 36 | * @param other Object to be moved. |
| 37 | */ |
| 38 | request_builder(request_builder&& other) noexcept; |
| 39 | |
| 40 | ~request_builder(); |
| 41 | |
| 42 | request_builder& operator=(const request_builder& other) = delete; |
| 43 | |
| 44 | /** |
| 45 | * @brief Move assignment operator. |
| 46 | * @param other Object to be moved. |
| 47 | * @return Reference to self. |
| 48 | */ |
| 49 | request_builder& operator=(request_builder&& other) noexcept; |
| 50 | |
| 51 | /** |
| 52 | * @brief Set the request config for the request. |
| 53 | * @param req_cfg Request config to use. |
| 54 | * @return Reference to self. |
| 55 | */ |
| 56 | request_builder& set_request_config(request_config& req_cfg); |
| 57 | |
| 58 | /** |
| 59 | * @brief Get the current request config. |
| 60 | * @return Const reference to the current request config stored by this |
| 61 | * object. |
| 62 | */ |
| 63 | const request_config& get_request_config() const noexcept; |
| 64 | |
| 65 | /** |
| 66 | * @brief Set consumer in the request config stored by this object. |
| 67 | * @param consumer New consumer string. |
| 68 | * @return Reference to self. |
| 69 | */ |
| 70 | request_builder& set_consumer(const ::std::string& consumer) noexcept; |
| 71 | |
| 72 | /** |
| 73 | * @brief Set the event buffer size in the request config stored by |
| 74 | * this object. |
| 75 | * @param event_buffer_size New event buffer size. |
| 76 | * @return Reference to self. |
| 77 | */ |
| 78 | request_builder& set_event_buffer_size(::std::size_t event_buffer_size) noexcept; |
| 79 | |
| 80 | /** |
| 81 | * @brief Set the line config for this request. |
| 82 | * @param line_cfg Line config to use. |
| 83 | * @return Reference to self. |
| 84 | */ |
| 85 | request_builder& set_line_config(line_config &line_cfg); |
| 86 | |
| 87 | /** |
| 88 | * @brief Get the current line config. |
| 89 | * @return Const reference to the current line config stored by this |
| 90 | * object. |
| 91 | */ |
| 92 | const line_config& get_line_config() const noexcept; |
| 93 | |
| 94 | /** |
| 95 | * @brief Add line settings to the line config stored by this object |
| 96 | * for a single offset. |
| 97 | * @param offset Offset for which to add settings. |
| 98 | * @param settings Line settings to use. |
| 99 | * @return Reference to self. |
| 100 | */ |
| 101 | request_builder& add_line_settings(line::offset offset, const line_settings& settings); |
| 102 | |
| 103 | /** |
| 104 | * @brief Add line settings to the line config stored by this object |
| 105 | * for a set of offsets. |
| 106 | * @param offsets Offsets for which to add settings. |
| 107 | * @param settings Settings to add. |
| 108 | * @return Reference to self. |
| 109 | */ |
| 110 | request_builder& add_line_settings(const line::offsets& offsets, const line_settings& settings); |
| 111 | |
| 112 | /** |
| 113 | * @brief Set output values for a number of lines in the line config |
| 114 | * stored by this object. |
| 115 | * @param values Buffer containing the output values. |
| 116 | * @return Reference to self. |
| 117 | */ |
| 118 | request_builder& set_output_values(const line::values& values); |
| 119 | |
| 120 | /** |
| 121 | * @brief Make the line request. |
| 122 | * @return New line_request object. |
| 123 | */ |
| 124 | line_request do_request(); |
| 125 | |
| 126 | private: |
| 127 | |
| 128 | struct impl; |
| 129 | |
| 130 | request_builder(chip& chip); |
| 131 | |
| 132 | ::std::unique_ptr<impl> _m_priv; |
| 133 | |
| 134 | friend chip; |
| 135 | friend ::std::ostream& operator<<(::std::ostream& out, const request_builder& builder); |
| 136 | }; |
| 137 | |
| 138 | /** |
| 139 | * @brief Stream insertion operator for GPIO request builder objects. |
| 140 | * @param out Output stream to write to. |
| 141 | * @param builder Request builder object to insert into the output stream. |
| 142 | * @return Reference to out. |
| 143 | */ |
| 144 | ::std::ostream& operator<<(::std::ostream& out, const request_builder& builder); |
| 145 | |
| 146 | } /* namespace gpiod */ |
| 147 | |
| 148 | #endif /* __LIBGPIOD_CXX_REQUEST_BUILDER_HPP__ */ |