diff --git a/redfish-core/include/utils/resource_utils.hpp b/redfish-core/include/utils/resource_utils.hpp new file mode 100644 index 000000000..eb9336c9e --- /dev/null +++ b/redfish-core/include/utils/resource_utils.hpp @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Copyright OpenBMC Authors +#pragma once + +#include "async_resp.hpp" +#include "dbus_utility.hpp" +#include "error_messages.hpp" +#include "generated/enums/resource.hpp" +#include "logging.hpp" + +#include + +#include +#include +#include +#include + +#include +#include +#include + +namespace redfish +{ +namespace resource_utils +{ + +struct ResourceStatus +{ + bool present = true; + bool available = true; + bool functional = true; + uint8_t pending = 0; +}; + +/** + * @brief Fetches resource status from DBus interfaces + * + */ +inline void determineResourceState( + const std::shared_ptr& asyncResp, + const std::shared_ptr& status, + const nlohmann::json::json_pointer& jsonPtr) +{ + BMCWEB_LOG_DEBUG("determineResourceState"); + if (--status->pending != 0) + { + return; + } + + nlohmann::json& statusJson = asyncResp->res.jsonValue[jsonPtr]["Status"]; + + // Absent takes priority over unavailable + if (!status->present) + { + statusJson["State"] = resource::State::Absent; + } + else if (!status->available) + { + statusJson["State"] = resource::State::UnavailableOffline; + } + else + { + statusJson["State"] = resource::State::Enabled; + } + + if (!status->functional) + { + statusJson["Health"] = resource::Health::Critical; + } + else + { + statusJson["Health"] = resource::Health::OK; + } +} + +/** + * @brief Helper to fetch boolean property and update status + * + */ +inline void getStatusProperty( + const std::shared_ptr& asyncResp, + const std::shared_ptr& status, const std::string& service, + const std::string& path, const std::string& interface, + const std::string& property, const nlohmann::json::json_pointer& jsonPtr, + std::function&& callback) +{ + sdbusplus::asio::getProperty( + *crow::connections::systemBus, service, path, interface, property, + [status, asyncResp, property, jsonPtr, callback{std::move(callback)}]( + const boost::system::error_code& ec, bool value) { + if (ec) + { + if (ec.value() != EBADR) + { + BMCWEB_LOG_ERROR("DBUS response error for {}, ec {}", + property, ec.value()); + messages::internalError(asyncResp->res); + return; + } + } + else + { + callback(*status, value); + } + determineResourceState(asyncResp, status, jsonPtr); + }); +} + +/* + * @brief Retrieves the status of the resource's state and health + * + * Queries three interfaces: + * - xyz.openbmc_project.Inventory.Item::Present + * - xyz.openbmc_project.State.Decorator.Availability::Available + * - xyz.openbmc_project.State.Decorator.OperationalStatus::Functional + */ +inline void getResourceStatus( + const std::shared_ptr& asyncResp, + const std::string& service, const std::string& path, + const nlohmann::json::json_pointer& jsonPtr) +{ + // Default values + asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] = + resource::State::Enabled; + asyncResp->res.jsonValue[jsonPtr]["Status"]["Health"] = + resource::Health::OK; + + BMCWEB_LOG_DEBUG("getResourceStatus"); + auto status = std::make_shared(); + status->pending = 3; + + getStatusProperty(asyncResp, status, service, path, + "xyz.openbmc_project.Inventory.Item", "Present", jsonPtr, + [](ResourceStatus& s, bool val) { s.present = val; }); + getStatusProperty(asyncResp, status, service, path, + "xyz.openbmc_project.State.Decorator.Availability", + "Available", jsonPtr, + [](ResourceStatus& s, bool val) { s.available = val; }); + getStatusProperty(asyncResp, status, service, path, + "xyz.openbmc_project.State.Decorator.OperationalStatus", + "Functional", jsonPtr, + [](ResourceStatus& s, bool val) { s.functional = val; }); +} + +inline void getResourceStatus( + const std::shared_ptr& asyncResp, + const std::string& service, const std::string& path) +{ + getResourceStatus(asyncResp, service, path, ""_json_pointer); +} + +} // namespace resource_utils +} // namespace redfish diff --git a/redfish-core/lib/assembly.hpp b/redfish-core/lib/assembly.hpp index 3e88ef63c..b466b3c25 100644 --- a/redfish-core/lib/assembly.hpp +++ b/redfish-core/lib/assembly.hpp @@ -19,6 +19,7 @@ #include "utils/asset_utils.hpp" #include "utils/json_utils.hpp" #include "utils/name_utils.hpp" +#include "utils/resource_utils.hpp" #include @@ -77,14 +78,11 @@ inline void getAssemblyLocationCode( }); } -inline void getAssemblyState( +inline void getAssemblyReadyToRemove( const std::shared_ptr& asyncResp, const auto& serviceName, const auto& assembly, const nlohmann::json::json_pointer& assemblyJsonPtr) { - asyncResp->res.jsonValue[assemblyJsonPtr]["Status"]["State"] = - resource::State::Enabled; - dbus::utility::getProperty( serviceName, assembly, "xyz.openbmc_project.Inventory.Item", "Present", [asyncResp, assemblyJsonPtr, @@ -99,12 +97,6 @@ inline void getAssemblyState( return; } - if (!value) - { - asyncResp->res.jsonValue[assemblyJsonPtr]["Status"]["State"] = - resource::State::Absent; - } - std::string fru = sdbusplus::message::object_path(assembly).filename(); // Special handling for LCD and base panel CM. @@ -122,36 +114,6 @@ inline void getAssemblyState( }); } -void getAssemblyHealth(const std::shared_ptr& asyncResp, - const auto& serviceName, const auto& assembly, - const nlohmann::json::json_pointer& assemblyJsonPtr) -{ - asyncResp->res.jsonValue[assemblyJsonPtr]["Status"]["Health"] = - resource::Health::OK; - - dbus::utility::getProperty( - serviceName, assembly, - "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", - [asyncResp, assemblyJsonPtr](const boost::system::error_code& ec, - bool functional) { - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - if (!functional) - { - asyncResp->res.jsonValue[assemblyJsonPtr]["Status"]["Health"] = - resource::Health::Critical; - } - }); -} - inline void afterGetDbusObject( const std::shared_ptr& asyncResp, const std::string& assembly, @@ -188,14 +150,11 @@ inline void afterGetDbusObject( } else if (interface == "xyz.openbmc_project.Inventory.Item") { - getAssemblyState(asyncResp, serviceName, assembly, - assemblyJsonPtr); - } - else if (interface == - "xyz.openbmc_project.State.Decorator.OperationalStatus") - { - getAssemblyHealth(asyncResp, serviceName, assembly, - assemblyJsonPtr); + resource_utils::getResourceStatus(asyncResp, serviceName, + assembly, assemblyJsonPtr); + + getAssemblyReadyToRemove(asyncResp, serviceName, assembly, + assemblyJsonPtr); } } } diff --git a/redfish-core/lib/cable.hpp b/redfish-core/lib/cable.hpp index df0369b17..4e6834a34 100644 --- a/redfish-core/lib/cable.hpp +++ b/redfish-core/lib/cable.hpp @@ -18,6 +18,7 @@ #include "utils/chassis_utils.hpp" #include "utils/collection.hpp" #include "utils/dbus_utils.hpp" +#include "utils/resource_utils.hpp" #include #include @@ -159,35 +160,6 @@ inline void fillCablePartNumber( }); } -inline void fillCableHealthState( - const std::shared_ptr& asyncResp, - const std::string& cableObjectPath, const std::string& service) -{ - dbus::utility::getProperty( - *crow::connections::systemBus, service, cableObjectPath, - "xyz.openbmc_project.Inventory.Item", "Present", - [asyncResp, - cableObjectPath](const boost::system::error_code& ec, bool present) { - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR( - "get presence failed for Cable {} with error {}", - cableObjectPath, ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - if (!present) - { - asyncResp->res.jsonValue["Status"]["State"] = - resource::State::Absent; - } - }); -} - inline void afterGetCableUpstreamResources( const std::shared_ptr& asyncResp, const boost::system::error_code& ec, @@ -490,7 +462,8 @@ inline void getCableProperties( } else if (interface == "xyz.openbmc_project.Inventory.Item") { - fillCableHealthState(asyncResp, cableObjectPath, service); + resource_utils::getResourceStatus(asyncResp, service, + cableObjectPath); } else if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") diff --git a/redfish-core/lib/fabric_adapters.hpp b/redfish-core/lib/fabric_adapters.hpp index a2e2a0b3e..741fe53db 100644 --- a/redfish-core/lib/fabric_adapters.hpp +++ b/redfish-core/lib/fabric_adapters.hpp @@ -19,6 +19,7 @@ #include "utils/collection.hpp" #include "utils/json_utils.hpp" #include "utils/name_utils.hpp" +#include "utils/resource_utils.hpp" #include @@ -65,59 +66,6 @@ inline void getFabricAdapterLocation( }); } -inline void getFabricAdapterState( - const std::shared_ptr& asyncResp, - const std::string& serviceName, const std::string& fabricAdapterPath) -{ - dbus::utility::getProperty( - serviceName, fabricAdapterPath, "xyz.openbmc_project.Inventory.Item", - "Present", - [asyncResp](const boost::system::error_code& ec, const bool present) { - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error for State"); - messages::internalError(asyncResp->res); - } - return; - } - - if (!present) - { - asyncResp->res.jsonValue["Status"]["State"] = - resource::State::Absent; - } - }); -} - -inline void getFabricAdapterHealth( - const std::shared_ptr& asyncResp, - const std::string& serviceName, const std::string& fabricAdapterPath) -{ - dbus::utility::getProperty( - serviceName, fabricAdapterPath, - "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", - [asyncResp](const boost::system::error_code& ec, - const bool functional) { - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error for Health"); - messages::internalError(asyncResp->res); - } - return; - } - - if (!functional) - { - asyncResp->res.jsonValue["Status"]["Health"] = - resource::Health::Critical; - } - }); -} - inline void afterDoCheckFabricAdapterChassis( const std::shared_ptr& asyncResp, const dbus::utility::MapperEndPoints& pcieSlotPaths, @@ -259,9 +207,6 @@ inline void doAdapterGet( asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( "/redfish/v1/Systems/{}/FabricAdapters/{}", systemName, adapterId); - asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; - asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; - asyncResp->res.jsonValue["Ports"]["@odata.id"] = boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters/{}/Ports", systemName, adapterId); @@ -281,8 +226,8 @@ inline void doAdapterGet( getFabricAdapterLocation(asyncResp, serviceName, fabricAdapterPath); asset_utils::getAssetInfo(asyncResp, serviceName, fabricAdapterPath, ""_json_pointer, true); - getFabricAdapterState(asyncResp, serviceName, fabricAdapterPath); - getFabricAdapterHealth(asyncResp, serviceName, fabricAdapterPath); + resource_utils::getResourceStatus(asyncResp, serviceName, + fabricAdapterPath); getLocationIndicatorActive(asyncResp, fabricAdapterPath); // if the adapter also implements this interface, link the adapter schema to diff --git a/redfish-core/lib/fabric_ports.hpp b/redfish-core/lib/fabric_ports.hpp index 78040a5b3..808a09e50 100644 --- a/redfish-core/lib/fabric_ports.hpp +++ b/redfish-core/lib/fabric_ports.hpp @@ -18,6 +18,7 @@ #include "registries/privilege_registry.hpp" #include "utils/json_utils.hpp" #include "utils/name_utils.hpp" +#include "utils/resource_utils.hpp" #include @@ -72,69 +73,6 @@ inline void getFabricPortLocation( std::bind_front(afterGetFabricPortLocation, asyncResp)); } -inline void afterGetFabricPortState( - const std::shared_ptr& asyncResp, - const boost::system::error_code& ec, bool present) -{ - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error for State, ec {}", - ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - if (!present) - { - asyncResp->res.jsonValue["Status"]["State"] = resource::State::Absent; - } -} - -inline void getFabricPortState( - const std::shared_ptr& asyncResp, - const std::string& portPath, const std::string& serviceName) -{ - sdbusplus::asio::getProperty( - *crow::connections::systemBus, serviceName, portPath, - "xyz.openbmc_project.Inventory.Item", "Present", - std::bind_front(afterGetFabricPortState, asyncResp)); -} - -inline void afterGetFabricPortHealth( - const std::shared_ptr& asyncResp, - const boost::system::error_code& ec, bool functional) -{ - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error for Health, ec {}", - ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - if (!functional) - { - asyncResp->res.jsonValue["Status"]["Health"] = - resource::Health::Critical; - } -} - -inline void getFabricPortHealth( - const std::shared_ptr& asyncResp, - const std::string& portPath, const std::string& serviceName) -{ - sdbusplus::asio::getProperty( - *crow::connections::systemBus, serviceName, portPath, - "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", - std::bind_front(afterGetFabricPortHealth, asyncResp)); -} - inline void getFabricPortProperties( const std::shared_ptr& asyncResp, const std::string& systemName, const std::string& adapterId, @@ -161,12 +99,8 @@ inline void getFabricPortProperties( nlohmann::json::json_pointer ptr("/Name"); name_util::getPrettyName(asyncResp, portPath, serviceName, ptr); - asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; - asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; - getFabricPortLocation(asyncResp, portPath, serviceName); - getFabricPortState(asyncResp, portPath, serviceName); - getFabricPortHealth(asyncResp, portPath, serviceName); + resource_utils::getResourceStatus(asyncResp, serviceName, portPath); getLocationIndicatorActive(asyncResp, portPath); } diff --git a/redfish-core/lib/fan.hpp b/redfish-core/lib/fan.hpp index 052c7b57b..28e4052f9 100644 --- a/redfish-core/lib/fan.hpp +++ b/redfish-core/lib/fan.hpp @@ -17,6 +17,7 @@ #include "utils/fan_utils.hpp" #include "utils/json_utils.hpp" #include "utils/name_utils.hpp" +#include "utils/resource_utils.hpp" #include @@ -228,59 +229,6 @@ inline void addFanCommonProperties(crow::Response& resp, resp.jsonValue["Id"] = fanId; resp.jsonValue["@odata.id"] = boost::urls::format( "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans/{}", chassisId, fanId); - resp.jsonValue["Status"]["State"] = resource::State::Enabled; - resp.jsonValue["Status"]["Health"] = resource::Health::OK; -} - -inline void getFanHealth(const std::shared_ptr& asyncResp, - const std::string& fanPath, const std::string& service) -{ - dbus::utility::getProperty( - service, fanPath, - "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", - [asyncResp](const boost::system::error_code& ec, const bool value) { - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error for Health {}", - ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - if (!value) - { - asyncResp->res.jsonValue["Status"]["Health"] = - resource::Health::Critical; - } - }); -} - -inline void getFanState(const std::shared_ptr& asyncResp, - const std::string& fanPath, const std::string& service) -{ - dbus::utility::getProperty( - service, fanPath, "xyz.openbmc_project.Inventory.Item", "Present", - [asyncResp](const boost::system::error_code& ec, const bool value) { - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error for State {}", - ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - if (!value) - { - asyncResp->res.jsonValue["Status"]["State"] = - resource::State::Absent; - } - }); } inline void getFanLocation(const std::shared_ptr& asyncResp, @@ -314,8 +262,7 @@ inline void afterGetValidFanObject( const std::string& fanPath, const std::string& service) { addFanCommonProperties(asyncResp->res, chassisId, fanId); - getFanState(asyncResp, fanPath, service); - getFanHealth(asyncResp, fanPath, service); + resource_utils::getResourceStatus(asyncResp, service, fanPath); asset_utils::getAssetInfo(asyncResp, service, fanPath, ""_json_pointer, true); getFanLocation(asyncResp, fanPath, service); diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp index 75039bb3d..bf69f44fe 100644 --- a/redfish-core/lib/memory.hpp +++ b/redfish-core/lib/memory.hpp @@ -442,6 +442,7 @@ inline void assembleDimmProperties( const std::string* model = nullptr; const std::string* locationCode = nullptr; const bool* functional = nullptr; + const bool* available = nullptr; const bool success = sdbusplus::unpackPropertiesNoThrow( dbus_utils::UnpackErrorPrinter(), properties, "MemoryDataWidth", @@ -454,7 +455,8 @@ inline void assembleDimmProperties( memoryConfiguredSpeedInMhz, "MemoryType", memoryType, "Channel", channel, "MemoryController", memoryController, "Slot", slot, "Socket", socket, "SparePartNumber", sparePartNumber, "Model", model, - "LocationCode", locationCode, "Functional", functional); + "LocationCode", locationCode, "Functional", functional, "Available", + available); if (!success) { @@ -499,6 +501,11 @@ inline void assembleDimmProperties( asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] = resource::State::Absent; } + else if (available != nullptr && !*available) + { + asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] = + resource::State::UnavailableOffline; + } if (memoryTotalWidth != nullptr) { diff --git a/redfish-core/lib/power_supply.hpp b/redfish-core/lib/power_supply.hpp index a73f2ce40..d5dad0f30 100644 --- a/redfish-core/lib/power_supply.hpp +++ b/redfish-core/lib/power_supply.hpp @@ -17,6 +17,7 @@ #include "utils/dbus_utils.hpp" #include "utils/json_utils.hpp" #include "utils/name_utils.hpp" +#include "utils/resource_utils.hpp" #include "utils/time_utils.hpp" #include @@ -223,91 +224,6 @@ inline void getValidPowerSupplyPath( }); } -inline void getPowerSupplyState( - const std::shared_ptr& asyncResp, - const std::string& service, const std::string& path, bool available) -{ - dbus::utility::getProperty( - service, path, "xyz.openbmc_project.Inventory.Item", "Present", - [asyncResp, - available](const boost::system::error_code& ec, const bool value) { - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error for State {}", - ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - if (!value) - { - asyncResp->res.jsonValue["Status"]["State"] = - resource::State::Absent; - } - else if (!available) - { - asyncResp->res.jsonValue["Status"]["State"] = - resource::State::UnavailableOffline; - } - }); -} - -inline void getPowerSupplyHealth( - const std::shared_ptr& asyncResp, - const std::string& service, const std::string& path, bool available) -{ - dbus::utility::getProperty( - service, path, "xyz.openbmc_project.State.Decorator.OperationalStatus", - "Functional", - [asyncResp, - available](const boost::system::error_code& ec, const bool value) { - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error for Health {}", - ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - if (!value || !available) - { - asyncResp->res.jsonValue["Status"]["Health"] = - resource::Health::Critical; - } - }); -} - -inline void getPowerSupplyStateAndHealth( - const std::shared_ptr& asyncResp, - const std::string& service, const std::string& path) -{ - dbus::utility::getProperty( - service, path, "xyz.openbmc_project.State.Decorator.Availability", - "Available", - [asyncResp, service, - path](const boost::system::error_code& ec, const bool available) { - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error for Available {}", - ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - getPowerSupplyState(asyncResp, service, path, available); - getPowerSupplyHealth(asyncResp, service, path, available); - }); -} - inline void getPowerSupplyAsset( const std::shared_ptr& asyncResp, const std::string& service, const std::string& path) @@ -504,7 +420,7 @@ inline void doPowerSupplyGet( asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; - getPowerSupplyStateAndHealth(asyncResp, service, powerSupplyPath); + resource_utils::getResourceStatus(asyncResp, service, powerSupplyPath); getPowerSupplyAsset(asyncResp, service, powerSupplyPath); getPowerSupplyFirmwareVersion(asyncResp, service, powerSupplyPath); getPowerSupplyLocation(asyncResp, service, powerSupplyPath); diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp index 4691fa02d..3a35690ce 100644 --- a/redfish-core/lib/processor.hpp +++ b/redfish-core/lib/processor.hpp @@ -22,6 +22,7 @@ #include "utils/hw_isolation.hpp" #include "utils/json_utils.hpp" #include "utils/name_utils.hpp" +#include "utils/resource_utils.hpp" #include @@ -167,6 +168,20 @@ inline void getCpuDataByInterface( resource::State::Absent; } } + else if (property.first == "Available") + { + const bool* cpuAvailable = std::get_if(&property.second); + if (cpuAvailable == nullptr) + { + messages::internalError(asyncResp->res); + return; + } + if (!*cpuAvailable) + { + asyncResp->res.jsonValue["Status"]["State"] = + resource::State::UnavailableOffline; + } + } else if (property.first == "Functional") { const bool* cpuFunctional = std::get_if(&property.second); @@ -537,10 +552,11 @@ inline void getAcceleratorDataByService( const bool* functional = nullptr; const bool* present = nullptr; + const bool* available = nullptr; const bool success = sdbusplus::unpackPropertiesNoThrow( dbus_utils::UnpackErrorPrinter(), properties, "Functional", - functional, "Present", present); + functional, "Present", present, "Available", available); if (!success) { @@ -548,19 +564,23 @@ inline void getAcceleratorDataByService( return; } - std::string state = "Enabled"; - std::string health = "OK"; + auto state = resource::State::Enabled; + auto health = resource::Health::OK; if (present != nullptr && !*present) { - state = "Absent"; + state = resource::State::Absent; + } + else if (available != nullptr && !*available) + { + state = resource::State::UnavailableOffline; } if (functional != nullptr && !*functional) { - if (state == "Enabled") + if (state == resource::State::Enabled) { - health = "Critical"; + health = resource::Health::Critical; } } @@ -1026,65 +1046,6 @@ inline void getSubProcessorsCoreHealth( }); } -inline void afterGetSubProcessorsCorePresent( - const std::shared_ptr& asyncResp, - const boost::system::error_code& ec, bool present) -{ - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error for Available {}", - ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - if (!present) - { - asyncResp->res.jsonValue["Status"]["State"] = resource::State::Absent; - return; - } -} - -inline void afterGetSubProcessorsCoreAvailable( - const std::shared_ptr& asyncResp, - const std::string& service, const std::string& corePath, - const boost::system::error_code& ec, bool available) -{ - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error, ec: {}", ec.value()); - messages::internalError(asyncResp->res); - } - return; - } - - if (!available) - { - asyncResp->res.jsonValue["Status"]["State"] = - resource::State::UnavailableOffline; - } - - dbus::utility::getProperty( - service, corePath, "xyz.openbmc_project.Inventory.Item", "Present", - std::bind_front(afterGetSubProcessorsCorePresent, asyncResp)); -} - -inline void getSubProcessorsCoreState( - const std::shared_ptr& asyncResp, - const std::string& service, const std::string& corePath) -{ - dbus::utility::getProperty( - service, corePath, "xyz.openbmc_project.State.Decorator.Availability", - "Available", - std::bind_front(afterGetSubProcessorsCoreAvailable, asyncResp, service, - corePath)); -} - inline void getEnabledStatus( const std::shared_ptr& asyncResp, const std::string& service, const std::string& objPath, @@ -1122,9 +1083,6 @@ inline void getSubProcessorsCoreData( asyncResp->res.jsonValue["Name"] = "SubProcessor"; asyncResp->res.jsonValue["Id"] = coreId; - asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; - asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; - for (const auto& [service, interfaces] : object) { for (const auto& intf : interfaces) @@ -1140,8 +1098,7 @@ inline void getSubProcessorsCoreData( } } - getSubProcessorsCoreState(asyncResp, service, corePath); - getSubProcessorsCoreHealth(asyncResp, service, corePath); + resource_utils::getResourceStatus(asyncResp, service, corePath); if constexpr (BMCWEB_HW_ISOLATION) {