blob: dbb75c940c0d1dd9defe2fe0d8e07be672fae52f [file] [log] [blame]
Tom Joseph2be58bc2017-02-09 19:54:12 +05301#pragma once
2
3#include <algorithm>
Andrew Geissler9d9b7632020-05-17 09:18:05 -05004#include <cstddef>
Vernon Mauery9e801a22018-10-12 13:20:49 -07005#include <cstdint>
Tom Joseph2be58bc2017-02-09 19:54:12 +05306#include <deque>
7#include <vector>
8
9namespace sol
10{
11
12using ConsoleBuffer = std::deque<uint8_t>;
Tom Joseph2be58bc2017-02-09 19:54:12 +053013
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 */
21class ConsoleData
22{
Vernon Mauery9e801a22018-10-12 13:20:49 -070023 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 Joseph2be58bc2017-02-09 19:54:12 +053032
Vernon Mauery9e801a22018-10-12 13:20:49 -070033 /** @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 Joseph2be58bc2017-02-09 19:54:12 +053044
Vernon Mauery9e801a22018-10-12 13:20:49 -070045 /** @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 Joseph2be58bc2017-02-09 19:54:12 +053055
Vernon Mauery9e801a22018-10-12 13:20:49 -070056 /** @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 Joseph2be58bc2017-02-09 19:54:12 +053068
Vernon Mauery9e801a22018-10-12 13:20:49 -070069 private:
70 /** @brief Storage for host console data. */
71 ConsoleBuffer data;
Tom Joseph2be58bc2017-02-09 19:54:12 +053072};
73
74} // namespace sol