| Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 1 | #pragma once | 
|  | 2 |  | 
| Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 3 | #include <memory> | 
| Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 4 | #include <sdbusplus/asio/object_server.hpp> | 
| Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 5 | #include <string> | 
| Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 6 |  | 
|  | 7 | enum IntrusionSensorType | 
|  | 8 | { | 
|  | 9 | pch, | 
|  | 10 | gpio | 
|  | 11 | }; | 
|  | 12 |  | 
|  | 13 | class 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 XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 47 | 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 | }; |