From 803d35bce81427bc82e999c45174fc2e9b6c3871 Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Wed, 9 May 2018 12:15:46 -0500 Subject: Use shared getProperty function in control manager When the manager checks a getProperty condition for fan control, it should use the shared getProperty function that now returns a DbusMethodError to better exit/restart the fan control application. Tested: Condition check functions the same Change-Id: I37f83ef4273343bd527ac149ac5eee213d0ad63d Signed-off-by: Matthew Barth --- control/manager.cpp | 58 +++++++---------------------------------------------- 1 file changed, 7 insertions(+), 51 deletions(-) (limited to 'control') diff --git a/control/manager.cpp b/control/manager.cpp index d5f97d7..a322c10 100644 --- a/control/manager.cpp +++ b/control/manager.cpp @@ -21,6 +21,7 @@ #include #include "manager.hpp" #include "utility.hpp" +#include "sdbusplus.hpp" namespace phosphor { @@ -36,50 +37,6 @@ constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; constexpr auto FAN_CONTROL_READY_TARGET = "obmc-fan-control-ready@0.target"; -constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties"; -constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; -constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; -constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; - - -/** - * Get the current value of the D-Bus property under the specified path - * and interface. - * - * @param[in] bus - The D-Bus bus object - * @param[in] path - The D-Bus path - * @param[in] interface - The D-Bus interface - * @param[in] propertyName - The D-Bus property - * @param[out] value - The D-Bus property's value - */ -template -void getProperty(sdbusplus::bus::bus& bus, - const std::string& path, - const std::string& interface, - const std::string& propertyName, - T& value) -{ - sdbusplus::message::variant property; - std::string service = phosphor::fan::util::getService(path, interface, bus); - - auto method = bus.new_method_call(service.c_str(), - path.c_str(), - PROPERTY_INTERFACE, - "Get"); - - method.append(interface, propertyName); - auto reply = bus.call(method); - - if (reply.is_method_error()) - { - log("Error in call response for retrieving property"); - elog(); - } - reply.read(property); - value = sdbusplus::message::variant_ns::get(property); -} - - /** * Check if a condition is true. Conditions are used to determine * which fan zone to use. @@ -95,17 +52,16 @@ bool checkCondition(sdbusplus::bus::bus& bus, const auto& c) for (auto& p : properties) { - bool value = std::get(p); - bool propertyValue; + auto value = std::get(p); // TODO openbmc/openbmc#1769: Support more types than just getProperty. if (type.compare("getProperty") == 0) { - getProperty(bus, - std::get(p), - std::get(p), - std::get(p), - propertyValue); + auto propertyValue = util::SDBusPlus::getProperty( + bus, + std::get(p), + std::get(p), + std::get(p)); if (value != propertyValue) { -- cgit v1.2.1