Implement access to parsed OpenPOWER VPD
This change implements the access API to retrieve parsed OpenPOWER VPD.
Access is provided only to supported and valid VPD. This is achieved by
having template specializations for a valid record:keyword combination.
Change-Id: I1ec39a94bf947bebade861fd7d9c74ccaa4ac96d
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/defines.hpp b/defines.hpp
index 1da3ab6..6b0ce45 100644
--- a/defines.hpp
+++ b/defines.hpp
@@ -13,6 +13,31 @@
OSYS /**< Information specific to a system board */
};
+/** @brief Convert VPD Record name from enum to string
+ * @tparam R - VPD Record
+ * @returns string representation of Record name
+ */
+template<Record R>
+constexpr const char* getRecord() = delete;
+
+template<>
+constexpr const char* getRecord<Record::VINI>()
+{
+ return "VINI";
+}
+
+template<>
+constexpr const char* getRecord<Record::OPFR>()
+{
+ return "OPFR";
+}
+
+template<>
+constexpr const char* getRecord<Record::OSYS>()
+{
+ return "OSYS";
+}
+
namespace record
{
@@ -30,6 +55,67 @@
MM /**< FRU model */
};
+/** @brief Convert VPD Keyword name from enum to string
+ * @tparam K - VPD Keyword
+ * @returns string representation of Keyword name
+ */
+template<Keyword K>
+constexpr const char* getKeyword() = delete;
+
+template<>
+constexpr const char* getKeyword<Keyword::DR>()
+{
+ return "DR";
+}
+
+template<>
+constexpr const char* getKeyword<Keyword::PN>()
+{
+ return "PN";
+}
+
+template<>
+constexpr const char* getKeyword<Keyword::SN>()
+{
+ return "SN";
+}
+
+template<>
+constexpr const char* getKeyword<Keyword::CC>()
+{
+ return "CC";
+}
+
+template<>
+constexpr const char* getKeyword<Keyword::HW>()
+{
+ return "HW";
+}
+
+template<>
+constexpr const char* getKeyword<Keyword::B1>()
+{
+ return "B1";
+}
+
+template<>
+constexpr const char* getKeyword<Keyword::VN>()
+{
+ return "VN";
+}
+
+template<>
+constexpr const char* getKeyword<Keyword::MB>()
+{
+ return "MB";
+}
+
+template<>
+constexpr const char* getKeyword<Keyword::MM>()
+{
+ return "MM";
+}
+
} // namespace record
} // namespace vpd
} // namespace openpower
diff --git a/store.hpp b/store.hpp
index e9cbeba..9da07f4 100644
--- a/store.hpp
+++ b/store.hpp
@@ -53,5 +53,23 @@
Parsed vpd;
};
+template<Record R, record::Keyword K>
+inline const std::string& Store::get() const
+{
+ static const std::string record = getRecord<R>();
+ static const std::string keyword = record::getKeyword<K>();
+ static const std::string empty = "";
+ auto kw = vpd.find(record);
+ if (vpd.end() != kw)
+ {
+ auto value = (kw->second).find(keyword);
+ if ((kw->second).end() != value)
+ {
+ return value->second;
+ }
+ }
+ return empty;
+}
+
} // namespace vpd
} // namespace openpower