blob: 51383cf3b8d0d21bf3e4c31654cfc3b3d4fcac7a [file] [log] [blame]
Tom Joseph2be58bc2017-02-09 19:54:12 +05301#pragma once
2
3#include <algorithm>
Vernon Mauery9e801a22018-10-12 13:20:49 -07004#include <cstdint>
Tom Joseph2be58bc2017-02-09 19:54:12 +05305#include <deque>
6#include <vector>
7
8namespace sol
9{
10
11using ConsoleBuffer = std::deque<uint8_t>;
Tom Joseph2be58bc2017-02-09 19:54:12 +053012
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 */
20class ConsoleData
21{
Vernon Mauery9e801a22018-10-12 13:20:49 -070022 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 Joseph2be58bc2017-02-09 19:54:12 +053031
Vernon Mauery9e801a22018-10-12 13:20:49 -070032 /** @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 Joseph2be58bc2017-02-09 19:54:12 +053043
Vernon Mauery9e801a22018-10-12 13:20:49 -070044 /** @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 Joseph2be58bc2017-02-09 19:54:12 +053054
Vernon Mauery9e801a22018-10-12 13:20:49 -070055 /** @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 Joseph2be58bc2017-02-09 19:54:12 +053067
Vernon Mauery9e801a22018-10-12 13:20:49 -070068 private:
69 /** @brief Storage for host console data. */
70 ConsoleBuffer data;
Tom Joseph2be58bc2017-02-09 19:54:12 +053071};
72
73} // namespace sol