Update hwmon fan target sysfs entries

Override the default FanSpeed.Target set implementation so when a target
value is written to the FanSpeed interface it is also updated in the
related fan target sysfs file. This sets a particular fan to the given
target speed.

Resolves openbmc/openbmc#962
Resolves openbmc/phosphor-hwmon#1

Change-Id: I867811737269b3f42d2a0dc15b37782a74f147b8
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/fan_speed.hpp b/fan_speed.hpp
new file mode 100644
index 0000000..7c7da3a
--- /dev/null
+++ b/fan_speed.hpp
@@ -0,0 +1,59 @@
+#pragma once
+
+#include "interface.hpp"
+
+namespace hwmon
+{
+
+/**
+ * @class FanSpeed
+ * @brief Target fan speed control implementation
+ * @details Derived FanSpeedObject type that writes the target value to sysfs
+ * which in turn sets the fan speed to that target value
+ */
+class FanSpeed : public FanSpeedObject
+{
+    public:
+
+        /**
+         * @brief Constructs FanSpeed Object
+         *
+         * @param[in] sysfsRoot - The hwmon class root
+         * @param[in] instance - The hwmon instance (ex. hwmon1)
+         * @param[in] id - The hwmon id
+         * @param[in] bus - Dbus bus object
+         * @param[in] objPath - Dbus object path
+         * @param[in] defer - Dbus object registration defer
+         */
+        FanSpeed(const std::string& sysfsRoot,
+                 const std::string& instance,
+                 const std::string& id,
+                 sdbusplus::bus::bus& bus,
+                 const char* objPath,
+                 bool defer) : FanSpeedObject(bus, objPath, defer),
+                    sysfsRoot(sysfsRoot),
+                    instance(instance),
+                    id(id)
+        {
+            // Nothing to do here
+        }
+
+        /**
+         * @brief Set the value of target
+         *
+         * @return Value of target
+         */
+        uint64_t target(uint64_t value) override;
+
+    private:
+        /** @brief hwmon class root */
+        std::string sysfsRoot;
+        /** @brief hwmon instance */
+        std::string instance;
+        /** @brief hwmon type */
+        static constexpr auto type = "fan";
+        /** @brief hwmon id */
+        std::string id;
+};
+
+} // namespace hwmon