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