James Feist | 139cb57 | 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 | af79dd3 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 5 | #include <sensor.hpp> |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 6 | |
James Feist | af79dd3 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 7 | class CPUSensor : public Sensor |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 8 | { |
Jae Hyun Yoo | a8fa4d2 | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 9 | public: |
| 10 | std::string name; |
| 11 | std::string configuration; |
| 12 | CPUSensor(const std::string &path, const std::string &objectType, |
Jae Hyun Yoo | f78ec41 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 13 | sdbusplus::asio::object_server &objectServer, |
Jae Hyun Yoo | a8fa4d2 | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 14 | std::shared_ptr<sdbusplus::asio::connection> &conn, |
Jae Hyun Yoo | f78ec41 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 15 | boost::asio::io_service &io, const std::string &fanName, |
Jae Hyun Yoo | a8fa4d2 | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 16 | std::vector<thresholds::Threshold> &&thresholds, |
| 17 | const std::string &configuration); |
| 18 | ~CPUSensor(); |
Jae Hyun Yoo | f78ec41 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 19 | static constexpr unsigned int sensorScaleFactor = 1000; |
| 20 | static constexpr unsigned int sensorPollMs = 1000; |
Jae Hyun Yoo | a8fa4d2 | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 21 | |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 22 | 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 Yoo | f78ec41 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 27 | 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 Feist | af79dd3 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 37 | |
Jae Hyun Yoo | f78ec41 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 38 | void setInitialProperties( |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 39 | std::shared_ptr<sdbusplus::asio::connection> &conn); |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 40 | }; |