blob: 36e3eaaed1061cf77ecf2f197e41b63cfe9a383e [file] [log] [blame]
James Feist139cb572018-09-10 15:26:18 -07001#pragma once
2
3#include <Thresholds.hpp>
James Feist39132a62018-10-31 12:53:20 -07004#include <boost/container/flat_map.hpp>
5#include <boost/container/flat_set.hpp>
James Feist139cb572018-09-10 15:26:18 -07006#include <sdbusplus/asio/object_server.hpp>
James Feistaf79dd32018-09-12 12:54:15 -07007#include <sensor.hpp>
James Feist139cb572018-09-10 15:26:18 -07008
James Feist7c391352018-10-26 14:09:45 -07009constexpr const char *gpioPath = "/sys/class/gpio/";
10class 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 Feist39132a62018-10-31 12:53:20 -070028
29class 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 Feistaf79dd32018-09-12 12:54:15 -070045class TachSensor : public Sensor
James Feist139cb572018-09-10 15:26:18 -070046{
47 public:
James Feist139cb572018-09-10 15:26:18 -070048 std::string configuration;
49 TachSensor(const std::string &path,
50 sdbusplus::asio::object_server &objectServer,
51 std::shared_ptr<sdbusplus::asio::connection> &conn,
James Feist7c391352018-10-26 14:09:45 -070052 std::unique_ptr<PresenceSensor> &&presence,
James Feist39132a62018-10-31 12:53:20 -070053 std::unique_ptr<RedundancySensor> &redundancy,
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070054 boost::asio::io_service &io, const std::string &fanName,
James Feist139cb572018-09-10 15:26:18 -070055 std::vector<thresholds::Threshold> &&thresholds,
56 const std::string &sensorConfiguration);
57 ~TachSensor();
58
59 private:
James Feist139cb572018-09-10 15:26:18 -070060 sdbusplus::asio::object_server &objServer;
James Feist39132a62018-10-31 12:53:20 -070061 std::unique_ptr<RedundancySensor> &redundancy;
James Feist139cb572018-09-10 15:26:18 -070062 std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
James Feist7c391352018-10-26 14:09:45 -070063 std::unique_ptr<PresenceSensor> presence;
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070064 boost::asio::posix::stream_descriptor inputDev;
65 boost::asio::deadline_timer waitTimer;
66 boost::asio::streambuf readBuf;
67 int errCount;
68 double maxValue;
69 double minValue;
70 void setupRead(void);
71 void handleResponse(const boost::system::error_code &err);
72 void checkThresholds(void);
73 void updateValue(const double &newValue);
James Feistaf79dd32018-09-12 12:54:15 -070074
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070075 void setInitialProperties(
James Feist139cb572018-09-10 15:26:18 -070076 std::shared_ptr<sdbusplus::asio::connection> &conn);
77};