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