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/TachSensor.cpp b/src/TachSensor.cpp
index 2c48cc9..4ba7777 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -61,17 +61,12 @@
"/xyz/openbmc_project/sensors/fan_tach/" + name,
"xyz.openbmc_project.Sensor.Value");
- if (thresholds::hasWarningInterface(thresholds))
+ for (const auto& threshold : thresholds)
{
- thresholdInterfaceWarning = objectServer.add_interface(
- "/xyz/openbmc_project/sensors/fan_tach/" + name,
- "xyz.openbmc_project.Sensor.Threshold.Warning");
- }
- if (thresholds::hasCriticalInterface(thresholds))
- {
- thresholdInterfaceCritical = objectServer.add_interface(
- "/xyz/openbmc_project/sensors/fan_tach/" + name,
- "xyz.openbmc_project.Sensor.Threshold.Critical");
+ std::string interface = thresholds::getInterface(threshold.level);
+ thresholdInterfaces[static_cast<size_t>(threshold.level)] =
+ objectServer.add_interface(
+ "/xyz/openbmc_project/sensors/fan_tach/" + name, interface);
}
association = objectServer.add_interface(
"/xyz/openbmc_project/sensors/fan_tach/" + name,
@@ -104,8 +99,10 @@
// close the input dev to cancel async operations
inputDev.close();
waitTimer.cancel();
- objServer.remove_interface(thresholdInterfaceWarning);
- objServer.remove_interface(thresholdInterfaceCritical);
+ for (const auto& iface : thresholdInterfaces)
+ {
+ objServer.remove_interface(iface);
+ }
objServer.remove_interface(sensorInterface);
objServer.remove_interface(association);
objServer.remove_interface(itemIface);