blob: c6f255ff55b4b8ff8f3b945d44c2d13f2987e5c9 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
2
3#include <Thresholds.hpp>
James Feistdc6c55f2018-10-31 12:53:20 -07004#include <boost/container/flat_map.hpp>
5#include <boost/container/flat_set.hpp>
James Feist6714a252018-09-10 15:26:18 -07006#include <sdbusplus/asio/object_server.hpp>
James Feist251c7822018-09-12 12:54:15 -07007#include <sensor.hpp>
James Feist6714a252018-09-10 15:26:18 -07008
James Feistd8705872019-02-08 13:26:09 -08009constexpr const char* gpioPath = "/sys/class/gpio/";
James Feist7bc2bab2018-10-26 14:09:45 -070010class PresenceSensor
11{
12
13 public:
14 PresenceSensor(const size_t index, bool inverted,
James Feistd8705872019-02-08 13:26:09 -080015 boost::asio::io_service& io);
James Feist7bc2bab2018-10-26 14:09:45 -070016 ~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 Feistdc6c55f2018-10-31 12:53:20 -070028
29class RedundancySensor
30{
31 public:
James Feistd8705872019-02-08 13:26:09 -080032 RedundancySensor(size_t count, const std::vector<std::string>& children,
James Feist9bb67462019-03-15 15:09:50 -070033 sdbusplus::asio::object_server& objectServer,
34 const std::string& sensorConfiguration);
James Feistdc6c55f2018-10-31 12:53:20 -070035 ~RedundancySensor();
36
James Feistd8705872019-02-08 13:26:09 -080037 void update(const std::string& name, bool failed);
James Feistdc6c55f2018-10-31 12:53:20 -070038
39 private:
40 size_t count;
41 std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
James Feist9bb67462019-03-15 15:09:50 -070042 std::shared_ptr<sdbusplus::asio::dbus_interface> association;
James Feistd8705872019-02-08 13:26:09 -080043 sdbusplus::asio::object_server& objectServer;
James Feistdc6c55f2018-10-31 12:53:20 -070044 boost::container::flat_map<std::string, bool> statuses;
45};
46
James Feist251c7822018-09-12 12:54:15 -070047class TachSensor : public Sensor
James Feist6714a252018-09-10 15:26:18 -070048{
49 public:
James Feistd8705872019-02-08 13:26:09 -080050 TachSensor(const std::string& path, const std::string& objectType,
51 sdbusplus::asio::object_server& objectServer,
52 std::shared_ptr<sdbusplus::asio::connection>& conn,
53 std::unique_ptr<PresenceSensor>&& presence,
54 const std::shared_ptr<RedundancySensor>& redundancy,
55 boost::asio::io_service& io, const std::string& fanName,
56 std::vector<thresholds::Threshold>&& thresholds,
57 const std::string& sensorConfiguration,
58 const std::pair<size_t, size_t>& limits);
James Feist6714a252018-09-10 15:26:18 -070059 ~TachSensor();
60
61 private:
James Feistd8705872019-02-08 13:26:09 -080062 sdbusplus::asio::object_server& objServer;
James Feist95b079b2018-11-21 09:28:00 -080063 std::shared_ptr<RedundancySensor> redundancy;
James Feist7bc2bab2018-10-26 14:09:45 -070064 std::unique_ptr<PresenceSensor> presence;
James Feist60c0ec72019-03-18 15:08:43 -070065 std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070066 boost::asio::posix::stream_descriptor inputDev;
67 boost::asio::deadline_timer waitTimer;
68 boost::asio::streambuf readBuf;
69 int errCount;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070070 void setupRead(void);
James Feistd8705872019-02-08 13:26:09 -080071 void handleResponse(const boost::system::error_code& err);
James Feistce3fca42018-11-21 12:58:24 -080072 void checkThresholds(void) override;
James Feist6714a252018-09-10 15:26:18 -070073};