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