Remove timer in favor of sdeventplus/utility/timer

This removes the custom timer implementation and moves to the
sdeventplus utility. Functionally this should make no change

Tested:
    Built and run through the unit test suite.

Change-Id: Ib7ee90d489d5db72496aaaca91c3cf5490ad47d6
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/control/actions.cpp b/control/actions.cpp
index 0267c10..25b6a09 100644
--- a/control/actions.cpp
+++ b/control/actions.cpp
@@ -41,10 +41,6 @@
                 auto timer = zone.findTimer(group, actions);
                 if (timer != std::end(zone.getTimerEvents()))
                 {
-                    if (std::get<timerTimerPos>(*timer)->running())
-                    {
-                        std::get<timerTimerPos>(*timer)->stop();
-                    }
                     zone.removeTimer(timer);
                 }
             }
diff --git a/control/types.hpp b/control/types.hpp
index 967b0b4..239d00d 100644
--- a/control/types.hpp
+++ b/control/types.hpp
@@ -3,7 +3,8 @@
 #include <tuple>
 #include <vector>
 #include <sdbusplus/server.hpp>
-#include "timer.hpp"
+#include <sdeventplus/clock.hpp>
+#include <sdeventplus/utility/timer.hpp>
 
 namespace phosphor
 {
@@ -64,7 +65,11 @@
 
 constexpr auto intervalPos = 0;
 constexpr auto typePos = 1;
-using TimerType = phosphor::fan::util::Timer::TimerType;
+enum class TimerType
+{
+    oneshot,
+    repeating,
+};
 using TimerConf = std::tuple<std::chrono::seconds,
                              TimerType>;
 
@@ -89,9 +94,8 @@
 
 constexpr auto timerEventDataPos = 0;
 constexpr auto timerTimerPos = 1;
-using TimerEvent =
-    std::tuple<std::unique_ptr<EventData>,
-               std::unique_ptr<phosphor::fan::util::Timer>>;
+using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
+using TimerEvent = std::tuple<std::unique_ptr<EventData>, Timer>;
 
 constexpr auto signalEventDataPos = 0;
 constexpr auto signalMatchPos = 1;
diff --git a/control/zone.cpp b/control/zone.cpp
index 4531151..293945c 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -18,6 +18,7 @@
 #include <phosphor-logging/log.hpp>
 #include <phosphor-logging/elog.hpp>
 #include <phosphor-logging/elog-errors.hpp>
+#include <stdexcept>
 #include <xyz/openbmc_project/Common/error.hpp>
 #include "zone.hpp"
 #include "utility.hpp"
@@ -72,10 +73,7 @@
             initEvent(event);
         }
         // Start timer for fan speed decreases
-        if (!_decTimer.running() && _decInterval != seconds::zero())
-        {
-            _decTimer.start(_decInterval, TimerType::repeating);
-        }
+        _decTimer.restart(_decInterval);
     }
 }
 
@@ -238,14 +236,9 @@
         {
             requestTarget = _ceilingSpeed;
         }
-        // Cancel current timer countdown
-        if (_incTimer.running())
-        {
-            _incTimer.stop();
-        }
         setSpeed(requestTarget);
-        // Start timer countdown for fan speed increase
-        _incTimer.start(_incDelay, TimerType::oneshot);
+        // Retart timer countdown for fan speed increase
+        _incTimer.restartOnce(_incDelay);
     }
 }
 
@@ -277,7 +270,7 @@
     // where no requested increases exist and
     // the increase timer is not running
     // (i.e. not in the middle of increasing)
-    if (decAllowed && _incSpeedDelta == 0 && !_incTimer.running())
+    if (decAllowed && _incSpeedDelta == 0 && !_incTimer.isEnabled())
     {
         auto requestTarget = getRequestSpeedBase();
         // Request target speed should not start above ceiling
@@ -449,26 +442,31 @@
                     const std::vector<Action>& actions,
                     const TimerConf& tConf)
 {
-    // Associate event data with timer
-    auto data = std::make_unique<EventData>(
+    auto eventData = std::make_unique<EventData>(
             group,
             "",
             nullptr,
             actions
     );
-    auto timer = std::make_unique<util::Timer>(
+    Timer timer(
         _eventLoop,
         std::bind(&Zone::timerExpired,
                   this,
-                  std::cref(std::get<Group>(*data)),
-                  std::cref(std::get<std::vector<Action>>(*data)))
-    );
-    if (!timer->running())
+                  std::cref(std::get<Group>(*eventData)),
+                  std::cref(std::get<std::vector<Action>>(*eventData))));
+    if (std::get<TimerType>(tConf) == TimerType::repeating)
     {
-        timer->start(std::get<intervalPos>(tConf),
-                     std::get<typePos>(tConf));
+        timer.restart(std::get<intervalPos>(tConf));
     }
-    _timerEvents.emplace_back(std::move(data), std::move(timer));
+    else if (std::get<TimerType>(tConf) == TimerType::oneshot)
+    {
+        timer.restartOnce(std::get<intervalPos>(tConf));
+    }
+    else
+    {
+        throw std::invalid_argument("Invalid Timer Type");
+    }
+    _timerEvents.emplace_back(std::move(eventData), std::move(timer));
 }
 
 void Zone::timerExpired(const Group& eventGroup,
diff --git a/control/zone.hpp b/control/zone.hpp
index d01e972..9c85655 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -1,14 +1,12 @@
 #pragma once
+#include <algorithm>
 #include <cassert>
 #include <chrono>
-#include <vector>
-#include <cassert>
-#include <algorithm>
 #include <sdbusplus/bus.hpp>
 #include <sdeventplus/event.hpp>
+#include <vector>
 #include "fan.hpp"
 #include "types.hpp"
-#include "timer.hpp"
 
 namespace phosphor
 {
@@ -423,9 +421,6 @@
          */
         inline void removeTimer(std::vector<TimerEvent>::iterator& teIter)
         {
-            assert(teIter != std::end(_timerEvents));
-            std::get<timerEventDataPos>(*teIter).reset();
-            std::get<timerTimerPos>(*teIter).reset();
             _timerEvents.erase(teIter);
         }
 
@@ -547,12 +542,12 @@
         /**
          * The increase timer object
          */
-        phosphor::fan::util::Timer _incTimer;
+        Timer _incTimer;
 
         /**
          * The decrease timer object
          */
-        phosphor::fan::util::Timer _decTimer;
+        Timer _decTimer;
 
         /**
          * Event loop used on set speed event timers