monitor: Change Fan/Sensor def tuples to structs

The tuples were big and hard to read/use.  Change them to structs so the
members are always named.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I79826563faf44636b251e614f45ff86f1e02c607
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index ed2399c..a421290 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -39,12 +39,11 @@
          std::unique_ptr<trust::Manager>& trust, const FanDefinition& def,
          System& system) :
     _bus(bus),
-    _name(std::get<fanNameField>(def)),
-    _deviation(std::get<fanDeviationField>(def)),
-    _numSensorFailsForNonFunc(std::get<numSensorFailsForNonfuncField>(def)),
+    _name(def.name), _deviation(def.deviation),
+    _numSensorFailsForNonFunc(def.numSensorFailsForNonfunc),
     _trustManager(trust),
 #ifdef MONITOR_USE_JSON
-    _monitorDelay(std::get<monitorStartDelayField>(def)),
+    _monitorDelay(def.monitorStartDelay),
     _monitorTimer(event, std::bind(std::mem_fn(&Fan::startMonitor), this)),
 #endif
     _system(system),
@@ -59,22 +58,17 @@
             rules::argNpath(0, util::INVENTORY_PATH + _name),
         std::bind(std::mem_fn(&Fan::presenceIfaceAdded), this,
                   std::placeholders::_1)),
-    _fanMissingErrorDelay(std::get<fanMissingErrDelayField>(def)),
-    _setFuncOnPresent(std::get<funcOnPresentField>(def))
+    _fanMissingErrorDelay(def.fanMissingErrDelay),
+    _setFuncOnPresent(def.funcOnPresent)
 {
     // Setup tach sensors for monitoring
-    auto& sensors = std::get<sensorListField>(def);
-    for (auto& s : sensors)
+    for (const auto& s : def.sensorList)
     {
         _sensors.emplace_back(std::make_shared<TachSensor>(
-            mode, bus, *this, std::get<sensorNameField>(s),
-            std::get<hasTargetField>(s), std::get<funcDelay>(def),
-            std::get<targetInterfaceField>(s), std::get<targetPathField>(s),
-            std::get<factorField>(s), std::get<offsetField>(s),
-            std::get<methodField>(def), std::get<thresholdField>(s),
-            std::get<ignoreAboveMaxField>(s), std::get<timeoutField>(def),
-            std::get<nonfuncRotorErrDelayField>(def),
-            std::get<countIntervalField>(def), event));
+            mode, bus, *this, s.name, s.hasTarget, def.funcDelay,
+            s.targetInterface, s.targetPath, s.factor, s.offset, def.method,
+            s.threshold, s.ignoreAboveMax, def.timeout,
+            def.nonfuncRotorErrDelay, def.countInterval, event));
 
         _trustManager->registerSensor(_sensors.back());
     }
diff --git a/monitor/json_parser.cpp b/monitor/json_parser.cpp
index 6714984..d81d767 100644
--- a/monitor/json_parser.cpp
+++ b/monitor/json_parser.cpp
@@ -153,19 +153,19 @@
             targetPath = sensor["target_path"].get<std::string>();
         }
         // Factor is optional and defaults to 1
-        auto factor = 1.0;
+        double factor = 1.0;
         if (sensor.contains("factor"))
         {
             factor = sensor["factor"].get<double>();
         }
         // Offset is optional and defaults to 0
-        auto offset = 0;
+        int64_t offset = 0;
         if (sensor.contains("offset"))
         {
             offset = sensor["offset"].get<int64_t>();
         }
         // Threshold is optional and defaults to 1
-        auto threshold = 1;
+        size_t threshold = 1;
         if (sensor.contains("threshold"))
         {
             threshold = sensor["threshold"].get<size_t>();
@@ -177,9 +177,16 @@
             ignoreAboveMax = sensor["ignore_above_max"].get<bool>();
         }
 
-        sensorDefs.emplace_back(std::tuple(
-            sensor["name"].get<std::string>(), sensor["has_target"].get<bool>(),
-            targetIntf, targetPath, factor, offset, threshold, ignoreAboveMax));
+        SensorDefinition def{.name = sensor["name"].get<std::string>(),
+                             .hasTarget = sensor["has_target"].get<bool>(),
+                             .targetInterface = targetIntf,
+                             .targetPath = targetPath,
+                             .factor = factor,
+                             .offset = offset,
+                             .threshold = threshold,
+                             .ignoreAboveMax = ignoreAboveMax};
+
+        sensorDefs.push_back(std::move(def));
     }
 
     return sensorDefs;
@@ -349,11 +356,21 @@
             setFuncOnPresent = fan["set_func_on_present"].get<bool>();
         }
 
-        fanDefs.emplace_back(std::tuple(
-            fan["inventory"].get<std::string>(), method, funcDelay, timeout,
-            deviation, nonfuncSensorsCount, monitorDelay, countInterval,
-            nonfuncRotorErrorDelay, fanMissingErrorDelay, sensorDefs, cond,
-            setFuncOnPresent));
+        FanDefinition def{.name = fan["inventory"].get<std::string>(),
+                          .method = method,
+                          .funcDelay = funcDelay,
+                          .timeout = timeout,
+                          .deviation = deviation,
+                          .numSensorFailsForNonfunc = nonfuncSensorsCount,
+                          .monitorStartDelay = monitorDelay,
+                          .countInterval = countInterval,
+                          .nonfuncRotorErrDelay = nonfuncRotorErrorDelay,
+                          .fanMissingErrDelay = fanMissingErrorDelay,
+                          .sensorList = std::move(sensorDefs),
+                          .condition = cond,
+                          .funcOnPresent = setFuncOnPresent};
+
+        fanDefs.push_back(std::move(def));
     }
 
     return fanDefs;
diff --git a/monitor/system.cpp b/monitor/system.cpp
index 0fc2c44..4a33bb5 100644
--- a/monitor/system.cpp
+++ b/monitor/system.cpp
@@ -271,7 +271,7 @@
     for (const auto& fanDef : fanDefs)
     {
         // Check if a condition exists on the fan
-        auto condition = std::get<conditionField>(fanDef);
+        auto condition = fanDef.condition;
         if (condition)
         {
             // Condition exists, skip adding fan if it fails
diff --git a/monitor/types.hpp b/monitor/types.hpp
index 740f069..30b416f 100644
--- a/monitor/types.hpp
+++ b/monitor/types.hpp
@@ -102,36 +102,34 @@
 
 using CreateGroupFunction = std::function<std::unique_ptr<trust::Group>()>;
 
-constexpr auto sensorNameField = 0;
-constexpr auto hasTargetField = 1;
-constexpr auto targetInterfaceField = 2;
-constexpr auto targetPathField = 3;
-constexpr auto factorField = 4;
-constexpr auto offsetField = 5;
-constexpr auto thresholdField = 6;
-constexpr auto ignoreAboveMaxField = 7;
+struct SensorDefinition
+{
+    std::string name;
+    bool hasTarget;
+    std::string targetInterface;
+    std::string targetPath;
+    double factor;
+    int64_t offset;
+    size_t threshold;
+    bool ignoreAboveMax;
+};
 
-using SensorDefinition = std::tuple<std::string, bool, std::string, std::string,
-                                    double, int64_t, size_t, bool>;
-
-constexpr auto fanNameField = 0;
-constexpr auto methodField = 1;
-constexpr auto funcDelay = 2;
-constexpr auto timeoutField = 3;
-constexpr auto fanDeviationField = 4;
-constexpr auto numSensorFailsForNonfuncField = 5;
-constexpr auto monitorStartDelayField = 6;
-constexpr auto countIntervalField = 7;
-constexpr auto nonfuncRotorErrDelayField = 8;
-constexpr auto fanMissingErrDelayField = 9;
-constexpr auto sensorListField = 10;
-constexpr auto conditionField = 11;
-constexpr auto funcOnPresentField = 12;
-
-using FanDefinition =
-    std::tuple<std::string, size_t, size_t, size_t, size_t, size_t, size_t,
-               size_t, std::optional<size_t>, std::optional<size_t>,
-               std::vector<SensorDefinition>, std::optional<Condition>, bool>;
+struct FanDefinition
+{
+    std::string name;
+    size_t method;
+    size_t funcDelay;
+    size_t timeout;
+    size_t deviation;
+    size_t numSensorFailsForNonfunc;
+    size_t monitorStartDelay;
+    size_t countInterval;
+    std::optional<size_t> nonfuncRotorErrDelay;
+    std::optional<size_t> fanMissingErrDelay;
+    std::vector<SensorDefinition> sensorList;
+    std::optional<Condition> condition;
+    bool funcOnPresent;
+};
 
 constexpr auto presentHealthPos = 0;
 constexpr auto sensorFuncHealthPos = 1;