blob: 651e768e41ab08cdbb41af76dde5a0bd23cfbe97 [file] [log] [blame]
Qiang XUe28d1fa2019-02-27 13:50:56 +08001#pragma once
2
Patrick Venturefd6ba732019-10-31 14:27:39 -07003#include <memory>
Qiang XUe28d1fa2019-02-27 13:50:56 +08004#include <sdbusplus/asio/object_server.hpp>
Patrick Venturefd6ba732019-10-31 14:27:39 -07005#include <string>
Qiang XUe28d1fa2019-02-27 13:50:56 +08006
7enum IntrusionSensorType
8{
9 pch,
10 gpio
11};
12
13class ChassisIntrusionSensor
14{
15 public:
16 ChassisIntrusionSensor(
17 boost::asio::io_service& io,
18 std::shared_ptr<sdbusplus::asio::dbus_interface> iface);
19
20 ~ChassisIntrusionSensor();
21
22 void start(IntrusionSensorType type, int busId, int slaveAddr,
23 int gpioIndex, bool gpioInverted);
24
25 private:
26 std::shared_ptr<sdbusplus::asio::dbus_interface> mIface;
27 std::shared_ptr<sdbusplus::asio::connection> mDbusConn;
28
29 IntrusionSensorType mType;
30
31 // intrusion status. 0: not intruded, 1: intruded
32 std::string mValue = "unknown";
33 std::string mOldValue = "unknown";
34
35 // valid if it is PCH register via i2c
36 int mBusId;
37 int mSlaveAddr;
38 boost::asio::deadline_timer mPollTimer;
39
40 // valid if it is via GPIO
41 int mGpioIndex;
42 bool mGpioInverted;
43 boost::asio::ip::tcp::socket mInputDev;
44 int mFd;
45
46 // common members
Qiang XUe28d1fa2019-02-27 13:50:56 +080047 bool mOverridenState = false;
48 bool mInternalSet = false;
49
50 bool mInitialized = false;
51
52 void updateValue(const std::string newValue);
53 int i2cReadFromPch(int busId, int slaveAddr);
54 void pollSensorStatusByPch();
55 void readGpio();
56 void pollSensorStatusByGpio();
57 void initGpioDeviceFile(const int index);
58 int setSensorValue(const std::string& req, std::string& propertyValue);
59};