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>
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 @@
 
 // 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 @@
 
 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;