blob: d22eaf8f7dadffd5a59d30bda3d09012c6db290a [file] [log] [blame]
Qiang XUe28d1fa2019-02-27 13:50:56 +08001#pragma once
2
Ed Tanous1f978632023-02-28 18:16:39 -08003#include <boost/asio/io_context.hpp>
Ed Tanous9b4a20e2022-09-06 08:47:11 -07004#include <boost/asio/steady_timer.hpp>
ZhikuiRenba8a8bf2020-01-09 15:55:43 -08005#include <gpiod.hpp>
Qiang XUe28d1fa2019-02-27 13:50:56 +08006#include <sdbusplus/asio/object_server.hpp>
James Feist38fb5982020-05-28 10:09:54 -07007
8#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -07009#include <string>
Qiang XUe28d1fa2019-02-27 13:50:56 +080010
Chau Lycebb28c2022-10-21 10:01:52 +000011namespace fs = std::filesystem;
Qiang XUe28d1fa2019-02-27 13:50:56 +080012
13class ChassisIntrusionSensor
14{
15 public:
Chau Lyb318dca2022-10-26 04:12:52 +000016 explicit ChassisIntrusionSensor(bool autoRearm,
17 sdbusplus::asio::object_server& objServer);
Qiang XUe28d1fa2019-02-27 13:50:56 +080018
Chau Lycebb28c2022-10-21 10:01:52 +000019 virtual ~ChassisIntrusionSensor();
Qiang XUe28d1fa2019-02-27 13:50:56 +080020
Chau Lycebb28c2022-10-21 10:01:52 +000021 void start();
22
23 protected:
24 virtual int readSensor() = 0;
25 virtual void pollSensorStatus() = 0;
26 void updateValue(const size_t& value);
Qiang XUe28d1fa2019-02-27 13:50:56 +080027
28 private:
Chau Lyb318dca2022-10-26 04:12:52 +000029 std::string mValue;
30 // If this sensor uses automatic rearm method. Otherwise, manually rearm it
31 bool mAutoRearm;
Chau Lycebb28c2022-10-21 10:01:52 +000032 std::shared_ptr<sdbusplus::asio::dbus_interface> mIface;
33 sdbusplus::asio::object_server& mObjServer;
34 bool mOverridenState = false;
35 bool mInternalSet = false;
Chau Lyb318dca2022-10-26 04:12:52 +000036 bool mRearmFlag = false;
Qiang XUe28d1fa2019-02-27 13:50:56 +080037
Chau Lycebb28c2022-10-21 10:01:52 +000038 int setSensorValue(const std::string& req, std::string& propertyValue);
39};
40
41class ChassisIntrusionPchSensor :
42 public ChassisIntrusionSensor,
43 public std::enable_shared_from_this<ChassisIntrusionPchSensor>
44{
45 public:
Chau Lyb318dca2022-10-26 04:12:52 +000046 ChassisIntrusionPchSensor(bool autoRearm, boost::asio::io_context& io,
Chau Lycebb28c2022-10-21 10:01:52 +000047 sdbusplus::asio::object_server& objServer,
48 int busId, int slaveAddr);
49
50 ~ChassisIntrusionPchSensor() override;
51
52 private:
53 int mBusFd{-1};
Ed Tanousb429f312022-06-27 16:09:53 -070054 int mSlaveAddr{-1};
Ed Tanous9b4a20e2022-09-06 08:47:11 -070055 boost::asio::steady_timer mPollTimer;
Chau Lycebb28c2022-10-21 10:01:52 +000056 int readSensor() override;
57 void pollSensorStatus() override;
58};
Qiang XUe28d1fa2019-02-27 13:50:56 +080059
Chau Lycebb28c2022-10-21 10:01:52 +000060class ChassisIntrusionGpioSensor :
61 public ChassisIntrusionSensor,
62 public std::enable_shared_from_this<ChassisIntrusionGpioSensor>
63{
64 public:
Chau Lyb318dca2022-10-26 04:12:52 +000065 ChassisIntrusionGpioSensor(bool autoRearm, boost::asio::io_context& io,
Chau Lycebb28c2022-10-21 10:01:52 +000066 sdbusplus::asio::object_server& objServer,
67 bool gpioInverted);
68
69 ~ChassisIntrusionGpioSensor() override;
70
71 private:
Ed Tanousb429f312022-06-27 16:09:53 -070072 bool mGpioInverted{false};
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080073 std::string mPinName = "CHASSIS_INTRUSION";
74 gpiod::line mGpioLine;
75 boost::asio::posix::stream_descriptor mGpioFd;
Chau Lycebb28c2022-10-21 10:01:52 +000076 int readSensor() override;
77 void pollSensorStatus() override;
Qiang XUe28d1fa2019-02-27 13:50:56 +080078};
Chau Ly95f49932023-04-19 09:44:55 +000079
80class ChassisIntrusionHwmonSensor :
81 public ChassisIntrusionSensor,
82 public std::enable_shared_from_this<ChassisIntrusionHwmonSensor>
83{
84 public:
Chau Lyb318dca2022-10-26 04:12:52 +000085 ChassisIntrusionHwmonSensor(bool autoRearm, boost::asio::io_context& io,
Chau Ly95f49932023-04-19 09:44:55 +000086 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};