obmon  0.0.0
 All Classes Functions Variables Enumerations Groups Pages
ObSensor.h
1 
5 
7 #pragma once
8 
9 #include <spdlog/spdlog.h>
10 #include <vector>
11 
18 
19 class ObSensor {
20 public:
21 
23  enum class SensorType { VALUE, SPEED };
24 
25  ObSensor(std::string name = {"sensor"});
26  virtual ~ObSensor();
27 
28  virtual void init();
30  virtual void process(){};
32  virtual void speed(ObSensor * /*s1*/, ObSensor * /*s2*/,
33  int /*timeout*/){};
34  virtual std::string json(const std::string name = {}) const;
35 
36  virtual void update(int timeout) final;
37 
39  std::string name() const { return _name; }
40 
42  void type(SensorType t) { _type = t; }
43 
45  SensorType type() const { return _type; }
46 
48  std::vector<ObSensor *> &sensors() { return _sensors; }
49 
50 protected:
51  std::shared_ptr<spdlog::logger> _logger;
52  std::string _name;
57  std::vector<ObSensor *> _sensors{};
58 };
59 
std::shared_ptr< spdlog::logger > _logger
Pointer to spd logger.
Definition: ObSensor.h:51
std::vector< ObSensor * > & sensors()
Return list of sensors.
Definition: ObSensor.h:48
SensorType _type
Sensor type.
Definition: ObSensor.h:53
ObSensor(std::string name={"sensor"})
Definition: ObSensor.cpp:3
virtual void init()
Definition: ObSensor.cpp:16
std::string name() const
Returns name of sensor.
Definition: ObSensor.h:39
virtual void speed(ObSensor *, ObSensor *, int)
Calculate time change (speed)
Definition: ObSensor.h:32
std::vector< ObSensor * > _sensors
List of subsensors.
Definition: ObSensor.h:57
ObSensor * _first
Pointer to first sensor.
Definition: ObSensor.h:54
SensorType
Enums for sensor type.
Definition: ObSensor.h:23
ObSensor * _change
Pointer to change sensor.
Definition: ObSensor.h:56
virtual std::string json(const std::string name={}) const
Definition: ObSensor.cpp:50
ObSensor * _second
Pointer to second sensor.
Definition: ObSensor.h:55
virtual void update(int timeout) final
Definition: ObSensor.cpp:26
Base Obmon sensor class.
Definition: ObSensor.h:19
virtual void process()
Process function.
Definition: ObSensor.h:30
virtual ~ObSensor()
Definition: ObSensor.cpp:10
SensorType type() const
Returns sensor type.
Definition: ObSensor.h:45
std::string _name
Sensor name.
Definition: ObSensor.h:52
void type(SensorType t)
Sets sensor type.
Definition: ObSensor.h:42