James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <Thresholds.hpp> |
| 4 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 5 | #include <sensor.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 6 | |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 7 | class CPUSensor : public Sensor |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 8 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 9 | public: |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 10 | std::string configuration; |
| 11 | CPUSensor(const std::string &path, const std::string &objectType, |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 12 | sdbusplus::asio::object_server &objectServer, |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 13 | std::shared_ptr<sdbusplus::asio::connection> &conn, |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 14 | boost::asio::io_service &io, const std::string &fanName, |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 15 | std::vector<thresholds::Threshold> &&thresholds, |
| 16 | const std::string &configuration); |
| 17 | ~CPUSensor(); |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 18 | static constexpr unsigned int sensorScaleFactor = 1000; |
| 19 | static constexpr unsigned int sensorPollMs = 1000; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 20 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 21 | private: |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 22 | std::string objectType; |
| 23 | sdbusplus::asio::object_server &objServer; |
| 24 | std::shared_ptr<sdbusplus::asio::connection> dbusConnection; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 25 | 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 Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 35 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 36 | void setInitialProperties( |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 37 | std::shared_ptr<sdbusplus::asio::connection> &conn); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 38 | }; |