Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/asio/object_server.hpp> |
| 4 | |
| 5 | enum IntrusionSensorType |
| 6 | { |
| 7 | pch, |
| 8 | gpio |
| 9 | }; |
| 10 | |
| 11 | class 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 |
| 45 | std::string mOverriddenValue = "unknown"; |
| 46 | bool mOverridenState = false; |
| 47 | bool mInternalSet = false; |
| 48 | |
| 49 | bool mInitialized = false; |
| 50 | |
| 51 | void updateValue(const std::string newValue); |
| 52 | int i2cReadFromPch(int busId, int slaveAddr); |
| 53 | void pollSensorStatusByPch(); |
| 54 | void readGpio(); |
| 55 | void pollSensorStatusByGpio(); |
| 56 | void initGpioDeviceFile(const int index); |
| 57 | int setSensorValue(const std::string& req, std::string& propertyValue); |
| 58 | }; |