diff options
author | Tom Joseph <tomjoseph@in.ibm.com> | 2017-02-09 19:54:12 +0530 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-04-24 11:01:26 +0000 |
commit | 2be58bcb343487151c082e7193e5d09887acc318 (patch) | |
tree | ae95f6f476b6acbe4e55ced0b227335af8d18309 | |
parent | 4173cf8577c80b6c3e6db9ee3aa2fbeb49ada174 (diff) | |
download | phosphor-net-ipmid-2be58bcb343487151c082e7193e5d09887acc318.tar.gz phosphor-net-ipmid-2be58bcb343487151c082e7193e5d09887acc318.zip |
Implement Host Console Buffer
Implement host console buffer to buffer host data and provide
interfaces to read the buffer, write to the buffer and erase
the buffer
Change-Id: I67bec738dee6fa3b22c30aaefe5056edf4fb937c
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | sol/console_buffer.hpp | 74 |
2 files changed, 76 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index fbd2116..7480d0c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,7 +39,8 @@ netipmid_SOURCES = \ provider_registration.hpp \ provider_registration.cpp \ crypt_algo.hpp \ - crypt_algo.cpp + crypt_algo.cpp \ + sol/console_buffer.hpp netipmid_CPPFLAGS = -DNET_IPMID_LIB_PATH=\"/usr/lib/net-ipmid/\" netipmid_LDFLAGS = $(SYSTEMD_LIBS) $(CRYPTO_LIBS) $(libmapper_LIBS) $(LIBADD_DLOPEN) -export-dynamic diff --git a/sol/console_buffer.hpp b/sol/console_buffer.hpp new file mode 100644 index 0000000..b874be5 --- /dev/null +++ b/sol/console_buffer.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include <algorithm> +#include <deque> +#include <vector> + +namespace sol +{ + +using ConsoleBuffer = std::deque<uint8_t>; +using Buffer = std::vector<uint8_t>; + +/** @class ConsoleData + * + * The console data is the buffer that holds the data that comes from the host + * console which is to be sent to the remote console. The buffer is needed due + * to the latency with the IPMI remote client. The current support for the + * buffer is to support one instance of the SOL payload. + */ +class ConsoleData +{ + public: + /** @brief Get the current size of the host console buffer. + * + * @return size of the host console buffer. + */ + auto size() const noexcept + { + return data.size(); + } + + /** @brief Read host console data. + * + * This API would return the iterator to the read data from the + * console data buffer. + * + * @return iterator to read data from the buffer + */ + auto read() const + { + return data.cbegin(); + } + + /** @brief Write host console data. + * + * This API would append the input data to the host console buffer. + * + * @param[in] input - data to be written to the console buffer. + */ + void write(const Buffer& input) + { + data.insert(data.end(), input.begin(), input.end()); + } + + /** @brief Erase console buffer. + * + * @param[in] size - the number of bytes to be erased from the console + * buffer. + * + * @note If the console buffer has less bytes that that was requested, + * then the available size is erased. + */ + void erase(size_t size) noexcept + { + data.erase(data.begin(), data.begin() + std::min(data.size(), + size)); + } + + private: + /** @brief Storage for host console data. */ + ConsoleBuffer data; +}; + +} // namespace sol |