thresholds: simplify logic and template

Simplify the Threshold template by turning it into a child-class of the
underlying threshold class and reducing corresponding logic / template
boilerplate.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I0333669cf92255f4d365fedcdb23cbeaf52ba696
diff --git a/virtualSensor.cpp b/virtualSensor.cpp
index 74b04f7..a67077b 100644
--- a/virtualSensor.cpp
+++ b/virtualSensor.cpp
@@ -88,8 +88,8 @@
         if (threshold.contains("CriticalHigh") ||
             threshold.contains("CriticalLow"))
         {
-            criticalIface =
-                std::make_unique<CriticalObject>(bus, objPath.c_str());
+            criticalIface = std::make_unique<Threshold<CriticalObject>>(
+                bus, objPath.c_str());
 
             criticalIface->criticalHigh(threshold.value(
                 "CriticalHigh", std::numeric_limits<double>::quiet_NaN()));
@@ -100,8 +100,8 @@
         if (threshold.contains("WarningHigh") ||
             threshold.contains("WarningLow"))
         {
-            warningIface =
-                std::make_unique<WarningObject>(bus, objPath.c_str());
+            warningIface = std::make_unique<Threshold<WarningObject>>(
+                bus, objPath.c_str());
 
             warningIface->warningHigh(threshold.value(
                 "WarningHigh", std::numeric_limits<double>::quiet_NaN()));
@@ -112,8 +112,8 @@
         if (threshold.contains("HardShutdownHigh") ||
             threshold.contains("HardShutdownLow"))
         {
-            hardShutdownIface =
-                std::make_unique<HardShutdownObject>(bus, objPath.c_str());
+            hardShutdownIface = std::make_unique<Threshold<HardShutdownObject>>(
+                bus, objPath.c_str());
 
             hardShutdownIface->hardShutdownHigh(threshold.value(
                 "HardShutdownHigh", std::numeric_limits<double>::quiet_NaN()));
@@ -124,8 +124,8 @@
         if (threshold.contains("SoftShutdownHigh") ||
             threshold.contains("SoftShutdownLow"))
         {
-            softShutdownIface =
-                std::make_unique<SoftShutdownObject>(bus, objPath.c_str());
+            softShutdownIface = std::make_unique<Threshold<SoftShutdownObject>>(
+                bus, objPath.c_str());
 
             softShutdownIface->softShutdownHigh(threshold.value(
                 "SoftShutdownHigh", std::numeric_limits<double>::quiet_NaN()));
@@ -248,10 +248,10 @@
         std::cout << "Sensor value is " << val << "\n";
 
     /* Check sensor thresholds and log required message */
-    checkThresholds(val, warningIface.get());
-    checkThresholds(val, criticalIface.get());
-    checkThresholds(val, softShutdownIface.get());
-    checkThresholds(val, hardShutdownIface.get());
+    checkThresholds(val, warningIface);
+    checkThresholds(val, criticalIface);
+    checkThresholds(val, softShutdownIface);
+    checkThresholds(val, hardShutdownIface);
 }
 
 /** @brief Parsing Virtual Sensor config JSON file  */