Change primary postcode interface to byte array
Change primary code to std::vector<uint8_t> to meet the changes in
phosphor-dbus-interface.
[1] https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/74633
Change-Id: Ie1207d703f8bc1ad42fedc5bcbcbd0e4c23dacde
Signed-off-by: Cosmo Chou <cosmo.chou@quantatw.com>
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
diff --git a/src/groupextcommands.cpp b/src/groupextcommands.cpp
index 8fa9f08..eb6b48e 100644
--- a/src/groupextcommands.cpp
+++ b/src/groupextcommands.cpp
@@ -24,7 +24,7 @@
ipmi::RspType<> ipmiSBMRSendBootProgress(ipmi::Context::ptr ctx,
std::vector<uint8_t> data)
{
- using postcode_t = std::tuple<uint64_t, std::vector<uint8_t>>;
+ using postcode_t = std::tuple<std::vector<uint8_t>, std::vector<uint8_t>>;
std::optional<size_t> hostId = findHost(ctx->hostIdx);
@@ -43,11 +43,7 @@
try
{
- auto primaryPostCode = reinterpret_cast<const uint64_t*>(data.data());
- auto secondaryPostCode =
- std::vector<uint8_t>(data.begin() + 8, data.end());
- auto postCode =
- postcode_t(bigEndianToHost(*primaryPostCode), secondaryPostCode);
+ postcode_t postCode(std::move(data), {});
auto conn = getSdBus();
auto hostbootRawObj =
std::string(bootRawObjPrefix) + std::to_string(*hostId);
@@ -55,7 +51,8 @@
conn->new_method_call(bootRawBusName, hostbootRawObj.data(),
"org.freedesktop.DBus.Properties", "Set");
- method.append(bootRawIntf, "Value", std::variant<postcode_t>(postCode));
+ method.append(bootRawIntf, "Value",
+ std::variant<postcode_t>(std::move(postCode)));
conn->call_noreply(method);
}
diff --git a/src/usb-dbg.cpp b/src/usb-dbg.cpp
index 78fff85..ed15e4e 100644
--- a/src/usb-dbg.cpp
+++ b/src/usb-dbg.cpp
@@ -787,11 +787,6 @@
// up to 70 codes can be displayed on 10 pages
static constexpr size_t maxPostcodes = 70;
- static constexpr const char* formatStr =
- (postCodeSize == 4) ? "{:08X}"
- : (postCodeSize == 8) ? "{:016X}"
- : "{:02X}";
-
if (page == 1)
{
// Initialize and clear frame (example initialization)
@@ -816,17 +811,19 @@
auto reply = bus.call(method); // Send synchronous method call
// Read postcode value
- std::vector<std::tuple<uint64_t, std::vector<uint8_t>>> postcodes;
+ std::vector<std::tuple<std::vector<uint8_t>, std::vector<uint8_t>>>
+ postcodes;
reply.read(postcodes);
// retrieve the latest postcodes
size_t numEntries = std::min(maxPostcodes, postcodes.size());
- for (auto it = postcodes.rbegin();
- it != postcodes.rbegin() + numEntries; ++it)
+ auto range = std::ranges::subrange(postcodes.rbegin(),
+ postcodes.rbegin() + numEntries);
+ for (const auto& [code, extra] : range)
{
- const auto& [code, extra] = *it;
- std::string result = std::format(formatStr, code);
- for (const auto& byte : extra)
+ std::string result;
+ result.reserve(2 * code.size());
+ for (const auto& byte : code)
{
result += std::format("{:02X}", byte);
}