diff options
author | Matt Spinler <spinler@us.ibm.com> | 2018-05-04 10:52:40 -0500 |
---|---|---|
committer | Matt Spinler <spinler@us.ibm.com> | 2018-05-07 21:19:53 +0000 |
commit | 7c424807216cf276fb247954060561030720ea4e (patch) | |
tree | 9e8a3c0342e6a75db0584295732423965d2ad62c | |
parent | c897d8bb66ff98882a5f5c4df5afb94d678f61d4 (diff) | |
download | phosphor-hwmon-7c424807216cf276fb247954060561030720ea4e.tar.gz phosphor-hwmon-7c424807216cf276fb247954060561030720ea4e.zip |
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>
-rw-r--r-- | env.cpp | 3 | ||||
-rw-r--r-- | env.hpp | 4 | ||||
-rw-r--r-- | mainloop.cpp | 15 |
3 files changed, 16 insertions, 6 deletions
@@ -52,6 +52,7 @@ std::string getEnv( std::string getIndirectID( std::string path, + const std::string& fileSuffix, const SensorSet::key_type& sensor) { std::string content; @@ -59,7 +60,7 @@ std::string getIndirectID( 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()) @@ -43,14 +43,16 @@ std::string getEnv( /** @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 @@ std::string MainLoop::getID(SensorSet::container_t::const_reference sensor) /* * 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()) { |