Properties stored of different types

Allow properties stored for processing events to be of types other than
bool

Change-Id: Ie1dde5aca562c9958bdff6fa3d1b19d3154b2c6d
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/actions.hpp b/control/actions.hpp
index 21d9365..8a2675b 100644
--- a/control/actions.hpp
+++ b/control/actions.hpp
@@ -24,16 +24,19 @@
  *     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)
+template <typename T>
+auto count_state_before_speed(size_t count, T&& state, uint64_t speed)
 {
-    return [=](auto& zone, auto& group)
+    return [count,
+            speed,
+            state = std::forward<T>(state)](auto& zone, auto& group)
     {
         size_t numAtState = std::count_if(
             group.begin(),
             group.end(),
             [&zone, &state](auto const& entry)
             {
-                return zone.getPropertyValue(
+                return zone.template getPropertyValue<T>(
                         entry.first,
                         std::get<intfPos>(entry.second),
                         std::get<propPos>(entry.second)) == state;
diff --git a/control/types.hpp b/control/types.hpp
index 2b7509c..de56186 100644
--- a/control/types.hpp
+++ b/control/types.hpp
@@ -28,6 +28,8 @@
 using Condition = std::tuple<std::string,
                              std::vector<ConditionProperty>>;
 
+using PropertyVariantType = sdbusplus::message::variant<bool, int64_t>;
+
 constexpr auto fanNamePos = 0;
 constexpr auto sensorListPos = 1;
 using FanDefinition = std::tuple<std::string, std::vector<std::string>>;
diff --git a/control/zone.cpp b/control/zone.cpp
index 7a61c77..a57174d 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -51,16 +51,16 @@
             {
                 try
                 {
-                    bool value = false;
+                    PropertyVariantType property;
                     getProperty(_bus,
                                 entry.first,
                                 std::get<intfPos>(entry.second),
                                 std::get<propPos>(entry.second),
-                                value);
+                                property);
                     setPropertyValue(entry.first.c_str(),
                                      std::get<intfPos>(entry.second).c_str(),
                                      std::get<propPos>(entry.second).c_str(),
-                                     value);
+                                     property);
                 }
                 catch (const std::exception& e)
                 {
@@ -119,14 +119,12 @@
     }
 }
 
-template <typename T>
 void Zone::getProperty(sdbusplus::bus::bus& bus,
                        const std::string& path,
                        const std::string& iface,
                        const std::string& prop,
-                       T& value)
+                       PropertyVariantType& value)
 {
-    sdbusplus::message::variant<T> property;
     auto serv = phosphor::fan::util::getService(path, iface, bus);
     auto hostCall = bus.new_method_call(serv.c_str(),
                                         path.c_str(),
@@ -140,8 +138,7 @@
         throw std::runtime_error(
             "Error in host call response for retrieving property");
     }
-    hostResponseMsg.read(property);
-    value = sdbusplus::message::variant_ns::get<T>(property);
+    hostResponseMsg.read(value);
 }
 
 void Zone::handleEvent(sdbusplus::message::message& msg,
diff --git a/control/zone.hpp b/control/zone.hpp
index bd6e080..1af0c22 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -86,10 +86,11 @@
          * @param[in] property - Property name
          * @param[in] value - Property value
          */
+        template <typename T>
         void setPropertyValue(const char* object,
                               const char* interface,
                               const char* property,
-                              bool value)
+                              T value)
         {
             _properties[object][interface][property] = value;
         };
@@ -103,11 +104,13 @@
          *
          * @return - The property value
          */
+        template <typename T>
         inline auto getPropertyValue(const std::string& object,
                                      const std::string& interface,
                                      const std::string& property)
         {
-            return _properties[object][interface][property];
+            return sdbusplus::message::variant_ns::get<T>(
+                    _properties[object][interface][property]);
         };
 
     private:
@@ -143,7 +146,7 @@
         std::map<std::string,
                  std::map<std::string,
                           std::map<std::string,
-                                   bool>>> _properties;
+                                   PropertyVariantType>>> _properties;
 
         /**
          * @brief Map of active fan control allowed by groups
@@ -169,12 +172,11 @@
          * @param[in] prop - the property name
          * @param[out] value - the value of the property
          */
-        template <typename T>
         static void getProperty(sdbusplus::bus::bus& bus,
                                 const std::string& path,
                                 const std::string& iface,
                                 const std::string& prop,
-                                T& value);
+                                PropertyVariantType& value);
 
         /**
          * @brief Dbus signal change callback handler