blob: add5c2db3867ebe797997f0e64e451d3fcd8b5c3 [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"
7
8#include <map>
9
10using namespace pldm::dbus_api;
11using namespace pldm::responder;
12
13namespace pldm
14{
15
16using SensorId = uint16_t;
17using DbusObjMaps =
18 std::map<SensorId,
19 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>;
20using sensorEvent =
21 std::function<void(SensorId sensorId, const DbusObjMaps& dbusMaps)>;
22
23namespace state_sensor
24{
25/** @class DbusToPLDMEvent
26 * @brief This class can listen to the state sensor PDRs and send PLDM event
27 * msg when a D-Bus property changes
28 */
29class DbusToPLDMEvent
30{
31 public:
32 DbusToPLDMEvent() = delete;
33 DbusToPLDMEvent(const DbusToPLDMEvent&) = delete;
34 DbusToPLDMEvent(DbusToPLDMEvent&&) = delete;
35 DbusToPLDMEvent& operator=(const DbusToPLDMEvent&) = delete;
36 DbusToPLDMEvent& operator=(DbusToPLDMEvent&&) = delete;
37 ~DbusToPLDMEvent() = default;
38
39 /** @brief Constructor
40 * @param[in] mctp_fd - fd of MCTP communications socket
41 * @param[in] mctp_eid - MCTP EID of host firmware
42 * @param[in] requester - reference to Requester object
43 */
44 explicit DbusToPLDMEvent(int mctp_fd, uint8_t mctp_eid,
45 Requester& requester);
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 */
52 void listenSensorEvent(const pdr_utils::Repo& repo,
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 */
77 Requester& requester;
78
79 /** @brief D-Bus property changed signal match */
80 std::vector<std::unique_ptr<sdbusplus::bus::match::match>>
81 stateSensorMatchs;
82};
83
84} // namespace state_sensor
85} // namespace pldm