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