summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-11-01 16:29:18 -0700
committerPatrick Venture <venture@google.com>2018-11-08 02:00:20 +0000
commitc83c4dc327447a6aee8ddebcd98963ac411169fb (patch)
tree20cadc16abe7c69e5046bff5460bb5760749b608
parent6c830e9dfa89a6fce124762d1f162e7efc5291dd (diff)
downloadopenpower-vpd-parser-c83c4dc327447a6aee8ddebcd98963ac411169fb.tar.gz
openpower-vpd-parser-c83c4dc327447a6aee8ddebcd98963ac411169fb.zip
Add .clang-format to repo for automated style
Add .clang-format to repo for automated style. A consistent style across Openbmc makes the code easier to read and edit. Change-Id: I7c09792d2482f0be3e01776804347700f3e3e651 Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r--.clang-format99
-rw-r--r--app.cpp25
-rw-r--r--args.cpp33
-rw-r--r--args.hpp4
-rw-r--r--defines.hpp58
-rw-r--r--impl.cpp133
-rw-r--r--impl.hpp166
-rw-r--r--parser.cpp1
-rw-r--r--parser.hpp3
-rw-r--r--store.hpp86
-rw-r--r--test/parser/parser.cpp9
-rw-r--r--test/store/store.cpp6
-rw-r--r--types.hpp4
-rw-r--r--utils.cpp30
-rw-r--r--utils.hpp4
-rw-r--r--write.cpp20
-rw-r--r--write.hpp7
17 files changed, 382 insertions, 306 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..ea71ad6
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,99 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+PointerAlignment: Left
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+ - Regex: '^[<"](gtest|gmock)'
+ Priority: 5
+ - Regex: '^"config.h"'
+ Priority: -1
+ - Regex: '^".*\.hpp"'
+ Priority: 1
+ - Regex: '^<.*\.h>'
+ Priority: 2
+ - Regex: '^<.*'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 4
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
+...
+
diff --git a/app.cpp b/app.cpp
index 876cf61..96c9ee4 100644
--- a/app.cpp
+++ b/app.cpp
@@ -1,12 +1,14 @@
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <iterator>
-#include <exception>
-#include "defines.hpp"
-#include "write.hpp"
#include "args.hpp"
+#include "defines.hpp"
#include "parser.hpp"
+#include "write.hpp"
+
+#include <exception>
+#include <fstream>
+#include <iostream>
+#include <iterator>
+#include <string>
+#include <vector>
int main(int argc, char** argv)
{
@@ -16,7 +18,7 @@ int main(int argc, char** argv)
{
using namespace openpower::vpd;
- args::Args arguments = args::parse(argc, argv);
+ args::Args arguments = args::parse(argc, argv);
// We need vpd file, FRU type and object path
if ((arguments.end() != arguments.find("vpd")) &&
@@ -39,7 +41,7 @@ int main(int argc, char** argv)
if (frus.size() != objects.size())
{
std::cerr << "Unequal number of FRU types and object paths "
- "specified\n";
+ "specified\n";
rc = -1;
}
else
@@ -47,10 +49,7 @@ int main(int argc, char** argv)
// Write VPD to FRU inventory
for (std::size_t index = 0; index < frus.size(); ++index)
{
- inventory::write(
- frus[index],
- vpdStore,
- objects[index]);
+ inventory::write(frus[index], vpdStore, objects[index]);
}
}
}
diff --git a/args.cpp b/args.cpp
index 8ec90dd..673b080 100644
--- a/args.cpp
+++ b/args.cpp
@@ -1,10 +1,12 @@
+#include "args.hpp"
+
#include <getopt.h>
-#include <string>
-#include <vector>
-#include <utility>
+
#include <iostream>
#include <sstream>
-#include "args.hpp"
+#include <string>
+#include <utility>
+#include <vector>
namespace openpower
{
@@ -14,13 +16,12 @@ namespace args
{
static constexpr auto shortForm = "v:f:o:h";
-static const option longForm[] =
-{
- { "vpd", required_argument, nullptr, 'v' },
- { "fru", required_argument, nullptr, 'f' },
- { "object", required_argument, nullptr, 'o' },
- { "help", no_argument, nullptr, 'h' },
- { 0, 0, 0, 0},
+static const option longForm[] = {
+ {"vpd", required_argument, nullptr, 'v'},
+ {"fru", required_argument, nullptr, 'f'},
+ {"object", required_argument, nullptr, 'o'},
+ {"help", no_argument, nullptr, 'h'},
+ {0, 0, 0, 0},
};
void usage(char** argv)
@@ -30,13 +31,15 @@ void usage(char** argv)
std::cerr << "--vpd=<vpd file> pathname of file containing vpd,";
std::cerr << " for eg an eeprom file\n";
std::cerr << "--fru=<FRU type>, supported types:\n";
- std::cerr << "\t" << "bmc\n";
- std::cerr << "\t" << "ethernet\n";
+ std::cerr << "\t"
+ << "bmc\n";
+ std::cerr << "\t"
+ << "ethernet\n";
std::cerr << "Specify multiple FRU types via comma-separated list\n";
std::cerr << "--object=<FRU object path> for eg,";
std::cerr << " chassis/bmc0/planar\n";
std::cerr << "Specify multiple object paths via comma-separated list, "
- "ordered as the FRU types\n";
+ "ordered as the FRU types\n";
std::cerr << "--help display usage\n";
}
@@ -71,7 +74,7 @@ Args parse(int argc, char** argv)
// There could be a comma-separated list
std::string opts(optarg);
std::istringstream stream(std::move(opts));
- std::string input {};
+ std::string input{};
while (std::getline(stream, input, ','))
{
values.push_back(std::move(input));
diff --git a/args.hpp b/args.hpp
index ee82986..02afc67 100644
--- a/args.hpp
+++ b/args.hpp
@@ -2,6 +2,7 @@
#include <string>
#include <unordered_map>
+#include <vector>
namespace openpower
{
@@ -10,8 +11,7 @@ namespace vpd
namespace args
{
-using Args = std::unordered_map<std::string,
- std::vector<std::string>>;
+using Args = std::unordered_map<std::string, std::vector<std::string>>;
/** @brief Command-line argument parser for openpower-read-vpd
*
diff --git a/defines.hpp b/defines.hpp
index dda0530..91eda13 100644
--- a/defines.hpp
+++ b/defines.hpp
@@ -17,22 +17,22 @@ enum class Record
* @tparam R - VPD Record
* @returns string representation of Record name
*/
-template<Record R>
+template <Record R>
constexpr const char* getRecord() = delete;
-template<>
+template <>
constexpr const char* getRecord<Record::VINI>()
{
return "VINI";
}
-template<>
+template <>
constexpr const char* getRecord<Record::OPFR>()
{
return "OPFR";
}
-template<>
+template <>
constexpr const char* getRecord<Record::OSYS>()
{
return "OSYS";
@@ -44,94 +44,94 @@ namespace record
/** @brief OpenPOWER VPD keywords we're interested in */
enum class Keyword
{
- DR, /**< FRU name/description */
- PN, /**< FRU part number */
- SN, /**< FRU serial number */
- CC, /**< Customer Card Identification Number (CCIN) */
- HW, /**< FRU version */
- B1, /**< MAC Address */
- VN, /**< FRU manufacturer name */
- MB, /**< FRU manufacture date */
- MM, /**< FRU model */
- UD, /**< System UUID */
- VS, /**< OpenPower serial number */
- VP /**< OpenPower part number */
+ DR, /**< FRU name/description */
+ PN, /**< FRU part number */
+ SN, /**< FRU serial number */
+ CC, /**< Customer Card Identification Number (CCIN) */
+ HW, /**< FRU version */
+ B1, /**< MAC Address */
+ VN, /**< FRU manufacturer name */
+ MB, /**< FRU manufacture date */
+ MM, /**< FRU model */
+ UD, /**< System UUID */
+ VS, /**< OpenPower serial number */
+ VP /**< OpenPower part number */
};
/** @brief Convert VPD Keyword name from enum to string
* @tparam K - VPD Keyword
* @returns string representation of Keyword name
*/
-template<Keyword K>
+template <Keyword K>
constexpr const char* getKeyword() = delete;
-template<>
+template <>
constexpr const char* getKeyword<Keyword::DR>()
{
return "DR";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::PN>()
{
return "PN";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::SN>()
{
return "SN";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::CC>()
{
return "CC";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::HW>()
{
return "HW";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::B1>()
{
return "B1";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::VN>()
{
return "VN";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::MB>()
{
return "MB";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::MM>()
{
return "MM";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::UD>()
{
return "UD";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::VS>()
{
return "VS";
}
-template<>
+template <>
constexpr const char* getKeyword<Keyword::VP>()
{
return "VP";
diff --git a/impl.cpp b/impl.cpp
index 925b693..ba85346 100644
--- a/impl.cpp
+++ b/impl.cpp
@@ -1,13 +1,15 @@
-#include <sstream>
+#include "impl.hpp"
+
+#include "defines.hpp"
+
+#include <algorithm>
#include <exception>
+#include <iomanip>
#include <iostream>
#include <iterator>
-#include <unordered_map>
-#include <iomanip>
+#include <sstream>
#include <tuple>
-#include <algorithm>
-#include "defines.hpp"
-#include "impl.hpp"
+#include <unordered_map>
namespace openpower
{
@@ -16,12 +18,8 @@ namespace vpd
namespace parser
{
-static const std::unordered_map<std::string, Record> supportedRecords =
-{
- {"VINI", Record::VINI},
- {"OPFR", Record::OPFR},
- {"OSYS", Record::OSYS}
-};
+static const std::unordered_map<std::string, Record> supportedRecords = {
+ {"VINI", Record::VINI}, {"OPFR", Record::OPFR}, {"OSYS", Record::OSYS}};
static constexpr auto MAC_ADDRESS_LEN_BYTES = 6;
static constexpr auto LAST_KW = "PF";
@@ -31,21 +29,20 @@ static constexpr auto UUID_TIME_MID_END = 13;
static constexpr auto UUID_TIME_HIGH_END = 18;
static constexpr auto UUID_CLK_SEQ_END = 23;
-static const std::unordered_map<std::string,
- internal::KeywordInfo> supportedKeywords =
-{
- {"DR", std::make_tuple(record::Keyword::DR, keyword::Encoding::ASCII)},
- {"PN", std::make_tuple(record::Keyword::PN, keyword::Encoding::ASCII)},
- {"SN", std::make_tuple(record::Keyword::SN, keyword::Encoding::ASCII)},
- {"CC", std::make_tuple(record::Keyword::CC, keyword::Encoding::ASCII)},
- {"HW", std::make_tuple(record::Keyword::HW, keyword::Encoding::RAW)},
- {"B1", std::make_tuple(record::Keyword::B1, keyword::Encoding::B1)},
- {"VN", std::make_tuple(record::Keyword::VN, keyword::Encoding::ASCII)},
- {"MB", std::make_tuple(record::Keyword::MB, keyword::Encoding::RAW)},
- {"MM", std::make_tuple(record::Keyword::MM, keyword::Encoding::ASCII)},
- {"UD", std::make_tuple(record::Keyword::UD, keyword::Encoding::UD)},
- {"VP", std::make_tuple(record::Keyword::VP, keyword::Encoding::ASCII)},
- {"VS", std::make_tuple(record::Keyword::VS, keyword::Encoding::ASCII)},
+static const std::unordered_map<std::string, internal::KeywordInfo>
+ supportedKeywords = {
+ {"DR", std::make_tuple(record::Keyword::DR, keyword::Encoding::ASCII)},
+ {"PN", std::make_tuple(record::Keyword::PN, keyword::Encoding::ASCII)},
+ {"SN", std::make_tuple(record::Keyword::SN, keyword::Encoding::ASCII)},
+ {"CC", std::make_tuple(record::Keyword::CC, keyword::Encoding::ASCII)},
+ {"HW", std::make_tuple(record::Keyword::HW, keyword::Encoding::RAW)},
+ {"B1", std::make_tuple(record::Keyword::B1, keyword::Encoding::B1)},
+ {"VN", std::make_tuple(record::Keyword::VN, keyword::Encoding::ASCII)},
+ {"MB", std::make_tuple(record::Keyword::MB, keyword::Encoding::RAW)},
+ {"MM", std::make_tuple(record::Keyword::MM, keyword::Encoding::ASCII)},
+ {"UD", std::make_tuple(record::Keyword::UD, keyword::Encoding::UD)},
+ {"VP", std::make_tuple(record::Keyword::VP, keyword::Encoding::ASCII)},
+ {"VS", std::make_tuple(record::Keyword::VS, keyword::Encoding::ASCII)},
};
namespace
@@ -66,7 +63,7 @@ constexpr auto toHex(size_t c)
return map[c];
}
-}
+} // namespace
namespace offsets
{
@@ -77,7 +74,6 @@ enum Offsets
VHDR_TOC_ENTRY = 29,
VTOC_PTR = 35,
};
-
}
namespace lengths
@@ -89,7 +85,6 @@ enum Lengths
KW_NAME = 2,
RECORD_MIN = 44,
};
-
}
void Impl::checkHeader() const
@@ -113,7 +108,7 @@ void Impl::checkHeader() const
internal::OffsetList Impl::readTOC() const
{
- internal::OffsetList offsets {};
+ internal::OffsetList offsets{};
// The offset to VTOC could be 1 or 2 bytes long
RecordOffset vtocOffset = vpd.at(offsets::VTOC_PTR);
@@ -123,14 +118,10 @@ internal::OffsetList Impl::readTOC() const
// Got the offset to VTOC, skip past record header and keyword header
// to get to the record name.
auto iterator = vpd.cbegin();
- std::advance(iterator,
- vtocOffset +
- sizeof(RecordId) +
- sizeof(RecordSize) +
- // Skip past the RT keyword, which contains
- // the record name.
- lengths::KW_NAME +
- sizeof(KwSize));
+ std::advance(iterator, vtocOffset + sizeof(RecordId) + sizeof(RecordSize) +
+ // Skip past the RT keyword, which contains
+ // the record name.
+ lengths::KW_NAME + sizeof(KwSize));
auto stop = std::next(iterator, lengths::RECORD_NAME);
std::string record(iterator, stop);
@@ -175,11 +166,8 @@ internal::OffsetList Impl::readPT(Binary::const_iterator iterator,
offsets.push_back(offset);
// Jump record size, record length, ECC offset and ECC length
- std::advance(iterator,
- sizeof(RecordSize) +
- sizeof(RecordLength) +
- sizeof(ECCOffset) +
- sizeof(ECCLength));
+ std::advance(iterator, sizeof(RecordSize) + sizeof(RecordLength) +
+ sizeof(ECCOffset) + sizeof(ECCLength));
}
return offsets;
@@ -188,13 +176,10 @@ internal::OffsetList Impl::readPT(Binary::const_iterator iterator,
void Impl::processRecord(std::size_t recordOffset)
{
// Jump to record name
- auto nameOffset = recordOffset +
- sizeof(RecordId) +
- sizeof(RecordSize) +
+ auto nameOffset = recordOffset + sizeof(RecordId) + sizeof(RecordSize) +
// Skip past the RT keyword, which contains
// the record name.
- lengths::KW_NAME +
- sizeof(KwSize);
+ lengths::KW_NAME + sizeof(KwSize);
// Get record name
auto iterator = vpd.cbegin();
std::advance(iterator, nameOffset);
@@ -228,52 +213,46 @@ std::string Impl::readKwData(const internal::KeywordInfo& keyword,
{
auto stop = std::next(iterator, dataLength);
std::string data(iterator, stop);
- std::string result {};
- std::for_each(data.cbegin(), data.cend(),
- [&result](size_t c)
- {
- result += toHex(c >> 4);
- result += toHex(c & 0x0F);
- });
+ std::string result{};
+ std::for_each(data.cbegin(), data.cend(), [&result](size_t c) {
+ result += toHex(c >> 4);
+ result += toHex(c & 0x0F);
+ });
return result;
}
case keyword::Encoding::B1:
{
- //B1 is MAC address, represent as AA:BB:CC:DD:EE:FF
+ // B1 is MAC address, represent as AA:BB:CC:DD:EE:FF
auto stop = std::next(iterator, MAC_ADDRESS_LEN_BYTES);
std::string data(iterator, stop);
- std::string result {};
+ std::string result{};
auto strItr = data.cbegin();
size_t firstDigit = *strItr;
result += toHex(firstDigit >> 4);
result += toHex(firstDigit & 0x0F);
std::advance(strItr, 1);
- std::for_each(strItr, data.cend(),
- [&result](size_t c)
- {
- result += ":";
- result += toHex(c >> 4);
- result += toHex(c & 0x0F);
- });
+ std::for_each(strItr, data.cend(), [&result](size_t c) {
+ result += ":";
+ result += toHex(c >> 4);
+ result += toHex(c & 0x0F);
+ });
return result;
}
case keyword::Encoding::UD:
{
- //UD, the UUID info, represented as
- //123e4567-e89b-12d3-a456-426655440000
+ // UD, the UUID info, represented as
+ // 123e4567-e89b-12d3-a456-426655440000
//<time_low>-<time_mid>-<time hi and version>
//-<clock_seq_hi_and_res clock_seq_low>-<48 bits node id>
auto stop = std::next(iterator, UUID_LEN_BYTES);
std::string data(iterator, stop);
std::string result{};
- std::for_each(data.cbegin(), data.cend(),
- [&result](size_t c)
- {
- result += toHex(c >> 4);
- result += toHex(c & 0x0F);
- });
+ std::for_each(data.cbegin(), data.cend(), [&result](size_t c) {
+ result += toHex(c >> 4);
+ result += toHex(c & 0x0F);
+ });
result.insert(UUID_TIME_LOW_END, 1, '-');
result.insert(UUID_TIME_MID_END, 1, '-');
result.insert(UUID_TIME_HIGH_END, 1, '-');
@@ -290,7 +269,7 @@ std::string Impl::readKwData(const internal::KeywordInfo& keyword,
internal::KeywordMap Impl::readKeywords(Binary::const_iterator iterator)
{
- internal::KeywordMap map {};
+ internal::KeywordMap map{};
while (true)
{
// Note keyword name
@@ -310,10 +289,8 @@ internal::KeywordMap Impl::readKeywords(Binary::const_iterator iterator)
if (supportedKeywords.end() != supportedKeywords.find(kw))
{
// Keyword is of interest to us
- std::string data = readKwData(
- (supportedKeywords.find(kw))->second,
- length,
- iterator);
+ std::string data = readKwData((supportedKeywords.find(kw))->second,
+ length, iterator);
map.emplace(std::move(kw), std::move(data));
}
// Jump past keyword data length
diff --git a/impl.hpp b/impl.hpp
index 520a7e0..15a9503 100644
--- a/impl.hpp
+++ b/impl.hpp
@@ -1,8 +1,9 @@
#pragma once
-#include <cstddef>
#include "store.hpp"
+#include <cstddef>
+
namespace openpower
{
namespace vpd
@@ -18,8 +19,8 @@ enum class Encoding
ASCII, /**< data encoded in ascii */
RAW, /**< raw data */
// Keywords needing custom decoding
- B1, /**< The keyword B1 needs to be decoded specially */
- UD /**< Special decoding of UD meant for UUID */
+ B1, /**< The keyword B1 needs to be decoded specially */
+ UD /**< Special decoding of UD meant for UUID */
};
} // namespace keyword
@@ -31,7 +32,7 @@ using KeywordInfo = std::tuple<record::Keyword, keyword::Encoding>;
using OffsetList = std::vector<uint32_t>;
using KeywordMap = Parsed::mapped_type;
-}
+} // namespace internal
/** @class Impl
* @brief Implements parser for OpenPOWER VPD
@@ -54,85 +55,84 @@ using KeywordMap = Parsed::mapped_type;
*/
class Impl
{
- public:
- Impl() = delete;
- Impl(const Impl&) = delete;
- Impl& operator=(const Impl&) = delete;
- Impl(Impl&&) = delete;
- Impl& operator=(Impl&&) = delete;
- ~Impl() = default;
-
- /** @brief Construct an Impl
- *
- * @param[in] vpdBuffer - Binary OpenPOWER VPD
- */
- explicit Impl(Binary&& vpdBuffer)
- : vpd(std::move(vpdBuffer)),
- out{}
- {}
-
- /** @brief Run the parser on binary OpenPOWER VPD
- *
- * @returns openpower::vpd::Store object
- */
- Store run();
-
- private:
- /** @brief Process the table of contents record, VHDR
- *
- * @returns List of offsets to records in VPD
- */
- internal::OffsetList readTOC() const;
-
- /** @brief Read the PT keyword contained in the VHDR record,
- * to obtain offsets to other records in the VPD.
- *
- * @param[in] iterator - iterator to buffer containing VPD
- * @param[in] ptLength - Length of PT keyword data
- *
- * @returns List of offsets to records in VPD
- */
- internal::OffsetList readPT(Binary::const_iterator iterator,
- std::size_t ptLen) const;
-
- /** @brief Read VPD information contained within a record
- *
- * @param[in] recordOffset - offset to a record location
- * within the binary OpenPOWER VPD
- */
- void processRecord(std::size_t recordOffset);
-
- /** @brief Read keyword data
- *
- * @param[in] keyword - OpenPOWER VPD keyword
- * @param[in] dataLength - Length of data to be read
- * @param[in] iterator - iterator pointing to a Keyword's data in
- * the VPD
- *
- * @returns keyword data as a string
- */
- std::string readKwData(const internal::KeywordInfo& keyword,
- std::size_t dataLength,
- Binary::const_iterator iterator);
-
- /** @brief While we're pointing at the keyword section of
- * a record in the VPD, this will read all contained
- * keywords and their values.
- *
- * @param[in] iterator - iterator pointing to a Keyword in the VPD
- *
- * @returns map of keyword:data
- */
- internal::KeywordMap readKeywords(Binary::const_iterator iterator);
-
- /** @brief Checks if the VHDR record is present in the VPD */
- void checkHeader() const;
-
- /** @brief OpenPOWER VPD in binary format */
- Binary vpd;
-
- /** @brief parser output */
- Parsed out;
+ public:
+ Impl() = delete;
+ Impl(const Impl&) = delete;
+ Impl& operator=(const Impl&) = delete;
+ Impl(Impl&&) = delete;
+ Impl& operator=(Impl&&) = delete;
+ ~Impl() = default;
+
+ /** @brief Construct an Impl
+ *
+ * @param[in] vpdBuffer - Binary OpenPOWER VPD
+ */
+ explicit Impl(Binary&& vpdBuffer) : vpd(std::move(vpdBuffer)), out{}
+ {
+ }
+
+ /** @brief Run the parser on binary OpenPOWER VPD
+ *
+ * @returns openpower::vpd::Store object
+ */
+ Store run();
+
+ private:
+ /** @brief Process the table of contents record, VHDR
+ *
+ * @returns List of offsets to records in VPD
+ */
+ internal::OffsetList readTOC() const;
+
+ /** @brief Read the PT keyword contained in the VHDR record,
+ * to obtain offsets to other records in the VPD.
+ *
+ * @param[in] iterator - iterator to buffer containing VPD
+ * @param[in] ptLength - Length of PT keyword data
+ *
+ * @returns List of offsets to records in VPD
+ */
+ internal::OffsetList readPT(Binary::const_iterator iterator,
+ std::size_t ptLen) const;
+
+ /** @brief Read VPD information contained within a record
+ *
+ * @param[in] recordOffset - offset to a record location
+ * within the binary OpenPOWER VPD
+ */
+ void processRecord(std::size_t recordOffset);
+
+ /** @brief Read keyword data
+ *
+ * @param[in] keyword - OpenPOWER VPD keyword
+ * @param[in] dataLength - Length of data to be read
+ * @param[in] iterator - iterator pointing to a Keyword's data in
+ * the VPD
+ *
+ * @returns keyword data as a string
+ */
+ std::string readKwData(const internal::KeywordInfo& keyword,
+ std::size_t dataLength,
+ Binary::const_iterator iterator);
+
+ /** @brief While we're pointing at the keyword section of
+ * a record in the VPD, this will read all contained
+ * keywords and their values.
+ *
+ * @param[in] iterator - iterator pointing to a Keyword in the VPD
+ *
+ * @returns map of keyword:data
+ */
+ internal::KeywordMap readKeywords(Binary::const_iterator iterator);
+
+ /** @brief Checks if the VHDR record is present in the VPD */
+ void checkHeader() const;
+
+ /** @brief OpenPOWER VPD in binary format */
+ Binary vpd;
+
+ /** @brief parser output */
+ Parsed out;
};
} // namespace parser
diff --git a/parser.cpp b/parser.cpp
index e33cc79..3b9776e 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -1,4 +1,5 @@
#include "parser.hpp"
+
#include "impl.hpp"
namespace openpower
diff --git a/parser.hpp b/parser.hpp
index 04949f9..e131c46 100644
--- a/parser.hpp
+++ b/parser.hpp
@@ -1,8 +1,9 @@
#pragma once
-#include <vector>
#include "store.hpp"
+#include <vector>
+
namespace openpower
{
namespace vpd
diff --git a/store.hpp b/store.hpp
index 340446f..d5e0d72 100644
--- a/store.hpp
+++ b/store.hpp
@@ -1,10 +1,11 @@
#pragma once
-#include <string>
-#include <unordered_map>
#include "defines.hpp"
#include "types.hpp"
+#include <string>
+#include <unordered_map>
+
namespace openpower
{
namespace vpd
@@ -12,9 +13,8 @@ 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<std::string,
- std::unordered_map<std::string, std::string>>;
+using Parsed = std::unordered_map<std::string,
+ std::unordered_map<std::string, std::string>>;
/** @class Store
* @brief Store for parsed OpenPOWER VPD
@@ -25,49 +25,51 @@ using Parsed =
*/
class Store final
{
- public:
- Store() = delete;
- Store(const Store&) = delete;
- Store& operator=(const Store&) = delete;
- Store(Store&&) = default;
- Store& operator=(Store&&) = default;
- ~Store() = default;
+ 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 Construct a Store
+ *
+ * @param[in] vpdBuffer - A parsed VPD object
+ */
+ explicit Store(Parsed&& vpdBuffer) : vpd(std::move(vpdBuffer))
+ {
+ }
- /** @brief Retrieves VPD from Store
- *
- * @tparam R - VPD record
- * @tparam K - VPD keyword
- * @returns VPD stored in input record:keyword
- */
- template<Record R, record::Keyword K>
- inline const std::string& get() const;
+ /** @brief Retrieves VPD from Store
+ *
+ * @tparam R - VPD record
+ * @tparam K - VPD keyword
+ * @returns VPD stored in input record:keyword
+ */
+ template <Record R, record::Keyword K>
+ inline const std::string& get() const;
- /** @brief Checks if VPD exists in store
- *
- * @tparam R - VPD record
- * @tparam K - VPD keyword
- * @returns true if {R,K} exists
- */
- template<Record R, record::Keyword K>
- bool exists() const
- {
- static const std::string record = getRecord<R>();
- static const std::string keyword = record::getKeyword<K>();
- return vpd.count(record) && vpd.at(record).count(keyword);
- }
+ /** @brief Checks if VPD exists in store
+ *
+ * @tparam R - VPD record
+ * @tparam K - VPD keyword
+ * @returns true if {R,K} exists
+ */
+ template <Record R, record::Keyword K>
+ bool exists() const
+ {
+ static const std::string record = getRecord<R>();
+ static const std::string keyword = record::getKeyword<K>();
+ return vpd.count(record) && vpd.at(record).count(keyword);
+ }
- private:
- /** @brief The store for parsed VPD */
- Parsed vpd;
+ private:
+ /** @brief The store for parsed VPD */
+ Parsed vpd;
};
-template<Record R, record::Keyword K>
+template <Record R, record::Keyword K>
inline const std::string& Store::get() const
{
static const std::string record = getRecord<R>();
diff --git a/test/parser/parser.cpp b/test/parser/parser.cpp
index eda30af..69b2005 100644
--- a/test/parser/parser.cpp
+++ b/test/parser/parser.cpp
@@ -1,9 +1,9 @@
-#include <defines.hpp>
-#include <store.hpp>
-#include <parser.hpp>
#include <cassert>
+#include <defines.hpp>
#include <fstream>
#include <iterator>
+#include <parser.hpp>
+#include <store.hpp>
void runTests()
{
@@ -17,8 +17,7 @@ void runTests()
auto vpdStore = parse(std::move(vpd));
- assert(("P012" ==
- vpdStore.get<Record::VINI, record::Keyword::CC>()));
+ assert(("P012" == vpdStore.get<Record::VINI, record::Keyword::CC>()));
}
}
diff --git a/test/store/store.cpp b/test/store/store.cpp
index 32b403c..4c83ba7 100644
--- a/test/store/store.cpp
+++ b/test/store/store.cpp
@@ -1,9 +1,11 @@
+#include "store.hpp"
+
+#include "defines.hpp"
+
#include <cassert>
#include <string>
#include <unordered_map>
#include <utility>
-#include "defines.hpp"
-#include "store.hpp"
void runTests()
{
diff --git a/types.hpp b/types.hpp
index 4e30208..196e0fd 100644
--- a/types.hpp
+++ b/types.hpp
@@ -1,10 +1,10 @@
#pragma once
#include <climits>
-#include <vector>
-#include <string>
#include <map>
#include <sdbusplus/server.hpp>
+#include <string>
+#include <vector>
namespace openpower
{
diff --git a/utils.cpp b/utils.cpp
index 57cba0a..276f406 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -1,7 +1,8 @@
#include "utils.hpp"
-#include <sdbusplus/server.hpp>
-#include <phosphor-logging/log.hpp>
+
#include <iostream>
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/server.hpp>
namespace openpower
{
@@ -15,24 +16,22 @@ auto getPIMService()
{
auto bus = sdbusplus::bus::new_default();
auto mapper =
- bus.new_method_call(
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper",
- "GetObject");
+ bus.new_method_call("xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetObject");
mapper.append(pimPath);
mapper.append(std::vector<std::string>({pimIntf}));
auto result = bus.call(mapper);
- if(result.is_method_error())
+ if (result.is_method_error())
{
throw std::runtime_error("ObjectMapper GetObject failed");
}
std::map<std::string, std::vector<std::string>> response;
result.read(response);
- if(response.empty())
+ if (response.empty())
{
throw std::runtime_error("ObjectMapper GetObject bad response");
}
@@ -48,14 +47,11 @@ void callPIM(ObjectMap&& objects)
{
service = getPIMService();
auto bus = sdbusplus::bus::new_default();
- auto pimMsg = bus.new_method_call(
- service.c_str(),
- pimPath,
- pimIntf,
- "Notify");
+ auto pimMsg =
+ bus.new_method_call(service.c_str(), pimPath, pimIntf, "Notify");
pimMsg.append(std::move(objects));
auto result = bus.call(pimMsg);
- if(result.is_method_error())
+ if (result.is_method_error())
{
std::cerr << "PIM Notify() failed\n";
}
@@ -69,5 +65,5 @@ void callPIM(ObjectMap&& objects)
} // namespace inventory
-} //namespace vpd
-} //namespace openpower
+} // namespace vpd
+} // namespace openpower
diff --git a/utils.hpp b/utils.hpp
index 0aeeb32..4b690ab 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -22,5 +22,5 @@ void callPIM(ObjectMap&& objects);
} // namespace inventory
-} //namespace vpd
-} //namespace openpower
+} // namespace vpd
+} // namespace openpower
diff --git a/write.cpp b/write.cpp
index e4f3e59..b0293a5 100644
--- a/write.cpp
+++ b/write.cpp
@@ -1,9 +1,11 @@
-#include <exception>
-#include <algorithm>
-#include "defines.hpp"
#include "write.hpp"
+
+#include "defines.hpp"
#include "writefru.hpp"
+#include <algorithm>
+#include <exception>
+
namespace openpower
{
namespace vpd
@@ -11,14 +13,10 @@ namespace vpd
namespace inventory
{
-static const std::unordered_map<std::string, Fru> supportedFrus =
-{
- {"BMC", Fru::BMC},
- {"ETHERNET", Fru::ETHERNET}
-};
+static const std::unordered_map<std::string, Fru> supportedFrus = {
+ {"BMC", Fru::BMC}, {"ETHERNET", Fru::ETHERNET}};
-void write(const std::string& type,
- const Store& vpdStore,
+void write(const std::string& type, const Store& vpdStore,
const std::string& path)
{
// Get the enum corresponding to type, and call
@@ -54,6 +52,6 @@ void write(const std::string& type,
}
}
-} // inventory
+} // namespace inventory
} // namespace vpd
} // namespace openpower
diff --git a/write.hpp b/write.hpp
index 2e7fe33..0544bdf 100644
--- a/write.hpp
+++ b/write.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include <string>
#include <store.hpp>
+#include <string>
namespace openpower
{
@@ -16,10 +16,9 @@ namespace inventory
* @param [in] vpdStore - Store object containing parsed VPD
* @param [in] path - FRU object path
*/
-void write(const std::string& type,
- const Store& vpdStore,
+void write(const std::string& type, const Store& vpdStore,
const std::string& path);
-} // inventory
+} // namespace inventory
} // namespace vpd
} // namespace openpower
OpenPOWER on IntegriCloud