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