summaryrefslogtreecommitdiffstats
path: root/sensorset.hpp
blob: 7f6f3f934e2365d09e98dd261eb7017615466d7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once

#include <map>
#include <set>
#include <string>

/**
 * @class SensorSet
 * @brief Finds and holds the available hwmon sensors for a device
 * @details When passed a hwmon device directory on construction,
 *          this class will find all hwmon sysfs files in that directory
 *          and store them in a map.  The public begin() and end() methods
 *          on this class allow traversal of this map.
 *
 *          For example, a file named temp5_input will have a map entry of:
 *
 *              key:   pair<string, string> = {"temp", "5"}
 *              value: std::string = "input"
 */
class SensorSet
{
  public:
    typedef std::map<std::pair<std::string, std::string>, std::set<std::string>>
        container_t;
    using mapped_type = container_t::mapped_type;
    using key_type = container_t::key_type;

    /**
     * @brief Constructor
     * @details Builds a map of the hwmon sysfs files in the passed
     *          in directory.
     *
     * @param[in] path - path to the hwmon device directory
     *
     */
    explicit SensorSet(const std::string& path);
    ~SensorSet() = default;
    SensorSet() = delete;
    SensorSet(const SensorSet&) = delete;
    SensorSet& operator=(const SensorSet&) = delete;
    SensorSet(SensorSet&&) = default;
    SensorSet& operator=(SensorSet&&) = default;

    /**
     * @brief Returns an iterator to the beginning of the map
     *
     * @return const_iterator
     */
    container_t::const_iterator begin()
    {
        return const_cast<const container_t&>(_container).begin();
    }

    /**
     * @brief Returns an iterator to the end of the map
     *
     * @return const_iterator
     */
    container_t::const_iterator end()
    {
        return const_cast<const container_t&>(_container).end();
    }

  private:
    /**
     * @brief The map of hwmon files in the directory
     * @details For example:
     *          key = pair("temp", "1")
     *          value = "input"
     */
    container_t _container;
};

// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
OpenPOWER on IntegriCloud