Fix display of sensor units
An earlier change modified getSensorTypeStringFromPath() and
removed the comparison function for the sensor units map.
Because they are char* and the type string failed, the default
sort and find map functions don't work and sensor units appear
as unspecified.
This change fixes the type string and adds the char* comparison
function back in so find() can correctly find the sensor unit.
Tested: Ran the 'sensor list' command and verified that the units
are correctly displayed.
Change-Id: Iac29b763dfd899ced9cb8885ddfa0f2edb8c4d64
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/src/sensorcommands.cpp b/src/sensorcommands.cpp
index 3c1f050..a4fe05a 100644
--- a/src/sensorcommands.cpp
+++ b/src/sensorcommands.cpp
@@ -53,12 +53,20 @@
static SensorSubTree sensorTree;
static boost::container::flat_map<std::string, ManagedObjectType> SensorCache;
-const static boost::container::flat_map<const char *, SensorUnits> sensorUnits{
- {{"temperature", SensorUnits::degreesC},
- {"voltage", SensorUnits::volts},
- {"current", SensorUnits::amps},
- {"fan_tach", SensorUnits::rpm},
- {"power", SensorUnits::watts}}};
+// Specify the comparison required to sort and find char* map objects
+struct CmpStr
+{
+ bool operator()(const char *a, const char *b) const
+ {
+ return std::strcmp(a, b) < 0;
+ }
+};
+const static boost::container::flat_map<const char *, SensorUnits, CmpStr>
+ sensorUnits{{{"temperature", SensorUnits::degreesC},
+ {"voltage", SensorUnits::volts},
+ {"current", SensorUnits::amps},
+ {"fan_tach", SensorUnits::rpm},
+ {"power", SensorUnits::watts}}};
void registerSensorFunctions() __attribute__((constructor));
static sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection());