blob: 8f09e03710d7dd3206cb1e1b34f2d6118a76d1b0 [file] [log] [blame]
Brad Bishop26b815f2017-01-04 13:32:47 -05001#pragma once
Patrick Williams3667cf32015-10-20 22:39:11 -05002
3#include <fstream>
4#include <string>
5
6template <typename T>
7void read_sysfs(const std::string& path, T& val)
8{
9 std::ifstream s(path);
10 s >> val;
11}
12
13template <typename T>
14void write_sysfs(const std::string& path, const T& val)
15{
16 std::ofstream s(path);
17 s << val;
18}
19
Brad Bishopa9b5f052017-01-17 14:50:08 -050020inline std::string make_sysfs_path(const std::string& path,
21 const std::string& type,
22 const std::string& id,
23 const std::string& entry)
Patrick Williams3667cf32015-10-20 22:39:11 -050024{
25 using namespace std::literals;
26
27 return path + "/"s + type + id + "_"s + entry;
28}
29
Brad Bishop613a5b32017-01-05 20:58:13 -050030
31/** @brief Find hwmon instances
32 *
33 * Look for a matching hwmon instance given an
34 * open firmware device path.
35 *
36 * @param[in] ofNode- The open firmware device path.
37 *
38 * @returns[in] - The hwmon instance path or an empty
39 * string if no match is found.
40 */
41std::string findHwmon(const std::string& ofNode);
42
Brad Bishop03476f12016-12-19 13:09:12 -050043// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4