blob: 2a25243b92748b3748d546f68a406af3eb1af1f0 [file] [log] [blame]
George Liucae18662020-05-15 09:32:57 +08001#pragma once
2
3#include "libpldm/platform.h"
4
5#include "libpldmresponder/pdr_utils.hpp"
6#include "pldmd/dbus_impl_requester.hpp"
Sampa Misrac0c79482021-06-02 08:01:54 -05007#include "requester/handler.hpp"
George Liucae18662020-05-15 09:32:57 +08008
9#include <map>
10
11using namespace pldm::dbus_api;
12using namespace pldm::responder;
13
14namespace pldm
15{
16
17using SensorId = uint16_t;
18using DbusObjMaps =
19 std::map<SensorId,
20 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>;
21using sensorEvent =
22 std::function<void(SensorId sensorId, const DbusObjMaps& dbusMaps)>;
23
24namespace 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 */
30class 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 Misrac0c79482021-06-02 08:01:54 -050044 * @param[in] handler - PLDM request handler
George Liucae18662020-05-15 09:32:57 +080045 */
Sampa Misrac0c79482021-06-02 08:01:54 -050046 explicit DbusToPLDMEvent(
47 int mctp_fd, uint8_t mctp_eid, Requester& requester,
48 pldm::requester::Handler<pldm::requester::Request>* handler);
George Liucae18662020-05-15 09:32:57 +080049
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 Misrac0c79482021-06-02 08:01:54 -050085
86 /** @brief PLDM request handler */
87 pldm::requester::Handler<pldm::requester::Request>* handler;
George Liucae18662020-05-15 09:32:57 +080088};
89
90} // namespace state_sensor
91} // namespace pldm