From 26e96122ee89ccaa2de317deb70af5dc5011f48f Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Wed, 9 May 2018 14:55:41 -0500 Subject: Use setProperty function in fan set speed When a fan's target speed is set, using the setProperty function allows for better handling of dbus failures setting the fan target property. If a failure occurs setting this property, a journal entry is created and a DBusPropertyError exception is thrown to allow the fan control application to exit and restart quickly in its allowed attempts configured in systemd. Tested: Fan control application logs an error to the journal and then terminates when a dbus error occurs setting a fan target speed. Change-Id: Ibd4bd8b18b6010727831d97e32c14fd6c681e170 Signed-off-by: Matthew Barth --- control/fan.cpp | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'control') diff --git a/control/fan.cpp b/control/fan.cpp index 40ec6b4..d4303cf 100644 --- a/control/fan.cpp +++ b/control/fan.cpp @@ -13,10 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include -#include -#include #include #include "fan.hpp" #include "sdbusplus.hpp" @@ -30,14 +26,10 @@ namespace control // For throwing exception using namespace phosphor::logging; -using InternalFailure = sdbusplus::xyz::openbmc_project::Common:: - Error::InternalFailure; -constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties"; constexpr auto FAN_SENSOR_PATH = "/xyz/openbmc_project/sensors/fan_tach/"; constexpr auto FAN_TARGET_PROPERTY = "Target"; - Fan::Fan(sdbusplus::bus::bus& bus, const FanDefinition& def): _bus(bus), _name(std::get(def)), @@ -70,25 +62,16 @@ Fan::Fan(sdbusplus::bus::bus& bus, const FanDefinition& def): void Fan::setSpeed(uint64_t speed) { - sdbusplus::message::variant value = speed; - std::string property{FAN_TARGET_PROPERTY}; - for (auto& sensor : _sensors) { - auto method = _bus.new_method_call(sensor.second.c_str(), - sensor.first.c_str(), - PROPERTY_INTERFACE, - "Set"); - method.append(_interface, property, value); - - auto response = _bus.call(method); - if (response.is_method_error()) - { - log( - "Failed call to set fan speed ", - entry("SENSOR=%s", sensor.first)); - elog(); - } + auto value = speed; + util::SDBusPlus::setProperty( + _bus, + sensor.second, + sensor.first, + _interface, + FAN_TARGET_PROPERTY, + std::move(value)); } _targetSpeed = speed; -- cgit v1.2.1