Brad Bishop | 26b815f | 2017-01-04 13:32:47 -0500 | [diff] [blame] | 1 | #pragma once |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 2 | |
| 3 | #include <map> |
| 4 | #include <set> |
| 5 | #include <string> |
| 6 | |
Matt Spinler | a4353bc | 2018-06-19 10:52:32 -0500 | [diff] [blame] | 7 | /** |
| 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 Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 20 | class SensorSet |
| 21 | { |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 22 | public: |
| 23 | typedef std::map<std::pair<std::string, std::string>, std::set<std::string>> |
| 24 | container_t; |
| 25 | using mapped_type = container_t::mapped_type; |
| 26 | using key_type = container_t::key_type; |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 27 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 28 | /** |
| 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 | */ |
| 36 | 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 Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 43 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 44 | /** |
| 45 | * @brief Returns an iterator to the beginning of the map |
| 46 | * |
| 47 | * @return const_iterator |
| 48 | */ |
| 49 | container_t::const_iterator begin() |
| 50 | { |
Patrick Venture | d0f5097 | 2018-12-19 14:43:12 -0800 | [diff] [blame] | 51 | return const_cast<const container_t&>(_container).begin(); |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 52 | } |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 53 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 54 | /** |
| 55 | * @brief Returns an iterator to the end of the map |
| 56 | * |
| 57 | * @return const_iterator |
| 58 | */ |
| 59 | container_t::const_iterator end() |
| 60 | { |
Patrick Venture | d0f5097 | 2018-12-19 14:43:12 -0800 | [diff] [blame] | 61 | return const_cast<const container_t&>(_container).end(); |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 62 | } |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 63 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 64 | private: |
| 65 | /** |
| 66 | * @brief The map of hwmon files in the directory |
| 67 | * @details For example: |
| 68 | * key = pair("temp", "1") |
| 69 | * value = "input" |
| 70 | */ |
Patrick Venture | d0f5097 | 2018-12-19 14:43:12 -0800 | [diff] [blame] | 71 | container_t _container; |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 72 | }; |