Add support for Previous State in Sensor events

Previously, the sensor events generated by the PLDM stack only
included the current state of the sensor without any reference
to the previous state.

This commit introduces a new feature to address this limitation
by caching the previous states of all sensors.

The enhancement ensures that platform event messages(sensor events)
now contain the correct previous state information alongside the
current state.

Behavior Model:
1. Upon the initial occurrence of a sensor event, both the current
   state and the previous state are identical, adhering to the
   specification.
2. Subsequently, when the PLDM stack sends out sensor events, it
   retrieves the previous state from its cache and populates it
   accordingly.

Testing:
1. Example: Change the value of a sensor, such as dimm8 identify, to
   false using busctl.
   Tx: 81 02 0a 01 00 00 4d 00 01 00 [ 01 01 ]
- Note: Initially, both the event state and the previous state are 01.

2. Change the value of dimm8 identify to true.
   Tx: 81 02 0a 01 00 00 4d 00 01 00 [ 02 01 ]
- Result: Event state: 02, Previous state: 01.

3. Change the value of dimm8 identify back to false.
   Tx: 81 02 0a 01 00 00 4d 00 01 00 [ 01 02 ]
- Result: Event state: 01, Previous state: 02.

4. Similar results can be obtained using the getStateSensorReadings
   command for the same sensor at respective times.

Change-Id: Ic93a55e61fd5128cecc698b3555a6639876882ed
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/host-bmc/dbus_to_event_handler.hpp b/host-bmc/dbus_to_event_handler.hpp
index 846f210..273a03a 100644
--- a/host-bmc/dbus_to_event_handler.hpp
+++ b/host-bmc/dbus_to_event_handler.hpp
@@ -17,6 +17,8 @@
                                   pldm::responder::pdr_utils::DbusValMaps>>;
 using sensorEvent =
     std::function<void(SensorId sensorId, const DbusObjMaps& dbusMaps)>;
+using stateSensorCacheMaps =
+    std::map<pldm::pdr::SensorID, pldm::responder::pdr_utils::EventStates>;
 
 namespace state_sensor
 {
@@ -52,6 +54,24 @@
     void listenSensorEvent(const pldm::responder::pdr_utils::Repo& repo,
                            const DbusObjMaps& dbusMaps);
 
+    /** @brief get the sensor state cache */
+    inline const stateSensorCacheMaps& getSensorCache()
+    {
+        return sensorCacheMap;
+    }
+
+    /** @brief function to update the sensor cache
+     *  @param[in] sensorId - sensor Id of the corresponding sensor
+     *  @param[in] sensorRearm - sensor rearm value with in the sensor
+     *  @param[in] previousState - previous state of the sensor
+     */
+    inline void updateSensorCacheMaps(pldm::pdr::SensorID sensorId,
+                                      size_t sensorRearm, uint8_t previousState)
+    {
+        // update the sensor cache
+        sensorCacheMap[sensorId][sensorRearm] = previousState;
+    }
+
   private:
     /** @brief Send state sensor event msg when a D-Bus property changes
      *  @param[in] sensorId - sensor id
@@ -81,6 +101,9 @@
 
     /** @brief PLDM request handler */
     pldm::requester::Handler<pldm::requester::Request>* handler;
+
+    /** @brief sensor cache */
+    stateSensorCacheMaps sensorCacheMap;
 };
 
 } // namespace state_sensor