Move threshold interfaces to common function
Threshold Hardshutdown and Softshutdown interfaces needs to be
created for sensors. Therefore, created a common function
called getInterface() to access all the threshold
interfaces from all the sensors source file and removed
hasCriticalInterface(), hasWarningInterface() functions.
Moreover, threshold interfaces from all the sensor constructor has
been refactored to avoid duplicating functions.
TESTED: Tested on Facebook YosemiteV2 hardware. Verified that the
Warning and Critical interfaces are created and displaying in
dbus objects.
Signed-off-by: Jayashree Dhanapal <jayashree-d@hcl.com>
Change-Id: I9c7d049c7d4445d7199bf63d8e729838990880e9
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index 4e0d32b..c405ef5 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -78,15 +78,11 @@
sensorInterface = objectServer.add_interface(
dbusPath, "xyz.openbmc_project.Sensor.Value");
- if (thresholds::hasWarningInterface(thresholds))
+ for (const auto& threshold : thresholds)
{
- thresholdInterfaceWarning = objectServer.add_interface(
- dbusPath, "xyz.openbmc_project.Sensor.Threshold.Warning");
- }
- if (thresholds::hasCriticalInterface(thresholds))
- {
- thresholdInterfaceCritical = objectServer.add_interface(
- dbusPath, "xyz.openbmc_project.Sensor.Threshold.Critical");
+ std::string interface = thresholds::getInterface(threshold.level);
+ thresholdInterfaces[static_cast<size_t>(threshold.level)] =
+ objectServer.add_interface(dbusPath, interface);
}
// This should be called before initializing association.
@@ -111,8 +107,10 @@
waitTimer.cancel();
inputDev.close();
objServer.remove_interface(sensorInterface);
- objServer.remove_interface(thresholdInterfaceWarning);
- objServer.remove_interface(thresholdInterfaceCritical);
+ for (const auto& iface : thresholdInterfaces)
+ {
+ objServer.remove_interface(iface);
+ }
objServer.remove_interface(association);
}