blob: 10c1f4eeb46c79fd734dc1e4d8d60e62ee97e00f [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
2
3#include <Thresholds.hpp>
4#include <sdbusplus/asio/object_server.hpp>
James Feist251c7822018-09-12 12:54:15 -07005#include <sensor.hpp>
James Feist6714a252018-09-10 15:26:18 -07006
James Feist251c7822018-09-12 12:54:15 -07007class CPUSensor : public Sensor
James Feist6714a252018-09-10 15:26:18 -07008{
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -07009 public:
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -070010 CPUSensor(const std::string &path, const std::string &objectType,
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070011 sdbusplus::asio::object_server &objectServer,
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -070012 std::shared_ptr<sdbusplus::asio::connection> &conn,
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070013 boost::asio::io_service &io, const std::string &fanName,
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -070014 std::vector<thresholds::Threshold> &&thresholds,
15 const std::string &configuration);
16 ~CPUSensor();
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070017 static constexpr unsigned int sensorScaleFactor = 1000;
18 static constexpr unsigned int sensorPollMs = 1000;
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -070019
James Feist6714a252018-09-10 15:26:18 -070020 private:
James Feist6714a252018-09-10 15:26:18 -070021 sdbusplus::asio::object_server &objServer;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070022 boost::asio::posix::stream_descriptor inputDev;
23 boost::asio::deadline_timer waitTimer;
24 boost::asio::streambuf readBuf;
25 int errCount;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070026 void setupRead(void);
27 void handleResponse(const boost::system::error_code &err);
James Feistce3fca42018-11-21 12:58:24 -080028 void checkThresholds(void) override;
James Feist6714a252018-09-10 15:26:18 -070029};