Implementation of minimum watchdog interval.

Tested: phosphor-watchdog CI unittest - set interval to value smaller than
the minimum interval and test that the minimum interval was set as the
interval.
Change-Id: I88d7ca865ce57eaccea8aaf50396dbb50bd396fb
Signed-off-by: Ofer Yehielli <ofery@google.com>
diff --git a/watchdog.hpp b/watchdog.hpp
index 34b0411..7de9bb3 100644
--- a/watchdog.hpp
+++ b/watchdog.hpp
@@ -15,6 +15,7 @@
 namespace watchdog
 {
 
+constexpr auto DEFAULT_MIN_INTERVAL_MS = 0;
 namespace Base = sdbusplus::xyz::openbmc_project::State::server;
 using WatchdogInherits = sdbusplus::server::object::object<Base::Watchdog>;
 
@@ -62,12 +63,15 @@
     Watchdog(sdbusplus::bus::bus& bus, const char* objPath,
              const sdeventplus::Event& event,
              ActionTargetMap&& actionTargetMap = {},
-             std::optional<Fallback>&& fallback = std::nullopt) :
+             std::optional<Fallback>&& fallback = std::nullopt,
+             uint64_t minInterval = DEFAULT_MIN_INTERVAL_MS) :
         WatchdogInherits(bus, objPath),
         bus(bus), actionTargetMap(std::move(actionTargetMap)),
-        fallback(std::move(fallback)),
+        fallback(std::move(fallback)), minInterval(minInterval),
         timer(event, std::bind(&Watchdog::timeOutHandler, this))
     {
+        // We set the watchdog interval with the default value.
+        interval(interval());
         // We need to poke the enable mechanism to make sure that the timer
         // enters the fallback state if the fallback is always enabled.
         tryFallbackOrDisable();
@@ -116,6 +120,23 @@
      */
     uint64_t timeRemaining(uint64_t value) override;
 
+    /** @brief Get value of Interval
+     *
+     *
+     *  @return: current interval
+     *
+     */
+    using WatchdogInherits::interval;
+
+    /** @brief Set value of Interval
+     *
+     *  @param[in] value - interval time to set
+     *
+     *  @return: interval that was set
+     *
+     */
+    uint64_t interval(uint64_t value);
+
     /** @brief Tells if the referenced timer is expired or not */
     inline auto timerExpired() const
     {
@@ -138,6 +159,9 @@
     /** @brief Fallback timer options */
     std::optional<Fallback> fallback;
 
+    /** @brief Minimum watchdog interval value */
+    uint64_t minInterval;
+
     /** @brief Contained timer object */
     sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer;