1 #pragma once
2 
3 #include "interfaces.hpp"
4 
5 #include <chrono>
6 #include <string>
7 
8 /**
9  * Abstract base class for all sensors.
10  */
11 class Sensor
12 {
13   public:
14     /**
15      * Given a sensor's type, return the default timeout value.
16      * A timeout of 0 means there isn't a timeout for this sensor.
17      * By default a fan sensor isn't checked for a timeout, whereas
18      * any of sensor is meant to be sampled once per second.  By default.
19      *
20      * @param[in] type - the sensor type (e.g. fan)
21      * @return the default timeout for that type (in seconds).
22      */
23     static int64_t getDefaultTimeout(const std::string& type)
24     {
25         return (type == "fan") ? 0 : 2;
26     }
27 
28     Sensor(const std::string& name, int64_t timeout) :
29         _name(name), _timeout(timeout)
30     {}
31 
32     virtual ~Sensor()
33     {}
34 
35     virtual ReadReturn read(void) = 0;
36     virtual void write(double value) = 0;
37     virtual bool getFailed(void)
38     {
39         return false;
40     };
41 
42     std::string getName(void) const
43     {
44         return _name;
45     }
46 
47     /* Returns the configurable timeout period
48      * for this sensor in seconds (undecorated).
49      */
50     int64_t getTimeout(void) const
51     {
52         return _timeout;
53     }
54 
55   private:
56     std::string _name;
57     int64_t _timeout;
58 };
59