From b0adbcdd5a854702c8eab02a63ff08936103540e Mon Sep 17 00:00:00 2001 From: Tom Joseph Date: Wed, 24 Jan 2018 11:51:29 +0530 Subject: sensor: Add support for multiple sensor naming pattern Change-Id: Ibf58d4a4f5a2783a9152f4b5f685e28ef527c5e2 Signed-off-by: Tom Joseph --- sensordatahandler.hpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'sensordatahandler.hpp') diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp index 1b05342..01b8e4f 100644 --- a/sensordatahandler.hpp +++ b/sensordatahandler.hpp @@ -49,6 +49,60 @@ ipmi_ret_t updateToDbus(IpmiUpdateData& msg); namespace get { +/** @brief Populate sensor name from the D-Bus property associated with the + * sensor. In the example entry from the yaml, the name of the D-bus + * property "AttemptsLeft" is the sensor name. + * + * 0x07: + * sensorType: 195 + * path: /xyz/openbmc_project/state/host0 + * sensorReadingType: 0x6F + * serviceInterface: org.freedesktop.DBus.Properties + * readingType: readingAssertion + * sensorNamePattern: nameProperty + * interfaces: + * xyz.openbmc_project.Control.Boot.RebootAttempts: + * AttemptsLeft: + * Offsets: + * 0xFF: + * type: uint32_t + * + * + * @param[in] sensorInfo - Dbus info related to sensor. + * + * @return On success return the sensor name for the sensor. + */ +inline SensorName nameProperty(const Info& sensorInfo) +{ + return sensorInfo.propertyInterfaces.begin()->second.begin()->first; +} + +/** @brief Populate sensor name from the D-Bus object associated with the + * sensor. If the object path is /system/chassis/motherboard/dimm0 then + * the leaf dimm0 is considered as the sensor name. + * + * @param[in] sensorInfo - Dbus info related to sensor. + * + * @return On success return the sensor name for the sensor. + */ +inline SensorName nameLeaf(const Info& sensorInfo) +{ + return sensorInfo.sensorPath.substr( + sensorInfo.sensorPath.find_last_of('/') + 1, + sensorInfo.sensorPath.length()); +} + +/** @brief Populate sensor name from the D-Bus object associated with the + * sensor. If the object path is /system/chassis/motherboard/cpu0/core0 + * then the sensor name is cpu0_core0. The leaf and the parent is put + * together to get the sensor name. + * + * @param[in] sensorInfo - Dbus info related to sensor. + * + * @return On success return the sensor name for the sensor. + */ +SensorName nameParentLeaf(const Info& sensorInfo); + /** * @brief Helper function to map the dbus info to sensor's assertion status * for the get sensor reading command. -- cgit v1.2.1