12be58bcbSTom Joseph #pragma once
22be58bcbSTom Joseph 
32be58bcbSTom Joseph #include <algorithm>
4*9e801a2bSVernon Mauery #include <cstdint>
52be58bcbSTom Joseph #include <deque>
62be58bcbSTom Joseph #include <vector>
72be58bcbSTom Joseph 
82be58bcbSTom Joseph namespace sol
92be58bcbSTom Joseph {
102be58bcbSTom Joseph 
112be58bcbSTom Joseph using ConsoleBuffer = std::deque<uint8_t>;
122be58bcbSTom Joseph 
132be58bcbSTom Joseph /** @class ConsoleData
142be58bcbSTom Joseph  *
152be58bcbSTom Joseph  *  The console data is the buffer that holds the data that comes from the host
162be58bcbSTom Joseph  *  console which is to be sent to the remote console. The buffer is needed due
172be58bcbSTom Joseph  *  to the latency with the IPMI remote client. The current support for the
182be58bcbSTom Joseph  *  buffer is to support one instance of the SOL payload.
192be58bcbSTom Joseph  */
202be58bcbSTom Joseph class ConsoleData
212be58bcbSTom Joseph {
222be58bcbSTom Joseph   public:
232be58bcbSTom Joseph     /** @brief Get the current size of the host console buffer.
242be58bcbSTom Joseph      *
252be58bcbSTom Joseph      *  @return size of the host console buffer.
262be58bcbSTom Joseph      */
272be58bcbSTom Joseph     auto size() const noexcept
282be58bcbSTom Joseph     {
292be58bcbSTom Joseph         return data.size();
302be58bcbSTom Joseph     }
312be58bcbSTom Joseph 
322be58bcbSTom Joseph     /** @brief Read host console data.
332be58bcbSTom Joseph      *
342be58bcbSTom Joseph      *  This API would return the iterator to the read data from the
352be58bcbSTom Joseph      *  console data buffer.
362be58bcbSTom Joseph      *
372be58bcbSTom Joseph      *  @return iterator to read data from the buffer
382be58bcbSTom Joseph      */
392be58bcbSTom Joseph     auto read() const
402be58bcbSTom Joseph     {
412be58bcbSTom Joseph         return data.cbegin();
422be58bcbSTom Joseph     }
432be58bcbSTom Joseph 
442be58bcbSTom Joseph     /** @brief Write host console data.
452be58bcbSTom Joseph      *
462be58bcbSTom Joseph      *  This API would append the input data to the host console buffer.
472be58bcbSTom Joseph      *
482be58bcbSTom Joseph      *  @param[in] input - data to be written to the console buffer.
492be58bcbSTom Joseph      */
5070fd29cfSVernon Mauery     void write(const std::vector<uint8_t>& input)
512be58bcbSTom Joseph     {
522be58bcbSTom Joseph         data.insert(data.end(), input.begin(), input.end());
532be58bcbSTom Joseph     }
542be58bcbSTom Joseph 
552be58bcbSTom Joseph     /** @brief Erase console buffer.
562be58bcbSTom Joseph      *
572be58bcbSTom Joseph      *  @param[in] size - the number of bytes to be erased from the console
582be58bcbSTom Joseph      *                    buffer.
592be58bcbSTom Joseph      *
602be58bcbSTom Joseph      *  @note If the console buffer has less bytes that that was requested,
612be58bcbSTom Joseph      *        then the available size is erased.
622be58bcbSTom Joseph      */
632be58bcbSTom Joseph     void erase(size_t size) noexcept
642be58bcbSTom Joseph     {
65*9e801a2bSVernon Mauery         data.erase(data.begin(), data.begin() + std::min(data.size(), size));
662be58bcbSTom Joseph     }
672be58bcbSTom Joseph 
682be58bcbSTom Joseph   private:
692be58bcbSTom Joseph     /** @brief Storage for host console data. */
702be58bcbSTom Joseph     ConsoleBuffer data;
712be58bcbSTom Joseph };
722be58bcbSTom Joseph 
732be58bcbSTom Joseph } // namespace sol
74