blob: e3b84cff8916edb9486a66f6f97543a6370ac225 [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 Lycebb28c2022-10-21 10:01:52 +000016 explicit ChassisIntrusionSensor(sdbusplus::asio::object_server& objServer);
Qiang XUe28d1fa2019-02-27 13:50:56 +080017
Chau Lycebb28c2022-10-21 10:01:52 +000018 virtual ~ChassisIntrusionSensor();
Qiang XUe28d1fa2019-02-27 13:50:56 +080019
Chau Lycebb28c2022-10-21 10:01:52 +000020 void start();
21
22 protected:
23 virtual int readSensor() = 0;
24 virtual void pollSensorStatus() = 0;
25 void updateValue(const size_t& value);
Qiang XUe28d1fa2019-02-27 13:50:56 +080026
27 private:
Qiang XUe28d1fa2019-02-27 13:50:56 +080028 // intrusion status. 0: not intruded, 1: intruded
29 std::string mValue = "unknown";
Matt Simmeringa7109572023-06-27 10:30:23 -070030 std::string mOldValue = "Normal";
Chau Lycebb28c2022-10-21 10:01:52 +000031 std::shared_ptr<sdbusplus::asio::dbus_interface> mIface;
32 sdbusplus::asio::object_server& mObjServer;
33 bool mOverridenState = false;
34 bool mInternalSet = false;
Qiang XUe28d1fa2019-02-27 13:50:56 +080035
Chau Lycebb28c2022-10-21 10:01:52 +000036 int setSensorValue(const std::string& req, std::string& propertyValue);
37};
38
39class 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 Tanousb429f312022-06-27 16:09:53 -070052 int mSlaveAddr{-1};
Ed Tanous9b4a20e2022-09-06 08:47:11 -070053 boost::asio::steady_timer mPollTimer;
Chau Lycebb28c2022-10-21 10:01:52 +000054 int readSensor() override;
55 void pollSensorStatus() override;
56};
Qiang XUe28d1fa2019-02-27 13:50:56 +080057
Chau Lycebb28c2022-10-21 10:01:52 +000058class 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 Tanousb429f312022-06-27 16:09:53 -070070 bool mGpioInverted{false};
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080071 std::string mPinName = "CHASSIS_INTRUSION";
72 gpiod::line mGpioLine;
73 boost::asio::posix::stream_descriptor mGpioFd;
Chau Lycebb28c2022-10-21 10:01:52 +000074 int readSensor() override;
75 void pollSensorStatus() override;
Qiang XUe28d1fa2019-02-27 13:50:56 +080076};
Chau Ly95f49932023-04-19 09:44:55 +000077
78class 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};