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 | b318dca | 2022-10-26 04:12:52 +0000 | [diff] [blame^] | 16 | explicit ChassisIntrusionSensor(bool autoRearm, |
| 17 | sdbusplus::asio::object_server& objServer); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 18 | |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 19 | virtual ~ChassisIntrusionSensor(); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 20 | |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 21 | void start(); |
| 22 | |
| 23 | protected: |
| 24 | virtual int readSensor() = 0; |
| 25 | virtual void pollSensorStatus() = 0; |
| 26 | void updateValue(const size_t& value); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 27 | |
| 28 | private: |
Chau Ly | b318dca | 2022-10-26 04:12:52 +0000 | [diff] [blame^] | 29 | std::string mValue; |
| 30 | // If this sensor uses automatic rearm method. Otherwise, manually rearm it |
| 31 | bool mAutoRearm; |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 32 | std::shared_ptr<sdbusplus::asio::dbus_interface> mIface; |
| 33 | sdbusplus::asio::object_server& mObjServer; |
| 34 | bool mOverridenState = false; |
| 35 | bool mInternalSet = false; |
Chau Ly | b318dca | 2022-10-26 04:12:52 +0000 | [diff] [blame^] | 36 | bool mRearmFlag = false; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 37 | |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 38 | int setSensorValue(const std::string& req, std::string& propertyValue); |
| 39 | }; |
| 40 | |
| 41 | class ChassisIntrusionPchSensor : |
| 42 | public ChassisIntrusionSensor, |
| 43 | public std::enable_shared_from_this<ChassisIntrusionPchSensor> |
| 44 | { |
| 45 | public: |
Chau Ly | b318dca | 2022-10-26 04:12:52 +0000 | [diff] [blame^] | 46 | ChassisIntrusionPchSensor(bool autoRearm, boost::asio::io_context& io, |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 47 | sdbusplus::asio::object_server& objServer, |
| 48 | int busId, int slaveAddr); |
| 49 | |
| 50 | ~ChassisIntrusionPchSensor() override; |
| 51 | |
| 52 | private: |
| 53 | int mBusFd{-1}; |
Ed Tanous | b429f31 | 2022-06-27 16:09:53 -0700 | [diff] [blame] | 54 | int mSlaveAddr{-1}; |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 55 | boost::asio::steady_timer mPollTimer; |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 56 | int readSensor() override; |
| 57 | void pollSensorStatus() override; |
| 58 | }; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 59 | |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 60 | class ChassisIntrusionGpioSensor : |
| 61 | public ChassisIntrusionSensor, |
| 62 | public std::enable_shared_from_this<ChassisIntrusionGpioSensor> |
| 63 | { |
| 64 | public: |
Chau Ly | b318dca | 2022-10-26 04:12:52 +0000 | [diff] [blame^] | 65 | ChassisIntrusionGpioSensor(bool autoRearm, boost::asio::io_context& io, |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 66 | sdbusplus::asio::object_server& objServer, |
| 67 | bool gpioInverted); |
| 68 | |
| 69 | ~ChassisIntrusionGpioSensor() override; |
| 70 | |
| 71 | private: |
Ed Tanous | b429f31 | 2022-06-27 16:09:53 -0700 | [diff] [blame] | 72 | bool mGpioInverted{false}; |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 73 | std::string mPinName = "CHASSIS_INTRUSION"; |
| 74 | gpiod::line mGpioLine; |
| 75 | boost::asio::posix::stream_descriptor mGpioFd; |
Chau Ly | cebb28c | 2022-10-21 10:01:52 +0000 | [diff] [blame] | 76 | int readSensor() override; |
| 77 | void pollSensorStatus() override; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 78 | }; |
Chau Ly | 95f4993 | 2023-04-19 09:44:55 +0000 | [diff] [blame] | 79 | |
| 80 | class ChassisIntrusionHwmonSensor : |
| 81 | public ChassisIntrusionSensor, |
| 82 | public std::enable_shared_from_this<ChassisIntrusionHwmonSensor> |
| 83 | { |
| 84 | public: |
Chau Ly | b318dca | 2022-10-26 04:12:52 +0000 | [diff] [blame^] | 85 | ChassisIntrusionHwmonSensor(bool autoRearm, boost::asio::io_context& io, |
Chau Ly | 95f4993 | 2023-04-19 09:44:55 +0000 | [diff] [blame] | 86 | sdbusplus::asio::object_server& objServer, |
| 87 | std::string hwmonName); |
| 88 | |
| 89 | ~ChassisIntrusionHwmonSensor() override; |
| 90 | |
| 91 | private: |
| 92 | std::string mHwmonName; |
| 93 | std::string mHwmonPath; |
| 94 | boost::asio::steady_timer mPollTimer; |
| 95 | int readSensor() override; |
| 96 | void pollSensorStatus() override; |
| 97 | }; |