1cae1866fSGeorge Liu #pragma once 2cae1866fSGeorge Liu 32abbce76SAndrew Jeffery #include "common/instance_id.hpp" 4cae1866fSGeorge Liu #include "libpldmresponder/pdr_utils.hpp" 5c0c79481SSampa Misra #include "requester/handler.hpp" 6cae1866fSGeorge Liu 7c453e164SGeorge Liu #include <libpldm/platform.h> 8c453e164SGeorge Liu 9cae1866fSGeorge Liu #include <map> 10cae1866fSGeorge Liu 11cae1866fSGeorge Liu namespace pldm 12cae1866fSGeorge Liu { 13cae1866fSGeorge Liu 14cae1866fSGeorge Liu using SensorId = uint16_t; 15cae1866fSGeorge Liu using DbusObjMaps = 165079ac4aSBrad Bishop std::map<SensorId, std::tuple<pldm::responder::pdr_utils::DbusMappings, 175079ac4aSBrad Bishop pldm::responder::pdr_utils::DbusValMaps>>; 18cae1866fSGeorge Liu using sensorEvent = 19cae1866fSGeorge Liu std::function<void(SensorId sensorId, const DbusObjMaps& dbusMaps)>; 20*ae933cc2SManojkiran Eda using stateSensorCacheMaps = 21*ae933cc2SManojkiran Eda std::map<pldm::pdr::SensorID, pldm::responder::pdr_utils::EventStates>; 22cae1866fSGeorge Liu 23cae1866fSGeorge Liu namespace state_sensor 24cae1866fSGeorge Liu { 25cae1866fSGeorge Liu /** @class DbusToPLDMEvent 26cae1866fSGeorge Liu * @brief This class can listen to the state sensor PDRs and send PLDM event 27cae1866fSGeorge Liu * msg when a D-Bus property changes 28cae1866fSGeorge Liu */ 29cae1866fSGeorge Liu class DbusToPLDMEvent 30cae1866fSGeorge Liu { 31cae1866fSGeorge Liu public: 32cae1866fSGeorge Liu DbusToPLDMEvent() = delete; 33cae1866fSGeorge Liu DbusToPLDMEvent(const DbusToPLDMEvent&) = delete; 34cae1866fSGeorge Liu DbusToPLDMEvent(DbusToPLDMEvent&&) = delete; 35cae1866fSGeorge Liu DbusToPLDMEvent& operator=(const DbusToPLDMEvent&) = delete; 36cae1866fSGeorge Liu DbusToPLDMEvent& operator=(DbusToPLDMEvent&&) = delete; 37cae1866fSGeorge Liu ~DbusToPLDMEvent() = default; 38cae1866fSGeorge Liu 39cae1866fSGeorge Liu /** @brief Constructor 40cae1866fSGeorge Liu * @param[in] mctp_fd - fd of MCTP communications socket 41cae1866fSGeorge Liu * @param[in] mctp_eid - MCTP EID of host firmware 42cae1866fSGeorge Liu * @param[in] requester - reference to Requester object 43c0c79481SSampa Misra * @param[in] handler - PLDM request handler 44cae1866fSGeorge Liu */ 45c0c79481SSampa Misra explicit DbusToPLDMEvent( 46a330b2f0SAndrew Jeffery int mctp_fd, uint8_t mctp_eid, pldm::InstanceIdDb& instanceIdDb, 47c0c79481SSampa Misra pldm::requester::Handler<pldm::requester::Request>* handler); 48cae1866fSGeorge Liu 49cae1866fSGeorge Liu public: 50cae1866fSGeorge Liu /** @brief Listen all of the state sensor PDRs 51cae1866fSGeorge Liu * @param[in] repo - pdr utils repo object 52cae1866fSGeorge Liu * @param[in] dbusMaps - The map of D-Bus mapping and value 53cae1866fSGeorge Liu */ 545079ac4aSBrad Bishop void listenSensorEvent(const pldm::responder::pdr_utils::Repo& repo, 55cae1866fSGeorge Liu const DbusObjMaps& dbusMaps); 56cae1866fSGeorge Liu 57*ae933cc2SManojkiran Eda /** @brief get the sensor state cache */ getSensorCache()58*ae933cc2SManojkiran Eda inline const stateSensorCacheMaps& getSensorCache() 59*ae933cc2SManojkiran Eda { 60*ae933cc2SManojkiran Eda return sensorCacheMap; 61*ae933cc2SManojkiran Eda } 62*ae933cc2SManojkiran Eda 63*ae933cc2SManojkiran Eda /** @brief function to update the sensor cache 64*ae933cc2SManojkiran Eda * @param[in] sensorId - sensor Id of the corresponding sensor 65*ae933cc2SManojkiran Eda * @param[in] sensorRearm - sensor rearm value with in the sensor 66*ae933cc2SManojkiran Eda * @param[in] previousState - previous state of the sensor 67*ae933cc2SManojkiran Eda */ updateSensorCacheMaps(pldm::pdr::SensorID sensorId,size_t sensorRearm,uint8_t previousState)68*ae933cc2SManojkiran Eda inline void updateSensorCacheMaps(pldm::pdr::SensorID sensorId, 69*ae933cc2SManojkiran Eda size_t sensorRearm, uint8_t previousState) 70*ae933cc2SManojkiran Eda { 71*ae933cc2SManojkiran Eda // update the sensor cache 72*ae933cc2SManojkiran Eda sensorCacheMap[sensorId][sensorRearm] = previousState; 73*ae933cc2SManojkiran Eda } 74*ae933cc2SManojkiran Eda 75cae1866fSGeorge Liu private: 76cae1866fSGeorge Liu /** @brief Send state sensor event msg when a D-Bus property changes 77cae1866fSGeorge Liu * @param[in] sensorId - sensor id 78cae1866fSGeorge Liu */ 79cae1866fSGeorge Liu void sendStateSensorEvent(SensorId sensorId, const DbusObjMaps& dbusMaps); 80cae1866fSGeorge Liu 81cae1866fSGeorge Liu /** @brief Send all of sensor event 82cae1866fSGeorge Liu * @param[in] eventType - PLDM Event types 83cae1866fSGeorge Liu * @param[in] eventDataVec - std::vector, contains send event data 84cae1866fSGeorge Liu */ 85cae1866fSGeorge Liu void sendEventMsg(uint8_t eventType, 86cae1866fSGeorge Liu const std::vector<uint8_t>& eventDataVec); 87cae1866fSGeorge Liu 88cae1866fSGeorge Liu /** @brief fd of MCTP communications socket */ 89cae1866fSGeorge Liu int mctp_fd; 90cae1866fSGeorge Liu 91cae1866fSGeorge Liu /** @brief MCTP EID of host firmware */ 92cae1866fSGeorge Liu uint8_t mctp_eid; 93cae1866fSGeorge Liu 94a330b2f0SAndrew Jeffery /** @brief reference to an Instance ID database object, used to obtain PLDM 95a330b2f0SAndrew Jeffery * instance IDs 96cae1866fSGeorge Liu */ 97a330b2f0SAndrew Jeffery pldm::InstanceIdDb& instanceIdDb; 98cae1866fSGeorge Liu 99cae1866fSGeorge Liu /** @brief D-Bus property changed signal match */ 10084b790cbSPatrick Williams std::vector<std::unique_ptr<sdbusplus::bus::match_t>> stateSensorMatchs; 101c0c79481SSampa Misra 102c0c79481SSampa Misra /** @brief PLDM request handler */ 103c0c79481SSampa Misra pldm::requester::Handler<pldm::requester::Request>* handler; 104*ae933cc2SManojkiran Eda 105*ae933cc2SManojkiran Eda /** @brief sensor cache */ 106*ae933cc2SManojkiran Eda stateSensorCacheMaps sensorCacheMap; 107cae1866fSGeorge Liu }; 108cae1866fSGeorge Liu 109cae1866fSGeorge Liu } // namespace state_sensor 110cae1866fSGeorge Liu } // namespace pldm 111