1 #pragma once 2 3 #include <chrono> 4 #include <exception> 5 #include <fstream> 6 #include <string> 7 8 namespace sysfs { 9 10 inline std::string make_sysfs_path(const std::string& path, 11 const std::string& type, 12 const std::string& id, 13 const std::string& entry) 14 { 15 using namespace std::literals; 16 17 if (entry.empty()) { 18 return path + "/"s + type + id; 19 } 20 21 return path + "/"s + type + id + "_"s + entry; 22 } 23 24 /** @brief Return the path to the phandle file matching value in io-channels. 25 * 26 * This function will take two passed in paths. 27 * One path is used to find the io-channels file. 28 * The other path is used to find the phandle file. 29 * The 4 byte phandle value is read from the phandle file(s). 30 * The 4 byte phandle value and 4 byte index value is read from io-channels. 31 * When a match is found, the path to the matching phandle file is returned. 32 * 33 * @param[in] iochanneldir - Path to file for getting phandle from io-channels 34 * @param[in] phandledir - Path to use for reading from phandle file 35 * 36 * @return Path to phandle file with value matching that in io-channels 37 */ 38 std::string findPhandleMatch( 39 const std::string& iochanneldir, 40 const std::string& phandledir); 41 42 /** @brief Find hwmon instances from an open-firmware device tree path 43 * 44 * Look for a matching hwmon instance given an 45 * open firmware device path. 46 * 47 * @param[in] ofNode- The open firmware device path. 48 * 49 * @returns[in] - The hwmon instance path or an empty 50 * string if no match is found. 51 */ 52 std::string findHwmonFromOFPath(const std::string& ofNode); 53 54 /** @brief Find hwmon instances from a device path 55 * 56 * Look for a matching hwmon instance given a device path that 57 * starts with /devices. This path is the DEVPATH udev attribute 58 * for the device except it has the '/hwmon/hwmonN' stripped off. 59 * 60 * @param[in] devPath - The device path. 61 * 62 * @return - The hwmon instance path or an empty 63 * string if no match is found. 64 */ 65 std::string findHwmonFromDevPath(const std::string& devPath); 66 67 /** @brief Return the path to use for a call out. 68 * 69 * Return an empty string if a callout path cannot be 70 * found. 71 * 72 * @param[in] instancePath - /sys/class/hwmon/hwmon<N> path. 73 * 74 * @return Path to use for call out 75 */ 76 std::string findCalloutPath(const std::string& instancePath); 77 78 } // namespace sysfs 79 80 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 81