1 #pragma once
2 
3 #include <algorithm>
4 #include <cstddef>
5 #include <cstdint>
6 #include <deque>
7 #include <vector>
8 
9 namespace sol
10 {
11 
12 using ConsoleBuffer = std::deque<uint8_t>;
13 
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  */
21 class ConsoleData
22 {
23   public:
24     /** @brief Get the current size of the host console buffer.
25      *
26      *  @return size of the host console buffer.
27      */
size() const28     auto size() const noexcept
29     {
30         return data.size();
31     }
32 
33     /** @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      */
read() const40     auto read() const
41     {
42         return data.cbegin();
43     }
44 
45     /** @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      */
write(const std::vector<uint8_t> & input)51     void write(const std::vector<uint8_t>& input)
52     {
53         data.insert(data.end(), input.begin(), input.end());
54     }
55 
56     /** @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      */
erase(size_t size)64     void erase(size_t size) noexcept
65     {
66         data.erase(data.begin(), data.begin() + std::min(data.size(), size));
67     }
68 
69   private:
70     /** @brief Storage for host console data. */
71     ConsoleBuffer data;
72 };
73 
74 } // namespace sol
75