James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 3 | #include <systemd/sd-journal.h> |
| 4 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 5 | #include <Thresholds.hpp> |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 6 | #include <boost/container/flat_map.hpp> |
| 7 | #include <boost/container/flat_set.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 8 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 9 | #include <sensor.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 10 | |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 11 | class PresenceSensor |
| 12 | { |
| 13 | |
| 14 | public: |
| 15 | PresenceSensor(const size_t index, bool inverted, |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 16 | boost::asio::io_service& io, const std::string& name); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 17 | ~PresenceSensor(); |
| 18 | |
| 19 | void monitorPresence(void); |
| 20 | void read(void); |
| 21 | bool getValue(void); |
| 22 | |
| 23 | private: |
| 24 | bool status = true; |
| 25 | bool inverted; |
| 26 | boost::asio::ip::tcp::socket inputDev; |
| 27 | int fd; |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 28 | std::string name; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 29 | }; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 30 | |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 31 | namespace redundancy |
| 32 | { |
| 33 | constexpr const char* full = "Full"; |
| 34 | constexpr const char* degraded = "Degraded"; |
| 35 | constexpr const char* failed = "Failed"; |
| 36 | } // namespace redundancy |
| 37 | |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 38 | class RedundancySensor |
| 39 | { |
| 40 | public: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 41 | RedundancySensor(size_t count, const std::vector<std::string>& children, |
James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 42 | sdbusplus::asio::object_server& objectServer, |
| 43 | const std::string& sensorConfiguration); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 44 | ~RedundancySensor(); |
| 45 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 46 | void update(const std::string& name, bool failed); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | size_t count; |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 50 | std::string state = redundancy::full; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 51 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface; |
James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 52 | std::shared_ptr<sdbusplus::asio::dbus_interface> association; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 53 | sdbusplus::asio::object_server& objectServer; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 54 | boost::container::flat_map<std::string, bool> statuses; |
| 55 | }; |
| 56 | |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 57 | class TachSensor : public Sensor |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 58 | { |
| 59 | public: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 60 | TachSensor(const std::string& path, const std::string& objectType, |
| 61 | sdbusplus::asio::object_server& objectServer, |
| 62 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 63 | std::unique_ptr<PresenceSensor>&& presence, |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 64 | std::optional<RedundancySensor>* redundancy, |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 65 | boost::asio::io_service& io, const std::string& fanName, |
| 66 | std::vector<thresholds::Threshold>&& thresholds, |
| 67 | const std::string& sensorConfiguration, |
| 68 | const std::pair<size_t, size_t>& limits); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 69 | ~TachSensor(); |
| 70 | |
| 71 | private: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 72 | sdbusplus::asio::object_server& objServer; |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 73 | std::optional<RedundancySensor>* redundancy; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 74 | std::unique_ptr<PresenceSensor> presence; |
James Feist | 60c0ec7 | 2019-03-18 15:08:43 -0700 | [diff] [blame] | 75 | std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface; |
James Feist | d8bd562 | 2019-06-26 12:09:05 -0700 | [diff] [blame^] | 76 | std::shared_ptr<sdbusplus::asio::dbus_interface> itemAssoc; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 77 | boost::asio::posix::stream_descriptor inputDev; |
| 78 | boost::asio::deadline_timer waitTimer; |
| 79 | boost::asio::streambuf readBuf; |
James Feist | 930fcde | 2019-05-28 12:58:43 -0700 | [diff] [blame] | 80 | std::string path; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 81 | int errCount; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 82 | void setupRead(void); |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 83 | void handleResponse(const boost::system::error_code& err); |
James Feist | ce3fca4 | 2018-11-21 12:58:24 -0800 | [diff] [blame] | 84 | void checkThresholds(void) override; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 85 | }; |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 86 | |
| 87 | inline void logFanInserted(const std::string& device) |
| 88 | { |
| 89 | |
| 90 | sd_journal_send("MESSAGE=%s", "Fan Inserted", "PRIORITY=%i", LOG_ERR, |
| 91 | "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanInserted", |
| 92 | "REDFISH_MESSAGE_ARGS=%s", device.c_str(), NULL); |
| 93 | } |
| 94 | |
| 95 | inline void logFanRemoved(const std::string& device) |
| 96 | { |
| 97 | |
| 98 | sd_journal_send("MESSAGE=%s", "Fan Removed", "PRIORITY=%i", LOG_ERR, |
| 99 | "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanRemoved", |
| 100 | "REDFISH_MESSAGE_ARGS=%s", device.c_str(), NULL); |
| 101 | } |
| 102 | |
| 103 | inline void logFanRedundancyLost(void) |
| 104 | { |
| 105 | |
| 106 | sd_journal_send("MESSAGE=%s", "Fan Inserted", "PRIORITY=%i", LOG_ERR, |
| 107 | "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanRedundancyLost", |
| 108 | NULL); |
| 109 | } |
| 110 | |
| 111 | inline void logFanRedundancyRestored(void) |
| 112 | { |
| 113 | |
| 114 | sd_journal_send("MESSAGE=%s", "Fan Removed", "PRIORITY=%i", LOG_ERR, |
| 115 | "REDFISH_MESSAGE_ID=%s", |
| 116 | "OpenBMC.0.1.FanRedundancyRegained", NULL); |
| 117 | } |