summaryrefslogtreecommitdiffstats
path: root/sensordatahandler.cpp
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.cpp
parent8b26d353da78858d92c2e0fa814a79e5a6dd29e7 (diff)
downloadphosphor-host-ipmid-1bb0d387cd238a1d4b8c38c474433ccaada47a22.tar.gz
phosphor-host-ipmid-1bb0d387cd238a1d4b8c38c474433ccaada47a22.zip
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.cpp')
-rw-r--r--sensordatahandler.cpp63
1 files changed, 32 insertions, 31 deletions
diff --git a/sensordatahandler.cpp b/sensordatahandler.cpp
index 7c4cd3c..b9ef5e2 100644
--- a/sensordatahandler.cpp
+++ b/sensordatahandler.cpp
@@ -127,11 +127,17 @@ IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
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 @@ ipmi_ret_t appendDiscreteSignalData(IpmiUpdateData& msg,
}
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 @@ ipmi_ret_t appendAssertion(IpmiUpdateData& msg,
}
}
}
- return IPMI_CC_OK;
+ return updateToDbus(msg);
}
+
}//namespace set
namespace notify
@@ -213,16 +210,20 @@ IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
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 @@ ipmi_ret_t appendAssertion(IpmiUpdateData& msg,
}
}
}
- 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
OpenPOWER on IntegriCloud