monitor: Move count timer into TachSensor

Instead of the Fan class owning the count error detection method timer,
this commit moves it into each TachSensor object.

This timer will be stopped until the first time Fan::tachChanged()
detects an out of range sensor, then it will be started.  From that
point on, the timer expiration function is what will call Fan::process()
to increment/decrement the count.  If the count goes back to zero, then
the timer will be stopped and Fan::tachChanged() will take back over.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I1cfc8440d299302b088f53764b71c06ea513690b
diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp
index fa62045..f110722 100644
--- a/monitor/tach_sensor.cpp
+++ b/monitor/tach_sensor.cpp
@@ -73,14 +73,14 @@
                        const std::string& interface, double factor,
                        int64_t offset, size_t method, size_t threshold,
                        size_t timeout, const std::optional<size_t>& errorDelay,
-                       const sdeventplus::Event& event) :
+                       size_t countInterval, const sdeventplus::Event& event) :
     _bus(bus),
     _fan(fan), _name(FAN_SENSOR_PATH + id), _invName(path(fan.getName()) / id),
     _hasTarget(hasTarget), _funcDelay(funcDelay), _interface(interface),
     _factor(factor), _offset(offset), _method(method), _threshold(threshold),
     _timeout(timeout), _timerMode(TimerMode::func),
     _timer(event, std::bind(&Fan::updateState, &fan, std::ref(*this))),
-    _errorDelay(errorDelay)
+    _errorDelay(errorDelay), _countInterval(countInterval)
 {
     // Start from a known state of functional
     setFunctional(true);
@@ -122,6 +122,14 @@
                 event, std::bind(&Fan::sensorErrorTimerExpired, &fan,
                                  std::ref(*this)));
         }
+
+        if (_method == MethodMode::count)
+        {
+            _countTimer = std::make_unique<
+                sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>(
+                event,
+                std::bind(&Fan::countTimerExpired, &fan, std::ref(*this)));
+        }
 #ifndef MONITOR_USE_JSON
     }
 #endif
@@ -303,6 +311,27 @@
     }
 }
 
+void TachSensor::startCountTimer()
+{
+    if (_countTimer)
+    {
+        log<level::DEBUG>(
+            fmt::format("Starting count timer on sensor {}", _name).c_str());
+        _countTimer->restart(std::chrono::seconds(_countInterval));
+    }
+}
+
+void TachSensor::stopCountTimer()
+{
+    if (_countTimer && _countTimer->isEnabled())
+    {
+        log<level::DEBUG>(
+            fmt::format("Stopping count timer on tach sensor {}.", _name)
+                .c_str());
+        _countTimer->setEnabled(false);
+    }
+}
+
 void TachSensor::updateInventory(bool functional)
 {
     auto objectMap =