Move getSensorConnection to header file
Move getSensorConnection to header file, so that the same
can be used by ipmi-providers Set Sensor override command
Change-Id: Ic6c313eb2bc07710c175b7908647a800f5fe45a0
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
diff --git a/include/sensorcommands.hpp b/include/sensorcommands.hpp
index 691fb11..6135105 100644
--- a/include/sensorcommands.hpp
+++ b/include/sensorcommands.hpp
@@ -132,3 +132,35 @@
ipmiCmdGetSensorType = 0x2F,
ipmiCmdSetSensorReadingAndEventStatus = 0x30,
};
+
+extern SensorSubTree sensorTree;
+static ipmi_ret_t getSensorConnection(uint8_t sensnum, std::string &connection,
+ std::string &path)
+{
+ if (sensorTree.empty() && !getSensorSubtree(sensorTree))
+ {
+ return IPMI_CC_RESPONSE_ERROR;
+ }
+
+ if (sensorTree.size() < (sensnum + 1))
+ {
+ return IPMI_CC_INVALID_FIELD_REQUEST;
+ }
+
+ uint8_t sensorIndex = sensnum;
+ for (const auto &sensor : sensorTree)
+ {
+ if (sensorIndex-- == 0)
+ {
+ if (!sensor.second.size())
+ {
+ return IPMI_CC_RESPONSE_ERROR;
+ }
+ connection = sensor.second.begin()->first;
+ path = sensor.first;
+ break;
+ }
+ }
+
+ return 0;
+}