blob: b874be5b212eb348d29eb0f27603257c35cf24b7 [file] [log] [blame]
Tom Joseph2be58bc2017-02-09 19:54:12 +05301#pragma once
2
3#include <algorithm>
4#include <deque>
5#include <vector>
6
7namespace sol
8{
9
10using ConsoleBuffer = std::deque<uint8_t>;
11using Buffer = std::vector<uint8_t>;
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 */
20class ConsoleData
21{
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 }
31
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 }
43
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 Buffer& input)
51 {
52 data.insert(data.end(), input.begin(), input.end());
53 }
54
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(),
66 size));
67 }
68
69 private:
70 /** @brief Storage for host console data. */
71 ConsoleBuffer data;
72};
73
74} // namespace sol