monitor: Create count timer

When the method for monitoring fan speeds is set to 'count', which is
when an up/down counter is used determine when a fan should be
considered faulted/nonfunctional, there needs to be some interval at
which the speeds are checked and the count is changed if necessary.
Otherwise, if the checks just happened in the tach changed callback as
they do today, then a fan with a non-changing rotor speed would never
trigger a check.

This commit creates a new timer in the Fan class that is constantly
running when the monitor is active if any of the fan's sensors use this
mode.  In the expiration function, the sensors' tach targets will be
compared to their input values and the error count will be
incremented/decremented as was previously happening in the tach changed
callback.

The interval to use is read from a new 'count_interval' property in the
JSON, which defaults to 1 if not present and the count method is
enabled.

The timer is started in the startMonitor function, and stopped when a
power off is detected.

This commit also added some DEBUG journal traces when the counter on a
sensor changes values to help with debugging the new code, and so it can
be enabled on a system if desired by enabling debug level tracing.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I238606e95bb91df93afd6ec7c00bd0577bc603f2
diff --git a/monitor/fan.hpp b/monitor/fan.hpp
index 4bf1757..92016b1 100644
--- a/monitor/fan.hpp
+++ b/monitor/fan.hpp
@@ -176,6 +176,12 @@
      */
     void powerStateChanged(bool powerStateOn);
 
+    /**
+     * @brief Timer callback function that deals with sensors using
+     *        the 'count' method for determining functional status.
+     */
+    void countTimerExpired();
+
   private:
     /**
      * @brief Returns true if the sensor input is not within
@@ -320,6 +326,20 @@
     std::unique_ptr<
         sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>
         _fanMissingErrorTimer;
+
+    /**
+     * @brief The interval, in seconds, to use for the timer that runs
+     *        the checks for sensors using the 'count' method.
+     */
+    size_t _countInterval;
+
+    /**
+     * @brief The timer whose callback function handles the sensors
+     *        using the 'count' method for determining functional status.
+     */
+    std::unique_ptr<
+        sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>
+        _countTimer;
 };
 
 } // namespace monitor