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