blob: f79fb4d90c416cf1f4c4032f675a58c9107ddb40 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
2
James Feist7b18b1e2019-05-14 13:42:09 -07003#include <systemd/sd-journal.h>
4
James Feist6714a252018-09-10 15:26:18 -07005#include <Thresholds.hpp>
James Feistdc6c55f2018-10-31 12:53:20 -07006#include <boost/container/flat_map.hpp>
7#include <boost/container/flat_set.hpp>
James Feist6714a252018-09-10 15:26:18 -07008#include <sdbusplus/asio/object_server.hpp>
James Feist251c7822018-09-12 12:54:15 -07009#include <sensor.hpp>
James Feist6714a252018-09-10 15:26:18 -070010
James Feist7bc2bab2018-10-26 14:09:45 -070011class PresenceSensor
12{
13
14 public:
15 PresenceSensor(const size_t index, bool inverted,
James Feist7b18b1e2019-05-14 13:42:09 -070016 boost::asio::io_service& io, const std::string& name);
James Feist7bc2bab2018-10-26 14:09:45 -070017 ~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 Feist7b18b1e2019-05-14 13:42:09 -070028 std::string name;
James Feist7bc2bab2018-10-26 14:09:45 -070029};
James Feistdc6c55f2018-10-31 12:53:20 -070030
James Feist7b18b1e2019-05-14 13:42:09 -070031namespace redundancy
32{
33constexpr const char* full = "Full";
34constexpr const char* degraded = "Degraded";
35constexpr const char* failed = "Failed";
36} // namespace redundancy
37
James Feistdc6c55f2018-10-31 12:53:20 -070038class RedundancySensor
39{
40 public:
James Feistd8705872019-02-08 13:26:09 -080041 RedundancySensor(size_t count, const std::vector<std::string>& children,
James Feist9bb67462019-03-15 15:09:50 -070042 sdbusplus::asio::object_server& objectServer,
43 const std::string& sensorConfiguration);
James Feistdc6c55f2018-10-31 12:53:20 -070044 ~RedundancySensor();
45
James Feistd8705872019-02-08 13:26:09 -080046 void update(const std::string& name, bool failed);
James Feistdc6c55f2018-10-31 12:53:20 -070047
48 private:
49 size_t count;
James Feist7b18b1e2019-05-14 13:42:09 -070050 std::string state = redundancy::full;
James Feistdc6c55f2018-10-31 12:53:20 -070051 std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
James Feist9bb67462019-03-15 15:09:50 -070052 std::shared_ptr<sdbusplus::asio::dbus_interface> association;
James Feistd8705872019-02-08 13:26:09 -080053 sdbusplus::asio::object_server& objectServer;
James Feistdc6c55f2018-10-31 12:53:20 -070054 boost::container::flat_map<std::string, bool> statuses;
55};
56
James Feist251c7822018-09-12 12:54:15 -070057class TachSensor : public Sensor
James Feist6714a252018-09-10 15:26:18 -070058{
59 public:
James Feistd8705872019-02-08 13:26:09 -080060 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 Feist7b18b1e2019-05-14 13:42:09 -070064 std::optional<RedundancySensor>* redundancy,
James Feistd8705872019-02-08 13:26:09 -080065 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 Feist6714a252018-09-10 15:26:18 -070069 ~TachSensor();
70
71 private:
James Feistd8705872019-02-08 13:26:09 -080072 sdbusplus::asio::object_server& objServer;
James Feist7b18b1e2019-05-14 13:42:09 -070073 std::optional<RedundancySensor>* redundancy;
James Feist7bc2bab2018-10-26 14:09:45 -070074 std::unique_ptr<PresenceSensor> presence;
James Feist60c0ec72019-03-18 15:08:43 -070075 std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface;
James Feistd8bd5622019-06-26 12:09:05 -070076 std::shared_ptr<sdbusplus::asio::dbus_interface> itemAssoc;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070077 boost::asio::posix::stream_descriptor inputDev;
78 boost::asio::deadline_timer waitTimer;
79 boost::asio::streambuf readBuf;
James Feist930fcde2019-05-28 12:58:43 -070080 std::string path;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070081 int errCount;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070082 void setupRead(void);
James Feistd8705872019-02-08 13:26:09 -080083 void handleResponse(const boost::system::error_code& err);
James Feistce3fca42018-11-21 12:58:24 -080084 void checkThresholds(void) override;
James Feist6714a252018-09-10 15:26:18 -070085};
James Feist7b18b1e2019-05-14 13:42:09 -070086
87inline 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
95inline 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
103inline 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
111inline 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}