James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <Thresholds.hpp> |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 4 | #include <boost/container/flat_map.hpp> |
| 5 | #include <boost/container/flat_set.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 6 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 7 | #include <sensor.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 8 | |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 9 | constexpr const char *gpioPath = "/sys/class/gpio/"; |
| 10 | class PresenceSensor |
| 11 | { |
| 12 | |
| 13 | public: |
| 14 | PresenceSensor(const size_t index, bool inverted, |
| 15 | boost::asio::io_service &io); |
| 16 | ~PresenceSensor(); |
| 17 | |
| 18 | void monitorPresence(void); |
| 19 | void read(void); |
| 20 | bool getValue(void); |
| 21 | |
| 22 | private: |
| 23 | bool status = true; |
| 24 | bool inverted; |
| 25 | boost::asio::ip::tcp::socket inputDev; |
| 26 | int fd; |
| 27 | }; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 28 | |
| 29 | class RedundancySensor |
| 30 | { |
| 31 | public: |
| 32 | RedundancySensor(size_t count, const std::vector<std::string> &children, |
| 33 | sdbusplus::asio::object_server &objectServer); |
| 34 | ~RedundancySensor(); |
| 35 | |
| 36 | void update(const std::string &name, bool failed); |
| 37 | |
| 38 | private: |
| 39 | size_t count; |
| 40 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface; |
| 41 | sdbusplus::asio::object_server &objectServer; |
| 42 | boost::container::flat_map<std::string, bool> statuses; |
| 43 | }; |
| 44 | |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 45 | class TachSensor : public Sensor |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 46 | { |
| 47 | public: |
James Feist | ce3fca4 | 2018-11-21 12:58:24 -0800 | [diff] [blame] | 48 | TachSensor(const std::string &path, const std::string &objectType, |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 49 | sdbusplus::asio::object_server &objectServer, |
| 50 | std::shared_ptr<sdbusplus::asio::connection> &conn, |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 51 | std::unique_ptr<PresenceSensor> &&presence, |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 52 | const std::shared_ptr<RedundancySensor> &redundancy, |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 53 | boost::asio::io_service &io, const std::string &fanName, |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 54 | std::vector<thresholds::Threshold> &&thresholds, |
| 55 | const std::string &sensorConfiguration); |
| 56 | ~TachSensor(); |
| 57 | |
| 58 | private: |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 59 | sdbusplus::asio::object_server &objServer; |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 60 | std::shared_ptr<RedundancySensor> redundancy; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 61 | std::shared_ptr<sdbusplus::asio::connection> dbusConnection; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 62 | std::unique_ptr<PresenceSensor> presence; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 63 | boost::asio::posix::stream_descriptor inputDev; |
| 64 | boost::asio::deadline_timer waitTimer; |
| 65 | boost::asio::streambuf readBuf; |
| 66 | int errCount; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 67 | void setupRead(void); |
| 68 | void handleResponse(const boost::system::error_code &err); |
James Feist | ce3fca4 | 2018-11-21 12:58:24 -0800 | [diff] [blame] | 69 | void checkThresholds(void) override; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 70 | }; |