diff options
author | Matthew Barth <msbarth@us.ibm.com> | 2018-05-09 14:55:41 -0500 |
---|---|---|
committer | Matthew Barth <msbarth@us.ibm.com> | 2018-05-17 12:13:36 -0500 |
commit | 26e96122ee89ccaa2de317deb70af5dc5011f48f (patch) | |
tree | bd3f48d8ba8e31630358ed434da81cbee9a0166e /control | |
parent | 88923a06e6fdceb452157b712587176b677bb917 (diff) | |
download | phosphor-fan-presence-26e96122ee89ccaa2de317deb70af5dc5011f48f.tar.gz phosphor-fan-presence-26e96122ee89ccaa2de317deb70af5dc5011f48f.zip |
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 <msbarth@us.ibm.com>
Diffstat (limited to 'control')
-rw-r--r-- | control/fan.cpp | 33 |
1 files changed, 8 insertions, 25 deletions
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 <phosphor-logging/log.hpp> -#include <phosphor-logging/elog.hpp> -#include <phosphor-logging/elog-errors.hpp> -#include <xyz/openbmc_project/Common/error.hpp> #include <string> #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<fanNamePos>(def)), @@ -70,25 +62,16 @@ Fan::Fan(sdbusplus::bus::bus& bus, const FanDefinition& def): void Fan::setSpeed(uint64_t speed) { - sdbusplus::message::variant<uint64_t> 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<level::ERR>( - "Failed call to set fan speed ", - entry("SENSOR=%s", sensor.first)); - elog<InternalFailure>(); - } + auto value = speed; + util::SDBusPlus::setProperty<uint64_t>( + _bus, + sensor.second, + sensor.first, + _interface, + FAN_TARGET_PROPERTY, + std::move(value)); } _targetSpeed = speed; |