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