Support indirections other than just "label"

The current code only allowed the MODE_<type><Num> env var
to be "label" when doing DBus naming indirection.

Add support to allow it to be anything, and then use that value
to do the lookup.

For example, if MODE_temp1 = "foo", then the code will read the
temp1_foo file to find the value to append to LABEL to find the
DBus object name.  So if temp1_foo contained a 42, then the code
will use the LABEL_temp42 var to find the object name.

Tested: Test on the OpenPower OCC device which use 'label' and now
        'function_id' for the indirections.

Change-Id: I1f3115a2d37d008efca74748ac7eff8434d8320a
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/env.cpp b/env.cpp
index 6841987..677f6fb 100644
--- a/env.cpp
+++ b/env.cpp
@@ -52,6 +52,7 @@
 
 std::string getIndirectID(
         std::string path,
+        const std::string& fileSuffix,
         const SensorSet::key_type& sensor)
 {
     std::string content;
@@ -59,7 +60,7 @@
     path.append(sensor.first);
     path.append(sensor.second);
     path.append(1, '_');
-    path.append(hwmon::entry::label);
+    path.append(fileSuffix);
 
     std::ifstream handle(path.c_str());
     if (!handle.fail())
diff --git a/env.hpp b/env.hpp
index fa23888..56dd2aa 100644
--- a/env.hpp
+++ b/env.hpp
@@ -43,14 +43,16 @@
 
 /** @brief Gets the ID for the sensor with a level of indirection
  *
- *  Read the sensor number/ID from the <path>/<item><X>_label file.
+ *  Read the ID from the <path>/<item><X>_<suffix> file.
  *  <item> & <X> are populated from the sensor key.
  *
  *  @param[in] path - Directory path of the label file
+ *  @param[in] fileSuffix - The file suffix
  *  @param[in] sensor - Sensor details
  */
 std::string getIndirectID(
     std::string path,
+    const std::string& fileSuffix,
     const SensorSet::key_type& sensor);
 
 }  // namespace env
diff --git a/mainloop.cpp b/mainloop.cpp
index 221c8c9..5243f3c 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -216,17 +216,24 @@
 
     /*
      * Check if the value of the MODE_<item><X> env variable for the sensor
-     * is "label", then read the sensor number from the <item><X>_label
+     * is set. If it is, then read the from the <item><X>_<mode>
      * file. The name of the DBUS object would be the value of the env
-     * variable LABEL_<item><sensorNum>. If the MODE_<item><X> env variable
+     * variable LABEL_<item><mode value>. If the MODE_<item><X> env variable
      * doesn't exist, then the name of DBUS object is the value of the env
      * variable LABEL_<item><X>.
+     *
+     * For example, if MODE_temp1 = "label", then code reads the temp1_label
+     * file.  If it has a 5 in it, then it will use the following entry to
+     * name the object: LABEL_temp5 = "My DBus object name".
+     *
      */
     auto mode = env::getEnv("MODE", sensor.first);
-    if (!mode.compare(hwmon::entry::label))
+    if (!mode.empty())
     {
         id = env::getIndirectID(
-                _hwmonRoot + '/' + _instance + '/', sensor.first);
+                _hwmonRoot + '/' + _instance + '/',
+                mode,
+                sensor.first);
 
         if (id.empty())
         {