Move to common variant
This saves approximately 34kB in the compressed binary size of bmcweb
due to reduced template instantiations. This amounts to a 2.5%
reduction in the overall size.
Note, there were a few places where we broke const-correctness in the
form of pulling a non-const reference out of a const variant. This
new variant now requires const correctness, so some consts are
added where required.
Tested: Code compiles.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I6a60c8881c1268627eedb4ffddf16689dc5f6ed2
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index 1872c02..1904c26 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -18,6 +18,7 @@
#include <app.hpp>
#include <boost/system/linux_error.hpp>
+#include <dbus_utility.hpp>
#include <registries/privilege_registry.hpp>
namespace redfish
@@ -143,76 +144,93 @@
const std::string& device)
{
- auto getPCIeDeviceCallback = [asyncResp, device](
- const boost::system::error_code
- ec,
- boost::container::flat_map<
- std::string,
- std::variant<std::string>>&
- pcieDevProperties) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG
- << "failed to get PCIe Device properties ec: "
- << ec.value() << ": " << ec.message();
- if (ec.value() ==
- boost::system::linux_error::bad_request_descriptor)
+ auto getPCIeDeviceCallback =
+ [asyncResp,
+ device](const boost::system::error_code ec,
+ boost::container::flat_map<
+ std::string, dbus::utility::DbusVariantType>&
+ pcieDevProperties) {
+ if (ec)
{
- messages::resourceNotFound(asyncResp->res,
- "PCIeDevice", device);
- }
- else
- {
- messages::internalError(asyncResp->res);
- }
- return;
- }
-
- asyncResp->res.jsonValue = {
- {"@odata.type", "#PCIeDevice.v1_4_0.PCIeDevice"},
- {"@odata.id",
- "/redfish/v1/Systems/system/PCIeDevices/" + device},
- {"Name", "PCIe Device"},
- {"Id", device}};
-
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Manufacturer"]);
- property)
- {
- asyncResp->res.jsonValue["Manufacturer"] = *property;
- }
-
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["DeviceType"]);
- property)
- {
- asyncResp->res.jsonValue["DeviceType"] = *property;
- }
-
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["GenerationInUse"]);
- property)
- {
- std::optional<std::string> generationInUse =
- redfishPcieGenerationFromDbus(*property);
- if (!generationInUse)
- {
- messages::internalError(asyncResp->res);
+ BMCWEB_LOG_DEBUG
+ << "failed to get PCIe Device properties ec: "
+ << ec.value() << ": " << ec.message();
+ if (ec.value() == boost::system::linux_error::
+ bad_request_descriptor)
+ {
+ messages::resourceNotFound(
+ asyncResp->res, "PCIeDevice", device);
+ }
+ else
+ {
+ messages::internalError(asyncResp->res);
+ }
return;
}
- if (*generationInUse == "")
+
+ asyncResp->res.jsonValue = {
+ {"@odata.type", "#PCIeDevice.v1_4_0.PCIeDevice"},
+ {"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" +
+ device},
+ {"Name", "PCIe Device"},
+ {"Id", device}};
+
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Manufacturer"]);
+ property)
{
- // unknown, no need to handle
- return;
+ asyncResp->res.jsonValue["Manufacturer"] =
+ *property;
}
- asyncResp->res.jsonValue["PCIeInterface"]["PcieType"] =
- *generationInUse;
- }
- asyncResp->res.jsonValue["PCIeFunctions"] = {
- {"@odata.id",
- "/redfish/v1/Systems/system/PCIeDevices/" + device +
- "/PCIeFunctions"}};
- };
+
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["DeviceType"]);
+ property)
+ {
+ asyncResp->res.jsonValue["DeviceType"] = *property;
+ }
+
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Manufacturer"]);
+ property)
+ {
+ asyncResp->res.jsonValue["Manufacturer"] =
+ *property;
+ }
+
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["DeviceType"]);
+ property)
+ {
+ asyncResp->res.jsonValue["DeviceType"] = *property;
+ }
+
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["GenerationInUse"]);
+ property)
+ {
+ std::optional<std::string> generationInUse =
+ redfishPcieGenerationFromDbus(*property);
+ if (!generationInUse)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ if (*generationInUse == "")
+ {
+ // unknown, no need to handle
+ return;
+ }
+ asyncResp->res
+ .jsonValue["PCIeInterface"]["PcieType"] =
+ *generationInUse;
+ }
+ asyncResp->res.jsonValue["PCIeFunctions"] = {
+ {"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" +
+ device + "/PCIeFunctions"}};
+ };
std::string escapedPath = std::string(pciePath) + "/" + device;
dbus::utility::escapePathForDbus(escapedPath);
crow::connections::systemBus->async_method_call(
@@ -250,7 +268,8 @@
ec,
boost::container::flat_map<
std::string,
- std::variant<std::string>>&
+ dbus::utility::
+ DbusVariantType>&
pcieDevProperties) {
if (ec)
{
@@ -317,116 +336,121 @@
bmcweb::AsyncResp>& asyncResp,
const std::string& device,
const std::string& function) {
- auto getPCIeDeviceCallback = [asyncResp, device, function](
- const boost::system::error_code ec,
- boost::container::flat_map<
- std::string,
- std::variant<std::string>>&
- pcieDevProperties) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG
- << "failed to get PCIe Device properties ec: "
- << ec.value() << ": " << ec.message();
- if (ec.value() ==
- boost::system::linux_error::bad_request_descriptor)
+ auto getPCIeDeviceCallback =
+ [asyncResp, device, function](
+ const boost::system::error_code ec,
+ boost::container::flat_map<std::string,
+ dbus::utility::DbusVariantType>&
+ pcieDevProperties) {
+ if (ec)
{
- messages::resourceNotFound(asyncResp->res, "PCIeDevice",
- device);
+ BMCWEB_LOG_DEBUG
+ << "failed to get PCIe Device properties ec: "
+ << ec.value() << ": " << ec.message();
+ if (ec.value() ==
+ boost::system::linux_error::bad_request_descriptor)
+ {
+ messages::resourceNotFound(asyncResp->res,
+ "PCIeDevice", device);
+ }
+ else
+ {
+ messages::internalError(asyncResp->res);
+ }
+ return;
}
- else
+
+ // Check if this function exists by looking for a device ID
+ std::string devIDProperty =
+ "Function" + function + "DeviceId";
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties[devIDProperty]);
+ property && property->empty())
{
- messages::internalError(asyncResp->res);
+ messages::resourceNotFound(asyncResp->res,
+ "PCIeFunction", function);
+ return;
}
- return;
- }
- // Check if this function exists by looking for a device ID
- std::string devIDProperty = "Function" + function + "DeviceId";
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties[devIDProperty]);
- property && property->empty())
- {
- messages::resourceNotFound(asyncResp->res, "PCIeFunction",
- function);
- return;
- }
+ asyncResp->res.jsonValue = {
+ {"@odata.type", "#PCIeFunction.v1_2_0.PCIeFunction"},
+ {"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" + device +
+ "/PCIeFunctions/" + function},
+ {"Name", "PCIe Function"},
+ {"Id", function},
+ {"FunctionId", std::stoi(function)},
+ {"Links",
+ {{"PCIeDevice",
+ {{"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" +
+ device}}}}}};
- asyncResp->res.jsonValue = {
- {"@odata.type", "#PCIeFunction.v1_2_0.PCIeFunction"},
- {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices/" +
- device + "/PCIeFunctions/" + function},
- {"Name", "PCIe Function"},
- {"Id", function},
- {"FunctionId", std::stoi(function)},
- {"Links",
- {{"PCIeDevice",
- {{"@odata.id",
- "/redfish/v1/Systems/system/PCIeDevices/" +
- device}}}}}};
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "DeviceId"]);
+ property)
+ {
+ asyncResp->res.jsonValue["DeviceId"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function + "DeviceId"]);
- property)
- {
- asyncResp->res.jsonValue["DeviceId"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "VendorId"]);
+ property)
+ {
+ asyncResp->res.jsonValue["VendorId"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function + "VendorId"]);
- property)
- {
- asyncResp->res.jsonValue["VendorId"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "FunctionType"]);
+ property)
+ {
+ asyncResp->res.jsonValue["FunctionType"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function +
- "FunctionType"]);
- property)
- {
- asyncResp->res.jsonValue["FunctionType"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "DeviceClass"]);
+ property)
+ {
+ asyncResp->res.jsonValue["DeviceClass"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function +
- "DeviceClass"]);
- property)
- {
- asyncResp->res.jsonValue["DeviceClass"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "ClassCode"]);
+ property)
+ {
+ asyncResp->res.jsonValue["ClassCode"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function +
- "ClassCode"]);
- property)
- {
- asyncResp->res.jsonValue["ClassCode"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "RevisionId"]);
+ property)
+ {
+ asyncResp->res.jsonValue["RevisionId"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function +
- "RevisionId"]);
- property)
- {
- asyncResp->res.jsonValue["RevisionId"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "SubsystemId"]);
+ property)
+ {
+ asyncResp->res.jsonValue["SubsystemId"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function +
- "SubsystemId"]);
- property)
- {
- asyncResp->res.jsonValue["SubsystemId"] = *property;
- }
-
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function +
- "SubsystemVendorId"]);
- property)
- {
- asyncResp->res.jsonValue["SubsystemVendorId"] = *property;
- }
- };
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "SubsystemVendorId"]);
+ property)
+ {
+ asyncResp->res.jsonValue["SubsystemVendorId"] =
+ *property;
+ }
+ };
std::string escapedPath = std::string(pciePath) + "/" + device;
dbus::utility::escapePathForDbus(escapedPath);
crow::connections::systemBus->async_method_call(