blob: c4fca5d6944429b8204a1b7428b07adbb9ea2526 [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,
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070013 sdbusplus::asio::object_server &objectServer,
Jae Hyun Yooa8fa4d22018-10-22 15:24:29 -070014 std::shared_ptr<sdbusplus::asio::connection> &conn,
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070015 boost::asio::io_service &io, const std::string &fanName,
Jae Hyun Yooa8fa4d22018-10-22 15:24:29 -070016 std::vector<thresholds::Threshold> &&thresholds,
17 const std::string &configuration);
18 ~CPUSensor();
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070019 static constexpr unsigned int sensorScaleFactor = 1000;
20 static constexpr unsigned int sensorPollMs = 1000;
Jae Hyun Yooa8fa4d22018-10-22 15:24:29 -070021
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;
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070027 boost::asio::posix::stream_descriptor inputDev;
28 boost::asio::deadline_timer waitTimer;
29 boost::asio::streambuf readBuf;
30 int errCount;
31 double maxValue;
32 double minValue;
33 void setupRead(void);
34 void handleResponse(const boost::system::error_code &err);
35 void checkThresholds(void);
36 void updateValue(const double &newValue);
James Feistaf79dd32018-09-12 12:54:15 -070037
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070038 void setInitialProperties(
James Feist139cb572018-09-10 15:26:18 -070039 std::shared_ptr<sdbusplus::asio::connection> &conn);
James Feist139cb572018-09-10 15:26:18 -070040};