From 35c7fb166734da24777f0204518bd47d66cac6a0 Mon Sep 17 00:00:00 2001 From: Deepak Kodihalli Date: Mon, 21 Nov 2016 04:32:44 -0600 Subject: Add API to provide access to parsed OpenPOWER VPD This change adds the Store class, which serves as a store for parsed OpenPOWER VPD, as well as provides access to the VPD specified by a record:keyword combination. Change-Id: Ie9efe5825a3e799d78b59333c06955b0214a6823 Signed-off-by: Deepak Kodihalli --- store.hpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ types.hpp | 18 ++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 store.hpp create mode 100644 types.hpp diff --git a/store.hpp b/store.hpp new file mode 100644 index 0000000..e9cbeba --- /dev/null +++ b/store.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include +#include +#include "defines.hpp" +#include "types.hpp" + +namespace openpower +{ +namespace vpd +{ + +/** @brief Parsed VPD is represented as a dictionary of records, where + * each record in itself is a dictionary of keywords */ +using Parsed = + std::unordered_map>; + +/** @class Store + * @brief Store for parsed OpenPOWER VPD + * + * A Store object stores parsed OpenPOWER VPD, and provides access + * to the VPD, specified by record and keyword. Parsed VPD is typically + * provided by the Parser class. + */ +class Store final +{ + public: + Store() = delete; + Store(const Store&) = delete; + Store& operator=(const Store&) = delete; + Store(Store&&) = default; + Store& operator=(Store&&) = default; + ~Store() = default; + + /** @brief Construct a Store + * + * @param[in] vpdBuffer - A parsed VPD object + */ + explicit Store(Parsed&& vpdBuffer): vpd(std::move(vpdBuffer)) {} + + /** @brief Retrives VPD from Store + * + * @tparam R - VPD record + * @tparam K - VPD keyword + * @returns VPD stored in input record:keyword + */ + template + inline const std::string& get() const; + + private: + /** @brief The store for parsed VPD */ + Parsed vpd; +}; + +} // namespace vpd +} // namespace openpower diff --git a/types.hpp b/types.hpp new file mode 100644 index 0000000..7e56eb4 --- /dev/null +++ b/types.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +namespace openpower +{ +namespace vpd +{ + +/** @brief The OpenPOWER VPD, in binary, is specified as a + * sequence of characters */ +static_assert((8 == CHAR_BIT), "A byte is not 8 bits!"); +using Byte = uint8_t; +using Binary = std::vector; + +} // namespace vpd +} // namespace openpower -- cgit v1.2.1