summaryrefslogtreecommitdiffstats
path: root/sensordatahandler.hpp
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2017-08-12 02:01:27 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-08-15 19:29:25 +0000
commit1bb0d387cd238a1d4b8c38c474433ccaada47a22 (patch)
tree2034d96ff380e7f20f5405fad129fb1cddd54149 /sensordatahandler.hpp
parent8b26d353da78858d92c2e0fa814a79e5a6dd29e7 (diff)
downloadphosphor-host-ipmid-1bb0d387cd238a1d4b8c38c474433ccaada47a22.zip
phosphor-host-ipmid-1bb0d387cd238a1d4b8c38c474433ccaada47a22.tar.gz
Refactor set sensor handling code
A summary of the changes: - Do not generate per sensor type code to update d-bus objects corresponding to sensors. Function to update d-bus objects based on standard sensor event types, such as assertion, event data, are now generic functions - the need not be generated per sensor or per sensor type. - There's a special case where the assertion is treated as a reading (i.e read the entire assertion field as-is). In this case, code needs to be generated per sensor because the type of the mapped d-bus property can vary. In this case have a generic template function, and generate minimal code like so: inline ipmi_ret_t readingAssertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo) { // Corresponding d-bus property is uint32_t return set::readingAssertion<uint32_t>(cmdData, sensorInfo); } - Make sensor-example.yaml succinct. - Make the code in writesensor.mako.cpp more pythonic. Change-Id: I84415ca6e3f756bbb51a90e290539eb086a7f78b Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Diffstat (limited to 'sensordatahandler.hpp')
-rw-r--r--sensordatahandler.hpp133
1 files changed, 76 insertions, 57 deletions
diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp
index f75c377..68a122d 100644
--- a/sensordatahandler.hpp
+++ b/sensordatahandler.hpp
@@ -1,3 +1,5 @@
+#pragma once
+
#include "types.hpp"
#include "host-ipmid/ipmid-api.h"
@@ -57,37 +59,84 @@ IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
const std::string& command,
const std::string& sensorInterface);
-/** @brief Create a message for IPMI assertion
- * @param[in] msg - Message to add the values
- * @param[in] interface - sensor interface
- * @param[in] sensorPath - Path of the sensor
+/** @brief Update d-bus based on assertion type sensor data
* @param[in] cmdData - input sensor data
+ * @param[in] sensorInfo - sensor d-bus info
* @return a IPMI error code
*/
-ipmi_ret_t appendAssertion(IpmiUpdateData& msg,
- const DbusInterfaceMap& interfaceMap,
- const std::string& sensorPath,
- const SetSensorReadingReq& cmdData);
+ipmi_ret_t assertion(const SetSensorReadingReq& cmdData,
+ const Info& sensorInfo);
+
+/** @brief Update d-bus based on a reading assertion
+ * @tparam T - type of d-bus property mapping this sensor
+ * @param[in] cmdData - input sensor data
+ * @param[in] sensorInfo - sensor d-bus info
+ * @return a IPMI error code
+ */
+template<typename T>
+ipmi_ret_t readingAssertion(const SetSensorReadingReq& cmdData,
+ const Info& sensorInfo)
+{
+ auto msg = makeDbusMsg(
+ "org.freedesktop.DBus.Properties",
+ sensorInfo.sensorPath,
+ "Set",
+ sensorInfo.sensorInterface);
+
+ const auto& interface = sensorInfo.propertyInterfaces.begin();
+ msg.append(interface->first);
+ for (const auto& property : interface->second)
+ {
+ msg.append(property.first);
+ sdbusplus::message::variant<T> value =
+ (cmdData.assertOffset8_14 << 8) | cmdData.assertOffset0_7;
+ msg.append(value);
+ }
+ return updateToDbus(msg);
+}
+
+
+/** @brief Update d-bus based on eventdata type sensor data
+ * @param[in] cmdData - input sensor data
+ * @param[in] sensorInfo - sensor d-bus info
+ * @return a IPMI error code
+ */
+ipmi_ret_t eventdata(const SetSensorReadingReq& cmdData,
+ const Info& sensorInfo,
+ uint8_t data);
-/** @brief Create a message for discrete signal
- * @param[in] msg - Message to add the values
- * @param[in] interface - sensor interface
- * @param[in] data - input discrete sensor data
+/** @brief Update d-bus based on eventdata1 type sensor data
+ * @param[in] cmdData - input sensor data
+ * @param[in] sensorInfo - sensor d-bus info
* @return a IPMI error code
*/
-ipmi_ret_t appendDiscreteSignalData(IpmiUpdateData& msg,
- const DbusInterfaceMap& interfaceMap,
- uint8_t data);
-
-/** @brief Create a message for reading data
- * @param[in] msg - Message to add the values
- * @param[in] interface - sensor interface
- * @param[in] data - input sensor data
+inline ipmi_ret_t eventdata1(const SetSensorReadingReq& cmdData,
+ const Info& sensorInfo)
+{
+ return eventdata(cmdData, sensorInfo, cmdData.eventData1);
+}
+
+/** @brief Update d-bus based on eventdata2 type sensor data
+ * @param[in] cmdData - input sensor data
+ * @param[in] sensorInfo - sensor d-bus info
* @return a IPMI error code
*/
-ipmi_ret_t appendReadingData(IpmiUpdateData& msg,
- const DbusInterfaceMap& interfaceMap,
- const Value& data);
+inline ipmi_ret_t eventdata2(const SetSensorReadingReq& cmdData,
+ const Info& sensorInfo)
+{
+ return eventdata(cmdData, sensorInfo, cmdData.eventData2);
+}
+
+/** @brief Update d-bus based on eventdata3 type sensor data
+ * @param[in] cmdData - input sensor data
+ * @param[in] sensorInfo - sensor d-bus info
+ * @return a IPMI error code
+ */
+inline ipmi_ret_t eventdata3(const SetSensorReadingReq& cmdData,
+ const Info& sensorInfo)
+{
+ return eventdata(cmdData, sensorInfo, cmdData.eventData3);
+}
}//namespace set
@@ -106,44 +155,14 @@ IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
const std::string& command,
const std::string& sensorInterface);
-/** @brief Create a message for IPMI discrete signal
- * @param[in] msg - Message to add the values
+/** @brief Update d-bus based on assertion type sensor data
* @param[in] interfaceMap - sensor interface
- * @param[in] sensorPath - Path of the sensor
* @param[in] cmdData - input sensor data
+ * @param[in] sensorInfo - sensor d-bus info
* @return a IPMI error code
*/
-inline ipmi_ret_t appendDiscreteSignalData(IpmiUpdateData& msg,
- const DbusInterfaceMap& interfaceMap,
- uint8_t data)
-{
- return IPMI_CC_OK;
-}
-
-/** @brief Create a message for reading data
- * @param[in] msg - Message to add the values
- * @param[in] interfaceMap - sensor interface
- * @param[in] data - input sensor data
- * @return a IPMI error code
- */
-inline ipmi_ret_t appendReadingData(IpmiUpdateData& msg,
- const DbusInterfaceMap& interfaceMap,
- const Value &data)
-{
- return IPMI_CC_OK;
-}
-
-/** @brief Create a message for IPMI asserting
- * @param[in] msg - Message to add the values
- * @param[in] interfaceMap - sensor interface
- * @param[in] sensorPath - Path of the sensor
- * @param[in] cmdData - input sensor data
- * @return a IPMI error code
- */
-ipmi_ret_t appendAssertion(IpmiUpdateData& msg,
- const DbusInterfaceMap& interfaceMap,
- const std::string& sensorPath,
- const SetSensorReadingReq& cmdData);
+ipmi_ret_t assertion(const SetSensorReadingReq& cmdData,
+ const Info& sensorInfo);
}//namespace notify
}//namespace sensor
OpenPOWER on IntegriCloud