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