blob: d22eaf8f7dadffd5a59d30bda3d09012c6db290a [file] [log] [blame]
#pragma once
#include <boost/asio/io_context.hpp>
#include <boost/asio/steady_timer.hpp>
#include <gpiod.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <memory>
#include <string>
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<sdbusplus::asio::dbus_interface> 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<ChassisIntrusionPchSensor>
{
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<ChassisIntrusionGpioSensor>
{
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<ChassisIntrusionHwmonSensor>
{
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;
};