openpower-occ-control:failure to read OCC state.

Failure to read OCC state set the OCCs sensors to Nan/Not Functional
Tested: cronus error inject on OCC with and without OCC resets.
Signed-off-by: Sheldon Bailey <baileysh@us.ibm.com>
Change-Id: I2a6bb6a431f09ea816979b3a482b54a28e21db53
Signed-off-by: Sheldon Bailey <baileysh@us.ibm.com>
diff --git a/occ_status.hpp b/occ_status.hpp
index 6376b6c..e02aaea 100644
--- a/occ_status.hpp
+++ b/occ_status.hpp
@@ -79,7 +79,7 @@
 #ifdef POWER10
            std::unique_ptr<powermode::PowerMode>& powerModeRef,
 #endif
-           std::function<void(bool)> callBack = nullptr
+           std::function<void(instanceID, bool)> callBack = nullptr
 #ifdef PLDM
            ,
            std::function<void(instanceID)> resetCallBack = nullptr
@@ -117,8 +117,12 @@
         sdpEvent(sdeventplus::Event::get_default()),
         safeStateDelayTimer(
             sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>(
-                sdpEvent, std::bind(&Status::safeStateDelayExpired, this)))
+                sdpEvent, std::bind(&Status::safeStateDelayExpired, this))),
+        occReadStateFailTimer(
+            sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>(
+                sdpEvent, std::bind(&Status::occReadStateNow, this)))
 #endif
+
 #ifdef PLDM
         ,
         resetCallBack(resetCallBack)
@@ -213,7 +217,7 @@
     /** @brief Callback handler to be invoked during property change.
      *         This is a handler in Manager class
      */
-    std::function<void(bool)> managerCallBack;
+    std::function<void(instanceID, bool)> managerCallBack;
 
     /** @brief OCC instance number. Ex, 0,1, etc */
     unsigned int instance;
@@ -221,6 +225,15 @@
     /** @brief The last state read from the OCC */
     unsigned int lastState = 0;
 
+    /** @brief Number of retry attempts to open file and update state. */
+    const unsigned int occReadRetries = 1;
+
+    /** @brief Current number of retries attempted towards occReadRetries. */
+    size_t currentOccReadRetriesCount = 0;
+
+    /** @brief The Trigger to indicate OCC State is valid or not. */
+    bool stateValid = false;
+
     /** @brief OCC instance to Sensor definitions mapping */
     static const std::map<instanceID, sensorDefs> sensorMap;
 
@@ -284,7 +297,18 @@
      * safe mode. Called to verify and then disable and reset the OCCs.
      */
     void safeStateDelayExpired();
+
+    /**
+     * @brief Timer that is started when OCC read Valid state failed.
+     */
+    sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>
+        occReadStateFailTimer;
+
 #endif // POWER10
+    /** @brief Callback for timer that is started when OCC state
+     * was not able to be read. Called to attempt another read when needed.
+     */
+    void occReadStateNow();
 
     /** @brief Override the sensor name with name from the definition.
      *  @param[in]  estimatedPath - Estimated OCC Dbus object path