xref: /openbmc/phosphor-hwmon/sensor.hpp (revision 2e41b13f)
1 #pragma once
2 
3 #include "types.hpp"
4 #include "sensorset.hpp"
5 #include "hwmonio.hpp"
6 
7 namespace sensor
8 {
9 
10 /** @class Sensor
11  *  @brief Sensor object based on a SensorSet container's key type
12  *  @details Sensor object to create and modify an associated device's sensor
13  *  attributes based on the key type of each sensor in the set provided by the
14  *  device.
15  */
16 class Sensor
17 {
18     public:
19         Sensor() = delete;
20         Sensor(const Sensor&) = delete;
21         Sensor(Sensor&&) = default;
22         Sensor& operator=(const Sensor&) = delete;
23         Sensor& operator=(Sensor&&) = default;
24         ~Sensor() = default;
25 
26         /**
27          * @brief Constructs Sensor object
28          *
29          * @param[in] sensor - A pair of sensor indentifiers
30          * @param[in] ioAccess - Hwmon sysfs access
31          * @param[in] devPath - Device sysfs path
32          */
33         explicit Sensor(const SensorSet::key_type& sensor,
34                         const hwmonio::HwmonIO& ioAccess,
35                         const std::string& devPath);
36 
37         /**
38          * @brief Add status interface and functional property for sensor
39          * @details When a sensor has an associated fault file, the
40          * OperationalStatus interface is added along with setting the
41          * Functional property to the corresponding value found in the
42          * fault file.
43          *
44          * @param[in] info - Sensor object information
45          *
46          * @return - Shared pointer to the status object
47          */
48         std::shared_ptr<StatusObject> addStatus(
49                 ObjectInfo& info);
50 
51     private:
52         /** @brief Sensor object's identifiers */
53         SensorSet::key_type sensor;
54 
55         /** @brief Hwmon sysfs access. */
56         const hwmonio::HwmonIO& ioAccess;
57 
58         /** @brief Physical device sysfs path. */
59         const std::string& devPath;
60 };
61 
62 } // namespace sensor
63