Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 3 | #include <boost/asio/io_context.hpp> |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 4 | #include <boost/asio/steady_timer.hpp> |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 5 | #include <gpiod.hpp> |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 6 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 9 | #include <string> |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 10 | |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 11 | namespace fs = std::filesystem; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 12 | |
| 13 | class ChassisIntrusionSensor |
| 14 | { |
| 15 | public: |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 16 | explicit ChassisIntrusionSensor(sdbusplus::asio::object_server& objServer); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 17 | |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 18 | virtual ~ChassisIntrusionSensor(); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 19 | |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 20 | void start(); |
| 21 | |
| 22 | protected: |
| 23 | virtual int readSensor() = 0; |
| 24 | virtual void pollSensorStatus() = 0; |
| 25 | void updateValue(const size_t& value); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 26 | |
| 27 | private: |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 28 | // intrusion status. 0: not intruded, 1: intruded |
| 29 | std::string mValue = "unknown"; |
Matt Simmering | a710957 | 2023-06-27 10:30:23 -0700 | [diff] [blame] | 30 | std::string mOldValue = "Normal"; |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 31 | std::shared_ptr<sdbusplus::asio::dbus_interface> mIface; |
| 32 | sdbusplus::asio::object_server& mObjServer; |
| 33 | bool mOverridenState = false; |
| 34 | bool mInternalSet = false; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 35 | |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 36 | int setSensorValue(const std::string& req, std::string& propertyValue); |
| 37 | }; |
| 38 | |
| 39 | class ChassisIntrusionPchSensor : |
| 40 | public ChassisIntrusionSensor, |
| 41 | public std::enable_shared_from_this<ChassisIntrusionPchSensor> |
| 42 | { |
| 43 | public: |
| 44 | ChassisIntrusionPchSensor(boost::asio::io_context& io, |
| 45 | sdbusplus::asio::object_server& objServer, |
| 46 | int busId, int slaveAddr); |
| 47 | |
| 48 | ~ChassisIntrusionPchSensor() override; |
| 49 | |
| 50 | private: |
| 51 | int mBusFd{-1}; |
Ed Tanous | b429f31 | 2022-06-27 16:09:53 -0700 | [diff] [blame] | 52 | int mSlaveAddr{-1}; |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 53 | boost::asio::steady_timer mPollTimer; |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 54 | int readSensor() override; |
| 55 | void pollSensorStatus() override; |
| 56 | }; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 57 | |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 58 | class ChassisIntrusionGpioSensor : |
| 59 | public ChassisIntrusionSensor, |
| 60 | public std::enable_shared_from_this<ChassisIntrusionGpioSensor> |
| 61 | { |
| 62 | public: |
| 63 | ChassisIntrusionGpioSensor(boost::asio::io_context& io, |
| 64 | sdbusplus::asio::object_server& objServer, |
| 65 | bool gpioInverted); |
| 66 | |
| 67 | ~ChassisIntrusionGpioSensor() override; |
| 68 | |
| 69 | private: |
Ed Tanous | b429f31 | 2022-06-27 16:09:53 -0700 | [diff] [blame] | 70 | bool mGpioInverted{false}; |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 71 | std::string mPinName = "CHASSIS_INTRUSION"; |
| 72 | gpiod::line mGpioLine; |
| 73 | boost::asio::posix::stream_descriptor mGpioFd; |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 74 | int readSensor() override; |
| 75 | void pollSensorStatus() override; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 76 | }; |
Chau Ly | 95f4993 | 2023-04-19 09:44:55 +0000 | [diff] [blame] | 77 | |
| 78 | class ChassisIntrusionHwmonSensor : |
| 79 | public ChassisIntrusionSensor, |
| 80 | public std::enable_shared_from_this<ChassisIntrusionHwmonSensor> |
| 81 | { |
| 82 | public: |
| 83 | ChassisIntrusionHwmonSensor(boost::asio::io_context& io, |
| 84 | sdbusplus::asio::object_server& objServer, |
| 85 | std::string hwmonName); |
| 86 | |
| 87 | ~ChassisIntrusionHwmonSensor() override; |
| 88 | |
| 89 | private: |
| 90 | std::string mHwmonName; |
| 91 | std::string mHwmonPath; |
| 92 | boost::asio::steady_timer mPollTimer; |
| 93 | int readSensor() override; |
| 94 | void pollSensorStatus() override; |
| 95 | }; |