blob: 87668c2daffafced129d160b6f7a263c1fec1c0f [file] [log] [blame]
George Liucae18662020-05-15 09:32:57 +08001#pragma once
2
George Liucae18662020-05-15 09:32:57 +08003#include "libpldmresponder/pdr_utils.hpp"
Andrew Jefferya330b2f2023-05-04 14:55:37 +09304#include "pldmd/instance_id.hpp"
Sampa Misrac0c79482021-06-02 08:01:54 -05005#include "requester/handler.hpp"
George Liucae18662020-05-15 09:32:57 +08006
George Liuc453e162022-12-21 17:16:23 +08007#include <libpldm/platform.h>
8
George Liucae18662020-05-15 09:32:57 +08009#include <map>
10
George Liucae18662020-05-15 09:32:57 +080011namespace pldm
12{
13
14using SensorId = uint16_t;
15using DbusObjMaps =
Brad Bishop5079ac42021-08-19 18:35:06 -040016 std::map<SensorId, std::tuple<pldm::responder::pdr_utils::DbusMappings,
17 pldm::responder::pdr_utils::DbusValMaps>>;
George Liucae18662020-05-15 09:32:57 +080018using sensorEvent =
19 std::function<void(SensorId sensorId, const DbusObjMaps& dbusMaps)>;
20
21namespace 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 */
27class 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 Misrac0c79482021-06-02 08:01:54 -050041 * @param[in] handler - PLDM request handler
George Liucae18662020-05-15 09:32:57 +080042 */
Sampa Misrac0c79482021-06-02 08:01:54 -050043 explicit DbusToPLDMEvent(
Andrew Jefferya330b2f2023-05-04 14:55:37 +093044 int mctp_fd, uint8_t mctp_eid, pldm::InstanceIdDb& instanceIdDb,
Sampa Misrac0c79482021-06-02 08:01:54 -050045 pldm::requester::Handler<pldm::requester::Request>* handler);
George Liucae18662020-05-15 09:32:57 +080046
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 Bishop5079ac42021-08-19 18:35:06 -040052 void listenSensorEvent(const pldm::responder::pdr_utils::Repo& repo,
George Liucae18662020-05-15 09:32:57 +080053 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
Andrew Jefferya330b2f2023-05-04 14:55:37 +093074 /** @brief reference to an Instance ID database object, used to obtain PLDM
75 * instance IDs
George Liucae18662020-05-15 09:32:57 +080076 */
Andrew Jefferya330b2f2023-05-04 14:55:37 +093077 pldm::InstanceIdDb& instanceIdDb;
George Liucae18662020-05-15 09:32:57 +080078
79 /** @brief D-Bus property changed signal match */
Patrick Williams84b790c2022-07-22 19:26:56 -050080 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> stateSensorMatchs;
Sampa Misrac0c79482021-06-02 08:01:54 -050081
82 /** @brief PLDM request handler */
83 pldm::requester::Handler<pldm::requester::Request>* handler;
George Liucae18662020-05-15 09:32:57 +080084};
85
86} // namespace state_sensor
87} // namespace pldm