Add setting zone speed action

Enable an action to be defined that sets the zone to a given speed when
a number of properties are set to a given value

Change-Id: I5252a20a24bdb14dee63080f2c08b080c82ad7e8
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/actions.hpp b/control/actions.hpp
new file mode 100644
index 0000000..eb857b6
--- /dev/null
+++ b/control/actions.hpp
@@ -0,0 +1,50 @@
+#pragma once
+
+#include <algorithm>
+
+namespace phosphor
+{
+namespace fan
+{
+namespace control
+{
+namespace action
+{
+
+/**
+ * @brief An action to set the speed on a zone
+ * @details The zone is set to the given speed when a defined number of
+ * properties in the group are set to the given state
+ *
+ * @param[in] count - Number of properties
+ * @param[in] state - Value the property(s) needed to be set at
+ * @param[in] speed - Speed to set the zone to
+ *
+ * @return Lambda function
+ *     A lambda function to set the zone speed when the number of properties
+ *     within the group are at a certain value
+ */
+auto count_state_before_speed(size_t count, bool state, uint64_t speed)
+{
+    return [=](auto& zone, auto& group)
+    {
+        size_t numAtState = std::count_if(
+            group.begin(),
+            group.end(),
+            [&zone, &state](auto const& entry)
+            {
+                return zone.getPropertyValue(
+                        entry.first,
+                        std::get<propPos>(entry.second)) == state;
+            });
+        if (numAtState >= count)
+        {
+            zone.setSpeed(speed);
+        }
+    };
+}
+
+} // namespace action
+} // namespace control
+} // namespace fan
+} // namespace phosphor