Add getIndirectID function
This function will look up the sensor ID for a sensor when
it is specified in a label file in hwmon sysfs.
This functionality was previously all contained in
getIndirectlLabelEnv(). A future commit will remove this
function entirely and just use getIndirectID() and getEnv()
to look up the label for the indirect case.
Change-Id: Ifeb636eb0e58a6204f782f64e9aba839b812a967
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/env.cpp b/env.cpp
index efd081b..3194441 100644
--- a/env.cpp
+++ b/env.cpp
@@ -48,6 +48,34 @@
return getEnv(prefix, sensor);
}
+std::string getIndirectID(
+ std::string path,
+ const SensorSet::key_type& sensor)
+{
+ std::string content;
+
+ path.append(sensor.first);
+ path.append(sensor.second);
+ path.append(1, '_');
+ path.append(hwmon::entry::label);
+
+ std::ifstream handle(path.c_str());
+ if (!handle.fail())
+ {
+ content.assign(
+ (std::istreambuf_iterator<char>(handle)),
+ (std::istreambuf_iterator<char>()));
+
+ if (!content.empty())
+ {
+ //remove the newline
+ content.pop_back();
+ }
+ }
+
+ return content;
+}
+
std::string getIndirectLabelEnv(
const char* prefix, std::string path, const SensorSet::key_type& sensor)
{
diff --git a/env.hpp b/env.hpp
index 6342e25..e1169e1 100644
--- a/env.hpp
+++ b/env.hpp
@@ -27,6 +27,18 @@
const std::string& type,
const std::string& id);
+/** @brief Gets the ID for the sensor with a level of indirection
+ *
+ * Read the sensor number/ID from the <path>/<item><X>_label file.
+ * <item> & <X> are populated from the sensor key.
+ *
+ * @param[in] path - Directory path of the label file
+ * @param[in] sensor - Sensor details
+ */
+std::string getIndirectID(
+ std::string path,
+ const SensorSet::key_type& sensor);
+
/** @brief Get the label for the sensor with a level of indirection.
*
* Read the sensor number from the <path>/<item><X>_label file.<item> & <X> is