blob: 42298018c5155c546aa2298d335cc0496edb3565 [file] [log] [blame]
James Feist139cb572018-09-10 15:26:18 -07001#pragma once
2
3#include <Thresholds.hpp>
4#include <sdbusplus/asio/object_server.hpp>
James Feistaf79dd32018-09-12 12:54:15 -07005#include <sensor.hpp>
James Feist139cb572018-09-10 15:26:18 -07006
James Feistaf79dd32018-09-12 12:54:15 -07007class CPUSensor : public Sensor
James Feist139cb572018-09-10 15:26:18 -07008{
Jae Hyun Yooa8fa4d22018-10-22 15:24:29 -07009 public:
10 std::string name;
11 std::string configuration;
12 CPUSensor(const std::string &path, const std::string &objectType,
13 sdbusplus::asio::object_server &object_server,
14 std::shared_ptr<sdbusplus::asio::connection> &conn,
15 boost::asio::io_service &io, const std::string &fan_name,
16 std::vector<thresholds::Threshold> &&thresholds,
17 const std::string &configuration);
18 ~CPUSensor();
19 constexpr static unsigned int SENSOR_SCALE_FACTOR = 1000;
20 constexpr static unsigned int SENSOR_POLL_MS = 1000;
21
James Feist139cb572018-09-10 15:26:18 -070022 private:
23 std::string path;
24 std::string objectType;
25 sdbusplus::asio::object_server &objServer;
26 std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
James Feist139cb572018-09-10 15:26:18 -070027 boost::asio::posix::stream_descriptor input_dev;
28 boost::asio::deadline_timer wait_timer;
29 boost::asio::streambuf read_buf;
James Feist139cb572018-09-10 15:26:18 -070030 int err_count;
31 double max_value;
32 double min_value;
33 void setup_read(void);
34 void handle_response(const boost::system::error_code &err);
35 void check_thresholds(void);
36 void update_value(const double &new_value);
James Feistaf79dd32018-09-12 12:54:15 -070037
James Feist139cb572018-09-10 15:26:18 -070038 void set_initial_properties(
39 std::shared_ptr<sdbusplus::asio::connection> &conn);
James Feist139cb572018-09-10 15:26:18 -070040};