blob: 8ab1083ba6cc9f8bf3a5972aa3b628d8e9b59150 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
2
Patrick Ventureca44b2f2019-10-31 11:02:26 -07003#include "Thresholds.hpp"
4#include "sensor.hpp"
5
James Feist7b18b1e2019-05-14 13:42:09 -07006#include <systemd/sd-journal.h>
7
James Feistdc6c55f2018-10-31 12:53:20 -07008#include <boost/container/flat_map.hpp>
9#include <boost/container/flat_set.hpp>
James Feist6714a252018-09-10 15:26:18 -070010#include <sdbusplus/asio/object_server.hpp>
11
James Feist7bc2bab2018-10-26 14:09:45 -070012class PresenceSensor
13{
14
15 public:
16 PresenceSensor(const size_t index, bool inverted,
James Feist7b18b1e2019-05-14 13:42:09 -070017 boost::asio::io_service& io, const std::string& name);
James Feist7bc2bab2018-10-26 14:09:45 -070018 ~PresenceSensor();
19
20 void monitorPresence(void);
21 void read(void);
22 bool getValue(void);
23
24 private:
25 bool status = true;
26 bool inverted;
27 boost::asio::ip::tcp::socket inputDev;
28 int fd;
James Feist7b18b1e2019-05-14 13:42:09 -070029 std::string name;
James Feist7bc2bab2018-10-26 14:09:45 -070030};
James Feistdc6c55f2018-10-31 12:53:20 -070031
James Feist7b18b1e2019-05-14 13:42:09 -070032namespace redundancy
33{
34constexpr const char* full = "Full";
35constexpr const char* degraded = "Degraded";
36constexpr const char* failed = "Failed";
37} // namespace redundancy
38
James Feistdc6c55f2018-10-31 12:53:20 -070039class RedundancySensor
40{
41 public:
James Feistd8705872019-02-08 13:26:09 -080042 RedundancySensor(size_t count, const std::vector<std::string>& children,
James Feist9bb67462019-03-15 15:09:50 -070043 sdbusplus::asio::object_server& objectServer,
44 const std::string& sensorConfiguration);
James Feistdc6c55f2018-10-31 12:53:20 -070045 ~RedundancySensor();
46
James Feistd8705872019-02-08 13:26:09 -080047 void update(const std::string& name, bool failed);
James Feistdc6c55f2018-10-31 12:53:20 -070048
49 private:
50 size_t count;
James Feist7b18b1e2019-05-14 13:42:09 -070051 std::string state = redundancy::full;
James Feistdc6c55f2018-10-31 12:53:20 -070052 std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
James Feist9bb67462019-03-15 15:09:50 -070053 std::shared_ptr<sdbusplus::asio::dbus_interface> association;
James Feistd8705872019-02-08 13:26:09 -080054 sdbusplus::asio::object_server& objectServer;
James Feistdc6c55f2018-10-31 12:53:20 -070055 boost::container::flat_map<std::string, bool> statuses;
56};
57
James Feist251c7822018-09-12 12:54:15 -070058class TachSensor : public Sensor
James Feist6714a252018-09-10 15:26:18 -070059{
60 public:
James Feistd8705872019-02-08 13:26:09 -080061 TachSensor(const std::string& path, const std::string& objectType,
62 sdbusplus::asio::object_server& objectServer,
63 std::shared_ptr<sdbusplus::asio::connection>& conn,
64 std::unique_ptr<PresenceSensor>&& presence,
James Feist7b18b1e2019-05-14 13:42:09 -070065 std::optional<RedundancySensor>* redundancy,
James Feistd8705872019-02-08 13:26:09 -080066 boost::asio::io_service& io, const std::string& fanName,
67 std::vector<thresholds::Threshold>&& thresholds,
68 const std::string& sensorConfiguration,
69 const std::pair<size_t, size_t>& limits);
James Feist6714a252018-09-10 15:26:18 -070070 ~TachSensor();
71
72 private:
James Feistd8705872019-02-08 13:26:09 -080073 sdbusplus::asio::object_server& objServer;
James Feist7b18b1e2019-05-14 13:42:09 -070074 std::optional<RedundancySensor>* redundancy;
James Feist7bc2bab2018-10-26 14:09:45 -070075 std::unique_ptr<PresenceSensor> presence;
James Feist60c0ec72019-03-18 15:08:43 -070076 std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface;
James Feistd8bd5622019-06-26 12:09:05 -070077 std::shared_ptr<sdbusplus::asio::dbus_interface> itemAssoc;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070078 boost::asio::posix::stream_descriptor inputDev;
79 boost::asio::deadline_timer waitTimer;
80 boost::asio::streambuf readBuf;
James Feist930fcde2019-05-28 12:58:43 -070081 std::string path;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070082 int errCount;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070083 void setupRead(void);
James Feistd8705872019-02-08 13:26:09 -080084 void handleResponse(const boost::system::error_code& err);
James Feistce3fca42018-11-21 12:58:24 -080085 void checkThresholds(void) override;
James Feist6714a252018-09-10 15:26:18 -070086};
James Feist7b18b1e2019-05-14 13:42:09 -070087
88inline void logFanInserted(const std::string& device)
89{
90
91 sd_journal_send("MESSAGE=%s", "Fan Inserted", "PRIORITY=%i", LOG_ERR,
92 "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanInserted",
93 "REDFISH_MESSAGE_ARGS=%s", device.c_str(), NULL);
94}
95
96inline void logFanRemoved(const std::string& device)
97{
98
99 sd_journal_send("MESSAGE=%s", "Fan Removed", "PRIORITY=%i", LOG_ERR,
100 "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanRemoved",
101 "REDFISH_MESSAGE_ARGS=%s", device.c_str(), NULL);
102}
103
104inline void logFanRedundancyLost(void)
105{
106
107 sd_journal_send("MESSAGE=%s", "Fan Inserted", "PRIORITY=%i", LOG_ERR,
108 "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanRedundancyLost",
109 NULL);
110}
111
112inline void logFanRedundancyRestored(void)
113{
114
115 sd_journal_send("MESSAGE=%s", "Fan Removed", "PRIORITY=%i", LOG_ERR,
116 "REDFISH_MESSAGE_ID=%s",
117 "OpenBMC.0.1.FanRedundancyRegained", NULL);
118}