Trigger periodic OCC POLL commands when the OCCs are running

The OCC control app will periodically trigger kernel poll commands
to the OCC when the OCCs are active.
Code change also adds an interface to allow any OCC command to be
sent to an OCC. The pass-through interface was also updated to
use the new command object.

Tested: I did several IPLs on multiple Rainier systems to verify
the changes. I forced OCC resets to ensure polling stopped when
OCCs were disabled and restarted after it came out of reset.

Change-Id: I56970e781a988bb94f17ac38173ace8a68bb5fad
Signed-off-by: Chris Cain <cjcain@us.ibm.com>
diff --git a/occ_manager.hpp b/occ_manager.hpp
index d8282b1..4db762c 100644
--- a/occ_manager.hpp
+++ b/occ_manager.hpp
@@ -10,6 +10,8 @@
 #include <cstring>
 #include <functional>
 #include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
+#include <sdeventplus/utility/timer.hpp>
 #include <vector>
 
 namespace sdbusRule = sdbusplus::bus::match::rules;
@@ -18,6 +20,9 @@
 namespace occ
 {
 
+/** @brief Default time, in seconds, between OCC poll commands */
+constexpr unsigned int defaultPollingInterval = 10;
+
 /** @class Manager
  *  @brief Builds and manages OCC objects
  */
@@ -38,7 +43,12 @@
      *  @param[in] event - Unique ptr reference to sd_event
      */
     Manager(sdbusplus::bus::bus& bus, EventPtr& event) :
-        bus(bus), event(event)
+        bus(bus), event(event), pollInterval(defaultPollingInterval),
+        sdpEvent(sdeventplus::Event::get_default()),
+        _pollTimer(
+            std::make_unique<
+                sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>(
+                sdpEvent, std::bind(&Manager::pollerTimerExpired, this)))
 #ifdef PLDM
         ,
         pldmHandle(std::make_unique<pldm::Interface>(
@@ -55,6 +65,7 @@
 #endif
     }
 
+    /** @brief Return the number of bound OCCs */
     inline auto getNumOCCs() const
     {
         return activeCount;
@@ -117,6 +128,20 @@
     /** @brief Number of OCCs that are bound */
     uint8_t activeCount = 0;
 
+    /** @brief Number of seconds between poll commands */
+    uint8_t pollInterval;
+
+    /** @brief Poll timer event */
+    sdeventplus::Event sdpEvent;
+
+    /**
+     * @brief The timer to be used once the OCC goes active.  When it expires,
+     *        a POLL command will be sent to the OCC and then timer restarted.
+     */
+    std::unique_ptr<
+        sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>
+        _pollTimer;
+
 #ifdef I2C_OCC
     /** @brief Init Status objects for I2C OCC devices
      *
@@ -142,6 +167,12 @@
 
     std::unique_ptr<pldm::Interface> pldmHandle = nullptr;
 #endif
+
+    /**
+     * @brief Called when poll timer expires and forces a POLL command to the
+     * OCC. The poll timer will then be restarted.
+     * */
+    void pollerTimerExpired();
 };
 
 } // namespace occ