blob: 420761feadc36f478cce0b0a8faf8d2c2732631d [file] [log] [blame]
Brad Bishop26b815f2017-01-04 13:32:47 -05001#pragma once
Patrick Williams3667cf32015-10-20 22:39:11 -05002
3#include <map>
4#include <set>
5#include <string>
6
Matt Spinlera4353bc2018-06-19 10:52:32 -05007/**
8 * @class SensorSet
9 * @brief Finds and holds the available hwmon sensors for a device
10 * @details When passed a hwmon device directory on construction,
11 * this class will find all hwmon sysfs files in that directory
12 * and store them in a map. The public begin() and end() methods
13 * on this class allow traversal of this map.
14 *
15 * For example, a file named temp5_input will have a map entry of:
16 *
17 * key: pair<string, string> = {"temp", "5"}
18 * value: std::string = "input"
19 */
Patrick Williams3667cf32015-10-20 22:39:11 -050020class SensorSet
21{
22 public:
23 typedef std::map<std::pair<std::string, std::string>,
Brad Bishop6bb97a92016-12-19 13:06:40 -050024 std::set<std::string>> container_t;
Brad Bishop75017ae2017-01-05 12:07:04 -050025 using mapped_type = container_t::mapped_type;
26 using key_type = container_t::key_type;
Patrick Williams3667cf32015-10-20 22:39:11 -050027
Matt Spinlera4353bc2018-06-19 10:52:32 -050028 /**
29 * @brief Constructor
30 * @details Builds a map of the hwmon sysfs files in the passed
31 * in directory.
32 *
33 * @param[in] path - path to the hwmon device directory
34 *
35 */
Brad Bishop92bbd052017-01-05 06:53:02 -050036 explicit SensorSet(const std::string& path);
37 ~SensorSet() = default;
38 SensorSet() = delete;
39 SensorSet(const SensorSet&) = delete;
40 SensorSet& operator=(const SensorSet&) = delete;
41 SensorSet(SensorSet&&) = default;
42 SensorSet& operator=(SensorSet&&) = default;
Patrick Williams3667cf32015-10-20 22:39:11 -050043
Matt Spinlera4353bc2018-06-19 10:52:32 -050044 /**
45 * @brief Returns an iterator to the beginning of the map
46 *
47 * @return const_iterator
48 */
Patrick Williams3667cf32015-10-20 22:39:11 -050049 container_t::const_iterator begin()
50 {
51 return const_cast<const container_t&>(container).begin();
52 }
53
Matt Spinlera4353bc2018-06-19 10:52:32 -050054 /**
55 * @brief Returns an iterator to the end of the map
56 *
57 * @return const_iterator
58 */
Patrick Williams3667cf32015-10-20 22:39:11 -050059 container_t::const_iterator end()
60 {
61 return const_cast<const container_t&>(container).end();
62 }
63
64 private:
Matt Spinlera4353bc2018-06-19 10:52:32 -050065
66 /**
67 * @brief The map of hwmon files in the directory
68 * @details For example:
69 * key = pair("temp", "1")
70 * value = "input"
71 */
Patrick Williams3667cf32015-10-20 22:39:11 -050072 container_t container;
73
74};
75
Brad Bishop03476f12016-12-19 13:09:12 -050076// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4