1*83929002SChris Cain #pragma once 2*83929002SChris Cain 3*83929002SChris Cain #include "sensor.hpp" 4*83929002SChris Cain 5*83929002SChris Cain #include <gpiod.hpp> 6*83929002SChris Cain #include <phosphor-logging/lg2.hpp> 7*83929002SChris Cain 8*83929002SChris Cain class PresenceGpio 9*83929002SChris Cain { 10*83929002SChris Cain public: PresenceGpio(const std::string & type,const std::string & name)11*83929002SChris Cain PresenceGpio(const std::string& type, const std::string& name) : 12*83929002SChris Cain deviceType(type), deviceName(name) {}; 13*83929002SChris Cain PresenceGpio(const PresenceGpio&) = delete; 14*83929002SChris Cain PresenceGpio& operator=(const PresenceGpio&) = delete; 15*83929002SChris Cain virtual ~PresenceGpio() = 0; 16*83929002SChris Cain isPresent() const17*83929002SChris Cain bool isPresent() const 18*83929002SChris Cain { 19*83929002SChris Cain return status; 20*83929002SChris Cain } 21*83929002SChris Cain 22*83929002SChris Cain protected: 23*83929002SChris Cain gpiod::line gpioLine; 24*83929002SChris Cain bool status = false; 25*83929002SChris Cain std::string deviceType; 26*83929002SChris Cain std::string deviceName; 27*83929002SChris Cain 28*83929002SChris Cain virtual void monitorPresence() = 0; 29*83929002SChris Cain logPresent(const std::string & device)30*83929002SChris Cain void logPresent(const std::string& device) 31*83929002SChris Cain { 32*83929002SChris Cain std::string summary = deviceType + " " + deviceName + " Inserted"; 33*83929002SChris Cain std::string msg = "OpenBMC.0.1." + deviceType + "Inserted"; 34*83929002SChris Cain lg2::info(summary.c_str(), "REDFISH_MESSAGE_ID", msg.c_str(), 35*83929002SChris Cain "REDFISH_MESSAGE_ARGS", device); 36*83929002SChris Cain } 37*83929002SChris Cain logRemoved(const std::string & device)38*83929002SChris Cain void logRemoved(const std::string& device) 39*83929002SChris Cain { 40*83929002SChris Cain std::string summary = deviceType + " " + deviceName + " Removed"; 41*83929002SChris Cain std::string msg = "OpenBMC.0.1." + deviceType + "Removed"; 42*83929002SChris Cain lg2::error(summary.c_str(), "REDFISH_MESSAGE_ID", msg.c_str(), 43*83929002SChris Cain "REDFISH_MESSAGE_ARGS", device); 44*83929002SChris Cain } 45*83929002SChris Cain 46*83929002SChris Cain void updateAndTracePresence(); 47*83929002SChris Cain }; 48*83929002SChris Cain 49*83929002SChris Cain class EventPresenceGpio : 50*83929002SChris Cain public PresenceGpio, 51*83929002SChris Cain public std::enable_shared_from_this<EventPresenceGpio> 52*83929002SChris Cain { 53*83929002SChris Cain public: 54*83929002SChris Cain EventPresenceGpio(const std::string& iDeviceType, 55*83929002SChris Cain const std::string& iDeviceName, 56*83929002SChris Cain const std::string& gpioName, bool inverted, 57*83929002SChris Cain boost::asio::io_context& io); 58*83929002SChris Cain 59*83929002SChris Cain private: 60*83929002SChris Cain boost::asio::posix::stream_descriptor gpioFd; 61*83929002SChris Cain 62*83929002SChris Cain void monitorPresence() override; 63*83929002SChris Cain void read(); 64*83929002SChris Cain }; 65