Add framework to set properties on a zone

Properties hosted by a zone object need the ability to be set upon zone
initialization. This adds support to allow the zone configuration yaml
to contain what properties to set and with what values on a zone. The
parser updates to generate what uses this framework is in a followup
commit.

Change-Id: I9fd93746cc097f05869400451daff03cf3ef89b7
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/functor.hpp b/control/functor.hpp
index 71607c5..ab5005d 100644
--- a/control/functor.hpp
+++ b/control/functor.hpp
@@ -17,6 +17,19 @@
 using namespace phosphor::logging;
 
 /**
+ * @brief Create a zone handler function object
+ *
+ * @param[in] handler - The handler being created
+ *
+ * @return - The created zone handler function object
+ */
+template <typename T>
+auto make_zoneHandler(T&& handler)
+{
+    return ZoneHandler(std::forward<T>(handler));
+}
+
+/**
  * @brief Create a handler function object
  *
  * @param[in] handler - The handler being created
diff --git a/control/handlers.hpp b/control/handlers.hpp
index 6661e1a..215662a 100644
--- a/control/handlers.hpp
+++ b/control/handlers.hpp
@@ -10,6 +10,26 @@
 {
 
 /**
+ * @brief A handler function to set/update a property on a zone
+ * @details Sets or updates a zone property to the given value using the
+ * provided zone dbus object's set property function
+ *
+ * @param[in] value - Value to set property to
+ * @param[in] func - Zone set property function pointer
+ *
+ * @return Lambda function
+ *     A lambda function to set/update the zone property
+ */
+template <typename T>
+auto setZoneProperty(T (Zone::*func)(T), T&& value)
+{
+    return [func, value = std::forward<T>(value)](auto& zone)
+    {
+        (zone.*func)(value);
+    };
+}
+
+/**
  * @brief A handler function to set/update a property
  * @details Sets or updates a property's value determined by a combination of
  * an object's path and property names
diff --git a/control/types.hpp b/control/types.hpp
index 239d00d..dcc1b8c 100644
--- a/control/types.hpp
+++ b/control/types.hpp
@@ -45,6 +45,7 @@
 constexpr auto intfPos = 0;
 constexpr auto propPos = 1;
 using Group = std::map<std::string, std::tuple<std::string, std::string>>;
+using ZoneHandler = std::function<void(Zone&)>;
 using Handler = std::function<void(sdbusplus::bus::bus&,
                                    sdbusplus::message::message&,
                                    Zone&)>;
@@ -108,13 +109,15 @@
 constexpr auto floorSpeedPos = 2;
 constexpr auto incDelayPos = 3;
 constexpr auto decIntervalPos = 4;
-constexpr auto fanListPos = 5;
-constexpr auto setSpeedEventsPos = 6;
+constexpr auto handlerPos = 5;
+constexpr auto fanListPos = 6;
+constexpr auto setSpeedEventsPos = 7;
 using ZoneDefinition = std::tuple<size_t,
                                   uint64_t,
                                   uint64_t,
                                   size_t,
                                   size_t,
+                                  std::vector<ZoneHandler>,
                                   std::vector<FanDefinition>,
                                   std::vector<SetSpeedEvent>>;
 
diff --git a/control/zone.cpp b/control/zone.cpp
index 326ca68..b844793 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -72,6 +72,12 @@
     // Do not enable set speed events when in init mode
     if (mode == Mode::control)
     {
+        // Process any zone handlers defined
+        for (auto& hand : std::get<handlerPos>(def))
+        {
+            hand(*this);
+        }
+
         // Restore thermal control current mode state
         restoreCurrentMode();