sensor-mon: Handle propertiesChanged
Fill in the handler for a Threshold.HardShutdown or
Threshold.SoftShutdown property changing.
If the power is off, do nothing, otherwise read out the changed alarm
properties and check if any action needs to be taken.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I379e90dffe3e6d3acdf18820bda34f2a5671f57a
diff --git a/sensor-monitor/shutdown_alarm_monitor.cpp b/sensor-monitor/shutdown_alarm_monitor.cpp
index 2017770..b5b5843 100644
--- a/sensor-monitor/shutdown_alarm_monitor.cpp
+++ b/sensor-monitor/shutdown_alarm_monitor.cpp
@@ -119,7 +119,47 @@
void ShutdownAlarmMonitor::propertiesChanged(
sdbusplus::message::message& message)
{
- // check the values
+ std::map<std::string, std::variant<bool>> properties;
+ std::string interface;
+
+ if (!_powerState->isPowerOn())
+ {
+ return;
+ }
+
+ message.read(interface, properties);
+
+ auto type = getShutdownType(interface);
+ if (!type)
+ {
+ return;
+ }
+
+ std::string sensorPath = message.get_path();
+
+ const auto& lowAlarmName = alarmProperties.at(*type).at(AlarmType::low);
+ if (properties.count(lowAlarmName) > 0)
+ {
+ AlarmKey alarmKey{sensorPath, *type, AlarmType::low};
+ auto alarm = alarms.find(alarmKey);
+ if (alarm == alarms.end())
+ {
+ alarms.emplace(alarmKey, nullptr);
+ }
+ checkAlarm(std::get<bool>(properties.at(lowAlarmName)), alarmKey);
+ }
+
+ const auto& highAlarmName = alarmProperties.at(*type).at(AlarmType::high);
+ if (properties.count(highAlarmName) > 0)
+ {
+ AlarmKey alarmKey{sensorPath, *type, AlarmType::high};
+ auto alarm = alarms.find(alarmKey);
+ if (alarm == alarms.end())
+ {
+ alarms.emplace(alarmKey, nullptr);
+ }
+ checkAlarm(std::get<bool>(properties.at(highAlarmName)), alarmKey);
+ }
}
void ShutdownAlarmMonitor::checkAlarm(bool value, const AlarmKey& alarmKey)
@@ -139,4 +179,19 @@
}
}
+std::optional<ShutdownType>
+ ShutdownAlarmMonitor::getShutdownType(const std::string& interface) const
+{
+ auto it = std::find_if(
+ shutdownInterfaces.begin(), shutdownInterfaces.end(),
+ [interface](const auto& a) { return a.second == interface; });
+
+ if (it == shutdownInterfaces.end())
+ {
+ return std::nullopt;
+ }
+
+ return it->first;
+}
+
} // namespace sensor::monitor
diff --git a/sensor-monitor/shutdown_alarm_monitor.hpp b/sensor-monitor/shutdown_alarm_monitor.hpp
index 6b1c823..65f905d 100644
--- a/sensor-monitor/shutdown_alarm_monitor.hpp
+++ b/sensor-monitor/shutdown_alarm_monitor.hpp
@@ -117,6 +117,16 @@
void powerStateChanged(bool powerStateOn);
/**
+ * @brief Returns the ShutdownType for the passed in interface
+ *
+ * @param[in] interface - The D-Bus interface name
+ * @return The interface, or std::nullopt if the interface isn't one
+ * of the shutdown interfaces.
+ */
+ std::optional<ShutdownType>
+ getShutdownType(const std::string& interface) const;
+
+ /**
* @brief The sdbusplus bus object
*/
sdbusplus::bus::bus& bus;