From 8d85b0f37638c606e195753553fe21cbe8663cd1 Mon Sep 17 00:00:00 2001 From: wangjue Date: Tue, 15 Oct 2024 18:42:41 +0800 Subject: [PATCH] Add Status interface to settableInterfaces Signed-off-by: wangjue %% original patch: 0001-Add-Status-interface-to-settableInterfaces.patch --- src/entity_manager.cpp | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/entity_manager.cpp b/src/entity_manager.cpp index ee08c00..24da084 100644 --- a/src/entity_manager.cpp +++ b/src/entity_manager.cpp @@ -52,6 +52,9 @@ constexpr const char* tempConfigDir = "/tmp/configuration/"; constexpr const char* lastConfiguration = "/tmp/configuration/last.json"; constexpr const char* currentConfiguration = "/var/configuration/system.json"; constexpr const char* globalSchema = "global.json"; +constexpr auto configIfaceName = "xyz.openbmc_project.Configuration.Status"; +constexpr auto statusPropName = "Status"; +bool internalSet = false; const boost::container::flat_map probeTypes{{{"FALSE", probe_type_codes::FALSE_T}, @@ -61,8 +64,8 @@ const boost::container::flat_map {"FOUND", probe_type_codes::FOUND}, {"MATCH_ONE", probe_type_codes::MATCH_ONE}}}; -static constexpr std::array settableInterfaces = { - "FanProfile", "Pid", "Pid.Zone", "Stepwise", "Thresholds", "Polling"}; +static constexpr std::array settableInterfaces = { + "FanProfile", "Pid", "Pid.Zone", "Stepwise", "Thresholds", "Polling", "Status", "Description", "Health"}; using JsonVariantType = std::variant, std::vector, std::string, int64_t, uint64_t, double, int32_t, uint32_t, int16_t, @@ -216,9 +219,31 @@ void addProperty(const std::string& name, const PropertyType& value, iface->register_property( name, value, [&systemConfiguration, - jsonPointerString{std::string(jsonPointerString)}]( - const PropertyType& newVal, PropertyType& val) { - val = newVal; + jsonPointerString{std::string(jsonPointerString)}, + interface = iface->get_interface_name(), + propertyName = name](const PropertyType& newVal, PropertyType& val) { + // if set from external source, for status property, only + // keep the bits 0..15 + if (!internalSet && interface == configIfaceName && + propertyName == statusPropName) + { + if constexpr (std::is_same_v) + { + auto tmp = static_cast(newVal); + tmp &= 0xFFFF; + val = static_cast( + (static_cast(val) & ~0xFFFF) | tmp); + } + else + { + val = newVal; + } + } + else + { + val = newVal; + } + if (!setJsonFromPointer(jsonPointerString, val, systemConfiguration)) { std::cerr << "error setting json field\n"; @@ -1280,6 +1305,7 @@ int main() entityIface->register_method("ReScan", [&]() { propertiesChangedCallback(systemConfiguration, objServer); }); + entityIface->initialize(); if (fwVersionIsSame()) -- 2.34.1