1*cae1866fSGeorge Liu #pragma once 2*cae1866fSGeorge Liu 3*cae1866fSGeorge Liu #include "libpldm/platform.h" 4*cae1866fSGeorge Liu 5*cae1866fSGeorge Liu #include "libpldmresponder/pdr_utils.hpp" 6*cae1866fSGeorge Liu #include "pldmd/dbus_impl_requester.hpp" 7*cae1866fSGeorge Liu 8*cae1866fSGeorge Liu #include <map> 9*cae1866fSGeorge Liu 10*cae1866fSGeorge Liu using namespace pldm::dbus_api; 11*cae1866fSGeorge Liu using namespace pldm::responder; 12*cae1866fSGeorge Liu 13*cae1866fSGeorge Liu namespace pldm 14*cae1866fSGeorge Liu { 15*cae1866fSGeorge Liu 16*cae1866fSGeorge Liu using SensorId = uint16_t; 17*cae1866fSGeorge Liu using DbusObjMaps = 18*cae1866fSGeorge Liu std::map<SensorId, 19*cae1866fSGeorge Liu std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>; 20*cae1866fSGeorge Liu using sensorEvent = 21*cae1866fSGeorge Liu std::function<void(SensorId sensorId, const DbusObjMaps& dbusMaps)>; 22*cae1866fSGeorge Liu 23*cae1866fSGeorge Liu namespace state_sensor 24*cae1866fSGeorge Liu { 25*cae1866fSGeorge Liu /** @class DbusToPLDMEvent 26*cae1866fSGeorge Liu * @brief This class can listen to the state sensor PDRs and send PLDM event 27*cae1866fSGeorge Liu * msg when a D-Bus property changes 28*cae1866fSGeorge Liu */ 29*cae1866fSGeorge Liu class DbusToPLDMEvent 30*cae1866fSGeorge Liu { 31*cae1866fSGeorge Liu public: 32*cae1866fSGeorge Liu DbusToPLDMEvent() = delete; 33*cae1866fSGeorge Liu DbusToPLDMEvent(const DbusToPLDMEvent&) = delete; 34*cae1866fSGeorge Liu DbusToPLDMEvent(DbusToPLDMEvent&&) = delete; 35*cae1866fSGeorge Liu DbusToPLDMEvent& operator=(const DbusToPLDMEvent&) = delete; 36*cae1866fSGeorge Liu DbusToPLDMEvent& operator=(DbusToPLDMEvent&&) = delete; 37*cae1866fSGeorge Liu ~DbusToPLDMEvent() = default; 38*cae1866fSGeorge Liu 39*cae1866fSGeorge Liu /** @brief Constructor 40*cae1866fSGeorge Liu * @param[in] mctp_fd - fd of MCTP communications socket 41*cae1866fSGeorge Liu * @param[in] mctp_eid - MCTP EID of host firmware 42*cae1866fSGeorge Liu * @param[in] requester - reference to Requester object 43*cae1866fSGeorge Liu */ 44*cae1866fSGeorge Liu explicit DbusToPLDMEvent(int mctp_fd, uint8_t mctp_eid, 45*cae1866fSGeorge Liu Requester& requester); 46*cae1866fSGeorge Liu 47*cae1866fSGeorge Liu public: 48*cae1866fSGeorge Liu /** @brief Listen all of the state sensor PDRs 49*cae1866fSGeorge Liu * @param[in] repo - pdr utils repo object 50*cae1866fSGeorge Liu * @param[in] dbusMaps - The map of D-Bus mapping and value 51*cae1866fSGeorge Liu */ 52*cae1866fSGeorge Liu void listenSensorEvent(const pdr_utils::Repo& repo, 53*cae1866fSGeorge Liu const DbusObjMaps& dbusMaps); 54*cae1866fSGeorge Liu 55*cae1866fSGeorge Liu private: 56*cae1866fSGeorge Liu /** @brief Send state sensor event msg when a D-Bus property changes 57*cae1866fSGeorge Liu * @param[in] sensorId - sensor id 58*cae1866fSGeorge Liu */ 59*cae1866fSGeorge Liu void sendStateSensorEvent(SensorId sensorId, const DbusObjMaps& dbusMaps); 60*cae1866fSGeorge Liu 61*cae1866fSGeorge Liu /** @brief Send all of sensor event 62*cae1866fSGeorge Liu * @param[in] eventType - PLDM Event types 63*cae1866fSGeorge Liu * @param[in] eventDataVec - std::vector, contains send event data 64*cae1866fSGeorge Liu */ 65*cae1866fSGeorge Liu void sendEventMsg(uint8_t eventType, 66*cae1866fSGeorge Liu const std::vector<uint8_t>& eventDataVec); 67*cae1866fSGeorge Liu 68*cae1866fSGeorge Liu /** @brief fd of MCTP communications socket */ 69*cae1866fSGeorge Liu int mctp_fd; 70*cae1866fSGeorge Liu 71*cae1866fSGeorge Liu /** @brief MCTP EID of host firmware */ 72*cae1866fSGeorge Liu uint8_t mctp_eid; 73*cae1866fSGeorge Liu 74*cae1866fSGeorge Liu /** @brief reference to Requester object, primarily used to access API to 75*cae1866fSGeorge Liu * obtain PLDM instance id. 76*cae1866fSGeorge Liu */ 77*cae1866fSGeorge Liu Requester& requester; 78*cae1866fSGeorge Liu 79*cae1866fSGeorge Liu /** @brief D-Bus property changed signal match */ 80*cae1866fSGeorge Liu std::vector<std::unique_ptr<sdbusplus::bus::match::match>> 81*cae1866fSGeorge Liu stateSensorMatchs; 82*cae1866fSGeorge Liu }; 83*cae1866fSGeorge Liu 84*cae1866fSGeorge Liu } // namespace state_sensor 85*cae1866fSGeorge Liu } // namespace pldm 86