#pragma once #include #include #include #include #include #include namespace fs = std::filesystem; class ChassisIntrusionSensor { public: explicit ChassisIntrusionSensor(bool autoRearm, sdbusplus::asio::object_server& objServer); virtual ~ChassisIntrusionSensor(); void start(); protected: virtual int readSensor() = 0; virtual void pollSensorStatus() = 0; void updateValue(const size_t& value); private: std::string mValue; // If this sensor uses automatic rearm method. Otherwise, manually rearm it bool mAutoRearm; std::shared_ptr mIface; sdbusplus::asio::object_server& mObjServer; bool mOverridenState = false; bool mInternalSet = false; bool mRearmFlag = false; int setSensorValue(const std::string& req, std::string& propertyValue); }; class ChassisIntrusionPchSensor : public ChassisIntrusionSensor, public std::enable_shared_from_this { public: ChassisIntrusionPchSensor(bool autoRearm, boost::asio::io_context& io, sdbusplus::asio::object_server& objServer, int busId, int slaveAddr); ~ChassisIntrusionPchSensor() override; private: int mBusFd{-1}; int mSlaveAddr{-1}; boost::asio::steady_timer mPollTimer; int readSensor() override; void pollSensorStatus() override; }; class ChassisIntrusionGpioSensor : public ChassisIntrusionSensor, public std::enable_shared_from_this { public: ChassisIntrusionGpioSensor(bool autoRearm, boost::asio::io_context& io, sdbusplus::asio::object_server& objServer, bool gpioInverted); ~ChassisIntrusionGpioSensor() override; private: bool mGpioInverted{false}; std::string mPinName = "CHASSIS_INTRUSION"; gpiod::line mGpioLine; boost::asio::posix::stream_descriptor mGpioFd; int readSensor() override; void pollSensorStatus() override; }; class ChassisIntrusionHwmonSensor : public ChassisIntrusionSensor, public std::enable_shared_from_this { public: ChassisIntrusionHwmonSensor(bool autoRearm, boost::asio::io_context& io, sdbusplus::asio::object_server& objServer, std::string hwmonName); ~ChassisIntrusionHwmonSensor() override; private: std::string mHwmonName; std::string mHwmonPath; boost::asio::steady_timer mPollTimer; int readSensor() override; void pollSensorStatus() override; };