summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Grobelny <krzysztof.grobelny@intel.com>2022-08-31 14:15:26 +0300
committerEd Tanous <ed@tanous.net>2022-09-02 03:41:07 +0300
commitc1343bf6a51b22b85a0521050948ad6026027fc8 (patch)
tree5862dbd260d44f9e5a70872b5f408d2c705d8bad
parent033f1e4d7ffe66b742b2d3fb6f18f2ba2025afb8 (diff)
downloadbmcweb-c1343bf6a51b22b85a0521050948ad6026027fc8.tar.xz
used sdbusplus::unpackPropertiesNoThrow part 6
used sdbusplus::unpackPropertiesNoThrow in openbmc_dbus_rest.hpp, memory.hpp and sensors.hpp, also replaced all usages of "GetAll" with sdbusplus::asio::getAllProperties bmcweb size: 2697624 -> 2697624 (0) compressed size: 1129645 -> 1130037 (+392) Tested: Performed get on: - /redfish/v1/Systems/system/Memory/dimm0 Performed get one of the members of: - /redfish/v1/Chassis/chassis/Sensors Get result before and after the change was in same format. Change-Id: I05efcedfd905ea2c8d1d663e909cb59ebc2cf2b7 Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
-rw-r--r--include/openbmc_dbus_rest.hpp8
-rw-r--r--redfish-core/lib/memory.hpp885
-rw-r--r--redfish-core/lib/sensors.hpp75
3 files changed, 420 insertions, 548 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index f458fac10d..d8a4e66d6f 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -36,6 +36,7 @@
#include <dbus_utility.hpp>
#include <nlohmann/json.hpp>
#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <sdbusplus/exception.hpp>
#include <sdbusplus/message.hpp>
#include <sdbusplus/message/native_types.hpp>
@@ -184,7 +185,8 @@ inline void getPropertiesForEnumerate(
BMCWEB_LOG_DEBUG << "getPropertiesForEnumerate " << objectPath << " "
<< service << " " << interface;
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, service, objectPath, interface,
[asyncResp, objectPath, service,
interface](const boost::system::error_code ec,
const dbus::utility::DBusPropertiesMap& propertiesList) {
@@ -221,9 +223,7 @@ inline void getPropertiesForEnumerate(
},
value);
}
- },
- service, objectPath, "org.freedesktop.DBus.Properties", "GetAll",
- interface);
+ });
}
// Find any results that weren't picked up by ObjectManagers, to be
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp
index 3c10130e5b..dcd017dcff 100644
--- a/redfish-core/lib/memory.hpp
+++ b/redfish-core/lib/memory.hpp
@@ -22,6 +22,8 @@
#include <nlohmann/json.hpp>
#include <query.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
#include <utils/collection.hpp>
#include <utils/hex_utils.hpp>
#include <utils/json_utils.hpp>
@@ -138,17 +140,12 @@ inline std::string translateMemoryTypeToRedfish(const std::string& memoryType)
return "";
}
-inline void
- dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
- const char* key,
- const dbus::utility::DBusPropertiesMap::value_type& property,
- const nlohmann::json::json_pointer& jsonPtr)
+inline void dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ const char* key, const uint16_t* value,
+ const nlohmann::json::json_pointer& jsonPtr)
{
- const uint16_t* value = std::get_if<uint16_t>(&property.second);
if (value == nullptr)
{
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for " << property.first;
return;
}
aResp->res.jsonValue[jsonPtr][key] = "0x" + intToHexString(*value, 4);
@@ -156,233 +153,176 @@ inline void
inline void getPersistentMemoryProperties(
const std::shared_ptr<bmcweb::AsyncResp>& aResp,
- const dbus::utility::DBusPropertiesMap::value_type& property,
+ const dbus::utility::DBusPropertiesMap& properties,
const nlohmann::json::json_pointer& jsonPtr)
{
- if (property.first == "ModuleManufacturerID")
- {
- dimmPropToHex(aResp, "ModuleManufacturerID", property, jsonPtr);
- }
- else if (property.first == "ModuleProductID")
+ const uint16_t* moduleManufacturerID = nullptr;
+ const uint16_t* moduleProductID = nullptr;
+ const uint16_t* subsystemVendorID = nullptr;
+ const uint16_t* subsystemDeviceID = nullptr;
+ const uint64_t* volatileRegionSizeLimitInKiB = nullptr;
+ const uint64_t* pmRegionSizeLimitInKiB = nullptr;
+ const uint64_t* volatileSizeInKiB = nullptr;
+ const uint64_t* pmSizeInKiB = nullptr;
+ const uint64_t* cacheSizeInKB = nullptr;
+ const uint64_t* voltaileRegionMaxSizeInKib = nullptr;
+ const uint64_t* pmRegionMaxSizeInKiB = nullptr;
+ const uint64_t* allocationIncrementInKiB = nullptr;
+ const uint64_t* allocationAlignmentInKiB = nullptr;
+ const uint64_t* volatileRegionNumberLimit = nullptr;
+ const uint64_t* pmRegionNumberLimit = nullptr;
+ const uint64_t* spareDeviceCount = nullptr;
+ const bool* isSpareDeviceInUse = nullptr;
+ const bool* isRankSpareEnabled = nullptr;
+ const std::vector<uint32_t>* maxAveragePowerLimitmW = nullptr;
+ const bool* configurationLocked = nullptr;
+ const std::string* allowedMemoryModes = nullptr;
+ const std::string* memoryMedia = nullptr;
+ const bool* configurationLockCapable = nullptr;
+ const bool* dataLockCapable = nullptr;
+ const bool* passphraseCapable = nullptr;
+ const uint64_t* maxPassphraseCount = nullptr;
+ const uint64_t* passphraseLockLimit = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), properties, "ModuleManufacturerID",
+ moduleManufacturerID, "ModuleProductID", moduleProductID,
+ "SubsystemVendorID", subsystemVendorID, "SubsystemDeviceID",
+ subsystemDeviceID, "VolatileRegionSizeLimitInKiB",
+ volatileRegionSizeLimitInKiB, "PmRegionSizeLimitInKiB",
+ pmRegionSizeLimitInKiB, "VolatileSizeInKiB", volatileSizeInKiB,
+ "PmSizeInKiB", pmSizeInKiB, "CacheSizeInKB", cacheSizeInKB,
+ "VoltaileRegionMaxSizeInKib", voltaileRegionMaxSizeInKib,
+ "PmRegionMaxSizeInKiB", pmRegionMaxSizeInKiB,
+ "AllocationIncrementInKiB", allocationIncrementInKiB,
+ "AllocationAlignmentInKiB", allocationAlignmentInKiB,
+ "VolatileRegionNumberLimit", volatileRegionNumberLimit,
+ "PmRegionNumberLimit", pmRegionNumberLimit, "SpareDeviceCount",
+ spareDeviceCount, "IsSpareDeviceInUse", isSpareDeviceInUse,
+ "IsRankSpareEnabled", isRankSpareEnabled, "MaxAveragePowerLimitmW",
+ maxAveragePowerLimitmW, "ConfigurationLocked", configurationLocked,
+ "AllowedMemoryModes", allowedMemoryModes, "MemoryMedia", memoryMedia,
+ "ConfigurationLockCapable", configurationLockCapable, "DataLockCapable",
+ dataLockCapable, "PassphraseCapable", passphraseCapable,
+ "MaxPassphraseCount", maxPassphraseCount, "PassphraseLockLimit",
+ passphraseLockLimit);
+
+ if (!success)
{
- dimmPropToHex(aResp, "ModuleProductID", property, jsonPtr);
- }
- else if (property.first == "SubsystemVendorID")
- {
- dimmPropToHex(aResp, "MemorySubsystemControllerManufacturerID",
- property, jsonPtr);
- }
- else if (property.first == "SubsystemDeviceID")
- {
- dimmPropToHex(aResp, "MemorySubsystemControllerProductID", property,
- jsonPtr);
+ messages::internalError(aResp->res);
+ return;
}
- else if (property.first == "VolatileRegionSizeLimitInKiB")
- {
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG
- << "Invalid property type for VolatileRegionSizeLimitKiB";
- return;
- }
+ dimmPropToHex(aResp, "ModuleManufacturerID", moduleManufacturerID, jsonPtr);
+ dimmPropToHex(aResp, "ModuleProductID", moduleProductID, jsonPtr);
+ dimmPropToHex(aResp, "MemorySubsystemControllerManufacturerID",
+ subsystemVendorID, jsonPtr);
+ dimmPropToHex(aResp, "MemorySubsystemControllerProductID",
+ subsystemDeviceID, jsonPtr);
+
+ if (volatileRegionSizeLimitInKiB != nullptr)
+ {
aResp->res.jsonValue[jsonPtr]["VolatileRegionSizeLimitMiB"] =
- (*value) >> 10;
+ (*volatileRegionSizeLimitInKiB) >> 10;
}
- else if (property.first == "PmRegionSizeLimitInKiB")
- {
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for PmRegioSizeLimitKiB";
- return;
- }
+ if (pmRegionSizeLimitInKiB != nullptr)
+ {
aResp->res.jsonValue[jsonPtr]["PersistentRegionSizeLimitMiB"] =
- (*value) >> 10;
+ (*pmRegionSizeLimitInKiB) >> 10;
}
- else if (property.first == "VolatileSizeInKiB")
+
+ if (volatileSizeInKiB != nullptr)
{
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for VolatileSizeInKiB";
- return;
- }
- aResp->res.jsonValue[jsonPtr]["VolatileSizeMiB"] = (*value) >> 10;
+ aResp->res.jsonValue[jsonPtr]["VolatileSizeMiB"] =
+ (*volatileSizeInKiB) >> 10;
}
- else if (property.first == "PmSizeInKiB")
+
+ if (pmSizeInKiB != nullptr)
{
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for PmSizeInKiB";
- return;
- }
- aResp->res.jsonValue[jsonPtr]["NonVolatileSizeMiB"] = (*value) >> 10;
+ aResp->res.jsonValue[jsonPtr]["NonVolatileSizeMiB"] =
+ (*pmSizeInKiB) >> 10;
}
- else if (property.first == "CacheSizeInKB")
+
+ if (cacheSizeInKB != nullptr)
{
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for CacheSizeInKB";
- return;
- }
- aResp->res.jsonValue[jsonPtr]["CacheSizeMiB"] = (*value >> 10);
+ aResp->res.jsonValue[jsonPtr]["CacheSizeMiB"] = (*cacheSizeInKB >> 10);
}
- else if (property.first == "VoltaileRegionMaxSizeInKib")
+ if (voltaileRegionMaxSizeInKib != nullptr)
{
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
-
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG
- << "Invalid property type for VolatileRegionMaxSizeInKib";
- return;
- }
aResp->res.jsonValue[jsonPtr]["VolatileRegionSizeMaxMiB"] =
- (*value) >> 10;
+ (*voltaileRegionMaxSizeInKib) >> 10;
}
- else if (property.first == "PmRegionMaxSizeInKiB")
- {
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG
- << "Invalid property type for PmRegionMaxSizeInKiB";
- return;
- }
+ if (pmRegionMaxSizeInKiB != nullptr)
+ {
aResp->res.jsonValue[jsonPtr]["PersistentRegionSizeMaxMiB"] =
- (*value) >> 10;
+ (*pmRegionMaxSizeInKiB) >> 10;
}
- else if (property.first == "AllocationIncrementInKiB")
- {
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG
- << "Invalid property type for AllocationIncrementInKiB";
- return;
- }
+ if (allocationIncrementInKiB != nullptr)
+ {
aResp->res.jsonValue[jsonPtr]["AllocationIncrementMiB"] =
- (*value) >> 10;
+ (*allocationIncrementInKiB) >> 10;
}
- else if (property.first == "AllocationAlignmentInKiB")
- {
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG
- << "Invalid property type for AllocationAlignmentInKiB";
- return;
- }
+ if (allocationAlignmentInKiB != nullptr)
+ {
aResp->res.jsonValue[jsonPtr]["AllocationAlignmentMiB"] =
- (*value) >> 10;
+ (*allocationAlignmentInKiB) >> 10;
}
- else if (property.first == "VolatileRegionNumberLimit")
+
+ if (volatileRegionNumberLimit != nullptr)
{
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["VolatileRegionNumberLimit"] = *value;
+ aResp->res.jsonValue[jsonPtr]["VolatileRegionNumberLimit"] =
+ *volatileRegionNumberLimit;
}
- else if (property.first == "PmRegionNumberLimit")
+
+ if (pmRegionNumberLimit != nullptr)
{
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["PersistentRegionNumberLimit"] = *value;
+ aResp->res.jsonValue[jsonPtr]["PersistentRegionNumberLimit"] =
+ *pmRegionNumberLimit;
}
- else if (property.first == "SpareDeviceCount")
+
+ if (spareDeviceCount != nullptr)
{
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["SpareDeviceCount"] = *value;
+ aResp->res.jsonValue[jsonPtr]["SpareDeviceCount"] = *spareDeviceCount;
}
- else if (property.first == "IsSpareDeviceInUse")
+
+ if (isSpareDeviceInUse != nullptr)
{
- const bool* value = std::get_if<bool>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["IsSpareDeviceEnabled"] = *value;
+ aResp->res.jsonValue[jsonPtr]["IsSpareDeviceEnabled"] =
+ *isSpareDeviceInUse;
}
- else if (property.first == "IsRankSpareEnabled")
+
+ if (isRankSpareEnabled != nullptr)
{
- const bool* value = std::get_if<bool>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["IsRankSpareEnabled"] = *value;
+ aResp->res.jsonValue[jsonPtr]["IsRankSpareEnabled"] =
+ *isRankSpareEnabled;
}
- else if (property.first == "MaxAveragePowerLimitmW")
+
+ if (maxAveragePowerLimitmW != nullptr)
{
- const auto* value =
- std::get_if<std::vector<uint32_t>>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG
- << "Invalid property type for MaxAveragePowerLimitmW";
- return;
- }
- aResp->res.jsonValue[jsonPtr]["MaxTDPMilliWatts"] = *value;
+ aResp->res.jsonValue[jsonPtr]["MaxTDPMilliWatts"] =
+ *maxAveragePowerLimitmW;
}
- else if (property.first == "ConfigurationLocked")
+
+ if (configurationLocked != nullptr)
{
- const bool* value = std::get_if<bool>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["ConfigurationLocked"] = *value;
+ aResp->res.jsonValue[jsonPtr]["ConfigurationLocked"] =
+ *configurationLocked;
}
- else if (property.first == "AllowedMemoryModes")
+
+ if (allowedMemoryModes != nullptr)
{
- const std::string* value = std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for FormFactor";
- return;
- }
constexpr const std::array<const char*, 3> values{"Volatile", "PMEM",
"Block"};
for (const char* v : values)
{
- if (value->ends_with(v))
+ if (allowedMemoryModes->ends_with(v))
{
aResp->res.jsonValue[jsonPtr]["OperatingMemoryModes"].push_back(
v);
@@ -390,52 +330,55 @@ inline void getPersistentMemoryProperties(
}
}
}
- else if (property.first == "MemoryMedia")
+
+ if (memoryMedia != nullptr)
{
- const std::string* value = std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for MemoryMedia";
- return;
- }
constexpr const std::array<const char*, 3> values{"DRAM", "NAND",
"Intel3DXPoint"};
for (const char* v : values)
{
- if (value->ends_with(v))
+ if (memoryMedia->ends_with(v))
{
aResp->res.jsonValue[jsonPtr]["MemoryMedia"].push_back(v);
break;
}
}
}
- // PersistantMemory.SecurityCapabilites interface
- else if (property.first == "ConfigurationLockCapable" ||
- property.first == "DataLockCapable" ||
- property.first == "PassphraseCapable")
+
+ if (configurationLockCapable != nullptr)
{
- const bool* value = std::get_if<bool>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["SecurityCapabilities"][property.first] =
- *value;
+ aResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
+ ["ConfigurationLockCapable"] =
+ *configurationLockCapable;
}
- else if (property.first == "MaxPassphraseCount" ||
- property.first == "PassphraseLockLimit")
+
+ if (dataLockCapable != nullptr)
{
- const uint64_t* value = std::get_if<uint64_t>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["SecurityCapabilities"][property.first] =
- *value;
+ aResp->res
+ .jsonValue[jsonPtr]["SecurityCapabilities"]["DataLockCapable"] =
+ *dataLockCapable;
+ }
+
+ if (passphraseCapable != nullptr)
+ {
+ aResp->res
+ .jsonValue[jsonPtr]["SecurityCapabilities"]["PassphraseCapable"] =
+ *passphraseCapable;
+ }
+
+ if (maxPassphraseCount != nullptr)
+ {
+ aResp->res
+ .jsonValue[jsonPtr]["SecurityCapabilities"]["MaxPassphraseCount"] =
+ *maxPassphraseCount;
+ }
+
+ if (passphraseLockLimit != nullptr)
+ {
+ aResp->res
+ .jsonValue[jsonPtr]["SecurityCapabilities"]["PassphraseLockLimit"] =
+ *passphraseLockLimit;
}
}
@@ -450,257 +393,202 @@ inline void
aResp->res.jsonValue[jsonPtr]["Status"]["State"] = "Enabled";
aResp->res.jsonValue[jsonPtr]["Status"]["Health"] = "OK";
- for (const auto& property : properties)
+ const uint16_t* memoryDataWidth = nullptr;
+ const size_t* memorySizeInKB = nullptr;
+ const std::string* partNumber = nullptr;
+ const std::string* serialNumber = nullptr;
+ const std::string* manufacturer = nullptr;
+ const uint16_t* revisionCode = nullptr;
+ const bool* present = nullptr;
+ const uint16_t* memoryTotalWidth = nullptr;
+ const std::string* ecc = nullptr;
+ const std::string* formFactor = nullptr;
+ const std::vector<uint16_t>* allowedSpeedsMT = nullptr;
+ const uint8_t* memoryAttributes = nullptr;
+ const uint16_t* memoryConfiguredSpeedInMhz = nullptr;
+ const std::string* memoryType = nullptr;
+ const std::string* channel = nullptr;
+ const std::string* memoryController = nullptr;
+ const std::string* slot = nullptr;
+ const std::string* socket = nullptr;
+ const std::string* sparePartNumber = nullptr;
+ const std::string* model = nullptr;
+ const std::string* locationCode = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), properties, "MemoryDataWidth",
+ memoryDataWidth, "MemorySizeInKB", memorySizeInKB, "PartNumber",
+ partNumber, "SerialNumber", serialNumber, "Present", present,
+ "MemoryTotalWidth", memoryTotalWidth, "ECC", ecc, "FormFactor",
+ formFactor, "AllowedSpeedsMT", allowedSpeedsMT, "MemoryAttributes",
+ memoryAttributes, "MemoryConfiguredSpeedInMhz",
+ memoryConfiguredSpeedInMhz, "MemoryType", memoryType, "Channel",
+ channel, "MemoryController", memoryController, "Slot", slot, "Socket",
+ socket, "SparePartNumber", sparePartNumber, "Model", model,
+ "LocationCode", locationCode);
+
+ if (!success)
{
- if (property.first == "MemoryDataWidth")
- {
- const uint16_t* value = std::get_if<uint16_t>(&property.second);
- if (value == nullptr)
- {
- continue;
- }
- aResp->res.jsonValue[jsonPtr]["DataWidthBits"] = *value;
- }
- else if (property.first == "MemorySizeInKB")
- {
- const size_t* memorySize = std::get_if<size_t>(&property.second);
- if (memorySize == nullptr)
- {
- // Important property not in desired type
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["CapacityMiB"] = (*memorySize >> 10);
- }
- else if (property.first == "PartNumber")
- {
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- continue;
- }
- aResp->res.jsonValue[jsonPtr]["PartNumber"] = *value;
- }
- else if (property.first == "SerialNumber")
- {
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- continue;
- }
- aResp->res.jsonValue[jsonPtr]["SerialNumber"] = *value;
- }
- else if (property.first == "Manufacturer")
- {
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- continue;
- }
- aResp->res.jsonValue[jsonPtr]["Manufacturer"] = *value;
- }
- else if (property.first == "RevisionCode")
- {
- const uint16_t* value = std::get_if<uint16_t>(&property.second);
+ messages::internalError(aResp->res);
+ return;
+ }
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for RevisionCode";
- return;
- }
- aResp->res.jsonValue[jsonPtr]["FirmwareRevision"] =
- std::to_string(*value);
- }
- else if (property.first == "Present")
- {
- const bool* value = std::get_if<bool>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for Dimm Presence";
- return;
- }
- if (!*value)
- {
- aResp->res.jsonValue[jsonPtr]["Status"]["State"] = "Absent";
- }
- }
- else if (property.first == "MemoryTotalWidth")
- {
- const uint16_t* value = std::get_if<uint16_t>(&property.second);
- if (value == nullptr)
- {
- continue;
- }
- aResp->res.jsonValue[jsonPtr]["BusWidthBits"] = *value;
- }
- else if (property.first == "ECC")
- {
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for ECC";
- return;
- }
- constexpr const std::array<const char*, 4> values{
- "NoECC", "SingleBitECC", "MultiBitECC", "AddressParity"};
+ if (memoryDataWidth != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["DataWidthBits"] = *memoryDataWidth;
+ }
- for (const char* v : values)
- {
- if (value->ends_with(v))
- {
- aResp->res.jsonValue[jsonPtr]["ErrorCorrection"] = v;
- break;
- }
- }
- }
- else if (property.first == "FormFactor")
- {
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for FormFactor";
- return;
- }
- constexpr const std::array<const char*, 11> values{
- "RDIMM", "UDIMM", "SO_DIMM", "LRDIMM",
- "Mini_RDIMM", "Mini_UDIMM", "SO_RDIMM_72b", "SO_UDIMM_72b",
- "SO_DIMM_16b", "SO_DIMM_32b", "Die"};
+ if (memorySizeInKB != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["CapacityMiB"] = (*memorySizeInKB >> 10);
+ }
- for (const char* v : values)
- {
- if (value->ends_with(v))
- {
- aResp->res.jsonValue[jsonPtr]["BaseModuleType"] = v;
- break;
- }
- }
- }
- else if (property.first == "AllowedSpeedsMT")
- {
- const std::vector<uint16_t>* value =
- std::get_if<std::vector<uint16_t>>(&property.second);
- if (value == nullptr)
- {
- continue;
- }
- nlohmann::json& jValue =
- aResp->res.jsonValue[jsonPtr]["AllowedSpeedsMHz"];
- jValue = nlohmann::json::array();
- for (uint16_t subVal : *value)
- {
- jValue.push_back(subVal);
- }
- }
- else if (property.first == "MemoryAttributes")
- {
- const uint8_t* value = std::get_if<uint8_t>(&property.second);
+ if (partNumber != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["PartNumber"] = *partNumber;
+ }
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG
- << "Invalid property type for MemoryAttributes";
- return;
- }
- aResp->res.jsonValue[jsonPtr]["RankCount"] =
- static_cast<uint64_t>(*value);
- }
- else if (property.first == "MemoryConfiguredSpeedInMhz")
- {
- const uint16_t* value = std::get_if<uint16_t>(&property.second);
- if (value == nullptr)
- {
- continue;
- }
- aResp->res.jsonValue[jsonPtr]["OperatingSpeedMhz"] = *value;
- }
- else if (property.first == "MemoryType")
+ if (serialNumber != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["SerialNumber"] = *serialNumber;
+ }
+
+ if (manufacturer != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["Manufacturer"] = *manufacturer;
+ }
+
+ if (revisionCode != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["FirmwareRevision"] =
+ std::to_string(*revisionCode);
+ }
+
+ if (present != nullptr && !*present)
+ {
+ aResp->res.jsonValue[jsonPtr]["Status"]["State"] = "Absent";
+ }
+
+ if (memoryTotalWidth != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["BusWidthBits"] = *memoryTotalWidth;
+ }
+
+ if (ecc != nullptr)
+ {
+ constexpr const std::array<const char*, 4> values{
+ "NoECC", "SingleBitECC", "MultiBitECC", "AddressParity"};
+
+ for (const char* v : values)
{
- const auto* value = std::get_if<std::string>(&property.second);
- if (value != nullptr)
+ if (ecc->ends_with(v))
{
- std::string memoryDeviceType =
- translateMemoryTypeToRedfish(*value);
- // Values like "Unknown" or "Other" will return empty
- // so just leave off
- if (!memoryDeviceType.empty())
- {
- aResp->res.jsonValue[jsonPtr]["MemoryDeviceType"] =
- memoryDeviceType;
- }
- if (value->find("DDR") != std::string::npos)
- {
- aResp->res.jsonValue[jsonPtr]["MemoryType"] = "DRAM";
- }
- else if (value->ends_with("Logical"))
- {
- aResp->res.jsonValue[jsonPtr]["MemoryType"] = "IntelOptane";
- }
+ aResp->res.jsonValue[jsonPtr]["ErrorCorrection"] = v;
+ break;
}
}
- // memory location interface
- else if (property.first == "Channel" ||
- property.first == "MemoryController" ||
- property.first == "Slot" || property.first == "Socket")
+ }
+
+ if (formFactor != nullptr)
+ {
+ constexpr const std::array<const char*, 11> values{
+ "RDIMM", "UDIMM", "SO_DIMM", "LRDIMM",
+ "Mini_RDIMM", "Mini_UDIMM", "SO_RDIMM_72b", "SO_UDIMM_72b",
+ "SO_DIMM_16b", "SO_DIMM_32b", "Die"};
+
+ for (const char* v : values)
{
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value == nullptr)
+ if (formFactor->ends_with(v))
{
- messages::internalError(aResp->res);
- return;
+ aResp->res.jsonValue[jsonPtr]["BaseModuleType"] = v;
+ break;
}
- aResp->res.jsonValue[jsonPtr]["MemoryLocation"][property.first] =
- *value;
}
- else if (property.first == "SparePartNumber")
+ }
+
+ if (allowedSpeedsMT != nullptr)
+ {
+ nlohmann::json& jValue =
+ aResp->res.jsonValue[jsonPtr]["AllowedSpeedsMHz"];
+ jValue = nlohmann::json::array();
+ for (uint16_t subVal : *allowedSpeedsMT)
{
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["SparePartNumber"] = *value;
+ jValue.push_back(subVal);
}
- else if (property.first == "Model")
+ }
+
+ if (memoryAttributes != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["RankCount"] =
+ static_cast<uint64_t>(*memoryAttributes);
+ }
+
+ if (memoryConfiguredSpeedInMhz != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["OperatingSpeedMhz"] =
+ *memoryConfiguredSpeedInMhz;
+ }
+
+ if (memoryType != nullptr)
+ {
+ std::string memoryDeviceType =
+ translateMemoryTypeToRedfish(*memoryType);
+ // Values like "Unknown" or "Other" will return empty
+ // so just leave off
+ if (!memoryDeviceType.empty())
{
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["Model"] = *value;
+ aResp->res.jsonValue[jsonPtr]["MemoryDeviceType"] =
+ memoryDeviceType;
}
- else if (property.first == "LocationCode")
+ if (memoryType->find("DDR") != std::string::npos)
{
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue[jsonPtr]["Location"]["PartLocation"]
- ["ServiceLabel"] = *value;
+ aResp->res.jsonValue[jsonPtr]["MemoryType"] = "DRAM";
}
- else
+ else if (memoryType->ends_with("Logical"))
{
- getPersistentMemoryProperties(aResp, property, jsonPtr);
+ aResp->res.jsonValue[jsonPtr]["MemoryType"] = "IntelOptane";
}
}
+
+ if (channel != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Channel"] = *channel;
+ }
+
+ if (memoryController != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["MemoryLocation"]["MemoryController"] =
+ *memoryController;
+ }
+
+ if (slot != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Slot"] = *slot;
+ }
+
+ if (socket != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Socket"] = *socket;
+ }
+
+ if (sparePartNumber != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["SparePartNumber"] = *sparePartNumber;
+ }
+
+ if (model != nullptr)
+ {
+ aResp->res.jsonValue[jsonPtr]["Model"] = *model;
+ }
+
+ if (locationCode != nullptr)
+ {
+ aResp->res
+ .jsonValue[jsonPtr]["Location"]["PartLocation"]["ServiceLabel"] =
+ *locationCode;
+ }
+
+ getPersistentMemoryProperties(aResp, properties, jsonPtr);
}
inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
@@ -713,7 +601,8 @@ inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
health->populate();
BMCWEB_LOG_DEBUG << "Get available system components.";
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, service, objPath, "",
[dimmId, aResp{std::move(aResp)}](
const boost::system::error_code ec,
const dbus::utility::DBusPropertiesMap& properties) {
@@ -724,8 +613,7 @@ inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
return;
}
assembleDimmProperties(dimmId, aResp, properties, ""_json_pointer);
- },
- service, objPath, "org.freedesktop.DBus.Properties", "GetAll", "");
+ });
}
inline void assembleDimmPartitionData(
@@ -733,63 +621,51 @@ inline void assembleDimmPartitionData(
const dbus::utility::DBusPropertiesMap& properties,
const nlohmann::json::json_pointer& regionPtr)
{
+ const std::string* memoryClassification = nullptr;
+ const uint64_t* offsetInKiB = nullptr;
+ const std::string* partitionId = nullptr;
+ const bool* passphraseState = nullptr;
+ const uint64_t* sizeInKiB = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), properties, "MemoryClassification",
+ memoryClassification, "OffsetInKiB", offsetInKiB, "PartitionId",
+ partitionId, "PassphraseState", passphraseState, "SizeInKiB",
+ sizeInKiB);
+
+ if (!success)
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+
nlohmann::json::object_t partition;
- for (const auto& [key, val] : properties)
+
+ if (memoryClassification != nullptr)
{
- if (key == "MemoryClassification")
- {
- const std::string* value = std::get_if<std::string>(&val);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- partition[key] = *value;
- }
- else if (key == "OffsetInKiB")
- {
- const uint64_t* value = std::get_if<uint64_t>(&val);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
+ partition["MemoryClassification"] = *memoryClassification;
+ }
- partition["OffsetMiB"] = (*value >> 10);
- }
- else if (key == "PartitionId")
- {
- const std::string* value = std::get_if<std::string>(&val);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- partition["RegionId"] = *value;
- }
+ if (offsetInKiB != nullptr)
+ {
+ partition["OffsetMiB"] = (*offsetInKiB >> 10);
+ }
- else if (key == "PassphraseState")
- {
- const bool* value = std::get_if<bool>(&val);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- partition["PassphraseEnabled"] = *value;
- }
- else if (key == "SizeInKiB")
- {
- const uint64_t* value = std::get_if<uint64_t>(&val);
- if (value == nullptr)
- {
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for SizeInKiB";
- return;
- }
- partition["SizeMiB"] = (*value >> 10);
- }
+ if (partitionId != nullptr)
+ {
+ partition["RegionId"] = *partitionId;
}
+
+ if (passphraseState != nullptr)
+ {
+ partition["PassphraseEnabled"] = *passphraseState;
+ }
+
+ if (sizeInKiB != nullptr)
+ {
+ partition["SizeMiB"] = (*sizeInKiB >> 10);
+ }
+
aResp->res.jsonValue[regionPtr].emplace_back(std::move(partition));
}
@@ -797,7 +673,9 @@ inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> aResp,
const std::string& service,
const std::string& path)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, service, path,
+ "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition",
[aResp{std::move(aResp)}](
const boost::system::error_code ec,
const dbus::utility::DBusPropertiesMap& properties) {
@@ -810,10 +688,9 @@ inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> aResp,
}
nlohmann::json::json_pointer regionPtr = "/Regions"_json_pointer;
assembleDimmPartitionData(aResp, properties, regionPtr);
- },
+ }
- service, path, "org.freedesktop.DBus.Properties", "GetAll",
- "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition");
+ );
}
inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> aResp,
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index d0485f0136..cf63bd7078 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -713,21 +713,24 @@ inline std::string getHealth(nlohmann::json& sensorJson,
return "Critical";
}
- // Check if sensor has critical threshold alarm
-
- for (const auto& [valueName, value] : valuesDict)
- {
- if (valueName == "CriticalAlarmHigh" || valueName == "CriticalAlarmLow")
+ const bool* criticalAlarmHigh = nullptr;
+ const bool* criticalAlarmLow = nullptr;
+ const bool* warningAlarmHigh = nullptr;
+ const bool* warningAlarmLow = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), valuesDict, "CriticalAlarmHigh",
+ criticalAlarmHigh, "CriticalAlarmLow", criticalAlarmLow,
+ "WarningAlarmHigh", warningAlarmHigh, "WarningAlarmLow",
+ warningAlarmLow);
+
+ if (success)
+ {
+ // Check if sensor has critical threshold alarm
+ if ((criticalAlarmHigh != nullptr && *criticalAlarmHigh) ||
+ (criticalAlarmLow != nullptr && *criticalAlarmLow))
{
- const bool* asserted = std::get_if<bool>(&value);
- if (asserted == nullptr)
- {
- BMCWEB_LOG_ERROR << "Illegal sensor threshold";
- }
- else if (*asserted)
- {
- return "Critical";
- }
+ return "Critical";
}
}
@@ -737,27 +740,20 @@ inline std::string getHealth(nlohmann::json& sensorJson,
return "Critical";
}
- // If current health in JSON object is already Warning, return that. This
+ // If current health in JSON object is already Warning, return that. This
// should override the sensor status, which might be less severe.
if (currentHealth == "Warning")
{
return "Warning";
}
- // Check if sensor has warning threshold alarm
- for (const auto& [valueName, value] : valuesDict)
+ if (success)
{
- if (valueName == "WarningAlarmHigh" || valueName == "WarningAlarmLow")
+ // Check if sensor has warning threshold alarm
+ if ((warningAlarmHigh != nullptr && *warningAlarmHigh) ||
+ (warningAlarmLow != nullptr && *warningAlarmLow))
{
- const bool* asserted = std::get_if<bool>(&value);
- if (asserted == nullptr)
- {
- BMCWEB_LOG_ERROR << "Illegal sensor threshold";
- }
- else if (*asserted)
- {
- return "Warning";
- }
+ return "Warning";
}
}
@@ -806,16 +802,15 @@ inline void objectPropertiesToJson(
{
// Assume values exist as is (10^0 == 1) if no scale exists
int64_t scaleMultiplier = 0;
- for (const auto& [valueName, value] : propertiesDict)
+
+ const int64_t* scale = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), propertiesDict, "Scale", scale);
+
+ if (success && scale != nullptr)
{
- if (valueName == "Scale")
- {
- const int64_t* int64Value = std::get_if<int64_t>(&value);
- if (int64Value != nullptr)
- {
- scaleMultiplier = *int64Value;
- }
- }
+ scaleMultiplier = *scale;
}
if (chassisSubNode == sensors::node::sensors)
@@ -2990,7 +2985,9 @@ inline void
const std::string& connectionName = valueIface.first;
BMCWEB_LOG_DEBUG << "Looking up " << connectionName;
BMCWEB_LOG_DEBUG << "Path " << sensorPath;
- crow::connections::systemBus->async_method_call(
+
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, connectionName, sensorPath, "",
[asyncResp,
sensorPath](const boost::system::error_code ec,
const ::dbus::utility::DBusPropertiesMap& valuesDict) {
@@ -3005,9 +3002,7 @@ inline void
std::string type = path.filename();
objectPropertiesToJson(name, type, sensors::node::sensors, valuesDict,
asyncResp->res.jsonValue, nullptr);
- },
- connectionName, sensorPath, "org.freedesktop.DBus.Properties", "GetAll",
- "");
+ });
}
inline void handleSensorGet(App& app, const crow::Request& req,