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>
diff --git a/sensordatahandler.cpp b/sensordatahandler.cpp
index 7c4cd3c..b9ef5e2 100644
--- a/sensordatahandler.cpp
+++ b/sensordatahandler.cpp
@@ -127,11 +127,17 @@
command.c_str());
}
-ipmi_ret_t appendDiscreteSignalData(IpmiUpdateData& msg,
- const DbusInterfaceMap& interfaceMap,
- uint8_t data)
+ipmi_ret_t eventdata(const SetSensorReadingReq& cmdData,
+ const Info& sensorInfo,
+ uint8_t data)
{
- const auto& interface = interfaceMap.begin();
+ 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)
{
@@ -144,32 +150,22 @@
}
msg.append(iter->second.assert);
}
- return IPMI_CC_OK;
+ return updateToDbus(msg);
}
-ipmi_ret_t appendReadingData(IpmiUpdateData& msg,
- const DbusInterfaceMap& interfaceMap,
- const Value &data)
+ipmi_ret_t assertion(const SetSensorReadingReq& cmdData,
+ const Info& sensorInfo)
{
- const auto& interface = interfaceMap.begin();
- msg.append(interface->first);
- for (const auto& property : interface->second)
- {
- msg.append(property.first);
- msg.append(data);
- }
- return IPMI_CC_OK;
-}
+ auto msg = makeDbusMsg(
+ "org.freedesktop.DBus.Properties",
+ sensorInfo.sensorPath,
+ "Set",
+ sensorInfo.sensorInterface);
-ipmi_ret_t appendAssertion(IpmiUpdateData& msg,
- const DbusInterfaceMap& interfaceMap,
- const std::string& sensorPath,
- const SetSensorReadingReq& cmdData)
-{
std::bitset<16> assertionSet(getAssertionSet(cmdData).first);
std::bitset<16> deassertionSet(getAssertionSet(cmdData).second);
- const auto& interface = interfaceMap.begin();
+ const auto& interface = sensorInfo.propertyInterfaces.begin();
msg.append(interface->first);
for (const auto& property : interface->second)
{
@@ -186,8 +182,9 @@
}
}
}
- return IPMI_CC_OK;
+ return updateToDbus(msg);
}
+
}//namespace set
namespace notify
@@ -213,16 +210,20 @@
command.c_str());
}
-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)
{
+ auto msg = makeDbusMsg(
+ sensorInfo.sensorInterface,
+ sensorInfo.sensorPath,
+ "Notify",
+ sensorInfo.sensorInterface);
+
std::bitset<16> assertionSet(getAssertionSet(cmdData).first);
std::bitset<16> deassertionSet(getAssertionSet(cmdData).second);
ipmi::sensor::ObjectMap objects;
ipmi::sensor::InterfaceMap interfaces;
- for (const auto& interface : interfaceMap)
+ for (const auto& interface : sensorInfo.propertyInterfaces)
{
for (const auto& property : interface.second)
{
@@ -247,9 +248,9 @@
}
}
}
- objects.emplace(sensorPath, std::move(interfaces));
+ objects.emplace(sensorInfo.sensorPath, std::move(interfaces));
msg.append(std::move(objects));
- return IPMI_CC_OK;
+ return updateToDbus(msg);
}
}//namespace notify
}//namespace sensor