Tom Joseph | 2be58bc | 2017-02-09 19:54:12 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <algorithm> |
Andrew Geissler | 9d9b763 | 2020-05-17 09:18:05 -0500 | [diff] [blame] | 4 | #include <cstddef> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 5 | #include <cstdint> |
Tom Joseph | 2be58bc | 2017-02-09 19:54:12 +0530 | [diff] [blame] | 6 | #include <deque> |
| 7 | #include <vector> |
| 8 | |
| 9 | namespace sol |
| 10 | { |
| 11 | |
| 12 | using ConsoleBuffer = std::deque<uint8_t>; |
Tom Joseph | 2be58bc | 2017-02-09 19:54:12 +0530 | [diff] [blame] | 13 | |
| 14 | /** @class ConsoleData |
| 15 | * |
| 16 | * The console data is the buffer that holds the data that comes from the host |
| 17 | * console which is to be sent to the remote console. The buffer is needed due |
| 18 | * to the latency with the IPMI remote client. The current support for the |
| 19 | * buffer is to support one instance of the SOL payload. |
| 20 | */ |
| 21 | class ConsoleData |
| 22 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 23 | public: |
| 24 | /** @brief Get the current size of the host console buffer. |
| 25 | * |
| 26 | * @return size of the host console buffer. |
| 27 | */ |
| 28 | auto size() const noexcept |
| 29 | { |
| 30 | return data.size(); |
| 31 | } |
Tom Joseph | 2be58bc | 2017-02-09 19:54:12 +0530 | [diff] [blame] | 32 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 33 | /** @brief Read host console data. |
| 34 | * |
| 35 | * This API would return the iterator to the read data from the |
| 36 | * console data buffer. |
| 37 | * |
| 38 | * @return iterator to read data from the buffer |
| 39 | */ |
| 40 | auto read() const |
| 41 | { |
| 42 | return data.cbegin(); |
| 43 | } |
Tom Joseph | 2be58bc | 2017-02-09 19:54:12 +0530 | [diff] [blame] | 44 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 45 | /** @brief Write host console data. |
| 46 | * |
| 47 | * This API would append the input data to the host console buffer. |
| 48 | * |
| 49 | * @param[in] input - data to be written to the console buffer. |
| 50 | */ |
| 51 | void write(const std::vector<uint8_t>& input) |
| 52 | { |
| 53 | data.insert(data.end(), input.begin(), input.end()); |
| 54 | } |
Tom Joseph | 2be58bc | 2017-02-09 19:54:12 +0530 | [diff] [blame] | 55 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 56 | /** @brief Erase console buffer. |
| 57 | * |
| 58 | * @param[in] size - the number of bytes to be erased from the console |
| 59 | * buffer. |
| 60 | * |
| 61 | * @note If the console buffer has less bytes that that was requested, |
| 62 | * then the available size is erased. |
| 63 | */ |
| 64 | void erase(size_t size) noexcept |
| 65 | { |
| 66 | data.erase(data.begin(), data.begin() + std::min(data.size(), size)); |
| 67 | } |
Tom Joseph | 2be58bc | 2017-02-09 19:54:12 +0530 | [diff] [blame] | 68 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 69 | private: |
| 70 | /** @brief Storage for host console data. */ |
| 71 | ConsoleBuffer data; |
Tom Joseph | 2be58bc | 2017-02-09 19:54:12 +0530 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | } // namespace sol |