blob: 41cc02ffe754ec91d6da11112f8c9521e06eeeea [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:
Jae Hyun Yooa8fa4d22018-10-22 15:24:29 -070010 std::string configuration;
11 CPUSensor(const std::string &path, const std::string &objectType,
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070012 sdbusplus::asio::object_server &objectServer,
Jae Hyun Yooa8fa4d22018-10-22 15:24:29 -070013 std::shared_ptr<sdbusplus::asio::connection> &conn,
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070014 boost::asio::io_service &io, const std::string &fanName,
Jae Hyun Yooa8fa4d22018-10-22 15:24:29 -070015 std::vector<thresholds::Threshold> &&thresholds,
16 const std::string &configuration);
17 ~CPUSensor();
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070018 static constexpr unsigned int sensorScaleFactor = 1000;
19 static constexpr unsigned int sensorPollMs = 1000;
Jae Hyun Yooa8fa4d22018-10-22 15:24:29 -070020
James Feist139cb572018-09-10 15:26:18 -070021 private:
James Feist139cb572018-09-10 15:26:18 -070022 std::string objectType;
23 sdbusplus::asio::object_server &objServer;
24 std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070025 boost::asio::posix::stream_descriptor inputDev;
26 boost::asio::deadline_timer waitTimer;
27 boost::asio::streambuf readBuf;
28 int errCount;
29 double maxValue;
30 double minValue;
31 void setupRead(void);
32 void handleResponse(const boost::system::error_code &err);
33 void checkThresholds(void);
34 void updateValue(const double &newValue);
James Feistaf79dd32018-09-12 12:54:15 -070035
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070036 void setInitialProperties(
James Feist139cb572018-09-10 15:26:18 -070037 std::shared_ptr<sdbusplus::asio::connection> &conn);
James Feist139cb572018-09-10 15:26:18 -070038};