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