platform-mc: Refactor all threshold alarms into helpers

This moves a lot of the common logic around getting/setting
thresholds and their corresponding alarms into small
helper functions. This allows us to refactor out a lot
of the repeated code.

Tested:
Tested on a yosemite4 system where the CPU sensor
is behind a uC with PLDM as the interface to the BMC.
Lower the fan speed and ensure we still get the existing
alarm.
```
root@sled325945102-oob:~# busctl introspect -l xyz.openbmc_project.Logging /xyz/openbmc_project/logging/entry/20 xyz.openbmc_project.Logging.Entry | grep "AdditionalData\|Message\|Resolved"
.AdditionalData  property  a{ss} <snip>
.Message property  s  "xyz.openbmc_project.Sensor.Threshold.Error.TemperatureCriticalHigh"                                                                                                                                                                                            emits-change writable
.Resolved property  b  false
```
Increase the fan speed to allow the CPU to cool down.
```
root@sled325945102-oob:~# busctl introspect -l xyz.openbmc_project.Logging /xyz/openbmc_project/logging/entry/23 xyz.openbmc_project.Logging.Entry | grep "AdditionalData\|Message\|Resolved"
.AdditionalData property  a{ss}  5 <snip>
.Message property  s  "xyz.openbmc_project.Sensor.Threshold.Error.TemperatureCriticalHighClear"                                                                                                                                                                                       emits-change writable
.Resolved property  b  false
```

Change-Id: Id705828092d2bb6d1b14a56901b9deb96db22c2c
Signed-off-by: Amithash Prasad <amithash@meta.com>
diff --git a/platform-mc/numeric_sensor.hpp b/platform-mc/numeric_sensor.hpp
index 37f4695..b09bcd4 100644
--- a/platform-mc/numeric_sensor.hpp
+++ b/platform-mc/numeric_sensor.hpp
@@ -200,7 +200,7 @@
      *
      *  @return double - Lower HardShutdown threshold
      */
-    double getThresholdLowerHardShutdownl()
+    double getThresholdLowerHardShutdown()
     {
         if (thresholdHardShutdownIntf)
         {
@@ -212,6 +212,138 @@
         }
     };
 
+    /** @brief Get threshold given level and direction
+     *
+     * @param[in] level - The threshold level (WARNING/CRITICAL/etc)
+     * @param[in] direction - The threshold direction (HIGH/LOW)
+     *
+     * @return double - The requested threshold.
+     */
+    double getThreshold(pldm::utils::Level level,
+                        pldm::utils::Direction direction)
+    {
+        if (direction != pldm::utils::Direction::HIGH &&
+            direction != pldm::utils::Direction::LOW)
+        {
+            return std::numeric_limits<double>::quiet_NaN();
+        }
+        switch (level)
+        {
+            case pldm::utils::Level::WARNING:
+                return direction == pldm::utils::Direction::HIGH
+                           ? getThresholdUpperWarning()
+                           : getThresholdLowerWarning();
+            case pldm::utils::Level::CRITICAL:
+                return direction == pldm::utils::Direction::HIGH
+                           ? getThresholdUpperCritical()
+                           : getThresholdLowerCritical();
+            case pldm::utils::Level::HARDSHUTDOWN:
+                return direction == pldm::utils::Direction::HIGH
+                           ? getThresholdUpperHardShutdown()
+                           : getThresholdLowerHardShutdown();
+            default:
+                break;
+        }
+        return std::numeric_limits<double>::quiet_NaN();
+    }
+
+    /* @brief returns true if the given threshold at level/direction is defined.
+     *
+     * @param[in] level - The threshold level (WARNING/CRITICAL/etc)
+     * @param[in] direction - The threshold direction (HIGH/LOW)
+     *
+     * @return true if the threshold is valid
+     */
+    bool isThresholdValid(pldm::utils::Level level,
+                          pldm::utils::Direction direction)
+    {
+        return std::isfinite(getThreshold(level, direction));
+    }
+
+    /* @brief Get the alarm status of the given threshold
+     *
+     * @param[in] level - The threshold level (WARNING/CRITICAL/etc)
+     * @param[in] direction - The threshold direction (HIGH/LOW)
+     *
+     * @return true if the current alarm status is asserted.
+     */
+    bool getThresholdAlarm(pldm::utils::Level level,
+                           pldm::utils::Direction direction)
+    {
+        if (!isThresholdValid(level, direction))
+        {
+            return false;
+        }
+        switch (level)
+        {
+            case pldm::utils::Level::WARNING:
+                return direction == pldm::utils::Direction::HIGH
+                           ? thresholdWarningIntf->warningAlarmHigh()
+                           : thresholdWarningIntf->warningAlarmLow();
+            case pldm::utils::Level::CRITICAL:
+                return direction == pldm::utils::Direction::HIGH
+                           ? thresholdCriticalIntf->criticalAlarmHigh()
+                           : thresholdCriticalIntf->criticalAlarmLow();
+            case pldm::utils::Level::HARDSHUTDOWN:
+                return direction == pldm::utils::Direction::HIGH
+                           ? thresholdHardShutdownIntf->hardShutdownAlarmHigh()
+                           : thresholdHardShutdownIntf->hardShutdownAlarmLow();
+            default:
+                break;
+        }
+        return false;
+    }
+
+    /* @brief raises the alarm on the warning threshold
+     *
+     * @param[in] direction - The threshold direction (HIGH/LOW)
+     * @param[in] value - The current numeric sensor reading
+     * @param[in] asserted - true if we want to set the alarm, false
+     *                       if we want to clear it.
+     *
+     * @return PLDM_SUCCESS or a valid error code.
+     */
+    void setWarningThresholdAlarm(pldm::utils::Direction direction,
+                                  double value, bool asserted);
+
+    /* @brief raises the alarm on the critical threshold
+     *
+     * @param[in] direction - The threshold direction (HIGH/LOW)
+     * @param[in] value - The current numeric sensor reading
+     * @param[in] asserted - true if we want to set the alarm, false
+     *                       if we want to clear it.
+     *
+     * @return PLDM_SUCCESS or a valid error code.
+     */
+    void setCriticalThresholdAlarm(pldm::utils::Direction direction,
+                                   double value, bool asserted);
+
+    /* @brief raises the alarm on the hard-shutdown threshold
+     *
+     * @param[in] direction - The threshold direction (HIGH/LOW)
+     * @param[in] value - The current numeric sensor reading
+     * @param[in] asserted - true if we want to set the alarm, false
+     *                       if we want to clear it.
+     *
+     * @return PLDM_SUCCESS or a valid error code.
+     */
+    void setHardShutdownThresholdAlarm(pldm::utils::Direction direction,
+                                       double value, bool asserted);
+
+    /* @brief raises the alarm on the threshold
+     *
+     * @param[in] level - The threshold level (WARNING/CRITICAL/etc)
+     * @param[in] direction - The threshold direction (HIGH/LOW)
+     * @param[in] value - The current numeric sensor reading
+     * @param[in] asserted - true if we want to set the alarm, false
+     *                       if we want to clear it.
+     *
+     * @return PLDM_SUCCESS or a valid error code.
+     */
+    int setThresholdAlarm(pldm::utils::Level level,
+                          pldm::utils::Direction direction, double value,
+                          bool asserted);
+
     /** @brief Check if value is over threshold.
      *
      *  @param[in] eventType - event level in pldm::utils::Level